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

[sfpshow]: display eeprom data in table format #1030

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ This command displays information for all the interfaces for the transceiver req

- Usage:
```
show interfaces transceiver (eeprom [-d|--dom] | lpmode | presence) [<interface_name>]
show interfaces transceiver (eeprom [-d|--dom] [-t|--table] | lpmode | presence) [<interface_name>]
```

- Example (Decode and display information stored on the EEPROM of SFP transceiver connected to Ethernet0):
Expand Down
80 changes: 78 additions & 2 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ dom_value_unit_map = {'rx1power': 'dBm', 'rx2power': 'dBm',
'tx3power': 'dBm', 'tx4power': 'dBm',
'temperature': 'C', 'voltage': 'Volts'}

table_header_info = ['Interface', 'Identifier',
'Connector', 'Vendor Name',
'Model Name', 'Serial Number',
'Nominal Bit Rate(100Mbs)']

table_header_dom = ['Interface', 'Lane Number',
'Temp(C)', 'Voltage(V)',
Copy link
Collaborator

@keboliu keboliu Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a concern about the way you handle the temperature, it's not some sensor that monitored per lane, here you added it to each lane, it's kind of misleading. The same comment goes to the voltage.

'Current(mA)', 'Tx Power(dBm)',
'Rx Power(dBm)']


class SFPShow(object):
Expand Down Expand Up @@ -291,6 +300,50 @@ class SFPShow(object):

return out_put

# Convert sfp dom sensor info to cli output string
def display_dom_val(self, input_dict, val_key, low_key, high_key):
val = input_dict.get(val_key)
low = input_dict.get(low_key)
high = input_dict.get(high_key)
return '{0} [low={1},high={2}]'.format(val, low, high) if val else 'N/A'

# Convert sfp info and dom sensor info in DB to output tuple
def convert_interface_sfp_info_to_tuple(self, state_db, interface_name, dump_dom):
out_put = []
null = 'N/A'

presence = self.sdb.exists(
self.sdb.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name))
sfp_info_dict = state_db.get_all(
state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name)) if presence else {}

if dump_dom:
dom_info_dict = state_db.get_all(
state_db.STATE_DB, 'TRANSCEIVER_DOM_SENSOR|{}'.format(interface_name)) if presence else {}

lanes = self.adb.get(
self.adb.APPL_DB, "PORT_TABLE:{}".format(interface_name), "lanes")
num_of_lane = len(lanes.split(",")) if lanes else 1
for lane in range(1, num_of_lane+1):
port = interface_name if lane == 1 else ""
out_put.append((port,
"Lane {}".format(lane),
self.display_dom_val(dom_info_dict, 'temperature', 'templowwarning', 'temphighalarm'),
self.display_dom_val(dom_info_dict, 'voltage', 'txbiaslowwarning', 'txbiashighwarning'),
self.display_dom_val(dom_info_dict, 'tx{}bias'.format(lane), 'txbiaslowwarning', 'txbiashighwarning'),
self.display_dom_val(dom_info_dict, 'tx{}power'.format(lane), 'txpowerlowwarning', 'txpowerhighwarning'),
self.display_dom_val(dom_info_dict, 'rx{}power'.format(lane), 'rxpowerlowwarning', 'rxpowerhighwarning')
))
else:
out_put.append((interface_name,
sfp_info_dict.get('type', null),
sfp_info_dict.get('connector', null),
sfp_info_dict.get('manufacturer', null),
sfp_info_dict.get('model', null),
sfp_info_dict.get('serial', null),
sfp_info_dict.get('nominal_bit_rate', null)))
return out_put

def display_eeprom(self, interfacename, dump_dom):
out_put = ''

Expand All @@ -316,6 +369,25 @@ class SFPShow(object):

click.echo(out_put)

def display_eeprom_table(self, interfacename, dump_dom):
table = []
header = table_header_info if not dump_dom else table_header_dom

if interfacename is not None:
table += self.convert_interface_sfp_info_to_tuple(
self.sdb, interfacename, dump_dom)

else:
port_table_keys = self.adb.keys(self.adb.APPL_DB, "PORT_TABLE:*")
sorted_table_keys = natsorted(port_table_keys)
for i in sorted_table_keys:
interface = re.split(':', i, maxsplit=1)[-1].strip()
if interface and interface.startswith('Ethernet'):
table += self.convert_interface_sfp_info_to_tuple(
self.sdb, interface, dump_dom)

click.echo(tabulate(table, header, tablefmt="simple", stralign='left'))

def display_presence(self, interfacename):
port_table = []
header = ['Port', 'Presence']
Expand Down Expand Up @@ -350,9 +422,13 @@ def cli():
@cli.command()
@click.option('-p', '--port', metavar='<port_name>', help="Display SFP EEPROM data for port <port_name> only")
@click.option('-d', '--dom', 'dump_dom', is_flag=True, help="Also display Digital Optical Monitoring (DOM) data")
def eeprom(port, dump_dom):
@click.option('-t', '--table', 'table', is_flag=True, help="Display SFP EEPROM data in table format")
def eeprom(port, dump_dom, table):
sfp = SFPShow()
sfp.display_eeprom(port, dump_dom)
if table:
sfp.display_eeprom_table(port, dump_dom)
else:
sfp.display_eeprom(port, dump_dom)

# 'presence' subcommand
@cli.command()
Expand Down
6 changes: 5 additions & 1 deletion show/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ def transceiver():
@transceiver.command()
@click.argument('interfacename', required=False)
@click.option('-d', '--dom', 'dump_dom', is_flag=True, help="Also display Digital Optical Monitoring (DOM) data")
@click.option('-t', '--table', 'table', is_flag=True, help="Display SFP EEPROM data in table format")
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def eeprom(interfacename, dump_dom, verbose):
def eeprom(interfacename, dump_dom, table, verbose):
"""Show interface transceiver EEPROM information"""

ctx = click.get_current_context()
Expand All @@ -295,6 +296,9 @@ def eeprom(interfacename, dump_dom, verbose):
if dump_dom:
cmd += " --dom"

if table:
cmd += " --table"

if interfacename is not None:
interfacename = try_convert_interfacename_from_alias(ctx, interfacename)

Expand Down
39 changes: 39 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
"nominal_bit_rate": "255",
"application_advertisement": "N/A"
},
"TRANSCEIVER_INFO|Ethernet32": {
"serial": "CRCL17490BGUP",
"manufacturer": "INTEL CORP",
"model": "SPTSBP2CLCKS",
"connector": "LC",
"nominal_bit_rate": "255"
},
"TRANSCEIVER_DOM_SENSOR|Ethernet0": {
"temperature": "30.9258",
"voltage": "3.2824",
Expand Down Expand Up @@ -49,6 +56,38 @@
"vcclowalarm": "2.9700",
"vcclowwarning": "3.1349"
},
"TRANSCEIVER_DOM_SENSOR|Ethernet32": {
"temperature": "32.1055",
"voltage": "3.3769",
"rx1power": "0.4961",
"rx2power": "0.3782",
"rx3power": "-0.0860",
"rx4power": "0.5918",
"tx1bias": "6.7500",
"tx2bias": "6.7500",
"tx3bias": "6.7500",
"tx4bias": "6.7500",
"tx1power": "0.4961",
"tx2power": "0.3782",
"tx3power": "0.5918",
"tx4power": "-0.1909",
"rxpowerhighalarm": "3.4001",
"rxpowerhighwarning": "2.4000",
"rxpowerlowalarm": "-13.5067",
"rxpowerlowwarning": "-9.5001",
"txbiashighalarm": "10.0000",
"txbiashighwarning": "9.5000",
"txbiaslowalarm": "0.5000",
"txbiaslowwarning": "1.0000",
"temphighalarm": "75.0000",
"temphighwarning": "70.0000",
"templowalarm": "-5.0000",
"templowwarning": "0.0000",
"vcchighalarm": "3.6300",
"vcchighwarning": "3.4650",
"vcclowalarm": "2.9700",
"vcclowwarning": "3.1349"
},
"CHASSIS_INFO|chassis 1": {
"psu_num": "2"
},
Expand Down
27 changes: 27 additions & 0 deletions tests/sfp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@
Vendor SN: MT1706FT02064
"""

test_sfp_eeprom_table_output = """\
Interface Identifier Connector Vendor Name Model Name Serial Number Nominal Bit Rate(100Mbs)
----------- --------------- ---------------------- ------------- ------------ --------------- --------------------------
Ethernet0 QSFP28 or later No separable connector Mellanox MFA1A00-C003 MT1706FT02064 255
"""

test_sfp_eeprom_with_dom_table_output = """\
Interface Lane Number Temp(C) Voltage(V) Current(mA) Tx Power(dBm) Rx Power(dBm)
----------- ------------- --------------------------------- ------------------------------- ------------------------------- ---------------------------- ---------------------------------
Ethernet32 Lane 1 32.1055 [low=0.0000,high=75.0000] 3.3769 [low=1.0000,high=9.5000] 6.7500 [low=1.0000,high=9.5000] 0.4961 [low=None,high=None] 0.4961 [low=-9.5001,high=2.4000]
Lane 2 32.1055 [low=0.0000,high=75.0000] 3.3769 [low=1.0000,high=9.5000] 6.7500 [low=1.0000,high=9.5000] 0.3782 [low=None,high=None] 0.3782 [low=-9.5001,high=2.4000]
Lane 3 32.1055 [low=0.0000,high=75.0000] 3.3769 [low=1.0000,high=9.5000] 6.7500 [low=1.0000,high=9.5000] 0.5918 [low=None,high=None] -0.0860 [low=-9.5001,high=2.4000]
Lane 4 32.1055 [low=0.0000,high=75.0000] 3.3769 [low=1.0000,high=9.5000] 6.7500 [low=1.0000,high=9.5000] -0.1909 [low=None,high=None] 0.5918 [low=-9.5001,high=2.4000]
"""

class TestSFP(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -111,6 +126,12 @@ def test_sfp_eeprom_with_dom(self):
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_sfp_eeprom_with_dom_output

def test_sfp_eeprom_with_dom_table(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ["Ethernet32 -dt"])
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_sfp_eeprom_with_dom_table_output

def test_sfp_eeprom(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ["Ethernet0"])
Expand All @@ -122,6 +143,12 @@ def test_sfp_eeprom(self):
expected = "Ethernet200: SFP EEPROM Not detected"
assert result_lines == expected

def test_sfp_eeprom_table(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ["Ethernet0 -t"])
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_sfp_eeprom_table_output

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down