Skip to content

Commit

Permalink
[frrcfgd] introduce frrcfgd to manage frr config when frr_mgmt_framew…
Browse files Browse the repository at this point in the history
…ork_config is true (#5142)

- Support for non-template based FRR configurations (BGP, route-map, OSPF, static route..etc) using config DB schema.
- Support for save & restore - Jinja template based config-DB data read and apply to FRR during startup

**- How I did it**

- add frrcfgd service
- when frr_mgmg_framework_config is set, frrcfgd starts in bgp container
- when user changed the BGP or other related table entries in config DB, frrcfgd will run corresponding VTYSH commands to program on FRR.
- add jinja template to generate FRR config file to be used by FRR daemons while bgp container restarted

**- How to verify it**
1. Add/delete data on config DB and then run VTYSH "show running-config" command to check if FRR configuration changed.
1. Restart bgp container and check if generated FRR config file is correct and run VTYSH "show running-config" command to check if FRR configuration is consistent with attributes in config DB

Co-authored-by: Zhenhong Zhao <zhenhong.zhao@dell.com>
  • Loading branch information
2 people authored and lguohan committed Jan 25, 2021
1 parent 7e2b755 commit 154a6ab
Show file tree
Hide file tree
Showing 42 changed files with 5,976 additions and 14 deletions.
1 change: 0 additions & 1 deletion dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ COPY ["TSA", "/usr/bin/TSA"]
COPY ["TSB", "/usr/bin/TSB"]
COPY ["TSC", "/usr/bin/TSC"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["critical_processes", "/etc/supervisor"]
COPY ["bgpd.sh", "/usr/bin/"]
RUN chmod a+x /usr/bin/TSA && \
chmod a+x /usr/bin/TSB && \
Expand Down
5 changes: 0 additions & 5 deletions dockers/docker-fpm-frr/critical_processes

This file was deleted.

22 changes: 16 additions & 6 deletions dockers/docker-fpm-frr/docker_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ mkdir -p /etc/supervisor/conf.d
CFGGEN_PARAMS=" \
-d \
-y /etc/sonic/constants.yml \
-t /usr/share/sonic/templates/supervisord/frr_vars.j2 \
-t /usr/share/sonic/templates/frr_vars.j2 \
-t /usr/share/sonic/templates/supervisord/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
-t /usr/share/sonic/templates/bgpd/bgpd.conf.j2,/etc/frr/bgpd.conf \
-t /usr/share/sonic/templates/bgpd/gen_bgpd.conf.j2,/etc/frr/bgpd.conf \
-t /usr/share/sonic/templates/supervisord/critical_processes.j2,/etc/supervisor/critical_processes \
-t /usr/share/sonic/templates/zebra/zebra.conf.j2,/etc/frr/zebra.conf \
-t /usr/share/sonic/templates/staticd/staticd.conf.j2,/etc/frr/staticd.conf \
-t /usr/share/sonic/templates/frr.conf.j2,/etc/frr/frr.conf \
-t /usr/share/sonic/templates/staticd/gen_staticd.conf.j2,/etc/frr/staticd.conf \
-t /usr/share/sonic/templates/gen_frr.conf.j2,/etc/frr/frr.conf \
-t /usr/share/sonic/templates/isolate.j2,/usr/sbin/bgp-isolate \
-t /usr/share/sonic/templates/unisolate.j2,/usr/sbin/bgp-unisolate \
-t /usr/local/sonic/frrcfgd/bfdd.conf.j2,/etc/frr/bfdd.conf \
-t /usr/local/sonic/frrcfgd/ospfd.conf.j2,/etc/frr/ospfd.conf \
"
CONFIG_TYPE=$(sonic-cfggen $CFGGEN_PARAMS)

FRR_VARS=$(sonic-cfggen $CFGGEN_PARAMS)
MGMT_FRAMEWORK_CONFIG=$(echo $FRR_VARS | jq -r '.frr_mgmt_framework_config')
CONFIG_TYPE=$(echo $FRR_VARS | jq -r '.docker_routing_config_mode')
if [ -z "$MGMT_FRAMEWORK_CONFIG" ] || [ "$MGMT_FRAMEWORK_CONFIG" == "false" ]; then
rm /etc/frr/bfdd.conf /etc/frr/ospfd.conf
fi

update_default_gw()
{
Expand Down Expand Up @@ -52,7 +61,8 @@ if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
rm -f /etc/frr/frr.conf
elif [ "$CONFIG_TYPE" == "unified" ]; then
echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf \
/etc/frr/bfdd.conf /etc/frr/ospfd.conf /etc/frr/pimd.conf
fi

chown -R frr:frr /etc/frr/
Expand Down
5 changes: 5 additions & 0 deletions dockers/docker-fpm-frr/frr/bgpd/gen_bgpd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
{% include "/usr/local/sonic/frrcfgd/bgpd.conf.j2" %}
{% else %}
{% include "/usr/share/sonic/templates/bgpd/bgpd.conf.j2" %}
{% endif %}
15 changes: 14 additions & 1 deletion dockers/docker-fpm-frr/frr/frr_vars.j2
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
{{ DEVICE_METADATA["localhost"]["docker_routing_config_mode"] }}
{
"frr_mgmt_framework_config":
{% if "frr_mgmt_framework_config" in DEVICE_METADATA["localhost"].keys() %}
"{{ DEVICE_METADATA["localhost"]["frr_mgmt_framework_config"] }}"
{% else %}
""
{% endif %},
"docker_routing_config_mode":
{% if "docker_routing_config_mode" in DEVICE_METADATA["localhost"].keys() %}
"{{ DEVICE_METADATA["localhost"]["docker_routing_config_mode"] }}"
{% else %}
""
{% endif %}
}
5 changes: 5 additions & 0 deletions dockers/docker-fpm-frr/frr/gen_frr.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
{% include "/usr/local/sonic/frrcfgd/frr.conf.j2" %}
{% else %}
{% include "/usr/share/sonic/templates/frr.conf.j2" %}
{% endif %}
5 changes: 5 additions & 0 deletions dockers/docker-fpm-frr/frr/staticd/gen_staticd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
{% include "/usr/local/sonic/frrcfgd/staticd.conf.j2" %}
{% else %}
{% include "/usr/share/sonic/templates/staticd/staticd.conf.j2" %}
{% endif %}
12 changes: 12 additions & 0 deletions dockers/docker-fpm-frr/frr/supervisord/critical_processes.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
program:zebra
program:staticd
program:bgpd
program:fpmsyncd
{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
program:bfdd
program:ospfd
program:pimd
program:frrcfgd
{% else %}
program:bgpcfgd
{% endif %}
45 changes: 45 additions & 0 deletions dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=zebra:running

{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
[program:bfdd]
command=/usr/lib/frr/bfdd -A 127.0.0.1
priority=4
stopsignal=KILL
autostart=false
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=zebra:running
{% endif %}

[program:bgpd]
command=/usr/bin/bgpd.sh -A 127.0.0.1 -M snmp
priority=5
Expand All @@ -62,6 +76,32 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=zebra:running

{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
[program:ospfd]
command=/usr/lib/frr/ospfd -A 127.0.0.1 -M snmp
priority=5
stopsignal=KILL
autostart=false
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=zebra:running

[program:pimd]
command=/usr/lib/frr/pimd -A 127.0.0.1
priority=5
stopsignal=KILL
autostart=false
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=zebra:running
{% endif %}

[program:fpmsyncd]
command=fpmsyncd
priority=6
Expand All @@ -73,8 +113,13 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=bgpd:running

{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
[program:frrcfgd]
command=/usr/local/bin/frrcfgd
{% else %}
[program:bgpcfgd]
command=/usr/local/bin/bgpcfgd
{% endif %}
priority=6
autostart=false
autorestart=false
Expand Down
2 changes: 1 addition & 1 deletion rules/docker-fpm-frr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DOCKER_FPM_FRR = $(DOCKER_FPM_FRR_STEM).gz
DOCKER_FPM_FRR_DBG = $(DOCKER_FPM_FRR_STEM)-$(DBG_IMAGE_MARK).gz

$(DOCKER_FPM_FRR)_PATH = $(DOCKERS_PATH)/$(DOCKER_FPM_FRR_STEM)
$(DOCKER_FPM_FRR)_PYTHON_WHEELS += $(SONIC_BGPCFGD)
$(DOCKER_FPM_FRR)_PYTHON_WHEELS += $(SONIC_BGPCFGD) $(SONIC_FRR_MGMT_FRAMEWORK)

$(DOCKER_FPM_FRR)_DEPENDS += $(FRR) $(FRR_SNMP) $(SWSS) $(LIBYANG1)
$(DOCKER_FPM_FRR)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS)
Expand Down
8 changes: 8 additions & 0 deletions rules/sonic-frr-mgmt-framework.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SPATH := $($(SONIC_FRR_MGMT_FRAMEWORK)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-frr-mgmt-framework.mk rules/sonic-frr-mgmt-framework.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
DEP_FILES += $(shell git ls-files $(SPATH))

$(SONIC_FRR_MGMT_FRAMEWORK)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_FRR_MGMT_FRAMEWORK)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_FRR_MGMT_FRAMEWORK)_DEP_FILES := $(DEP_FILES)
13 changes: 13 additions & 0 deletions rules/sonic-frr-mgmt-framework.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# sonic-frr-mgmt-framework package

SONIC_FRR_MGMT_FRAMEWORK = sonic_frr_mgmt_framework-1.0-py3-none-any.whl
$(SONIC_FRR_MGMT_FRAMEWORK)_SRC_PATH = $(SRC_PATH)/sonic-frr-mgmt-framework
# These dependencies are only needed because they are dependencies
# of sonic-config-engine and frrcfgd explicitly calls sonic-cfggen
# as part of its unit tests.
# TODO: Refactor unit tests so that these dependencies are not needed

$(SONIC_FRR_MGMT_FRAMEWORK)_DEPENDS += $(SONIC_CONFIG_ENGINE_PY3)
$(SONIC_FRR_MGMT_FRAMEWORK)_DEBS_DEPENDS += $(PYTHON_SWSSCOMMON)
$(SONIC_FRR_MGMT_FRAMEWORK)_PYTHON_VERSION = 3
SONIC_PYTHON_WHEELS += $(SONIC_FRR_MGMT_FRAMEWORK)
12 changes: 12 additions & 0 deletions src/sonic-frr-mgmt-framework/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.eggs/
build/
dist/
*.egg-info/
frrcfgd/*.pyc
tests/*.pyc
tests/__pycache__/
.idea
.coverage
frrcfgd/__pycache__/
venv
tests/.coverage*
Empty file.
Loading

0 comments on commit 154a6ab

Please sign in to comment.