| 1 | // Copyright 2018 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package main |
| 16 | |
| 17 | import ( |
| 18 | "context" |
| 19 | "encoding/json" |
| 20 | "fmt" |
| 21 | "net" |
| 22 | "os" |
| 23 | "time" |
| 24 | |
| 25 | . "github.com/onsi/ginkgo/v2" |
| 26 | . "github.com/onsi/gomega" |
| 27 | "github.com/onsi/gomega/gexec" |
| 28 | "github.com/vishvananda/netlink" |
| 29 | |
| 30 | "github.com/containernetworking/cni/pkg/invoke" |
| 31 | "github.com/containernetworking/cni/pkg/skel" |
| 32 | "github.com/containernetworking/cni/pkg/types" |
| 33 | types100 "github.com/containernetworking/cni/pkg/types/100" |
| 34 | "github.com/containernetworking/plugins/pkg/netlinksafe" |
| 35 | "github.com/containernetworking/plugins/pkg/ns" |
| 36 | "github.com/containernetworking/plugins/pkg/testutils" |
| 37 | ) |
| 38 | |
| 39 | func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.Result) ([]byte, error) { |
| 40 | var err error |
| 41 | |
| 42 | inject := map[string]interface{}{ |
| 43 | "name": name, |
| 44 | "cniVersion": cniVersion, |
| 45 | } |
| 46 | // Add previous plugin result |
| 47 | if prevResult != nil { |
| 48 | r, err := prevResult.GetAsVersion(cniVersion) |
| 49 | Expect(err).NotTo(HaveOccurred()) |
| 50 | inject["prevResult"] = r |
| 51 | } |
| 52 | |
| 53 | // Ensure every config uses the same name and version |
| 54 | config := make(map[string]interface{}) |
| 55 | |
| 56 | confBytes, err := json.Marshal(orig) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | |
| 61 | err = json.Unmarshal(confBytes, &config) |
| 62 | if err != nil { |
| 63 | return nil, fmt.Errorf("unmarshal existing network bytes: %s", err) |
| 64 | } |
| 65 | |
| 66 | for key, value := range inject { |
| 67 | config[key] = value |
| 68 | } |
| 69 | |
| 70 | newBytes, err := json.Marshal(config) |
| 71 | if err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | |
| 75 | conf := &PluginConf{} |
| 76 | if err := json.Unmarshal(newBytes, &conf); err != nil { |
| 77 | return nil, fmt.Errorf("error parsing configuration: %s", err) |
| 78 | } |
| 79 | |
| 80 | return newBytes, nil |
| 81 | } |
| 82 | |
| 83 | var _ = Describe("bandwidth test", func() { |
| 84 | var ( |
| 85 | hostNs ns.NetNS |
| 86 | containerNs ns.NetNS |
| 87 | ifbDeviceName string |
| 88 | hostIfname string |
| 89 | containerIfname string |
| 90 | hostIP net.IP |
| 91 | containerIP net.IP |
| 92 | hostIfaceMTU int |
| 93 | ) |
| 94 | |
| 95 | BeforeEach(func() { |
| 96 | var err error |
| 97 | |
| 98 | hostIfname = "host-veth" |
| 99 | containerIfname = "container-veth" |
| 100 | |
| 101 | hostNs, err = testutils.NewNS() |
| 102 | Expect(err).NotTo(HaveOccurred()) |
| 103 | |
| 104 | containerNs, err = testutils.NewNS() |
| 105 | Expect(err).NotTo(HaveOccurred()) |
| 106 | |
| 107 | hostIP = net.IP{169, 254, 0, 1} |
| 108 | containerIP = net.IP{10, 254, 0, 1} |
| 109 | hostIfaceMTU = 1024 |
| 110 | ifbDeviceName = "bwpa8eda89404b7" |
| 111 | |
| 112 | createVeth(hostNs, hostIfname, containerNs, containerIfname, hostIP, containerIP, hostIfaceMTU) |
| 113 | }) |
| 114 | |
| 115 | AfterEach(func() { |
| 116 | Expect(containerNs.Close()).To(Succeed()) |
| 117 | Expect(testutils.UnmountNS(containerNs)).To(Succeed()) |
| 118 | Expect(hostNs.Close()).To(Succeed()) |
| 119 | Expect(testutils.UnmountNS(hostNs)).To(Succeed()) |
| 120 | }) |
| 121 | |
| 122 | // Bandwidth requires host-side interface info, and thus only |
| 123 | // supports 0.3.0 and later CNI versions |
| 124 | for _, ver := range []string{"0.3.0", "0.3.1", "0.4.0", "1.0.0"} { |
| 125 | // Redefine ver inside for scope so real value is picked up by each dynamically defined It() |
| 126 | // See Gingkgo's "Patterns for dynamically generating tests" documentation. |
| 127 | ver := ver |
| 128 | |
| 129 | Describe("cmdADD", func() { |
| 130 | It(fmt.Sprintf("[%s] works with a Veth pair", ver), func() { |
| 131 | conf := fmt.Sprintf(`{ |
| 132 | "cniVersion": "%s", |
| 133 | "name": "cni-plugin-bandwidth-test", |
| 134 | "type": "bandwidth", |
| 135 | "ingressRate": 8, |
| 136 | "ingressBurst": 8, |
| 137 | "egressRate": 16, |
| 138 | "egressBurst": 8, |
| 139 | "prevResult": { |
| 140 | "interfaces": [ |
| 141 | { |
| 142 | "name": "%s", |
| 143 | "sandbox": "" |
| 144 | }, |
| 145 | { |
| 146 | "name": "%s", |
| 147 | "sandbox": "%s" |
| 148 | } |
| 149 | ], |
| 150 | "ips": [ |
| 151 | { |
| 152 | "version": "4", |
| 153 | "address": "%s/24", |
| 154 | "gateway": "10.0.0.1", |
| 155 | "interface": 1 |
| 156 | } |
| 157 | ], |
| 158 | "routes": [] |
| 159 | } |
| 160 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 161 | |
| 162 | args := &skel.CmdArgs{ |
| 163 | ContainerID: "dummy", |
| 164 | Netns: containerNs.Path(), |
| 165 | IfName: containerIfname, |
| 166 | StdinData: []byte(conf), |
| 167 | } |
| 168 | |
| 169 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 170 | defer GinkgoRecover() |
| 171 | r, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 172 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 173 | result, err := types100.GetResult(r) |
| 174 | Expect(err).NotTo(HaveOccurred()) |
| 175 | |
| 176 | Expect(result.Interfaces).To(HaveLen(3)) |
| 177 | Expect(result.Interfaces[2].Name).To(Equal(ifbDeviceName)) |
| 178 | Expect(result.Interfaces[2].Sandbox).To(Equal("")) |
| 179 | |
| 180 | ifbLink, err := netlinksafe.LinkByName(ifbDeviceName) |
| 181 | Expect(err).NotTo(HaveOccurred()) |
| 182 | Expect(ifbLink.Attrs().MTU).To(Equal(hostIfaceMTU)) |
| 183 | |
| 184 | qdiscs, err := netlinksafe.QdiscList(ifbLink) |
| 185 | Expect(err).NotTo(HaveOccurred()) |
| 186 | |
| 187 | Expect(qdiscs).To(HaveLen(1)) |
| 188 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(ifbLink.Attrs().Index)) |
| 189 | |
| 190 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 191 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(2))) |
| 192 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1))) |
| 193 | |
| 194 | hostVethLink, err := netlinksafe.LinkByName(hostIfname) |
| 195 | Expect(err).NotTo(HaveOccurred()) |
| 196 | |
| 197 | qdiscFilters, err := netlinksafe.FilterList(hostVethLink, netlink.MakeHandle(0xffff, 0)) |
| 198 | Expect(err).NotTo(HaveOccurred()) |
| 199 | |
| 200 | Expect(qdiscFilters).To(HaveLen(1)) |
| 201 | Expect(qdiscFilters[0].(*netlink.U32).Actions[0].(*netlink.MirredAction).Ifindex).To(Equal(ifbLink.Attrs().Index)) |
| 202 | |
| 203 | return nil |
| 204 | })).To(Succeed()) |
| 205 | |
| 206 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 207 | defer GinkgoRecover() |
| 208 | |
| 209 | ifbLink, err := netlinksafe.LinkByName(hostIfname) |
| 210 | Expect(err).NotTo(HaveOccurred()) |
| 211 | |
| 212 | qdiscs, err := netlinksafe.QdiscList(ifbLink) |
| 213 | Expect(err).NotTo(HaveOccurred()) |
| 214 | |
| 215 | Expect(qdiscs).To(HaveLen(2)) |
| 216 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(ifbLink.Attrs().Index)) |
| 217 | |
| 218 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 219 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(1))) |
| 220 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1))) |
| 221 | return nil |
| 222 | })).To(Succeed()) |
| 223 | }) |
| 224 | |
| 225 | It(fmt.Sprintf("[%s] does not apply ingress when disabled", ver), func() { |
| 226 | conf := fmt.Sprintf(`{ |
| 227 | "cniVersion": "%s", |
| 228 | "name": "cni-plugin-bandwidth-test", |
| 229 | "type": "bandwidth", |
| 230 | "ingressRate": 0, |
| 231 | "ingressBurst": 0, |
| 232 | "egressRate": 8000, |
| 233 | "egressBurst": 80, |
| 234 | "prevResult": { |
| 235 | "interfaces": [ |
| 236 | { |
| 237 | "name": "%s", |
| 238 | "sandbox": "" |
| 239 | }, |
| 240 | { |
| 241 | "name": "%s", |
| 242 | "sandbox": "%s" |
| 243 | } |
| 244 | ], |
| 245 | "ips": [ |
| 246 | { |
| 247 | "version": "4", |
| 248 | "address": "%s/24", |
| 249 | "gateway": "10.0.0.1", |
| 250 | "interface": 1 |
| 251 | } |
| 252 | ], |
| 253 | "routes": [] |
| 254 | } |
| 255 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 256 | |
| 257 | args := &skel.CmdArgs{ |
| 258 | ContainerID: "dummy", |
| 259 | Netns: containerNs.Path(), |
| 260 | IfName: containerIfname, |
| 261 | StdinData: []byte(conf), |
| 262 | } |
| 263 | |
| 264 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 265 | defer GinkgoRecover() |
| 266 | |
| 267 | _, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, ifbDeviceName, []byte(conf), func() error { return cmdAdd(args) }) |
| 268 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 269 | |
| 270 | _, err = netlinksafe.LinkByName(ifbDeviceName) |
| 271 | Expect(err).NotTo(HaveOccurred()) |
| 272 | return nil |
| 273 | })).To(Succeed()) |
| 274 | |
| 275 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 276 | defer GinkgoRecover() |
| 277 | |
| 278 | containerIfLink, err := netlinksafe.LinkByName(hostIfname) |
| 279 | Expect(err).NotTo(HaveOccurred()) |
| 280 | |
| 281 | qdiscs, err := netlinksafe.QdiscList(containerIfLink) |
| 282 | Expect(err).NotTo(HaveOccurred()) |
| 283 | |
| 284 | Expect(qdiscs).To(HaveLen(2)) |
| 285 | Expect(qdiscs[0]).NotTo(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 286 | Expect(qdiscs[1]).NotTo(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 287 | |
| 288 | return nil |
| 289 | })).To(Succeed()) |
| 290 | }) |
| 291 | |
| 292 | It(fmt.Sprintf("[%s] does not apply egress when disabled", ver), func() { |
| 293 | conf := fmt.Sprintf(`{ |
| 294 | "cniVersion": "%s", |
| 295 | "name": "cni-plugin-bandwidth-test", |
| 296 | "type": "bandwidth", |
| 297 | "egressRate": 0, |
| 298 | "egressBurst": 0, |
| 299 | "ingressRate": 8000, |
| 300 | "ingressBurst": 80, |
| 301 | "prevResult": { |
| 302 | "interfaces": [ |
| 303 | { |
| 304 | "name": "%s", |
| 305 | "sandbox": "" |
| 306 | }, |
| 307 | { |
| 308 | "name": "%s", |
| 309 | "sandbox": "%s" |
| 310 | } |
| 311 | ], |
| 312 | "ips": [ |
| 313 | { |
| 314 | "version": "4", |
| 315 | "address": "%s/24", |
| 316 | "gateway": "10.0.0.1", |
| 317 | "interface": 1 |
| 318 | } |
| 319 | ], |
| 320 | "routes": [] |
| 321 | } |
| 322 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 323 | |
| 324 | args := &skel.CmdArgs{ |
| 325 | ContainerID: "dummy", |
| 326 | Netns: containerNs.Path(), |
| 327 | IfName: containerIfname, |
| 328 | StdinData: []byte(conf), |
| 329 | } |
| 330 | |
| 331 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 332 | defer GinkgoRecover() |
| 333 | |
| 334 | _, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, ifbDeviceName, []byte(conf), func() error { return cmdAdd(args) }) |
| 335 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 336 | |
| 337 | _, err = netlinksafe.LinkByName(ifbDeviceName) |
| 338 | Expect(err).To(HaveOccurred()) |
| 339 | return nil |
| 340 | })).To(Succeed()) |
| 341 | |
| 342 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 343 | defer GinkgoRecover() |
| 344 | |
| 345 | containerIfLink, err := netlinksafe.LinkByName(hostIfname) |
| 346 | Expect(err).NotTo(HaveOccurred()) |
| 347 | |
| 348 | qdiscs, err := netlinksafe.QdiscList(containerIfLink) |
| 349 | Expect(err).NotTo(HaveOccurred()) |
| 350 | |
| 351 | Expect(qdiscs).To(HaveLen(1)) |
| 352 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(containerIfLink.Attrs().Index)) |
| 353 | |
| 354 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 355 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(1000))) |
| 356 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(35))) |
| 357 | return nil |
| 358 | })).To(Succeed()) |
| 359 | }) |
| 360 | |
| 361 | It(fmt.Sprintf("[%s] fails an invalid ingress config", ver), func() { |
| 362 | conf := fmt.Sprintf(`{ |
| 363 | "cniVersion": "%s", |
| 364 | "name": "cni-plugin-bandwidth-test", |
| 365 | "type": "bandwidth", |
| 366 | "ingressRate": 0, |
| 367 | "ingressBurst": 123, |
| 368 | "egressRate": 123, |
| 369 | "egressBurst": 123, |
| 370 | "prevResult": { |
| 371 | "interfaces": [ |
| 372 | { |
| 373 | "name": "%s", |
| 374 | "sandbox": "" |
| 375 | }, |
| 376 | { |
| 377 | "name": "%s", |
| 378 | "sandbox": "%s" |
| 379 | } |
| 380 | ], |
| 381 | "ips": [ |
| 382 | { |
| 383 | "version": "4", |
| 384 | "address": "%s/24", |
| 385 | "gateway": "10.0.0.1", |
| 386 | "interface": 1 |
| 387 | } |
| 388 | ], |
| 389 | "routes": [] |
| 390 | } |
| 391 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 392 | |
| 393 | args := &skel.CmdArgs{ |
| 394 | ContainerID: "dummy", |
| 395 | Netns: containerNs.Path(), |
| 396 | IfName: "eth0", |
| 397 | StdinData: []byte(conf), |
| 398 | } |
| 399 | |
| 400 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 401 | defer GinkgoRecover() |
| 402 | |
| 403 | _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 404 | Expect(err).To(MatchError("if burst is set, rate must also be set")) |
| 405 | return nil |
| 406 | })).To(Succeed()) |
| 407 | }) |
| 408 | |
| 409 | It(fmt.Sprintf("[%s] works with a Veth pair using runtime config", ver), func() { |
| 410 | conf := fmt.Sprintf(`{ |
| 411 | "cniVersion": "%s", |
| 412 | "name": "cni-plugin-bandwidth-test", |
| 413 | "type": "bandwidth", |
| 414 | "runtimeConfig": { |
| 415 | "bandWidth": { |
| 416 | "ingressRate": 8, |
| 417 | "ingressBurst": 8, |
| 418 | "egressRate": 16, |
| 419 | "egressBurst": 9 |
| 420 | } |
| 421 | }, |
| 422 | "prevResult": { |
| 423 | "interfaces": [ |
| 424 | { |
| 425 | "name": "%s", |
| 426 | "sandbox": "" |
| 427 | }, |
| 428 | { |
| 429 | "name": "%s", |
| 430 | "sandbox": "%s" |
| 431 | } |
| 432 | ], |
| 433 | "ips": [ |
| 434 | { |
| 435 | "version": "4", |
| 436 | "address": "%s/24", |
| 437 | "gateway": "10.0.0.1", |
| 438 | "interface": 1 |
| 439 | } |
| 440 | ], |
| 441 | "routes": [] |
| 442 | } |
| 443 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 444 | |
| 445 | args := &skel.CmdArgs{ |
| 446 | ContainerID: "dummy", |
| 447 | Netns: containerNs.Path(), |
| 448 | IfName: containerIfname, |
| 449 | StdinData: []byte(conf), |
| 450 | } |
| 451 | |
| 452 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 453 | defer GinkgoRecover() |
| 454 | r, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 455 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 456 | result, err := types100.GetResult(r) |
| 457 | Expect(err).NotTo(HaveOccurred()) |
| 458 | |
| 459 | Expect(result.Interfaces).To(HaveLen(3)) |
| 460 | Expect(result.Interfaces[2].Name).To(Equal(ifbDeviceName)) |
| 461 | Expect(result.Interfaces[2].Sandbox).To(Equal("")) |
| 462 | |
| 463 | ifbLink, err := netlinksafe.LinkByName(ifbDeviceName) |
| 464 | Expect(err).NotTo(HaveOccurred()) |
| 465 | Expect(ifbLink.Attrs().MTU).To(Equal(hostIfaceMTU)) |
| 466 | |
| 467 | qdiscs, err := netlinksafe.QdiscList(ifbLink) |
| 468 | Expect(err).NotTo(HaveOccurred()) |
| 469 | |
| 470 | Expect(qdiscs).To(HaveLen(1)) |
| 471 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(ifbLink.Attrs().Index)) |
| 472 | |
| 473 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 474 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(2))) |
| 475 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1))) |
| 476 | |
| 477 | hostVethLink, err := netlinksafe.LinkByName(hostIfname) |
| 478 | Expect(err).NotTo(HaveOccurred()) |
| 479 | |
| 480 | qdiscFilters, err := netlinksafe.FilterList(hostVethLink, netlink.MakeHandle(0xffff, 0)) |
| 481 | Expect(err).NotTo(HaveOccurred()) |
| 482 | |
| 483 | Expect(qdiscFilters).To(HaveLen(1)) |
| 484 | Expect(qdiscFilters[0].(*netlink.U32).Actions[0].(*netlink.MirredAction).Ifindex).To(Equal(ifbLink.Attrs().Index)) |
| 485 | |
| 486 | return nil |
| 487 | })).To(Succeed()) |
| 488 | |
| 489 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 490 | defer GinkgoRecover() |
| 491 | |
| 492 | ifbLink, err := netlinksafe.LinkByName(hostIfname) |
| 493 | Expect(err).NotTo(HaveOccurred()) |
| 494 | |
| 495 | qdiscs, err := netlinksafe.QdiscList(ifbLink) |
| 496 | Expect(err).NotTo(HaveOccurred()) |
| 497 | |
| 498 | Expect(qdiscs).To(HaveLen(2)) |
| 499 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(ifbLink.Attrs().Index)) |
| 500 | |
| 501 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 502 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(1))) |
| 503 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1))) |
| 504 | return nil |
| 505 | })).To(Succeed()) |
| 506 | }) |
| 507 | |
| 508 | It(fmt.Sprintf("[%s] should apply static config when both static config and runtime config exist", ver), func() { |
| 509 | conf := fmt.Sprintf(`{ |
| 510 | "cniVersion": "%s", |
| 511 | "name": "cni-plugin-bandwidth-test", |
| 512 | "type": "bandwidth", |
| 513 | "ingressRate": 0, |
| 514 | "ingressBurst": 123, |
| 515 | "egressRate": 123, |
| 516 | "egressBurst": 123, |
| 517 | "runtimeConfig": { |
| 518 | "bandWidth": { |
| 519 | "ingressRate": 8, |
| 520 | "ingressBurst": 8, |
| 521 | "egressRate": 16, |
| 522 | "egressBurst": 9 |
| 523 | } |
| 524 | }, |
| 525 | "prevResult": { |
| 526 | "interfaces": [ |
| 527 | { |
| 528 | "name": "%s", |
| 529 | "sandbox": "" |
| 530 | }, |
| 531 | { |
| 532 | "name": "%s", |
| 533 | "sandbox": "%s" |
| 534 | } |
| 535 | ], |
| 536 | "ips": [ |
| 537 | { |
| 538 | "version": "4", |
| 539 | "address": "%s/24", |
| 540 | "gateway": "10.0.0.1", |
| 541 | "interface": 1 |
| 542 | } |
| 543 | ], |
| 544 | "routes": [] |
| 545 | } |
| 546 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 547 | |
| 548 | args := &skel.CmdArgs{ |
| 549 | ContainerID: "dummy", |
| 550 | Netns: containerNs.Path(), |
| 551 | IfName: "eth0", |
| 552 | StdinData: []byte(conf), |
| 553 | } |
| 554 | |
| 555 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 556 | defer GinkgoRecover() |
| 557 | |
| 558 | _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 559 | Expect(err).To(MatchError("if burst is set, rate must also be set")) |
| 560 | return nil |
| 561 | })).To(Succeed()) |
| 562 | }) |
| 563 | }) |
| 564 | |
| 565 | Describe("cmdDEL", func() { |
| 566 | It(fmt.Sprintf("[%s] works with a Veth pair using 0.3.0 config", ver), func() { |
| 567 | conf := fmt.Sprintf(`{ |
| 568 | "cniVersion": "%s", |
| 569 | "name": "cni-plugin-bandwidth-test", |
| 570 | "type": "bandwidth", |
| 571 | "ingressRate": 8, |
| 572 | "ingressBurst": 8, |
| 573 | "egressRate": 9, |
| 574 | "egressBurst": 9, |
| 575 | "prevResult": { |
| 576 | "interfaces": [ |
| 577 | { |
| 578 | "name": "%s", |
| 579 | "sandbox": "" |
| 580 | }, |
| 581 | { |
| 582 | "name": "%s", |
| 583 | "sandbox": "%s" |
| 584 | } |
| 585 | ], |
| 586 | "ips": [ |
| 587 | { |
| 588 | "version": "4", |
| 589 | "address": "%s/24", |
| 590 | "gateway": "10.0.0.1", |
| 591 | "interface": 1 |
| 592 | } |
| 593 | ], |
| 594 | "routes": [] |
| 595 | } |
| 596 | }`, ver, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 597 | |
| 598 | args := &skel.CmdArgs{ |
| 599 | ContainerID: "dummy", |
| 600 | Netns: containerNs.Path(), |
| 601 | IfName: containerIfname, |
| 602 | StdinData: []byte(conf), |
| 603 | } |
| 604 | |
| 605 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 606 | defer GinkgoRecover() |
| 607 | _, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 608 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 609 | |
| 610 | err = testutils.CmdDel(containerNs.Path(), args.ContainerID, "", func() error { return cmdDel(args) }) |
| 611 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 612 | |
| 613 | _, err = netlinksafe.LinkByName(ifbDeviceName) |
| 614 | Expect(err).To(HaveOccurred()) |
| 615 | |
| 616 | return nil |
| 617 | })).To(Succeed()) |
| 618 | }) |
| 619 | }) |
| 620 | |
| 621 | Describe("Getting the host interface which plugin should work on from veth peer of container interface", func() { |
| 622 | It(fmt.Sprintf("[%s] should work with multiple host veth interfaces", ver), func() { |
| 623 | // create veth peer in host ns |
| 624 | vethName, peerName := "host-veth-peer1", "host-veth-peer2" |
| 625 | createVethInOneNs(hostNs, vethName, peerName) |
| 626 | |
| 627 | conf := fmt.Sprintf(`{ |
| 628 | "cniVersion": "%s", |
| 629 | "name": "cni-plugin-bandwidth-test", |
| 630 | "type": "bandwidth", |
| 631 | "ingressRate": 8, |
| 632 | "ingressBurst": 8, |
| 633 | "egressRate": 16, |
| 634 | "egressBurst": 8, |
| 635 | "prevResult": { |
| 636 | "interfaces": [ |
| 637 | { |
| 638 | "name": "%s", |
| 639 | "sandbox": "" |
| 640 | }, |
| 641 | { |
| 642 | "name": "%s", |
| 643 | "sandbox": "" |
| 644 | }, |
| 645 | { |
| 646 | "name": "%s", |
| 647 | "sandbox": "" |
| 648 | }, |
| 649 | { |
| 650 | "name": "%s", |
| 651 | "sandbox": "%s" |
| 652 | } |
| 653 | ], |
| 654 | "ips": [ |
| 655 | { |
| 656 | "version": "4", |
| 657 | "address": "%s/24", |
| 658 | "gateway": "10.0.0.1", |
| 659 | "interface": 1 |
| 660 | } |
| 661 | ], |
| 662 | "routes": [] |
| 663 | } |
| 664 | }`, ver, vethName, peerName, hostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 665 | |
| 666 | args := &skel.CmdArgs{ |
| 667 | ContainerID: "dummy", |
| 668 | Netns: containerNs.Path(), |
| 669 | IfName: containerIfname, |
| 670 | StdinData: []byte(conf), |
| 671 | } |
| 672 | |
| 673 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 674 | defer GinkgoRecover() |
| 675 | r, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 676 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 677 | result, err := types100.GetResult(r) |
| 678 | Expect(err).NotTo(HaveOccurred()) |
| 679 | |
| 680 | Expect(result.Interfaces).To(HaveLen(5)) |
| 681 | Expect(result.Interfaces[4].Name).To(Equal(ifbDeviceName)) |
| 682 | Expect(result.Interfaces[4].Sandbox).To(Equal("")) |
| 683 | |
| 684 | ifbLink, err := netlinksafe.LinkByName(ifbDeviceName) |
| 685 | Expect(err).NotTo(HaveOccurred()) |
| 686 | Expect(ifbLink.Attrs().MTU).To(Equal(hostIfaceMTU)) |
| 687 | |
| 688 | qdiscs, err := netlinksafe.QdiscList(ifbLink) |
| 689 | Expect(err).NotTo(HaveOccurred()) |
| 690 | |
| 691 | Expect(qdiscs).To(HaveLen(1)) |
| 692 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(ifbLink.Attrs().Index)) |
| 693 | |
| 694 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 695 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(2))) |
| 696 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1))) |
| 697 | |
| 698 | hostVethLink, err := netlinksafe.LinkByName(hostIfname) |
| 699 | Expect(err).NotTo(HaveOccurred()) |
| 700 | |
| 701 | qdiscFilters, err := netlinksafe.FilterList(hostVethLink, netlink.MakeHandle(0xffff, 0)) |
| 702 | Expect(err).NotTo(HaveOccurred()) |
| 703 | |
| 704 | Expect(qdiscFilters).To(HaveLen(1)) |
| 705 | Expect(qdiscFilters[0].(*netlink.U32).Actions[0].(*netlink.MirredAction).Ifindex).To(Equal(ifbLink.Attrs().Index)) |
| 706 | |
| 707 | return nil |
| 708 | })).To(Succeed()) |
| 709 | |
| 710 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 711 | defer GinkgoRecover() |
| 712 | |
| 713 | ifbLink, err := netlinksafe.LinkByName(hostIfname) |
| 714 | Expect(err).NotTo(HaveOccurred()) |
| 715 | |
| 716 | qdiscs, err := netlinksafe.QdiscList(ifbLink) |
| 717 | Expect(err).NotTo(HaveOccurred()) |
| 718 | |
| 719 | Expect(qdiscs).To(HaveLen(2)) |
| 720 | Expect(qdiscs[0].Attrs().LinkIndex).To(Equal(ifbLink.Attrs().Index)) |
| 721 | |
| 722 | Expect(qdiscs[0]).To(BeAssignableToTypeOf(&netlink.Tbf{})) |
| 723 | Expect(qdiscs[0].(*netlink.Tbf).Rate).To(Equal(uint64(1))) |
| 724 | Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1))) |
| 725 | return nil |
| 726 | })).To(Succeed()) |
| 727 | }) |
| 728 | |
| 729 | It(fmt.Sprintf("[%s] should fail when container interface has no veth peer", ver), func() { |
| 730 | // create a macvlan device to be container interface |
| 731 | macvlanContainerIfname := "container-macv" |
| 732 | createMacvlan(containerNs, containerIfname, macvlanContainerIfname) |
| 733 | |
| 734 | conf := fmt.Sprintf(`{ |
| 735 | "cniVersion": "%s", |
| 736 | "name": "cni-plugin-bandwidth-test", |
| 737 | "type": "bandwidth", |
| 738 | "ingressRate": 8, |
| 739 | "ingressBurst": 8, |
| 740 | "egressRate": 16, |
| 741 | "egressBurst": 8, |
| 742 | "prevResult": { |
| 743 | "interfaces": [ |
| 744 | { |
| 745 | "name": "%s", |
| 746 | "sandbox": "" |
| 747 | }, |
| 748 | { |
| 749 | "name": "%s", |
| 750 | "sandbox": "%s" |
| 751 | } |
| 752 | ], |
| 753 | "ips": [ |
| 754 | { |
| 755 | "version": "4", |
| 756 | "address": "%s/24", |
| 757 | "gateway": "10.0.0.1", |
| 758 | "interface": 1 |
| 759 | } |
| 760 | ], |
| 761 | "routes": [] |
| 762 | } |
| 763 | }`, ver, hostIfname, macvlanContainerIfname, containerNs.Path(), containerIP.String()) |
| 764 | |
| 765 | args := &skel.CmdArgs{ |
| 766 | ContainerID: "dummy", |
| 767 | Netns: containerNs.Path(), |
| 768 | IfName: macvlanContainerIfname, |
| 769 | StdinData: []byte(conf), |
| 770 | } |
| 771 | |
| 772 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 773 | defer GinkgoRecover() |
| 774 | |
| 775 | _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 776 | Expect(err).To(HaveOccurred()) |
| 777 | |
| 778 | return nil |
| 779 | })).To(Succeed()) |
| 780 | }) |
| 781 | |
| 782 | It(fmt.Sprintf("[%s] should fail when preResult has no interfaces", ver), func() { |
| 783 | conf := fmt.Sprintf(`{ |
| 784 | "cniVersion": "%s", |
| 785 | "name": "cni-plugin-bandwidth-test", |
| 786 | "type": "bandwidth", |
| 787 | "ingressRate": 8, |
| 788 | "ingressBurst": 8, |
| 789 | "egressRate": 16, |
| 790 | "egressBurst": 8, |
| 791 | "prevResult": { |
| 792 | "interfaces": [], |
| 793 | "ips": [], |
| 794 | "routes": [] |
| 795 | } |
| 796 | }`, ver) |
| 797 | |
| 798 | args := &skel.CmdArgs{ |
| 799 | ContainerID: "dummy", |
| 800 | Netns: containerNs.Path(), |
| 801 | IfName: "eth0", |
| 802 | StdinData: []byte(conf), |
| 803 | } |
| 804 | |
| 805 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 806 | defer GinkgoRecover() |
| 807 | |
| 808 | _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 809 | Expect(err).To(HaveOccurred()) |
| 810 | |
| 811 | return nil |
| 812 | })).To(Succeed()) |
| 813 | }) |
| 814 | |
| 815 | It(fmt.Sprintf("[%s] should fail when veth peer of container interface does not match any of host interfaces in preResult", ver), func() { |
| 816 | // fake a non-exist host interface name |
| 817 | fakeHostIfname := fmt.Sprintf("%s-fake", hostIfname) |
| 818 | |
| 819 | conf := fmt.Sprintf(`{ |
| 820 | "cniVersion": "%s", |
| 821 | "name": "cni-plugin-bandwidth-test", |
| 822 | "type": "bandwidth", |
| 823 | "ingressRate": 8, |
| 824 | "ingressBurst": 8, |
| 825 | "egressRate": 16, |
| 826 | "egressBurst": 8, |
| 827 | "prevResult": { |
| 828 | "interfaces": [ |
| 829 | { |
| 830 | "name": "%s", |
| 831 | "sandbox": "" |
| 832 | }, |
| 833 | { |
| 834 | "name": "%s", |
| 835 | "sandbox": "%s" |
| 836 | } |
| 837 | ], |
| 838 | "ips": [ |
| 839 | { |
| 840 | "version": "4", |
| 841 | "address": "%s/24", |
| 842 | "gateway": "10.0.0.1", |
| 843 | "interface": 1 |
| 844 | } |
| 845 | ], |
| 846 | "routes": [] |
| 847 | } |
| 848 | }`, ver, fakeHostIfname, containerIfname, containerNs.Path(), containerIP.String()) |
| 849 | |
| 850 | args := &skel.CmdArgs{ |
| 851 | ContainerID: "dummy", |
| 852 | Netns: containerNs.Path(), |
| 853 | IfName: containerIfname, |
| 854 | StdinData: []byte(conf), |
| 855 | } |
| 856 | |
| 857 | Expect(hostNs.Do(func(_ ns.NetNS) error { |
| 858 | defer GinkgoRecover() |
| 859 | |
| 860 | _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) |
| 861 | Expect(err).To(HaveOccurred()) |
| 862 | |
| 863 | return nil |
| 864 | })).To(Succeed()) |
| 865 | }) |
| 866 | }) |
| 867 | |
| 868 | Context(fmt.Sprintf("[%s] when chaining bandwidth plugin with PTP", ver), func() { |
| 869 | var ptpConf string |
| 870 | var rateInBits uint64 |
| 871 | var burstInBits uint64 |
| 872 | var packetInBytes int |
| 873 | var containerWithoutTbfNS ns.NetNS |
| 874 | var containerWithTbfNS ns.NetNS |
| 875 | var portServerWithTbf int |
| 876 | var portServerWithoutTbf int |
| 877 | |
| 878 | var containerWithTbfRes types.Result |
| 879 | var containerWithoutTbfRes types.Result |
| 880 | var echoServerWithTbf *gexec.Session |
| 881 | var echoServerWithoutTbf *gexec.Session |
| 882 | var dataDir string |
| 883 | |
| 884 | BeforeEach(func() { |
| 885 | rateInBytes := 1000 |
| 886 | rateInBits = uint64(rateInBytes * 8) |
| 887 | burstInBits = rateInBits * 2 |
| 888 | packetInBytes = rateInBytes * 25 |
| 889 | |
| 890 | var err error |
| 891 | dataDir, err = os.MkdirTemp("", "bandwidth_linux_test") |
| 892 | Expect(err).NotTo(HaveOccurred()) |
| 893 | |
| 894 | ptpConf = fmt.Sprintf(`{ |
| 895 | "cniVersion": "%s", |
| 896 | "name": "myBWnet", |
| 897 | "type": "ptp", |
| 898 | "ipMasq": true, |
| 899 | "mtu": 512, |
| 900 | "ipam": { |
| 901 | "type": "host-local", |
| 902 | "subnet": "10.1.2.0/24", |
| 903 | "dataDir": "%s" |
| 904 | } |
| 905 | }`, ver, dataDir) |
| 906 | |
| 907 | const ( |
| 908 | containerWithTbfIFName = "ptp0" |
| 909 | containerWithoutTbfIFName = "ptp1" |
| 910 | ) |
| 911 | |
| 912 | containerWithTbfNS, err = testutils.NewNS() |
| 913 | Expect(err).NotTo(HaveOccurred()) |
| 914 | |
| 915 | containerWithoutTbfNS, err = testutils.NewNS() |
| 916 | Expect(err).NotTo(HaveOccurred()) |
| 917 | |
| 918 | By("create two containers, and use the bandwidth plugin on one of them") |
| 919 | Expect(hostNs.Do(func(ns.NetNS) error { |
| 920 | defer GinkgoRecover() |
| 921 | |
| 922 | containerWithTbfRes, _, err = testutils.CmdAdd(containerWithTbfNS.Path(), "dummy", containerWithTbfIFName, []byte(ptpConf), func() error { |
| 923 | r, err := invoke.DelegateAdd(context.TODO(), "ptp", []byte(ptpConf), nil) |
| 924 | Expect(err).NotTo(HaveOccurred()) |
| 925 | Expect(r.Print()).To(Succeed()) |
| 926 | |
| 927 | return err |
| 928 | }) |
| 929 | Expect(err).NotTo(HaveOccurred()) |
| 930 | |
| 931 | containerWithoutTbfRes, _, err = testutils.CmdAdd(containerWithoutTbfNS.Path(), "dummy2", containerWithoutTbfIFName, []byte(ptpConf), func() error { |
| 932 | r, err := invoke.DelegateAdd(context.TODO(), "ptp", []byte(ptpConf), nil) |
| 933 | Expect(err).NotTo(HaveOccurred()) |
| 934 | Expect(r.Print()).To(Succeed()) |
| 935 | |
| 936 | return err |
| 937 | }) |
| 938 | Expect(err).NotTo(HaveOccurred()) |
| 939 | |
| 940 | containerWithTbfResult, err := types100.GetResult(containerWithTbfRes) |
| 941 | Expect(err).NotTo(HaveOccurred()) |
| 942 | |
| 943 | tbfPluginConf := &PluginConf{} |
| 944 | err = json.Unmarshal([]byte(ptpConf), &tbfPluginConf) |
| 945 | Expect(err).NotTo(HaveOccurred()) |
| 946 | |
| 947 | tbfPluginConf.RuntimeConfig.Bandwidth = &BandwidthEntry{ |
| 948 | IngressBurst: burstInBits, |
| 949 | IngressRate: rateInBits, |
| 950 | EgressBurst: burstInBits, |
| 951 | EgressRate: rateInBits, |
| 952 | } |
| 953 | tbfPluginConf.Type = "bandwidth" |
| 954 | newConfBytes, err := buildOneConfig("myBWnet", ver, tbfPluginConf, containerWithTbfResult) |
| 955 | Expect(err).NotTo(HaveOccurred()) |
| 956 | |
| 957 | args := &skel.CmdArgs{ |
| 958 | ContainerID: "dummy3", |
| 959 | Netns: containerWithTbfNS.Path(), |
| 960 | IfName: containerWithTbfIFName, |
| 961 | StdinData: newConfBytes, |
| 962 | } |
| 963 | |
| 964 | result, out, err := testutils.CmdAdd(containerWithTbfNS.Path(), args.ContainerID, "", newConfBytes, func() error { return cmdAdd(args) }) |
| 965 | Expect(err).NotTo(HaveOccurred(), string(out)) |
| 966 | |
| 967 | if testutils.SpecVersionHasCHECK(ver) { |
| 968 | // Do CNI Check |
| 969 | checkConf := &PluginConf{} |
| 970 | err = json.Unmarshal([]byte(ptpConf), &checkConf) |
| 971 | Expect(err).NotTo(HaveOccurred()) |
| 972 | |
| 973 | checkConf.RuntimeConfig.Bandwidth = &BandwidthEntry{ |
| 974 | IngressBurst: burstInBits, |
| 975 | IngressRate: rateInBits, |
| 976 | EgressBurst: burstInBits, |
| 977 | EgressRate: rateInBits, |
| 978 | } |
| 979 | checkConf.Type = "bandwidth" |
| 980 | |
| 981 | newCheckBytes, err := buildOneConfig("myBWnet", ver, checkConf, result) |
| 982 | Expect(err).NotTo(HaveOccurred()) |
| 983 | |
| 984 | args = &skel.CmdArgs{ |
| 985 | ContainerID: "dummy3", |
| 986 | Netns: containerWithTbfNS.Path(), |
| 987 | IfName: containerWithTbfIFName, |
| 988 | StdinData: newCheckBytes, |
| 989 | } |
| 990 | |
| 991 | err = testutils.CmdCheck(containerWithTbfNS.Path(), args.ContainerID, "", func() error { return cmdCheck(args) }) |
| 992 | Expect(err).NotTo(HaveOccurred()) |
| 993 | } |
| 994 | |
| 995 | return nil |
| 996 | })).To(Succeed()) |
| 997 | |
| 998 | By("starting a tcp server on both containers") |
| 999 | portServerWithTbf, echoServerWithTbf = startEchoServerInNamespace(containerWithTbfNS) |
| 1000 | portServerWithoutTbf, echoServerWithoutTbf = startEchoServerInNamespace(containerWithoutTbfNS) |
| 1001 | }) |
| 1002 | |
| 1003 | AfterEach(func() { |
| 1004 | Expect(os.RemoveAll(dataDir)).To(Succeed()) |
| 1005 | |
| 1006 | Expect(containerWithTbfNS.Close()).To(Succeed()) |
| 1007 | Expect(testutils.UnmountNS(containerWithTbfNS)).To(Succeed()) |
| 1008 | Expect(containerWithoutTbfNS.Close()).To(Succeed()) |
| 1009 | Expect(testutils.UnmountNS(containerWithoutTbfNS)).To(Succeed()) |
| 1010 | |
| 1011 | if echoServerWithoutTbf != nil { |
| 1012 | echoServerWithoutTbf.Kill() |
| 1013 | } |
| 1014 | if echoServerWithTbf != nil { |
| 1015 | echoServerWithTbf.Kill() |
| 1016 | } |
| 1017 | }) |
| 1018 | |
| 1019 | Measure("limits ingress traffic on veth device", func(b Benchmarker) { |
| 1020 | var runtimeWithLimit time.Duration |
| 1021 | var runtimeWithoutLimit time.Duration |
| 1022 | |
| 1023 | By("gather timing statistics about both containers") |
| 1024 | By("sending tcp traffic to the container that has traffic shaped", func() { |
| 1025 | runtimeWithLimit = b.Time("with tbf", func() { |
| 1026 | result, err := types100.GetResult(containerWithTbfRes) |
| 1027 | Expect(err).NotTo(HaveOccurred()) |
| 1028 | |
| 1029 | makeTCPClientInNS(hostNs.Path(), result.IPs[0].Address.IP.String(), portServerWithTbf, packetInBytes) |
| 1030 | }) |
| 1031 | }) |
| 1032 | |
| 1033 | By("sending tcp traffic to the container that does not have traffic shaped", func() { |
| 1034 | runtimeWithoutLimit = b.Time("without tbf", func() { |
| 1035 | result, err := types100.GetResult(containerWithoutTbfRes) |
| 1036 | Expect(err).NotTo(HaveOccurred()) |
| 1037 | |
| 1038 | makeTCPClientInNS(hostNs.Path(), result.IPs[0].Address.IP.String(), portServerWithoutTbf, packetInBytes) |
| 1039 | }) |
| 1040 | }) |
| 1041 | |
| 1042 | Expect(runtimeWithLimit).To(BeNumerically(">", runtimeWithoutLimit+1000*time.Millisecond)) |
| 1043 | }, 1) |
| 1044 | }) |
| 1045 | } |
| 1046 | |
| 1047 | Describe("Validating input", func() { |
| 1048 | It("Should allow only 4GB burst rate", func() { |
| 1049 | err := validateRateAndBurst(5000, 4*1024*1024*1024*8-16) // 2 bytes less than the max should pass |
| 1050 | Expect(err).NotTo(HaveOccurred()) |
| 1051 | err = validateRateAndBurst(5000, 4*1024*1024*1024*8) // we're 1 bit above MaxUint32 |
| 1052 | Expect(err).To(HaveOccurred()) |
| 1053 | err = validateRateAndBurst(0, 1) |
| 1054 | Expect(err).To(HaveOccurred()) |
| 1055 | err = validateRateAndBurst(1, 0) |
| 1056 | Expect(err).To(HaveOccurred()) |
| 1057 | err = validateRateAndBurst(0, 0) |
| 1058 | Expect(err).NotTo(HaveOccurred()) |
| 1059 | }) |
| 1060 | }) |
| 1061 | }) |