Skip to content

Commit

Permalink
[xcvrd] support for integrating Credo Y cable Ports initialization an…
Browse files Browse the repository at this point in the history
…d status updates with xcvrd. (sonic-net#105)

* [xcvrd] support for integrating y cable within xcvrd

This PR provides the necessary infrastructure to initialize the Y cable Ports inside SONIC with xcvrd as the platform daemon.
Particularly there are two parts of integration:

While xcvrd initializes , there is within config_db for Y cable presence. This is done by checking the key-value pairs for
presence of mux_cable identifier as a key. Once a Y cable is found to be attached to a port, State DB is updated with
the corresponding data for the Y cable Port.

Once the init process is done, and a Y cable presence is established, A thread is run to periodically monitor changes
to APPL DB MUX_CABLE_COMMAND table for updates, and also one that periodically checks for a change events,  If an update is found, the corresponding changes are done on MUX using
sonic_y_cable package and corresponding changes are updated in STATE_DB

What is the motivation for this PR?
To add the necessary infrastructure for Credo Y cable integration within SONIC

How did you do it?
Added the necessary changes and a new xcvrd_utilities sub directory for utilities of y_cable code.
Reorganized the setup.py and sonix-xcvrd code to this form

sonic-xcvrd/setup.py
sonic-xcvrd/src/init.py
sonic-xcvrd/scripts/xcvrd → sonic-xcvrd/src/xcvrd.py
sonic-xcvrd/src/xcvrd_utilities/init.py
sonic-xcvrd/src/xcvrd_utilities/y_cable_helper.py

Signed-off-by: vaibhav-dahiya <[email protected]>
  • Loading branch information
vdahiya12 authored Nov 9, 2020
1 parent 600d043 commit 850d0c6
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 7 deletions.
8 changes: 5 additions & 3 deletions sonic-xcvrd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
url = 'https://github.com/Azure/sonic-platform-daemons',
maintainer = 'Kebo Liu',
maintainer_email = '[email protected]',
scripts = [
'scripts/xcvrd',
],
entry_points = {
'console_scripts': [
'xcvrd = src.xcvrd:main',
]
},
install_requires = [
# NOTE: This package also requires swsscommon, but it is not currently installed as a wheel
'enum34; python_version < "3.4"',
Expand Down
Empty file added sonic-xcvrd/src/__init__.py
Empty file.
32 changes: 28 additions & 4 deletions sonic-xcvrd/scripts/xcvrd → sonic-xcvrd/src/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from sonic_py_common import daemon_base, device_info, logger
from sonic_py_common import multi_asic
from swsscommon import swsscommon

from .xcvrd_utilities import y_cable_helper
except ImportError, e:
raise ImportError (str(e) + " - required module not found")

Expand Down Expand Up @@ -854,7 +856,7 @@ def _mapping_event_from_change_event(self, status, port_dict):
helper_logger.log_debug("mapping from {} {} to {}".format(status, port_dict, event))
return event

def task_worker(self, stopping_event, sfp_error_event):
def task_worker(self, stopping_event, sfp_error_event, y_cable_presence):
helper_logger.log_info("Start SFP monitoring loop")

transceiver_dict = {}
Expand Down Expand Up @@ -1042,6 +1044,9 @@ def task_worker(self, stopping_event, sfp_error_event):
# SFP return unkown event, just ignore for now.
helper_logger.log_warning("Got unknown event {}, ignored".format(value))
continue

# Since ports could be connected to a mux cable, if there is a change event process the change for being on a Y cable Port
y_cable_helper.change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, stopping_event)
else:
next_state = STATE_EXIT
elif event == SYSTEM_FAIL:
Expand Down Expand Up @@ -1079,11 +1084,11 @@ def task_worker(self, stopping_event, sfp_error_event):

helper_logger.log_info("Stop SFP monitoring loop")

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

self.task_process = multiprocessing.Process(target=self.task_worker,args=(self.task_stopping_event, sfp_error_event))
self.task_process = multiprocessing.Process(target=self.task_worker,args=(self.task_stopping_event, sfp_error_event, y_cable_presence))
self.task_process.start()

def task_stop(self):
Expand All @@ -1102,6 +1107,7 @@ def __init__(self, log_identifier):
self.num_asics = multi_asic.get_num_asics()
self.stop_event = threading.Event()
self.sfp_error_event = multiprocessing.Event()
self.y_cable_presence = [False]

# Signal handler
def signal_handler(self, sig, frame):
Expand Down Expand Up @@ -1231,6 +1237,9 @@ def init(self):
self.log_info("Init port sfp status table")
init_port_sfp_status_tbl(self.stop_event)

# Init port y_cable status table
y_cable_helper.init_ports_status_for_y_cable(platform_sfputil, platform_chassis, self.y_cable_presence, self.stop_event)

# Deinitialize daemon
def deinit(self):
self.log_info("Start daemon deinit...")
Expand All @@ -1247,6 +1256,10 @@ def deinit(self):
del_port_sfp_dom_info_from_db(logical_port_name, self.int_tbl[asic_index], self.dom_tbl[asic_index])
delete_port_from_status_table(logical_port_name, self.status_tbl[asic_index])

if self.y_cable_presence[0] is True:
y_cable_helper.delete_ports_status_for_y_cable()


# Run daemon
def run(self):
self.log_info("Starting up...")
Expand All @@ -1260,7 +1273,13 @@ def run(self):

# Start the sfp state info update process
sfp_state_update = SfpStateUpdateTask()
sfp_state_update.task_run(self.sfp_error_event)
sfp_state_update.task_run(self.sfp_error_event, self.y_cable_presence)

# Start the Y-cable state info update process if Y cable presence established
y_cable_state_update = None
if self.y_cable_presence[0] is True:
y_cable_state_update = y_cable_helper.YCableTableUpdateTask()
y_cable_state_update.task_run()

# Start main loop
self.log_info("Start daemon main loop")
Expand All @@ -1277,6 +1296,10 @@ def run(self):
# Stop the sfp state info update process
sfp_state_update.task_stop()

# Stop the Y-cable state info update process
if self.y_cable_presence[0] is True:
y_cable_state_update.task_stop()

# Start daemon deinitialization sequence
self.deinit()

Expand All @@ -1289,6 +1312,7 @@ def run(self):
# Main =========================================================================
#

# This is our main entry point for xcvrd script
def main():
xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER)
xcvrd.run()
Expand Down
Empty file.
Loading

0 comments on commit 850d0c6

Please sign in to comment.