Bringing up Large Networks Using ip --batch

Follow

If you have a large network with many bridges and VLAN subinterfaces, restoring the configuration at system boot up can take a long time if you are doing it through /etc/network/interfaces/ifup and ifdown.

To reduce the configuration time, you can utilize the --force --batch option of the ip command. To do so, collect all the ip commands for your configuration, put them in one or more files and execute them with one command with the --force --batch option. Note that you should remove the ip keyword from the files — see the example files below.

It is also important to note that the file can only contain ip commands; otherwise execution will abort at the first non-ip command. For the same reason, some common brctl commands should be replaced with the equivalent ip commands to leverage the batching efficiency. For example, use ip link add <name> type bridge instead of brctl addbr <name>, and ip link set dev <if_name> master <br_name> instead of brctl addif <br_name> <if_name>. If the configuration order requires some non-ip commands to be interleaved among ip commands, the ip commands must be broken up into multiple batches as needed.

Caution: The ip --force --batch option is not supported by ifup/ifdown. Thus, you cannot use ifup/ifdown (and their add-on scripts) to bring interfaces up or down after they are configured. You must use ip link set up/down instead.

Example Scripts and Configuration

Following are example files demonstrating this configuration: /etc/rc.local and the two configuration scripts, iface_create and bridge_setup.

The ip command references iface_create to create the bridges and VLANs and bridge_setup to configure the bridge parameters and bring up the bridges; if you so choose, you can break out the ip commands at the bottom of the bridge_setup file and put them into a third file and run with ip --force --batch (removing the ip keyword from that file, as discussed above).

You run the two scripts through /etc/rc.local. Edit rc.local and add the following content before the exit 0 line:

ip -force -batch /etc/cumulus/iface_create
/etc/cumulus/bridge_setup

The scripts run at the end of each multi-user runlevel, after all other services have started, to quickly bring up all the bridges and VLANs.

rc.local Sample Content

Here is all the content needed for this configuration in rc.local:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

ip -force -batch /etc/cumulus/iface_create
/etc/cumulus/bridge_setup

exit 0

iface_create Sample Content

Here is some sample content for iface_create; feel free to edit this content for your network.

link set dev bond0 up
link set dev bond1 up
link set dev bond2 up
link add br1000 type bridge
addr add 11.0.0.0/24 dev br1000
link add link bond0 name bond0.1000 type vlan id 1000
link set dev bond0.1000 master br1000 up
link add link bond1 name bond1.1000 type vlan id 1000
link set dev bond1.1000 master br1000 up
link add link bond2 name bond2.1000 type vlan id 1000
link set dev bond2.1000 master br1000 up
link add br1001 type bridge
addr add 11.0.0.1/24 dev br1001
link add link bond0 name bond0.1001 type vlan id 1001
link set dev bond0.1001 master br1001 up
link add link bond1 name bond1.1001 type vlan id 1001
link set dev bond1.1001 master br1001 up
link add link bond2 name bond2.1001 type vlan id 1001
link set dev bond2.1001 master br1001 up
link add br1002 type bridge
addr add 11.0.0.2/24 dev br1002
link add link bond0 name bond0.1002 type vlan id 1002
link set dev bond0.1002 master br1002 up
link add link bond1 name bond1.1002 type vlan id 1002
link set dev bond1.1002 master br1002 up
link add link bond2 name bond2.1002 type vlan id 1002
link set dev bond2.1002 master br1002 up
link add br1003 type bridge
addr add 11.0.0.3/24 dev br1003
link add link bond0 name bond0.1003 type vlan id 1003
link set dev bond0.1003 master br1003 up
link add link bond1 name bond1.1003 type vlan id 1003
link set dev bond1.1003 master br1003 up
link add link bond2 name bond2.1003 type vlan id 1003
link set dev bond2.1003 master br1003 up
link add br1004 type bridge
addr add 11.0.0.4/24 dev br1004
link add link bond0 name bond0.1004 type vlan id 1004
link set dev bond0.1004 master br1004 up
link add link bond1 name bond1.1004 type vlan id 1004
link set dev bond1.1004 master br1004 up
link add link bond2 name bond2.1004 type vlan id 1004
link set dev bond2.1004 master br1004 up
link add br1005 type bridge
addr add 11.0.0.5/24 dev br1005
link add link bond0 name bond0.1005 type vlan id 1005
link set dev bond0.1005 master br1005 up
link add link bond1 name bond1.1005 type vlan id 1005
link set dev bond1.1005 master br1005 up
link add link bond2 name bond2.1005 type vlan id 1005
link set dev bond2.1005 master br1005 up
 

bridge_setup Sample Content

Here is some sample content for bridge_setup; feel free to edit this content for your network.

brctl stp br1000 on
mstpctl addbridge br1000
mstpctl sethello br1000 3
brctl stp br1001 on
mstpctl addbridge br1001
mstpctl sethello br1001 3
brctl stp br1002 on
mstpctl addbridge br1002
mstpctl sethello br1002 3
brctl stp br1003 on
mstpctl addbridge br1003
mstpctl sethello br1003 3
brctl stp br1004 on
mstpctl addbridge br1004
mstpctl sethello br1004 3
brctl stp br1005 on
mstpctl addbridge br1005
mstpctl sethello br1005 3
ip link set dev br1000 up
ip link set dev br1001 up
ip link set dev br1002 up
ip link set dev br1003 up
ip link set dev br1004 up
ip link set dev br1005 up

Have more questions? Submit a request

Comments

Powered by Zendesk