labctl: segments sur des bridges de l'hôte, routeurs et passerelle VRRP #2
All checks were successful
Tests / test (push) Successful in 3m46s
All checks were successful
Tests / test (push) Successful in 3m46s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
e0de56a64f
commit
e9a0c19b72
24 changed files with 1766 additions and 578 deletions
|
|
@ -12,7 +12,7 @@ import (
|
|||
func (p *Plan) Write(w io.Writer) error {
|
||||
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
|
||||
|
||||
fmt.Fprintf(tw, "lab %s: nodes %d, segments %d, cables %d\n", p.Name, len(p.Nodes), len(p.Segments), len(p.Cables))
|
||||
fmt.Fprintf(tw, "lab %s: nodes %d, segments %d, ports %d\n", p.Name, len(p.Nodes), len(p.Segments), len(p.Ports))
|
||||
|
||||
fmt.Fprintf(tw, "\nnodes\n")
|
||||
fmt.Fprintf(tw, " name\trole\timage\tcpus\tmemory\tssh\n")
|
||||
|
|
@ -37,21 +37,29 @@ func (p *Plan) Write(w io.Writer) error {
|
|||
}
|
||||
|
||||
for _, s := range p.Segments {
|
||||
fmt.Fprintf(tw, "\nsegment %s: %s, mtu %d, switch %s, bridge %s, gateway %s\n",
|
||||
s.Name, s.Network, s.MTU, s.Switch, s.Bridge, s.Gateway)
|
||||
fmt.Fprintf(tw, " node\tinterface\taddress\tmac\tudp\t\tswitch port\tmac\tudp\n")
|
||||
for _, c := range p.Cables {
|
||||
if c.Segment != s.Name {
|
||||
fmt.Fprintf(tw, "\nsegment %s: %s, mtu %d, bridge %s, %s\n", s.Name, s.Network, s.MTU, s.Bridge, gateway(s))
|
||||
fmt.Fprintf(tw, " node\tinterface\taddress\tmac\ttap\n")
|
||||
for _, port := range p.Ports {
|
||||
if port.Segment != s.Name {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(tw, " %s\t%s\t%s\t%s\t%d\t<->\t%s %s\t%s\t%d\n",
|
||||
c.Node, c.NodeInterface, c.NodeAddress, c.NodeMAC, c.NodePort,
|
||||
c.Switch, c.SwitchInterface, c.SwitchMAC, c.SwitchPort)
|
||||
fmt.Fprintf(tw, " %s\t%s\t%s\t%s\t%s\n", port.Node, port.Interface, port.Address, port.MAC, port.Tap)
|
||||
}
|
||||
}
|
||||
return tw.Flush()
|
||||
}
|
||||
|
||||
func gateway(s SegmentPlan) string {
|
||||
switch {
|
||||
case len(s.Routers) == 0:
|
||||
return "no gateway"
|
||||
case s.VRID == 0:
|
||||
return fmt.Sprintf("gateway %s on %s", s.Gateway, s.Routers[0])
|
||||
default:
|
||||
return fmt.Sprintf("gateway %s by vrrp %d on %s", s.Gateway, s.VRID, strings.Join(s.Routers, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
func loopback(n NodePlan) string {
|
||||
if !n.Loopback.IsValid() {
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
SSHBasePort = 2200
|
||||
CableBasePort = 20000
|
||||
SSHBasePort = 2200
|
||||
|
||||
BridgePrefix = "lb-"
|
||||
TapPrefix = "lt"
|
||||
|
||||
maxNodes = 1000
|
||||
maxSegments = 256
|
||||
|
|
@ -21,15 +23,16 @@ type Plan struct {
|
|||
Images []Image
|
||||
Segments []SegmentPlan
|
||||
Nodes []NodePlan
|
||||
Cables []Cable
|
||||
Ports []Port
|
||||
}
|
||||
|
||||
type SegmentPlan struct {
|
||||
Name string
|
||||
Switch string
|
||||
Bridge string
|
||||
Network netip.Prefix
|
||||
Gateway netip.Addr
|
||||
Routers []string
|
||||
VRID int
|
||||
MTU int
|
||||
}
|
||||
|
||||
|
|
@ -49,20 +52,14 @@ type NodePlan struct {
|
|||
Services []string
|
||||
}
|
||||
|
||||
type Cable struct {
|
||||
Segment string
|
||||
MTU int
|
||||
|
||||
Node string
|
||||
NodeInterface string
|
||||
NodeMAC net.HardwareAddr
|
||||
NodeAddress netip.Prefix
|
||||
NodePort int
|
||||
|
||||
Switch string
|
||||
SwitchInterface string
|
||||
SwitchMAC net.HardwareAddr
|
||||
SwitchPort int
|
||||
type Port struct {
|
||||
Segment string
|
||||
MTU int
|
||||
Node string
|
||||
Interface string
|
||||
MAC net.HardwareAddr
|
||||
Address netip.Prefix
|
||||
Tap string
|
||||
}
|
||||
|
||||
func Compute(t *Topology) (*Plan, error) {
|
||||
|
|
@ -102,17 +99,22 @@ func Compute(t *Topology) (*Plan, error) {
|
|||
var errs []error
|
||||
for segIndex, s := range t.Segments {
|
||||
network := netip.MustParsePrefix(s.CIDR)
|
||||
gateway := network.Addr().Next()
|
||||
p.Segments = append(p.Segments, SegmentPlan{
|
||||
segment := SegmentPlan{
|
||||
Name: s.Name,
|
||||
Switch: s.Switch,
|
||||
Bridge: "br-" + s.Name,
|
||||
Bridge: BridgePrefix + s.Name,
|
||||
Network: network,
|
||||
Gateway: gateway,
|
||||
Routers: append([]string(nil), s.Routers...),
|
||||
MTU: s.MTU,
|
||||
})
|
||||
}
|
||||
if len(s.Routers) > 0 {
|
||||
segment.Gateway = network.Addr().Next()
|
||||
}
|
||||
if len(s.Routers) > 1 {
|
||||
segment.VRID = segIndex + 1
|
||||
}
|
||||
p.Segments = append(p.Segments, segment)
|
||||
|
||||
addresses, err := allocate(t, s, network, gateway)
|
||||
addresses, err := allocate(t, s, network, segment.Gateway)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
|
|
@ -123,26 +125,18 @@ func Compute(t *Topology) (*Plan, error) {
|
|||
if !ok {
|
||||
continue
|
||||
}
|
||||
cable := len(p.Cables)
|
||||
p.Cables = append(p.Cables, Cable{
|
||||
Segment: s.Name,
|
||||
MTU: s.MTU,
|
||||
Node: n.Name,
|
||||
NodeInterface: s.Name,
|
||||
NodeMAC: mac(nodeIndex, segIndex, 0),
|
||||
NodeAddress: netip.PrefixFrom(address, network.Bits()),
|
||||
NodePort: CableBasePort + 2*cable,
|
||||
Switch: s.Switch,
|
||||
SwitchInterface: "p" + strconv.Itoa(cable),
|
||||
SwitchMAC: mac(nodeIndex, segIndex, 1),
|
||||
SwitchPort: CableBasePort + 2*cable + 1,
|
||||
p.Ports = append(p.Ports, Port{
|
||||
Segment: s.Name,
|
||||
MTU: s.MTU,
|
||||
Node: n.Name,
|
||||
Interface: s.Name,
|
||||
MAC: mac(nodeIndex, segIndex),
|
||||
Address: netip.PrefixFrom(address, network.Bits()),
|
||||
Tap: TapPrefix + strconv.Itoa(len(p.Ports)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if last := CableBasePort + 2*len(p.Cables) - 1; last > 65535 {
|
||||
errs = append(errs, fmt.Errorf("cables: %d cables need udp ports up to %d, beyond 65535", len(p.Cables), last))
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return nil, errors.Join(errs...)
|
||||
}
|
||||
|
|
@ -151,7 +145,12 @@ func Compute(t *Topology) (*Plan, error) {
|
|||
|
||||
func allocate(t *Topology, s Segment, network netip.Prefix, gateway netip.Addr) (map[string]netip.Addr, error) {
|
||||
broadcast := lastAddr(network)
|
||||
used := map[netip.Addr]string{gateway: s.Switch + " (gateway)"}
|
||||
used := map[netip.Addr]string{}
|
||||
first := network.Addr().Next()
|
||||
if gateway.IsValid() {
|
||||
used[gateway] = "the gateway"
|
||||
first = gateway.Next()
|
||||
}
|
||||
result := map[string]netip.Addr{}
|
||||
var errs []error
|
||||
|
||||
|
|
@ -179,7 +178,7 @@ func allocate(t *Topology, s Segment, network netip.Prefix, gateway netip.Addr)
|
|||
}
|
||||
}
|
||||
|
||||
next := gateway.Next()
|
||||
next := first
|
||||
for _, name := range auto {
|
||||
for next != broadcast && used[next] != "" {
|
||||
next = next.Next()
|
||||
|
|
@ -206,8 +205,8 @@ func lastAddr(network netip.Prefix) netip.Addr {
|
|||
return netip.AddrFrom4([4]byte{byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)})
|
||||
}
|
||||
|
||||
func mac(node, segment, side int) net.HardwareAddr {
|
||||
return net.HardwareAddr{0x02, 0x4c, byte(node >> 8), byte(node), byte(segment), byte(side)}
|
||||
func mac(node, segment int) net.HardwareAddr {
|
||||
return net.HardwareAddr{0x02, 0x4c, byte(node >> 8), byte(node), byte(segment), 0x00}
|
||||
}
|
||||
|
||||
func contains(list []string, value string) bool {
|
||||
|
|
|
|||
|
|
@ -27,15 +27,26 @@ func computeError(t *testing.T, doc string) string {
|
|||
return err.Error()
|
||||
}
|
||||
|
||||
func cableOf(t *testing.T, p *Plan, node, segment string) Cable {
|
||||
func portOf(t *testing.T, p *Plan, node, segment string) Port {
|
||||
t.Helper()
|
||||
for _, c := range p.Cables {
|
||||
if c.Node == node && c.Segment == segment {
|
||||
return c
|
||||
for _, port := range p.Ports {
|
||||
if port.Node == node && port.Segment == segment {
|
||||
return port
|
||||
}
|
||||
}
|
||||
t.Fatalf("no cable for %s on %s", node, segment)
|
||||
return Cable{}
|
||||
t.Fatalf("no port for %s on %s", node, segment)
|
||||
return Port{}
|
||||
}
|
||||
|
||||
func segmentOf(t *testing.T, p *Plan, name string) SegmentPlan {
|
||||
t.Helper()
|
||||
for _, s := range p.Segments {
|
||||
if s.Name == name {
|
||||
return s
|
||||
}
|
||||
}
|
||||
t.Fatalf("no segment %s", name)
|
||||
return SegmentPlan{}
|
||||
}
|
||||
|
||||
func nodeOf(t *testing.T, p *Plan, name string) NodePlan {
|
||||
|
|
@ -51,12 +62,12 @@ func nodeOf(t *testing.T, p *Plan, name string) NodePlan {
|
|||
|
||||
const twoHypervisors = header + `
|
||||
segments:
|
||||
underlay: { switch: sw1, cidr: 10.250.0.0/24, mtu: 9000 }
|
||||
underlay: { routers: [sw1], cidr: 10.250.0.0/24, mtu: 9000 }
|
||||
nodes:
|
||||
sw1: { role: switch, image: deb, cpus: 2, memory: 1024 }
|
||||
rr1: { role: rr, image: deb, cpus: 1, memory: 1024, segments: [underlay] }
|
||||
hv1: { role: host, image: deb, cpus: 4, memory: 16384, segments: [underlay] }
|
||||
hv2: { role: host, image: deb, cpus: 4, memory: 16384, segments: [underlay] }
|
||||
sw1: { role: router, image: deb, cpus: 2, memory: 1024, segments: [underlay] }
|
||||
rr1: { role: rr, image: deb, cpus: 1, memory: 1024, segments: [underlay] }
|
||||
hv1: { role: host, image: deb, cpus: 4, memory: 16384, segments: [underlay] }
|
||||
hv2: { role: host, image: deb, cpus: 4, memory: 16384, segments: [underlay] }
|
||||
`
|
||||
|
||||
func TestCompute_TwoHypervisorsPlan(t *testing.T) {
|
||||
|
|
@ -66,34 +77,34 @@ func TestCompute_TwoHypervisorsPlan(t *testing.T) {
|
|||
t.Fatalf("%d segments, want 1", len(p.Segments))
|
||||
}
|
||||
s := p.Segments[0]
|
||||
if s.Bridge != "br-underlay" || s.Gateway != netip.MustParseAddr("10.250.0.1") || s.MTU != 9000 || s.Switch != "sw1" {
|
||||
if s.Bridge != "lb-underlay" || s.Gateway != netip.MustParseAddr("10.250.0.1") || s.MTU != 9000 || !reflect.DeepEqual(s.Routers, []string{"sw1"}) || s.VRID != 0 {
|
||||
t.Errorf("segment = %+v", s)
|
||||
}
|
||||
|
||||
want := []struct {
|
||||
node, address, nodeMAC, switchMAC, switchIface string
|
||||
nodePort, switchPort int
|
||||
node, address, mac, tap string
|
||||
}{
|
||||
{"rr1", "10.250.0.2/24", "02:4c:00:01:00:00", "02:4c:00:01:00:01", "p0", 20000, 20001},
|
||||
{"hv1", "10.250.0.3/24", "02:4c:00:02:00:00", "02:4c:00:02:00:01", "p1", 20002, 20003},
|
||||
{"hv2", "10.250.0.4/24", "02:4c:00:03:00:00", "02:4c:00:03:00:01", "p2", 20004, 20005},
|
||||
{"sw1", "10.250.0.2/24", "02:4c:00:00:00:00", "lt0"},
|
||||
{"rr1", "10.250.0.3/24", "02:4c:00:01:00:00", "lt1"},
|
||||
{"hv1", "10.250.0.4/24", "02:4c:00:02:00:00", "lt2"},
|
||||
{"hv2", "10.250.0.5/24", "02:4c:00:03:00:00", "lt3"},
|
||||
}
|
||||
if len(p.Cables) != len(want) {
|
||||
t.Fatalf("%d cables, want %d", len(p.Cables), len(want))
|
||||
if len(p.Ports) != len(want) {
|
||||
t.Fatalf("%d ports, want %d", len(p.Ports), len(want))
|
||||
}
|
||||
for _, w := range want {
|
||||
c := cableOf(t, p, w.node, "underlay")
|
||||
if c.NodeAddress.String() != w.address {
|
||||
t.Errorf("%s address = %s, want %s", w.node, c.NodeAddress, w.address)
|
||||
port := portOf(t, p, w.node, "underlay")
|
||||
if port.Address.String() != w.address {
|
||||
t.Errorf("%s address = %s, want %s", w.node, port.Address, w.address)
|
||||
}
|
||||
if c.NodeMAC.String() != w.nodeMAC || c.SwitchMAC.String() != w.switchMAC {
|
||||
t.Errorf("%s macs = %s / %s, want %s / %s", w.node, c.NodeMAC, c.SwitchMAC, w.nodeMAC, w.switchMAC)
|
||||
if port.MAC.String() != w.mac {
|
||||
t.Errorf("%s mac = %s, want %s", w.node, port.MAC, w.mac)
|
||||
}
|
||||
if c.NodePort != w.nodePort || c.SwitchPort != w.switchPort {
|
||||
t.Errorf("%s ports = %d / %d, want %d / %d", w.node, c.NodePort, c.SwitchPort, w.nodePort, w.switchPort)
|
||||
if port.Tap != w.tap {
|
||||
t.Errorf("%s tap = %s, want %s", w.node, port.Tap, w.tap)
|
||||
}
|
||||
if c.NodeInterface != "underlay" || c.SwitchInterface != w.switchIface || c.Switch != "sw1" || c.MTU != 9000 {
|
||||
t.Errorf("%s cable = %+v", w.node, c)
|
||||
if port.Interface != "underlay" || port.MTU != 9000 {
|
||||
t.Errorf("%s port = %+v", w.node, port)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,104 +138,206 @@ func TestCompute_IsStableAcrossRuns(t *testing.T) {
|
|||
func TestCompute_AddressesFollowDeclarationOrderNotNames(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
under: { switch: sw, cidr: 10.0.0.0/24 }
|
||||
under: { routers: [sw], cidr: 10.0.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
zeta: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
alfa: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
`)
|
||||
if got := cableOf(t, p, "zeta", "under").NodeAddress.String(); got != "10.0.0.2/24" {
|
||||
t.Errorf("zeta = %s, want 10.0.0.2/24", got)
|
||||
}
|
||||
if got := cableOf(t, p, "alfa", "under").NodeAddress.String(); got != "10.0.0.3/24" {
|
||||
t.Errorf("alfa = %s, want 10.0.0.3/24", got)
|
||||
for node, want := range map[string]string{"zeta": "10.0.0.2/24", "sw": "10.0.0.3/24", "alfa": "10.0.0.4/24"} {
|
||||
if got := portOf(t, p, node, "under").Address.String(); got != want {
|
||||
t.Errorf("%s = %s, want %s", node, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_ExplicitAddressIsKeptAndSkippedByAllocation(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
under: { switch: sw, cidr: 10.0.0.0/24 }
|
||||
under: { routers: [sw], cidr: 10.0.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [under], addresses: {under: 10.0.0.254} }
|
||||
a: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
b: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under], addresses: {under: 10.0.0.3} }
|
||||
c: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
`)
|
||||
for node, want := range map[string]string{"a": "10.0.0.2/24", "b": "10.0.0.3/24", "c": "10.0.0.4/24"} {
|
||||
if got := cableOf(t, p, node, "under").NodeAddress.String(); got != want {
|
||||
for node, want := range map[string]string{"sw": "10.0.0.254/24", "a": "10.0.0.2/24", "b": "10.0.0.3/24", "c": "10.0.0.4/24"} {
|
||||
if got := portOf(t, p, node, "under").Address.String(); got != want {
|
||||
t.Errorf("%s = %s, want %s", node, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_TwoSegmentsCableOrderMacsAndPorts(t *testing.T) {
|
||||
func TestCompute_SegmentWithoutRouterHasNoGateway(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
red: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
blue: { switch: sw, cidr: 10.2.0.0/24, mtu: 1500 }
|
||||
l2: { cidr: 10.3.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [blue, red] }
|
||||
rr: { role: rr, image: deb, cpus: 1, memory: 512, segments: [red] }
|
||||
a: { role: host, image: deb, cpus: 1, memory: 512, segments: [l2] }
|
||||
b: { role: host, image: deb, cpus: 1, memory: 512, segments: [l2] }
|
||||
`)
|
||||
got := make([]string, 0, len(p.Cables))
|
||||
for _, c := range p.Cables {
|
||||
got = append(got, c.Segment+"/"+c.Node+"/"+c.SwitchInterface)
|
||||
s := segmentOf(t, p, "l2")
|
||||
if s.Gateway.IsValid() || s.VRID != 0 || len(s.Routers) != 0 || s.Bridge != "lb-l2" {
|
||||
t.Errorf("segment = %+v, want no gateway", s)
|
||||
}
|
||||
if strings.Join(got, ",") != "red/hv/p0,red/rr/p1,blue/hv/p2" {
|
||||
t.Errorf("cable order = %v", got)
|
||||
}
|
||||
blue := cableOf(t, p, "hv", "blue")
|
||||
if blue.NodeMAC.String() != "02:4c:00:01:01:00" || blue.NodePort != 20004 || blue.MTU != 1500 || blue.NodeAddress.String() != "10.2.0.2/24" {
|
||||
t.Errorf("hv on blue = %+v", blue)
|
||||
}
|
||||
if red := cableOf(t, p, "hv", "red"); red.NodeMAC.String() != "02:4c:00:01:00:00" {
|
||||
t.Errorf("hv on red mac = %s", red.NodeMAC)
|
||||
for node, want := range map[string]string{"a": "10.3.0.1/24", "b": "10.3.0.2/24"} {
|
||||
if got := portOf(t, p, node, "l2").Address.String(); got != want {
|
||||
t.Errorf("%s = %s, want %s", node, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_EveryMacAndPortIsUnique(t *testing.T) {
|
||||
func TestCompute_SegmentWithoutRouterAcceptsTheFirstAddress(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
a: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
b: { switch: sw, cidr: 10.2.0.0/24 }
|
||||
l2: { cidr: 10.3.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
a: { role: host, image: deb, cpus: 1, memory: 512, segments: [l2] }
|
||||
b: { role: host, image: deb, cpus: 1, memory: 512, segments: [l2], addresses: {l2: 10.3.0.1} }
|
||||
`)
|
||||
for node, want := range map[string]string{"a": "10.3.0.2/24", "b": "10.3.0.1/24"} {
|
||||
if got := portOf(t, p, node, "l2").Address.String(); got != want {
|
||||
t.Errorf("%s = %s, want %s", node, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_SegmentWithOneRouter(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
red: { routers: [r1], cidr: 10.1.0.0/24 }
|
||||
nodes:
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red] }
|
||||
r1: { role: router, image: deb, cpus: 1, memory: 512, segments: [red] }
|
||||
`)
|
||||
s := segmentOf(t, p, "red")
|
||||
if s.Gateway != netip.MustParseAddr("10.1.0.1") || s.VRID != 0 || !reflect.DeepEqual(s.Routers, []string{"r1"}) {
|
||||
t.Errorf("segment = %+v", s)
|
||||
}
|
||||
for node, want := range map[string]string{"hv": "10.1.0.2/24", "r1": "10.1.0.3/24"} {
|
||||
if got := portOf(t, p, node, "red").Address.String(); got != want {
|
||||
t.Errorf("%s = %s, want %s", node, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_SegmentWithTwoRoutersUsesVRRP(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
red: { routers: [r1], cidr: 10.1.0.0/24 }
|
||||
blue: { routers: [r2, r1], cidr: 10.2.0.0/24 }
|
||||
pure: { cidr: 10.3.0.0/24 }
|
||||
nodes:
|
||||
r1: { role: router, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
r2: { role: router, image: deb, cpus: 1, memory: 512, segments: [blue], addresses: {blue: 10.2.0.250} }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red, blue, pure] }
|
||||
`)
|
||||
blue := segmentOf(t, p, "blue")
|
||||
if blue.VRID != 2 || blue.Gateway != netip.MustParseAddr("10.2.0.1") || !reflect.DeepEqual(blue.Routers, []string{"r2", "r1"}) {
|
||||
t.Errorf("blue = %+v", blue)
|
||||
}
|
||||
if red := segmentOf(t, p, "red"); red.VRID != 0 {
|
||||
t.Errorf("red vrid = %d, want 0", red.VRID)
|
||||
}
|
||||
if pure := segmentOf(t, p, "pure"); pure.VRID != 0 || pure.Gateway.IsValid() {
|
||||
t.Errorf("pure = %+v", pure)
|
||||
}
|
||||
for node, want := range map[string]string{"r1": "10.2.0.2/24", "r2": "10.2.0.250/24", "hv": "10.2.0.3/24"} {
|
||||
if got := portOf(t, p, node, "blue").Address.String(); got != want {
|
||||
t.Errorf("%s = %s, want %s", node, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_TwoSegmentsPortOrderMacsAndTaps(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
red: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
blue: { cidr: 10.2.0.0/24, mtu: 1500 }
|
||||
nodes:
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [red] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [blue, red] }
|
||||
rr: { role: rr, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
`)
|
||||
got := make([]string, 0, len(p.Ports))
|
||||
for _, port := range p.Ports {
|
||||
got = append(got, port.Segment+"/"+port.Node+"/"+port.Tap)
|
||||
}
|
||||
if strings.Join(got, ",") != "red/sw/lt0,red/hv/lt1,red/rr/lt2,blue/hv/lt3,blue/rr/lt4" {
|
||||
t.Errorf("port order = %v", got)
|
||||
}
|
||||
blue := portOf(t, p, "hv", "blue")
|
||||
if blue.MAC.String() != "02:4c:00:01:01:00" || blue.Tap != "lt3" || blue.MTU != 1500 || blue.Interface != "blue" || blue.Address.String() != "10.2.0.1/24" {
|
||||
t.Errorf("hv on blue = %+v", blue)
|
||||
}
|
||||
if red := portOf(t, p, "hv", "red"); red.MAC.String() != "02:4c:00:01:00:00" || red.Address.String() != "10.1.0.3/24" {
|
||||
t.Errorf("hv on red = %+v", red)
|
||||
}
|
||||
if rr := portOf(t, p, "rr", "blue"); rr.MAC.String() != "02:4c:00:02:01:00" || rr.Address.String() != "10.2.0.2/24" {
|
||||
t.Errorf("rr on blue = %+v", rr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_MacEncodesNodeAndSegmentRanks(t *testing.T) {
|
||||
p := compute(t, generated(3, 300))
|
||||
if got := portOf(t, p, "n299", "s2").MAC.String(); got != "02:4c:01:2b:02:00" {
|
||||
t.Errorf("n299 on s2 mac = %s, want 02:4c:01:2b:02:00", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_EveryMacTapAndPortIsUnique(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
a: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
b: { routers: [sw], cidr: 10.2.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [a, b] }
|
||||
n1: { role: rr, image: deb, cpus: 1, memory: 512, segments: [a, b] }
|
||||
n2: { role: rr, image: deb, cpus: 1, memory: 512, segments: [a, b] }
|
||||
n3: { role: host, image: deb, cpus: 1, memory: 512, segments: [b, a] }
|
||||
`)
|
||||
macs := map[string]bool{}
|
||||
taps := map[string]bool{}
|
||||
ports := map[int]bool{}
|
||||
for _, n := range p.Nodes {
|
||||
if ports[n.SSHPort] {
|
||||
t.Errorf("ssh port %d used twice", n.SSHPort)
|
||||
}
|
||||
ports[n.SSHPort] = true
|
||||
}
|
||||
for _, c := range p.Cables {
|
||||
for _, m := range []string{c.NodeMAC.String(), c.SwitchMAC.String()} {
|
||||
if macs[m] {
|
||||
t.Errorf("mac %s used twice", m)
|
||||
}
|
||||
macs[m] = true
|
||||
for _, port := range p.Ports {
|
||||
if macs[port.MAC.String()] {
|
||||
t.Errorf("mac %s used twice", port.MAC)
|
||||
}
|
||||
for _, port := range []int{c.NodePort, c.SwitchPort} {
|
||||
if ports[port] {
|
||||
t.Errorf("port %d used twice", port)
|
||||
}
|
||||
ports[port] = true
|
||||
macs[port.MAC.String()] = true
|
||||
if taps[port.Tap] {
|
||||
t.Errorf("tap %s used twice", port.Tap)
|
||||
}
|
||||
taps[port.Tap] = true
|
||||
}
|
||||
if len(macs) != 12 {
|
||||
t.Errorf("%d distinct macs, want 12", len(macs))
|
||||
if len(macs) != 8 || len(taps) != 8 {
|
||||
t.Errorf("%d distinct macs and %d distinct taps, want 8", len(macs), len(taps))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_MacsAreLocallyAdministeredUnicast(t *testing.T) {
|
||||
for _, c := range compute(t, twoHypervisors).Cables {
|
||||
for _, m := range []string{c.NodeMAC.String(), c.SwitchMAC.String()} {
|
||||
if !strings.HasPrefix(m, "02:") {
|
||||
t.Errorf("mac %s is not locally administered unicast", m)
|
||||
}
|
||||
for _, port := range compute(t, twoHypervisors).Ports {
|
||||
if m := port.MAC.String(); !strings.HasPrefix(m, "02:") {
|
||||
t.Errorf("mac %s is not locally administered unicast", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_InterfaceAndTapNamesFitInIFNAMSIZ(t *testing.T) {
|
||||
p := compute(t, generated(23, 1000))
|
||||
for _, port := range p.Ports {
|
||||
if len(port.Tap) > 15 || len(port.Interface) > 15 {
|
||||
t.Fatalf("port %+v has a name longer than 15", port)
|
||||
}
|
||||
}
|
||||
for _, s := range p.Segments {
|
||||
if len(s.Bridge) > 15 {
|
||||
t.Fatalf("bridge %s is longer than 15", s.Bridge)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -233,9 +346,9 @@ func TestCompute_AddressRejections(t *testing.T) {
|
|||
base := func(addresses string) string {
|
||||
return header + `
|
||||
segments:
|
||||
under: { switch: sw, cidr: 10.0.0.0/29 }
|
||||
under: { routers: [sw], cidr: 10.0.0.0/29 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
a: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under]` + addresses + ` }
|
||||
b: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under], addresses: {under: 10.0.0.5} }
|
||||
`
|
||||
|
|
@ -244,7 +357,7 @@ nodes:
|
|||
{"outside", ", addresses: {under: 10.0.1.2}", "node a: address 10.0.1.2 is outside segment under"},
|
||||
{"network", ", addresses: {under: 10.0.0.0}", "node a: address 10.0.0.0 is the network or broadcast"},
|
||||
{"broadcast", ", addresses: {under: 10.0.0.7}", "node a: address 10.0.0.7 is the network or broadcast"},
|
||||
{"gateway", ", addresses: {under: 10.0.0.1}", "node a: address 10.0.0.1 on segment under is already taken by sw (gateway)"},
|
||||
{"gateway", ", addresses: {under: 10.0.0.1}", "node a: address 10.0.0.1 on segment under is already taken by the gateway"},
|
||||
{"duplicate", ", addresses: {under: 10.0.0.5}", "node b: address 10.0.0.5 on segment under is already taken by a"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
|
|
@ -254,37 +367,58 @@ nodes:
|
|||
}
|
||||
}
|
||||
|
||||
func TestCompute_RouterAddressCannotBeTheGateway(t *testing.T) {
|
||||
got := computeError(t, header+`
|
||||
segments:
|
||||
under: { routers: [sw], cidr: 10.0.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [under], addresses: {under: 10.0.0.1} }
|
||||
`)
|
||||
requireContains(t, got, "node sw: address 10.0.0.1 on segment under is already taken by the gateway")
|
||||
}
|
||||
|
||||
func TestCompute_ReportsExhaustedSegment(t *testing.T) {
|
||||
got := computeError(t, header+`
|
||||
segments:
|
||||
tiny: { switch: sw, cidr: 10.0.0.0/30 }
|
||||
tiny: { routers: [sw], cidr: 10.0.0.0/30 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
a: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
b: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
`)
|
||||
requireContains(t, got, "segment tiny: no address left in 10.0.0.0/30 for node b")
|
||||
requireContains(t, got, "segment tiny: no address left in 10.0.0.0/30 for node a")
|
||||
}
|
||||
|
||||
func TestCompute_FillsSegmentExactly(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
tiny: { switch: sw, cidr: 10.0.0.0/29 }
|
||||
tiny: { routers: [sw], cidr: 10.0.0.0/29 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
a: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
b: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
c: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
d: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
e: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
`)
|
||||
if got := cableOf(t, p, "e", "tiny").NodeAddress.String(); got != "10.0.0.6/29" {
|
||||
if got := portOf(t, p, "d", "tiny").Address.String(); got != "10.0.0.6/29" {
|
||||
t.Errorf("last node = %s, want 10.0.0.6/29", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_FillsSegmentWithoutRouterExactly(t *testing.T) {
|
||||
p := compute(t, header+`
|
||||
segments:
|
||||
tiny: { cidr: 10.0.0.0/30 }
|
||||
nodes:
|
||||
a: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
b: { role: rr, image: deb, cpus: 1, memory: 512, segments: [tiny] }
|
||||
`)
|
||||
if got := portOf(t, p, "b", "tiny").Address.String(); got != "10.0.0.2/30" {
|
||||
t.Errorf("last node = %s, want 10.0.0.2/30", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_RefusesInvalidTopology(t *testing.T) {
|
||||
requireContains(t, computeError(t, strings.Replace(valid, "role: rr", "role: router", 1)), `role "router"`)
|
||||
requireContains(t, computeError(t, strings.Replace(valid, "role: rr", "role: spine", 1)), `role "spine"`)
|
||||
}
|
||||
|
||||
func TestLastAddr(t *testing.T) {
|
||||
|
|
@ -305,41 +439,86 @@ func TestWrite_TwoHypervisorsPlan(t *testing.T) {
|
|||
if err := compute(t, twoHypervisors).Write(&buf); err != nil {
|
||||
t.Fatalf("Write: %v", err)
|
||||
}
|
||||
want := `lab lab-test: nodes 4, segments 1, cables 3
|
||||
want := `lab lab-test: nodes 4, segments 1, ports 4
|
||||
|
||||
nodes
|
||||
name role image cpus memory ssh
|
||||
sw1 switch deb 2 1024 MiB 127.0.0.1:2200
|
||||
sw1 router deb 2 1024 MiB 127.0.0.1:2200
|
||||
rr1 rr deb 1 1024 MiB 127.0.0.1:2201
|
||||
hv1 host deb 4 16384 MiB 127.0.0.1:2202
|
||||
hv2 host deb 4 16384 MiB 127.0.0.1:2203
|
||||
|
||||
segment underlay: 10.250.0.0/24, mtu 9000, switch sw1, bridge br-underlay, gateway 10.250.0.1
|
||||
node interface address mac udp switch port mac udp
|
||||
rr1 underlay 10.250.0.2/24 02:4c:00:01:00:00 20000 <-> sw1 p0 02:4c:00:01:00:01 20001
|
||||
hv1 underlay 10.250.0.3/24 02:4c:00:02:00:00 20002 <-> sw1 p1 02:4c:00:02:00:01 20003
|
||||
hv2 underlay 10.250.0.4/24 02:4c:00:03:00:00 20004 <-> sw1 p2 02:4c:00:03:00:01 20005
|
||||
segment underlay: 10.250.0.0/24, mtu 9000, bridge lb-underlay, gateway 10.250.0.1 on sw1
|
||||
node interface address mac tap
|
||||
sw1 underlay 10.250.0.2/24 02:4c:00:00:00:00 lt0
|
||||
rr1 underlay 10.250.0.3/24 02:4c:00:01:00:00 lt1
|
||||
hv1 underlay 10.250.0.4/24 02:4c:00:02:00:00 lt2
|
||||
hv2 underlay 10.250.0.5/24 02:4c:00:03:00:00 lt3
|
||||
`
|
||||
if buf.String() != want {
|
||||
t.Errorf("output:\n%s\nwant:\n%s", buf.String(), want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrite_GatewayLines(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
if err := compute(t, header+`
|
||||
segments:
|
||||
red: { routers: [r1], cidr: 10.1.0.0/24 }
|
||||
blue: { routers: [r2, r1], cidr: 10.2.0.0/24, mtu: 1500 }
|
||||
pure: { cidr: 10.3.0.0/24 }
|
||||
nodes:
|
||||
r1: { role: router, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
r2: { role: router, image: deb, cpus: 1, memory: 512, segments: [blue] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [blue, pure] }
|
||||
`).Write(&buf); err != nil {
|
||||
t.Fatalf("Write: %v", err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"lab lab-test: nodes 3, segments 3, ports 5\n",
|
||||
"\nsegment red: 10.1.0.0/24, mtu 9000, bridge lb-red, gateway 10.1.0.1 on r1\n",
|
||||
"\nsegment blue: 10.2.0.0/24, mtu 1500, bridge lb-blue, gateway 10.2.0.1 by vrrp 2 on r2, r1\n",
|
||||
"\nsegment pure: 10.3.0.0/24, mtu 9000, bridge lb-pure, no gateway\n",
|
||||
" hv pure 10.3.0.1/24 02:4c:00:02:02:00 lt4\n",
|
||||
} {
|
||||
if !strings.Contains(buf.String(), want) {
|
||||
t.Errorf("plan:\n%s\ndoes not contain %q", buf.String(), want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func generated(segments, nodes int) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(header + "segments:\n")
|
||||
names := make([]string, segments)
|
||||
for i := range names {
|
||||
names[i] = fmt.Sprintf("s%d", i)
|
||||
fmt.Fprintf(&b, " %s: { switch: sw, cidr: 10.%d.0.0/16 }\n", names[i], i%250)
|
||||
fmt.Fprintf(&b, " %s: { routers: [sw], cidr: 10.%d.0.0/16 }\n", names[i], i%250)
|
||||
}
|
||||
b.WriteString("nodes:\n sw: { role: switch, image: deb, cpus: 1, memory: 512 }\n")
|
||||
fmt.Fprintf(&b, "nodes:\n sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [%s] }\n", strings.Join(names, ", "))
|
||||
for i := 1; i < nodes; i++ {
|
||||
fmt.Fprintf(&b, " n%d: { role: rr, image: deb, cpus: 1, memory: 512, segments: [%s] }\n", i, strings.Join(names, ", "))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func withVRRPAt(segments, rank int) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(header + "segments:\n")
|
||||
names := make([]string, segments)
|
||||
for i := range names {
|
||||
names[i] = fmt.Sprintf("s%d", i)
|
||||
routers := "[r1]"
|
||||
if i == rank {
|
||||
routers = "[r1, r2]"
|
||||
}
|
||||
fmt.Fprintf(&b, " %s: { routers: %s, cidr: 10.%d.0.0/16 }\n", names[i], routers, i%250)
|
||||
}
|
||||
fmt.Fprintf(&b, "nodes:\n r1: { role: router, image: deb, cpus: 1, memory: 512, segments: [%s] }\n", strings.Join(names, ", "))
|
||||
fmt.Fprintf(&b, " r2: { role: router, image: deb, cpus: 1, memory: 512, segments: [%s] }\n", names[rank])
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func TestValidate_RejectsTooManyNodes(t *testing.T) {
|
||||
requireContains(t, validationError(t, generated(1, 1001)), "nodes: 1001 declared, at most 1000")
|
||||
}
|
||||
|
|
@ -354,6 +533,24 @@ func TestValidate_RejectsTooManySegments(t *testing.T) {
|
|||
requireContains(t, validationError(t, generated(257, 2)), "segments: 257 declared, at most 256")
|
||||
}
|
||||
|
||||
func TestCompute_RejectsCablesBeyondUDPPortRange(t *testing.T) {
|
||||
requireContains(t, computeError(t, generated(23, 1000)), "cables: 22977 cables need udp ports up to 65953, beyond 65535")
|
||||
func TestValidate_RejectsVRRPBeyondTheVRIDRange(t *testing.T) {
|
||||
msg := validationError(t, withVRRPAt(256, 255))
|
||||
requireContains(t, msg, "segment s255: a segment with several routers must be among the first 255")
|
||||
}
|
||||
|
||||
func TestCompute_AcceptsVRRPOnTheLastVRID(t *testing.T) {
|
||||
p := compute(t, withVRRPAt(256, 254))
|
||||
if got := segmentOf(t, p, "s254").VRID; got != 255 {
|
||||
t.Errorf("vrid = %d, want 255", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompute_ManyPortsNeedNoPortRange(t *testing.T) {
|
||||
p := compute(t, generated(23, 1000))
|
||||
if len(p.Ports) != 23000 {
|
||||
t.Fatalf("%d ports, want 23000", len(p.Ports))
|
||||
}
|
||||
if last := p.Ports[len(p.Ports)-1].Tap; last != "lt22999" {
|
||||
t.Errorf("last tap = %s, want lt22999", last)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import (
|
|||
|
||||
const withRoles = header + `
|
||||
segments:
|
||||
underlay: { switch: sw1, cidr: 192.168.14.0/24 }
|
||||
underlay: { routers: [sw1], cidr: 192.168.14.0/24 }
|
||||
nodes:
|
||||
sw1: { role: switch, image: deb, cpus: 2, memory: 1024, secondary: { underlay: [169.254.0.1/28] }, frr: frr/sw1.conf }
|
||||
sw1: { role: router, image: deb, cpus: 2, memory: 1024, segments: [underlay], secondary: { underlay: [169.254.0.1/28] }, frr: frr/sw1.conf }
|
||||
rr1: { role: rr, image: deb, cpus: 1, memory: 1024, segments: [underlay], secondary: { underlay: [169.254.0.3/28] }, loopback: 10.255.255.1/32, frr: frr/rr1.conf }
|
||||
hv1: { role: host, image: deb, cpus: 4, memory: 16384, segments: [underlay], frr: /etc/lab/hv1.conf, provision: provision/hv.sh, post_provision: /opt/lab/post.sh, files: { agent.yml: agent/two.yml, deploy.sh: /opt/deploy.sh }, services: [agent.service] }
|
||||
`
|
||||
|
|
@ -95,10 +95,10 @@ func TestValidate_RoleFieldRejections(t *testing.T) {
|
|||
t.Run(name, func(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
red: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
blue: { switch: sw, cidr: 10.2.0.0/24 }
|
||||
red: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
blue: { routers: [sw], cidr: 10.2.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
` + c.node + `
|
||||
`
|
||||
|
|
@ -107,29 +107,29 @@ nodes:
|
|||
}
|
||||
}
|
||||
|
||||
func TestValidate_SwitchSecondaryOnlyOnItsOwnSegments(t *testing.T) {
|
||||
func TestValidate_RouterSecondaryOnlyOnItsOwnSegments(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
red: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
blue: { switch: other, cidr: 10.2.0.0/24 }
|
||||
red: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
blue: { routers: [other], cidr: 10.2.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512, secondary: { red: [169.254.0.1/28], blue: [169.254.1.1/28] } }
|
||||
other: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [red], secondary: { red: [169.254.0.1/28], blue: [169.254.1.1/28] } }
|
||||
other: { role: router, image: deb, cpus: 1, memory: 512, segments: [blue] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
`
|
||||
msg := validationError(t, doc)
|
||||
requireContains(t, msg, "node sw: secondary address given for segment blue it is not attached to")
|
||||
if bytes.Contains([]byte(msg), []byte("segment red")) {
|
||||
t.Errorf("the switch's own segment was refused:\n%s", msg)
|
||||
t.Errorf("the router's own segment was refused:\n%s", msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate_LoopbackInterfaceNameIsReserved(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
lo1: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
lo1: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [lo1] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [lo1] }
|
||||
`
|
||||
requireContains(t, validationError(t, doc), "segment lo1: name is reserved for the loopback interface")
|
||||
|
|
@ -156,9 +156,9 @@ func TestWrite_NoRolesSectionWithoutRoleFields(t *testing.T) {
|
|||
var buf bytes.Buffer
|
||||
doc := header + `
|
||||
segments:
|
||||
underlay: { switch: sw1, cidr: 10.250.0.0/24 }
|
||||
underlay: { routers: [sw1], cidr: 10.250.0.0/24 }
|
||||
nodes:
|
||||
sw1: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw1: { role: router, image: deb, cpus: 1, memory: 512, segments: [underlay] }
|
||||
rr1: { role: rr, image: deb, cpus: 1, memory: 512, segments: [underlay] }
|
||||
`
|
||||
if err := compute(t, doc).Write(&buf); err != nil {
|
||||
|
|
@ -176,7 +176,7 @@ func TestValidate_ProvisionRejections(t *testing.T) {
|
|||
}{
|
||||
"the hypervisor role is gone": {
|
||||
`hv: { role: hypervisor, image: deb, cpus: 1, memory: 512, segments: [red] }`,
|
||||
`node hv: role "hypervisor" must be one of switch, rr, host`,
|
||||
`node hv: role "hypervisor" must be one of router, rr, host`,
|
||||
},
|
||||
"file name leaving the files directory": {
|
||||
`hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red], files: { ../etc/passwd: a.yml } }`,
|
||||
|
|
@ -203,9 +203,9 @@ func TestValidate_ProvisionRejections(t *testing.T) {
|
|||
t.Run(name, func(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
red: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
red: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [red] }
|
||||
` + c.node + `
|
||||
`
|
||||
requireContains(t, validationError(t, doc), c.want)
|
||||
|
|
@ -216,9 +216,9 @@ nodes:
|
|||
func TestValidate_ProvisionIsAllowedOnEveryRole(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
red: { switch: sw, cidr: 10.1.0.0/24 }
|
||||
red: { routers: [sw], cidr: 10.1.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512, provision: sw.sh, files: { a.conf: a.conf }, services: [lab-switch.service] }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [red], provision: sw.sh, files: { a.conf: a.conf }, services: [lab-router.service] }
|
||||
rr: { role: rr, image: deb, cpus: 1, memory: 512, segments: [red], provision: rr.sh, post_provision: rr-post.sh }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red], files: { agent.yml: agent.yml }, services: [agent.service] }
|
||||
`
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
RoleSwitch = "switch"
|
||||
RoleRouter = "router"
|
||||
RoleRR = "rr"
|
||||
RoleHost = "host"
|
||||
|
||||
|
|
@ -32,10 +32,12 @@ type Image struct {
|
|||
}
|
||||
|
||||
type Segment struct {
|
||||
Name string
|
||||
Switch string
|
||||
CIDR string
|
||||
MTU int
|
||||
Name string
|
||||
Routers []string
|
||||
CIDR string
|
||||
MTU int
|
||||
|
||||
legacySwitch string
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
|
|
@ -61,9 +63,10 @@ type fileImage struct {
|
|||
}
|
||||
|
||||
type fileSegment struct {
|
||||
Switch string `yaml:"switch"`
|
||||
CIDR string `yaml:"cidr"`
|
||||
MTU int `yaml:"mtu"`
|
||||
Routers []string `yaml:"routers"`
|
||||
CIDR string `yaml:"cidr"`
|
||||
MTU int `yaml:"mtu"`
|
||||
Switch string `yaml:"switch"`
|
||||
}
|
||||
|
||||
type fileNode struct {
|
||||
|
|
@ -145,7 +148,7 @@ func Parse(data []byte) (*Topology, error) {
|
|||
if mtu == 0 {
|
||||
mtu = DefaultMTU
|
||||
}
|
||||
t.Segments = append(t.Segments, Segment{Name: name, Switch: s.Switch, CIDR: s.CIDR, MTU: mtu})
|
||||
t.Segments = append(t.Segments, Segment{Name: name, Routers: s.Routers, CIDR: s.CIDR, MTU: mtu, legacySwitch: s.Switch})
|
||||
}
|
||||
for _, name := range order["nodes"] {
|
||||
n := f.Nodes[name]
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ func requireContains(t *testing.T, got, want string) {
|
|||
func TestParse_KeepsDeclarationOrderOfNodesAndSegments(t *testing.T) {
|
||||
topo := parse(t, header+`
|
||||
segments:
|
||||
zulu: { switch: sw, cidr: 10.0.1.0/24 }
|
||||
alpha: { switch: sw, cidr: 10.0.2.0/24 }
|
||||
zulu: { routers: [sw], cidr: 10.0.1.0/24 }
|
||||
alpha: { routers: [sw], cidr: 10.0.2.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [zulu, alpha] }
|
||||
zeta: { role: rr, image: deb, cpus: 1, memory: 512, segments: [zulu, alpha] }
|
||||
beta: { role: rr, image: deb, cpus: 1, memory: 512, segments: [zulu] }
|
||||
`)
|
||||
|
|
@ -65,9 +65,9 @@ nodes:
|
|||
func TestParse_DefaultsMTUTo9000(t *testing.T) {
|
||||
topo := parse(t, header+`
|
||||
segments:
|
||||
under: { switch: sw, cidr: 10.0.0.0/24 }
|
||||
under: { cidr: 10.0.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
`)
|
||||
if topo.Segments[0].MTU != 9000 {
|
||||
t.Errorf("MTU = %d, want 9000", topo.Segments[0].MTU)
|
||||
|
|
@ -77,7 +77,7 @@ nodes:
|
|||
func TestParse_RejectsUnknownField(t *testing.T) {
|
||||
_, err := Parse([]byte(header + `
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512, ram: 4 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, ram: 4 }
|
||||
`))
|
||||
if err == nil || !strings.Contains(err.Error(), "ram") {
|
||||
t.Fatalf("unknown field not rejected: %v", err)
|
||||
|
|
@ -87,7 +87,7 @@ nodes:
|
|||
func TestParse_RejectsDuplicateNode(t *testing.T) {
|
||||
_, err := Parse([]byte(header + `
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: rr, image: deb, cpus: 1, memory: 512 }
|
||||
`))
|
||||
if err == nil || !strings.Contains(err.Error(), "already defined") {
|
||||
|
|
@ -109,9 +109,9 @@ func TestLoad_ReportsPathOnError(t *testing.T) {
|
|||
|
||||
const valid = header + `
|
||||
segments:
|
||||
under: { switch: sw, cidr: 10.0.0.0/24 }
|
||||
under: { routers: [sw], cidr: 10.0.0.0/24 }
|
||||
nodes:
|
||||
sw: { role: switch, image: deb, cpus: 1, memory: 512 }
|
||||
sw: { role: router, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
rr: { role: rr, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
`
|
||||
|
||||
|
|
@ -129,9 +129,11 @@ func TestValidate_Rejections(t *testing.T) {
|
|||
{"image url not https", strings.Replace(valid, "url: https://", "url: http://", 1), "image deb: url"},
|
||||
{"image sums not https", strings.Replace(valid, "sums: https://", "sums: ftp://", 1), "image deb: sums"},
|
||||
{"no node", header + "\nsegments: {}\nnodes: {}\n", "at least one node"},
|
||||
{"segment switch missing", strings.Replace(valid, "switch: sw, cidr", "cidr", 1), "segment under: switch is required"},
|
||||
{"segment switch unknown", strings.Replace(valid, "switch: sw, cidr", "switch: ghost, cidr", 1), "switch ghost is not a declared node"},
|
||||
{"segment switch not a switch", strings.Replace(valid, "switch: sw, cidr", "switch: rr, cidr", 1), "rr is a rr, not a switch"},
|
||||
{"legacy segment switch", strings.Replace(valid, "routers: [sw], cidr", "switch: sw, cidr", 1), "segment under: switch was replaced by routers"},
|
||||
{"legacy role switch", strings.Replace(valid, "role: router", "role: switch", 1), "node sw: role switch was renamed router"},
|
||||
{"segment router unknown", strings.Replace(valid, "routers: [sw]", "routers: [ghost]", 1), "segment under: router ghost is not a declared node"},
|
||||
{"segment router not a router", strings.Replace(valid, "routers: [sw]", "routers: [rr]", 1), "segment under: rr is a rr, not a router"},
|
||||
{"segment router listed twice", strings.Replace(valid, "routers: [sw]", "routers: [sw, sw]", 1), "segment under: router sw listed twice"},
|
||||
{"segment name too long", strings.ReplaceAll(valid, "under", "underlayunder"), "segment underlayunder: name must match"},
|
||||
{"segment named like the admin interface", strings.ReplaceAll(valid, "under", "mgmt0"), "segment mgmt0: name is reserved"},
|
||||
{"segment name with dash", strings.ReplaceAll(valid, "under", "un-der"), "segment un-der: name must match"},
|
||||
|
|
@ -143,19 +145,17 @@ func TestValidate_Rejections(t *testing.T) {
|
|||
{"cidr too small", strings.Replace(valid, "10.0.0.0/24", "10.0.0.0/31", 1), "prefix length out of range"},
|
||||
{"cidr too large", strings.Replace(valid, "10.0.0.0/24", "10.0.0.0/7", 1), "prefix length out of range"},
|
||||
{"bad node name", strings.Replace(valid, " rr: {", " RR: {", 1), "node RR: name must match"},
|
||||
{"bad role", strings.Replace(valid, "role: rr", "role: router", 1), `role "router"`},
|
||||
{"bad role", strings.Replace(valid, "role: rr", "role: spine", 1), `role "spine"`},
|
||||
{"unknown image", strings.Replace(valid, "role: rr, image: deb", "role: rr, image: ubuntu", 1), `image "ubuntu" is not declared`},
|
||||
{"no cpu", strings.Replace(valid, "role: rr, image: deb, cpus: 1", "role: rr, image: deb, cpus: 0", 1), "node rr: cpus must be at least 1"},
|
||||
{"memory too low", strings.Replace(valid, "cpus: 1, memory: 512, segments", "cpus: 1, memory: 255, segments", 1), "node rr: memory must be at least 256"},
|
||||
{"switch with segments", strings.Replace(valid, "role: switch, image: deb, cpus: 1, memory: 512 }", "role: switch, image: deb, cpus: 1, memory: 512, segments: [under] }", 1), "node sw: a switch carries its segments"},
|
||||
{"switch with addresses", strings.Replace(valid, "role: switch, image: deb, cpus: 1, memory: 512 }", "role: switch, image: deb, cpus: 1, memory: 512, addresses: {under: 10.0.0.9} }", 1), "node sw: a switch carries its segments"},
|
||||
{"switch without segment", valid + " sw2: { role: switch, image: deb, cpus: 1, memory: 512 }\n", "node sw2: switch carries no segment"},
|
||||
{"memory too low", strings.Replace(valid, "role: rr, image: deb, cpus: 1, memory: 512", "role: rr, image: deb, cpus: 1, memory: 255", 1), "node rr: memory must be at least 256"},
|
||||
{"router without segment", valid + " r2: { role: router, image: deb, cpus: 1, memory: 512 }\n", "node r2: must be attached to at least one segment"},
|
||||
{"node without segment", valid + " rr2: { role: rr, image: deb, cpus: 1, memory: 512 }\n", "node rr2: must be attached to at least one segment"},
|
||||
{"node on unknown segment", strings.Replace(valid, "segments: [under]", "segments: [over]", 1), "node rr: segment over is not declared"},
|
||||
{"node on segment twice", strings.Replace(valid, "segments: [under]", "segments: [under, under]", 1), "node rr: segment under listed twice"},
|
||||
{"segment without node", strings.Replace(valid, " under: { switch: sw, cidr: 10.0.0.0/24 }", " under: { switch: sw, cidr: 10.0.0.0/24 }\n empty: { switch: sw, cidr: 10.0.9.0/24 }", 1), "segment empty: no node is attached"},
|
||||
{"address on foreign segment", strings.Replace(valid, "segments: [under]", "segments: [under], addresses: {over: 10.0.0.9}", 1), "address given for segment over"},
|
||||
{"address unparsable", strings.Replace(valid, "segments: [under]", "segments: [under], addresses: {under: 10.0.0}", 1), `address "10.0.0" on under`},
|
||||
{"node on unknown segment", strings.Replace(valid, "role: rr, image: deb, cpus: 1, memory: 512, segments: [under]", "role: rr, image: deb, cpus: 1, memory: 512, segments: [over]", 1), "node rr: segment over is not declared"},
|
||||
{"node on segment twice", strings.Replace(valid, "role: rr, image: deb, cpus: 1, memory: 512, segments: [under]", "role: rr, image: deb, cpus: 1, memory: 512, segments: [under, under]", 1), "node rr: segment under listed twice"},
|
||||
{"segment without node", strings.Replace(valid, " under: { routers: [sw], cidr: 10.0.0.0/24 }", " under: { routers: [sw], cidr: 10.0.0.0/24 }\n empty: { cidr: 10.0.9.0/24 }", 1), "segment empty: no node is attached"},
|
||||
{"address on foreign segment", strings.Replace(valid, "role: rr, image: deb, cpus: 1, memory: 512, segments: [under]", "role: rr, image: deb, cpus: 1, memory: 512, segments: [under], addresses: {over: 10.0.0.9}", 1), "node rr: address given for segment over"},
|
||||
{"address unparsable", strings.Replace(valid, "role: rr, image: deb, cpus: 1, memory: 512, segments: [under]", "role: rr, image: deb, cpus: 1, memory: 512, segments: [under], addresses: {under: 10.0.0}", 1), `node rr: address "10.0.0" on under`},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
|
|
@ -164,10 +164,53 @@ func TestValidate_Rejections(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestValidate_RejectsRouterNotAttachedToItsSegment(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
red: { routers: [r], cidr: 10.1.0.0/24 }
|
||||
blue: { routers: [r], cidr: 10.2.0.0/24 }
|
||||
nodes:
|
||||
r: { role: router, image: deb, cpus: 1, memory: 512, segments: [blue] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [red, blue] }
|
||||
`
|
||||
msg := validationError(t, doc)
|
||||
requireContains(t, msg, "segment red: router r is not attached to it")
|
||||
if strings.Contains(msg, "segment blue") {
|
||||
t.Errorf("the router's own segment was refused:\n%s", msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate_AcceptsSegmentWithoutRouter(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
l2: { cidr: 10.3.0.0/24 }
|
||||
nodes:
|
||||
a: { role: host, image: deb, cpus: 1, memory: 512, segments: [l2] }
|
||||
b: { role: host, image: deb, cpus: 1, memory: 512, segments: [l2] }
|
||||
`
|
||||
if err := parse(t, doc).Validate(); err != nil {
|
||||
t.Fatalf("Validate: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate_AcceptsTwoRoutersOnASegment(t *testing.T) {
|
||||
doc := header + `
|
||||
segments:
|
||||
under: { routers: [r1, r2], cidr: 10.0.0.0/24 }
|
||||
nodes:
|
||||
r1: { role: router, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
r2: { role: router, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
hv: { role: host, image: deb, cpus: 1, memory: 512, segments: [under] }
|
||||
`
|
||||
if err := parse(t, doc).Validate(); err != nil {
|
||||
t.Fatalf("Validate: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate_ReportsEveryErrorAtOnce(t *testing.T) {
|
||||
doc := strings.Replace(valid, "role: rr", "role: router", 1)
|
||||
doc := strings.Replace(valid, "role: rr", "role: spine", 1)
|
||||
doc = strings.Replace(doc, "10.0.0.0/24", "10.0.0.0/31", 1)
|
||||
got := validationError(t, doc)
|
||||
requireContains(t, got, `role "router"`)
|
||||
requireContains(t, got, `role "spine"`)
|
||||
requireContains(t, got, "prefix length out of range")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ const (
|
|||
|
||||
ReservedInterface = "mgmt0"
|
||||
LoopbackInterface = "lo1"
|
||||
|
||||
MaxVRID = 255
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -74,14 +76,23 @@ func (t *Topology) Validate() error {
|
|||
if s.Name == LoopbackInterface {
|
||||
add("segment %s: name is reserved for the loopback interface", s.Name)
|
||||
}
|
||||
sw, ok := nodes[s.Switch]
|
||||
switch {
|
||||
case s.Switch == "":
|
||||
add("segment %s: switch is required", s.Name)
|
||||
case !ok:
|
||||
add("segment %s: switch %s is not a declared node", s.Name, s.Switch)
|
||||
case sw.Role != RoleSwitch:
|
||||
add("segment %s: %s is a %s, not a switch", s.Name, s.Switch, sw.Role)
|
||||
if s.legacySwitch != "" {
|
||||
add("segment %s: switch was replaced by routers: declare %s with role %s, attach it to %s through its segments, and list it in segments.%s.routers", s.Name, s.legacySwitch, RoleRouter, s.Name, s.Name)
|
||||
}
|
||||
seenRouters := map[string]bool{}
|
||||
for _, name := range s.Routers {
|
||||
r, ok := nodes[name]
|
||||
switch {
|
||||
case seenRouters[name]:
|
||||
add("segment %s: router %s listed twice", s.Name, name)
|
||||
case !ok:
|
||||
add("segment %s: router %s is not a declared node", s.Name, name)
|
||||
case r.Role != RoleRouter:
|
||||
add("segment %s: %s is a %s, not a %s", s.Name, name, r.Role, RoleRouter)
|
||||
case !contains(r.Segments, s.Name):
|
||||
add("segment %s: router %s is not attached to it", s.Name, name)
|
||||
}
|
||||
seenRouters[name] = true
|
||||
}
|
||||
if s.MTU < MinMTU || s.MTU > MaxMTU {
|
||||
add("segment %s: mtu %d out of range [%d, %d]", s.Name, s.MTU, MinMTU, MaxMTU)
|
||||
|
|
@ -99,19 +110,25 @@ func (t *Topology) Validate() error {
|
|||
}
|
||||
}
|
||||
|
||||
attached := map[string]int{}
|
||||
hosting := map[string]int{}
|
||||
for _, s := range t.Segments {
|
||||
hosting[s.Switch]++
|
||||
for i, s := range t.Segments {
|
||||
if len(s.Routers) > 1 {
|
||||
if i+1 > MaxVRID {
|
||||
add("segment %s: a segment with several routers must be among the first %d, its rank sets the vrrp id", s.Name, MaxVRID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attached := map[string]int{}
|
||||
for _, n := range t.Nodes {
|
||||
if !namePattern.MatchString(n.Name) {
|
||||
add("node %s: name must match %s", n.Name, namePattern)
|
||||
}
|
||||
switch n.Role {
|
||||
case RoleSwitch, RoleRR, RoleHost:
|
||||
case RoleRouter, RoleRR, RoleHost:
|
||||
case "switch":
|
||||
add("node %s: role switch was renamed %s: attach it to its segments through segments and addresses, and list it in segments.<name>.routers", n.Name, RoleRouter)
|
||||
default:
|
||||
add("node %s: role %q must be one of %s, %s, %s", n.Name, n.Role, RoleSwitch, RoleRR, RoleHost)
|
||||
add("node %s: role %q must be one of %s, %s, %s", n.Name, n.Role, RoleRouter, RoleRR, RoleHost)
|
||||
}
|
||||
if !images[n.Image] {
|
||||
add("node %s: image %q is not declared", n.Name, n.Image)
|
||||
|
|
@ -123,15 +140,6 @@ func (t *Topology) Validate() error {
|
|||
add("node %s: memory must be at least %d MiB", n.Name, MinMemory)
|
||||
}
|
||||
validateExtras(n, segments, add)
|
||||
if n.Role == RoleSwitch {
|
||||
if len(n.Segments) > 0 || len(n.Addresses) > 0 {
|
||||
add("node %s: a switch carries its segments through segments.<name>.switch, not through segments or addresses", n.Name)
|
||||
}
|
||||
if hosting[n.Name] == 0 {
|
||||
add("node %s: switch carries no segment", n.Name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if len(n.Segments) == 0 {
|
||||
add("node %s: must be attached to at least one segment", n.Name)
|
||||
}
|
||||
|
|
@ -174,16 +182,8 @@ func (t *Topology) Validate() error {
|
|||
|
||||
func validateExtras(n Node, segments map[string]Segment, add func(string, ...any)) {
|
||||
carried := map[string]bool{}
|
||||
if n.Role == RoleSwitch {
|
||||
for name, s := range segments {
|
||||
if s.Switch == n.Name {
|
||||
carried[name] = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, name := range n.Segments {
|
||||
carried[name] = true
|
||||
}
|
||||
for _, name := range n.Segments {
|
||||
carried[name] = true
|
||||
}
|
||||
names := make([]string, 0, len(n.Secondary))
|
||||
for name := range n.Secondary {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue