Skip to content

Commit

Permalink
[sfputilbase]: enhance the sfputilbase for transceiver monitoring (so…
Browse files Browse the repository at this point in the history
…nic-net#9)

* [sfputilbase]: enhance the sfputilbase

[List of changes]

* add ability to only read and parse specific bytes from eeprom
* add two API to read the transceiver info and dom info which intrested by SNMP
* add a new API definiton: get_transceiver_change_event
* fix a bug: wrong 'VendorOUI' offset for sff8472

	modified:   sff8436.py
	modified:   sff8472.py
	modified:   sfputilbase.py

Signed-off-by Liu Kebo [email protected]

* fix for missing N/A

* fix review comments

* fix indent

* fix file close bug

* add tx_power support

* fix typo

* fix typo
  • Loading branch information
keboliu authored and lguohan committed Jul 30, 2018
1 parent 76ae431 commit d98600e
Show file tree
Hide file tree
Showing 3 changed files with 631 additions and 16 deletions.
237 changes: 235 additions & 2 deletions sonic_sfp/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,61 @@ class sff8436InterfaceId(sffbase):
'type' : 'bitmap',
'decode': {}}}

sfp_type = {
'type':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': type_of_transceiver}
}

vendor_name = {
'Vendor Name':
{'offset': 0,
'size': 16,
'type': 'str'}
}

vendor_pn = {
'Vendor PN':
{'offset': 0,
'size': 16,
'type': 'str'}
}

vendor_rev = {
'Vendor Rev':
{'offset': 0,
'size': 2,
'type': 'str'}
}

vendor_sn = {
'Vendor SN':
{'offset': 0,
'size': 16,
'type': 'str'}
}

qsfp_dom_capability = {
'Tx_power_support':
{'offset': 0,
'bit': 2,
'type': 'bitvalue'},
'Rx_power_support':
{'offset': 0,
'bit': 3,
'type': 'bitvalue'},
'Voltage_support':
{'offset': 0,
'bit': 4,
'type': 'bitvalue'},
'Temp_support':
{'offset': 0,
'bit': 5,
'type': 'bitvalue'}
}


def __init__(self, eeprom_raw_data=None):
self.interface_data = None
Expand All @@ -378,6 +433,24 @@ def __init__(self, eeprom_raw_data=None):
def parse(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.interface_id, eeprom_raw_data, start_pos)

def parse_sfp_type(self, type_raw_data, start_pos):
return sffbase.parse(self, self.sfp_type, type_raw_data, start_pos)

def parse_vendor_name(self, name_raw_data, start_pos):
return sffbase.parse(self, self.vendor_name, name_raw_data, start_pos)

def parse_vendor_rev(self, rev_raw_data, start_pos):
return sffbase.parse(self, self.vendor_rev, rev_raw_data, start_pos)

def parse_vendor_pn(self, pn_raw_data, start_pos):
return sffbase.parse(self, self.vendor_pn, pn_raw_data, start_pos)

def parse_vendor_sn(self, sn_raw_data, start_pos):
return sffbase.parse(self, self.vendor_sn, sn_raw_data, start_pos)

def parse_qsfp_dom_capability(self, sn_raw_data, start_pos):
return sffbase.parse(self, self.qsfp_dom_capability, sn_raw_data, start_pos)

def dump_pretty(self):
if self.interface_data == None:
print('Object not initialized, nothing to print')
Expand Down Expand Up @@ -640,7 +713,6 @@ def calc_rx_power(self, eeprom_data, offset, size):

return retval


dom_status_indicator = {'DataNotReady':
{'offset': 2,
'bit': 0,
Expand Down Expand Up @@ -857,7 +929,6 @@ def calc_rx_power(self, eeprom_data, offset, size):
'bit': 0,
'type': 'bitvalue'}}


dom_module_monitor_values = {'Temperature':
{'offset':22,
'size':2,
Expand Down Expand Up @@ -923,6 +994,148 @@ def calc_rx_power(self, eeprom_data, offset, size):
'type': 'nested',
'decode': dom_channel_monitor_values}}

# new added parser for some specific values interested by SNMP
# TO DO: find a way to reuse the definitions in above code, need refactor
revision_compliance = {
'00': 'Revision not specified',
'01': 'SFF-8436 Rev 4.8',
'02': 'SFF-8436 Rev 4.8 with extra bytes support',
'03': 'SFF-8636 Rev 1.3',
'04': 'SFF-8636 Rev 1.4',
'05': 'SFF-8636 Rev 1.5',
'06': 'SFF-8636 Rev 2.0',
'07': 'SFF-8636 Rev 2.5'
}

sfp_dom_rev = {
'dom_rev':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': revision_compliance}
}

dom_module_temperature = {
'Temperature':
{'offset': 0,
'size': 2,
'type': 'func',
'decode': {'func': calc_temperature}}
}

dom_module_voltage = {
'Vcc':
{'offset': 0,
'size': 2,
'type': 'func',
'decode': {'func': calc_voltage}}
}

dom_channel_monitor_params = {
'RX1Power':
{'offset': 0,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'RX2Power':
{'offset': 2,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'RX3Power':
{'offset': 4,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'RX4Power':
{'offset': 6,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'TX1Bias':
{'offset': 8,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX2Bias':
{'offset': 10,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX3Bias':
{'offset': 12,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX4Bias':
{'offset': 14,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}}
}

dom_channel_monitor_params_with_tx_power = {
'RX1Power':
{'offset': 0,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'RX2Power':
{'offset': 2,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'RX3Power':
{'offset': 4,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'RX4Power':
{'offset': 6,
'size': 2,
'type': 'func',
'decode': {'func': calc_rx_power}},
'TX1Bias':
{'offset': 8,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX2Bias':
{'offset': 10,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX3Bias':
{'offset': 12,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX4Bias':
{'offset': 14,
'size': 2,
'type': 'func',
'decode': {'func': calc_bias}},
'TX1Power':
{'offset': 0,
'size': 2,
'type': 'func',
'decode': {'func': calc_tx_power}},
'TX2Power':
{'offset': 2,
'size': 2,
'type': 'func',
'decode': {'func': calc_tx_power}},
'TX3Power':
{'offset': 4,
'size': 2,
'type': 'func',
'decode': {'func': calc_tx_power}},
'TX4Power':
{'offset': 6,
'size': 2,
'type': 'func',
'decode': {'func': calc_tx_power}}
}

def __init__(self, eeprom_raw_data=None, calibration_type=1):
self._calibration_type = calibration_type
Expand All @@ -936,6 +1149,26 @@ def parse(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_map, eeprom_raw_data,
start_pos)

# Parser functions for specific values interested by SNMP
def parse_sfp_dom_rev(self, type_raw_data, start_pos):
return sffbase.parse(self, self.sfp_dom_rev, type_raw_data, start_pos)

def parse_temperature(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_module_temperature, eeprom_raw_data,
start_pos)

def parse_voltage(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_module_voltage, eeprom_raw_data,
start_pos)

def parse_channel_monitor_params(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_channel_monitor_params, eeprom_raw_data,
start_pos)

def parse_channel_monitor_params_with_tx_power(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_channel_monitor_params_with_tx_power, eeprom_raw_data,
start_pos)

def dump_pretty(self):
if self.dom_data == None:
print('Object not initialized, nothing to print')
Expand Down
Loading

0 comments on commit d98600e

Please sign in to comment.