-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Bandwidth.go
145 lines (126 loc) · 4.16 KB
/
Bandwidth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 Authors of Cilium
package k8sTest
import (
"fmt"
. "github.com/cilium/cilium/test/ginkgo-ext"
"github.com/cilium/cilium/test/helpers"
. "github.com/onsi/gomega"
)
var _ = SkipDescribeIf(helpers.DoesNotRunOnNetNextKernel, "K8sBandwidthTest", func() {
var (
kubectl *helpers.Kubectl
ciliumFilename string
demoYAML string
)
BeforeAll(func() {
kubectl = helpers.CreateKubectl(helpers.K8s1VMName(), logger)
ciliumFilename = helpers.TimestampFilename("cilium.yaml")
demoYAML = helpers.ManifestGet(kubectl.BasePath(), "demo_bw.yaml")
res := kubectl.ApplyDefault(demoYAML)
res.ExpectSuccess("Unable to apply %s", demoYAML)
})
AfterAll(func() {
_ = kubectl.Delete(demoYAML)
ExpectAllPodsTerminated(kubectl)
kubectl.CloseSSHClient()
})
Context("Checks Bandwidth Rate-Limiting", func() {
const (
testDS10 = "run=netperf-10"
testDS25 = "run=netperf-25"
testClientPod = "run=netperf-client-pod"
testClientHost = "run=netperf-client-host"
maxRateDeviation = 5
minBandwidth = 1
)
var (
podLabels = []string{
testDS10,
testDS25,
}
)
AfterFailed(func() {
kubectl.CiliumReport("cilium bpf bandwidth list", "cilium endpoint list")
})
JustAfterEach(func() {
kubectl.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
})
AfterAll(func() {
UninstallCiliumFromManifest(kubectl, ciliumFilename)
})
waitForTestPods := func() {
podLabels := []string{
testDS10,
testDS25,
testClientPod,
testClientHost,
}
for _, label := range podLabels {
err := kubectl.WaitforPods(helpers.DefaultNamespace,
fmt.Sprintf("-l %s", label), helpers.HelperTimeout)
Expect(err).Should(BeNil())
}
}
testNetperfFromPods := func(clientPodLabel, targetIP string, maxSessions, rate int) {
pods, err := kubectl.GetPodNames(helpers.DefaultNamespace, clientPodLabel)
ExpectWithOffset(1, err).Should(BeNil(), "cannot retrieve pod names by filter %q",
clientPodLabel)
for i := 1; i <= maxSessions; i++ {
cmd := helpers.SuperNetperf(i, targetIP, helpers.TCP_MAERTS, "")
for _, pod := range pods {
By("Running %d netperf session from %s pod to pod with IP %s (expected rate: %d)",
i, pod, targetIP, rate)
res := kubectl.ExecPodCmd(helpers.DefaultNamespace, pod, cmd)
ExpectWithOffset(1, res).Should(helpers.CMDSuccess(),
"Request from %s pod to pod with IP %s failed", pod, targetIP)
By("Session test completed, netperf result raw: %s", res.SingleOut())
if rate > 0 {
ExpectWithOffset(1, res.InRange(minBandwidth, rate+maxRateDeviation)).To(BeNil(),
"Rate mismatch")
}
}
}
}
testNetperf := func(podLabels []string, fromLabel string) {
for _, label := range podLabels {
podIPs, err := kubectl.GetPodsIPs(helpers.DefaultNamespace, label)
ExpectWithOffset(1, err).Should(BeNil(), "Cannot retrieve pod IPs for %s", label)
ExpectWithOffset(1, len(podIPs)).To(Equal(int(1)), "Expected pod IPs mismatch")
rate := 0
fmt.Sscanf(label, "run=netperf-%d", &rate)
for _, podIP := range podIPs {
testNetperfFromPods(fromLabel, podIP, 1, rate)
}
}
}
It("Checks Pod to Pod bandwidth, vxlan tunneling", func() {
DeployCiliumOptionsAndDNS(kubectl, ciliumFilename, map[string]string{
"bandwidthManager": "true",
"tunnel": "vxlan",
})
waitForTestPods()
testNetperf(podLabels, testClientPod)
testNetperf(podLabels, testClientHost)
})
It("Checks Pod to Pod bandwidth, geneve tunneling", func() {
DeployCiliumOptionsAndDNS(kubectl, ciliumFilename, map[string]string{
"bandwidthManager": "true",
"tunnel": "geneve",
})
waitForTestPods()
testNetperf(podLabels, testClientPod)
testNetperf(podLabels, testClientHost)
})
It("Checks Pod to Pod bandwidth, direct routing", func() {
DeployCiliumOptionsAndDNS(kubectl, ciliumFilename, map[string]string{
"bandwidthManager": "true",
"tunnel": "disabled",
"autoDirectNodeRoutes": "true",
})
waitForTestPods()
testNetperf(podLabels, testClientPod)
testNetperf(podLabels, testClientHost)
})
})
})