Skip to content

Commit

Permalink
Merge pull request #64 from judyjoseph/multi_asic_ledd_xcvr
Browse files Browse the repository at this point in the history
* platform daemon (Xcvrd, Ledd) changes for multi asic platform
  * Updates in ledd daemon to use namespaces and get the namespace from selector object.
  * Updates to xcvrd daemon to use the asic_id in talking to the right DB.
  * Updated based on new sonic-py-common API's
  * Invoke initializeGlobalConfig() in the SfpUpdate/DomInfoUpdate processes as well.
  • Loading branch information
judyjoseph committed Aug 25, 2020
2 parents 415b8c4 + 710689f commit e9628b6
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 71 deletions.
45 changes: 31 additions & 14 deletions sonic-ledd/scripts/ledd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ try:
import sys

from sonic_py_common import daemon_base
from sonic_py_common import multi_asic
from sonic_py_common.interface import backplane_prefix
from swsscommon import swsscommon
except ImportError as e:
raise ImportError (str(e) + " - required module not found")
Expand All @@ -35,6 +37,9 @@ SELECT_TIMEOUT = 1000

LEDUTIL_LOAD_ERROR = 1

# The empty namespace refers to linux host namespace.
EMPTY_NAMESPACE = ''

class DaemonLedd(daemon_base.DaemonBase):

# Run daemon
Expand Down Expand Up @@ -65,15 +70,24 @@ class DaemonLedd(daemon_base.DaemonBase):
self.log_error("Failed to load ledutil: %s" % (str(e)), True)
sys.exit(LEDUTIL_LOAD_ERROR)

# Open a handle to the Application database
appl_db = daemon_base.db_connect("APPL_DB")
# Load the namespace details first from the database_global.json file.
swsscommon.SonicDBConfig.initializeGlobalConfig()

# Get the namespaces in the platform. For multi-asic devices we get the namespaces
# of front-end ascis which have front-panel interfaces.
namespaces = multi_asic.get_front_end_namespaces()

# Subscribe to PORT table notifications in the Application DB
appl_db, sst = {}, {}
sel = swsscommon.Select()
sst = swsscommon.SubscriberStateTable(appl_db, swsscommon.APP_PORT_TABLE_NAME)
sel.addSelectable(sst)

# Listen indefinitely for changes to the PORT table in the Application DB
for namespace in namespaces:
# Open a handle to the Application database, in all namespaces
appl_db[namespace] = daemon_base.db_connect("APPL_DB", namespace=namespace)
sst[namespace] = swsscommon.SubscriberStateTable(appl_db[namespace], swsscommon.APP_PORT_TABLE_NAME)
sel.addSelectable(sst[namespace])

# Listen indefinitely for changes to the PORT table in the Application DB's
while True:
# Use timeout to prevent ignoring the signals we want to handle
# in signal_handler() (e.g. SIGTERM for graceful shutdown)
Expand All @@ -86,17 +100,20 @@ class DaemonLedd(daemon_base.DaemonBase):
self.log_warning("sel.select() did not return swsscommon.Select.OBJECT")
continue

(key, op, fvp) = sst.pop()

# TODO: Once these flag entries have been removed from the DB,
# we can remove this check
if key in ["PortConfigDone", "PortInitDone"]:
continue
# Get the namespace from the selectable object and use it to index the SubscriberStateTable handle.
ns=c.getDbNamespace()
(key, op, fvp) = sst[ns].pop()
if fvp:
# TODO: Once these flag entries have been removed from the DB,
# we can remove this check
if key in ["PortConfigDone", "PortInitDone"]:
continue

fvp_dict = dict(fvp)
fvp_dict = dict(fvp)

if op == "SET" and "oper_status" in fvp_dict:
led_control.port_link_state_change(key, fvp_dict["oper_status"])
if op == "SET" and "oper_status" in fvp_dict:
if not key.startswith(backplane_prefix()):
led_control.port_link_state_change(key, fvp_dict["oper_status"])

return 1

Expand Down
Loading

0 comments on commit e9628b6

Please sign in to comment.