Skip to content

Commit d2d0d54

Browse files
shi-susanthosh-kt
authored andcommitted
Add switch for synchronous mode (sonic-net#5237)
Add a master switch so that the sync/async mode can be configured. Example usage of the switch: 1. Configure mode while building an image `make ENABLE_SYNCHRONOUS_MODE=y <target>` 2. Configure when the device is running Change CONFIG_DB with `sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"synchronous_mode": "enable"}}}' --write-to-db` Restart swss with `systemctl restart swss`
1 parent 1d33e51 commit d2d0d54

File tree

15 files changed

+64
-5
lines changed

15 files changed

+64
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ platform/broadcom/sonic-platform-modules-dell/s6100/modules/dell_s6100_lpc.c
6060
platform/broadcom/sonic-platform-modules-dell/z9100/modules/dell_ich.c
6161
platform/broadcom/sonic-platform-modules-dell/z9100/modules/dell_mailbox.c
6262
platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/ipmihelper.py
63+
platform/vs/docker-sonic-vs/init_cfg.json
64+
platform/p4/docker-sonic-p4/init_cfg.json

Makefile.work

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# * SONIC_DPKG_CACHE_METHOD: Specifying method of obtaining the Debian packages from cache: none or cache
3939
# * SONIC_DPKG_CACHE_SOURCE: Debian package cache location when cache enabled for debian packages
4040
# * BUILD_LOG_TIMESTAMP: Set timestamp in the build log (simple/none)
41+
# * ENABLE_SYNCHRONOUS_MODE: Enable synchronous mode between orchagent and syncd
4142
#
4243
###############################################################################
4344

@@ -212,6 +213,7 @@ SONIC_BUILD_INSTRUCTION := make \
212213
EXTRA_DOCKER_TARGETS=$(EXTRA_DOCKER_TARGETS) \
213214
BUILD_LOG_TIMESTAMP=$(BUILD_LOG_TIMESTAMP) \
214215
SONIC_ENABLE_IMAGE_SIGNATURE=$(ENABLE_IMAGE_SIGNATURE) \
216+
ENABLE_SYNCHRONOUS_MODE=$(ENABLE_SYNCHRONOUS_MODE) \
215217
$(SONIC_OVERRIDE_BUILD_VARS)
216218

217219
.PHONY: sonic-slave-build sonic-slave-bash init reset

dockers/docker-orchagent/orchagent.sh

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ ORCHAGENT_ARGS="-d /var/log/swss "
2525
# Set orchagent pop batch size to 8192
2626
ORCHAGENT_ARGS+="-b 8192 "
2727

28+
# Set synchronous mode if it is enabled in CONFIG_DB
29+
SYNC_MODE=$(echo $SWSS_VARS | jq -r '.synchronous_mode')
30+
if [ "$SYNC_MODE" == "enable" ]; then
31+
ORCHAGENT_ARGS+="-s "
32+
fi
33+
2834
# Check if there is an "asic_id field" in the DEVICE_METADATA in configDB.
2935
#"DEVICE_METADATA": {
3036
# "localhost": {

dockers/docker-orchagent/swss_vars.j2

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"asic_type": "{{ asic_type }}",
33
"asic_id": "{{ DEVICE_METADATA.localhost.asic_id }}",
4-
"mac": "{{ DEVICE_METADATA.localhost.mac }}"
4+
"mac": "{{ DEVICE_METADATA.localhost.mac }}",
5+
"synchronous_mode": "{{ DEVICE_METADATA.localhost.synchronous_mode }}"
56
}
67

files/build_templates/init_cfg.json.j2

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"DEVICE_METADATA": {
33
"localhost": {
44
"default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %},
5-
"default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %}
5+
"default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %},
6+
"synchronous_mode": {% if enable_synchronous_mode == "y" %}"enable"{% else %}"disable"{% endif %}
67
}
78
},
89
"CRM": {

platform/p4/docker-sonic-p4/Dockerfile.j2

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ COPY ["start.sh", "orchagent.sh", "config_bm.sh", "/usr/bin/"]
7878
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
7979
COPY ["files/configdb-load.sh", "/usr/bin/"]
8080
COPY ["files/arp_update", "/usr/bin"]
81+
COPY ["init_cfg.json", "/etc/sonic/"]
8182
RUN echo "docker-sonic-p4" > /etc/hostname
8283
RUN touch /etc/quagga/zebra.conf
8384

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"DEVICE_METADATA": {
3+
"localhost": {
4+
"synchronous_mode": {% if enable_synchronous_mode == "y" %}"enable"{% else %}"disable"{% endif %}
5+
}
6+
}
7+
}

platform/p4/docker-sonic-p4/orchagent.sh

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ ORCHAGENT_ARGS="-d /var/log/swss "
1313
# Set orchagent pop batch size to 8192
1414
ORCHAGENT_ARGS+="-b 8192 "
1515

16+
# Set synchronous mode if it is enabled in CONFIG_DB
17+
SYNC_MODE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.synchronous_mode)
18+
if [ "$SYNC_MODE" == "enable" ]; then
19+
ORCHAGENT_ARGS+="-s "
20+
fi
21+
1622
# Set mac address
1723
ORCHAGENT_ARGS+="-m $MAC_ADDRESS"
1824

platform/p4/docker-sonic-p4/start.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ if ! ip link show eth0 &> /dev/null; then
88
fi
99

1010
SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
11-
sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json
11+
if [ -f /etc/sonic/init_cfg.json ]; then
12+
sonic-cfggen -j /etc/sonic/init_cfg.json -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /tmp/init_cfg.json
13+
mv /tmp/init_cfg.json /etc/sonic/init_cfg.json
14+
else
15+
sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json
16+
fi
1217

1318
if [ -f /etc/sonic/config_db.json ]; then
1419
sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json

platform/vs/docker-sonic-vs/Dockerfile.j2

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ COPY ["files/configdb-load.sh", "/usr/bin/"]
128128
COPY ["files/arp_update", "/usr/bin/"]
129129
COPY ["files/buffers_config.j2", "files/qos_config.j2", "/usr/share/sonic/templates/"]
130130
COPY ["files/sonic_version.yml", "/etc/sonic/"]
131+
COPY ["init_cfg.json", "/etc/sonic/"]
131132
COPY ["database_config.json", "/etc/default/sonic-db/"]
132133
COPY ["hostname.j2", "/usr/share/sonic/templates/"]
133134
COPY ["default_chassis_cfg.json", "/etc/default/sonic-db/"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"DEVICE_METADATA": {
3+
"localhost": {
4+
"synchronous_mode": {% if enable_synchronous_mode == "y" %}"enable"{% else %}"disable"{% endif %}
5+
}
6+
}
7+
}

platform/vs/docker-sonic-vs/orchagent.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ else
66
export platform=$fake_platform
77
fi
88

9-
MAC_ADDRESS=$(sonic-cfggen -d -v 'DEVICE_METADATA.localhost.mac')
9+
CFG_VARS=$(sonic-cfggen -d --var-json 'DEVICE_METADATA')
10+
MAC_ADDRESS=$(echo $CFG_VARS | jq -r '.localhost.mac')
1011
if [ "$MAC_ADDRESS" == "None" ] || [ -z "$MAC_ADDRESS" ]; then
1112
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
1213
logger "Mac address not found in Device Metadata, Falling back to eth0"
@@ -19,6 +20,12 @@ ORCHAGENT_ARGS="-d /var/log/swss "
1920
# Set orchagent pop batch size to 8192
2021
ORCHAGENT_ARGS+="-b 8192 "
2122

23+
# Set synchronous mode if it is enabled in CONFIG_DB
24+
SYNC_MODE=$(echo $CFG_VARS | jq -r '.localhost.synchronous_mode')
25+
if [ "$SYNC_MODE" == "enable" ]; then
26+
ORCHAGENT_ARGS+="-s "
27+
fi
28+
2229
# Set mac address
2330
ORCHAGENT_ARGS+="-m $MAC_ADDRESS"
2431

platform/vs/docker-sonic-vs/start.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ if [[ -f /usr/share/sonic/virtual_chassis/default_config.json ]]; then
3131
fi
3232

3333
SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
34-
sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' $CHASS_CFG --print-data > /etc/sonic/init_cfg.json
34+
if [ -f /etc/sonic/init_cfg.json ]; then
35+
sonic-cfggen -j /etc/sonic/init_cfg.json -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' $CHASS_CFG --print-data > /tmp/init_cfg.json
36+
mv /tmp/init_cfg.json /etc/sonic/init_cfg.json
37+
else
38+
sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' $CHASS_CFG --print-data > /etc/sonic/init_cfg.json
39+
fi
3540

3641
if [ -f /etc/sonic/config_db.json ]; then
3742
sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json

rules/config

+3
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,6 @@ K8s_GCR_IO_PAUSE_VERSION = 3.2
158158
# CA_CERT =
159159
# The relative path is build root folder.
160160
SONIC_ENABLE_IMAGE_SIGNATURE ?= n
161+
162+
# ENABLE_SYNCHRONOUS_MODE - enable synchronous mode between orchagent and syncd
163+
ENABLE_SYNCHRONOUS_MODE = n

slave.mk

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ $(info "INCLUDE_SFLOW" : "$(INCLUDE_SFLOW)")
230230
$(info "INCLUDE_NAT" : "$(INCLUDE_NAT)")
231231
$(info "INCLUDE_KUBERNETES" : "$(INCLUDE_KUBERNETES)")
232232
$(info "TELEMETRY_WRITABLE" : "$(TELEMETRY_WRITABLE)")
233+
$(info "ENABLE_SYNCHRONOUS_MODE" : "$(ENABLE_SYNCHRONOUS_MODE)")
233234
$(info )
234235

235236
include Makefile.cache
@@ -247,6 +248,7 @@ endif
247248

248249
export kernel_procure_method=$(KERNEL_PROCURE_METHOD)
249250
export vs_build_prepare_mem=$(VS_PREPARE_MEM)
251+
export enable_synchronous_mode=$(ENABLE_SYNCHRONOUS_MODE)
250252

251253
###############################################################################
252254
## Local targets
@@ -695,6 +697,9 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform
695697
$(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_whls=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_PYTHON_WHEELS)))\n" | awk '!a[$$0]++'))
696698
$(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_dbgs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DBG_PACKAGES)))\n" | awk '!a[$$0]++'))
697699
j2 $($*.gz_PATH)/Dockerfile.j2 > $($*.gz_PATH)/Dockerfile
700+
if [ -f $($*.gz_PATH)/init_cfg.json.j2 ] ; then
701+
j2 $($*.gz_PATH)/init_cfg.json.j2 > $($*.gz_PATH)/init_cfg.json
702+
fi
698703
docker info $(LOG)
699704
docker build --squash --no-cache \
700705
--build-arg http_proxy=$(HTTP_PROXY) \

0 commit comments

Comments
 (0)