-
Notifications
You must be signed in to change notification settings - Fork 6
/
switch_test.go
46 lines (36 loc) · 1.19 KB
/
switch_test.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
// SPDX-FileCopyrightText: 2023 Steffen Vogel <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package gont_test
import (
"testing"
g "cunicu.li/gont/v2/pkg"
o "cunicu.li/gont/v2/pkg/options"
"github.com/stretchr/testify/require"
)
// TestPing performs and end-to-end ping test
// between two hosts on a switched topology
//
// h1 <-> sw1 <-> sw2 <-> h2
func TestPingCascadedSwitches(t *testing.T) {
n, err := g.NewNetwork(*nname, globalNetworkOptions...)
require.NoError(t, err, "Failed to create network")
defer n.Close()
sw1, err := n.AddSwitch("sw1")
require.NoError(t, err, "Failed to add switch")
sw2, err := n.AddSwitch("sw2")
require.NoError(t, err, "Failed to add switch")
h1, err := n.AddHost("h1",
g.NewInterface("veth0", sw1,
o.AddressIP("10.0.0.1/24")))
require.NoError(t, err, "Failed to add host")
h2, err := n.AddHost("h2",
g.NewInterface("veth0", sw2,
o.AddressIP("10.0.0.2/24")))
require.NoError(t, err, "Failed to add host")
err = n.AddLink(
g.NewInterface("br-sw2", sw1),
g.NewInterface("br-sw1", sw2))
require.NoError(t, err, "Failed to add link")
err = g.TestConnectivity(h1, h2)
require.NoError(t, err, "Failed to check connectivity")
}