Skip to content

[bgp] Save admin state and set default state to shutdown #689

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
46 changes: 46 additions & 0 deletions dockers/docker-fpm-quagga/base_image_files/bgp_neighbor
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash -e

usage(){
echo "Usage: $0 <shutdown|startup> <neighbor_ip>"
exit 255
}

[[ $# -ne 2 ]] && usage

COMMAND=$1
NEIGHBOR_IP=$2

if [ "$COMMAND" == "shutdown" ]; then
CMD_PREFIX=""
elif [ "$COMMAND" == "startup" ]; then
CMD_PREFIX="no"
else
usage
fi

ASN=`vtysh -c "show ip bgp su" | sed -n "s/.*AS number \([0-9]\+\).*/\1/p"`
if [ -z "$ASN" ]; then
exit 255
fi

[ -f /etc/sonic/bgp_admin.yml ] || echo "bgp_admin_state:" > /etc/sonic/bgp_admin.yml

if [ "$NEIGHBOR_IP" == "0.0.0.0" ] ; then
for NEIGHBOR in `vtysh -c "show run" | grep nei | grep -oE "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | sort | uniq`; do
vtysh -c "configure terminal" -c "router bgp $ASN" -c "$CMD_PREFIX neighbor $NEIGHBOR shutdown"

# Save admin state in config file
sed -i "/^\s*$NEIGHBOR:/d" /etc/sonic/bgp_admin.yml
[ "$COMMAND" == "shutdown" ] || echo " $NEIGHBOR: on" >> /etc/sonic/bgp_admin.yml
done

else
# Examine bgp neighbor exists first
vtysh -c "show ip bgp neighbor $NEIGHBOR_IP" | grep -q "BGP neighbor is"

vtysh -c "configure terminal" -c "router bgp $ASN" -c "$CMD_PREFIX neighbor $NEIGHBOR_IP shutdown"

# Save admin state in config file
sed -i "/^\s*$NEIGHBOR_IP:/d" /etc/sonic/bgp_admin.yml
[ "$COMMAND" == "shutdown" ] || echo " $NEIGHBOR_IP: on" >> /etc/sonic/bgp_admin.yml
fi
3 changes: 3 additions & 0 deletions dockers/docker-fpm-quagga/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ router bgp {{ minigraph_bgp_asn }}
{% if bgp_session['asn'] != 0 %}
neighbor {{ bgp_session['addr'] }} remote-as {{ bgp_session['asn'] }}
neighbor {{ bgp_session['addr'] }} description {{ bgp_session['name'] }}
{% if not bgp_admin_state or not bgp_admin_state[bgp_session['addr']] %}
neighbor {{ bgp_session['addr'] }} shutdown
{% endif %}
{% if minigraph_devices[inventory_hostname]['type'] == 'ToRRouter' %}
neighbor {{ bgp_session['addr'] }} allowas-in 1
{% endif %}
Expand Down
6 changes: 5 additions & 1 deletion dockers/docker-fpm-quagga/config.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

mkdir -p /etc/quagga
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/bgpd.conf.j2 >/etc/quagga/bgpd.conf
if [ -f /etc/sonic/bgp_admin.yml ]; then
sonic-cfggen -m /etc/sonic/minigraph.xml -y /etc/sonic/bgp_admin.yml -t /usr/share/sonic/templates/bgpd.conf.j2 >/etc/quagga/bgpd.conf
else
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/bgpd.conf.j2 >/etc/quagga/bgpd.conf
fi
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/zebra.conf.j2 >/etc/quagga/zebra.conf

sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isolate.j2 >/usr/sbin/bgp-isolate
Expand Down
1 change: 1 addition & 0 deletions rules/docker-fpm-quagga.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ $(DOCKER_FPM_QUAGGA)_RUN_OPT += --net=host --privileged -t
$(DOCKER_FPM_QUAGGA)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro

$(DOCKER_FPM_QUAGGA)_BASE_IMAGE_FILES += vtysh:/usr/bin/vtysh
$(DOCKER_FPM_QUAGGA)_BASE_IMAGE_FILES += bgp_neighbor:/usr/bin/bgp_neighbor