Skip to content

Commit bf489ea

Browse files
ayurkiv-nvdayxieca
authored andcommittedFeb 23, 2021
Add new cli for SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS counter in counterpoll utility (#1355)
Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com> depends on: sonic-net/sonic-buildimage#6444 sonic-net/sonic-swss#1600 - What I did Added new option for "counterpoll" utility - How I did it Enhance counterpoll utility for SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS Add new CLI command and extend the show command. - How to verify it To test it use QoS test. run the pfcxontest and Pfcxofftest, drop can be triggered in either of the test. It runs in ptf32 topo and requires RPC image. admin@arc-switch1041:~$ counterpoll pg-drop enable --> to enable the new counter admin@arc-switch1041:~$ counterpoll show --> check new INGRESS_PG_STAT_DROP counter status

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
 

‎counterpoll/main.py

+43
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK"
77
PORT_BUFFER_DROP = "PORT_BUFFER_DROP"
8+
PG_DROP = "PG_DROP"
89
DISABLE = "disable"
910
ENABLE = "enable"
1011
DEFLT_60_SEC= "default (60000)"
@@ -123,6 +124,45 @@ def disable():
123124
port_info['FLEX_COUNTER_STATUS'] = DISABLE
124125
configdb.mod_entry("FLEX_COUNTER_TABLE", PORT_BUFFER_DROP, port_info)
125126

127+
# Ingress PG drop packet stat
128+
@cli.group()
129+
@click.pass_context
130+
def pg_drop(ctx):
131+
""" Ingress PG drop counter commands """
132+
ctx.obj = swsssdk.ConfigDBConnector()
133+
ctx.obj.connect()
134+
135+
@pg_drop.command()
136+
@click.argument('poll_interval', type=click.IntRange(1000, 30000))
137+
@click.pass_context
138+
def interval(ctx, poll_interval):
139+
"""
140+
Set pg_drop packets counter query interval
141+
interval is between 1s and 30s.
142+
"""
143+
144+
port_info = {}
145+
port_info['POLL_INTERVAL'] = poll_interval
146+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)
147+
148+
@pg_drop.command()
149+
@click.pass_context
150+
def enable(ctx):
151+
""" Enable pg_drop counter query """
152+
153+
port_info = {}
154+
port_info['FLEX_COUNTER_STATUS'] = ENABLE
155+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)
156+
157+
@pg_drop.command()
158+
@click.pass_context
159+
def disable(ctx):
160+
""" Disable pg_drop counter query """
161+
162+
port_info = {}
163+
port_info['FLEX_COUNTER_STATUS'] = DISABLE
164+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)
165+
126166
# RIF counter commands
127167
@cli.group()
128168
def rif():
@@ -212,6 +252,7 @@ def show():
212252
rif_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'RIF')
213253
queue_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE_WATERMARK')
214254
pg_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_WATERMARK')
255+
pg_drop_info = configdb.get_entry('FLEX_COUNTER_TABLE', PG_DROP)
215256
buffer_pool_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', BUFFER_POOL_WATERMARK)
216257

217258
header = ("Type", "Interval (in ms)", "Status")
@@ -228,6 +269,8 @@ def show():
228269
data.append(["QUEUE_WATERMARK_STAT", queue_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), queue_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
229270
if pg_wm_info:
230271
data.append(["PG_WATERMARK_STAT", pg_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
272+
if pg_drop_info:
273+
data.append(['PG_DROP_STAT', pg_drop_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_drop_info.get("FLEX_COUNTER_STATUS", DISABLE)])
231274
if buffer_pool_wm_info:
232275
data.append(["BUFFER_POOL_WATERMARK_STAT", buffer_pool_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), buffer_pool_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
233276

‎tests/counterpoll_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
from click.testing import CliRunner
99
from shutil import copyfile
10+
from utilities_common.db import Db
1011

1112
test_path = os.path.dirname(os.path.abspath(__file__))
1213
modules_path = os.path.dirname(test_path)
@@ -25,6 +26,7 @@
2526
PORT_BUFFER_DROP 60000 enable
2627
QUEUE_WATERMARK_STAT 10000 enable
2728
PG_WATERMARK_STAT 10000 enable
29+
PG_DROP_STAT 10000 enable
2830
"""
2931

3032
class TestCounterpoll(object):
@@ -54,6 +56,14 @@ def test_port_buffer_drop_interval_too_short(self):
5456
assert result.exit_code == 2
5557
assert expected in result.output
5658

59+
def test_pg_drop_interval_too_long(self):
60+
runner = CliRunner()
61+
result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], ["50000"])
62+
print(result.output)
63+
expected = "Invalid value for \"POLL_INTERVAL\": 50000 is not in the valid range of 1000 to 30000."
64+
assert result.exit_code == 2
65+
assert expected in result.output
66+
5767
@pytest.fixture(scope='class')
5868
def _get_config_db_file(self):
5969
sample_config_db_file = os.path.join(test_path, "counterpoll_input", "config_db.json")
@@ -76,6 +86,30 @@ def test_update_counter_config_db_status(self, status, _get_config_db_file):
7686
for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items():
7787
assert counter_config["FLEX_COUNTER_STATUS"] == status
7888

89+
@pytest.mark.parametrize("status", ["disable", "enable"])
90+
def test_update_pg_drop_status(self, status):
91+
runner = CliRunner()
92+
db = Db()
93+
94+
result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands[status], [], obj=db.cfgdb)
95+
print(result.exit_code, result.output)
96+
assert result.exit_code == 0
97+
98+
table = db.cfgdb.get_table('FLEX_COUNTER_TABLE')
99+
assert status == table["PG_DROP"]["FLEX_COUNTER_STATUS"]
100+
101+
def test_update_pg_drop_interval(self):
102+
runner = CliRunner()
103+
db = Db()
104+
test_interval = "20000"
105+
106+
result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], [test_interval], obj=db.cfgdb)
107+
print(result.exit_code, result.output)
108+
assert result.exit_code == 0
109+
110+
table = db.cfgdb.get_table('FLEX_COUNTER_TABLE')
111+
assert test_interval == table["PG_DROP"]["POLL_INTERVAL"]
112+
79113
@classmethod
80114
def teardown_class(cls):
81115
print("TEARDOWN")

‎tests/mock_tables/config_db.json

+4
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,10 @@
12631263
"POLL_INTERVAL": "10000",
12641264
"FLEX_COUNTER_STATUS": "enable"
12651265
},
1266+
"FLEX_COUNTER_TABLE|PG_DROP": {
1267+
"POLL_INTERVAL": "10000",
1268+
"FLEX_COUNTER_STATUS": "enable"
1269+
},
12661270
"PFC_WD|Ethernet0": {
12671271
"action": "drop",
12681272
"detection_time": "600",

0 commit comments

Comments
 (0)
Please sign in to comment.