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 ¶
const NetPortFile = "testdata/netport.yaml"
Variables ¶
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"}, }, }
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"}, }, }
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"}, }, }
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
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"}, }, }, }
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
var Goes, GoesIP string
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
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"}, }, }
var PortByNetPort, NetPortByPort map[string]string
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
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", }, }
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", }, }
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 NetPortCleanup ¶ added in v1.8.7
Types ¶
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.