Skip to content

Commit 6e0ee3e

Browse files
[CRM][DASH] Extend CRM utility to support DASH resources. (sonic-net#2800)
- What I did Extend CRM utility to support DASH resources. - How I did it Add "dash" sub-group to "crm config" and "crm show" commands. "dash" sub-group will be available for the user only if SONiC runs on the DPU. - How to verify it Compile sonic-utilities package. The tests will run automatically. To cover dash-related functionality new test tests/crm_dash_test.py was added. Code coverage is the following: crm/dash_config.py - 99% crm/dash_show.py - 98% crm/main.py - 92% - Previous command output (if the output of a command-line utility has changed) The existing commands are not affected. - New command output (if the output of a command-line utility has changed) crm config thresholds dash [vnet|eni|eni-ether-address] type [percentage|used|count] thresholds dash [vnet|eni|eni-ether-address] [low|high] thresholds dash [ipv4|ipv6] [inbound|outbound] routing type [percentage|used|count] thresholds dash [ipv4|ipv6] [inbound|outbound] routing [low|high] thresholds dash [ipv4|ipv6] pa-validation [percentage|used|count] thresholds dash [ipv4|ipv6] pa-validation [low|high] thresholds dash [ipv4|ipv6] outbound ca-to-pa [percentage|used|count] thresholds dash [ipv4|ipv6] outbound ca-to-pa [low|high] thresholds dash [ipv4|ipv6] acl group [percentage|used|count] thresholds dash [ipv4|ipv6] acl group [low|high] thresholds dash [ipv4|ipv6] acl rule [percentage|used|count] thresholds dash [ipv4|ipv6] acl rule [low|high] crm show [resources|thresholds] dash [vnet|eni|eni-ether-address] [resources|thresholds] dash [ipv4|ipv6] [inbound|outbound] routing [resources|thresholds] dash [ipv4|ipv6] pa-validation [resources|thresholds] dash [ipv4|ipv6] outbound ca-to-pa [resources|thresholds] dash [ipv4|ipv6] acl group [resources|thresholds] dash [ipv4|ipv6] acl rule show thresholds all show resources all Signed-off-by: Oleksandr Ivantsiv <[email protected]>
1 parent b2c29b0 commit 6e0ee3e

File tree

6 files changed

+666
-17
lines changed

6 files changed

+666
-17
lines changed

crm/dash_config.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import click
2+
3+
def get_attr_full_name(ctx, threshold):
4+
attr = 'dash_'
5+
6+
if ctx.obj["crm"].addr_family:
7+
attr += ctx.obj["crm"].addr_family + '_'
8+
9+
if ctx.obj["crm"].direction:
10+
attr += ctx.obj["crm"].direction + '_'
11+
12+
attr += ctx.obj["crm"].res_type + '_' + threshold
13+
return attr
14+
15+
@click.command('type')
16+
@click.argument('value', type=click.Choice(['percentage', 'used', 'free']))
17+
@click.pass_context
18+
def config_dash_type(ctx, value):
19+
"""CRM threshold type configuration"""
20+
ctx.obj["crm"].config(get_attr_full_name(ctx, 'threshold_type'), value)
21+
22+
@click.command('low')
23+
@click.argument('value', type=click.INT)
24+
@click.pass_context
25+
def config_dash_low(ctx, value):
26+
"""CRM low threshold configuration"""
27+
ctx.obj["crm"].config(get_attr_full_name(ctx, 'low_threshold'), value)
28+
29+
@click.command('high')
30+
@click.argument('value', type=click.INT)
31+
@click.pass_context
32+
def config_dash_high(ctx, value):
33+
"""CRM high threshold configuration"""
34+
ctx.obj["crm"].config(get_attr_full_name(ctx, 'high_threshold'), value)
35+
36+
def group_add_thresholds(group):
37+
group.add_command(config_dash_type)
38+
group.add_command(config_dash_low)
39+
group.add_command(config_dash_high)
40+
41+
@click.group('dash')
42+
@click.pass_context
43+
def config_dash(ctx):
44+
"""CRM configuration for DASH resource"""
45+
pass
46+
47+
@config_dash.group('ipv4')
48+
@click.pass_context
49+
def config_dash_ipv4(ctx):
50+
"""DASH CRM resource IPv4 address family"""
51+
ctx.obj["crm"].addr_family = 'ipv4'
52+
53+
@config_dash.group('ipv6')
54+
@click.pass_context
55+
def config_dash_ipv6(ctx):
56+
"""DASH CRM resource IPv6 address family"""
57+
ctx.obj["crm"].addr_family = 'ipv6'
58+
59+
@click.group('inbound')
60+
@click.pass_context
61+
def config_dash_inbound(ctx):
62+
"""DASH CRM inbound direction resource"""
63+
ctx.obj["crm"].direction = 'inbound'
64+
65+
config_dash_ipv4.add_command(config_dash_inbound)
66+
config_dash_ipv6.add_command(config_dash_inbound)
67+
68+
@click.group('outbound')
69+
@click.pass_context
70+
def config_dash_outbound(ctx):
71+
"""DASH CRM outbound direction resource"""
72+
ctx.obj["crm"].direction = 'outbound'
73+
74+
config_dash_ipv4.add_command(config_dash_outbound)
75+
config_dash_ipv6.add_command(config_dash_outbound)
76+
77+
@config_dash.group('eni')
78+
@click.pass_context
79+
def config_dash_eni(ctx):
80+
"""CRM configuration for DASH ENI resource"""
81+
ctx.obj["crm"].res_type = 'eni'
82+
83+
group_add_thresholds(config_dash_eni)
84+
85+
@config_dash.group('eni-ether-address')
86+
@click.pass_context
87+
def config_dash_eni_ether_address_map(ctx):
88+
"""CRM configuration for DASH ENI ETHER address map entry"""
89+
ctx.obj["crm"].res_type = 'eni_ether_address_map'
90+
91+
group_add_thresholds(config_dash_eni_ether_address_map)
92+
93+
@config_dash.group('vnet')
94+
@click.pass_context
95+
def config_dash_vnet(ctx):
96+
"""CRM configuration for DASH VNET resource"""
97+
ctx.obj["crm"].res_type = 'vnet'
98+
99+
group_add_thresholds(config_dash_vnet)
100+
101+
@click.group('routing')
102+
@click.pass_context
103+
def config_dash_routing(ctx):
104+
"""CRM configuration for DASH inbound routes"""
105+
ctx.obj["crm"].res_type = 'routing'
106+
107+
group_add_thresholds(config_dash_routing)
108+
config_dash_inbound.add_command(config_dash_routing)
109+
config_dash_outbound.add_command(config_dash_routing)
110+
111+
@click.group('pa-validation')
112+
@click.pass_context
113+
def config_dash_pa_validation(ctx):
114+
"""CRM configuration for DASH PA validation entries"""
115+
ctx.obj["crm"].res_type = 'pa_validation'
116+
117+
group_add_thresholds(config_dash_pa_validation)
118+
config_dash_ipv4.add_command(config_dash_pa_validation)
119+
config_dash_ipv6.add_command(config_dash_pa_validation)
120+
121+
@click.group('ca-to-pa')
122+
@click.pass_context
123+
def config_dash_ca_to_pa(ctx):
124+
"""CRM configuration for DASH CA to PA entries"""
125+
ctx.obj["crm"].res_type = 'ca_to_pa'
126+
127+
group_add_thresholds(config_dash_ca_to_pa)
128+
config_dash_outbound.add_command(config_dash_ca_to_pa)
129+
130+
@click.group('acl')
131+
@click.pass_context
132+
def config_dash_acl(ctx):
133+
"""DASH CRM ACL resource"""
134+
135+
config_dash_ipv4.add_command(config_dash_acl)
136+
config_dash_ipv6.add_command(config_dash_acl)
137+
138+
@click.group('group')
139+
@click.pass_context
140+
def config_dash_acl_group(ctx):
141+
"""CRM configuration for DASH ACL group entries"""
142+
ctx.obj["crm"].res_type = 'acl_group'
143+
144+
group_add_thresholds(config_dash_acl_group)
145+
config_dash_acl.add_command(config_dash_acl_group)
146+
147+
@click.group('rule')
148+
@click.pass_context
149+
def config_dash_acl_rule(ctx):
150+
"""CRM configuration for DASH ACL rule entries"""
151+
ctx.obj["crm"].res_type = 'acl_rule'
152+
153+
group_add_thresholds(config_dash_acl_rule)
154+
config_dash_acl.add_command(config_dash_acl_rule)
155+

crm/dash_show.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import click
2+
3+
def show_resource(ctx, resource):
4+
if ctx.obj["crm"].cli_mode == 'thresholds':
5+
ctx.obj["crm"].show_thresholds(resource)
6+
elif ctx.obj["crm"].cli_mode == 'resources':
7+
ctx.obj["crm"].show_resources(resource)
8+
9+
@click.group('dash')
10+
@click.pass_context
11+
def show_dash(ctx):
12+
"""Show CRM information for DASH"""
13+
pass
14+
15+
@show_dash.group('ipv4')
16+
@click.pass_context
17+
def show_dash_ipv4(ctx):
18+
"""Show CRM information for IPv4 address family"""
19+
ctx.obj["crm"].addr_family = 'ipv4'
20+
21+
@show_dash.group('ipv6')
22+
@click.pass_context
23+
def show_dash_ipv6(ctx):
24+
"""Show CRM information for IPv6 address family"""
25+
ctx.obj["crm"].addr_family = 'ipv6'
26+
27+
@click.group('inbound')
28+
@click.pass_context
29+
def show_dash_inbound(ctx):
30+
"""Show CRM information for inbound direction"""
31+
ctx.obj["crm"].direction = 'inbound'
32+
33+
show_dash_ipv4.add_command(show_dash_inbound)
34+
show_dash_ipv6.add_command(show_dash_inbound)
35+
36+
@click.group('outbound')
37+
@click.pass_context
38+
def show_dash_outbound(ctx):
39+
"""Show CRM information for outbound direction"""
40+
ctx.obj["crm"].direction = 'outbound'
41+
42+
show_dash_ipv4.add_command(show_dash_outbound)
43+
show_dash_ipv6.add_command(show_dash_outbound)
44+
45+
@show_dash.command('vnet')
46+
@click.pass_context
47+
def show_dash_vnet(ctx):
48+
"""Show CRM information for VNETs"""
49+
show_resource(ctx, 'dash_vnet')
50+
51+
@show_dash.command('eni')
52+
@click.pass_context
53+
def show_dash_eni(ctx):
54+
"""Show CRM information for ENIs"""
55+
show_resource(ctx, 'dash_eni')
56+
57+
@show_dash.command('eni-ether-address')
58+
@click.pass_context
59+
def show_dash_eni_ether_address_map(ctx):
60+
"""Show CRM information for ENI ETHER address map entries"""
61+
show_resource(ctx, 'dash_eni_ether_address_map')
62+
63+
@click.command('routing')
64+
@click.pass_context
65+
def show_dash_routing(ctx):
66+
"""Show CRM information for inbound routes"""
67+
resource = f'dash_{ctx.obj["crm"].addr_family}_{ctx.obj["crm"].direction}_routing'
68+
show_resource(ctx, resource)
69+
70+
show_dash_inbound.add_command(show_dash_routing)
71+
show_dash_outbound.add_command(show_dash_routing)
72+
73+
@click.command('pa-validation')
74+
@click.pass_context
75+
def show_dash_pa_validation(ctx):
76+
"""Show CRM information for PA validation entries"""
77+
resource = f'dash_{ctx.obj["crm"].addr_family}_pa_validation'
78+
show_resource(ctx, resource)
79+
80+
show_dash_ipv4.add_command(show_dash_pa_validation)
81+
show_dash_ipv6.add_command(show_dash_pa_validation)
82+
83+
@click.command('ca-to-pa')
84+
@click.pass_context
85+
def show_dash_ca_to_pa(ctx):
86+
"""Show CRM information for CA to PA entries"""
87+
resource = f'dash_{ctx.obj["crm"].addr_family}_{ctx.obj["crm"].direction}_ca_to_pa'
88+
show_resource(ctx, resource)
89+
90+
show_dash_outbound.add_command(show_dash_ca_to_pa)
91+
92+
@click.group('acl')
93+
@click.pass_context
94+
def show_dash_acl(ctx):
95+
"""Show CRM information for ACL resources"""
96+
97+
show_dash_ipv4.add_command(show_dash_acl)
98+
show_dash_ipv6.add_command(show_dash_acl)
99+
100+
@click.command('group')
101+
@click.pass_context
102+
def show_dash_acl_group(ctx):
103+
"""Show CRM information for ACL group entries"""
104+
resource = f'dash_{ctx.obj["crm"].addr_family}_acl_group'
105+
show_resource(ctx, resource)
106+
107+
show_dash_acl.add_command(show_dash_acl_group)
108+
109+
@click.command('rule')
110+
@click.pass_context
111+
def show_dash_acl_rule(ctx):
112+
"""Show CRM information for ACL rule entries"""
113+
resource = f'dash_{ctx.obj["crm"].addr_family}_acl_rule'
114+
if ctx.obj["crm"].cli_mode == 'thresholds':
115+
ctx.obj["crm"].show_thresholds(resource)
116+
elif ctx.obj["crm"].cli_mode == 'resources':
117+
ctx.obj["crm"].show_acl_group_resources(resource)
118+
119+
show_dash_acl.add_command(show_dash_acl_rule)

0 commit comments

Comments
 (0)