Skip to content

Commit 5b492d5

Browse files
[chassis][voq] clear: Fix clear queuecounters to also clear VOQ counters (#2878)
Fix a bug where the CLI command sonic-clear queuecounters would not clear the VOQ counters. fixes #15198 How I did it Added the command to clear the VOQ counters. How to verify it Start traffic on an interface on a specific queue. Use show queue counters and show queue counters --voq to verify that the counters are non-zero. Stop traffic on the interface. Run sonic-clear queuecounters. Repeat the show commands and ensure that the counters have been reset.
1 parent cf346a3 commit 5b492d5

File tree

3 files changed

+130
-73
lines changed

3 files changed

+130
-73
lines changed

clear/main.py

+3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ def queuecounters():
181181
command = ["queuestat", "-c"]
182182
run_command(command)
183183

184+
command = ["queuestat", "-c", "--voq"]
185+
run_command(command)
186+
184187
@cli.command()
185188
def pfccounters():
186189
"""Clear pfc counters"""

tests/mock_tables/counters_db.json

+27-27
Original file line numberDiff line numberDiff line change
@@ -1059,36 +1059,36 @@
10591059
},
10601060

10611061
"COUNTERS_SYSTEM_PORT_NAME_MAP": {
1062-
"Ethernet0": "oid:0x1000000000042",
1063-
"Ethernet4": "oid:0x1000000000043",
1064-
"Ethernet8": "oid:0x1000000000044"
1062+
"testsw|Ethernet0": "oid:0x1000000000042",
1063+
"testsw|Ethernet4": "oid:0x1000000000043",
1064+
"testsw|Ethernet8": "oid:0x1000000000044"
10651065
},
10661066

10671067
"COUNTERS_VOQ_NAME_MAP": {
1068-
"Ethernet0:0": "oid:0x15000000000657",
1069-
"Ethernet0:1": "oid:0x15000000000658",
1070-
"Ethernet0:2": "oid:0x15000000000659",
1071-
"Ethernet0:3": "oid:0x1500000000065a",
1072-
"Ethernet0:4": "oid:0x1500000000065b",
1073-
"Ethernet0:5": "oid:0x1500000000065c",
1074-
"Ethernet0:6": "oid:0x1500000000065d",
1075-
"Ethernet0:7": "oid:0x1500000000065e",
1076-
"Ethernet4:0": "oid:0x15000000000667",
1077-
"Ethernet4:1": "oid:0x15000000000668",
1078-
"Ethernet4:2": "oid:0x15000000000669",
1079-
"Ethernet4:3": "oid:0x1500000000066a",
1080-
"Ethernet4:4": "oid:0x1500000000066b",
1081-
"Ethernet4:5": "oid:0x1500000000066c",
1082-
"Ethernet4:6": "oid:0x1500000000066d",
1083-
"Ethernet4:7": "oid:0x1500000000066e",
1084-
"Ethernet8:0": "oid:0x15000000000677",
1085-
"Ethernet8:1": "oid:0x15000000000678",
1086-
"Ethernet8:2": "oid:0x15000000000679",
1087-
"Ethernet8:3": "oid:0x1500000000067a",
1088-
"Ethernet8:4": "oid:0x1500000000067b",
1089-
"Ethernet8:5": "oid:0x1500000000067c",
1090-
"Ethernet8:6": "oid:0x1500000000067d",
1091-
"Ethernet8:7": "oid:0x1500000000067e"
1068+
"testsw|Ethernet0:0": "oid:0x15000000000657",
1069+
"testsw|Ethernet0:1": "oid:0x15000000000658",
1070+
"testsw|Ethernet0:2": "oid:0x15000000000659",
1071+
"testsw|Ethernet0:3": "oid:0x1500000000065a",
1072+
"testsw|Ethernet0:4": "oid:0x1500000000065b",
1073+
"testsw|Ethernet0:5": "oid:0x1500000000065c",
1074+
"testsw|Ethernet0:6": "oid:0x1500000000065d",
1075+
"testsw|Ethernet0:7": "oid:0x1500000000065e",
1076+
"testsw|Ethernet4:0": "oid:0x15000000000667",
1077+
"testsw|Ethernet4:1": "oid:0x15000000000668",
1078+
"testsw|Ethernet4:2": "oid:0x15000000000669",
1079+
"testsw|Ethernet4:3": "oid:0x1500000000066a",
1080+
"testsw|Ethernet4:4": "oid:0x1500000000066b",
1081+
"testsw|Ethernet4:5": "oid:0x1500000000066c",
1082+
"testsw|Ethernet4:6": "oid:0x1500000000066d",
1083+
"testsw|Ethernet4:7": "oid:0x1500000000066e",
1084+
"testsw|Ethernet8:0": "oid:0x15000000000677",
1085+
"testsw|Ethernet8:1": "oid:0x15000000000678",
1086+
"testsw|Ethernet8:2": "oid:0x15000000000679",
1087+
"testsw|Ethernet8:3": "oid:0x1500000000067a",
1088+
"testsw|Ethernet8:4": "oid:0x1500000000067b",
1089+
"testsw|Ethernet8:5": "oid:0x1500000000067c",
1090+
"testsw|Ethernet8:6": "oid:0x1500000000067d",
1091+
"testsw|Ethernet8:7": "oid:0x1500000000067e"
10921092
},
10931093

10941094
"COUNTERS_PORT_NAME_MAP": {

tests/queue_counter_test.py

+100-46
Original file line numberDiff line numberDiff line change
@@ -997,58 +997,94 @@
997997
}"""
998998

999999
show_queue_voq_counters = """\
1000-
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1001-
--------- ----- -------------- --------------- ----------- ------------
1002-
Ethernet0 VOQ0 68 30 56 74
1003-
Ethernet0 VOQ1 60 43 39 1
1004-
Ethernet0 VOQ2 82 7 39 21
1005-
Ethernet0 VOQ3 11 59 12 94
1006-
Ethernet0 VOQ4 36 62 35 40
1007-
Ethernet0 VOQ5 49 91 2 88
1008-
Ethernet0 VOQ6 33 17 94 74
1009-
Ethernet0 VOQ7 40 71 95 33
1000+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1001+
---------------- ----- -------------- --------------- ----------- ------------
1002+
testsw|Ethernet0 VOQ0 68 30 56 74
1003+
testsw|Ethernet0 VOQ1 60 43 39 1
1004+
testsw|Ethernet0 VOQ2 82 7 39 21
1005+
testsw|Ethernet0 VOQ3 11 59 12 94
1006+
testsw|Ethernet0 VOQ4 36 62 35 40
1007+
testsw|Ethernet0 VOQ5 49 91 2 88
1008+
testsw|Ethernet0 VOQ6 33 17 94 74
1009+
testsw|Ethernet0 VOQ7 40 71 95 33
10101010
1011-
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1012-
--------- ----- -------------- --------------- ----------- ------------
1013-
Ethernet4 VOQ0 54 8 93 78
1014-
Ethernet4 VOQ1 83 96 74 9
1015-
Ethernet4 VOQ2 15 60 61 31
1016-
Ethernet4 VOQ3 45 52 82 94
1017-
Ethernet4 VOQ4 55 88 89 52
1018-
Ethernet4 VOQ5 14 70 95 79
1019-
Ethernet4 VOQ6 68 60 66 81
1020-
Ethernet4 VOQ7 63 4 48 76
1011+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1012+
---------------- ----- -------------- --------------- ----------- ------------
1013+
testsw|Ethernet4 VOQ0 54 8 93 78
1014+
testsw|Ethernet4 VOQ1 83 96 74 9
1015+
testsw|Ethernet4 VOQ2 15 60 61 31
1016+
testsw|Ethernet4 VOQ3 45 52 82 94
1017+
testsw|Ethernet4 VOQ4 55 88 89 52
1018+
testsw|Ethernet4 VOQ5 14 70 95 79
1019+
testsw|Ethernet4 VOQ6 68 60 66 81
1020+
testsw|Ethernet4 VOQ7 63 4 48 76
10211021
1022-
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1023-
--------- ----- -------------- --------------- ----------- ------------
1024-
Ethernet8 VOQ0 41 73 77 74
1025-
Ethernet8 VOQ1 60 21 56 54
1026-
Ethernet8 VOQ2 57 31 12 39
1027-
Ethernet8 VOQ3 41 96 70 98
1028-
Ethernet8 VOQ4 18 49 63 36
1029-
Ethernet8 VOQ5 99 90 3 15
1030-
Ethernet8 VOQ6 8 84 82 94
1031-
Ethernet8 VOQ7 83 15 75 92
1022+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1023+
---------------- ----- -------------- --------------- ----------- ------------
1024+
testsw|Ethernet8 VOQ0 41 73 77 74
1025+
testsw|Ethernet8 VOQ1 60 21 56 54
1026+
testsw|Ethernet8 VOQ2 57 31 12 39
1027+
testsw|Ethernet8 VOQ3 41 96 70 98
1028+
testsw|Ethernet8 VOQ4 18 49 63 36
1029+
testsw|Ethernet8 VOQ5 99 90 3 15
1030+
testsw|Ethernet8 VOQ6 8 84 82 94
1031+
testsw|Ethernet8 VOQ7 83 15 75 92
10321032
10331033
"""
10341034

1035+
show_queue_voq_counters_with_clear = ["""\
1036+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1037+
---------------- ----- -------------- --------------- ----------- ------------
1038+
testsw|Ethernet0 VOQ0 0 0 0 0
1039+
testsw|Ethernet0 VOQ1 0 0 0 0
1040+
testsw|Ethernet0 VOQ2 0 0 0 0
1041+
testsw|Ethernet0 VOQ3 0 0 0 0
1042+
testsw|Ethernet0 VOQ4 0 0 0 0
1043+
testsw|Ethernet0 VOQ5 0 0 0 0
1044+
testsw|Ethernet0 VOQ6 0 0 0 0
1045+
testsw|Ethernet0 VOQ7 0 0 0 0
1046+
""", """\
1047+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1048+
---------------- ----- -------------- --------------- ----------- ------------
1049+
testsw|Ethernet4 VOQ0 0 0 0 0
1050+
testsw|Ethernet4 VOQ1 0 0 0 0
1051+
testsw|Ethernet4 VOQ2 0 0 0 0
1052+
testsw|Ethernet4 VOQ3 0 0 0 0
1053+
testsw|Ethernet4 VOQ4 0 0 0 0
1054+
testsw|Ethernet4 VOQ5 0 0 0 0
1055+
testsw|Ethernet4 VOQ6 0 0 0 0
1056+
testsw|Ethernet4 VOQ7 0 0 0 0
1057+
""", """\
1058+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1059+
---------------- ----- -------------- --------------- ----------- ------------
1060+
testsw|Ethernet8 VOQ0 0 0 0 0
1061+
testsw|Ethernet8 VOQ1 0 0 0 0
1062+
testsw|Ethernet8 VOQ2 0 0 0 0
1063+
testsw|Ethernet8 VOQ3 0 0 0 0
1064+
testsw|Ethernet8 VOQ4 0 0 0 0
1065+
testsw|Ethernet8 VOQ5 0 0 0 0
1066+
testsw|Ethernet8 VOQ6 0 0 0 0
1067+
testsw|Ethernet8 VOQ7 0 0 0 0
1068+
"""
1069+
]
1070+
10351071
show_queue_port_voq_counters = """\
1036-
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1037-
--------- ----- -------------- --------------- ----------- ------------
1038-
Ethernet0 VOQ0 68 30 56 74
1039-
Ethernet0 VOQ1 60 43 39 1
1040-
Ethernet0 VOQ2 82 7 39 21
1041-
Ethernet0 VOQ3 11 59 12 94
1042-
Ethernet0 VOQ4 36 62 35 40
1043-
Ethernet0 VOQ5 49 91 2 88
1044-
Ethernet0 VOQ6 33 17 94 74
1045-
Ethernet0 VOQ7 40 71 95 33
1072+
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
1073+
---------------- ----- -------------- --------------- ----------- ------------
1074+
testsw|Ethernet0 VOQ0 68 30 56 74
1075+
testsw|Ethernet0 VOQ1 60 43 39 1
1076+
testsw|Ethernet0 VOQ2 82 7 39 21
1077+
testsw|Ethernet0 VOQ3 11 59 12 94
1078+
testsw|Ethernet0 VOQ4 36 62 35 40
1079+
testsw|Ethernet0 VOQ5 49 91 2 88
1080+
testsw|Ethernet0 VOQ6 33 17 94 74
1081+
testsw|Ethernet0 VOQ7 40 71 95 33
10461082
10471083
"""
10481084

10491085
show_queue_voq_counters_json = """\
10501086
{
1051-
"Ethernet0": {
1087+
"testsw|Ethernet0": {
10521088
"VOQ0": {
10531089
"dropbytes": "74",
10541090
"droppacket": "56",
@@ -1098,7 +1134,7 @@
10981134
"totalpacket": "40"
10991135
}
11001136
},
1101-
"Ethernet4": {
1137+
"testsw|Ethernet4": {
11021138
"VOQ0": {
11031139
"dropbytes": "78",
11041140
"droppacket": "93",
@@ -1148,7 +1184,7 @@
11481184
"totalpacket": "63"
11491185
}
11501186
},
1151-
"Ethernet8": {
1187+
"testsw|Ethernet8": {
11521188
"VOQ0": {
11531189
"dropbytes": "74",
11541190
"droppacket": "77",
@@ -1202,7 +1238,7 @@
12021238

12031239
show_queue_port_voq_counters_json = """\
12041240
{
1205-
"Ethernet0": {
1241+
"testsw|Ethernet0": {
12061242
"VOQ0": {
12071243
"dropbytes": "74",
12081244
"droppacket": "56",
@@ -1339,11 +1375,29 @@ def test_queue_voq_counters(self):
13391375
assert result.exit_code == 0
13401376
assert result.output == show_queue_voq_counters
13411377

1378+
def test_queue_voq_counters_with_clear(self):
1379+
runner = CliRunner()
1380+
result = runner.invoke(clear.cli.commands['queuecounters'], [])
1381+
assert result.exit_code == 0
1382+
result = runner.invoke(
1383+
show.cli.commands["queue"].commands["counters"],
1384+
["--voq"]
1385+
)
1386+
print(result.output)
1387+
show.run_command(['queuestat', '-d', '--voq'])
1388+
assert result.exit_code == 0
1389+
assert "Ethernet0 Last cached time was" in result.output and \
1390+
"Ethernet4 Last cached time was" in result.output and \
1391+
"Ethernet8 Last cached time was" in result.output
1392+
assert show_queue_voq_counters_with_clear[0] in result.output and \
1393+
show_queue_voq_counters_with_clear[1] in result.output and \
1394+
show_queue_voq_counters_with_clear[2] in result.output
1395+
13421396
def test_queue_port_voq_counters(self):
13431397
runner = CliRunner()
13441398
result = runner.invoke(
13451399
show.cli.commands["queue"].commands["counters"],
1346-
["Ethernet0", "--voq"]
1400+
["testsw|Ethernet0", "--voq"]
13471401
)
13481402
print(result.output)
13491403
assert result.exit_code == 0
@@ -1370,7 +1424,7 @@ def test_queue_voq_counters_port_json(self):
13701424
runner = CliRunner()
13711425
result = runner.invoke(
13721426
show.cli.commands["queue"].commands["counters"],
1373-
["Ethernet0", "--voq", "--json"]
1427+
["testsw|Ethernet0", "--voq", "--json"]
13741428
)
13751429
assert result.exit_code == 0
13761430
print(result.output)

0 commit comments

Comments
 (0)