From ad88700912ecb5855b7a8ca61d23ae323b5a773d Mon Sep 17 00:00:00 2001 From: judyjoseph <53951155+judyjoseph@users.noreply.github.com> Date: Fri, 12 Feb 2021 10:56:44 -0800 Subject: [PATCH] [docker-fpm-frr]: TSA/B/C changes for multi-asic (#6510) - Introduced TS common file in docker as well and moved common functions. - TSA/B/C scripts run only in BGP instances for front end ASICs. In addition skip enforcing it on route maps used between internal BGP sessions. admin@str--acs-1:~$ sudo /usr/bin/TSA System Mode: Normal -> Maintenance and in case of Multi-ASIC admin@str--acs-1:~$ sudo /usr/bin/TSA BGP0 : System Mode: Normal -> Maintenance BGP1 : System Mode: Normal -> Maintenance BGP2 : System Mode: Normal -> Maintenance --- dockers/docker-fpm-frr/Dockerfile.j2 | 1 + dockers/docker-fpm-frr/TS | 40 +++++++++++++++++++++ dockers/docker-fpm-frr/TSA | 16 ++------- dockers/docker-fpm-frr/TSB | 19 ++-------- dockers/docker-fpm-frr/TSC | 36 ++----------------- dockers/docker-fpm-frr/base_image_files/TS | 29 +++++++++++++++ dockers/docker-fpm-frr/base_image_files/TSA | 2 +- dockers/docker-fpm-frr/base_image_files/TSB | 2 +- dockers/docker-fpm-frr/base_image_files/TSC | 2 +- rules/docker-fpm-frr.mk | 1 + 10 files changed, 82 insertions(+), 66 deletions(-) create mode 100755 dockers/docker-fpm-frr/TS create mode 100755 dockers/docker-fpm-frr/base_image_files/TS diff --git a/dockers/docker-fpm-frr/Dockerfile.j2 b/dockers/docker-fpm-frr/Dockerfile.j2 index 360d64a12b82..42df1c6f38f8 100644 --- a/dockers/docker-fpm-frr/Dockerfile.j2 +++ b/dockers/docker-fpm-frr/Dockerfile.j2 @@ -53,6 +53,7 @@ COPY ["snmp.conf", "/etc/snmp/frr.conf"] COPY ["TSA", "/usr/bin/TSA"] COPY ["TSB", "/usr/bin/TSB"] COPY ["TSC", "/usr/bin/TSC"] +COPY ["TS", "/usr/bin/TS"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["zsocket.sh", "/usr/bin/"] RUN chmod a+x /usr/bin/TSA && \ diff --git a/dockers/docker-fpm-frr/TS b/dockers/docker-fpm-frr/TS new file mode 100755 index 000000000000..78ba24d5db63 --- /dev/null +++ b/dockers/docker-fpm-frr/TS @@ -0,0 +1,40 @@ +#!/bin/bash + +# Check whether the routemap is for internal BGP sessions. +function is_internal_route_map() +{ + [[ "$1" =~ .*"_INTERNAL_".* ]] +} + +function check_not_installed() +{ + c=0 + 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'); + do + is_internal_route_map $route_map_name && continue + echo "$config" | egrep -q "^route-map $route_map_name permit 20$" + c=$((c+$?)) + echo "$config" | egrep -q "^route-map $route_map_name deny 30$" + c=$((c+$?)) + done + return $c +} + +function check_installed() +{ + c=0 + e=0 + 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'); + do + is_internal_route_map $route_map_name && continue + echo "$config" | egrep -q "^route-map $route_map_name permit 20$" + c=$((c+$?)) + e=$((e+1)) + echo "$config" | egrep -q "^route-map $route_map_name deny 30$" + c=$((c+$?)) + e=$((e+1)) + done + return $((e-c)) +} diff --git a/dockers/docker-fpm-frr/TSA b/dockers/docker-fpm-frr/TSA index 524e4297d1c0..6312bf0ba5e6 100755 --- a/dockers/docker-fpm-frr/TSA +++ b/dockers/docker-fpm-frr/TSA @@ -1,18 +1,7 @@ #!/bin/bash -function check_not_installed() -{ - c=0 - config=$(vtysh -c "show run") - for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); - do - echo "$config" | egrep -q "^route-map $route_map_name permit 20$" - c=$((c+$?)) - echo "$config" | egrep -q "^route-map $route_map_name deny 30$" - c=$((c+$?)) - done - return $c -} +# Load the common functions +source /usr/bin/TS check_not_installed not_installed=$? @@ -21,6 +10,7 @@ then TSA_FILE=$(mktemp) for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); do + is_internal_route_map $route_map_name && continue case "$route_map_name" in *V4*) ip_version=V4 diff --git a/dockers/docker-fpm-frr/TSB b/dockers/docker-fpm-frr/TSB index 8592ad76cf69..44f9b15aea27 100755 --- a/dockers/docker-fpm-frr/TSB +++ b/dockers/docker-fpm-frr/TSB @@ -1,21 +1,7 @@ #!/bin/bash -function check_installed() -{ - c=0 - e=0 - config=$(vtysh -c "show run") - for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); - do - echo "$config" | egrep -q "^route-map $route_map_name permit 20$" - c=$((c+$?)) - e=$((e+1)) - echo "$config" | egrep -q "^route-map $route_map_name deny 30$" - c=$((c+$?)) - e=$((e+1)) - done - return $((e-c)) -} +# Load the common functions +source /usr/bin/TS check_installed installed=$? @@ -24,6 +10,7 @@ then TSB_FILE=$(mktemp) for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); do + is_internal_route_map $route_map_name && continue case "$route_map_name" in *V4*) ;; diff --git a/dockers/docker-fpm-frr/TSC b/dockers/docker-fpm-frr/TSC index c7fd8a2ff157..a0e908439e41 100755 --- a/dockers/docker-fpm-frr/TSC +++ b/dockers/docker-fpm-frr/TSC @@ -1,37 +1,7 @@ #!/bin/bash -function check_not_installed() -{ - c=0 - 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'); - do - echo "$config" | egrep -q "^route-map $route_map_name permit 20$" - c=$((c+$?)) - echo "$config" | egrep -q "^route-map $route_map_name deny 30$" - c=$((c+$?)) - done - return $c -} - -function check_installed() -{ - c=0 - e=0 - 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'); - do - echo "$config" | egrep -q "^route-map $route_map_name permit 20$" - c=$((c+$?)) - e=$((e+1)) - echo "$config" | egrep -q "^route-map $route_map_name deny 30$" - c=$((c+$?)) - e=$((e+1)) - done - return $((e-c)) -} - -echo "Traffic Shift Check:" +# Load the common functions +source /usr/bin/TS check_not_installed not_installed=$? @@ -48,5 +18,3 @@ then else echo "System Mode: Not consistent" fi - -echo diff --git a/dockers/docker-fpm-frr/base_image_files/TS b/dockers/docker-fpm-frr/base_image_files/TS new file mode 100755 index 000000000000..de1e50b7a306 --- /dev/null +++ b/dockers/docker-fpm-frr/base_image_files/TS @@ -0,0 +1,29 @@ +#!/bin/bash + +# 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 + # Run TSA/TSB/TSC scripts in BGP instance for frontend ASICs. + sub_role=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['sub_role']" -n $NAMESPACE_PREFIX$asic` + if [ $sub_role == 'FrontEnd' ] + then + echo -e "BGP"$asic" : \c" + docker exec -i bgp$asic /usr/bin/$1 + fi + asic=$[$asic+1] + done +else + docker exec -i bgp /usr/bin/$1 +fi diff --git a/dockers/docker-fpm-frr/base_image_files/TSA b/dockers/docker-fpm-frr/base_image_files/TSA index 95c7957f7dc1..e96c76dd67b2 100755 --- a/dockers/docker-fpm-frr/base_image_files/TSA +++ b/dockers/docker-fpm-frr/base_image_files/TSA @@ -1,3 +1,3 @@ #!/bin/bash -docker exec -i bgp /usr/bin/TSA +/usr/bin/TS TSA diff --git a/dockers/docker-fpm-frr/base_image_files/TSB b/dockers/docker-fpm-frr/base_image_files/TSB index f292d2031db3..176b10c684c8 100755 --- a/dockers/docker-fpm-frr/base_image_files/TSB +++ b/dockers/docker-fpm-frr/base_image_files/TSB @@ -1,3 +1,3 @@ #!/bin/bash -docker exec -i bgp /usr/bin/TSB +/usr/bin/TS TSB diff --git a/dockers/docker-fpm-frr/base_image_files/TSC b/dockers/docker-fpm-frr/base_image_files/TSC index b8136ae4f4c3..09d1409c50c7 100755 --- a/dockers/docker-fpm-frr/base_image_files/TSC +++ b/dockers/docker-fpm-frr/base_image_files/TSC @@ -1,5 +1,5 @@ #!/bin/bash -docker exec -i bgp /usr/bin/TSC +/usr/bin/TS TSC portstat -p 5 diff --git a/rules/docker-fpm-frr.mk b/rules/docker-fpm-frr.mk index d4aace307a19..1ea79bc80a42 100644 --- a/rules/docker-fpm-frr.mk +++ b/rules/docker-fpm-frr.mk @@ -30,4 +30,5 @@ $(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 +$(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TS:/usr/bin/TS $(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += monit_bgp:/etc/monit/conf.d