forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bgpcfgd]: Changes to support sequential IDF isolation (sonic-net#19136)
Why I did it In order to isolate an IDF sequentially (one device at a time), need a mechanism to perform downstream isolation on T2 device. Adding support for two kinds of isolation - By setting no-export BGP community on all routes advertised to T1 (except loopback), so the routes are not advertised to T0s By withdrawing all routes from T1 How I did it Added 1. New configuration to support the changes described by Yang model changes for Sequential IDF isolation sonic-net#18597 Script to update configDB on each ASIC to configure no-export/withdraw-all isolation and unisolation of IDF. This is copied to host 2. BGPcfgd changes to handle configDB events and add/remove the required route-maps 3. UT cases and data file changes for BGPCfgd and jinja templates How to verify it Corresponding templates on T2 have to be updated to verify the functionality Configuration options- sudo idf_isolation withdraw_all sudo idf_isolation no-export sudo idf_isolation unisolated Validate the routes on T1 are either withdrawn, tagged with no-export community or re-advertised based on the configuration
- Loading branch information
1 parent
a9299e5
commit 957a36c
Showing
18 changed files
with
382 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/bin/bash | ||
|
||
# Restrict command to sudo users | ||
if [ "$EUID" -ne 0 ] ; then | ||
echo "Root priveleges are needed for this operation" | ||
exit 1 | ||
fi | ||
|
||
# Command is only supported on spine routers | ||
if [[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.type)" != *"SpineRouter"* ]] ; then | ||
echo "Operation is not supported on this platform" | ||
exit 1 | ||
fi | ||
|
||
# Skip operation on chassis supervisor | ||
if [ -f /etc/sonic/chassisdb.conf ]; then | ||
echo "Skipping Operation on chassis supervisor" | ||
exit 0 | ||
fi | ||
|
||
idf_isolation_states=("isolated_no_export" "isolated_withdraw_all" "unisolated" "status") | ||
valid=false | ||
for state in "${idf_isolation_states[@]}"; do | ||
if [[ "$1" == "$state" ]]; then | ||
valid=true | ||
break | ||
fi | ||
done | ||
if [ $valid == false ]; then | ||
echo "Invalid parameter $1, Operation not supported" | ||
echo "" | ||
echo "Usage: sudo idf_isolation <isolated_no_export|isolated_withdraw_all|unisolated|status>" | ||
exit 0 | ||
fi | ||
|
||
IDF_ISOLATION_STATE="{\"BGP_DEVICE_GLOBAL\":{\"STATE\":{\"idf_isolation_state\": \"$1\"}}}" | ||
|
||
# read SONiC immutable variables | ||
[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment | ||
|
||
PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} | ||
|
||
# Parse the device specific asic conf file, if it exists | ||
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf | ||
[ -f $ASIC_CONF ] && . $ASIC_CONF | ||
|
||
if [[ ($NUM_ASIC -gt 1) ]]; then | ||
asic=0 | ||
NAMESPACE_PREFIX='asic' | ||
|
||
while [ $asic -lt $NUM_ASIC ] | ||
do | ||
sub_role=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['sub_role']" -n $NAMESPACE_PREFIX$asic` | ||
if [ $sub_role == 'FrontEnd' ] ; then | ||
cur_idf_isolation_state="$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.idf_isolation_state -n $NAMESPACE_PREFIX$asic)" | ||
if [ $1 == 'status' ] ; then | ||
echo "BGP$asic: IDF isolation state: $cur_idf_isolation_state" | ||
else | ||
if [ $1 == $cur_idf_isolation_state ]; then | ||
echo "BGP$asic: IDF is already in $1 state" | ||
else | ||
sonic-cfggen -a "$IDF_ISOLATION_STATE" -w -n $NAMESPACE_PREFIX$asic | ||
logger -t $1 -p user.info "IDF isolation state: $1" | ||
echo "BGP$asic: IDF isolation state: $1" | ||
fi | ||
fi | ||
fi | ||
asic=$[$asic+1] | ||
done | ||
else | ||
cur_idf_isolation_state="$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.idf_isolation_state)" | ||
if [ $1 == 'status' ] ; then | ||
echo "IDF isolation state: $cur_idf_isolation_state" | ||
else | ||
if [ $1 == $cur_idf_isolation_state ]; then | ||
echo "IDF is already in $1 state" | ||
else | ||
sonic-cfggen -a "$IDF_ISOLATION_STATE" -w | ||
logger -t $1 -p user.info "IDF isolation state: $1" | ||
echo "IDF isolation state: $1" | ||
fi | ||
fi | ||
fi | ||
|
||
if [ $1 != 'status' ]; then | ||
echo "Please execute 'sudo config save' to preserve IDF isolation state after reboot or config reload" | ||
fi |
20 changes: 20 additions & 0 deletions
20
dockers/docker-fpm-frr/frr/bgpd/idf_isolate/idf_isolate.conf.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
route-map CHECK_IDF_ISOLATION permit 1 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community {{ constants.bgp.traffic_shift_community }} | ||
route-map CHECK_IDF_ISOLATION permit 2 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community {{ constants.bgp.traffic_shift_community }} | ||
route-map CHECK_IDF_ISOLATION permit 3 | ||
match tag {{ constants.bgp.internal_community_match_tag }} | ||
set community {{ constants.bgp.traffic_shift_community }} | ||
{# #} | ||
{%- if isolation_status == "isolated_withdraw_all" -%} | ||
route-map CHECK_IDF_ISOLATION deny 4 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
no set community no-export additive{# Added to clean up state, in case of transition from isolated_no_export (not expected) #} | ||
{%- elif isolation_status == "isolated_no_export" -%} | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
set community no-export additive | ||
no route-map CHECK_IDF_ISOLATION deny 4{# Added to clean up state, in case of transition from isolated_withdraw_all (not expected) #} | ||
{# #} | ||
{%- endif -%} |
6 changes: 6 additions & 0 deletions
6
dockers/docker-fpm-frr/frr/bgpd/idf_isolate/idf_unisolate.conf.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
no route-map CHECK_IDF_ISOLATION permit 1 | ||
no route-map CHECK_IDF_ISOLATION permit 2 | ||
no route-map CHECK_IDF_ISOLATION permit 3 | ||
no route-map CHECK_IDF_ISOLATION deny 4 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
no set community no-export additive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all_idf_isolated_no_export.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
! | ||
! template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
neighbor PEER_V4 peer-group | ||
neighbor PEER_V6 peer-group | ||
address-family ipv4 | ||
neighbor PEER_V4 allowas-in 1 | ||
neighbor PEER_V4 soft-reconfiguration inbound | ||
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in | ||
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out | ||
exit-address-family | ||
address-family ipv6 | ||
neighbor PEER_V6 allowas-in 1 | ||
neighbor PEER_V6 soft-reconfiguration inbound | ||
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in | ||
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out | ||
exit-address-family | ||
! | ||
! end of template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
|
||
route-map CHECK_IDF_ISOLATION permit 1 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 2 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 3 | ||
match tag 1001 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
set community no-export additive | ||
no route-map CHECK_IDF_ISOLATION deny 4 | ||
|
33 changes: 33 additions & 0 deletions
33
...onic-bgpcfgd/tests/data/general/peer-group.conf/result_all_idf_isolated_withdraw_all.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
! | ||
! template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
neighbor PEER_V4 peer-group | ||
neighbor PEER_V6 peer-group | ||
address-family ipv4 | ||
neighbor PEER_V4 allowas-in 1 | ||
neighbor PEER_V4 soft-reconfiguration inbound | ||
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in | ||
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out | ||
exit-address-family | ||
address-family ipv6 | ||
neighbor PEER_V6 allowas-in 1 | ||
neighbor PEER_V6 soft-reconfiguration inbound | ||
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in | ||
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out | ||
exit-address-family | ||
! | ||
! end of template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
|
||
route-map CHECK_IDF_ISOLATION permit 1 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 2 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 3 | ||
match tag 1001 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION deny 4 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
no set community no-export additive |
27 changes: 27 additions & 0 deletions
27
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all_idf_unisolated.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
! | ||
! template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
neighbor PEER_V4 peer-group | ||
neighbor PEER_V6 peer-group | ||
address-family ipv4 | ||
neighbor PEER_V4 allowas-in 1 | ||
neighbor PEER_V4 soft-reconfiguration inbound | ||
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in | ||
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out | ||
exit-address-family | ||
address-family ipv6 | ||
neighbor PEER_V6 allowas-in 1 | ||
neighbor PEER_V6 soft-reconfiguration inbound | ||
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in | ||
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out | ||
exit-address-family | ||
! | ||
! end of template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
|
||
no route-map CHECK_IDF_ISOLATION permit 1 | ||
no route-map CHECK_IDF_ISOLATION permit 2 | ||
no route-map CHECK_IDF_ISOLATION permit 3 | ||
no route-map CHECK_IDF_ISOLATION deny 4 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
no set community no-export additive |
12 changes: 12 additions & 0 deletions
12
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_idf_isolated.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
route-map CHECK_IDF_ISOLATION permit 1 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 2 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 3 | ||
match tag 1001 | ||
set community 12345:12345 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
set community no-export additive | ||
no route-map CHECK_IDF_ISOLATION deny 4 |
12 changes: 12 additions & 0 deletions
12
src/sonic-bgpcfgd/tests/data/sonic-cfggen/idf_isolate/idf_isolated_no_export.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
route-map CHECK_IDF_ISOLATION permit 1 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:555 | ||
route-map CHECK_IDF_ISOLATION permit 2 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:555 | ||
route-map CHECK_IDF_ISOLATION permit 3 | ||
match tag 1002 | ||
set community 12345:555 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
set community no-export additive | ||
no route-map CHECK_IDF_ISOLATION deny 4 |
9 changes: 9 additions & 0 deletions
9
src/sonic-bgpcfgd/tests/data/sonic-cfggen/idf_isolate/idf_isolated_no_export.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"constants": { | ||
"bgp": { | ||
"traffic_shift_community": "12345:555", | ||
"internal_community_match_tag": "1002" | ||
} | ||
}, | ||
"isolation_status": "isolated_no_export" | ||
} |
12 changes: 12 additions & 0 deletions
12
src/sonic-bgpcfgd/tests/data/sonic-cfggen/idf_isolate/idf_isolated_withdraw_all.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
route-map CHECK_IDF_ISOLATION permit 1 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:555 | ||
route-map CHECK_IDF_ISOLATION permit 2 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:555 | ||
route-map CHECK_IDF_ISOLATION permit 3 | ||
match tag 1002 | ||
set community 12345:555 | ||
route-map CHECK_IDF_ISOLATION deny 4 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
no set community no-export additive |
9 changes: 9 additions & 0 deletions
9
src/sonic-bgpcfgd/tests/data/sonic-cfggen/idf_isolate/idf_isolated_withdraw_all.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"constants": { | ||
"bgp": { | ||
"traffic_shift_community": "12345:555", | ||
"internal_community_match_tag": "1002" | ||
} | ||
}, | ||
"isolation_status": "isolated_withdraw_all" | ||
} |
6 changes: 6 additions & 0 deletions
6
src/sonic-bgpcfgd/tests/data/sonic-cfggen/idf_isolate/idf_unisolated.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
no route-map CHECK_IDF_ISOLATION permit 1 | ||
no route-map CHECK_IDF_ISOLATION permit 2 | ||
no route-map CHECK_IDF_ISOLATION permit 3 | ||
no route-map CHECK_IDF_ISOLATION deny 4 | ||
route-map CHECK_IDF_ISOLATION permit 10 | ||
no set community no-export additive |
Oops, something went wrong.