Skip to content

Commit

Permalink
[TSA]: Add community to the loopback prefix, when isolated (sonic-net…
Browse files Browse the repository at this point in the history
…#3708)

* Rename asn/deployment_id_asn_map.yaml to constants/constants.yaml

* Fix bgp templates

* Add community for loopback when bgpd is isolated

* Use correct community value
  • Loading branch information
pavel-shirshov authored and zhenggen-xu committed Jan 9, 2020
1 parent 3ab1ebb commit 3cd68d0
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 29 deletions.
16 changes: 8 additions & 8 deletions dockers/docker-fpm-frr/TSA
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$(($c+$?))
c=$((c+$?))

if [[ $c -eq 4 ]];
then
vtysh -c "configure terminal" -c "route-map TO_BGP_PEER_V4 permit 2" -c "match ip address prefix-list PL_LoopbackV4"
vtysh -c "configure terminal" -c "route-map TO_BGP_PEER_V4 deny 3"
vtysh -c "configure terminal" -c "route-map TO_BGP_PEER_V6 permit 2" -c "match ipv6 address prefix-list PL_LoopbackV6"
vtysh -c "configure terminal" -c "route-map TO_BGP_PEER_V6 deny 3"
TSA_FILE=$(mktemp)
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
vtysh -f "$TSA_FILE"
rm -f "$TSA_FILE"
echo "System Mode: Normal -> Maintenance"
else
echo "System is already in Maintenance mode"
Expand Down
17 changes: 8 additions & 9 deletions dockers/docker-fpm-frr/TSB
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$(($c+$?))
c=$((c+$?))

if [[ $c -eq 0 ]];
then
vtysh -c "configure terminal" -c "no route-map TO_BGP_PEER_V4 deny 3"
vtysh -c "configure terminal" -c "no route-map TO_BGP_PEER_V4 permit 2"
vtysh -c "configure terminal" -c "no route-map TO_BGP_PEER_V6 deny 3"
vtysh -c "configure terminal" -c "no route-map TO_BGP_PEER_V6 permit 2"

TSB_FILE=$(mktemp)
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
vtysh -f "$TSB_FILE"
rm -f "$TSB_FILE"
echo "System Mode: Maintenance -> Normal"
else
echo "System is already in Normal mode"
Expand Down
8 changes: 4 additions & 4 deletions dockers/docker-fpm-frr/TSC
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ echo "Traffic Shift Check:"
c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$(($c+$?))
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$(($c+$?))
c=$((c+$?))

if [[ $c -eq 4 ]];
then
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-fpm-frr/bgpd.conf.default.j2
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_peer['peer_asn'] is defined %}
neighbor {{ bgp_peer['name'] }} remote-as {{ bgp_peer['peer_asn'] }}
{% else %}
neighbor {{ bgp_peer['name'] }} remote-as {{ deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }}
neighbor {{ bgp_peer['name'] }} remote-as {{ constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }}
{% endif %}
neighbor {{ bgp_peer['name'] }} ebgp-multihop 255
neighbor {{ bgp_peer['name'] }} soft-reconfiguration inbound
Expand Down
10 changes: 10 additions & 0 deletions dockers/docker-fpm-frr/bgpd.tsa.isolate.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
route-map TO_BGP_PEER_V4 permit 2
match ip address prefix-list PL_LoopbackV4
set community {{ constants.traffic_shift_community }}
route-map TO_BGP_PEER_V4 deny 3
!
route-map TO_BGP_PEER_V6 permit 2
match ipv6 address prefix-list PL_LoopbackV6
set community {{ constants.traffic_shift_community }}
route-map TO_BGP_PEER_V6 deny 3
!
6 changes: 6 additions & 0 deletions dockers/docker-fpm-frr/bgpd.tsa.unisolate.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
no route-map TO_BGP_PEER_V4 permit 2
no route-map TO_BGP_PEER_V4 deny 3
!
no route-map TO_BGP_PEER_V6 permit 2
no route-map TO_BGP_PEER_V6 deny 3
!
4 changes: 2 additions & 2 deletions dockers/docker-fpm-frr/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ mkdir -p /etc/frr
CONFIG_TYPE=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["docker_routing_config_mode"]'`

if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
sonic-cfggen -d -y /etc/sonic/deployment_id_asn_map.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/frr/bgpd.conf
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/frr/bgpd.conf
sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/frr/zebra.conf
sonic-cfggen -d -t /usr/share/sonic/templates/staticd.conf.j2 > /etc/frr/staticd.conf
echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/frr.conf
elif [ "$CONFIG_TYPE" == "unified" ]; then
sonic-cfggen -d -y /etc/sonic/deployment_id_asn_map.yml -t /usr/share/sonic/templates/frr.conf.j2 >/etc/frr/frr.conf
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/frr.conf.j2 >/etc/frr/frr.conf
echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf
fi
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-fpm-quagga/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_peer['peer_asn'] is defined %}
neighbor {{ bgp_peer['name'] }} remote-as {{ bgp_peer['peer_asn'] }}
{% else %}
neighbor {{ bgp_peer['name'] }} remote-as {{ deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }}
neighbor {{ bgp_peer['name'] }} remote-as {{ constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }}
{% endif %}
neighbor {{ bgp_peer['name'] }} ebgp-multihop 255
neighbor {{ bgp_peer['name'] }} soft-reconfiguration inbound
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-fpm-quagga/start.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

mkdir -p /etc/quagga
sonic-cfggen -d -y /etc/sonic/deployment_id_asn_map.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/quagga/bgpd.conf
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/quagga/bgpd.conf

sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/quagga/zebra.conf

Expand Down
2 changes: 1 addition & 1 deletion files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ sudo bash -c "echo '{ \"DEVICE_METADATA\": { \"localhost\": { \"default_bgp_stat
sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/

# Copy ASN configuration files
sudo cp $IMAGE_CONFIGS/asn/deployment_id_asn_map.yml $FILESYSTEM_ROOT/etc/sonic/
sudo cp $IMAGE_CONFIGS/constants/constants.yml $FILESYSTEM_ROOT/etc/sonic/

# Copy sudoers configuration file
sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/
Expand Down
2 changes: 0 additions & 2 deletions files/image_config/asn/deployment_id_asn_map.yml

This file was deleted.

4 changes: 4 additions & 0 deletions files/image_config/constants/constants.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
constants:
deployment_id_asn_map:
"1" : 65432
traffic_shift_community: 12345:12345

0 comments on commit 3cd68d0

Please sign in to comment.