From 17f6eb5ae83ee318c000a5bcfdae6d8e66a3bd87 Mon Sep 17 00:00:00 2001 From: shi-su Date: Thu, 20 Aug 2020 19:07:19 +0000 Subject: [PATCH 1/4] Add switch for synchronous mode --- Makefile.work | 2 ++ dockers/docker-orchagent/orchagent.sh | 7 +++++++ files/build_templates/init_cfg.json.j2 | 3 ++- platform/p4/docker-sonic-p4/Dockerfile.j2 | 1 + platform/p4/docker-sonic-p4/init_cfg.json.j2 | 7 +++++++ platform/p4/docker-sonic-p4/orchagent.sh | 6 ++++++ platform/p4/docker-sonic-p4/start.sh | 7 ++++++- platform/vs/docker-sonic-vs/Dockerfile.j2 | 1 + platform/vs/docker-sonic-vs/init_cfg.json.j2 | 7 +++++++ platform/vs/docker-sonic-vs/orchagent.sh | 6 ++++++ platform/vs/docker-sonic-vs/start.sh | 7 ++++++- rules/config | 3 +++ slave.mk | 5 +++++ 13 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 platform/p4/docker-sonic-p4/init_cfg.json.j2 create mode 100644 platform/vs/docker-sonic-vs/init_cfg.json.j2 diff --git a/Makefile.work b/Makefile.work index 4ba02939f991..99e8d85d1b24 100644 --- a/Makefile.work +++ b/Makefile.work @@ -38,6 +38,7 @@ # * SONIC_DPKG_CACHE_METHOD: Specifying method of obtaining the Debian packages from cache: none or cache # * SONIC_DPKG_CACHE_SOURCE: Debian package cache location when cache enabled for debian packages # * BUILD_LOG_TIMESTAMP: Set timestamp in the build log (simple/none) +# * ENABLE_SYNCHRONOUS_MODE: Enable synchronous mode between orchagent and syncd # ############################################################################### @@ -212,6 +213,7 @@ SONIC_BUILD_INSTRUCTION := make \ EXTRA_DOCKER_TARGETS=$(EXTRA_DOCKER_TARGETS) \ BUILD_LOG_TIMESTAMP=$(BUILD_LOG_TIMESTAMP) \ SONIC_ENABLE_IMAGE_SIGNATURE=$(ENABLE_IMAGE_SIGNATURE) \ + ENABLE_SYNCHRONOUS_MODE=$(ENABLE_SYNCHRONOUS_MODE) \ $(SONIC_OVERRIDE_BUILD_VARS) .PHONY: sonic-slave-build sonic-slave-bash init reset diff --git a/dockers/docker-orchagent/orchagent.sh b/dockers/docker-orchagent/orchagent.sh index 8743caea1fb5..0c4ba33253dd 100755 --- a/dockers/docker-orchagent/orchagent.sh +++ b/dockers/docker-orchagent/orchagent.sh @@ -25,6 +25,13 @@ ORCHAGENT_ARGS="-d /var/log/swss " # Set orchagent pop batch size to 8192 ORCHAGENT_ARGS+="-b 8192 " +# Set synchronous mode if it is enabled in CONFIG_DB +SYNC_MODE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.synchronous_mode) +if [ "$SYNC_MODE" == "enable" ]; then + ORCHAGENT_ARGS+="-s " +fi + + # Check if there is an "asic_id field" in the DEVICE_METADATA in configDB. #"DEVICE_METADATA": { # "localhost": { diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index 6db4fa8893d1..23c0b8eb195f 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -2,7 +2,8 @@ "DEVICE_METADATA": { "localhost": { "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, - "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} + "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %}, + "synchronous_mode": {% if enable_synchronous_mode == "y" %}"enable"{% else %}"disable"{% endif %} } }, "CRM": { diff --git a/platform/p4/docker-sonic-p4/Dockerfile.j2 b/platform/p4/docker-sonic-p4/Dockerfile.j2 index 22621b985465..c0063af09bd1 100644 --- a/platform/p4/docker-sonic-p4/Dockerfile.j2 +++ b/platform/p4/docker-sonic-p4/Dockerfile.j2 @@ -78,6 +78,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 ["init_cfg.json", "/etc/sonic/"] RUN echo "docker-sonic-p4" > /etc/hostname RUN touch /etc/quagga/zebra.conf diff --git a/platform/p4/docker-sonic-p4/init_cfg.json.j2 b/platform/p4/docker-sonic-p4/init_cfg.json.j2 new file mode 100644 index 000000000000..a30ea5770dd3 --- /dev/null +++ b/platform/p4/docker-sonic-p4/init_cfg.json.j2 @@ -0,0 +1,7 @@ +{ + "DEVICE_METADATA": { + "localhost": { + "synchronous_mode": {% if enable_synchronous_mode == "y" %}"enable"{% else %}"disable"{% endif %} + } + } +} diff --git a/platform/p4/docker-sonic-p4/orchagent.sh b/platform/p4/docker-sonic-p4/orchagent.sh index 9abfc22c967e..52cdd43265f0 100755 --- a/platform/p4/docker-sonic-p4/orchagent.sh +++ b/platform/p4/docker-sonic-p4/orchagent.sh @@ -13,6 +13,12 @@ ORCHAGENT_ARGS="-d /var/log/swss " # Set orchagent pop batch size to 8192 ORCHAGENT_ARGS+="-b 8192 " +# Set synchronous mode if it is enabled in CONFIG_DB +SYNC_MODE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.synchronous_mode) +if [ "$SYNC_MODE" == "enable" ]; then + ORCHAGENT_ARGS+="-s " +fi + # Set mac address ORCHAGENT_ARGS+="-m $MAC_ADDRESS" diff --git a/platform/p4/docker-sonic-p4/start.sh b/platform/p4/docker-sonic-p4/start.sh index e3251bb2f4e5..b3c451e7c3d4 100755 --- a/platform/p4/docker-sonic-p4/start.sh +++ b/platform/p4/docker-sonic-p4/start.sh @@ -8,7 +8,12 @@ if ! ip link show eth0 &> /dev/null; then fi SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') -sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json +if [ -f /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /tmp/init_cfg.json + mv /tmp/init_cfg.json /etc/sonic/init_cfg.json +else + sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json +fi if [ -f /etc/sonic/config_db.json ]; then sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index e96db2d79ddc..e651e5887187 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -127,6 +127,7 @@ 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/sonic_version.yml", "/etc/sonic/"] +COPY ["init_cfg.json", "/etc/sonic/"] COPY ["database_config.json", "/etc/default/sonic-db/"] COPY ["hostname.j2", "/usr/share/sonic/templates/"] COPY ["default_chassis_cfg.json", "/etc/default/sonic-db/"] diff --git a/platform/vs/docker-sonic-vs/init_cfg.json.j2 b/platform/vs/docker-sonic-vs/init_cfg.json.j2 new file mode 100644 index 000000000000..a30ea5770dd3 --- /dev/null +++ b/platform/vs/docker-sonic-vs/init_cfg.json.j2 @@ -0,0 +1,7 @@ +{ + "DEVICE_METADATA": { + "localhost": { + "synchronous_mode": {% if enable_synchronous_mode == "y" %}"enable"{% else %}"disable"{% endif %} + } + } +} diff --git a/platform/vs/docker-sonic-vs/orchagent.sh b/platform/vs/docker-sonic-vs/orchagent.sh index 2acd709a8e94..a45ab71b87c2 100755 --- a/platform/vs/docker-sonic-vs/orchagent.sh +++ b/platform/vs/docker-sonic-vs/orchagent.sh @@ -19,6 +19,12 @@ ORCHAGENT_ARGS="-d /var/log/swss " # Set orchagent pop batch size to 8192 ORCHAGENT_ARGS+="-b 8192 " +# Set synchronous mode if it is enabled in CONFIG_DB +SYNC_MODE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.synchronous_mode) +if [ "$SYNC_MODE" == "enable" ]; then + ORCHAGENT_ARGS+="-s " +fi + # Set mac address ORCHAGENT_ARGS+="-m $MAC_ADDRESS" diff --git a/platform/vs/docker-sonic-vs/start.sh b/platform/vs/docker-sonic-vs/start.sh index 5b1d462685a3..d4c90300fb22 100755 --- a/platform/vs/docker-sonic-vs/start.sh +++ b/platform/vs/docker-sonic-vs/start.sh @@ -31,7 +31,12 @@ if [[ -f /usr/share/sonic/virtual_chassis/default_config.json ]]; then fi SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') -sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' $CHASS_CFG --print-data > /etc/sonic/init_cfg.json +if [ -f /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' $CHASS_CFG --print-data > /tmp/init_cfg.json + mv /tmp/init_cfg.json /etc/sonic/init_cfg.json +else + sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' $CHASS_CFG --print-data > /etc/sonic/init_cfg.json +fi if [ -f /etc/sonic/config_db.json ]; then sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json diff --git a/rules/config b/rules/config index 1691fd129886..99f70d288fd6 100644 --- a/rules/config +++ b/rules/config @@ -154,3 +154,6 @@ K8s_GCR_IO_PAUSE_VERSION = 3.2 # CA_CERT = # The relative path is build root folder. SONIC_ENABLE_IMAGE_SIGNATURE ?= n + +# ENABLE_SYNCHRONOUS_MODE - enable synchronous mode between orchagent and syncd +ENABLE_SYNCHRONOUS_MODE = n diff --git a/slave.mk b/slave.mk index 83c45aec0bfd..92268663bdd0 100644 --- a/slave.mk +++ b/slave.mk @@ -229,6 +229,7 @@ $(info "INCLUDE_SFLOW" : "$(INCLUDE_SFLOW)") $(info "INCLUDE_NAT" : "$(INCLUDE_NAT)") $(info "INCLUDE_KUBERNETES" : "$(INCLUDE_KUBERNETES)") $(info "TELEMETRY_WRITABLE" : "$(TELEMETRY_WRITABLE)") +$(info "ENABLE_SYNCHRONOUS_MODE" : "$(ENABLE_SYNCHRONOUS_MODE)") $(info ) include Makefile.cache @@ -246,6 +247,7 @@ endif export kernel_procure_method=$(KERNEL_PROCURE_METHOD) export vs_build_prepare_mem=$(VS_PREPARE_MEM) +export enable_synchronous_mode=$(ENABLE_SYNCHRONOUS_MODE) ############################################################################### ## Local targets @@ -694,6 +696,9 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_whls=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_PYTHON_WHEELS)))\n" | awk '!a[$$0]++')) $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_dbgs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DBG_PACKAGES)))\n" | awk '!a[$$0]++')) j2 $($*.gz_PATH)/Dockerfile.j2 > $($*.gz_PATH)/Dockerfile + if [ -f $($*.gz_PATH)/init_cfg.json.j2 ] ; then + j2 $($*.gz_PATH)/init_cfg.json.j2 > $($*.gz_PATH)/init_cfg.json + fi docker info $(LOG) docker build --squash --no-cache \ --build-arg http_proxy=$(HTTP_PROXY) \ From 743af7075814b4b33482d1992d31e2b0fe96d068 Mon Sep 17 00:00:00 2001 From: shi-su Date: Fri, 21 Aug 2020 17:54:12 +0000 Subject: [PATCH 2/4] Update .gitignore to ignore init_cfg.json generated from template --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 307a6cf0ae46..2703a173a476 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,5 @@ platform/broadcom/sonic-platform-modules-dell/s6100/modules/dell_s6100_lpc.c platform/broadcom/sonic-platform-modules-dell/z9100/modules/dell_ich.c platform/broadcom/sonic-platform-modules-dell/z9100/modules/dell_mailbox.c platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/ipmihelper.py +platform/vs/docker-sonic-vs/init_cfg.json +platform/p4/docker-sonic-p4/init_cfg.json From 065c6b08d487a1f22888cdcf13bdf3e61607c227 Mon Sep 17 00:00:00 2001 From: shi-su Date: Fri, 21 Aug 2020 21:22:14 +0000 Subject: [PATCH 3/4] Remove an extra line break --- dockers/docker-orchagent/orchagent.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/dockers/docker-orchagent/orchagent.sh b/dockers/docker-orchagent/orchagent.sh index 0c4ba33253dd..2fd8838cffc7 100755 --- a/dockers/docker-orchagent/orchagent.sh +++ b/dockers/docker-orchagent/orchagent.sh @@ -31,7 +31,6 @@ if [ "$SYNC_MODE" == "enable" ]; then ORCHAGENT_ARGS+="-s " fi - # Check if there is an "asic_id field" in the DEVICE_METADATA in configDB. #"DEVICE_METADATA": { # "localhost": { From b30271963b45a7b32b2c72ba040692cf0f639985 Mon Sep 17 00:00:00 2001 From: shi-su Date: Mon, 24 Aug 2020 00:03:34 +0000 Subject: [PATCH 4/4] Reduce sonic-cfggen usage in orchagent.sh --- dockers/docker-orchagent/orchagent.sh | 2 +- dockers/docker-orchagent/swss_vars.j2 | 3 ++- platform/vs/docker-sonic-vs/orchagent.sh | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dockers/docker-orchagent/orchagent.sh b/dockers/docker-orchagent/orchagent.sh index 2fd8838cffc7..fde5370dc181 100755 --- a/dockers/docker-orchagent/orchagent.sh +++ b/dockers/docker-orchagent/orchagent.sh @@ -26,7 +26,7 @@ ORCHAGENT_ARGS="-d /var/log/swss " ORCHAGENT_ARGS+="-b 8192 " # Set synchronous mode if it is enabled in CONFIG_DB -SYNC_MODE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.synchronous_mode) +SYNC_MODE=$(echo $SWSS_VARS | jq -r '.synchronous_mode') if [ "$SYNC_MODE" == "enable" ]; then ORCHAGENT_ARGS+="-s " fi diff --git a/dockers/docker-orchagent/swss_vars.j2 b/dockers/docker-orchagent/swss_vars.j2 index 0a0b2712f46a..cb96aa826f6b 100644 --- a/dockers/docker-orchagent/swss_vars.j2 +++ b/dockers/docker-orchagent/swss_vars.j2 @@ -1,6 +1,7 @@ { "asic_type": "{{ asic_type }}", "asic_id": "{{ DEVICE_METADATA.localhost.asic_id }}", - "mac": "{{ DEVICE_METADATA.localhost.mac }}" + "mac": "{{ DEVICE_METADATA.localhost.mac }}", + "synchronous_mode": "{{ DEVICE_METADATA.localhost.synchronous_mode }}" } diff --git a/platform/vs/docker-sonic-vs/orchagent.sh b/platform/vs/docker-sonic-vs/orchagent.sh index a45ab71b87c2..ec703fa10ee6 100755 --- a/platform/vs/docker-sonic-vs/orchagent.sh +++ b/platform/vs/docker-sonic-vs/orchagent.sh @@ -6,7 +6,8 @@ else export platform=$fake_platform fi -MAC_ADDRESS=$(sonic-cfggen -d -v 'DEVICE_METADATA.localhost.mac') +CFG_VARS=$(sonic-cfggen -d --var-json 'DEVICE_METADATA') +MAC_ADDRESS=$(echo $CFG_VARS | jq -r '.localhost.mac') if [ "$MAC_ADDRESS" == "None" ] || [ -z "$MAC_ADDRESS" ]; then MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') logger "Mac address not found in Device Metadata, Falling back to eth0" @@ -20,7 +21,7 @@ ORCHAGENT_ARGS="-d /var/log/swss " ORCHAGENT_ARGS+="-b 8192 " # Set synchronous mode if it is enabled in CONFIG_DB -SYNC_MODE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.synchronous_mode) +SYNC_MODE=$(echo $CFG_VARS | jq -r '.localhost.synchronous_mode') if [ "$SYNC_MODE" == "enable" ]; then ORCHAGENT_ARGS+="-s " fi