Skip to content

Commit

Permalink
Changes to make default route programming correct in multi-npu platfo…
Browse files Browse the repository at this point in the history
…rms (#4774)

* Changes to make default route programming
correct in multi-asic platform where frr is not running
in host namespace. Change is to set correct administrative distance.
Also make NAMESPACE* enviroment variable available for all dockers
so that it can be used when needed.

Signed-off-by: Abhishek Dosi <[email protected]>

* Fix review comments

* Review comment to check to add default route
only if default route exist and delete is successful.
  • Loading branch information
abdosi committed Jul 5, 2020
1 parent b6b1f3f commit 75d5e30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 23 additions & 0 deletions dockers/docker-fpm-frr/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ mkdir -p /etc/frr

CONFIG_TYPE=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["docker_routing_config_mode"]'`

if [[ ! -z "$NAMESPACE_ID" ]]; then
# FRR is not running in host namespace so we need to delete
# default gw kernel route added by docker network via eth0 and add it back
# with higher administrative distance so that default route learnt
# by FRR becomes best route if/when available
GATEWAY_IP=$(ip route show 0.0.0.0/0 dev eth0 | awk '{print $3}')
#Check if docker default route is there
if [[ ! -z "$GATEWAY_IP" ]]; then
ip route del 0.0.0.0/0 dev eth0
#Make sure route is deleted
CHECK_GATEWAY_IP=$(ip route show 0.0.0.0/0 dev eth0 | awk '{print $3}')
if [[ -z "$CHECK_GATEWAY_IP" ]]; then
# Ref: http://docs.frrouting.org/en/latest/zebra.html#zebra-vrf
# Zebra does treat Kernel routes as special case for the purposes of Admin Distance. \
# Upon learning about a route that is not originated by FRR we read the metric value as a uint32_t.
# The top byte of the value is interpreted as the Administrative Distance and
# the low three bytes are read in as the metric.
# so here we are programming administrative distance of 210 (210 << 24) > 200 (for routes learnt via IBGP)
ip route add 0.0.0.0/0 via $GATEWAY_IP dev eth0 metric 3523215360
fi
fi
fi

if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
sonic-cfggen -d -t /usr/share/sonic/templates/bgpd/bgpd.conf.j2 -y /etc/sonic/constants.yml > /etc/frr/bgpd.conf
sonic-cfggen -d -t /usr/share/sonic/templates/zebra/zebra.conf.j2 > /etc/frr/zebra.conf
Expand Down
2 changes: 0 additions & 2 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,9 @@ start() {
--tmpfs /tmp \
{%- endif %}
--tmpfs /var/tmp \
{%- if docker_container_name == "database" %}
--env "NAMESPACE_ID"="$DEV" \
--env "NAMESPACE_PREFIX"="$NAMESPACE_PREFIX" \
--env "NAMESPACE_COUNT"=$NUM_ASIC \
{%- endif %}
--name={{docker_container_name}}$DEV {{docker_image_name}}:latest || {
echo "Failed to docker run" >&1
exit 4
Expand Down

0 comments on commit 75d5e30

Please sign in to comment.