Skip to content

Commit

Permalink
LACP support: added lacprate and xmitpolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
killianmuldoon committed May 29, 2020
1 parent f1722e1 commit 2e41fe1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bond/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type bondingConfig struct {
Mode string `json:"mode"`
LinksContNs bool `json:"linksInContainer"`
FailOverMac int `json:"failOverMac"`
XmitHashPolicy string `json: xmitHashPolicy`
LacpRate string `json: lacpRate`
Miimon string `json:"miimon"`
Links []map[string]interface{} `json:"links"`
}
Expand Down Expand Up @@ -91,14 +93,16 @@ func checkLinkExists(linkName string, netNsHandle *netlink.Handle) (netlink.Link
}

// configure the bonded link & add it using the netNsHandle context to add it to the required namespace. return a bondLinkObj pointer & error
func createBondedLink(bondName string, bondMode string, bondMiimon string, failOverMac int, netNsHandle *netlink.Handle) (*netlink.Bond, error) {
func createBondedLink(bondName string, bondMode string, xmitHashPolicy string, lacpRate string, bondMiimon string, failOverMac int, netNsHandle *netlink.Handle) (*netlink.Bond, error) {
var err error
bondLinkObj := netlink.NewLinkBond(netlink.NewLinkAttrs())
bondModeObj := netlink.StringToBondMode(bondMode)
bondLinkObj.Attrs().Name = bondName
bondLinkObj.Mode = bondModeObj
bondLinkObj.Miimon, err = strconv.Atoi(bondMiimon)
bondLinkObj.FailOverMac = netlink.BondFailOverMac(failOverMac)
bondLinkObj.XmitHashPolicy = netlink.StringToBondXmitHashPolicy(xmitHashPolicy)
bondLinkObj.LacpRate = netlink.StringToBondLacpRate(lacpRate)

if err != nil {
return nil, fmt.Errorf("Failed to convert bondMiimon value (%+v) to an int, error: %+v", bondMiimon, err)
Expand Down Expand Up @@ -240,7 +244,7 @@ func createBond(bondConf *bondingConfig, nspath string, ns ns.NetNS) (*current.I
if bondConf.FailOverMac< 0 || bondConf.FailOverMac > 2 {
return nil, fmt.Errorf("FailOverMac mode should be 0, 1 or 2 actual: %+v", bondConf.FailOverMac)
}
bondLinkObj, err := createBondedLink(bondConf.Name, bondConf.Mode, bondConf.Miimon, bondConf.FailOverMac, netNsHandle)
bondLinkObj, err := createBondedLink(bondConf.Name, bondConf.Mode, bondConf.XmitHashPolicy, bondConf.LacpRate ,bondConf.Miimon, bondConf.FailOverMac, netNsHandle)
if err != nil {
return nil, fmt.Errorf("Failed to create bonded link (%+v), error: %+v", bondConf.Name, err)
}
Expand Down
16 changes: 16 additions & 0 deletions examples/lacp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## LACP bonding mode - experimental

Three parameters are used in the bonding config to configure LACP mode:

First mode must be set to "802.3ad".

Second LACP Rate can be set to either "fast" or "slow"

Third xmitHashPolicy must be set. This defaults to layer2 and can be set to any of:
* "layer2"
* "layer3+4"
* "layer2+3"
* "encap2+3"
* "encap3+4"

Which of those is preferred depends your specific network design.
29 changes: 29 additions & 0 deletions examples/lacp/bond-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: bond-lacp
spec:
config: '{
"type": "bond",
"cniVersion": "0.3.1",
"name": "bond-lacp",
"ifname": "bond0",
"mode": "802.3ad",
"xmitHashPolicy": "layer2+3",
"lacpRate": "fast",
"mtu": 1500,
"linksInContainer": true,
"miimon": "100",
"links": [
{"name": "net1"},
{"name": "net2"}
],
"ipam": {
"type": "host-local",
"subnet": "10.56.217.0/24",
"routes": [{
"dst": "0.0.0.0/0"
}],
"gateway": "10.56.217.1"
}
}'
32 changes: 32 additions & 0 deletions examples/lacp/test-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Pod
metadata:
name: test-pod
annotations:
k8s.v1.cni.cncf.io/networks: '[
{"name": "sriov-backup-bondnet",
"interface": "net1"
},
{"name": "sriov-backup-bondnet",
"interface": "net2"
},
{"name": "bond-lacp",
"interface": "bond0"
}]'
spec:
restartPolicy: Never
hostPID: true
hostIPC: true
containers:
- name: bond-test
image: alpine:latest
command:
- /bin/sh
- "-c"
- "sleep 60m"
imagePullPolicy: IfNotPresent
resources:
requests:
intel.com/intel_sriov_netdevice: '2'
limits:
intel.com/intel_sriov_netdevice: '2'

0 comments on commit 2e41fe1

Please sign in to comment.