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

sonic_utilities: Support for DOM Threshold values for EEPROM dump #545

Merged
merged 4 commits into from
Jul 30, 2019
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
173 changes: 156 additions & 17 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,82 @@ qsfp_data_map = {'modelname': 'Vendor PN', 'vendor_oui': 'Vendor OUI',
'encoding': 'Encoding', 'Connector': 'Connector'
}

sfp_dom_channel_monitor_map = {'rx1power': 'RXPower', 'tx1bias': 'TXBias', 'tx1power': 'TXPower'}
sfp_dom_channel_monitor_map = {'rx1power': 'RXPower',
'tx1bias': 'TXBias',
'tx1power': 'TXPower'}

sfp_dom_channel_threshold_map = {
'txpowerhighalarm': 'TxPowerHighAlarm',
'txpowerlowalarm': 'TxPowerLowAlarm',
'txpowerhighwarning': 'TxPowerHighWarning',
'txpowerlowwarning': 'TxPowerLowWarning',
'rxpowerhighalarm': 'RxPowerHighAlarm',
'rxpowerlowalarm': 'RxPowerLowAlarm',
'rxpowerhighwarning': 'RxPowerHighWarning',
'rxpowerlowwarning': 'RxPowerLowWarning',
'txbiashighalarm': 'TxBiasHighAlarm',
'txbiaslowalarm': 'TxBiasLowAlarm',
'txbiashighwarning': 'TxBiasHighWarning',
'txbiaslowwarning': 'TxBiasLowWarning',
}

qsfp_dom_channel_threshold_map = {
'rxpowerhighalarm': 'RxPowerHighAlarm',
'rxpowerlowalarm': 'RxPowerLowAlarm',
'rxpowerhighwarning': 'RxPowerHighWarning',
'rxpowerlowwarning': 'RxPowerLowWarning',
'txbiashighalarm': 'TxBiasHighAlarm',
'txbiaslowalarm': 'TxBiasLowAlarm',
'txbiashighwarning': 'TxBiasHighWarning',
'txbiaslowwarning': 'TxBiasLowWarning',
}

dom_module_threshold_map = {
'temphighalarm': 'TempHighAlarm',
'templowalarm': 'TempLowAlarm',
'temphighwarning':'TempHighWarning',
'templowwarning': 'TempLowWarning',
'vcchighalarm': 'VccHighAlarm',
'vcclowalarm': 'VccLowAlarm',
'vcchighwarning': 'VccHighWarning',
'vcclowwarning': 'VccLowWarning'
}

qsfp_dom_channel_monitor_map = {'rx1power': 'RX1Power', 'rx2power': 'RX2Power',
'rx3power': 'RX3Power', 'rx4power': 'RX4Power',
'tx1bias': 'TX1Bias', 'tx2bias': 'TX2Bias',
'tx3bias': 'TX3Bias', 'tx4bias': 'TX4Bias',
'tx1bias': 'TX1Bias', 'tx2bias': 'TX2Bias',
'tx3bias': 'TX3Bias', 'tx4bias': 'TX4Bias',
'tx1power': 'TX1Power', 'tx2power': 'TX2Power',
'tx3power': 'TX3Power', 'tx4power': 'TX4Power'}

dom_module_monitor_map = {'temperature': 'Temperature', 'voltage': 'Vcc'}

dom_channel_threshold_unit_map = {
'txpowerhighalarm': 'dBm',
'txpowerlowalarm': 'dBm',
'txpowerhighwarning': 'dBm',
'txpowerlowwarning': 'dBm',
'rxpowerhighalarm': 'dBm',
'rxpowerlowalarm': 'dBm',
'rxpowerhighwarning': 'dBm',
'rxpowerlowwarning': 'dBm',
'txbiashighalarm': 'mA',
'txbiaslowalarm': 'mA',
'txbiashighwarning': 'mA',
'txbiaslowwarning': 'mA',
}

dom_module_threshold_unit_map = {
'temphighalarm': 'C',
'templowalarm': 'C',
'temphighwarning': 'C',
'templowwarning': 'C',
'vcchighalarm': 'Volts',
'vcclowalarm': 'Volts',
'vcchighwarning': 'Volts',
'vcclowwarning': 'Volts'
}

dom_value_unit_map = {'rx1power': 'dBm', 'rx2power': 'dBm',
'rx3power': 'dBm', 'rx4power': 'dBm',
'tx1bias': 'mA', 'tx2bias': 'mA',
Expand All @@ -70,39 +135,113 @@ class SFPShow(object):
self.sdb.connect(self.sdb.STATE_DB)
return

# Convert channel monitor values to cli output string
def convert_channel_monitor_value_to_output_string(self, sorted_key_table, dom_info_dict, channel_monitor_map):
# Convert dict values to cli output string
def format_dict_value_to_string(self, sorted_key_table,
dom_info_dict, dom_value_map,
dom_unit_map, alignment = 0):
out_put=''
ident = ' '
seperator = ": "
for key in sorted_key_table:
if dom_info_dict is not None and dom_info_dict[key] != 'N/A':
current_val = (ident + ident +
dom_value_map[key])
current_val = (current_val + seperator.rjust(len(seperator) +
alignment - len(dom_value_map[key])))
if dom_info_dict[key] == 'Unknown':
out_put = out_put + ident + ident + channel_monitor_map[key] + ': ' + dom_info_dict[key] + '\n'
current_val = (current_val + dom_info_dict[key])
else:
out_put = out_put + ident + ident + channel_monitor_map[key] + ': ' + dom_info_dict[key] + dom_value_unit_map[key] + '\n'
current_val = (current_val + dom_info_dict[key] +
dom_unit_map[key])
out_put = out_put + current_val + '\n'
return out_put

# Convert dom sensor info in DB to cli output string
def convert_dom_to_output_string(self, sfp_type, dom_info_dict):
ident = ' '
out_put_dom = ''
newline_ident = ': ' + '\n'
channel_threshold_align = 18
module_threshold_align = 15

if sfp_type.startswith('QSFP'):
out_put_dom = out_put_dom + ident + 'ChannelMonitorValues' + ': ' + '\n'
sorted_dom_channel_monitor_info_key_table = natsorted(qsfp_dom_channel_monitor_map)
out_put_channel = self.convert_channel_monitor_value_to_output_string(sorted_dom_channel_monitor_info_key_table, dom_info_dict, qsfp_dom_channel_monitor_map)
#Channel Monitor
out_put_dom = (out_put_dom + ident + 'ChannelMonitorValues'
+ newline_ident)
sorted_key_table = natsorted(qsfp_dom_channel_monitor_map)
out_put_channel = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
qsfp_dom_channel_monitor_map,
dom_value_unit_map)
out_put_dom = out_put_dom + out_put_channel

out_put_dom = out_put_dom + ident + 'ModuleMonitorValues' + ': ' + '\n'
#Channel Threshold
out_put_dom = (out_put_dom + ident + 'ChannelThresholdValues'
+ newline_ident)
sorted_key_table = natsorted(qsfp_dom_channel_threshold_map)
out_put_channel_threshold = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
qsfp_dom_channel_threshold_map,
dom_channel_threshold_unit_map,
channel_threshold_align)
out_put_dom = out_put_dom + out_put_channel_threshold

# Module Monitor
out_put_dom = (out_put_dom + ident + 'ModuleMonitorValues'
+ newline_ident)
sorted_key_table = natsorted(dom_module_monitor_map)
out_put_module = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
dom_module_monitor_map,
dom_value_unit_map)
out_put_dom = out_put_dom + out_put_module

#Module Threshold
out_put_dom = (out_put_dom + ident + 'ModuleThresholdValues'
+ newline_ident)
sorted_key_table = natsorted(dom_module_threshold_map)
out_put_module_threshold = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
dom_module_threshold_map,
dom_module_threshold_unit_map,
module_threshold_align)
out_put_dom = out_put_dom + out_put_module_threshold

else:
out_put_dom = out_put_dom + ident + 'MonitorData' + ': ' + '\n'
sorted_dom_channel_monitor_info_key_table = natsorted(sfp_dom_channel_monitor_map)
out_put_channel = self.convert_channel_monitor_value_to_output_string(sorted_dom_channel_monitor_info_key_table, dom_info_dict, sfp_dom_channel_monitor_map)
out_put_dom = out_put_dom + ident + 'MonitorData' + newline_ident
sorted_key_table = natsorted(sfp_dom_channel_monitor_map)
out_put_channel = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
sfp_dom_channel_monitor_map,
dom_value_unit_map)
out_put_dom = out_put_dom + out_put_channel

sorted_dom_module_monitor_info_key_table = natsorted(dom_module_monitor_map)
out_put_module = self.convert_channel_monitor_value_to_output_string(sorted_dom_module_monitor_info_key_table, dom_info_dict, dom_module_monitor_map)
out_put_dom = out_put_dom + out_put_module
sorted_key_table = natsorted(dom_module_monitor_map)
out_put_module = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
dom_module_monitor_map,
dom_value_unit_map)
out_put_dom = out_put_dom + out_put_module

out_put_dom = (out_put_dom + ident + 'ThresholdData'
+ newline_ident)
#Module Threshold
sorted_key_table = natsorted(dom_module_threshold_map)
out_put_module_threshold = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
dom_module_threshold_map,
dom_module_threshold_unit_map,
module_threshold_align)
out_put_dom = out_put_dom + out_put_module_threshold

#Channel Threshold
sorted_key_table = natsorted(sfp_dom_channel_threshold_map)
out_put_channel_threshold = self.format_dict_value_to_string(
sorted_key_table, dom_info_dict,
sfp_dom_channel_threshold_map,
dom_channel_threshold_unit_map,
channel_threshold_align)
out_put_dom = out_put_dom + out_put_channel_threshold

return out_put_dom

Expand Down
18 changes: 17 additions & 1 deletion sonic-utilities-tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,23 @@
"tx1power": "N/A",
"tx2power": "N/A",
"tx3power": "N/A",
"tx4power": "N/A"
"tx4power": "N/A",
"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
19 changes: 18 additions & 1 deletion sonic-utilities-tests/sfp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,27 @@ def test_sfp_eeprom_with_dom(self):
TX2Bias: 6.7500mA
TX3Bias: 6.7500mA
TX4Bias: 6.7500mA
ChannelThresholdValues:
RxPowerHighAlarm : 3.4001dBm
RxPowerHighWarning: 2.4000dBm
RxPowerLowAlarm : -13.5067dBm
RxPowerLowWarning : -9.5001dBm
TxBiasHighAlarm : 10.0000mA
TxBiasHighWarning : 9.5000mA
TxBiasLowAlarm : 0.5000mA
TxBiasLowWarning : 1.0000mA
ModuleMonitorValues:
Temperature: 30.9258C
Vcc: 3.2824Volts
ModuleThresholdValues:
TempHighAlarm : 75.0000C
TempHighWarning: 70.0000C
TempLowAlarm : -5.0000C
TempLowWarning : 0.0000C
VccHighAlarm : 3.6300Volts
VccHighWarning : 3.4650Volts
VccLowAlarm : 2.9700Volts
VccLowWarning : 3.1349Volts
"""
assert result.output == expected
Expand Down Expand Up @@ -100,4 +118,3 @@ def teardown_class(cls):
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"