From 89b739cb347bb8d3c66c0ad7aa570ac4c3da0885 Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Fri, 18 Sep 2020 18:44:23 -0700 Subject: [PATCH] [swss] Enhance ARP Update to Call Sonic Cfggen Once (#5398) This PR limited the number of calls to sonic-cfggen to one call per iteration instead of current 3 calls per iteration. The PR also installs jq on host for future scripts if needed. signed-off-by: Tamer Ahmed --- build_debian.sh | 3 ++- dockers/docker-orchagent/Dockerfile.j2 | 2 +- files/build_templates/arp_update_vars.j2 | 5 +++++ files/scripts/arp_update | 11 ++++++----- platform/p4/docker-sonic-p4.mk | 3 ++- platform/p4/docker-sonic-p4/Dockerfile.j2 | 2 ++ platform/vs/docker-sonic-vs.mk | 1 + platform/vs/docker-sonic-vs/Dockerfile.j2 | 2 +- rules/docker-orchagent.mk | 2 +- rules/scripts.mk | 4 ++++ 10 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 files/build_templates/arp_update_vars.j2 diff --git a/build_debian.sh b/build_debian.sh index 5c00a2c93986..5aba3202f1e3 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -301,7 +301,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in ipmitool \ ndisc6 \ makedumpfile \ - conntrack + conntrack \ + jq if [[ $CONFIGURED_ARCH == amd64 ]]; then diff --git a/dockers/docker-orchagent/Dockerfile.j2 b/dockers/docker-orchagent/Dockerfile.j2 index 0b208f5feef1..810bf9de71bc 100755 --- a/dockers/docker-orchagent/Dockerfile.j2 +++ b/dockers/docker-orchagent/Dockerfile.j2 @@ -63,7 +63,7 @@ RUN apt-get clean -y && \ rm -rf /debs COPY ["files/arp_update", "/usr/bin"] -COPY ["arp_update.conf", "/usr/share/sonic/templates/"] +COPY ["arp_update.conf", "files/arp_update_vars.j2", "/usr/share/sonic/templates/"] COPY ["enable_counters.py", "/usr/bin"] COPY ["docker-init.sh", "orchagent.sh", "swssconfig.sh", "/usr/bin/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] diff --git a/files/build_templates/arp_update_vars.j2 b/files/build_templates/arp_update_vars.j2 new file mode 100644 index 000000000000..b9315b5ebe50 --- /dev/null +++ b/files/build_templates/arp_update_vars.j2 @@ -0,0 +1,5 @@ +{ + "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" : "{% if VLAN %}{{ VLAN.keys() | join(' ') }}{% endif %}" +} diff --git a/files/scripts/arp_update b/files/scripts/arp_update index 3cc9cd267985..2fec40c14beb 100755 --- a/files/scripts/arp_update +++ b/files/scripts/arp_update @@ -7,12 +7,13 @@ # Send gratuitous ARP/NDP requests to VLAN member neighbors to refresh # the ipv4/ipv6 neighbors state. +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 - echo "{% for (name, prefix) in INTERFACE|pfx_filter %} {{name}} {% endfor %}" > /tmp/intf_tmp.j2 - INTERFACE=`sonic-cfggen -d -t /tmp/intf_tmp.j2` - echo "{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} {{name}} {% endfor %}" > /tmp/pc_intf_tmp.j2 - PC_INTERFACE=`sonic-cfggen -d -t /tmp/pc_intf_tmp.j2` + ARP_UPDATE_VARS=$(sonic-cfggen -d -t ${ARP_UPDATE_VARS_FILE}) + INTERFACE=$(echo $ARP_UPDATE_VARS | jq -r '.interface') + PC_INTERFACE=$(echo $ARP_UPDATE_VARS | jq -r '.pc_interface') ALL_INTERFACE="$INTERFACE $PC_INTERFACE" for intf in $ALL_INTERFACE; do @@ -23,7 +24,7 @@ while /bin/true; do fi done - VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'` + VLAN=$(echo $ARP_UPDATE_VARS | jq -r '.vlan') for vlan in $VLAN; do # generate a list of arping commands: # arping -q -w 0 -c 1 -i ; diff --git a/platform/p4/docker-sonic-p4.mk b/platform/p4/docker-sonic-p4.mk index 534d161631f5..301d4791fdc6 100644 --- a/platform/p4/docker-sonic-p4.mk +++ b/platform/p4/docker-sonic-p4.mk @@ -23,7 +23,8 @@ $(DOCKER_SONIC_P4)_DEPENDS += $(QUAGGA) # endif $(DOCKER_SONIC_P4)_FILES += $(CONFIGDB_LOAD_SCRIPT) \ - $(ARP_UPDATE_SCRIPT) + $(ARP_UPDATE_SCRIPT) \ + $(ARP_UPDATE_VARS_TEMPLATE) $(DOCKER_SONIC_P4)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE) SONIC_DOCKER_IMAGES += $(DOCKER_SONIC_P4) diff --git a/platform/p4/docker-sonic-p4/Dockerfile.j2 b/platform/p4/docker-sonic-p4/Dockerfile.j2 index 0f918821dea2..7cba39cb4077 100644 --- a/platform/p4/docker-sonic-p4/Dockerfile.j2 +++ b/platform/p4/docker-sonic-p4/Dockerfile.j2 @@ -16,6 +16,7 @@ RUN apt-get install -y net-tools \ ethtool \ tcpdump \ ifupdown \ + jq \ bridge-utils \ python-ply \ libqt5core5a \ @@ -79,6 +80,7 @@ COPY ["start.sh", "orchagent.sh", "config_bm.sh", "/usr/bin/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/configdb-load.sh", "/usr/bin/"] COPY ["files/arp_update", "/usr/bin"] +COPY ["files/arp_update_vars.j2", "/usr/share/sonic/templates/"] RUN echo "docker-sonic-p4" > /etc/hostname RUN touch /etc/quagga/zebra.conf diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index 41d8e0f12176..88586d3455fa 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -34,6 +34,7 @@ endif $(DOCKER_SONIC_VS)_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(ARP_UPDATE_SCRIPT) \ + $(ARP_UPDATE_VARS_TEMPLATE) \ $(BUFFERS_CONFIG_TEMPLATE) \ $(QOS_CONFIG_TEMPLATE) \ $(SONIC_VERSION) diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index ee3858aca647..2e1042b6c813 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -106,7 +106,7 @@ COPY ["start.sh", "orchagent.sh", "/usr/bin/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/configdb-load.sh", "/usr/bin/"] COPY ["files/arp_update", "/usr/bin/"] -COPY ["files/buffers_config.j2", "files/qos_config.j2", "/usr/share/sonic/templates/"] +COPY ["files/buffers_config.j2", "files/qos_config.j2", "files/arp_update_vars.j2", "/usr/share/sonic/templates/"] COPY ["files/sonic_version.yml", "/etc/sonic/"] COPY ["database_config.json", "/etc/default/sonic-db/"] diff --git a/rules/docker-orchagent.mk b/rules/docker-orchagent.mk index bab1a3a29920..c59bb4a22be9 100644 --- a/rules/docker-orchagent.mk +++ b/rules/docker-orchagent.mk @@ -35,4 +35,4 @@ $(DOCKER_ORCHAGENT)_RUN_OPT += -v /var/log/swss:/var/log/swss:rw $(DOCKER_ORCHAGENT)_BASE_IMAGE_FILES += swssloglevel:/usr/bin/swssloglevel $(DOCKER_ORCHAGENT)_BASE_IMAGE_FILES += monit_swss:/etc/monit/conf.d -$(DOCKER_ORCHAGENT)_FILES += $(ARP_UPDATE_SCRIPT) $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) +$(DOCKER_ORCHAGENT)_FILES += $(ARP_UPDATE_SCRIPT) $(ARP_UPDATE_VARS_TEMPLATE) $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) diff --git a/rules/scripts.mk b/rules/scripts.mk index b3ed0cab95f8..8788438e7696 100644 --- a/rules/scripts.mk +++ b/rules/scripts.mk @@ -2,6 +2,9 @@ ARP_UPDATE_SCRIPT = arp_update $(ARP_UPDATE_SCRIPT)_PATH = files/scripts +ARP_UPDATE_VARS_TEMPLATE = arp_update_vars.j2 +$(ARP_UPDATE_VARS_TEMPLATE)_PATH = files/build_templates + CONFIGDB_LOAD_SCRIPT = configdb-load.sh $(CONFIGDB_LOAD_SCRIPT)_PATH = files/scripts @@ -19,6 +22,7 @@ $(SYSCTL_NET_CONFIG)_PATH = files/image_config/sysctl SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(ARP_UPDATE_SCRIPT) \ + $(ARP_UPDATE_VARS_TEMPLATE) \ $(BUFFERS_CONFIG_TEMPLATE) \ $(QOS_CONFIG_TEMPLATE) \ $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) \