Skip to content

Commit 5621f7c

Browse files
deepak-singhal0408yanjundeng
authored andcommitted
T2: anchor prefix fixes (sonic-net#22130)
Why I did it fixes in T2 Radian Resiliency feature support checked in as part of PR sonic-net#21732 Work item tracking Microsoft ADO 31982579: How I did it The changes take care of following Fix a typo which fetching chassis subtype in prefix_list script remove root permission validation during radian status check Input argument parsing fix during status check during add_radian/del_radian template rendering, prefix-list entry to have prefixlen passed as an argument, instead of hardcoding it How to verify it Execute the prefix_list script, and make sure add/del radian entries go through as expected. Ensure that status check doesnt require sudo Ensure that status check fails when passed second argument Ensure that backend code renders radian config as per expectation
1 parent 6c16266 commit 5621f7c

File tree

8 files changed

+37
-25
lines changed

8 files changed

+37
-25
lines changed

dockers/docker-fpm-frr/base_image_files/prefix_list

+20-11
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ check_root_privileges() {
3535
# Function to check if the device is supported device with type spine routers and subtype UpstreamLC
3636
check_spine_router() {
3737
type=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.type)
38-
sub_type=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.sub_type)
39-
38+
subtype=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype)
39+
4040
# only supported on spine routers and UpstreamLC
41-
if [[ "$type" != "SpineRouter" || "$sub_type" != "UpstreamLC" ]]; then
41+
if [[ "$type" != "SpineRouter" || "$subtype" != "UpstreamLC" ]]; then
4242
echo "Operation is only supported on UpstreamLC of SpineRouter." >&2
4343
exit 1
4444
fi
4545
}
4646

4747
# Function to skip operation on chassis supervisor
4848
skip_chassis_supervisor() {
49-
if [ -f /etc/sonic/chassisdb.conf ]; then
49+
if [ -f /etc/sonic/chassisdb.conf ]; then
5050
echo "Skipping Operation on chassis supervisor"
5151
exit 0
5252
fi
@@ -72,12 +72,19 @@ validate_operation() {
7272
fi
7373

7474
# 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
75+
if [ "$1" == "status" ]; then
76+
if [ -n "$2" ]; then
77+
echo "No additional parameters required for status operation." >&2
78+
echo ""
79+
display_help
80+
exit 1
8081
fi
82+
else
83+
for prefix_type in "${supported_prefix_types[@]}"; do
84+
if [[ "$2" == "$prefix_type" ]]; then
85+
valid_prefix_type=true
86+
break
87+
fi
8188
done
8289

8390
if [ $valid_prefix_type == false ]; then
@@ -144,7 +151,9 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then
144151
display_help
145152
fi
146153

147-
check_root_privileges
154+
if [ "$1" != "status" ]; then
155+
check_root_privileges
156+
fi
148157
check_spine_router
149158
skip_chassis_supervisor
150159

@@ -162,7 +171,7 @@ ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
162171
if [[ ($NUM_ASIC -gt 1) ]]; then
163172
asic=0
164173
while [ $asic -lt $NUM_ASIC ]
165-
do
174+
do
166175
sub_role=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['sub_role']" -n asic$asic`
167176
if [ $sub_role == 'FrontEnd' ]; then
168177
handle_prefix_list_asic $asic $1 $2 $3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
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
1+
{{ data.ipv }} prefix-list ANCHOR_CONTRIBUTING_ROUTES permit {{ data.prefix }} ge {{ data.prefixlen + 1 }}
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+
aggregate-address {{ data.prefix }} route-map TAG_ANCHOR_COMMUNITY
9+
exit
1110
exit

dockers/docker-fpm-frr/frr/bgpd/radian/del_radian.conf.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
no {{ data.ipv }} prefix-list ANCHOR_CONTRIBUTING_ROUTES permit {{ data.prefix }} ge 48
1+
no {{ data.ipv }} prefix-list ANCHOR_CONTRIBUTING_ROUTES permit {{ data.prefix }} ge {{ data.prefixlen + 1 }}
22
router bgp {{ data.bgp_asn }}
33
{% if data.ipv == 'ip' -%}
44
address-family ipv4 unicast

src/sonic-bgpcfgd/bgpcfgd/managers_prefix_list.py

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def set_handler(self, key, data):
7575
return True
7676
data["prefix_list_name"] = prefix_list_name
7777
data["prefix"] = str(prefix.cidr)
78+
data["prefixlen"] = prefix.prefixlen
7879
data["ipv"] = self.get_ip_type(prefix)
7980
# Generate the prefix list configuration
8081
if self.generate_prefix_list_config(data, add=True):
@@ -96,6 +97,7 @@ def del_handler(self, key):
9697
data = {}
9798
data["prefix_list_name"] = prefix_list_name
9899
data["prefix"] = str(prefix.cidr)
100+
data["prefixlen"] = prefix.prefixlen
99101
data["ipv"] = self.get_ip_type(prefix)
100102
# remove the prefix list configuration
101103
if self.generate_prefix_list_config(data, add=False):

src/sonic-bgpcfgd/tests/data/sonic-cfggen/radian/add_radian.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ipv6 prefix-list ANCHOR_CONTRIBUTING_ROUTES permit ffff::/64 ge 48
1+
ipv6 prefix-list ANCHOR_CONTRIBUTING_ROUTES permit ffff::/64 ge 65
22
router bgp 1234
33
address-family ipv6 unicast
44
aggregate-address ffff::/64 route-map TAG_ANCHOR_COMMUNITY

src/sonic-bgpcfgd/tests/data/sonic-cfggen/radian/add_radian.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"data": {
33
"ipv": "ipv6",
44
"prefix": "ffff::/64",
5+
"prefixlen": 64,
56
"bgp_asn": 1234
67
}
78
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
no ipv6 prefix-list ANCHOR_CONTRIBUTING_ROUTES permit ffff::/64 ge 48
1+
no ipv6 prefix-list ANCHOR_CONTRIBUTING_ROUTES permit ffff::/64 ge 65
22
router bgp 1234
33
address-family ipv6 unicast
44
no aggregate-address ffff::/64 route-map TAG_ANCHOR_COMMUNITY
55
exit
6-
exit
6+
exit

src/sonic-bgpcfgd/tests/data/sonic-cfggen/radian/del_radian.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"data": {
33
"ipv": "ipv6",
44
"prefix": "ffff::/64",
5+
"prefixlen": 64,
56
"bgp_asn": 1234
67
}
78
}

0 commit comments

Comments
 (0)