From 12d4ebd3519c0580415930f26e5390ecd75fea62 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Mon, 23 Nov 2020 09:31:42 -0800 Subject: [PATCH] Copp Manager Changes (#4861) *Introduce CoPP Manager infrastructure Copp service to generate initial copp config template file Co-authored-by: dgsudharsan --- .../base_image_files/monit_swss | 4 + dockers/docker-orchagent/copp.json.j2 | 85 -------------- dockers/docker-orchagent/critical_processes | 1 + dockers/docker-orchagent/docker-init.sh | 1 - dockers/docker-orchagent/supervisord.conf | 12 ++ dockers/docker-orchagent/swssconfig.sh | 2 +- files/build_templates/docker_image_ctl.j2 | 2 +- .../build_templates/sonic_debian_extension.j2 | 6 + files/image_config/copp/copp-config.service | 11 ++ files/image_config/copp/copp-config.sh | 3 + files/image_config/copp/copp_cfg.j2 | 105 ++++++++++++++++++ platform/vs/docker-sonic-vs.mk | 3 +- platform/vs/docker-sonic-vs/Dockerfile.j2 | 2 +- platform/vs/docker-sonic-vs/start.sh | 3 + platform/vs/docker-sonic-vs/supervisord.conf | 8 ++ rules/scripts.dep | 1 + rules/scripts.mk | 6 +- 17 files changed, 164 insertions(+), 91 deletions(-) delete mode 100644 dockers/docker-orchagent/copp.json.j2 create mode 100755 files/image_config/copp/copp-config.service create mode 100755 files/image_config/copp/copp-config.sh create mode 100755 files/image_config/copp/copp_cfg.j2 diff --git a/dockers/docker-orchagent/base_image_files/monit_swss b/dockers/docker-orchagent/base_image_files/monit_swss index da601011e735..7557bd66ac9a 100644 --- a/dockers/docker-orchagent/base_image_files/monit_swss +++ b/dockers/docker-orchagent/base_image_files/monit_swss @@ -11,6 +11,7 @@ ## buffermgrd ## nbrmgrd ## vxlanmgrd +## coppmgrd ############################################################################## check program swss|orchagent with path "/usr/bin/process_checker swss /usr/bin/orchagent -d /var/log/swss" if status != 0 for 5 times within 5 cycles then alert repeat every 1 cycles @@ -41,3 +42,6 @@ check program swss|nbrmgrd with path "/usr/bin/process_checker swss /usr/bin/nbr check program swss|vxlanmgrd with path "/usr/bin/process_checker swss /usr/bin/vxlanmgrd" if status != 0 for 5 times within 5 cycles then alert repeat every 1 cycles + +check program swss|coppmgrd with path "/usr/bin/process_checker swss /usr/bin/coppmgrd" + if status != 0 for 5 times within 5 cycles then alert repeat every 1 cycles diff --git a/dockers/docker-orchagent/copp.json.j2 b/dockers/docker-orchagent/copp.json.j2 deleted file mode 100644 index 49173a54e99f..000000000000 --- a/dockers/docker-orchagent/copp.json.j2 +++ /dev/null @@ -1,85 +0,0 @@ -[ - { - "COPP_TABLE:default": { - "queue": "0", - "meter_type":"packets", - "mode":"sr_tcm", - "cir":"600", - "cbs":"600", - "red_action":"drop" - }, - "OP": "SET" - }, - { - "COPP_TABLE:trap.group.bgp.lacp": { - "trap_ids": "bgp,bgpv6,lacp", - "trap_action":"trap", - "trap_priority":"4", - "queue": "4" - }, - "OP": "SET" - }, - { - "COPP_TABLE:trap.group.arp": { - "trap_ids": "arp_req,arp_resp,neigh_discovery", - "trap_action":"copy", - "trap_priority":"4", - "queue": "4", - "meter_type":"packets", - "mode":"sr_tcm", - "cir":"600", - "cbs":"600", - "red_action":"drop" - }, - "OP": "SET" - }, -{% if DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != "ToRRouter" %} - { - "COPP_TABLE:trap.group.lldp.udld": { - "trap_ids": "lldp,udld", - "trap_action":"trap", - "trap_priority":"4", - "queue": "4" - }, - "OP": "SET" - }, -{% else %} - { - "COPP_TABLE:trap.group.lldp.dhcp.dhcpv6.udld": { - "trap_ids": "lldp,dhcp,dhcpv6,udld", - "trap_action":"trap", - "trap_priority":"4", - "queue": "4" - }, - "OP": "SET" - }, -{% endif %} - { - "COPP_TABLE:trap.group.ip2me": { - "trap_ids": "ip2me", - "trap_action":"trap", - "trap_priority":"1", - "queue": "1", - "meter_type":"packets", - "mode":"sr_tcm", - "cir":"6000", - "cbs":"6000", - "red_action":"drop" - }, - "OP": "SET" - }, - { - "COPP_TABLE:trap.group.nat": { - "trap_ids": "src_nat_miss,dest_nat_miss", - "trap_action":"trap", - "trap_priority":"1", - "queue": "1", - "meter_type":"packets", - "mode":"sr_tcm", - "cir":"600", - "cbs":"600", - "red_action":"drop" - }, - "OP": "SET" - } -] diff --git a/dockers/docker-orchagent/critical_processes b/dockers/docker-orchagent/critical_processes index 99f501e2cc03..809693684c80 100644 --- a/dockers/docker-orchagent/critical_processes +++ b/dockers/docker-orchagent/critical_processes @@ -8,3 +8,4 @@ program:buffermgrd program:vrfmgrd program:nbrmgrd program:vxlanmgrd +program:coppmgrd diff --git a/dockers/docker-orchagent/docker-init.sh b/dockers/docker-orchagent/docker-init.sh index d128422938ee..5bf5bf2d06cf 100755 --- a/dockers/docker-orchagent/docker-init.sh +++ b/dockers/docker-orchagent/docker-init.sh @@ -8,7 +8,6 @@ CFGGEN_PARAMS=" \ -t /usr/share/sonic/templates/switch.json.j2,/etc/swss/config.d/switch.json \ -t /usr/share/sonic/templates/ipinip.json.j2,/etc/swss/config.d/ipinip.json \ -t /usr/share/sonic/templates/ports.json.j2,/etc/swss/config.d/ports.json \ - -t /usr/share/sonic/templates/copp.json.j2,/etc/swss/config.d/00-copp.config.json \ -t /usr/share/sonic/templates/vlan_vars.j2 \ -t /usr/share/sonic/templates/ndppd.conf.j2,/etc/ndppd.conf \ " diff --git a/dockers/docker-orchagent/supervisord.conf b/dockers/docker-orchagent/supervisord.conf index 8ec2b6354ab3..8a942d8549c0 100644 --- a/dockers/docker-orchagent/supervisord.conf +++ b/dockers/docker-orchagent/supervisord.conf @@ -83,6 +83,18 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=swssconfig:exited +[program:coppmgrd] +command=/usr/bin/coppmgrd +priority=6 +autostart=false +autorestart=unexpected +startretries=0 +startsecs=0 +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=orchagent:running + [program:neighsyncd] command=/usr/bin/neighsyncd priority=7 diff --git a/dockers/docker-orchagent/swssconfig.sh b/dockers/docker-orchagent/swssconfig.sh index 276132a7ef29..0081d074ad60 100755 --- a/dockers/docker-orchagent/swssconfig.sh +++ b/dockers/docker-orchagent/swssconfig.sh @@ -52,7 +52,7 @@ if [[ "$SYSTEM_WARM_START" == "true" ]] || [[ "$SWSS_WARM_START" == "true" ]]; t exit 0 fi -SWSSCONFIG_ARGS="00-copp.config.json ipinip.json ports.json switch.json " +SWSSCONFIG_ARGS="ipinip.json ports.json switch.json " for file in $SWSSCONFIG_ARGS; do swssconfig /etc/swss/config.d/$file diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 3766dc918bab..477fd897bff5 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -138,7 +138,7 @@ function postStartAction() if [[ -x /usr/local/bin/db_migrator.py ]]; then # Migrate the DB to the latest schema version if needed if [ -z "$DEV" ]; then - /usr/bin/db_migrator.py -o migrate + /usr/local/bin/db_migrator.py -o migrate fi fi # Add redis UDS to the redis group and give read/write access to the group diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 00c0d9bbc525..82fb75d6c058 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -330,6 +330,12 @@ sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ echo "interfaces-config.service" | sudo tee -a $GENERATED_SERVICE_FILE +# Copy CoPP configuration files and templates +sudo cp $IMAGE_CONFIGS/copp/copp-config.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM +sudo cp $IMAGE_CONFIGS/copp/copp-config.sh $FILESYSTEM_ROOT/usr/bin/ +sudo cp $IMAGE_CONFIGS/copp/copp_cfg.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ +echo "copp-config.service" | sudo tee -a $GENERATED_SERVICE_FILE + # Copy dhcp client configuration template and create an initial configuration sudo cp files/dhcp/dhclient.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ j2 files/dhcp/dhclient.conf.j2 | sudo tee $FILESYSTEM_ROOT/etc/dhcp/dhclient.conf diff --git a/files/image_config/copp/copp-config.service b/files/image_config/copp/copp-config.service new file mode 100755 index 000000000000..8eed2353eddf --- /dev/null +++ b/files/image_config/copp/copp-config.service @@ -0,0 +1,11 @@ +[Unit] +Description=Update CoPP configuration +Requires=updategraph.service +After=updategraph.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/copp-config.sh + +[Install] +WantedBy=multi-user.target diff --git a/files/image_config/copp/copp-config.sh b/files/image_config/copp/copp-config.sh new file mode 100755 index 000000000000..0660528a54da --- /dev/null +++ b/files/image_config/copp/copp-config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sonic-cfggen -d -t /usr/share/sonic/templates/copp_cfg.j2 > /etc/sonic/copp_cfg.json diff --git a/files/image_config/copp/copp_cfg.j2 b/files/image_config/copp/copp_cfg.j2 new file mode 100755 index 000000000000..61f051f43de8 --- /dev/null +++ b/files/image_config/copp/copp_cfg.j2 @@ -0,0 +1,105 @@ +{ + "COPP_GROUP": { + "default": { + "queue": "0", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"600", + "cbs":"600", + "red_action":"drop" + }, + "queue4_group1": { + "trap_action":"trap", + "trap_priority":"4", + "queue": "4" + }, + "queue4_group2": { + "trap_action":"copy", + "trap_priority":"4", + "queue": "4", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"600", + "cbs":"600", + "red_action":"drop" + }, + "queue4_group3": { + "trap_action":"trap", + "trap_priority":"4", + "queue": "4" + }, + "queue1_group1": { + "trap_action":"trap", + "trap_priority":"1", + "queue": "1", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"6000", + "cbs":"6000", + "red_action":"drop" + }, + "queue1_group2": { + "trap_action":"trap", + "trap_priority":"1", + "queue": "1", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"600", + "cbs":"600", + "red_action":"drop" + }, + "queue2_group1": { + "cbs": "1000", + "cir": "1000", + "genetlink_mcgrp_name": "packets", + "genetlink_name": "psample", + "meter_type": "packets", + "mode": "sr_tcm", + "queue": "2", + "red_action": "drop", + "trap_action": "trap", + "trap_priority": "1" + + } + }, + "COPP_TRAP": { + "bgp": { + "trap_ids": "bgp,bgpv6", + "trap_group": "queue4_group1" + }, + "lacp": { + "trap_ids": "lacp", + "trap_group": "queue4_group1" + }, + "arp": { + "trap_ids": "arp_req,arp_resp,neigh_discovery", + "trap_group": "queue4_group2" + }, + "lldp": { + "trap_ids": "lldp", + "trap_group": "queue4_group3" + }, +{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != "ToRRouter") %} + "dhcp": { + "trap_ids": "dhcp,dhcpv6", + "trap_group": "queue4_group3" + }, +{% endif %} + "udld": { + "trap_ids": "udld", + "trap_group": "queue4_group3" + }, + "ip2me": { + "trap_ids": "ip2me", + "trap_group": "queue1_group1" + }, + "nat": { + "trap_ids": "src_nat_miss,dest_nat_miss", + "trap_group": "queue1_group2" + }, + "sflow": { + "trap_group": "queue2_group1", + "trap_ids": "sample_packet" + } + } +} diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index 875b649adc39..299ca7c14c13 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -48,7 +48,8 @@ $(DOCKER_SONIC_VS)_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(BUFFERS_CONFIG_TEMPLATE) \ $(QOS_CONFIG_TEMPLATE) \ $(SONIC_VERSION) \ - $(UPDATE_CHASSISDB_CONFIG_SCRIPT) + $(UPDATE_CHASSISDB_CONFIG_SCRIPT) \ + $(COPP_CONFIG_TEMPLATE) $(DOCKER_SONIC_VS)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) SONIC_DOCKER_IMAGES += $(DOCKER_SONIC_VS) diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index 50996e36e191..054446e525b0 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -143,7 +143,7 @@ COPY ["start.sh", "orchagent.sh", "files/update_chassisdb_config", "/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", "files/arp_update_vars.j2", "/usr/share/sonic/templates/"] +COPY ["files/buffers_config.j2", "files/qos_config.j2", "files/arp_update_vars.j2", "files/copp_cfg.j2", "/usr/share/sonic/templates/"] COPY ["files/sonic_version.yml", "/etc/sonic/"] COPY ["database_config.json", "/etc/default/sonic-db/"] COPY ["hostname.j2", "/usr/share/sonic/templates/"] diff --git a/platform/vs/docker-sonic-vs/start.sh b/platform/vs/docker-sonic-vs/start.sh index 349c538e1daf..ed668983c835 100755 --- a/platform/vs/docker-sonic-vs/start.sh +++ b/platform/vs/docker-sonic-vs/start.sh @@ -46,6 +46,7 @@ else sed -i "s/up/down/g" /tmp/ports.json sonic-cfggen -j /etc/sonic/init_cfg.json -j /tmp/buffers.json -j /tmp/qos.json -j /tmp/ports.json --print-data > /etc/sonic/config_db.json fi +sonic-cfggen -t /usr/share/sonic/templates/copp_cfg.j2 > /etc/sonic/copp_cfg.json mkdir -p /etc/swss/config.d/ @@ -94,6 +95,8 @@ supervisorctl start portsyncd supervisorctl start orchagent +supervisorctl start coppmgrd + supervisorctl start neighsyncd supervisorctl start teamsyncd diff --git a/platform/vs/docker-sonic-vs/supervisord.conf b/platform/vs/docker-sonic-vs/supervisord.conf index 79baead76765..09f9c34b14b4 100644 --- a/platform/vs/docker-sonic-vs/supervisord.conf +++ b/platform/vs/docker-sonic-vs/supervisord.conf @@ -59,6 +59,14 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog +[program:coppmgrd] +command=/usr/bin/coppmgrd +priority=7 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog + [program:neighsyncd] command=/usr/bin/neighsyncd priority=8 diff --git a/rules/scripts.dep b/rules/scripts.dep index 677a60c2ae47..929611852ea4 100644 --- a/rules/scripts.dep +++ b/rules/scripts.dep @@ -7,3 +7,4 @@ $(BUFFERS_CONFIG_TEMPLATE)_CACHE_MODE := none $(UPDATE_PROC_VARIABLES_SCRIPT)_CACHE_MODE := none $(QOS_CONFIG_TEMPLATE)_CACHE_MODE := none $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT)_CACHE_MODE := none +$(COPP_CONFIG_TEMPLATE)_CACHE_MODE := none diff --git a/rules/scripts.mk b/rules/scripts.mk index af160adcfa9c..0fdd0cf44462 100644 --- a/rules/scripts.mk +++ b/rules/scripts.mk @@ -26,6 +26,9 @@ $(UPDATE_CHASSISDB_CONFIG_SCRIPT)_PATH = files/scripts SWSS_VARS_TEMPLATE = swss_vars.j2 $(SWSS_VARS_TEMPLATE)_PATH = files/build_templates +COPP_CONFIG_TEMPLATE = copp_cfg.j2 +$(COPP_CONFIG_TEMPLATE)_PATH = files/image_config/copp + SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(ARP_UPDATE_SCRIPT) \ $(ARP_UPDATE_VARS_TEMPLATE) \ @@ -35,4 +38,5 @@ SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(SYSCTL_NET_CONFIG) $(SYSCTL_NET_CONFIG) \ $(UPDATE_CHASSISDB_CONFIG_SCRIPT) \ - $(SWSS_VARS_TEMPLATE) + $(SWSS_VARS_TEMPLATE) \ + $(COPP_CONFIG_TEMPLATE)