Skip to content

Commit 0b977d1

Browse files
authored
[trim]: Add Packet Trimming Asym DSCP CLI (#3971)
Signed-off-by: Nazarii Hnydyn <[email protected]> <!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "closes #xxxx", "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related issue when the PR is merged. If you are adding/modifying/removing any command or utility script, please also make sure to add/modify/remove any unit tests from the tests directory as appropriate. If you are modifying or removing an existing 'show', 'config' or 'sonic-clear' subcommand, or you are adding a new subcommand, please make sure you also update the Command Line Reference Guide (doc/Command-Reference.md) to reflect your changes. Please provide the following information: --> **HLD:** sonic-net/SONiC#1988 #### What I did * Implemented CLI for Packet Trimming Asymmetric DSCP feature #### How I did it * Integrated Packet Trimming Asymmetric DSCP interface into `config` and `show` CLI root #### How to verify it 1. Run Packet Trimming CLI UTs #### Previous command output (if the output of a command-line utility has changed) ``` admin@sonic:/home/admin# show switch-trimming global +-----------------------------+---------+ | Configuration | Value | +=============================+=========+ | Packet trimming size | 256 | +-----------------------------+---------+ | Packet trimming DSCP value | 25 | +-----------------------------+---------+ | Packet trimming queue index | 5 | +-----------------------------+---------+ ``` #### New command output (if the output of a command-line utility has changed) ``` admin@sonic:/home/admin# show switch-trimming global +-----------------------------+---------+ | Configuration | Value | +=============================+=========+ | Packet trimming size | 256 | +-----------------------------+---------+ | Packet trimming DSCP value | from-tc | +-----------------------------+---------+ | Packet trimming TC value | 10 | +-----------------------------+---------+ | Packet trimming queue index | 5 | +-----------------------------+---------+ ``` #### A picture of a cute animal (not mandatory but encouraged) ``` .---. .----------- / \ __ / ------ / / \( )/ ----- ////// ' \/ ` --- //// / // : : --- // / / /` '-- // //..\\ ====UU====UU==== '//||\\` ''`` ```
1 parent b51e117 commit 0b977d1

File tree

14 files changed

+291
-53
lines changed

14 files changed

+291
-53
lines changed

config/plugins/sonic-trimming.py

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
CFG_SWITCH_TRIMMING,
1111
STATE_SWITCH_CAPABILITY,
1212
STATE_CAP_TRIMMING_CAPABLE_KEY,
13+
STATE_CAP_DSCP_MODE_KEY,
14+
STATE_CAP_DSCP_MODE_DSCP_VALUE,
15+
STATE_CAP_DSCP_MODE_FROM_TC,
1316
STATE_CAP_QUEUE_MODE_KEY,
1417
STATE_CAP_QUEUE_MODE_DYNAMIC,
1518
STATE_CAP_QUEUE_MODE_STATIC,
19+
STATE_CAP_TC_NUM_KEY,
20+
STATE_CAP_QUEUE_NUM_KEY,
21+
CFG_TRIM_DSCP_VALUE_FROM_TC,
1622
CFG_TRIM_QUEUE_INDEX_DYNAMIC,
1723
CFG_TRIM_KEY,
1824
STATE_CAP_KEY,
25+
DSCP_MIN,
26+
DSCP_MAX,
1927
UINT32_MAX,
2028
UINT8_MAX,
2129
SYSLOG_IDENTIFIER,
@@ -32,6 +40,14 @@
3240
# Validators ----------------------------------------------------------------------------------------------------------
3341
#
3442

43+
def generic_validator(ctx, db):
44+
""" Generic configuration validator """
45+
entry = db.get_all(db.STATE_DB, "{}|{}".format(STATE_SWITCH_CAPABILITY, STATE_CAP_KEY))
46+
value = entry.get(STATE_CAP_TRIMMING_CAPABLE_KEY, "false")
47+
48+
if value != "true":
49+
ctx.fail("Failed to configure switch trimming: operation is not supported")
50+
3551

3652
class SizeTypeValidator(click.ParamType):
3753
""" Size option validator """
@@ -44,10 +60,68 @@ def convert(self, value, param, ctx):
4460

4561
class DscpTypeValidator(click.ParamType):
4662
""" Dscp option validator """
63+
name = "text"
64+
65+
def get_metavar(self, param):
66+
db = get_db(click.get_current_context())
67+
68+
entry = db.get_all(db.STATE_DB, "{}|{}".format(STATE_SWITCH_CAPABILITY, STATE_CAP_KEY))
69+
entry.setdefault(STATE_CAP_DSCP_MODE_KEY, "N/A")
70+
71+
cap_list = entry[STATE_CAP_DSCP_MODE_KEY].split(',')
72+
73+
if cap_list.count(STATE_CAP_DSCP_MODE_FROM_TC) == len(cap_list):
74+
return "from-tc"
75+
elif cap_list.count(STATE_CAP_DSCP_MODE_DSCP_VALUE) == len(cap_list):
76+
return "INTEGER"
77+
78+
return "[INTEGER|from-tc]"
79+
80+
def convert(self, value, param, ctx):
81+
db = get_db(ctx)
82+
83+
entry = db.get_all(db.STATE_DB, "{}|{}".format(STATE_SWITCH_CAPABILITY, STATE_CAP_KEY))
84+
entry.setdefault(STATE_CAP_DSCP_MODE_KEY, "N/A")
85+
86+
if not entry[STATE_CAP_DSCP_MODE_KEY]:
87+
raise click.UsageError("Failed to configure {}: no dscp resolution mode capabilities".format(
88+
param.get_error_hint(ctx)), ctx
89+
)
90+
91+
verify_cap = True
92+
93+
if entry[STATE_CAP_DSCP_MODE_KEY] == "N/A":
94+
verify_cap = False
95+
96+
cap_list = entry[STATE_CAP_DSCP_MODE_KEY].split(',')
97+
98+
if value == CFG_TRIM_DSCP_VALUE_FROM_TC:
99+
if verify_cap and (STATE_CAP_DSCP_MODE_FROM_TC not in cap_list):
100+
self.fail("asymmetric dscp resolution mode is not supported", param, ctx)
101+
else:
102+
if verify_cap and (STATE_CAP_DSCP_MODE_DSCP_VALUE not in cap_list):
103+
self.fail("symmetric dscp resolution mode is not supported", param, ctx)
104+
105+
click.IntRange(DSCP_MIN, DSCP_MAX).convert(value, param, ctx)
106+
107+
return value
108+
109+
110+
class TcTypeValidator(click.ParamType):
111+
""" Tc option validator """
47112
name = "integer"
48113

49114
def convert(self, value, param, ctx):
50-
click.IntRange(0, UINT8_MAX).convert(value, param, ctx)
115+
db = get_db(ctx)
116+
117+
entry = db.get_all(db.STATE_DB, "{}|{}".format(STATE_SWITCH_CAPABILITY, STATE_CAP_KEY))
118+
entry.setdefault(STATE_CAP_TC_NUM_KEY, "N/A")
119+
120+
if entry[STATE_CAP_TC_NUM_KEY] == "N/A":
121+
click.IntRange(0, UINT8_MAX).convert(value, param, ctx)
122+
else:
123+
click.IntRange(0, int(entry[STATE_CAP_TC_NUM_KEY])-1).convert(value, param, ctx)
124+
51125
return value
52126

53127

@@ -74,14 +148,8 @@ def convert(self, value, param, ctx):
74148
db = get_db(ctx)
75149

76150
entry = db.get_all(db.STATE_DB, "{}|{}".format(STATE_SWITCH_CAPABILITY, STATE_CAP_KEY))
77-
78-
entry.setdefault(STATE_CAP_TRIMMING_CAPABLE_KEY, "false")
79151
entry.setdefault(STATE_CAP_QUEUE_MODE_KEY, "N/A")
80-
81-
if entry[STATE_CAP_TRIMMING_CAPABLE_KEY] == "false":
82-
raise click.UsageError("Failed to configure {}: operation is not supported".format(
83-
param.get_error_hint(ctx)), ctx
84-
)
152+
entry.setdefault(STATE_CAP_QUEUE_NUM_KEY, "N/A")
85153

86154
if not entry[STATE_CAP_QUEUE_MODE_KEY]:
87155
raise click.UsageError("Failed to configure {}: no queue resolution mode capabilities".format(
@@ -102,7 +170,10 @@ def convert(self, value, param, ctx):
102170
if verify_cap and (STATE_CAP_QUEUE_MODE_STATIC not in cap_list):
103171
self.fail("static queue resolution mode is not supported", param, ctx)
104172

105-
click.IntRange(0, UINT8_MAX).convert(value, param, ctx)
173+
if entry[STATE_CAP_QUEUE_NUM_KEY] == "N/A":
174+
click.IntRange(0, UINT8_MAX).convert(value, param, ctx)
175+
else:
176+
click.IntRange(0, int(entry[STATE_CAP_QUEUE_NUM_KEY])-1).convert(value, param, ctx)
106177

107178
return value
108179

@@ -176,33 +247,41 @@ def SWITCH_TRIMMING():
176247
@click.option(
177248
"-s", "--size", "size",
178249
help="Configures size (in bytes) to trim eligible packet",
179-
type=SizeTypeValidator(),
250+
type=SizeTypeValidator()
180251
)
181252
@click.option(
182253
"-d", "--dscp", "dscp",
183254
help="Configures DSCP value assigned to a packet after trimming",
184-
type=DscpTypeValidator(),
255+
type=DscpTypeValidator()
256+
)
257+
@click.option(
258+
"-t", "--tc", "tc",
259+
help="Configures TC value assigned to a packet after trimming",
260+
type=TcTypeValidator()
185261
)
186262
@click.option(
187263
"-q", "--queue", "queue",
188264
help="Configures queue index to use for transmission of a packet after trimming",
189-
type=QueueTypeValidator(),
265+
type=QueueTypeValidator()
190266
)
191267
@clicommon.pass_db
192268
@click.pass_context
193-
def SWITCH_TRIMMING_GLOBAL(ctx, db, size, dscp, queue):
269+
def SWITCH_TRIMMING_GLOBAL(ctx, db, size, dscp, tc, queue):
194270
""" Configure switch trimming global """
195271

196-
if not (size or dscp or queue):
272+
if not (size or dscp or tc or queue):
197273
raise click.UsageError("Failed to configure switch trimming global: no options are provided", ctx)
198274

275+
generic_validator(ctx, db.db)
276+
199277
table = CFG_SWITCH_TRIMMING
200278
key = CFG_TRIM_KEY
201279

202280
data = {
203281
"size": size,
204282
"dscp_value": dscp,
205-
"queue_index": queue,
283+
"tc_value": tc,
284+
"queue_index": queue
206285
}
207286

208287
try:

doc/Command-Reference.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9166,19 +9166,22 @@ This command displays switch trimming global configuration.
91669166
```bash
91679167
admin@sonic:~$ show switch-trimming global
91689168
+-----------------------------+---------+
9169-
| Configuration | Value |
9169+
| Configuration | Value |
91709170
+=============================+=========+
9171-
| Packet trimming size | 200 |
9171+
| Packet trimming size | 200 |
91729172
+-----------------------------+---------+
9173-
| Packet trimming DSCP value | 20 |
9173+
| Packet trimming DSCP value | 20 |
91749174
+-----------------------------+---------+
9175-
| Packet trimming queue index | 2 |
9175+
| Packet trimming TC value | N/A |
9176+
+-----------------------------+---------+
9177+
| Packet trimming queue index | 2 |
91769178
+-----------------------------+---------+
91779179

91789180
admin@sonic:~$ show switch-trimming global --json
91799181
{
91809182
"size": "200",
91819183
"dscp_value": "20",
9184+
"tc_value": "N/A",
91829185
"queue_index": "2"
91839186
}
91849187
```
@@ -9199,22 +9202,21 @@ This command is used to manage switch trimming global configuration.
91999202
- Options:
92009203
- _-s,--size_: size (in bytes) to trim eligible packet
92019204
- _-d,--dscp_: dscp value assigned to a packet after trimming
9205+
- _-t,--tc_: tc value assigned to a packet after trimming
92029206
- _-q,--queue_: queue index to use for transmission of a packet after trimming
92039207

92049208
- Examples:
92059209
```bash
9206-
admin@sonic:~$ config switch-trimming global \
9207-
--size '128' \
9208-
--dscp '48' \
9209-
--queue '6'
9210+
admin@sonic:~$ config switch-trimming global --size '128' --dscp '48' --queue '6'
9211+
admin@sonic:~$ config switch-trimming global --size '128' --dscp '48' --queue 'dynamic'
9212+
admin@sonic:~$ config switch-trimming global --size '128' --dscp 'from-tc' --tc '6' --queue '6'
9213+
admin@sonic:~$ config switch-trimming global --size '128' --dscp 'from-tc' --tc '6' --queue 'dynamic'
92109214
```
92119215

92129216
- Note:
92139217
- At least one option must be provided
9218+
- When `--dscp` value is set to `from-tc`, the `--tc` value is used for mapping to DSCP
92149219
- When `--queue` value is set to `dynamic`, the `--dscp` value is used for mapping to the queue
9215-
```bash
9216-
admin@sonic:~$ config switch-trimming global --queue dynamic
9217-
```
92189220

92199221
Go Back To [Beginning of the document](#) or [Beginning of this section](#packet-trimming)
92209222

show/plugins/sonic-trimming.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from utilities_common.switch_trimming import (
1111
CFG_SWITCH_TRIMMING,
12-
CFG_TRIM_KEY
12+
CFG_TRIM_KEY,
1313
)
1414

1515

@@ -81,6 +81,7 @@ def SWITCH_TRIMMING_GLOBAL(ctx, db, json_format):
8181
json_dict = {
8282
"size": entry.get("size", "N/A"),
8383
"dscp_value": entry.get("dscp_value", "N/A"),
84+
"tc_value": entry.get("tc_value", "N/A"),
8485
"queue_index": entry.get("queue_index", "N/A")
8586
}
8687
click.echo(json.dumps(json_dict, indent=4))
@@ -110,6 +111,18 @@ def SWITCH_TRIMMING_GLOBAL(ctx, db, json_format):
110111
]
111112
body.append(row)
112113

114+
row = [
115+
"Packet trimming TC value",
116+
format_attr_value(
117+
entry,
118+
{
119+
'name': 'tc_value',
120+
'is-leaf-list': False
121+
}
122+
)
123+
]
124+
body.append(row)
125+
113126
row = [
114127
"Packet trimming queue index",
115128
format_attr_value(

tests/trimming_input/assert_show_output.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,38 @@
1414
+-----------------------------+---------+
1515
| Packet trimming DSCP value | 20 |
1616
+-----------------------------+---------+
17+
| Packet trimming TC value | N/A |
18+
+-----------------------------+---------+
1719
| Packet trimming queue index | N/A |
1820
+-----------------------------+---------+
1921
"""
2022
show_trim_partial_json = """\
2123
{
2224
"size": "200",
2325
"dscp_value": "20",
26+
"tc_value": "N/A",
2427
"queue_index": "N/A"
2528
}
2629
"""
2730

28-
show_trim_queue_static = """\
31+
show_trim_dscp_asymmetric = """\
2932
+-----------------------------+---------+
30-
| Configuration | Value |
33+
| Configuration | Value |
3134
+=============================+=========+
32-
| Packet trimming size | 200 |
35+
| Packet trimming size | 200 |
3336
+-----------------------------+---------+
34-
| Packet trimming DSCP value | 20 |
37+
| Packet trimming DSCP value | from-tc |
3538
+-----------------------------+---------+
36-
| Packet trimming queue index | 2 |
39+
| Packet trimming TC value | 2 |
40+
+-----------------------------+---------+
41+
| Packet trimming queue index | 2 |
3742
+-----------------------------+---------+
3843
"""
39-
show_trim_queue_static_json = """\
44+
show_trim_dscp_asymmetric_json = """\
4045
{
4146
"size": "200",
42-
"dscp_value": "20",
47+
"dscp_value": "from-tc",
48+
"tc_value": "2",
4349
"queue_index": "2"
4450
}
4551
"""
@@ -52,13 +58,16 @@
5258
+-----------------------------+---------+
5359
| Packet trimming DSCP value | 20 |
5460
+-----------------------------+---------+
61+
| Packet trimming TC value | N/A |
62+
+-----------------------------+---------+
5563
| Packet trimming queue index | dynamic |
5664
+-----------------------------+---------+
5765
"""
5866
show_trim_queue_dynamic_json = """\
5967
{
6068
"size": "200",
6169
"dscp_value": "20",
70+
"tc_value": "N/A",
6271
"queue_index": "dynamic"
6372
}
6473
"""
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"SWITCH_TRIMMING|GLOBAL": {
33
"size": "200",
4-
"dscp_value": "20",
4+
"dscp_value": "from-tc",
5+
"tc_value": "2",
56
"queue_index": "2"
67
}
78
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"SWITCH_CAPABILITY|switch": {
33
"SWITCH_TRIMMING_CAPABLE": "true",
4-
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": "STATIC,DYNAMIC"
4+
"SWITCH|PACKET_TRIMMING_DSCP_RESOLUTION_MODE": "DSCP_VALUE,FROM_TC",
5+
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": "STATIC,DYNAMIC",
6+
"SWITCH|NUMBER_OF_TRAFFIC_CLASSES": "16",
7+
"SWITCH|NUMBER_OF_UNICAST_QUEUES": "8"
58
}
69
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"SWITCH_CAPABILITY|switch": {
3+
"SWITCH_TRIMMING_CAPABLE": "true",
4+
"SWITCH|PACKET_TRIMMING_DSCP_RESOLUTION_MODE": "FROM_TC",
5+
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": "STATIC,DYNAMIC",
6+
"SWITCH|NUMBER_OF_TRAFFIC_CLASSES": "16",
7+
"SWITCH|NUMBER_OF_UNICAST_QUEUES": "8"
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"SWITCH_CAPABILITY|switch": {
3+
"SWITCH_TRIMMING_CAPABLE": "true",
4+
"SWITCH|PACKET_TRIMMING_DSCP_RESOLUTION_MODE": "DSCP_VALUE",
5+
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": "STATIC,DYNAMIC",
6+
"SWITCH|NUMBER_OF_TRAFFIC_CLASSES": "16",
7+
"SWITCH|NUMBER_OF_UNICAST_QUEUES": "8"
8+
}
9+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"SWITCH_CAPABILITY|switch": {
33
"SWITCH_TRIMMING_CAPABLE": "true",
4-
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": ""
4+
"SWITCH|PACKET_TRIMMING_DSCP_RESOLUTION_MODE": "",
5+
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": "",
6+
"SWITCH|NUMBER_OF_TRAFFIC_CLASSES": "N/A",
7+
"SWITCH|NUMBER_OF_UNICAST_QUEUES": "N/A"
58
}
69
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"SWITCH_CAPABILITY|switch": {
33
"SWITCH_TRIMMING_CAPABLE": "false",
4-
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": ""
4+
"SWITCH|PACKET_TRIMMING_DSCP_RESOLUTION_MODE": "",
5+
"SWITCH|PACKET_TRIMMING_QUEUE_RESOLUTION_MODE": "",
6+
"SWITCH|NUMBER_OF_TRAFFIC_CLASSES": "N/A",
7+
"SWITCH|NUMBER_OF_UNICAST_QUEUES": "N/A"
58
}
69
}

0 commit comments

Comments
 (0)