Skip to content

Commit 850d0c6

Browse files
authored
[xcvrd] support for integrating Credo Y cable Ports initialization and 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]>
1 parent 600d043 commit 850d0c6

File tree

5 files changed

+535
-7
lines changed

5 files changed

+535
-7
lines changed

sonic-xcvrd/setup.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
url = 'https://github.com/Azure/sonic-platform-daemons',
1111
maintainer = 'Kebo Liu',
1212
maintainer_email = '[email protected]',
13-
scripts = [
14-
'scripts/xcvrd',
15-
],
13+
entry_points = {
14+
'console_scripts': [
15+
'xcvrd = src.xcvrd:main',
16+
]
17+
},
1618
install_requires = [
1719
# NOTE: This package also requires swsscommon, but it is not currently installed as a wheel
1820
'enum34; python_version < "3.4"',

sonic-xcvrd/src/__init__.py

Whitespace-only changes.

sonic-xcvrd/scripts/xcvrd renamed to sonic-xcvrd/src/xcvrd.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from sonic_py_common import daemon_base, device_info, logger
2121
from sonic_py_common import multi_asic
2222
from swsscommon import swsscommon
23+
24+
from .xcvrd_utilities import y_cable_helper
2325
except ImportError, e:
2426
raise ImportError (str(e) + " - required module not found")
2527

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

857-
def task_worker(self, stopping_event, sfp_error_event):
859+
def task_worker(self, stopping_event, sfp_error_event, y_cable_presence):
858860
helper_logger.log_info("Start SFP monitoring loop")
859861

860862
transceiver_dict = {}
@@ -1042,6 +1044,9 @@ def task_worker(self, stopping_event, sfp_error_event):
10421044
# SFP return unkown event, just ignore for now.
10431045
helper_logger.log_warning("Got unknown event {}, ignored".format(value))
10441046
continue
1047+
1048+
# 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
1049+
y_cable_helper.change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, stopping_event)
10451050
else:
10461051
next_state = STATE_EXIT
10471052
elif event == SYSTEM_FAIL:
@@ -1079,11 +1084,11 @@ def task_worker(self, stopping_event, sfp_error_event):
10791084

10801085
helper_logger.log_info("Stop SFP monitoring loop")
10811086

1082-
def task_run(self, sfp_error_event):
1087+
def task_run(self, sfp_error_event, y_cable_presence):
10831088
if self.task_stopping_event.is_set():
10841089
return
10851090

1086-
self.task_process = multiprocessing.Process(target=self.task_worker,args=(self.task_stopping_event, sfp_error_event))
1091+
self.task_process = multiprocessing.Process(target=self.task_worker,args=(self.task_stopping_event, sfp_error_event, y_cable_presence))
10871092
self.task_process.start()
10881093

10891094
def task_stop(self):
@@ -1102,6 +1107,7 @@ def __init__(self, log_identifier):
11021107
self.num_asics = multi_asic.get_num_asics()
11031108
self.stop_event = threading.Event()
11041109
self.sfp_error_event = multiprocessing.Event()
1110+
self.y_cable_presence = [False]
11051111

11061112
# Signal handler
11071113
def signal_handler(self, sig, frame):
@@ -1231,6 +1237,9 @@ def init(self):
12311237
self.log_info("Init port sfp status table")
12321238
init_port_sfp_status_tbl(self.stop_event)
12331239

1240+
# Init port y_cable status table
1241+
y_cable_helper.init_ports_status_for_y_cable(platform_sfputil, platform_chassis, self.y_cable_presence, self.stop_event)
1242+
12341243
# Deinitialize daemon
12351244
def deinit(self):
12361245
self.log_info("Start daemon deinit...")
@@ -1247,6 +1256,10 @@ def deinit(self):
12471256
del_port_sfp_dom_info_from_db(logical_port_name, self.int_tbl[asic_index], self.dom_tbl[asic_index])
12481257
delete_port_from_status_table(logical_port_name, self.status_tbl[asic_index])
12491258

1259+
if self.y_cable_presence[0] is True:
1260+
y_cable_helper.delete_ports_status_for_y_cable()
1261+
1262+
12501263
# Run daemon
12511264
def run(self):
12521265
self.log_info("Starting up...")
@@ -1260,7 +1273,13 @@ def run(self):
12601273

12611274
# Start the sfp state info update process
12621275
sfp_state_update = SfpStateUpdateTask()
1263-
sfp_state_update.task_run(self.sfp_error_event)
1276+
sfp_state_update.task_run(self.sfp_error_event, self.y_cable_presence)
1277+
1278+
# Start the Y-cable state info update process if Y cable presence established
1279+
y_cable_state_update = None
1280+
if self.y_cable_presence[0] is True:
1281+
y_cable_state_update = y_cable_helper.YCableTableUpdateTask()
1282+
y_cable_state_update.task_run()
12641283

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

1299+
# Stop the Y-cable state info update process
1300+
if self.y_cable_presence[0] is True:
1301+
y_cable_state_update.task_stop()
1302+
12801303
# Start daemon deinitialization sequence
12811304
self.deinit()
12821305

@@ -1289,6 +1312,7 @@ def run(self):
12891312
# Main =========================================================================
12901313
#
12911314

1315+
# This is our main entry point for xcvrd script
12921316
def main():
12931317
xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER)
12941318
xcvrd.run()

sonic-xcvrd/src/xcvrd_utilities/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)