Skip to content

Commit

Permalink
add multicast e2e example
Browse files Browse the repository at this point in the history
  • Loading branch information
ceclinux committed Nov 3, 2021
1 parent b78862c commit 23ac04f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/images/ovs/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2019 Antrea Authors
# Copyright 2021 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (
antreaDefaultGW string = "antrea-gw0"
testNamespace string = "antrea-test"
busyboxContainerName string = "busybox"
mcjoinContainerName string = "mcjoin"
agnhostContainerName string = "agnhost"
controllerContainerName string = "antrea-controller"
ovsContainerName string = "antrea-ovs"
Expand Down Expand Up @@ -105,6 +106,7 @@ const (

agnhostImage = "projects.registry.vmware.com/antrea/agnhost:2.26"
busyboxImage = "projects.registry.vmware.com/library/busybox"
mcjoinImage = "troglobit/mcjoin"
nginxImage = "projects.registry.vmware.com/antrea/nginx"
perftoolImage = "projects.registry.vmware.com/antrea/perftool"
ipfixCollectorImage = "projects.registry.vmware.com/antrea/ipfix-collector:v0.5.8"
Expand Down Expand Up @@ -1035,6 +1037,11 @@ func (data *TestData) createBusyboxPodOnNode(name string, ns string, nodeName st
return data.createPodOnNode(name, ns, nodeName, busyboxImage, []string{"sleep", strconv.Itoa(sleepDuration)}, nil, nil, nil, hostNetwork, nil)
}

func (data *TestData) createMcJoinPodOnNode(name string, ns string, nodeName string, hostNetwork bool) error {
sleepDuration := 3600 // seconds
return data.createPodOnNode(name, ns, nodeName, mcjoinImage, []string{"sleep", strconv.Itoa(sleepDuration)}, nil, nil, nil, hostNetwork, nil)
}

// createNginxPodOnNode creates a Pod in the test namespace with a single nginx container. The
// Pod will be scheduled on the specified Node (if nodeName is not empty).
func (data *TestData) createNginxPodOnNode(name string, ns string, nodeName string, hostNetwork bool) error {
Expand Down
67 changes: 67 additions & 0 deletions test/e2e/multicast_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2019 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"antrea.io/antrea/pkg/agent/config"
"antrea.io/antrea/pkg/features"
)

func skipIfMulticastDisabled(tb testing.TB) {
skipIfFeatureDisabled(tb, features.Multicast, true, false)
}

func TestMulticast(t *testing.T) {
skipIfHasWindowsNodes(t)
skipIfNotIPv4Cluster(t)
skipIfMulticastDisabled(t)

data, err := setupTest(t)
if err != nil {
t.Fatalf("Error when setting up test: %v", err)
}
defer teardownTest(t, data)

t.Run("testMulticastBetweenPods", func(t *testing.T) {
skipIfEncapModeIsNot(t, data, config.TrafficEncapModeNoEncap)
testMulticastBetweenPods(t, data)
})
}

func testMulticastBetweenPods(t *testing.T, data *TestData) {
senderName, _, cleanupFunc := createAndWaitForPod(t, data, data.createMcJoinPodOnNode, "test-server-", "", testNamespace, false)
defer cleanupFunc()

receiverName, _, cleanupFunc := createAndWaitForPod(t, data, data.createMcJoinPodOnNode, "test-client-", "", testNamespace, false)
defer cleanupFunc()

multicastGroup := "224.1.2.3"

if clusterInfo.podV4NetworkCIDR != "" {
cmd := []string{"/bin/sh", "-c", fmt.Sprintf("mcjoin -c 100 -o -p 3456 -s -w 3 %s", multicastGroup)}
go func() {
data.runCommandFromPod(testNamespace, senderName, mcjoinContainerName, cmd)
}()
// set timeout to 10
cmd2 := []string{"/bin/sh", "-c", fmt.Sprintf("mcjoin -c 1 -o -p 3456 -W 10 %s", multicastGroup)}
res, _, _ := data.runCommandFromPod(testNamespace, receiverName, mcjoinContainerName, cmd2)
assert.Contains(t, res, "Total: 1 packets")
}
}

0 comments on commit 23ac04f

Please sign in to comment.