backhaul_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package adapters
  2. import "testing"
  3. func TestPickBackhaulUplink(t *testing.T) {
  4. // A managed switch with a 10G parent uplink (xg27) plus 1G AP downlinks and
  5. // a 100M access port that happens to be first: the core uplink wins.
  6. sw := []EthPort{
  7. {ID: "snmp-1", Label: "1/g1", Up: true, Speed: "100 Mbps", PeerKind: PeerKindMAC},
  8. {ID: "snmp-9", Label: "1/g9", Up: true, Speed: "1 Gbps", PeerKind: PeerKindRouterLinkLLDP},
  9. {ID: "snmp-27", Label: "1/xg27", Up: true, Speed: "10 Gbps", PeerKind: PeerKindRouterLinkLLDP},
  10. }
  11. if got := pickBackhaulUplink(sw); got == nil || got.ID != "snmp-27" {
  12. t.Fatalf("fastest router-link: %+v", got)
  13. }
  14. // Single router-link (an AP whose only wired peer is its parent): picked
  15. // even though a plain access port is up and listed first.
  16. ap := []EthPort{
  17. {ID: "eth1", Label: "ETH 1", Up: true, Speed: "1 Gbps", PeerKind: PeerKindMAC},
  18. {ID: "wan", Label: "WAN", Up: true, Speed: "2.5 Gbps", PeerKind: PeerKindRouterLink},
  19. }
  20. if got := pickBackhaulUplink(ap); got == nil || got.ID != "wan" {
  21. t.Fatalf("router-link over access port: %+v", got)
  22. }
  23. // No router-link peer (single-cable AP without LLDP): fall back to first up.
  24. noll := []EthPort{
  25. {ID: "eth1", Label: "ETH 1", Up: false},
  26. {ID: "eth2", Label: "ETH 2", Up: true, Speed: "1 Gbps", PeerKind: PeerKindMAC},
  27. }
  28. if got := pickBackhaulUplink(noll); got == nil || got.ID != "eth2" {
  29. t.Fatalf("first-up fallback: %+v", got)
  30. }
  31. // Nothing up: nil.
  32. if got := pickBackhaulUplink([]EthPort{{ID: "eth1", Up: false}}); got != nil {
  33. t.Fatalf("no up port should be nil, got %+v", got)
  34. }
  35. }