Skip to content
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

[chassis] Added support of isolating given LC in Chassis with TSA mode #16732

Merged
merged 32 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7a3d7e5
Fix the Loopback0 IPv6 address of LC's in chassis not reachable from
abdosi Aug 3, 2023
b5b08cf
Merge remote-tracking branch 'upstream/master'
abdosi Aug 17, 2023
8d9dbb6
Added change to have flag
abdosi Aug 17, 2023
d04bc54
Merge remote-tracking branch 'upstream/master'
abdosi Aug 23, 2023
264d912
Merge remote-tracking branch 'upstream/master'
abdosi Aug 25, 2023
957cd71
Merge remote-tracking branch 'upstream/master'
abdosi Aug 31, 2023
4e8b101
Assign the metric vaule for Ipv6 default route learnt via RA message to
abdosi Aug 31, 2023
05ec92a
Merge remote-tracking branch 'upstream/master'
abdosi Sep 8, 2023
fcbd38d
Add alternate name for bridge interface on supversior in chassis systrem
abdosi Sep 8, 2023
76019a7
Merge remote-tracking branch 'upstream/master'
abdosi Sep 8, 2023
311c639
Revert "Add alternate name for bridge interface on supversior in chas…
abdosi Sep 13, 2023
2109e03
ASIC Count is updated to the running numbers of ASIC's and not max
abdosi Sep 13, 2023
ced57e2
Merge remote-tracking branch 'upstream/master' into chassis
abdosi Sep 26, 2023
3cf4697
Enable Seding BGP Community over internal neighbors over iBGP Session
abdosi Sep 26, 2023
5d4fb5d
Revert "ASIC Count is updated to the running numbers of ASIC's and no…
abdosi Sep 26, 2023
4dbfe1c
In Chassis TSA mode Loopback0 Ip's of each should be advertise
abdosi Sep 27, 2023
48ba69f
Merge remote-tracking branch 'upstream/master' into chassis-bgp
abdosi Sep 27, 2023
4f295de
Updated UT
abdosi Sep 27, 2023
6dcf219
Updated UT
abdosi Sep 27, 2023
5457a6c
Added support when TSA is done on Line Card make sure it's completely
abdosi Sep 27, 2023
c38a06e
Added extra UT for chassis-packet.
abdosi Sep 28, 2023
c187ac4
Added extra UT for chassis-packet.
abdosi Sep 28, 2023
c94da05
FIxed UT typo
abdosi Sep 28, 2023
5db9b96
FIxed UT typo
abdosi Sep 28, 2023
16bf96d
Merge branch 'chassis-bgp' into chassis-bgp-2
abdosi Sep 28, 2023
ff5d302
Fixes
abdosi Sep 28, 2023
1146d32
Updated Local Preference to lower value (80) when we get route
abdosi Sep 28, 2023
4762df2
Update TS
abdosi Oct 5, 2023
b97e909
Update TS
abdosi Oct 6, 2023
2722d30
Merge remote-tracking branch 'upstream/master' into chassis-bgp-2
abdosi Nov 22, 2023
cfec119
Update result_chassis_packet_unisolate.conf
abdosi Dec 16, 2023
89e2621
Update result_chassis_packet_isolate.conf
abdosi Dec 16, 2023
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
22 changes: 18 additions & 4 deletions dockers/docker-fpm-frr/TS
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ switch_type=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['switch_type']"`
# Check whether the routemap is for internal BGP sessions.
function is_internal_route_map()
{
[[ "$1" =~ .*"_INTERNAL_".* || "$1" =~ .*"VOQ_".* ]]
if [[ "$1" =~ .*"_INTERNAL_".* || "$1" =~ .*"VOQ_".* ]]
then
return 1
else
return 0
fi
}

function check_not_installed()
Expand All @@ -13,7 +18,10 @@ function check_not_installed()
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p' | egrep 'V4|V6' | uniq);
do
is_internal_route_map $route_map_name && continue
is_internal_route_map $route_map_name
if [[ $? -eq 1 ]]; then
continue
fi
echo "$config" | egrep -q "^route-map $route_map_name permit 20$"
c=$((c+$?))
echo "$config" | egrep -q "^route-map $route_map_name permit 30$"
Expand All @@ -31,7 +39,10 @@ function check_installed()
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p' | egrep 'V4|V6' | uniq);
do
is_internal_route_map $route_map_name && continue
is_internal_route_map $route_map_name
if [[ $? -eq 1 ]]; then
continue
fi
echo "$config" | egrep -q "^route-map $route_map_name permit 20$"
c=$((c+$?))
e=$((e+1))
Expand All @@ -51,7 +62,10 @@ function find_num_routemap()
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p' | egrep 'V4|V6' | uniq);
do
is_internal_route_map $route_map_name && continue
is_internal_route_map $route_map_name
if [[ $? -eq 1 ]]; then
continue
fi
c=$((c+1))
done
return $c
Expand Down
5 changes: 3 additions & 2 deletions dockers/docker-fpm-frr/TSA
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ then
TSA_FILE=$(mktemp)
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p' | uniq);
do
is_internal_route_map $route_map_name && continue
is_internal_route_map $route_map_name
internal_route_map=$?
case "$route_map_name" in
*V4*)
ip_version=V4
Expand All @@ -30,7 +31,7 @@ then
continue
;;
esac
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\", \"ip_protocol\": \"$ip_protocol\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\", \"ip_protocol\": \"$ip_protocol\", \"internal_route_map\": \"$internal_route_map\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
vtysh -f "$TSA_FILE"
rm -f "$TSA_FILE"
done
Expand Down
5 changes: 3 additions & 2 deletions dockers/docker-fpm-frr/TSB
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ then
TSB_FILE=$(mktemp)
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p' | uniq);
do
is_internal_route_map $route_map_name && continue
is_internal_route_map $route_map_name
internal_route_map=$?
case "$route_map_name" in
*V4*)
;;
Expand All @@ -26,7 +27,7 @@ then
continue
;;
esac
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"internal_route_map\": \"$internal_route_map\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
vtysh -f "$TSB_FILE"
rm -f "$TSB_FILE"
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ route-map FROM_BGP_INTERNAL_PEER_V6 permit 2
set originator-id {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
{% elif CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit {{ constants.bgp.internal_community }}
bgp community-list standard NO_EXPORT permit no-export
!
route-map FROM_BGP_INTERNAL_PEER_V4 permit 1
match community DEVICE_INTERNAL_COMMUNITY
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag {{ constants.bgp.internal_community_match_tag }}
!
route-map FROM_BGP_INTERNAL_PEER_V4 permit 2
match community NO_EXPORT
set local-preference 80
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
set ipv6 next-hop prefer-global
on-match next
Expand All @@ -31,6 +36,10 @@ route-map FROM_BGP_INTERNAL_PEER_V6 permit 2
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag {{ constants.bgp.internal_community_match_tag }}
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 3
match community NO_EXPORT
set local-preference 80
!
route-map TO_BGP_INTERNAL_PEER_V4 permit 1
match ip address prefix-list PL_LoopbackV4
set community {{ constants.bgp.internal_community }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
! template: bgpd/templates/voq_chassis/policies.conf.j2
!
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit {{ constants.bgp.internal_community }}
bgp community-list standard NO_EXPORT permit no-export
!
route-map FROM_VOQ_CHASSIS_V4_PEER permit 1
match community DEVICE_INTERNAL_COMMUNITY
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag {{ constants.bgp.internal_community_match_tag }}
!
route-map FROM_VOQ_CHASSIS_V4_PEER permit 2
match community NO_EXPORT
set local-preference 80
!
route-map FROM_VOQ_CHASSIS_V4_PEER permit 100
!
route-map TO_VOQ_CHASSIS_V4_PEER permit 1
Expand All @@ -26,6 +31,10 @@ route-map FROM_VOQ_CHASSIS_V6_PEER permit 2
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag {{ constants.bgp.internal_community_match_tag }}
!
route-map FROM_VOQ_CHASSIS_V6_PEER permit 3
match community NO_EXPORT
set local-preference 80
!
route-map FROM_VOQ_CHASSIS_V6_PEER permit 100
!
route-map TO_VOQ_CHASSIS_V6_PEER permit 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{%- if internal_route_map == '1' -%}
route-map {{ route_map_name }} permit 20
set community no-export additive
{# #}
{%- else -%}
route-map {{ route_map_name }} permit 20
match {{ ip_protocol }} address prefix-list PL_Loopback{{ ip_version }}
set community {{ constants.bgp.traffic_shift_community }}
route-map {{ route_map_name }} permit 30
match tag {{ constants.bgp.internal_community_match_tag }}
set community {{ constants.bgp.traffic_shift_community }}
route-map {{ route_map_name }} deny 40
{# #}
{%- endif -%}
!
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{%- if internal_route_map == '1' -%}
no route-map {{ route_map_name }} permit 20
{# #}
{%- else -%}
no route-map {{ route_map_name }} permit 20
no route-map {{ route_map_name }} permit 30
no route-map {{ route_map_name }} deny 40
{# #}
{%- endif -%}
!
6 changes: 4 additions & 2 deletions src/sonic-bgpcfgd/bgpcfgd/managers_device_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ def __generate_routemaps_from_template(self, route_map_names, template):
# For packet-based chassis, the bgp session between the linecards are also considered internal sessions
# While isolating a single linecard, these sessions should not be skipped
if "_INTERNAL_" in rm or "VOQ_" in rm:
continue
is_internal="1"
else:
is_internal="0"
if "V4" in rm:
ipv="V4" ; ipp="ip"
elif "V6" in rm:
ipv="V6" ; ipp="ipv6"
else:
continue
cmd += template.render(route_map_name=rm,ip_version=ipv,ip_protocol=ipp, constants=self.constants)
cmd += template.render(route_map_name=rm,ip_version=ipv,ip_protocol=ipp,internal_route_map=is_internal, constants=self.constants)
cmd += "\n"
return cmd

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
!
! template: bgpd/templates/internal/peer-group.conf.j2
!
neighbor INTERNAL_PEER_V4 peer-group
neighbor INTERNAL_PEER_V6 peer-group
neighbor INTERNAL_PEER_V4 update-source Loopback4096
address-family ipv4
neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound
neighbor INTERNAL_PEER_V4 allowas-in 1
neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in
neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out
neighbor INTERNAL_PEER_V4 send-community
neighbor INTERNAL_PEER_V4 ttl-security hops 1
exit-address-family
neighbor INTERNAL_PEER_V6 update-source Loopback4096
address-family ipv6
neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound
neighbor INTERNAL_PEER_V6 allowas-in 1
neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in
neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out
neighbor INTERNAL_PEER_V6 send-community
neighbor INTERNAL_PEER_V6 ttl-security hops 1
exit-address-family
!
! end of template: bgpd/templates/internal/peer-group.conf.j2
!


route-map TO_BGP_INTERNAL_PEER_V4 permit 20
set community no-export additive
!
route-map TO_BGP_INTERNAL_PEER_V6 permit 20
set community no-export additive
!

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
!
! template: bgpd/templates/internal/peer-group.conf.j2
!
neighbor INTERNAL_PEER_V4 peer-group
neighbor INTERNAL_PEER_V6 peer-group
neighbor INTERNAL_PEER_V4 update-source Loopback4096
address-family ipv4
neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound
neighbor INTERNAL_PEER_V4 allowas-in 1
neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in
neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out
neighbor INTERNAL_PEER_V4 send-community
neighbor INTERNAL_PEER_V4 ttl-security hops 1
exit-address-family
neighbor INTERNAL_PEER_V6 update-source Loopback4096
address-family ipv6
neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound
neighbor INTERNAL_PEER_V6 allowas-in 1
neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in
neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out
neighbor INTERNAL_PEER_V6 send-community
neighbor INTERNAL_PEER_V6 ttl-security hops 1
exit-address-family
!
! end of template: bgpd/templates/internal/peer-group.conf.j2
!


no route-map TO_BGP_INTERNAL_PEER_V4 permit 20
!
no route-map TO_BGP_INTERNAL_PEER_V6 permit 20
!

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
! template: bgpd/templates/internal/policies.conf.j2
!
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit 12345:556
bgp community-list standard NO_EXPORT permit no-export
!
route-map FROM_BGP_INTERNAL_PEER_V4 permit 1
match community DEVICE_INTERNAL_COMMUNITY
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag 101
!
route-map FROM_BGP_INTERNAL_PEER_V4 permit 2
match community NO_EXPORT
set local-preference 80
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
set ipv6 next-hop prefer-global
on-match next
Expand All @@ -17,6 +22,10 @@ route-map FROM_BGP_INTERNAL_PEER_V6 permit 2
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag 101
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 3
match community NO_EXPORT
set local-preference 80
!
route-map TO_BGP_INTERNAL_PEER_V4 permit 1
match ip address prefix-list PL_LoopbackV4
set community 12345:556
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
! template: bgpd/templates/voq_chassis/policies.conf.j2
!
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit 12345:556
bgp community-list standard NO_EXPORT permit no-export
!
route-map FROM_VOQ_CHASSIS_V4_PEER permit 1
match community DEVICE_INTERNAL_COMMUNITY
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag 101
!
route-map FROM_VOQ_CHASSIS_V4_PEER permit 2
match community NO_EXPORT
set local-preference 80
!
route-map FROM_VOQ_CHASSIS_V4_PEER permit 100
!
route-map TO_VOQ_CHASSIS_V4_PEER permit 1
Expand All @@ -25,6 +30,10 @@ route-map FROM_VOQ_CHASSIS_V6_PEER permit 2
set comm-list DEVICE_INTERNAL_COMMUNITY delete
set tag 101
!
route-map FROM_VOQ_CHASSIS_V6_PEER permit 3
match community NO_EXPORT
set local-preference 80
!
route-map FROM_VOQ_CHASSIS_V6_PEER permit 100
!
route-map TO_VOQ_CHASSIS_V6_PEER permit 1
Expand Down
30 changes: 26 additions & 4 deletions src/sonic-bgpcfgd/tests/test_device_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

TEMPLATE_PATH = os.path.abspath('../../dockers/docker-fpm-frr/frr')
BASE_PATH = os.path.abspath('../sonic-bgpcfgd/tests/data/general/peer-group.conf/')
INTERNAL_BASE_PATH = os.path.abspath('../sonic-bgpcfgd/tests/data/internal/peer-group.conf/')
global_constants = {
"bgp": {
"traffic_shift_community" :"12345:12345",
"internal_community_match_tag" : "1001"
}
}

def constructor():
def constructor(check_internal=False):
cfg_mgr = MagicMock()
def get_text():
text = []
Expand All @@ -29,7 +30,10 @@ def get_text():
text += [" "]
return text
def update():
cfg_mgr.changes = get_string_from_file("/result_all.conf")
if check_internal:
cfg_mgr.changes = get_string_from_file("/result_chasiss_packet.conf", INTERNAL_BASE_PATH)
else:
cfg_mgr.changes = get_string_from_file("/result_all.conf")
def push(cfg):
cfg_mgr.changes += cfg + "\n"
def get_config():
Expand Down Expand Up @@ -59,6 +63,15 @@ def test_isolate_device(mocked_log_info):
mocked_log_info.assert_called_with("DeviceGlobalCfgMgr::Done")
assert m.cfg_mgr.get_config() == get_string_from_file("/result_all_isolate.conf")

@patch('bgpcfgd.managers_device_global.log_debug')
def test_isolate_device_internal_session(mocked_log_info):
m = constructor(check_internal=True)
res = m.set_handler("STATE", {"tsa_enabled": "true"})
assert res, "Expect True return value for set_handler"
mocked_log_info.assert_called_with("DeviceGlobalCfgMgr::Done")
assert m.cfg_mgr.get_config() == get_string_from_file("/result_chassis_packet_isolate.conf", INTERNAL_BASE_PATH)


@patch('bgpcfgd.managers_device_global.log_debug')
def test_unisolate_device(mocked_log_info):
m = constructor()
Expand All @@ -67,6 +80,15 @@ def test_unisolate_device(mocked_log_info):
mocked_log_info.assert_called_with("DeviceGlobalCfgMgr::Done")
assert m.cfg_mgr.get_config() == get_string_from_file("/result_all_unisolate.conf")

@patch('bgpcfgd.managers_device_global.log_debug')
def test_unisolate_device_internal_session(mocked_log_info):
m = constructor(check_internal=True)
res = m.set_handler("STATE", {"tsa_enabled": "false"})
assert res, "Expect True return value for set_handler"
mocked_log_info.assert_called_with("DeviceGlobalCfgMgr::Done")
assert m.cfg_mgr.get_config() == get_string_from_file("/result_chassis_packet_unisolate.conf", INTERNAL_BASE_PATH)


def test_check_state_and_get_tsa_routemaps():
m = constructor()
m.set_handler("STATE", {"tsa_enabled": "true"})
Expand All @@ -93,8 +115,8 @@ def test_get_tsb_routemaps():
expected_res = get_string_from_file("/result_unisolate.conf")
assert res == expected_res

def get_string_from_file(filename):
fp = open(BASE_PATH + filename, "r")
def get_string_from_file(filename, base_path=BASE_PATH):
fp = open(base_path + filename, "r")
cfg = fp.read()
fp.close()

Expand Down