Skip to content

[202205]implement staticroutebfd process #13764

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 6 commits into
base: 202205
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=bgpd:running

{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
{% else %}
[program:staticroutebfd]
command=/usr/local/bin/staticroutebfd
priority=6
autostart=false
autorestart=true
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=bgpd:running
{% endif %}

[program:bgpmon]
command=/usr/local/bin/bgpmon
priority=6
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-bgpcfgd/bgpcfgd/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def log_err(msg):

def log_crit(msg):
""" Send a message msg to the syslog as CRIT """
syslog.syslog(syslog.LOG_CRIT, msg)
syslog.syslog(syslog.LOG_CRIT, msg)
47 changes: 43 additions & 4 deletions src/sonic-bgpcfgd/bgpcfgd/managers_static_rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, common_objs, db, table):
self.directory.subscribe([("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/bgp_asn"),], self.on_bgp_asn_change)
self.static_routes = {}
self.vrf_pending_redistribution = set()
self.config_db = None

OP_DELETE = 'DELETE'
OP_ADD = 'ADD'
Expand All @@ -41,8 +42,18 @@ def set_handler(self, key, data):
intf_list = arg_list(data['ifname']) if 'ifname' in data else None
dist_list = arg_list(data['distance']) if 'distance' in data else None
nh_vrf_list = arg_list(data['nexthop-vrf']) if 'nexthop-vrf' in data else None
bfd_enable = arg_list(data['bfd']) if 'bfd' in data else None
route_tag = self.ROUTE_ADVERTISE_DISABLE_TAG if 'advertise' in data and data['advertise'] == "false" else self.ROUTE_ADVERTISE_ENABLE_TAG

# bfd enabled route would be handled in staticroutebfd, skip here
if bfd_enable and bfd_enable[0].lower() == "true":
log_debug("{} static route {} bfd flag is true".format(self.db_name, key))
tmp_nh_set, tmp_route_tag = self.static_routes.get(vrf, {}).get(ip_prefix, (IpNextHopSet(is_ipv6), route_tag))
if tmp_nh_set: #clear nexthop set if it is not empty
log_debug("{} static route {} bfd flag is true, cur_nh is not empty, clear it".format(self.db_name, key))
self.static_routes.setdefault(vrf, {}).pop(ip_prefix, None)
return True

try:
ip_nh_set = IpNextHopSet(is_ipv6, bkh_list, nh_list, intf_list, dist_list, nh_vrf_list)
cur_nh_set, cur_route_tag = self.static_routes.get(vrf, {}).get(ip_prefix, (IpNextHopSet(is_ipv6), route_tag))
Expand All @@ -60,19 +71,47 @@ def set_handler(self, key, data):

if cmd_list:
self.cfg_mgr.push_list(cmd_list)
log_debug("Static route {} is scheduled for updates".format(key))
log_debug("{} Static route {} is scheduled for updates. {}".format(self.db_name, key, str(cmd_list)))
else:
log_debug("Nothing to update for static route {}".format(key))
log_debug("{} Nothing to update for static route {}".format(self.db_name, key))

self.static_routes.setdefault(vrf, {})[ip_prefix] = (ip_nh_set, route_tag)

return True


def skip_appl_del(self, vrf, ip_prefix):
if self.db_name == "CONFIG_DB":
return False

if self.config_db is None:
self.config_db = swsscommon.SonicV2Connector()
self.config_db.connect(self.config_db.CONFIG_DB)

#just pop local cache if the route exist in config_db
cfg_key = "STATIC_ROUTE|" + vrf + "|" + ip_prefix
nexthop = self.config_db.get(self.config_db.CONFIG_DB, cfg_key, "nexthop")
if nexthop and len(nexthop)>0:
self.static_routes.setdefault(vrf, {}).pop(ip_prefix, None)
return True

if vrf == "default":
cfg_key = "STATIC_ROUTE|" + ip_prefix
nexthop = self.config_db.get(self.config_db.CONFIG_DB, cfg_key, "nexthop")
if nexthop and len(nexthop)>0:
self.static_routes.setdefault(vrf, {}).pop(ip_prefix, None)
return True

return False

def del_handler(self, key):
vrf, ip_prefix = self.split_key(key)
is_ipv6 = TemplateFabric.is_ipv6(ip_prefix)

if self.skip_appl_del(vrf, ip_prefix):
log_debug("{} ignore appl_db static route deletion because of key {} exist in config_db".format(self.db_name, key))
return

ip_nh_set = IpNextHopSet(is_ipv6)
cur_nh_set, route_tag = self.static_routes.get(vrf, {}).get(ip_prefix, (IpNextHopSet(is_ipv6), self.ROUTE_ADVERTISE_DISABLE_TAG))
cmd_list = self.static_route_commands(ip_nh_set, cur_nh_set, ip_prefix, vrf, route_tag, route_tag)
Expand All @@ -85,9 +124,9 @@ def del_handler(self, key):

if cmd_list:
self.cfg_mgr.push_list(cmd_list)
log_debug("Static route {} is scheduled for updates".format(key))
log_debug("{} Static route {} is scheduled for updates. {}".format(self.db_name, key, str(cmd_list)))
else:
log_debug("Nothing to update for static route {}".format(key))
log_debug("{} Nothing to update for static route {}".format(self.db_name, key))

self.static_routes.setdefault(vrf, {}).pop(ip_prefix, None)

Expand Down
1 change: 1 addition & 0 deletions src/sonic-bgpcfgd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
entry_points = {
'console_scripts': [
'bgpcfgd = bgpcfgd.main:main',
'staticroutebfd = staticroutebfd.main:main',
'bgpmon = bgpmon.bgpmon:main',
]
},
Expand Down
Empty file.
Loading