Skip to content

Commit b16fdef

Browse files
committed
Correcting UT, updating documentation
1 parent b4aad3c commit b16fdef

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

Diff for: pkg/cnidel/cniconfs.go

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func getSriovCniConfig(netInfo *danmtypes.DanmNet, ipamOptions datastructs.IpamC
6262
sriovConfig.CNIVersion = cniVersion
6363
sriovConfig.Name = netInfo.Spec.NetworkID
6464
sriovConfig.Type = "sriov"
65-
// initialize SriovNet specific fields:
6665
pfname, err := sriov_utils.GetPfName(ep.Spec.Iface.DeviceID)
6766
if err != nil {
6867
return nil, errors.New("failed to get the name of the sriov PF for device "+ ep.Spec.Iface.DeviceID +" due to:" + err.Error())

Diff for: test/utils/utils.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,30 @@ type MalformedObject struct {
5858
func SetupAllocationPools(nets []danmtypes.DanmNet) error {
5959
for index, dnet := range nets {
6060
if dnet.Spec.Options.Cidr != "" {
61-
admit.CreateAllocationArray(&dnet)
62-
_, ipnet, err := net.ParseCIDR(dnet.Spec.Options.Cidr)
63-
if err != nil {
64-
return err
65-
}
66-
if dnet.Spec.Options.Pool.Start == "" {
67-
dnet.Spec.Options.Pool.Start = (ipam.Int2ip(ipam.Ip2int(ipnet.IP) + 1)).String()
68-
}
69-
if dnet.Spec.Options.Pool.End == "" {
70-
dnet.Spec.Options.Pool.End = (ipam.Int2ip(ipam.Ip2int(admit.GetBroadcastAddress(ipnet)) - 1)).String()
71-
}
72-
if strings.HasPrefix(dnet.ObjectMeta.Name, "full") {
73-
exhaustNetwork(&dnet)
74-
}
75-
nets[index].Spec = dnet.Spec
61+
nets[index].Spec = InitAllocPool(&dnet).Spec
7662
}
7763
}
7864
return nil
7965
}
8066

67+
func InitAllocPool(dnet *danmtypes.DanmNet) *danmtypes.DanmNet {
68+
if dnet.Spec.Options.Cidr == "" {
69+
return dnet
70+
}
71+
admit.CreateAllocationArray(dnet)
72+
_, ipnet, _ := net.ParseCIDR(dnet.Spec.Options.Cidr)
73+
if dnet.Spec.Options.Pool.Start == "" {
74+
dnet.Spec.Options.Pool.Start = (ipam.Int2ip(ipam.Ip2int(ipnet.IP) + 1)).String()
75+
}
76+
if dnet.Spec.Options.Pool.End == "" {
77+
dnet.Spec.Options.Pool.End = (ipam.Int2ip(ipam.Ip2int(admit.GetBroadcastAddress(ipnet)) - 1)).String()
78+
}
79+
if strings.HasPrefix(dnet.ObjectMeta.Name, "full") {
80+
exhaustNetwork(dnet)
81+
}
82+
return dnet
83+
}
84+
8185
func GetTestNet(netId string, testNets []danmtypes.DanmNet) *danmtypes.DanmNet {
8286
for _, net := range testNets {
8387
if net.ObjectMeta.Name == netId {

Diff for: test/uts/cnidel_test/cnidel_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ var expectedCniConfigs = []CniConf {
134134
{"macvlan-ip4", []byte(`{"cniexp":{"cnitype":"macvlan","ip":"192.168.1.65/26","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"ens1f0"}},"cniconf":{"cniVersion":"0.3.1","name":"macvlan-v4","master":"ens1f0","mode":"bridge","mtu":1500,"ipam":{"type":"fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
135135
{"macvlan-ip6", []byte(`{"cniexp":{"cnitype":"macvlan","ip6":"2a00:8a00:a000:1193::/64","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"ens1f1"}},"cniconf":{"cniVersion":"0.3.1","name":"macvlan-v6","master":"ens1f1","mode":"bridge","mtu":1500,"ipam":{"type":"fakeipam"}}}`)},
136136
{"macvlan-dual-stack", []byte(`{"cniexp":{"cnitype":"macvlan","ip":"192.168.1.65/26","ip6":"2a00:8a00:a000:1193::/64","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"ens1f1"}},"cniconf":{"cniVersion":"0.3.1","name":"macvlan-ds","master":"ens1f1","mode":"bridge","mtu":1500,"ipam":{"type":"fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
137-
{"macvlan-ip4-type020", []byte(`{"cniexp":{"cnitype":"macvlan","ip":"192.168.1.66/26","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"ens1f0"},"return":"020"},"cniconf":{"cniVersion":"0.3.1","name":"macvlan-v4","master":"ens1f0","mode":"bridge","mtu":1500,"ipam":{"type":"fakeipam","ips":[{"ipcidr":"192.168.1.66/26","version":4}]}}}`)},
137+
{"macvlan-ip4-type020", []byte(`{"cniexp":{"cnitype":"macvlan","ip":"192.168.1.65/26","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"ens1f0"},"return":"020"},"cniconf":{"cniVersion":"0.3.1","name":"macvlan-v4","master":"ens1f0","mode":"bridge","mtu":1500,"ipam":{"type":"fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
138138
{"macvlan-ip6-type020", []byte(`{"cniexp":{"cnitype":"macvlan","ip6":"2a00:8a00:a000:1193::/64","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"ens1f1"},"return":"020"},"cniconf":{"cniVersion":"0.3.1","name":"macvlan-v6","master":"ens1f1","mode":"bridge","mtu":1500,"ipam":{"type":"fakeipam"}}}`)},
139-
{"sriov-l3", []byte(`{"cniexp":{"cnitype":"sriov","ip":"192.168.1.65/26","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"eth0"}},"cniconf":{"cniVersion":"0.3.1","name":"sriov-test","type":"sriov","master":"enp175s0f1","l2enable":false,"vlan":500,"deviceID":"0000:af:06.0","ipam":{"type":"fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
140-
{"sriov-l2", []byte(`{"cniexp":{"cnitype":"sriov","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"eth0"}},"cniconf":{"cniVersion":"0.3.1","name":"sriov-test","type":"sriov","master":"enp175s0f1","l2enable":true,"vlan":500,"deviceID":"0000:af:06.0"}}`)},
139+
{"sriov-l3", []byte(`{"cniexp":{"cnitype":"sriov","ip":"192.168.1.65/26","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"eth0"}},"cniconf":{"cniVersion":"0.3.1","name":"sriov-test","type":"sriov","master":"enp175s0f1","vlan":500,"deviceID":"0000:af:06.0","ipam":{"type":"fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
140+
{"sriov-l2", []byte(`{"cniexp":{"cnitype":"sriov","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"eth0"}},"cniconf":{"cniVersion":"0.3.1","name":"sriov-test","type":"sriov","master":"enp175s0f1","vlan":500,"deviceID":"0000:af:06.0"}}`)},
141141
{"deleteflannel", []byte(`{"cniexp":{"cnitype":"flannel","env":{"CNI_COMMAND":"DEL","CNI_IFNAME":"eth0"}},"cniconf":{"cniVersion":"0.3.1","name":"cbr0","type":"flannel","delegate":{"hairpinMode":true,"isDefaultGateway":true}}}`)},
142142
{"deletemacvlan", []byte(`{"cniexp":{"cnitype":"macvlan","env":{"CNI_COMMAND":"DEL","CNI_IFNAME":"ens1f0"}},"cniconf":{"cniVersion":"0.3.1","name":"full","master":"ens1f0","mode":"bridge","mtu":1500,"ipam": {"type": "fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
143143
{"bridge-l3-ip4", []byte(`{"cniexp":{"cnitype":"macvlan","ip":"192.168.1.65/26","env":{"CNI_COMMAND":"ADD","CNI_IFNAME":"eth0"}},"cniconf":{"cniVersion":"0.3.1","name": "mynet","type": "bridge","bridge": "mynet0","isDefaultGateway": true,"forceAddress": false,"ipMasq": true,"hairpinMode": true,"ipam": {"type": "fakeipam","ips":[{"ipcidr":"192.168.1.65/26","version":4}]}}}`)},
@@ -253,12 +253,12 @@ var delSetupTcs = []struct {
253253
{"dynamicMacvlanDualStack", "macvlan-ds", "dynamicDual", "macvlan-dual-stack", "192.168.1.65", "2a00:8a00:a000:1193", false, 1},
254254
{"dynamicMacvlanIpv4Type020Result", "macvlan-v4", "dynamicIpv4", "macvlan-ip4-type020", "192.168.1.65", "", false, 1},
255255
{"dynamicMacvlanIpv6Type020Result", "macvlan-v6", "dynamicIpv6", "macvlan-ip6-type020", "", "2a00:8a00:a000:1193", false, 0},
256-
{"dynamicSriovNoDeviceId", "sriov-test", "dynamicIpv4", "", "", "", true, 2},
256+
{"dynamicSriovNoDeviceId", "sriov-test", "dynamicIpv4", "", "", "", true, 1},
257257
{"dynamicSriovL3", "sriov-test", "dynamicIpv4WithDeviceId", "sriov-l3", "", "", false, 1},
258258
{"dynamicSriovL2", "sriov-test", "noneWithDeviceId", "sriov-l2", "", "", false, 0},
259259
{"bridgeWithV4Overwrite", "bridge-ipam-ipv4", "simpleIpv4", "bridge-l3-ip4", "", "", false, 1},
260260
{"bridgeWithV4Add", "bridge-ipam-l2", "simpleIpv4", "bridge-l2-ip4", "", "", false, 1},
261-
{"bridgeWithInvalidAdd", "bridge-invalid", "simpleIpv4", "", "", "", true, 2},
261+
{"bridgeWithInvalidAdd", "bridge-invalid", "simpleIpv4", "", "", "", true, 1},
262262
{"bridgeL3OriginalNoCidr", "bridge-noipam", "simpleIpv4", "bridge-l3-orig", "", "", false, 0},
263263
{"bridgeL3OriginalNoIp", "bridge-ipam-ipv4", "noIps", "bridge-l3-orig", "", "", false, 0},
264264
{"bridgeL2OriginalNoCidr", "bridge-noipam-l2", "simpleIpv4", "bridge-l2-orig", "", "", false, 0},
@@ -358,6 +358,7 @@ func TestDelegateInterfaceSetup(t *testing.T) {
358358
testNet := utils.GetTestNet(tc.netName, testNets)
359359
testEp := getTestEp(tc.epName)
360360
testEp.Spec.NetworkName = testNet.ObjectMeta.Name
361+
testNet = utils.InitAllocPool(testNet)
361362
cniRes, err := cnidel.DelegateInterfaceSetup(&cniConf,netClientStub,testNet,testEp)
362363
if (err != nil && !tc.isErrorExpected) || (err == nil && tc.isErrorExpected) {
363364
var detailedErrorMessage string

Diff for: user-guide.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* [DANM IPVLAN CNI](#danm-ipvlan-cni)
2424
* [Device Plugin Support](#device-plugin-support)
2525
* [Using Intel SR-IOV CNI](#using-intel-sr-iov-cni)
26+
* [DPDK support](#dpdk-support)
2627
* [Usage of DANM's Webhook component](#usage-of-danms-webhook-component)
2728
* [Responsibilities](#responsibilities)
2829
* [Connecting TenantNetworks to TenantConfigs](#connecting-tenantnetworks-to-tenantconfigs)
@@ -259,7 +260,8 @@ The CNI provisions IPVLAN interfaces in L2 mode, and supports the following extr
259260
* provisioning generic IP routes into a configured routing table inside the Pod's network namespace
260261
* Pod-level controlled provisioning of policy-based IP routes into Pod's network namespace
261262
#### Device Plugin support
262-
DANM provides general support to CNIs which interwork with Kubernetes' Device Plugin mechanism such as SR-IOV CNI.
263+
DANM provides general support for CNIs interworking with Kubernetes' Device Plugin mechanism.
264+
A practical example of such a network provisioner is the SR-IOV CNI.
263265
When a properly configured Network Device Plugin runs, the allocatable resource list for the node should be updated with resource discovered by the plugin.
264266
##### Using Intel SR-IOV CNI
265267
SR-IOV Network Device Plugin allows to create a list of *netdevice* type resource definitions with *sriovMode*, where each resource definition can have one or more assigned *rootDevice* (Physical Function). The plugin looks for Virtual Functions (VF) for each configured Physical Function (PF) and adds all discovered VFs to the allocatable resource's list of the given Kubernetes Node. The Device Plugin resource name will be the device pool name on the Node. These device pools can be referred in Pod definition's resource request part on the usual way.
@@ -329,6 +331,17 @@ spec:
329331
nodeSelector:
330332
sriov: enabled
331333
```
334+
##### DPDK support
335+
DANM's SR-IOV integration supports -and is tested with- both Intel, and Mellanox manufactured physical functions.
336+
Moreover Pods can use the allocated Virtual Functions for either kernel, or userspace networking.
337+
The only restriction to keep in mind is when a DPDK using application requests VFs from an Intel NIC for the purpose of userspace networking,
338+
those VFs shall be already bound to the vfio-pci kernel driver before the Pod is instantiated.
339+
To guarantee such VFs are always available on the Node the Pod is scheduled to, we strongly suggest advertising vfio-pci bound VFs as a separate Device Pool.
340+
When an already vfio bound function is mounted to an application, DANM also creates a dummy kernel interface in its stead in the Pod's network namespace.
341+
The dummy interface can be easily identified by the application, because it's named exactly as the VF would be.
342+
The dummy interface is used to communicate the IPAM details belonging to the non-kernel managed device, such as IP addresses, IP routes etc.
343+
Userspace applications can interrogate this information via the usual kernel APIs, and then configure the allocated resources into their own IP stack!
344+
332345
### Usage of DANM's Webhook component
333346
#### Responsibilities
334347
The Webhook component introduced in DANM V4 is responsible for three things:

0 commit comments

Comments
 (0)