From a3801054614ea48451da3d33282a3b61c73897f0 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:50:16 -0700 Subject: [PATCH] Enable ARP Update Script for Packet based chassis. (#11465) What I did: Following changes done for packet based chassis:- 1> Run arp_update on LC's to resolve static route nexthops over backend port-channel interfaces. 2> On Supervisor make sure arp_update exit gracefully --- dockers/docker-orchagent/docker-init.j2 | 9 +++++--- files/build_templates/arp_update_vars.j2 | 4 +++- files/scripts/arp_update | 28 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/dockers/docker-orchagent/docker-init.j2 b/dockers/docker-orchagent/docker-init.j2 index d0a3ef9e2d..4cd6a53a11 100755 --- a/dockers/docker-orchagent/docker-init.j2 +++ b/dockers/docker-orchagent/docker-init.j2 @@ -21,7 +21,7 @@ CFGGEN_PARAMS=" \ -t /usr/share/sonic/templates/wait_for_link.sh.j2,/usr/bin/wait_for_link.sh \ " VLAN=$(sonic-cfggen $CFGGEN_PARAMS) - +SWITCH_TYPE=${SWITCH_TYPE:-`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['switch_type']"`} chmod +x /usr/bin/wait_for_link.sh # Executed platform specific initialization tasks. @@ -34,9 +34,12 @@ if [ -x /usr/share/sonic/hwsku/hwsku-init ]; then /usr/share/sonic/hwsku/hwsku-init fi -# Start arp_update and NDP proxy daemon when VLAN exists -if [ "$VLAN" != "" ]; then +# Start arp update when VLAN exists or switch type as chassis packet for backend port channel interfaces +if [[ "$VLAN" != "" ]] || [[ "$SWITCH_TYPE" == "chassis-packet" ]]; then cp /usr/share/sonic/templates/arp_update.conf /etc/supervisor/conf.d/ +fi + +if [ "$VLAN" != "" ]; then cp /usr/share/sonic/templates/ndppd.conf /etc/supervisor/conf.d/ fi diff --git a/files/build_templates/arp_update_vars.j2 b/files/build_templates/arp_update_vars.j2 index 3cdfa81023..91992e781a 100644 --- a/files/build_templates/arp_update_vars.j2 +++ b/files/build_templates/arp_update_vars.j2 @@ -1,6 +1,8 @@ { + "switch_type": "{% if DEVICE_METADATA and 'localhost' in DEVICE_METADATA and 'switch_type' in DEVICE_METADATA['localhost'] %}{{ DEVICE_METADATA['localhost']['switch_type'] }}{%endif %}", "interface": "{% for (name, prefix) in INTERFACE|pfx_filter %}{% if prefix|ipv6 %}{{ name }} {% endif %}{% endfor %}", "pc_interface" : "{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}{% if prefix|ipv6 %}{{ name }} {% endif %}{% endfor %}", "vlan_sub_interface": "{% for (name, prefix) in VLAN_SUB_INTERFACE|pfx_filter %}{% if prefix|ipv6 %}{{ name }} {% endif %}{% endfor %}", - "vlan" : "{% if VLAN %}{{ VLAN.keys() | join(' ') }}{% endif %}" + "vlan" : "{% if VLAN %}{{ VLAN.keys() | join(' ') }}{% endif %}", + "static_route_nexthops": "{% if STATIC_ROUTE %}{% for static_route_prefix, static_route_attr in STATIC_ROUTE.items() %}{%- if static_route_prefix -%}{{ static_route_attr['nexthop'].split(',') | join(' ') | lower + " " }}{%- endif -%}{% endfor %}{% endif %}" } diff --git a/files/scripts/arp_update b/files/scripts/arp_update index e7f083e20d..2f66fc84b3 100755 --- a/files/scripts/arp_update +++ b/files/scripts/arp_update @@ -12,6 +12,34 @@ ARP_UPDATE_VARS_FILE="/usr/share/sonic/templates/arp_update_vars.j2" while /bin/true; do # find L3 interfaces which are UP, send ipv6 multicast pings ARP_UPDATE_VARS=$(sonic-cfggen -d -t ${ARP_UPDATE_VARS_FILE}) + SWITCH_TYPE=$(echo $ARP_UPDATE_VARS | jq -r '.switch_type') + if [[ "$SWITCH_TYPE" == "chassis-packet" ]]; then + STATIC_ROUTE_NEXTHOPS=$(echo $ARP_UPDATE_VARS | jq -r '.static_route_nexthops') + # on supervisor/rp exit the script gracefully + if [[ -z "$STATIC_ROUTE_NEXTHOPS" ]]; then + logger "arp_update: exiting as no static route in packet based chassis" + exit 0 + fi + for nexthop in $STATIC_ROUTE_NEXTHOPS; do + if [[ $nexthop == *"."* ]]; then + neigh_state=( $(ip -4 neigh show | grep $nexthop | tr -s ' ' | cut -d ' ' -f 3,4) ) + ping_prefix=ping + elif [[ $nexthop == *":"* ]] ; then + neigh_state=( $(ip -6 neigh show | grep $nexthop | tr -s ' ' | cut -d ' ' -f 3,4) ) + ping_prefix=ping6 + fi + + if [[ "${neigh_state[1]}" == "INCOMPLETE" ]] || [[ "${neigh_state[1]}" == "FAILED" ]]; then + pingcmd="timeout 0.2 $ping_prefix -I ${neigh_state[0]} -n -q -i 0 -c 1 -W 1 $nexthop >/dev/null" + eval $pingcmd + logger "arp_update: sttaic route nexthop not resolved, pinging $nexthop on ${neigh_state[0]}" + fi + done + + sleep 300 + continue + fi + # find L3 interfaces which are UP, send ipv6 multicast pings INTERFACE=$(echo $ARP_UPDATE_VARS | jq -r '.interface') PC_INTERFACE=$(echo $ARP_UPDATE_VARS | jq -r '.pc_interface') VLAN_SUB_INTERFACE=$(echo $ARP_UPDATE_VARS | jq -r '.vlan_sub_interface')