Skip to content

Commit 6a8a3ff

Browse files
LARLSNyanjundeng
authored andcommitted
feat(frrcfgd): update for new locator config way (sonic-net#21843)
[FRRCFGD]update for new locator config way
1 parent be30a1d commit 6a8a3ff

File tree

1 file changed

+37
-55
lines changed

1 file changed

+37
-55
lines changed

src/sonic-frr-mgmt-framework/frrcfgd/frrcfgd.py

+37-55
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def extract_cmd_daemons(cmd_str):
7575
class BgpdClientMgr(threading.Thread):
7676
VTYSH_MARK = 'vtysh '
7777
PROXY_SERVER_ADDR = '/etc/frr/bgpd_client_sock'
78-
ALL_DAEMONS = ['bgpd', 'zebra', 'staticd', 'bfdd', 'ospfd', 'pimd']
78+
ALL_DAEMONS = ['bgpd', 'zebra', 'staticd', 'bfdd', 'ospfd', 'pimd', 'mgmtd']
7979
TABLE_DAEMON = {
8080
'DEVICE_METADATA': ['bgpd'],
8181
'BGP_GLOBALS': ['bgpd'],
@@ -118,7 +118,9 @@ class BgpdClientMgr(threading.Thread):
118118
'PIM_INTERFACE': ['pimd'],
119119
'IGMP_INTERFACE': ['pimd'],
120120
'IGMP_INTERFACE_QUERY': ['pimd'],
121-
'SRV6_LOCATOR': ['zebra']
121+
'SRV6_MY_LOCATORS': ['zebra'],
122+
'SRV6_MY_SIDS': ['mgmtd']
123+
122124
}
123125
VTYSH_CMD_DAEMON = [(r'show (ip|ipv6) route($|\s+\S+)', ['zebra']),
124126
(r'show ip mroute($|\s+\S+)', ['pimd']),
@@ -402,46 +404,6 @@ def get_command_cmn(daemon, cmd_str, op, st_idx, vals, bool_values):
402404
cmd_args.append(CommandArgument(daemon, cmd_enable, vals[idx]))
403405
return [cmd_str.format(*cmd_args, no = CommandArgument(daemon, cmd_enable))]
404406

405-
def hdl_srv6_locator(daemon, cmd_str, op, st_idx, vals, bool_values):
406-
chk_val = None
407-
if op == CachedDataWithOp.OP_DELETE:
408-
if bool_values is not None and len(bool_values) >= 3:
409-
# set to default if given
410-
cmd_enable = bool_values[2]
411-
else:
412-
cmd_enable = False
413-
else:
414-
cmd_enable = True
415-
if bool_values is not None:
416-
if len(vals) <= st_idx:
417-
return None
418-
chk_val = vals[st_idx]
419-
if type(chk_val) is dict:
420-
cmd_enable = False
421-
for _, v in chk_val.items():
422-
if not v[1]:
423-
continue
424-
if v[0] == bool_values[0]:
425-
cmd_enable = True
426-
break
427-
else:
428-
if chk_val == bool_values[0]:
429-
cmd_enable = True
430-
elif chk_val == bool_values[1]:
431-
cmd_enable = False
432-
else:
433-
return None
434-
else:
435-
cmd_enable = True
436-
cmd_list = []
437-
for num in range(len(vals[0])):
438-
cmd_args = []
439-
for idx in range(len(vals)):
440-
if bool_values is not None and idx == st_idx:
441-
continue
442-
cmd_args.append(CommandArgument(daemon, cmd_enable, vals[idx][num]))
443-
cmd_list.append(cmd_str.format(*cmd_args, no = CommandArgument(daemon, cmd_enable)))
444-
return cmd_list
445407

446408
def hdl_set_extcomm(daemon, cmd_str, op, st_idx, args, is_inline):
447409
if is_inline:
@@ -2128,7 +2090,6 @@ class BGPConfigDaemon:
21282090
('icmo_ttl', 'ttl {}', handle_ip_sla_common),
21292091
('icmp_tos', 'tos {}', handle_ip_sla_common),
21302092
]
2131-
srv6_locator_key_map = [(['opcode_prefix', 'opcode_act', 'opcode_data'], '{no:no-prefix}opcode {} {} {}', hdl_srv6_locator)]
21322093

21332094

21342095
tbl_to_key_map = {'BGP_GLOBALS': global_key_map,
@@ -2159,7 +2120,6 @@ class BGPConfigDaemon:
21592120
'PIM_INTERFACE': pim_interface_key_map,
21602121
'IGMP_INTERFACE': igmp_mcast_grp_key_map,
21612122
'IGMP_INTERFACE_QUERY': igmp_interface_config_key_map,
2162-
'SRV6_LOCATOR': srv6_locator_key_map,
21632123
}
21642124

21652125
vrf_tables = {'BGP_GLOBALS', 'BGP_GLOBALS_AF',
@@ -2357,7 +2317,8 @@ def __init__(self):
23572317
('PIM_INTERFACE', self.bgp_table_handler_common),
23582318
('IGMP_INTERFACE', self.bgp_table_handler_common),
23592319
('IGMP_INTERFACE_QUERY', self.bgp_table_handler_common),
2360-
('SRV6_LOCATOR', self.bgp_table_handler_common),
2320+
('SRV6_MY_LOCATORS', self.bgp_table_handler_common),
2321+
('SRV6_MY_SIDS', self.bgp_table_handler_common),
23612322
]
23622323
self.bgp_message = queue.Queue(0)
23632324
self.table_data_cache = self.config_db.get_table_data([tbl for tbl, _ in self.table_handler_list])
@@ -2753,17 +2714,38 @@ def __update_bgp(self, data_list):
27532714
self.bgp_confed_peers[vrf] = copy.copy(self.upd_confed_peers)
27542715
else:
27552716
self.__delete_vrf_asn(vrf, table, data)
2756-
elif table == 'SRV6_LOCATOR':
2757-
key = prefix
2758-
prefix = data['prefix']
2759-
cmd_prefix = ['configure terminal', 'segment-routing', 'srv6', 'locators',
2760-
'locator {}'.format(key),
2761-
'prefix {} block-len {} node-len {} func-bits {}'.format(prefix.data, data['block_len'].data, data['node_len'].data, data['func_len'].data)]
2762-
2763-
if not key_map.run_command(self, table, data, cmd_prefix):
2764-
syslog.syslog(syslog.LOG_ERR, 'failed running SRV6 LOCATOR config command')
2717+
elif table == 'SRV6_MY_LOCATORS':
2718+
if key is None:
2719+
syslog.syslog(syslog.LOG_ERR, 'invalid key for SRV6_MY_LOCATORS table')
2720+
continue
2721+
if not del_table:
2722+
key = prefix
2723+
prefix = data['prefix']
2724+
cmd = "vtysh -c 'configure terminal' -c 'segment-routing' -c 'srv6' -c 'locators' "
2725+
cmd += " -c 'locator {}' ".format(key)
2726+
cmd += " -c 'prefix {} block-len {} node-len {} func-bits {}' ".format(prefix.data, data['block_len'].data, data['node_len'].data, data['func_len'].data)
2727+
if not self.__run_command(table, cmd):
2728+
syslog.syslog(syslog.LOG_ERR, 'failed running SRV6 POLICY config command')
2729+
continue
2730+
elif table == 'SRV6_MY_SIDS':
2731+
if key is None:
2732+
syslog.syslog(syslog.LOG_ERR, 'invalid key for SRV6_MY_SIDS table')
27652733
continue
2766-
2734+
if not del_table:
2735+
cmd = "vtysh -c 'configure terminal' -c 'segment-routing' -c 'srv6' "
2736+
cmd +="-c 'static-sids' "
2737+
uDTAction = ["uDT46", "uDT4", "uDT6"]
2738+
if data['action'].data in uDTAction:
2739+
cmd +="-c 'sid {} locator {} behavior {} vrf {}' ".format(key, prefix, data['action'].data, data['decap_vrf'].data)
2740+
elif data['action'].data == 'uN':
2741+
cmd +="-c 'sid {} locator {} behavior {} ' ".format(key, prefix, data['action'].data)
2742+
else:
2743+
syslog.syslog(syslog.LOG_ERR, 'failed running SRV6 POLICY config command, not support action %s'.format(data['action'].data))
2744+
continue
2745+
if not self.__run_command(table, cmd):
2746+
syslog.syslog(syslog.LOG_ERR, 'failed running SRV6 SRV6_MY_SIDS config command')
2747+
continue
2748+
27672749
elif table == 'BGP_GLOBALS_AF':
27682750
af, ip_type = key.lower().split('_')
27692751
#this is to temporarily make table cache key accessible to key_map handler function

0 commit comments

Comments
 (0)