Skip to content

Commit edec881

Browse files
authored
Sonic t2 support for radian (#21732)
Why I did it Adding support for RADIAN feature for SONiC T2 Work item tracking Microsoft ADO (number only):30112967 How I did it Cli commands to add/remove ANCHOR prefix to a PREFIX_LIST table in CONFIG_DB yang model changes for the new table PrefixListMgr to handle add/remove of configuration Templates add_radian/del_radian : to add or remove an anchor prefix list and aggregate address How to verify it Unit tests : config gen, manager and yang model --------- Signed-off-by: Mukul Chodhary <70460358+Muckthebuck@users.noreply.github.com>
1 parent 58c1c41 commit edec881

30 files changed

+745
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/bin/bash
2+
3+
# Function to display help message
4+
display_help() {
5+
echo "Usage: sudo prefix-list <command> <PREFIX_TYPE> <NETWORK>"
6+
echo ""
7+
echo "Commands:"
8+
echo " add Add a prefix with prefix type and network."
9+
echo " Requires: <PREFIX_TYPE>, <NETWORK>."
10+
echo ""
11+
echo " remove Remove a prefix with prefix type and network."
12+
echo " Requires: <PREFIX_TYPE>, <NETWORK>."
13+
echo ""
14+
echo " status Display current prefix lists."
15+
echo " No additional parameters required."
16+
echo ""
17+
echo "Arguments:"
18+
echo " <PREFIX_TYPE> Type of prefix list. Allowed values: {$(printf "%s" "${supported_prefix_types[*]}" | tr ' ' '|')}."
19+
echo " <NETWORK> Network in CIDR format."
20+
echo ""
21+
echo "Options:"
22+
echo " -h, --help Display this help message."
23+
exit 0
24+
}
25+
26+
27+
# Function to check if the user has root privileges
28+
check_root_privileges() {
29+
if [ "$EUID" -ne 0 ] ; then
30+
echo "Root privileges are needed for this operation." >&2
31+
exit 1
32+
fi
33+
}
34+
35+
# Function to check if the device is supported device with type spine routers and subtype UpstreamLC
36+
check_spine_router() {
37+
type=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.type)
38+
sub_type=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.sub_type)
39+
40+
# only supported on spine routers and UpstreamLC
41+
if [[ "$type" != "SpineRouter" || "$sub_type" != "UpstreamLC" ]]; then
42+
echo "Operation is only supported on UpstreamLC of SpineRouter." >&2
43+
exit 1
44+
fi
45+
}
46+
47+
# Function to skip operation on chassis supervisor
48+
skip_chassis_supervisor() {
49+
if [ -f /etc/sonic/chassisdb.conf ]; then
50+
echo "Skipping Operation on chassis supervisor"
51+
exit 0
52+
fi
53+
}
54+
55+
# Function to validate the operation and prefix type parameters
56+
validate_operation() {
57+
local valid_operation=false
58+
local valid_prefix_type=false
59+
60+
for operation in "${prefix_list_operations[@]}"; do
61+
if [[ "$1" == "$operation" ]]; then
62+
valid_operation=true
63+
break
64+
fi
65+
done
66+
67+
if [ $valid_operation == false ]; then
68+
echo "Invalid parameter $1, Operation not supported" >&2
69+
echo ""
70+
display_help
71+
exit 1
72+
fi
73+
74+
# Check if the prefix type is supported or not if the operation is not status
75+
if [ $1 != "status" ]; then
76+
for prefix_type in "${supported_prefix_types[@]}"; do
77+
if [[ "$2" == "$prefix_type" ]]; then
78+
valid_prefix_type=true
79+
break
80+
fi
81+
done
82+
83+
if [ $valid_prefix_type == false ]; then
84+
echo "Invalid parameter $2, Prefix type not supported" >&2
85+
echo ""
86+
display_help
87+
exit 1
88+
fi
89+
fi
90+
}
91+
92+
# Function to handle prefix list operations for a specific ASIC
93+
handle_prefix_list_asic() {
94+
local asic=$1
95+
local operation=$2
96+
local PREFIX_TYPE=$3
97+
local network=$4
98+
local namespace_prefix='asic'
99+
100+
if [ $operation == 'status' ] ; then
101+
echo "BGP$asic: Current prefix lists:"
102+
sonic-cfggen -d -v PREFIX_LIST -n $namespace_prefix$asic
103+
else
104+
if [ $operation == 'add' ]; then
105+
local prefix_list_entry="{\"PREFIX_LIST\":{\"$PREFIX_TYPE|$network\":{}}}"
106+
sonic-cfggen -a "$prefix_list_entry" -w -n $namespace_prefix$asic
107+
logger -t $operation -p user.info "Added prefix list: $PREFIX_TYPE with network: $network"
108+
echo "BGP$asic: Added prefix list: $PREFIX_TYPE with network: $network"
109+
elif [ $operation == 'remove' ]; then
110+
sonic-db-cli -n $namespace_prefix$asic CONFIG_DB DEL "PREFIX_LIST|$PREFIX_TYPE|$network"
111+
logger -t $operation -p user.info "Removed prefix list: $PREFIX_TYPE with network: $network"
112+
echo "BGP$asic: Removed prefix list: $PREFIX_TYPE with network: $network"
113+
fi
114+
fi
115+
}
116+
117+
# Function to handle prefix list operations for a single ASIC
118+
handle_prefix_list_single() {
119+
local operation=$1
120+
local PREFIX_TYPE=$2
121+
local network=$3
122+
123+
if [ $operation == 'status' ] ; then
124+
echo "Current prefix lists:"
125+
sonic-cfggen -d -v PREFIX_LIST
126+
else
127+
if [ $operation == 'add' ]; then
128+
local prefix_list_entry="{\"PREFIX_LIST\":{\"$PREFIX_TYPE|$network\":{}}}"
129+
sonic-cfggen -a "$prefix_list_entry" -w
130+
logger -t $operation -p user.info "Added prefix list: $PREFIX_TYPE with network: $network"
131+
echo "Added prefix list: $PREFIX_TYPE with network: $network"
132+
elif [ $operation == 'remove' ]; then
133+
sonic-db-cli CONFIG_DB DEL "PREFIX_LIST|$PREFIX_TYPE|$network"
134+
logger -t $operation -p user.info "Removed prefix list: $PREFIX_TYPE with network: $network"
135+
echo "Removed prefix list: $PREFIX_TYPE with network: $network"
136+
fi
137+
fi
138+
}
139+
140+
prefix_list_operations=("add" "remove" "status")
141+
supported_prefix_types=("ANCHOR_PREFIX")
142+
# Main script execution
143+
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
144+
display_help
145+
fi
146+
147+
check_root_privileges
148+
check_spine_router
149+
skip_chassis_supervisor
150+
151+
validate_operation $1 $2
152+
153+
# Read SONiC immutable variables
154+
[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment
155+
156+
PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`}
157+
158+
# Parse the device specific asic conf file, if it exists
159+
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
160+
[ -f $ASIC_CONF ] && . $ASIC_CONF
161+
162+
if [[ ($NUM_ASIC -gt 1) ]]; then
163+
asic=0
164+
while [ $asic -lt $NUM_ASIC ]
165+
do
166+
sub_role=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['sub_role']" -n asic$asic`
167+
if [ $sub_role == 'FrontEnd' ]; then
168+
handle_prefix_list_asic $asic $1 $2 $3
169+
fi
170+
asic=$((asic+1))
171+
done
172+
else
173+
handle_prefix_list_single $1 $2 $3
174+
fi
175+
176+
if [ $1 != 'status' ]; then
177+
echo "Please execute 'sudo config save' to preserve prefix list after reboot or config reload"
178+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ data.ipv }} prefix-list ANCHOR_CONTRIBUTING_ROUTES permit {{ data.prefix }} ge 48
2+
{# #}
3+
router bgp {{ data.bgp_asn }}
4+
{% if data.ipv == 'ip' -%}
5+
address-family ipv4 unicast
6+
{% else -%}
7+
address-family ipv6 unicast
8+
{% endif %}
9+
aggregate-address {{ data.prefix }} route-map TAG_ANCHOR_COMMUNITY
10+
exit
11+
exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
no {{ data.ipv }} prefix-list ANCHOR_CONTRIBUTING_ROUTES permit {{ data.prefix }} ge 48
2+
router bgp {{ data.bgp_asn }}
3+
{% if data.ipv == 'ip' -%}
4+
address-family ipv4 unicast
5+
{% else %}
6+
address-family ipv6 unicast
7+
{% endif -%}
8+
no aggregate-address {{ data.prefix }} route-map TAG_ANCHOR_COMMUNITY
9+
exit
10+
exit

dockers/docker-fpm-frr/frr/bgpd/templates/general/peer-group.conf.j2

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
neighbor PEER_V4 soft-reconfiguration inbound
1515
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in
1616
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out
17+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'SpineRouter' %}
18+
table-map SELECTIVE_ROUTE_DOWNLOAD_V4
19+
{% endif %}
1720
exit-address-family
1821
address-family ipv6
1922
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
@@ -26,6 +29,9 @@
2629
neighbor PEER_V6 soft-reconfiguration inbound
2730
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in
2831
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
32+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'SpineRouter' %}
33+
table-map SELECTIVE_ROUTE_DOWNLOAD_V6
34+
{% endif %}
2935
exit-address-family
3036
!
3137
! end of template: bgpd/templates/general/peer-group.conf.j2

dockers/docker-fpm-frr/frr/bgpd/templates/general/policies.conf.j2

+41-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ route-map FROM_BGP_PEER_V6 permit 13
7373
{% else %}
7474
set tag {{ constants.bgp.route_eligible_for_fallback_to_default_tag }}
7575
{% endif %}
76-
set community {{ constants.bgp.internal_fallback_community }} additive {% endif %}
76+
set community {{ constants.bgp.internal_fallback_community }} additive
77+
{% endif %}
7778
{% endif %}
7879
!
7980
{% endif %}
@@ -97,5 +98,44 @@ route-map TO_BGP_PEER_V6 permit 100
9798
!
9899
route-map CHECK_IDF_ISOLATION permit 10
99100
!
101+
!
102+
!
103+
{% if CONFIG_DB__DEVICE_METADATA and 'localhost' in CONFIG_DB__DEVICE_METADATA and 'type' in CONFIG_DB__DEVICE_METADATA['localhost'] and 'subtype' in CONFIG_DB__DEVICE_METADATA['localhost'] %}
104+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'SpineRouter' and CONFIG_DB__DEVICE_METADATA['localhost']['subtype'] == 'UpstreamLC' %}
105+
bgp community-list standard ANCHOR_ROUTE_COMMUNITY permit {{ constants.bgp.anchor_route_community }}
106+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit {{ constants.bgp.local_anchor_route_community }}
107+
bgp community-list standard ANCHOR_CONTRIBUTING_ROUTE_COMMUNITY permit {{ constants.bgp.anchor_contributing_route_community }}
108+
!
109+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 deny 10
110+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
111+
!
112+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 permit 1000
113+
!
114+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 deny 10
115+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
116+
!
117+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 permit 1000
118+
!
119+
route-map TAG_ANCHOR_COMMUNITY permit 10
120+
set community {{ constants.bgp.local_anchor_route_community }} {{ constants.bgp.anchor_route_community }} additive
121+
!
122+
route-map TO_BGP_PEER_V6 permit 30
123+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
124+
set community {{ constants.bgp.anchor_contributing_route_community }} additive
125+
on-match next
126+
!
127+
route-map TO_BGP_PEER_V6 permit 40
128+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
129+
!
130+
route-map TO_BGP_PEER_V4 permit 30
131+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
132+
set community {{ constants.bgp.anchor_contributing_route_community }} additive
133+
on-match next
134+
!
135+
route-map TO_BGP_PEER_V4 permit 40
136+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
137+
!
138+
{% endif %}
139+
{% endif %}
100140
! end of template: bgpd/templates/general/policies.conf.j2
101141
!

dockers/docker-fpm-frr/frr/bgpd/templates/voq_chassis/policies.conf.j2

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
!
22
! template: bgpd/templates/voq_chassis/policies.conf.j2
33
!
4+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit {{ constants.bgp.local_anchor_route_community }}
45
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit {{ constants.bgp.internal_community }}
56
bgp community-list standard DEVICE_INTERNAL_FALLBACK_COMMUNITY permit {{ constants.bgp.internal_fallback_community }}
67
bgp community-list standard NO_EXPORT permit no-export
@@ -31,6 +32,9 @@ route-map TO_VOQ_CHASSIS_V4_PEER permit 1
3132
match ip address prefix-list PL_LoopbackV4
3233
set community {{ constants.bgp.internal_community }}
3334
!
35+
route-map TO_VOQ_CHASSIS_V4_PEER deny 15
36+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
37+
!
3438
route-map TO_VOQ_CHASSIS_V4_PEER permit 100
3539
!
3640
route-map FROM_VOQ_CHASSIS_V6_PEER permit 1
@@ -63,6 +67,9 @@ route-map TO_VOQ_CHASSIS_V6_PEER permit 1
6367
match ipv6 address prefix-list PL_LoopbackV6
6468
set community {{ constants.bgp.internal_community }}
6569
!
70+
route-map TO_VOQ_CHASSIS_V6_PEER deny 15
71+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
72+
!
6673
route-map TO_VOQ_CHASSIS_V6_PEER permit 100
6774
!
6875
! end of template: bgpd/templates/voq_chassis/policies.conf.j2

files/image_config/constants/constants.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ constants:
88
internal_fallback_community: 22222:22222
99
sentinel_community: 12345:12346
1010
internal_community_match_tag: 201
11+
local_anchor_route_community: 12345:555
12+
anchor_route_community: 12345:666
13+
anchor_contributing_route_community: 12345:777
1114
route_do_not_send_appdb_tag: 202
1215
route_eligible_for_fallback_to_default_tag: 203
1316
families:

rules/docker-fpm-frr.mk

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ $(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TSB:/usr/bin/TSB
4141
$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TSC:/usr/bin/TSC
4242
$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TS:/usr/bin/TS
4343
$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += idf_isolation:/usr/bin/idf_isolation
44+
$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += prefix_list:/usr/bin/prefix_list
4445

4546
SONIC_BOOKWORM_DOCKERS += $(DOCKER_FPM_FRR)
4647
SONIC_BOOKWORM_DBG_DOCKERS += $(DOCKER_FPM_FRR_DBG)

src/sonic-bgpcfgd/bgpcfgd/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .managers_chassis_app_db import ChassisAppDbMgr
2525
from .managers_bfd import BfdMgr
2626
from .managers_srv6 import SRv6Mgr
27+
from .managers_prefix_list import PrefixListMgr
2728
from .static_rt_timer import StaticRouteTimer
2829
from .runner import Runner, signal_handler
2930
from .template import TemplateFabric
@@ -79,7 +80,9 @@ def do_work():
7980
DeviceGlobalCfgMgr(common_objs, "CONFIG_DB", swsscommon.CFG_BGP_DEVICE_GLOBAL_TABLE_NAME),
8081
# SRv6 Manager
8182
SRv6Mgr(common_objs, "CONFIG_DB", "SRV6_MY_SIDS"),
82-
SRv6Mgr(common_objs, "CONFIG_DB", "SRV6_MY_LOCATORS")
83+
SRv6Mgr(common_objs, "CONFIG_DB", "SRV6_MY_LOCATORS"),
84+
# Prefix List Manager
85+
PrefixListMgr(common_objs, "CONFIG_DB", "PREFIX_LIST")
8386
]
8487

8588
if device_info.is_chassis():

0 commit comments

Comments
 (0)