Skip to content

Commit

Permalink
[chassis] Add show fabric rate command (#3297)
Browse files Browse the repository at this point in the history
What I did
Added "show fabric counters rate mbps" command.

The output of the command is

  ASIC    Link ID    Rx Data Mbps    Tx Data Mbps
------  ---------  --------------  --------------
 asic0          0               0            19.8
 asic0          1               0            19.8
 asic0          2               0            39.8
 asic0          3               0            39.8
...

  ASIC    Link ID    Rx Data Mbps    Tx Data Mbps
------  ---------  --------------  --------------
 asic1          0               0               0
 asic1          1               0               0
 asic1          2               0               0
 asic1          3               0               0
...

The HLD is at here

https://github.com/sonic-net/SONiC/blob/master/doc/voq/fabric.md
Amendment is at sonic-net/SONiC#1656
  • Loading branch information
jfeng-arista authored May 20, 2024
1 parent 556026c commit 7298cd2
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 13 deletions.
67 changes: 59 additions & 8 deletions scripts/fabricstat
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,49 @@ class FabricIsolation(FabricStat):
print(tabulate(body, header, tablefmt='simple', stralign='right'))
return

class FabricRate(FabricStat):
def rate_print(self):
# Connect to database
self.db = multi_asic.connect_to_all_dbs_for_ns(self.namespace)
# Get the set of all fabric ports
port_keys = self.db.keys(self.db.STATE_DB, FABRIC_PORT_STATUS_TABLE_PREFIX + '*')
# Create a new dictionary. The keys are the local port values in integer format.
# Only fabric ports that have remote port data are added.
port_dict = {}
for port_key in port_keys:
port_data = self.db.get_all(self.db.STATE_DB, port_key)
port_number = int(port_key.replace("FABRIC_PORT_TABLE|PORT", ""))
port_dict.update({port_number: port_data})
# Create ordered table of fabric ports.
rxRate = 0
rxData = 0
txRate = 0
txData = 0
time = 0
local_time = ""
# RX data , Tx data , Time are for testing
asic = "asic0"
if self.namespace:
asic = self.namespace
header = ["ASIC", "Link ID", "Rx Data Mbps", "Tx Data Mbps"]
body = []
for port_number in sorted(port_dict.keys()):
port_data = port_dict[port_number]
if "OLD_RX_RATE_AVG" in port_data:
rxRate = port_data["OLD_RX_RATE_AVG"]
if "OLD_RX_DATA" in port_data:
rxData = port_data["OLD_RX_DATA"]
if "OLD_TX_RATE_AVG" in port_data:
txRate = port_data["OLD_TX_RATE_AVG"]
if "OLD_TX_DATA" in port_data:
txData = port_data["OLD_TX_DATA"]
if "LAST_TIME" in port_data:
time = int(port_data["LAST_TIME"])
local_time = datetime.fromtimestamp(time)
body.append((asic, port_number, rxRate, txRate));
click.echo()
click.echo(tabulate(body, header, tablefmt='simple', stralign='right'))

def main():
global cnstat_dir
global cnstat_fqn_file_port
Expand All @@ -415,6 +458,8 @@ Examples:
fabricstat -q -n asic0
fabricstat -c
fabricstat -c -n asic0
fabricstat -s
fabricstat -s -n asic0
fabricstat -C
fabricstat -D
""")
Expand All @@ -425,6 +470,7 @@ Examples:
parser.add_argument('-e', '--errors', action='store_true', help='Display errors')
parser.add_argument('-c','--capacity',action='store_true', help='Display fabric capacity')
parser.add_argument('-i','--isolation', action='store_true', help='Display fabric ports isolation status')
parser.add_argument('-s','--rate', action='store_true', help='Display fabric counters rate')
parser.add_argument('-C','--clear', action='store_true', help='Copy & clear fabric counters')
parser.add_argument('-D','--delete', action='store_true', help='Delete saved stats')

Expand All @@ -433,6 +479,7 @@ Examples:
reachability = args.reachability
capacity_status = args.capacity
isolation_status = args.isolation
rate = args.rate
namespace = args.namespace
errors_only = args.errors

Expand All @@ -455,17 +502,21 @@ Examples:

def nsStat(ns, errors_only):
if queue:
stat = FabricQueueStat(ns)
stat = FabricQueueStat(ns)
elif reachability:
stat = FabricReachability(ns)
stat.reachability_print()
return
stat = FabricReachability(ns)
stat.reachability_print()
return
elif isolation_status:
stat = FabricIsolation(ns)
stat.isolation_print()
return
stat = FabricIsolation(ns)
stat.isolation_print()
return
elif rate:
stat = FabricRate(ns)
stat.rate_print()
return
else:
stat = FabricPortStat(ns)
stat = FabricPortStat(ns)
cnstat_dict = stat.get_cnstat_dict()
if save_fresh_stats:
stat.save_fresh_stats()
Expand Down
10 changes: 10 additions & 0 deletions show/fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ def queue(namespace):
if namespace is not None:
cmd += ['-n', str(namespace)]
clicommon.run_command(cmd)


@counters.command()
@multi_asic_util.multi_asic_click_option_namespace
def rate(namespace):
"""Show fabric counters rate"""
cmd = ['fabricstat', '-s']
if namespace is not None:
cmd += ['-n', str(namespace)]
clicommon.run_command(cmd)
53 changes: 53 additions & 0 deletions tests/fabricstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,45 @@
7 0 0 0
"""

multi_asic_fabric_rate = """\
ASIC Link ID Rx Data Mbps Tx Data Mbps
------ --------- -------------- --------------
asic0 0 0 19.8
asic0 1 0 19.8
asic0 2 0 39.8
asic0 3 0 39.8
asic0 4 0 39.8
asic0 5 0 39.8
asic0 6 0 39.3
asic0 7 0 39.3
ASIC Link ID Rx Data Mbps Tx Data Mbps
------ --------- -------------- --------------
asic1 0 0 0
asic1 1 0 0
asic1 2 0 0
asic1 3 0 0
asic1 4 0 0
asic1 5 0 0
asic1 6 0 0
asic1 7 0 0
"""

multi_asic_fabric_rate_asic0 = """\
ASIC Link ID Rx Data Mbps Tx Data Mbps
------ --------- -------------- --------------
asic0 0 0 19.8
asic0 1 0 19.8
asic0 2 0 39.8
asic0 3 0 39.8
asic0 4 0 39.8
asic0 5 0 39.8
asic0 6 0 39.3
asic0 7 0 39.3
"""

class TestFabricStat(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -348,6 +387,20 @@ def test_multi_show_fabric_isolation_asic(self):
assert return_code == 0
assert result == multi_asic_fabric_isolation_asic0

def test_mutli_show_fabric_rate(self):
return_code, result = get_result_and_return_code(['fabricstat', '-s'])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert return_code == 0
assert result == multi_asic_fabric_rate

def test_multi_show_fabric_rate_asic(self):
return_code, result = get_result_and_return_code(['fabricstat', '-s', '-n', 'asic0'])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert return_code == 0
assert result == multi_asic_fabric_rate_asic0

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
35 changes: 30 additions & 5 deletions tests/mock_tables/asic0/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,36 +256,61 @@
"FABRIC_PORT_TABLE|PORT0" : {
"STATUS": "up",
"REMOTE_MOD": "0",
"REMOTE_PORT": "79"
"REMOTE_PORT": "79",
"OLD_RX_RATE_AVG": "0",
"OLD_RX_DATA": "0",
"OLD_TX_RATE_AVG": "19.8",
"OLD_TX_DATA": "18490000000",
"LAST_TIME": "1676672799"
},
"FABRIC_PORT_TABLE|PORT1" : {
"STATUS": "down"
},
"FABRIC_PORT_TABLE|PORT2" : {
"STATUS": "up",
"REMOTE_MOD": "0",
"REMOTE_PORT": "94"
"REMOTE_PORT": "94",
"OLD_RX_RATE_AVG": "0",
"OLD_RX_DATA": "0",
"OLD_TX_RATE_AVG": "39.8",
"OLD_TX_DATA": "24490000000",
"LAST_TIME": "1676672799"
},
"FABRIC_PORT_TABLE|PORT3" : {
"STATUS": "down"
},
"FABRIC_PORT_TABLE|PORT4" : {
"STATUS": "up",
"REMOTE_MOD": "0",
"REMOTE_PORT": "85"
"REMOTE_PORT": "85",
"OLD_RX_RATE_AVG": "0",
"OLD_RX_DATA": "0",
"OLD_TX_RATE_AVG": "39.8",
"OLD_TX_DATA": "24490000000",
"LAST_TIME": "1676672799"
},
"FABRIC_PORT_TABLE|PORT5" : {
"STATUS": "down"
},
"FABRIC_PORT_TABLE|PORT6" : {
"STATUS": "up",
"REMOTE_MOD": "0",
"REMOTE_PORT": "84"
"REMOTE_PORT": "84",
"OLD_RX_RATE_AVG": "0",
"OLD_RX_DATA": "0",
"OLD_TX_RATE_AVG": "39.3",
"OLD_TX_DATA": "24170000000",
"LAST_TIME": "1676672799"
},
"FABRIC_PORT_TABLE|PORT7" : {
"STATUS": "up",
"REMOTE_MOD": "0",
"REMOTE_PORT": "93"
"REMOTE_PORT": "93",
"OLD_RX_RATE_AVG": "0",
"OLD_RX_DATA": "0",
"OLD_TX_RATE_AVG": "39.3",
"OLD_TX_DATA": "24190000000",
"LAST_TIME": "1676672799"
},
"CHASSIS_MIDPLANE_TABLE|LINE-CARD0": {
"ip_address": "127.0.0.1",
Expand Down

0 comments on commit 7298cd2

Please sign in to comment.