Skip to content

Commit

Permalink
[xcvrd] Store mux_cable telemetry data in State DB (#148)
Browse files Browse the repository at this point in the history
* [xcvrd] adding mux_cable data for sonic-telemetry inside state db

Summary:
This PR provides the necessary infrastructure to initialize the mux_cable info and static tables and post them within state db
as part of xcvrd. The data is posted every 60 secs and streaming telemetry can utilize this info. 
Approach

Added changes in the sonic_xcvrd directory of sonic-platform-daemons
What is the motivation for this PR?

To add the necessary infrastructure for Credo Y cable support for posting streaming telemetry data inside state-db

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 authored Feb 18, 2021
1 parent 93cac0a commit 068bccc
Show file tree
Hide file tree
Showing 3 changed files with 681 additions and 22 deletions.
110 changes: 105 additions & 5 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ def test_xcvrd_helper_class_run(self):
def test_post_port_dom_info_to_db(self):
logical_port_name = "Ethernet0"
stop_event = threading.Event()
dom_tbl = Table("state_db", "dom_info_tbl")
dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE)
post_port_dom_info_to_db(logical_port_name, dom_tbl, stop_event)

@patch('xcvrd.xcvrd.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
def test_del_port_sfp_dom_info_from_db(self):
logical_port_name = "Ethernet0"
stop_event = threading.Event()
dom_tbl = Table("state_db", "dom_info_tbl")
init_tbl = Table("state_db", "init_info_tbl")
dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE)
init_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE)
del_port_sfp_dom_info_from_db(logical_port_name, init_tbl, dom_tbl)

@patch('xcvrd.xcvrd.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_del_port_sfp_dom_info_from_db(self):
def test_post_port_dom_threshold_info_to_db(self):
logical_port_name = "Ethernet0"
stop_event = threading.Event()
dom_tbl = Table("state_db", "dom_info_tbl")
dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE)
post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl, stop_event)

@patch('xcvrd.xcvrd.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
Expand All @@ -132,7 +132,7 @@ def test_post_port_dom_threshold_info_to_db(self):
def test_post_port_sfp_info_to_db(self):
logical_port_name = "Ethernet0"
stop_event = threading.Event()
dom_tbl = Table("state_db", "dom_info_tbl")
dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE)
transceiver_dict = {}
post_port_sfp_info_to_db(logical_port_name, dom_tbl, transceiver_dict, stop_event)

Expand Down Expand Up @@ -215,3 +215,103 @@ def test_post_port_sfp_dom_info_to_db(self):
def test_init_port_sfp_status_tbl(self):
stop_event = threading.Event()
init_port_sfp_status_tbl(stop_event)

@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
@patch('y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
@patch('y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
'mux_direction': 'self',
'manual_switch_count': '7',
'auto_switch_count': '71',
'link_status_self': 'up',
'link_status_peer': 'up',
'link_status_nic': 'up',
'nic_lane1_active': 'True',
'nic_lane2_active': 'True',
'nic_lane3_active': 'True',
'nic_lane4_active': 'True',
'self_eye_height_lane1': '500',
'self_eye_height_lane2': '510',
'peer_eye_height_lane1': '520',
'peer_eye_height_lane2': '530',
'nic_eye_height_lane1': '742',
'nic_eye_height_lane2': '750',
'internal_temperature': '28',
'internal_voltage': '3.3',
'nic_temperature': '20',
'nic_voltage': '2.7',
'build_slot1_nic': 'MS',
'build_slot2_nic': 'MS',
'version_slot1_nic': '1.7',
'version_slot2_nic': '1.7',
'run_slot1_nic': 'True',
'run_slot2_nic': 'False',
'commit_slot1_nic': 'True',
'commit_slot2_nic': 'False',
'empty_slot1_nic': 'True',
'empty_slot2_nic': 'False',
'build_slot1_tor1': 'MS',
'build_slot2_tor1': 'MS',
'version_slot1_tor1': '1.7',
'version_slot2_tor1': '1.7',
'run_slot1_tor1': 'True',
'run_slot2_tor1': 'False',
'commit_slot1_tor1': 'True',
'commit_slot2_tor1': 'False',
'empty_slot1_tor1': 'True',
'empty_slot2_tor1': 'False',
'build_slot1_tor2': 'MS',
'build_slot2_tor2': 'MS',
'version_slot1_tor2': '1.7',
'version_slot2_tor2': '1.7',
'run_slot1_tor2': 'True',
'run_slot2_tor2': 'False',
'commit_slot1_tor2': 'True',
'commit_slot2_tor2': 'False',
'empty_slot1_tor2': 'True',
'empty_slot2_tor2': 'False'}))
def test_post_port_mux_info_to_db(self):
logical_port_name = "Ethernet0"
mux_tbl = Table("STATE_DB", y_cable_helper.MUX_CABLE_INFO_TABLE)
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl)
assert(rc != -1)

@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
@patch('y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
@patch('y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self',
'nic_lane1_precursor1': '1',
'nic_lane1_precursor2': '-7',
'nic_lane1_maincursor': '-1',
'nic_lane1_postcursor1': '11',
'nic_lane1_postcursor2': '11',
'nic_lane2_precursor1': '12',
'nic_lane2_precursor2': '7',
'nic_lane2_maincursor': '7',
'nic_lane2_postcursor1': '7',
'nic_lane2_postcursor2': '7',
'tor_self_lane1_precursor1': '17',
'tor_self_lane1_precursor2': '17',
'tor_self_lane1_maincursor': '17',
'tor_self_lane1_postcursor1': '17',
'tor_self_lane1_postcursor2': '17',
'tor_self_lane2_precursor1': '7',
'tor_self_lane2_precursor2': '7',
'tor_self_lane2_maincursor': '7',
'tor_self_lane2_postcursor1': '7',
'tor_self_lane2_postcursor2': '7',
'tor_peer_lane1_precursor1': '7',
'tor_peer_lane1_precursor2': '7',
'tor_peer_lane1_maincursor': '17',
'tor_peer_lane1_postcursor1': '7',
'tor_peer_lane1_postcursor2': '17',
'tor_peer_lane2_precursor1': '7',
'tor_peer_lane2_precursor2': '7',
'tor_peer_lane2_maincursor': '17',
'tor_peer_lane2_postcursor1': '7',
'tor_peer_lane2_postcursor2': '17'}))
def test_post_port_mux_static_info_to_db(self):
logical_port_name = "Ethernet0"
mux_tbl = Table("STATE_DB", y_cable_helper.MUX_CABLE_STATIC_INFO_TABLE)
rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl)
assert(rc != -1)
11 changes: 7 additions & 4 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,12 @@ def __init__(self):
self.task_thread = None
self.task_stopping_event = threading.Event()

def task_worker(self):
def task_worker(self, y_cable_presence):
helper_logger.log_info("Start DOM monitoring loop")

# Connect to STATE_DB and create transceiver dom info table
state_db, dom_tbl, status_tbl = {}, {}, {}
mux_tbl = {}

# Get the namespaces in the platform
namespaces = multi_asic.get_front_end_namespaces()
Expand All @@ -859,14 +860,16 @@ def task_worker(self):
if not detect_port_in_error_status(logical_port_name, status_tbl[asic_index]):
post_port_dom_info_to_db(logical_port_name, dom_tbl[asic_index], self.task_stopping_event)
post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl[asic_index], self.task_stopping_event)
if y_cable_presence[0] is True:
y_cable_helper.check_identifier_presence_and_update_mux_info_entry(state_db, mux_tbl, asic_index, logical_port_name)

helper_logger.log_info("Stop DOM monitoring loop")

def task_run(self):
def task_run(self, y_cable_presence):
if self.task_stopping_event.is_set():
return

self.task_thread = threading.Thread(target=self.task_worker)
self.task_thread = threading.Thread(target=self.task_worker, args=(y_cable_presence,))
self.task_thread.start()

def task_stop(self):
Expand Down Expand Up @@ -1325,7 +1328,7 @@ def run(self):

# Start the dom sensor info update thread
dom_info_update = DomInfoUpdateTask()
dom_info_update.task_run()
dom_info_update.task_run(self.y_cable_presence)

# Start the sfp state info update process
sfp_state_update = SfpStateUpdateTask()
Expand Down
Loading

0 comments on commit 068bccc

Please sign in to comment.