Skip to content

Commit 88e1e68

Browse files
authored
fix(topology): cross port speed onto LLDP-evidence uplinks (#1381)
LLDP links carry the switch's physical port number ("3") while the polled port table names it "lan3"; the literal match missed and the uplink showed no speed. Normalize the lan prefix (digit ports only) when matching. Closes #1380
1 parent 518d618 commit 88e1e68

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎server-go/internal/adapters/topology.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ func fillUplinkSpeeds(polled map[string]*routerPolled, dists []DistributionNode,
641641
routerOfDist[d.ID] = d.RouterID
642642
portOfDist[d.ID] = d.Port
643643
}
644+
// #1380: los enlaces con evidencia LLDP llevan la boca física del switch
645+
// ("3", del PortDesc LLDP) mientras la tabla de puertos del switch la
646+
// nombra "lan3". Se normaliza el prefijo "lan" (solo si va seguido de un
647+
// dígito) para casar ambos lados sin falsos positivos (lan10 != "1").
648+
stripLAN := func(s string) string {
649+
if len(s) > 3 && s[:3] == "lan" && s[3] >= '0' && s[3] <= '9' {
650+
return s[3:]
651+
}
652+
return s
653+
}
644654
for i := range links {
645655
l := &links[i]
646656
if l.Kind != "uplink" || l.SpeedMbps > 0 || l.Port == "" {
@@ -660,7 +670,7 @@ func fillUplinkSpeeds(polled map[string]*routerPolled, dists []DistributionNode,
660670
continue
661671
}
662672
for _, ep := range p.ports {
663-
if ep.ID == l.Port && ep.Up {
673+
if ep.Up && (ep.ID == l.Port || stripLAN(ep.ID) == stripLAN(l.Port)) {
664674
if mbps := parseSpeedMbps(ep.Speed); mbps > 0 {
665675
l.SpeedMbps = mbps
666676
}

‎server-go/internal/adapters/topology_override_test.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,27 @@ func TestFillUplinkSpeeds(t *testing.T) {
286286
t.Fatalf("uplink ap3 (sin puerto): %d, want 0", links[2].SpeedMbps)
287287
}
288288
}
289+
290+
// #1380: el enlace con evidencia LLDP lleva la boca física del switch ("3",
291+
// del PortDesc LLDP) y la tabla del switch la nombra "lan3": la velocidad
292+
// debe cruzar igualmente.
293+
func TestFillUplinkSpeedsLldpPortFisico(t *testing.T) {
294+
polled := map[string]*routerPolled{
295+
"sw": {ports: []EthPort{
296+
{ID: "lan3", Up: true, Speed: "1 Gbps"},
297+
{ID: "lan6", Up: true, Speed: "1 Gbps"},
298+
{ID: "lan7", Up: true, Speed: "2.5 Gbps"},
299+
}},
300+
}
301+
links := []TopoLink{
302+
{From: "sw", To: "rt3", Kind: "uplink", Port: "3"},
303+
{From: "sw", To: "rt4", Kind: "uplink", Port: "6"},
304+
}
305+
fillUplinkSpeeds(polled, nil, links)
306+
if links[0].SpeedMbps != 1000 {
307+
t.Fatalf("uplink rt3 (boca \"3\" = lan3): %d, want 1000", links[0].SpeedMbps)
308+
}
309+
if links[1].SpeedMbps != 1000 {
310+
t.Fatalf("uplink rt4 (boca \"6\" = lan6): %d, want 1000", links[1].SpeedMbps)
311+
}
312+
}

0 commit comments

Comments
 (0)