-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux: add LAG support and bonding plugin for non-LAG cases (#1624)
- Loading branch information
Showing
25 changed files
with
430 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
(plugin-bonding)= | ||
# Host-side Link Bonding | ||
|
||
Linux networking has long supported *bonding*, the ability to use multiple links simultaneously. Netlab supports bonding with LACP through the *lag* module, | ||
this plugin adds support for the other bonding modes (that don't require any special configuration on peers) | ||
|
||
```eval_rst | ||
.. contents:: Table of Contents | ||
:depth: 2 | ||
:local: | ||
:backlinks: none | ||
``` | ||
|
||
## Using the Plugin | ||
|
||
* Add `plugin: [ bonding ]` to the lab topology. | ||
* Include the **bonding.ifindex** attribute in any links that need to be bonded | ||
|
||
### Supported attributes | ||
|
||
The plugin adds the following attributes defined at global, node or interface level: | ||
* **bonding.mode** (string, one of active-backup, balance-tlb, or balance-alb) -- the bonding mode to use, default `active-backup` | ||
|
||
Additional interface level attributes: | ||
* **bonding.ifindex** (int,mandatory) -- the interface index for the bonding device; links with matching ifindex are bonded together | ||
* **bonding.primary** (bool) -- optional flag to mark this interface as primary, default *False*. If none of the interfaces are marked as `primary`, the selection is left to the Linux default behavior | ||
|
||
### Caveats | ||
|
||
The plugin uses the `ip` command to create bond devices and add member links; in case of Linux VMs that are not Ubuntu, the plugin attempts to install this command when not available. | ||
This installation uses `apt-get` which may not work on some Linux VMs | ||
|
||
## Examples | ||
|
||
(active-backup-bonding)= | ||
### Connect a host to a pair of switches using active-backup bonding | ||
|
||
```yaml | ||
plugin: [ bonding ] | ||
|
||
bonding.mode: active-backup # Default | ||
|
||
vlans: | ||
v1: | ||
|
||
groups: | ||
_auto_create: True | ||
hosts: | ||
members: [ h1 ] | ||
device: linux | ||
switches: | ||
members: [ s1, s2 ] | ||
module: [ vlan ] | ||
|
||
links: | ||
- s1: | ||
s2: | ||
vlan.trunk: [ v1 ] | ||
|
||
# Bonded interfaces eth1/eth2 | ||
- s1: | ||
h1: | ||
bonding.ifindex: 1 | ||
- s2: | ||
h1: | ||
bonding: | ||
ifindex: 1 | ||
primary: True # Use this interface as primary | ||
``` | ||
Note how there are no bonding specific modules enabled on the switches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# This macro is used by the initial script to create bond devices | ||
# (which needs to be done early such that IP addresses can be assigned and/or VLAN interfaces created) | ||
# | ||
{% macro create_bond_dev(l,node_provider) %} | ||
{% if l.type in ['lag','bond'] %} | ||
{% set _m = l.lag.mode|default(l.bonding.mode|default("802.3ad")) %} | ||
{% if _m=="802.3ad" %} | ||
{% set _lacp = l.lag.lacp|default('fast') %} | ||
{% set lacp_act = 'off' if _lacp=='off' else 'on' %} | ||
{% set lacp_rate = (' lacp_rate ' + _lacp) if _lacp!='off' else '' %} | ||
{% set _m = _m + lacp_rate %} | ||
{% if node_provider == 'clab' %} | ||
{% set _m = _m + " lacp_active " + lacp_act %} | ||
{% endif %} | ||
{% elif l.bonding.primary is defined %} | ||
{% set _m = _m + " primary " + l.bonding.primary %} | ||
{% endif %} | ||
{% if _m in ["802.3ad","balance-xor","balance-alb","balance-tlb"] %} | ||
{% set _m = _m + " xmit_hash_policy encap3+4" %} | ||
{% endif -%} | ||
|
||
{% if node_provider!='clab' %} | ||
# | ||
# Make sure 'bonding' module is loaded | ||
# | ||
if [ ! -e /sys/module/bonding ]; then | ||
modprobe bonding miimon=100 mode=802.3ad lacp_rate=fast | ||
fi | ||
{% endif -%} | ||
|
||
if [ ! -e /sys/class/net/{{l.ifname}} ]; then | ||
ip link add dev {{l.ifname}} type bond mode {{ _m }} | ||
fi | ||
{% endif %} | ||
{% endmacro -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1 @@ | ||
#!/bin/bash | ||
# | ||
set -e # Exit immediately when any command fails | ||
# | ||
{% if node_provider != 'clab' %} | ||
modprobe bonding miimon=100 mode=802.3ad lacp_rate=fast | ||
{% endif %} | ||
# | ||
# Create bonds for LAGs, if any. Requires kernel bonding module loaded | ||
# | ||
{% for l in interfaces if 'lag' in l %} | ||
{% if l.type=='lag' %} | ||
{% set _m = l.lag.mode|default(lag.mode) %} | ||
{% if _m=="802.3ad" %} | ||
{% set _lacp = l.lag.lacp|default(lag.lacp) %} | ||
{% set lacp_act = 'off' if _lacp=='off' else 'on' %} | ||
{% set lacp_rate = (' lacp_rate ' + _lacp) if _lacp!='off' else '' %} | ||
{% set _m = _m + " xmit_hash_policy encap3+4" + lacp_rate %} | ||
{% if node_provider == 'clab' %} | ||
{% set _m = _m + " lacp_active " + lacp_act %} | ||
{% endif %} | ||
{% endif %} | ||
ip link add dev {{l.ifname}} type bond mode {{_m}} | ||
{% endif %} | ||
ip link set dev {{ l.ifname }} down | ||
{% endfor %} | ||
|
||
{% for l in interfaces if 'lag' in l and l.type != 'lag' %} | ||
{% if l.type=='p2p' %} | ||
{% if node_provider != 'clab' %} | ||
ethtool -s {{ l.ifname }} autoneg off speed 1000 duplex full | ||
{% endif %} | ||
ip link set dev {{ l.ifname }} master {% | ||
for i in interfaces if i.type=='lag' and i.linkindex==l.lag._parentindex %}{{ i.ifname }} | ||
{% endfor %} | ||
{% endif %} | ||
ip link set dev {{ l.ifname }} up | ||
{% endfor %} | ||
{% for l in interfaces if 'lag' in l and l.type == 'lag' %} | ||
ip link set dev {{ l.ifname }} up | ||
{% endfor %} | ||
exit 0 | ||
{% include "linux.j2" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% include "linux.j2" %} | ||
|
||
# | ||
# Note: The above script is executed within the netns context on the host | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% if node_provider=='clab' or netlab_linux_distro|default("") != "ubuntu" %} | ||
#!/bin/bash | ||
# | ||
set -e # Exit immediately when any command fails | ||
# | ||
# Bond devices are created by 'initial' module - add members | ||
# | ||
{% for l in interfaces if 'lag' in l and l.type not in ['lag','bond'] %} | ||
{% if l.type=='p2p' %} | ||
{% if node_provider!='clab' %} | ||
ethtool -s {{ l.ifname }} autoneg off speed 1000 duplex full | ||
{% endif %} | ||
ip link set dev {{ l.ifname }} down | ||
ip link set dev {{ l.ifname }} master {% | ||
for i in interfaces if i.type=='lag' and i.linkindex==l.lag._parentindex %}{{ i.ifname }} | ||
{% endfor %} | ||
{% endif %} | ||
ip link set dev {{ l.ifname }} up | ||
{% endfor %} | ||
{% for l in interfaces if 'lag' in l and l.type in ['lag','bond'] %} | ||
ip link set dev {{ l.ifname }} up | ||
{% endfor %} | ||
exit 0 | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.