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

[bgp]: Implement Universal Traffic Shift for SONiC #3209

Merged
merged 12 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
6 changes: 6 additions & 0 deletions dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ COPY ["bgpcfgd", "start.sh", "/usr/bin/"]
COPY ["*.j2", "/usr/share/sonic/templates/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["snmp.conf", "/etc/snmp/frr.conf"]
COPY ["TSA", "/usr/bin/TSA"]
COPY ["TSB", "/usr/bin/TSB"]
COPY ["TSC", "/usr/bin/TSC"]
RUN chmod a+x /usr/bin/TSA && \
chmod a+x /usr/bin/TSB && \
chmod a+x /usr/bin/TSC

ENTRYPOINT ["/usr/bin/supervisord"]
23 changes: 23 additions & 0 deletions dockers/docker-fpm-frr/TSA
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
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"
echo "System Mode: Normal -> Maintenance"
else
echo "System is already in Maintenance mode"
fi
24 changes: 24 additions & 0 deletions dockers/docker-fpm-frr/TSB
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
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"

echo "System Mode: Maintenance -> Normal"
else
echo "System is already in Normal mode"
fi
25 changes: 25 additions & 0 deletions dockers/docker-fpm-frr/TSC
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

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+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$(($c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$(($c+$?))

if [[ $c -eq 4 ]];
then
echo "System Mode: Normal"
elif [[ $c -eq 0 ]];
then
echo "System Mode: Maintenance"
else
echo "System Mode: Not consistent"
fi

echo
3 changes: 3 additions & 0 deletions dockers/docker-fpm-frr/base_image_files/TSA
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker exec -i bgp /usr/bin/TSA
3 changes: 3 additions & 0 deletions dockers/docker-fpm-frr/base_image_files/TSB
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker exec -i bgp /usr/bin/TSB
5 changes: 5 additions & 0 deletions dockers/docker-fpm-frr/base_image_files/TSC
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

docker exec -i bgp /usr/bin/TSC

/usr/bin/portstat -p 5
21 changes: 21 additions & 0 deletions dockers/docker-fpm-frr/bgpd.conf.default.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
!
route-map TO_BGP_SPEAKER_V4 deny 10
!
{# generate loopback prefix-lists #}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
ip prefix-list PL_LoopbackV4 permit {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
ipv6 prefix-list PL_LoopbackV6 permit {{ prefix | ip }}/64
{% endif %}
{% endfor %}
!
{# generate default peer route-maps #}
!
route-map TO_BGP_PEER_V4 permit 100
!
route-map TO_BGP_PEER_V6 permit 100
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
!
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
Expand Down Expand Up @@ -57,6 +72,10 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_session.has_key('admin_status') and bgp_session['admin_status'] == 'down' or not bgp_session.has_key('admin_status') and DEVICE_METADATA['localhost'].has_key('default_bgp_status') and DEVICE_METADATA['localhost']['default_bgp_status'] == 'down' %}
neighbor {{ neighbor_addr }} shutdown
{% endif %}
{# Apply default route-map for v4 peers #}
{% if neighbor_addr | ipv4 %}
neighbor {{ neighbor_addr }} route-map TO_BGP_PEER_V4 out
{% endif %}
{% if neighbor_addr | ipv4 %}
address-family ipv4
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
Expand Down Expand Up @@ -89,6 +108,8 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_session['asn'] != DEVICE_METADATA['localhost']['bgp_asn'] %}
neighbor {{ neighbor_addr }} route-map set-next-hop-global-v6 in
{% endif %}
{# Apply default route-map for v6 peers #}
neighbor {{ neighbor_addr }} route-map TO_BGP_PEER_V6 out
maximum-paths 64
exit-address-family
{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion rules/docker-fpm-frr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ $(DOCKER_FPM_FRR)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
$(DOCKER_FPM_FRR)_RUN_OPT += -v /etc/sonic/frr:/etc/frr:rw

$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += vtysh:/usr/bin/vtysh

$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TSA:/usr/bin/TSA
$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TSB:/usr/bin/TSB
$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TSC:/usr/bin/TSC