Skip to content

Commit a10c5bf

Browse files
authored
[frr] Reduce Calls to SONiC Cfggen (#5176)
Calls to sonic-cfggen is CPU expensive. This PR reduces calls to sonic-cfggen to two calls during startup when starting frr service. singed-off-by: Tamer Ahmed <[email protected]>
1 parent 3a10e9c commit a10c5bf

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

dockers/docker-fpm-frr/docker_init.sh

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
mkdir -p /etc/frr
44
mkdir -p /etc/supervisor/conf.d
55

6-
sonic-cfggen -d -t /usr/share/sonic/templates/supervisord/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
7-
8-
CONFIG_TYPE=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["docker_routing_config_mode"]'`
6+
CFGGEN_PARAMS=" \
7+
-d \
8+
-y /etc/sonic/constants.yml \
9+
-t /usr/share/sonic/templates/supervisord/frr_vars.j2 \
10+
-t /usr/share/sonic/templates/supervisord/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
11+
-t /usr/share/sonic/templates/bgpd/bgpd.conf.j2,/etc/frr/bgpd.conf \
12+
-t /usr/share/sonic/templates/zebra/zebra.conf.j2,/etc/frr/zebra.conf \
13+
-t /usr/share/sonic/templates/staticd/staticd.conf.j2,/etc/frr/staticd.conf \
14+
-t /usr/share/sonic/templates/frr.conf.j2,/etc/frr/frr.conf \
15+
-t /usr/share/sonic/templates/isolate.j2,/usr/sbin/bgp-isolate \
16+
-t /usr/share/sonic/templates/unisolate.j2,/usr/sbin/bgp-unisolate \
17+
"
18+
CONFIG_TYPE=$(sonic-cfggen $CFGGEN_PARAMS)
919

1020
if [[ ! -z "$NAMESPACE_ID" ]]; then
1121
# FRR is not running in host namespace so we need to delete
@@ -31,24 +41,18 @@ if [[ ! -z "$NAMESPACE_ID" ]]; then
3141
fi
3242

3343
if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
34-
sonic-cfggen -d -t /usr/share/sonic/templates/bgpd/bgpd.conf.j2 -y /etc/sonic/constants.yml > /etc/frr/bgpd.conf
35-
sonic-cfggen -d -t /usr/share/sonic/templates/zebra/zebra.conf.j2 > /etc/frr/zebra.conf
36-
sonic-cfggen -d -t /usr/share/sonic/templates/staticd/staticd.conf.j2 > /etc/frr/staticd.conf
3744
echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf
3845
rm -f /etc/frr/frr.conf
3946
elif [ "$CONFIG_TYPE" == "unified" ]; then
40-
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/frr.conf.j2 >/etc/frr/frr.conf
4147
echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf
4248
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf
4349
fi
4450

4551
chown -R frr:frr /etc/frr/
4652

47-
sonic-cfggen -d -t /usr/share/sonic/templates/isolate.j2 > /usr/sbin/bgp-isolate
4853
chown root:root /usr/sbin/bgp-isolate
4954
chmod 0755 /usr/sbin/bgp-isolate
5055

51-
sonic-cfggen -d -t /usr/share/sonic/templates/unisolate.j2 > /usr/sbin/bgp-unisolate
5256
chown root:root /usr/sbin/bgp-unisolate
5357
chmod 0755 /usr/sbin/bgp-unisolate
5458

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ DEVICE_METADATA["localhost"]["docker_routing_config_mode"] }}

dockers/docker-fpm-gobgp/start.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#!/usr/bin/env bash
22

33
mkdir -p /etc/quagga
4-
sonic-cfggen -d -t /usr/share/sonic/templates/gobgpd.conf.j2 > /etc/gobgp/gobgpd.conf
5-
sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/quagga/zebra.conf
64

7-
sonic-cfggen -d -t /usr/share/sonic/templates/isolate.j2 > /usr/sbin/bgp-isolate
5+
CFGGEN_PARAMS=" \
6+
-d \
7+
-t /usr/share/sonic/templates/gobgpd.conf.j2,/etc/gobgp/gobgpd.conf \
8+
-t /usr/share/sonic/templates/zebra.conf.j2,/etc/quagga/zebra.conf \
9+
-t /usr/share/sonic/templates/isolate.j2,/usr/sbin/bgp-isolate \
10+
-t /usr/share/sonic/templates/unisolate.j2,/usr/sbin/bgp-unisolate \
11+
"
12+
sonic-cfggen $CFGGEN_PARAMS
13+
814
chown root:root /usr/sbin/bgp-isolate
915
chmod 0755 /usr/sbin/bgp-isolate
1016

11-
sonic-cfggen -d -t /usr/share/sonic/templates/unisolate.j2 > /usr/sbin/bgp-unisolate
1217
chown root:root /usr/sbin/bgp-unisolate
1318
chmod 0755 /usr/sbin/bgp-unisolate
1419

dockers/docker-fpm-quagga/start.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#!/usr/bin/env bash
22

33
mkdir -p /etc/quagga
4-
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/quagga/bgpd.conf
54

6-
sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/quagga/zebra.conf
5+
CFGGEN_PARAMS=" \
6+
-d \
7+
-y /etc/sonic/constants.yml \
8+
-t /usr/share/sonic/templates/bgpd.conf.j2,/etc/quagga/bgpd.conf \
9+
-t /usr/share/sonic/templates/zebra.conf.j2,/etc/quagga/zebra.conf \
10+
-t /usr/share/sonic/templates/isolate.j2,/usr/sbin/bgp-isolate \
11+
-t /usr/share/sonic/templates/unisolate.j2,/usr/sbin/bgp-unisolate \
12+
"
13+
sonic-cfggen $CFGGEN_PARAMS
714

8-
sonic-cfggen -d -t /usr/share/sonic/templates/isolate.j2 > /usr/sbin/bgp-isolate
915
chown root:root /usr/sbin/bgp-isolate
1016
chmod 0755 /usr/sbin/bgp-isolate
1117

12-
sonic-cfggen -d -t /usr/share/sonic/templates/unisolate.j2 > /usr/sbin/bgp-unisolate
1318
chown root:root /usr/sbin/bgp-unisolate
1419
chmod 0755 /usr/sbin/bgp-unisolate
1520

0 commit comments

Comments
 (0)