backhaul.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // backhaul.go — choosing the uplink port that carries a non-gateway unit's
  2. // backhaul toward the rest of the network (issue #1544).
  3. package adapters
  4. // pickBackhaulUplink returns the port that carries a non-gateway unit's uplink,
  5. // or nil when it has no up port. The uplink is a port the enrichment flagged as
  6. // a router link (PeerKind router-link / router-link-lldp). A managed switch has
  7. // several router-links - its parent uplink plus downlinks to mesh APs - so the
  8. // fastest one is the core uplink (e.g. 1/xg27 10G beats 1G AP downlinks). The
  9. // previous matcher looked for Detail == "enlace entre routers", a string that is
  10. // never set server-side (it is a frontend i18n label), so it always fell through
  11. // to the first UP port - which on a switch is an arbitrary access port, making a
  12. // 10G-uplinked switch report a camera port's 100 Mbps as its backhaul. The
  13. // first-UP fallback is kept only when there is no router-link peer at all (a
  14. // single-cable AP without LLDP).
  15. func pickBackhaulUplink(enriched []EthPort) *EthPort {
  16. var uplink *EthPort
  17. bestMbps := -1
  18. for i := range enriched {
  19. ep := &enriched[i]
  20. if !ep.Up || (ep.PeerKind != PeerKindRouterLink && ep.PeerKind != PeerKindRouterLinkLLDP) {
  21. continue
  22. }
  23. if mb := parseSpeedMbps(ep.Speed); mb > bestMbps {
  24. bestMbps, uplink = mb, ep
  25. }
  26. }
  27. if uplink != nil {
  28. return uplink
  29. }
  30. for i := range enriched {
  31. if enriched[i].Up {
  32. return &enriched[i]
  33. }
  34. }
  35. return nil
  36. }