netport

package
v1.8.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2021 License: GPL-2.0, GPL-2.0-or-later Imports: 7 Imported by: 1

Documentation

Overview

Package netport parses testdata/netport.yaml for interface assingments along with utilities to build and test virtual networks configured from these assignments.

Index

Constants

View Source
const NetPortFile = "testdata/netport.yaml"

Variables

View Source
var BridgeNets0 = NetDevs{
	{
		Netns:   "h1",
		Vlan:    100,
		NetPort: "net0port0",
		Ifa:     "10.1.0.1/24",
		Remotes: []string{"10.1.0.2", "10.1.0.3"},
	},

	{
		Netns:   "r",
		Kind:    "xeth-bridge",
		Ifname:  "tb1",
		Ifa:     "10.1.0.2/24",
		Remotes: []string{"10.1.0.1", "10.1.0.3"},
		Lowers: []PortVlan{
			{NetPort: "net0port1", Vlan: 100},
			{NetPort: "net1port1", Vlan: 0},
		},
	},
	{
		Netns:   "h2",
		NetPort: "net1port0",
		Ifa:     "10.1.0.3/24",
		Remotes: []string{"10.1.0.1", "10.1.0.2"},
	},
}
View Source
var BridgeNets1 = NetDevs{
	{
		Netns:   "h1",
		Vlan:    100,
		NetPort: "net0port0",
		Ifa:     "10.1.0.2/24",
		Routes: []Route{
			{"10.2.0.0/24", "10.1.0.1"},
		},
		Remotes: []string{"10.1.0.1", "10.2.0.1", "10.2.0.2"},
	},

	{
		Netns:   "r",
		Kind:    "xeth-bridge",
		Ifname:  "tb1",
		Ifa:     "10.1.0.1/24",
		Remotes: []string{"10.1.0.2", "10.2.0.2"},
		Lowers: []PortVlan{
			{NetPort: "net0port1", Vlan: 100},
		},
	},
	{
		Netns:   "r",
		Kind:    "xeth-bridge",
		Ifname:  "tb3",
		Ifa:     "10.2.0.1/24",
		Remotes: []string{"10.1.0.2", "10.2.0.2"},
		Lowers: []PortVlan{
			{NetPort: "net1port1", Vlan: 200},
		},
	},

	{
		Netns:   "h2",
		Vlan:    200,
		NetPort: "net1port0",
		Ifa:     "10.2.0.2/24",
		Routes: []Route{
			{"10.1.0.0/24", "10.2.0.1"},
		},
		Remotes: []string{"10.2.0.1", "10.1.0.1", "10.1.0.2"},
	},
}
View Source
var BridgeNets1u = NetDevs{
	{
		Netns:   "h1",
		NetPort: "net0port0",
		Ifa:     "10.1.0.2/24",
		Routes: []Route{
			{"10.2.0.0/24", "10.1.0.1"},
		},
		Remotes: []string{"10.1.0.1", "10.2.0.1", "10.2.0.2"},
	},

	{
		Netns:   "r",
		Kind:    "xeth-bridge",
		Ifname:  "tb1",
		Ifa:     "10.1.0.1/24",
		Remotes: []string{"10.1.0.2", "10.2.0.2"},
		Lowers: []PortVlan{
			{NetPort: "net0port1", Vlan: 0},
		},
	},
	{
		Netns:   "r",
		Kind:    "xeth-bridge",
		Ifname:  "tb3",
		Ifa:     "10.2.0.1/24",
		Remotes: []string{"10.1.0.2", "10.2.0.2"},
		Lowers: []PortVlan{
			{NetPort: "net1port1", Vlan: 0},
		},
	},

	{
		Netns:   "h2",
		NetPort: "net1port0",
		Ifa:     "10.2.0.2/24",
		Routes: []Route{
			{"10.1.0.0/24", "10.2.0.1"},
		},
		Remotes: []string{"10.2.0.1", "10.1.0.1", "10.1.0.2"},
	},
}
View Source
var FourNets = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h1",
		Ifa:     "10.1.0.0/31",
		DummyIfs: []DummyIf{
			{"dummy0", "10.5.5.5"},
		},
		Routes: []Route{
			{"10.1.0.2/31", "10.1.0.1"},
			{"10.6.6.6", "10.1.0.1"},
		},
		Remotes: []string{"10.1.0.2", "10.6.6.6"},
	},
	{
		NetPort: "net0port1",
		Netns:   "r",
		Ifa:     "10.1.0.1/31",
		Routes: []Route{
			{"10.5.5.5", "10.1.0.0"},
		},
	},
	{
		NetPort: "net1port0",
		Netns:   "h2",
		Ifa:     "10.1.0.2/31",
		DummyIfs: []DummyIf{
			{"dummy0", "10.6.6.6"},
		},
		Routes: []Route{
			{"10.1.0.0/31", "10.1.0.3"},
			{"10.5.5.5", "10.1.0.3"},
		},
		Remotes: []string{"10.1.0.0", "10.5.5.5"},
	},
	{
		NetPort: "net1port1",
		Netns:   "r",
		Ifa:     "10.1.0.3/31",
		Routes: []Route{
			{"10.6.6.6", "10.1.0.2"},
		},
	},
	{
		NetPort: "net2port0",
		Netns:   "h1",
		Ifa:     "10.2.0.0/31",
		Routes: []Route{
			{"10.2.0.2/31", "10.2.0.1"},
			{"10.1.0.0/31", "10.2.0.1"},
			{"10.6.6.6", "10.2.0.1"},
		},
		Remotes: []string{"10.2.0.2"},
	},
	{
		NetPort: "net2port1",
		Netns:   "r",
		Ifa:     "10.2.0.1/31",
		Routes: []Route{
			{"10.5.5.5", "10.2.0.0"},
			{"10.1.0.0/31", "10.2.0.0"},
		},
	},
	{
		NetPort: "net3port0",
		Netns:   "h2",
		Ifa:     "10.2.0.2/31",
		Routes: []Route{
			{"10.2.0.0/31", "10.2.0.3"},
			{"10.1.0.2/31", "10.2.0.3"},
			{"10.5.5.5", "10.2.0.3"},
		},
		Remotes: []string{"10.2.0.0"},
	},
	{
		NetPort: "net3port1",
		Netns:   "r",
		Ifa:     "10.2.0.3/31",
		Routes: []Route{
			{"10.1.0.2/31", "10.2.0.2"},
			{"10.6.6.6", "10.2.0.2"},
		},
	},
}

TwoNets virtual network:

h1:net0port0 <-> r:net0port1
h2:net1port0 <-> r:net1port1
View Source
var FourNetsIp6 = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h1",
		Ifa:     "fc01:1:2:3:4:5:6:1/64",
		DummyIfs: []DummyIf{
			{"dummy0", "fc:5:5:5:5:5:5:5"},
		},
		Routes: []Route{
			{"fc02:1:2:3:4:5:6:1/64", "fc01:1:2:3:4:5:6:2"},
			{"fc:6:6:6:6:6:6:6", "fc01:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc02:1:2:3:4:5:6:1", "fc:6:6:6:6:6:6:6"},
	},
	{
		NetPort: "net0port1",
		Netns:   "r",
		Ifa:     "fc01:1:2:3:4:5:6:2/64",
		Routes: []Route{
			{"fc:5:5:5:5:5:5:5", "fc01:1:2:3:4:5:6:1"},
		},
	},
	{
		NetPort: "net1port0",
		Netns:   "h2",
		Ifa:     "fc02:1:2:3:4:5:6:1/64",
		DummyIfs: []DummyIf{
			{"dummy0", "fc:6:6:6:6:6:6:6"},
		},
		Routes: []Route{
			{"fc01:1:2:3:4:5:6:1/64", "fc02:1:2:3:4:5:6:2"},
			{"fc:5:5:5:5:5:5:5", "fc02:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc01:1:2:3:4:5:6:1", "fc:5:5:5:5:5:5:5"},
	},
	{
		NetPort: "net1port1",
		Netns:   "r",
		Ifa:     "fc02:1:2:3:4:5:6:2/64",
		Routes: []Route{
			{"fc:6:6:6:6:6:6:6", "fc02:1:2:3:4:5:6:1"},
		},
	},
	{
		NetPort: "net2port0",
		Netns:   "h1",
		Ifa:     "fc03:1:2:3:4:5:6:1/64",
		Routes: []Route{
			{"fc04:1:2:3:4:5:6:1/64", "fc03:1:2:3:4:5:6:2"},
			{"fc01:1:2:3:4:5:6:1/64", "fc03:1:2:3:4:5:6:2"},
			{"fc:6:6:6:6:6:6:6", "fc03:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc04:1:2:3:4:5:6:1"},
	},
	{
		NetPort: "net2port1",
		Netns:   "r",
		Ifa:     "fc03:1:2:3:4:5:6:2/64",
		Routes: []Route{
			{"fc:5:5:5:5:5:5:5", "fc03:1:2:3:4:5:6:1"},
			{"fc01:1:2:3:4:5:6:1/64", "fc03:1:2:3:4:5:6:1"},
		},
	},
	{
		NetPort: "net3port0",
		Netns:   "h2",
		Ifa:     "fc04:1:2:3:4:5:6:1/64",
		Routes: []Route{
			{"fc03:1:2:3:4:5:6:1/64", "fc04:1:2:3:4:5:6:2"},
			{"fc02:1:2:3:4:5:6:1/64", "fc04:1:2:3:4:5:6:2"},
			{"fc:5:5:5:5:5:5:5", "fc04:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc03:1:2:3:4:5:6:1"},
	},
	{
		NetPort: "net3port1",
		Netns:   "r",
		Ifa:     "fc04:1:2:3:4:5:6:2/64",
		Routes: []Route{
			{"fc02:1:2:3:4:5:6:1/64", "fc04:1:2:3:4:5:6:1"},
			{"fc:6:6:6:6:6:6:6", "fc04:1:2:3:4:5:6:1"},
		},
	},
}
View Source
var FourVlanNets = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h1",
		Vlan:    1,
		Ifa:     "10.1.0.0/31",
		DummyIfs: []DummyIf{
			{"dummy0", "10.5.5.5"},
		},
		Routes: []Route{
			{"10.1.0.2/31", "10.1.0.1"},
			{"10.6.6.6", "10.1.0.1"},
		},
		Remotes: []string{"10.1.0.2", "10.6.6.6"},
	},
	{
		NetPort: "net0port1",
		Netns:   "r",
		Vlan:    1,
		Ifa:     "10.1.0.1/31",
		Routes: []Route{
			{"10.5.5.5", "10.1.0.2"},
		},
	},
	{
		NetPort: "net1port0",
		Netns:   "h2",
		Vlan:    2,
		Ifa:     "10.1.0.2/31",
		DummyIfs: []DummyIf{
			{"dummy0", "10.6.6.6"},
		},
		Routes: []Route{
			{"10.1.0.0/31", "10.1.0.3"},
			{"10.5.5.5", "10.1.0.3"},
		},
		Remotes: []string{"10.1.0.0", "10.5.5.5"},
	},
	{
		NetPort: "net1port1",
		Netns:   "r",
		Vlan:    2,
		Ifa:     "10.1.0.3/31",
		Routes: []Route{
			{"10.6.6.6", "10.1.0.2"},
		},
	},
	{
		NetPort: "net2port0",
		Netns:   "h1",
		Vlan:    3,
		Ifa:     "10.2.0.0/31",
		Routes: []Route{
			{"10.2.0.2/31", "10.2.0.1"},
			{"10.6.6.6", "10.2.0.1"},
		},
		Remotes: []string{"10.2.0.2"},
	},
	{
		NetPort: "net2port1",
		Netns:   "r",
		Vlan:    3,
		Ifa:     "10.2.0.1/31",
		Routes: []Route{
			{"10.5.5.5", "10.2.0.2"},
		},
	},
	{
		NetPort: "net3port0",
		Netns:   "h2",
		Vlan:    4,
		Ifa:     "10.2.0.2/31",
		Routes: []Route{
			{"10.2.0.0/31", "10.2.0.3"},
			{"10.5.5.5", "10.2.0.3"},
		},
		Remotes: []string{"10.2.0.0"},
	},
	{
		NetPort: "net3port1",
		Netns:   "r",
		Vlan:    4,
		Ifa:     "10.2.0.3/31",
		Routes: []Route{
			{"10.6.6.6", "10.2.0.2"},
		},
	},
}

TwoVlanNets virtual network:

h1:net0port0.1 <-> r:net0port1.1
h2:net1port0.2 <-> r:net1port1.2
View Source
var Goes, GoesIP string
View Source
var OneNet = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h0",
		Ifa:     "10.1.0.0/31",
		Remotes: []string{"10.1.0.1"},
	},
	{
		NetPort: "net0port1",
		Netns:   "h1",
		Ifa:     "10.1.0.1/31",
		Remotes: []string{"10.1.0.0"},
	},
}

OneNet virtual network:

h0:net0port0 <-> h1:net0port1
View Source
var OneNetIp6 = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h0",
		Ifa:     "fc01:1:2:3:4:5:6:1/64",
		Remotes: []string{"fc01:1:2:3:4:5:6:2"},
	},
	{
		NetPort: "net0port1",
		Netns:   "h1",
		Ifa:     "fc01:1:2:3:4:5:6:2/64",
		Remotes: []string{"fc01:1:2:3:4:5:6:1"},
	},
}
View Source
var PortByNetPort, NetPortByPort map[string]string
View Source
var TwoNets = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h1",
		Ifa:     "10.1.0.0/31",
		Routes: []Route{
			{"10.1.0.2/31", "10.1.0.1"},
		},
		Remotes: []string{"10.1.0.2"},
	},
	{
		NetPort: "net0port1",
		Netns:   "r",
		Ifa:     "10.1.0.1/31",
	},
	{
		NetPort: "net1port0",
		Netns:   "h2",
		Ifa:     "10.1.0.2/31",
		Routes: []Route{
			{"10.1.0.0/31", "10.1.0.3"},
		},
		Remotes: []string{"10.1.0.0"},
	},
	{
		NetPort: "net1port1",
		Netns:   "r",
		Ifa:     "10.1.0.3/31",
	},
}

TwoNets virtual network:

h1:net0port0 <-> r:net0port1
h2:net1port0 <-> r:net1port1
View Source
var TwoNetsIp6 = NetDevs{
	{
		NetPort: "net0port0",
		Netns:   "h1",
		Ifa:     "fc01:1:2:3:4:5:6:1/64",
		Routes: []Route{
			{"fc02:1:2:3:4:5:6:1/64", "fc01:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc02:1:2:3:4:5:6:1"},
	},
	{
		NetPort: "net0port1",
		Netns:   "r",
		Ifa:     "fc01:1:2:3:4:5:6:2/64",
	},
	{
		NetPort: "net1port0",
		Netns:   "h2",
		Ifa:     "fc02:1:2:3:4:5:6:1/64",
		Routes: []Route{
			{"fc01:1:2:3:4:5:6:1/64", "fc02:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc01:1:2:3:4:5:6:1"},
	},
	{
		NetPort: "net1port1",
		Netns:   "r",
		Ifa:     "fc02:1:2:3:4:5:6:2/64",
	},
}
View Source
var TwoVlanIp6 = NetDevs{
	{
		Vlan:    1,
		NetPort: "net0port0",
		Netns:   "h1",
		Ifa:     "fc01:1:2:3:4:5:6:1/64",
		Routes: []Route{
			{"fc02:1:2:3:4:5:6:1/64", "fc01:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc02:1:2:3:4:5:6:1"},
	},
	{
		Vlan:    1,
		NetPort: "net0port1",
		Netns:   "r",
		Ifa:     "fc01:1:2:3:4:5:6:2/64",
	},
	{
		Vlan:    2,
		NetPort: "net1port0",
		Netns:   "h2",
		Ifa:     "fc02:1:2:3:4:5:6:1/64",
		Routes: []Route{
			{"fc01:1:2:3:4:5:6:1/64", "fc02:1:2:3:4:5:6:2"},
		},
		Remotes: []string{"fc01:1:2:3:4:5:6:1"},
	},
	{
		Vlan:    2,
		NetPort: "net1port1",
		Netns:   "r",
		Ifa:     "fc02:1:2:3:4:5:6:2/64",
	},
}
View Source
var TwoVlanNets = NetDevs{
	{
		Vlan:    1,
		NetPort: "net0port0",
		Netns:   "h1",
		Ifa:     "10.1.0.0/31",
		Routes: []Route{
			{"10.1.0.2/31", "10.1.0.1"},
		},
		Remotes: []string{"10.1.0.2"},
	},
	{
		Vlan:    1,
		NetPort: "net0port1",
		Netns:   "r",
		Ifa:     "10.1.0.1/31",
	},
	{
		Vlan:    2,
		NetPort: "net1port0",
		Netns:   "h2",
		Ifa:     "10.1.0.2/31",
		Routes: []Route{
			{"10.1.0.0/31", "10.1.0.3"},
		},
		Remotes: []string{"10.1.0.0"},
	},
	{
		Vlan:    2,
		NetPort: "net1port1",
		Netns:   "r",
		Ifa:     "10.1.0.3/31",
	},
}

TwoVlanNets virtual network:

h1:net0port0.1 <-> r:net0port1.1
h2:net1port0.2 <-> r:net1port1.2

Functions

func Init

func Init(goes string)

func NetPortCleanup added in v1.8.7

func NetPortCleanup(t *testing.T, ns string, ifname string, vlan int)

func NetPortConfig added in v1.8.7

func NetPortConfig(t *testing.T, ns string, netport string, vlan int) (ifname string)

add/del netport in netns, either as dataport or member of bridge

Types

type DummyIf

type DummyIf struct {
	Ifname string
	Ifa    string
}

type NetDev

type NetDev struct {
	Kind string

	NetPort string // lookup key for NetPortFile to Ifname
	Vlan    int    // for PORT_VLAN
	Ifname  string

	Netns    string
	Ifa      string
	DummyIfs []DummyIf
	Routes   []Route
	Remotes  []string
	Lowers   []PortVlan
}

NetDev describes a network interface configuration. default PORT sets ifa for ifname derived from NetPort BRIDGE adds a linux bridge device with ifname and ifa, plus its vlan members PORT_VLAN adds a linux vlan device to ifname derived from NetPort with ifa initial values filled from NetDev[], then DevKind and Ifname updated

type NetDevs

type NetDevs []NetDev

NetDevs describe all of the interfaces in the virtual network under test.

func (NetDevs) Test

func (netdevs NetDevs) Test(t *testing.T, tests ...test.Tester)

netdevs list the interface configurations of the network under test

type PortVlan added in v1.8.7

type PortVlan struct {
	NetPort string
	Vlan    int
	Ifname  string // runtime lookup
}

type Route

type Route struct {
	Prefix string
	GW     string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL