Skip to content

Commit

Permalink
Add new cli for SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS count…
Browse files Browse the repository at this point in the history
…er in counterpoll utility (sonic-net#1355)

Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com>

depends on:
sonic-net#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
  • Loading branch information
ayurkiv-nvda authored Feb 17, 2021
1 parent 6d1ed6c commit 9332b8e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
43 changes: 43 additions & 0 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK"
PORT_BUFFER_DROP = "PORT_BUFFER_DROP"
PG_DROP = "PG_DROP"
DISABLE = "disable"
ENABLE = "enable"
DEFLT_60_SEC= "default (60000)"
Expand Down Expand Up @@ -123,6 +124,45 @@ def disable():
port_info['FLEX_COUNTER_STATUS'] = DISABLE
configdb.mod_entry("FLEX_COUNTER_TABLE", PORT_BUFFER_DROP, port_info)

# Ingress PG drop packet stat
@cli.group()
@click.pass_context
def pg_drop(ctx):
""" Ingress PG drop counter commands """
ctx.obj = swsssdk.ConfigDBConnector()
ctx.obj.connect()

@pg_drop.command()
@click.argument('poll_interval', type=click.IntRange(1000, 30000))
@click.pass_context
def interval(ctx, poll_interval):
"""
Set pg_drop packets counter query interval
interval is between 1s and 30s.
"""

port_info = {}
port_info['POLL_INTERVAL'] = poll_interval
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)

@pg_drop.command()
@click.pass_context
def enable(ctx):
""" Enable pg_drop counter query """

port_info = {}
port_info['FLEX_COUNTER_STATUS'] = ENABLE
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)

@pg_drop.command()
@click.pass_context
def disable(ctx):
""" Disable pg_drop counter query """

port_info = {}
port_info['FLEX_COUNTER_STATUS'] = DISABLE
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)

# RIF counter commands
@cli.group()
def rif():
Expand Down Expand Up @@ -212,6 +252,7 @@ def show():
rif_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'RIF')
queue_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE_WATERMARK')
pg_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_WATERMARK')
pg_drop_info = configdb.get_entry('FLEX_COUNTER_TABLE', PG_DROP)
buffer_pool_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', BUFFER_POOL_WATERMARK)

header = ("Type", "Interval (in ms)", "Status")
Expand All @@ -228,6 +269,8 @@ def show():
data.append(["QUEUE_WATERMARK_STAT", queue_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), queue_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
if pg_wm_info:
data.append(["PG_WATERMARK_STAT", pg_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
if pg_drop_info:
data.append(['PG_DROP_STAT', pg_drop_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_drop_info.get("FLEX_COUNTER_STATUS", DISABLE)])
if buffer_pool_wm_info:
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)])

Expand Down
34 changes: 34 additions & 0 deletions tests/counterpoll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
from click.testing import CliRunner
from shutil import copyfile
from utilities_common.db import Db

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand All @@ -24,6 +25,7 @@
PORT_BUFFER_DROP 60000 enable
QUEUE_WATERMARK_STAT 10000 enable
PG_WATERMARK_STAT 10000 enable
PG_DROP_STAT 10000 enable
"""

class TestCounterpoll(object):
Expand Down Expand Up @@ -53,6 +55,14 @@ def test_port_buffer_drop_interval_too_short(self):
assert result.exit_code == 2
assert expected in result.output

def test_pg_drop_interval_too_long(self):
runner = CliRunner()
result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], ["50000"])
print(result.output)
expected = "Invalid value for \"POLL_INTERVAL\": 50000 is not in the valid range of 1000 to 30000."
assert result.exit_code == 2
assert expected in result.output

@pytest.fixture(scope='class')
def _get_config_db_file(self):
sample_config_db_file = os.path.join(test_path, "counterpoll_input", "config_db.json")
Expand All @@ -75,6 +85,30 @@ def test_update_counter_config_db_status(self, status, _get_config_db_file):
for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items():
assert counter_config["FLEX_COUNTER_STATUS"] == status

@pytest.mark.parametrize("status", ["disable", "enable"])
def test_update_pg_drop_status(self, status):
runner = CliRunner()
db = Db()

result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands[status], [], obj=db.cfgdb)
print(result.exit_code, result.output)
assert result.exit_code == 0

table = db.cfgdb.get_table('FLEX_COUNTER_TABLE')
assert status == table["PG_DROP"]["FLEX_COUNTER_STATUS"]

def test_update_pg_drop_interval(self):
runner = CliRunner()
db = Db()
test_interval = "20000"

result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], [test_interval], obj=db.cfgdb)
print(result.exit_code, result.output)
assert result.exit_code == 0

table = db.cfgdb.get_table('FLEX_COUNTER_TABLE')
assert test_interval == table["PG_DROP"]["POLL_INTERVAL"]

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
4 changes: 4 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,10 @@
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|PG_DROP": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"PFC_WD|Ethernet0": {
"action": "drop",
"detection_time": "600",
Expand Down

0 comments on commit 9332b8e

Please sign in to comment.