Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI][PFCWD][Multi-ASIC] Added multi ASIC support to 'pfcwd' CLI #1102

Merged
merged 5 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
661 changes: 419 additions & 242 deletions pfcwd/main.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
'mock_tables/*.json',
'mock_tables/asic0/*.json',
'mock_tables/asic1/*.json',
'filter_fdb_input/*']
'filter_fdb_input/*',
'pfcwd_input/*']
},
scripts=[
'scripts/aclshow',
Expand Down
14 changes: 10 additions & 4 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,20 +943,26 @@ def pfcwd():
pass

@pfcwd.command()
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def config(verbose):
def config(namespace, display, verbose):
"""Show pfc watchdog config"""

cmd = "pfcwd show config"
cmd = "pfcwd show config -d {}".format(display)
if namespace is not None:
cmd += " -n {}".format(namespace)

run_command(cmd, display_cmd=verbose)

@pfcwd.command()
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def stats(verbose):
def stats(namespace, display, verbose):
"""Show pfc watchdog stats"""

cmd = "pfcwd show stats"
cmd = "pfcwd show stats -d {}".format(display)
if namespace is not None:
cmd += " -n {}".format(namespace)

run_command(cmd, display_cmd=verbose)

Expand Down
26 changes: 25 additions & 1 deletion sonic-utilities-tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,29 @@
},
"PORTCHANNEL_MEMBER|PortChannel4001|Ethernet-BP4": {
"NULL": "NULL"
},
"PFC_WD|Ethernet0": {
"action": "drop",
"detection_time": "200",
"restoration_time": "200"
},
"PFC_WD|Ethernet4": {
"action": "drop",
"detection_time": "200",
"restoration_time": "200"
},
"PFC_WD|Ethernet-BP0": {
"action": "drop",
"detection_time": "200",
"restoration_time": "200"
},
"PFC_WD|Ethernet-BP4": {
"action": "drop",
"detection_time": "200",
"restoration_time": "200"
},
"PFC_WD|GLOBAL": {
"BIG_RED_SWITCH": "enable",
"POLL_INTERVAL": "199"
}
}
}
1,410 changes: 1,410 additions & 0 deletions sonic-utilities-tests/mock_tables/asic0/counters_db.json

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion sonic-utilities-tests/mock_tables/asic1/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,19 @@
},
"PORTCHANNEL_MEMBER|PortChannel4009|Ethernet-BP260" : {
"NULL": "NULL"
},
"PFC_WD|Ethernet-BP256": {
"action": "drop",
"detection_time": "200",
"restoration_time": "200"
},
"PFC_WD|Ethernet-BP260": {
"action": "drop",
"detection_time": "200",
"restoration_time": "200"
},
"PFC_WD|GLOBAL": {
"BIG_RED_SWITCH": "enable",
"POLL_INTERVAL": "199"
}
}
}
2 changes: 1 addition & 1 deletion sonic-utilities-tests/mock_tables/asic1/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -870,4 +870,4 @@
"COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": {
"DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE"
}
}
}
18 changes: 18 additions & 0 deletions sonic-utilities-tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,24 @@
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"PFC_WD|Ethernet0": {
"action": "drop",
"detection_time": "600",
"restoration_time": "600"
},
"PFC_WD|Ethernet4": {
"action": "drop",
"detection_time": "600",
"restoration_time": "600"
},
"PFC_WD|Ethernet8": {
"action": "drop",
"detection_time": "600",
"restoration_time": "600"
},
"PFC_WD|GLOBAL": {
"POLL_INTERVAL": "600"
}
}

59 changes: 59 additions & 0 deletions sonic-utilities-tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,71 @@
"Ethernet0": "oid:0x1000000000002",
"Ethernet4": "oid:0x1000000000004",
"Ethernet8": "oid:0x1000000000006"
},
"COUNTERS_QUEUE_NAME_MAP": {
"Ethernet0:3": "oid:0x1500000000035b",
"Ethernet4:3": "oid:0x15000000000383",
"Ethernet8:4": "oid:0x150000000003ac"
},
"COUNTERS_DEBUG_NAME_PORT_STAT_MAP": {
"DEBUG_0": "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE",
"DEBUG_2": "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"
},
"COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": {
"DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE"
},
"COUNTERS:oid:0x1500000000035b": {
"PFC_WD_ACTION": "drop",
"PFC_WD_DETECTION_TIME": "600000",
"PFC_WD_DETECTION_TIME_LEFT": "600000",
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "1",
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "0",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
"PFC_WD_RESTORATION_TIME": "600000",
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
"PFC_WD_STATUS": "stormed"
},
"COUNTERS:oid:0x15000000000383": {
"PFC_WD_ACTION": "drop",
"PFC_WD_DETECTION_TIME": "600000",
"PFC_WD_DETECTION_TIME_LEFT": "600000",
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "2",
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "2",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
"PFC_WD_RESTORATION_TIME": "600000",
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
"PFC_WD_STATUS": "operational"
},
"COUNTERS:oid:0x150000000003ac": {
"PFC_WD_ACTION": "drop",
"PFC_WD_DETECTION_TIME": "600000",
"PFC_WD_DETECTION_TIME_LEFT": "600000",
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "3",
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "2",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
"PFC_WD_RESTORATION_TIME": "600000",
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
"PFC_WD_STATUS": "stormed"
}
}
28 changes: 19 additions & 9 deletions sonic-utilities-tests/pfcstat_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import imp
import os
import shutil

Expand Down Expand Up @@ -59,7 +58,8 @@
Ethernet-BP256 400 201 202 203 204 205 206 207
Ethernet-BP260 400 401 402 403 404 405 406 407
"""
show_pfc_counters_asic0 = """\

show_pfc_counters_all_asic = """\
Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7
------------ ------ ------ ------ ------ ------ ------ ------ ------
Ethernet0 400 201 202 203 204 205 206 207
Expand Down Expand Up @@ -107,14 +107,20 @@
"""


def del_cached_stats():
uid = str(os.getuid())
cnstat_dir = os.path.join(os.sep, "tmp", "pfcstat-{}".format(uid))
shutil.rmtree(cnstat_dir, ignore_errors=True, onerror=None)


def pfc_clear(expected_output):
uid = str(os.getuid())
cnstat_dir = os.path.join(os.sep, "tmp", "pfcstat-{}".format(uid))
shutil.rmtree(cnstat_dir, ignore_errors=True, onerror=None)
del_cached_stats()

get_result_and_return_code('pfcstat -c')

# verify that files are created with stats
uid = str(os.getuid())
cnstat_dir = os.path.join(os.sep, "tmp", "pfcstat-{}".format(uid))
cnstat_fqn_file_rx = "{}rx".format(uid)
cnstat_fqn_file_tx = "{}tx".format(uid)
file_list = [cnstat_fqn_file_tx, cnstat_fqn_file_rx]
Expand All @@ -131,7 +137,7 @@ def pfc_clear(expected_output):
# this will also verify the saved counters are correct since the
# expected counters are all '0s'
assert result_stat == expected
shutil.rmtree(cnstat_dir, ignore_errors=True, onerror=None)
del_cached_stats()


class TestPfcstat(object):
Expand All @@ -140,6 +146,7 @@ def setup_class(cls):
print("SETUP")
os.environ["PATH"] += os.pathsep + scripts_path
os.environ["UTILITIES_UNIT_TESTING"] = "2"
del_cached_stats()

def test_pfc_counters(self):
runner = CliRunner()
Expand All @@ -161,6 +168,8 @@ def teardown_class(cls):
os.environ["PATH"].split(os.pathsep)[:-1]
)
os.environ["UTILITIES_UNIT_TESTING"] = "0"
del_cached_stats()



class TestMultiAsicPfcstat(object):
Expand All @@ -170,7 +179,7 @@ def setup_class(cls):
os.environ["PATH"] += os.pathsep + scripts_path
os.environ["UTILITIES_UNIT_TESTING"] = "2"
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
imp.reload(show)
del_cached_stats()

def test_pfc_counters_all(self):
runner = CliRunner()
Expand All @@ -197,9 +206,9 @@ def test_pfc_counters_asic_all(self):
_, result = get_result_and_return_code(
'pfcstat -n asic0 -s all'
)
assert result == show_pfc_counters_asic0
assert result == show_pfc_counters_all_asic

def test_pfc_clear(self):
def test_masic_pfc_clear(self):
pfc_clear(show_pfc_counters_msaic_output_diff)

@classmethod
Expand All @@ -210,3 +219,4 @@ def teardown_class(cls):
)
os.environ["UTILITIES_UNIT_TESTING"] = "0"
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = ""
del_cached_stats()
Empty file.
Loading