Skip to content

Add remote dpu db to bfdmon. #22705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/sonic-bgpcfgd/bfdmon/bfdmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import syslog
from swsscommon import swsscommon
from sonic_py_common import device_info
from sonic_py_common.general import getstatusoutput_noshell

class BfdFrrMon:
Expand All @@ -18,6 +19,15 @@ def __init__(self):
self.init_done = False
self.MAX_RETRY_ATTEMPTS = 3

self.remote_status_table = "DASH_BFD_PROBE_STATE"
switch_type = device_info.get_localhost_info("switch_type")
if switch_type and switch_type == "dpu":
self.remote_db_connector = swsscommon.DBConnector("DPU_STATE_DB", 0, True)
self.remote_table = swsscommon.Table(self.remote_db_connector, self.remote_status_table)
else:
self.remote_db_connector = None
self.remote_table = None

def check_bfdd(self):
"""
Check if bfdd is running.
Expand Down Expand Up @@ -73,7 +83,7 @@ def get_bfd_sessions(self):
self.frr_v6_peers.add(session["peer"])
else: # IPv4
self.frr_v4_peers.add(session["peer"])
return True
return True
except json.JSONDecodeError as e:
# Log the exception and retry if within the maximum attempts
retry_attempt += 1
Expand Down Expand Up @@ -113,14 +123,20 @@ def update_state_db(self):

# Update Redis with the new peer sets
values = [
("v4_bfd_up_sessions", json.dumps(list(self.local_v4_peers))),
("v6_bfd_up_sessions", json.dumps(list(self.local_v6_peers)))
("v4_bfd_up_sessions", json.dumps(list(self.local_v4_peers)).strip("[]")),
("v6_bfd_up_sessions", json.dumps(list(self.local_v6_peers)).strip("[]"))
]
self.table.set("", values)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to write into both STATE_DB/DPU_BFD_PROBE_STATE and DPU_STATE_DB/DASH_BFD_PROBE_STATE? The former is for DPU and the data format is for hamgrd to consume. Since hamgrd will use the latter. I see no need to have the first.

syslog.syslog(syslog.LOG_INFO,
"{} table in STATE_DB updated. v4_peers: {}, v6_peers: {}".format(
self.status_table, self.local_v4_peers, self.local_v6_peers))

if self.remote_table:
self.remote_table.set("", values)
syslog.syslog(syslog.LOG_INFO,
"{} table in DPU_STATE_DB updated. v4_peers: {}, v6_peers: {}".format(
self.remote_status_table, self.local_v4_peers, self.local_v6_peers))

self.init_done = True

def main():
Expand Down
Loading