Просмотр исходного кода

fix(topology): manual attach overrides win for fleet units (#1326)

Attach overrides whose MAC is the bridge MAC of a fleet router now pin that unit's uplink above every inference (override > LLDP > device > FDB > gateway), in all three #690 parent formats with port pinning via routerId:port. Uplink links carry speedMbps from the parent's polled EthPort; the map label and the backhaul table show real speed and entry port. Verified end-to-end on a live fleet.

Closes #1321.
Nacho 1 месяц назад
Родитель
Сommit
dc84b2c630

+ 26 - 9
app/src/components/topology/model.ts

@@ -1426,7 +1426,15 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
           const node = i >= 0 ? apNodes[i] : routerById.get(sl.to)
           if (!node) return null
           const isWifi = node.router.backhaul === 'wifi'
-          const label = isWifi ? 'WiFi uplink' : `Cable 1G${node.router.lldp ? ' · LLDP' : ''}`
+          // #1321: el enlace dice la velocidad real si el padre la midió en
+          // esa boca y el puerto por el que entra; sin dato, "1G" genérico.
+          const speedText = sl.speedMbps && sl.speedMbps > 0
+            ? (sl.speedMbps >= 1000
+              ? `${(sl.speedMbps / 1000).toFixed(sl.speedMbps % 1000 === 0 ? 0 : 1)} Gbps`
+              : `${sl.speedMbps} Mbps`)
+            : '1G'
+          const portSuffix = sl.port ? ` · ${sl.port}` : ''
+          const label = isWifi ? 'WiFi uplink' : `Cable ${speedText}${node.router.lldp ? ' · LLDP' : ''}${portSuffix}`
           // #1047: el padre lo decide la semántica (FDB del switch cuando no
           // hay LLDP); solo se cae al gateway si el server no lo resolvió.
           // #1060: el padre puede ser un distnode (círculo inferido/gestionado):
@@ -1563,14 +1571,14 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
   // distnode, p. ej. el padre aprendido por FDB #1047/#1060), no siempre el
   // gateway. Sin semántica o sin match → gateway (comportamiento de siempre,
   // demo incluido).
-  const uplinkFromByNodeId = new Map<string, string>()
+  const uplinkSemByNodeId = new Map<string, TopoSemLink>()
   if (sem) {
     for (const sl of sem.links) {
-      if (sl.kind === 'uplink') uplinkFromByNodeId.set(sl.to, sl.from)
+      if (sl.kind === 'uplink') uplinkSemByNodeId.set(sl.to, sl)
     }
   }
   const uplinkParentName = (nodeId: string): string => {
-    const fromId = uplinkFromByNodeId.get(nodeId)
+    const fromId = uplinkSemByNodeId.get(nodeId)?.from
     if (fromId) {
       const rn = routerById.get(fromId)
       if (rn) return rn.router.name
@@ -1579,6 +1587,14 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
     }
     return gatewayNode?.router.name ?? ''
   }
+  // #1321: puerto (y velocidad si el padre la midió) del uplink de una
+  // unidad, desde la semántica server-side; "—" honesta si no hay dato.
+  const uplinkPortSuffix = (nodeId: string): string => {
+    const port = uplinkSemByNodeId.get(nodeId)?.port
+    return port ? ` · ${port}` : ''
+  }
+  const uplinkSpeed = (nodeId: string): string =>
+    linkSpeed(uplinkSemByNodeId.get(nodeId)?.speedMbps)
   if (gatewayNode) {
     backhauls.push({
       id: 'wan', a: gatewayNode.router.name, b: 'Internet', kind: 'wan',
@@ -1590,12 +1606,13 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
   for (const node of apNodes) {
     const isWifi = node.router.backhaul === 'wifi'
     backhauls.push({
-      id: `uplink-${node.id}`, a: uplinkParentName(node.id), b: node.router.name, kind: 'uplink',
+      id: `uplink-${node.id}`, a: `${uplinkParentName(node.id)}${uplinkPortSuffix(node.id)}`, b: node.router.name, kind: 'uplink',
       type: isWifi ? 'topology.links.wifiUplink' : 'common.cable',
-      // El contrato no trae ni tasa PHY ni señal del backhaul de un AP, así
-      // que no se afirma ninguna. El tono sí es información real: un enlace
-      // por wifi merece mirarse más que uno por cable.
-      speed: '—',
+      // El contrato no trae señal del backhaul de un AP, así que no se
+      // afirma ninguna. La velocidad sí cuando el padre la midió en esa
+      // boca (#1321); "—" si nadie la midió. El tono sí es información
+      // real: un enlace por wifi merece mirarse más que uno por cable.
+      speed: uplinkSpeed(node.id),
       signal: '—',
       tone: isWifi ? 'warn' : 'ok',
       statusLabel: isWifi ? 'common.status.warn' : 'common.status.online',

+ 2 - 0
app/src/data/types.ts

@@ -424,6 +424,8 @@ export interface TopoSemLink {
   kind: 'wan' | 'uplink' | 'wired' | 'dist' | 'wg'
   /** puerto físico si aplica */
   port?: string
+  /** velocidad negociada en la boca del padre (Mbps), 0/ausente = sin dato (#1321) */
+  speedMbps?: number
 }
 
 /**

+ 1 - 1
server-go/internal/adapters/demo.go

@@ -225,7 +225,7 @@ func (d *Demo) buildOverview() *Overview {
 		Alerts:            d.alertsCopy(),
 		UnreadAlerts:      d.engine.UnreadCount(),
 		DistributionNodes: dists,
-		Topology:          BuildTopoSemantics(d.routers, d.devices, wg, dists, "", nil, nil), // SPEC-65 D65-3
+		Topology:          BuildTopoSemantics(d.routers, d.devices, wg, dists, "", nil, nil, nil), // SPEC-65 D65-3
 		VM:                ViewModelVersion,                                    // SPEC-65 D65-4
 		Ts:                time.Now().Unix(),
 	}

+ 9 - 2
server-go/internal/adapters/live.go

@@ -3127,8 +3127,10 @@ func (l *Live) buildOverview(ctx context.Context) (*Overview, error) {
 	devices, distNodes := inferTopology(stickyPolled, devices)
 	// Capa 2 manual (issue #142): overrides de topología tras el autodiscover.
 	// Sin BD (tests/demo) → no-op.
+	var overrides []TopologyOverride
 	if l.db != nil {
-		devices, distNodes = applyTopologyOverrides(routerList, devices, distNodes, loadTopologyOverrides(l.db))
+		overrides = loadTopologyOverrides(l.db)
+		devices, distNodes = applyTopologyOverrides(routerList, devices, distNodes, overrides)
 	}
 	// Capa 3 PVE (#561): si hay cluster Proxmox configurado, el inventario
 	// read-only sella hypervisor/ct con attachTo correcto (la relación
@@ -3216,6 +3218,9 @@ func (l *Live) buildOverview(ctx context.Context) (*Overview, error) {
 	// #1279: uplinks resueltos por LLDP (regla de puerto raíz); mandan sobre
 	// la evidencia FDB/device en BuildTopoSemantics.
 	lldpEvidence := fleetLldpEvidence(polled, gwID)
+	// #1321: los attaches manuales (#142) cuya MAC es la bridge de una unidad
+	// de flota fijan su uplink por encima de toda inferencia.
+	overrideUplinks := fleetOverrideEvidence(overrides, routerList)
 	wan := l.defaultWan(gw)
 	for _, r := range routerList {
 		if r.ID == gwID && r.Status == "offline" {
@@ -3258,6 +3263,8 @@ func (l *Live) buildOverview(ctx context.Context) (*Overview, error) {
 	unread := l.engine.UnreadCount()
 	usteerAvailable := l.usteerAvailableCached()
 	dawnDetected := dawnDeprecatedFromPolled(polled)
+	topo := BuildTopoSemantics(routerList, devices, wgStats, distNodes, wan.Gateway, fdbEvidence, lldpEvidence, overrideUplinks) // SPEC-65 D65-3 + #1042/#1051/#1279/#1321
+	fillUplinkSpeeds(polled, distNodes, topo.Links)
 	return &Overview{
 		Health:  computeHealth(routerList, adguard),
 		WAN:     wan,
@@ -3268,7 +3275,7 @@ func (l *Live) buildOverview(ctx context.Context) (*Overview, error) {
 		},
 		TopDevices: top, Alerts: alertsCopy, UnreadAlerts: unread,
 		DistributionNodes: distNodes,
-		Topology:          BuildTopoSemantics(routerList, devices, wgStats, distNodes, wan.Gateway, fdbEvidence, lldpEvidence), // SPEC-65 D65-3 + #1042/#1051/#1279
+		Topology:          topo,
 		Devices:           devices,
 		Usteer:            &UsteerOverview{Available: usteerAvailable},
 		DawnDeprecated:    dawnDetected,

+ 15 - 1
server-go/internal/adapters/topo_semantics.go

@@ -257,7 +257,7 @@ func fleetLldpEvidence(polled map[string]*routerPolled, gatewayID string) map[st
 	return out
 }
 
-func BuildTopoSemantics(routers []Router, devices []Device, wg WireGuardStats, dists []DistributionNode, wanGateway string, fdbEvidence map[string]topoParent, lldpEvidence map[string]topoParent) *TopoSemantics {
+func BuildTopoSemantics(routers []Router, devices []Device, wg WireGuardStats, dists []DistributionNode, wanGateway string, fdbEvidence map[string]topoParent, lldpEvidence map[string]topoParent, overrideUplinks map[string]topoParent) *TopoSemantics {
 	sem := &TopoSemantics{Links: []TopoLink{}, Rings: map[string][]string{}}
 	if len(routers) == 0 {
 		return sem
@@ -344,6 +344,20 @@ func BuildTopoSemantics(routers []Router, devices []Device, wg WireGuardStats, d
 			uplinkEvidence[rid] = ev
 		}
 	}
+	// #1321: el attach manual (#142) sobre la MAC bridge de una unidad de
+	// flota es la voluntad del admin y manda sobre TODO. Si el override no
+	// fija puerto, se conserva el que la inferencia hubiera dado.
+	for rid, ev := range overrideUplinks {
+		if ev.parent == rid {
+			continue
+		}
+		if ev.port == "" {
+			if old, ok := uplinkEvidence[rid]; ok {
+				ev.port = old.port
+			}
+		}
+		uplinkEvidence[rid] = ev
+	}
 	// #1042: el equipo aguas arriba del gateway (módem/ONT del ISP) se
 	// descubre por ARP como un cliente más, pero vive en el lado WAN: si su
 	// IP coincide con la puerta de enlace WAN se representa bajo el nodo

+ 34 - 12
server-go/internal/adapters/topo_semantics_test.go

@@ -23,7 +23,7 @@ import (
 //   - hiddenPeers ausente: todos los anillos bajo el límite de chips visibles
 //     de la app (gateway 13, AP 20)
 func TestTopoSemanticsGoldenCanon(t *testing.T) {
-	sem := BuildTopoSemantics(canonRouters(), canonAllDevices(), canonWireguard(), canonDistributionNodes(), "", nil, nil)
+	sem := BuildTopoSemantics(canonRouters(), canonAllDevices(), canonWireguard(), canonDistributionNodes(), "", nil, nil, nil)
 
 	wantLinks := []TopoLink{
 		{From: "internet", To: "flint2", Kind: "wan"},
@@ -109,7 +109,7 @@ func TestTopoSemanticsHiddenPeers(t *testing.T) {
 			RouterID: "ap", Band: "2.4 GHz", Online: true,
 		})
 	}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", nil, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", nil, nil, nil)
 	want := map[string]int{"gw": 2, "ap": 2} // 62-60 y 42-40
 	if !reflect.DeepEqual(sem.HiddenPeers, want) {
 		t.Fatalf("hiddenPeers: got %+v want %+v", sem.HiddenPeers, want)
@@ -133,7 +133,7 @@ func TestDemoOverviewIncluyeTopologyYVM(t *testing.T) {
 		t.Fatal("overview.Topology ausente en demo")
 	}
 	// Mismo resultado que el builder puro sobre el canon.
-	want := BuildTopoSemantics(canonRouters(), canonAllDevices(), canonWireguard(), canonDistributionNodes(), "", nil, nil)
+	want := BuildTopoSemantics(canonRouters(), canonAllDevices(), canonWireguard(), canonDistributionNodes(), "", nil, nil, nil)
 	if !reflect.DeepEqual(ov.Topology, want) {
 		t.Fatalf("overview.Topology != builder canon:\n got: %+v\nwant: %+v", ov.Topology, want)
 	}
@@ -141,7 +141,7 @@ func TestDemoOverviewIncluyeTopologyYVM(t *testing.T) {
 
 // Sin routers: semántica vacía pero no nil (la app cae a su cálculo propio).
 func TestTopoSemanticsSinRouters(t *testing.T) {
-	sem := BuildTopoSemantics(nil, nil, WireGuardStats{}, nil, "", nil, nil)
+	sem := BuildTopoSemantics(nil, nil, WireGuardStats{}, nil, "", nil, nil, nil)
 	if sem == nil || sem.Links == nil || sem.Rings == nil {
 		t.Fatalf("semántica vacía debe tener links/rings no-nil: %+v", sem)
 	}
@@ -161,7 +161,7 @@ func TestTopoSemanticsDeviceHubBajoDistnode(t *testing.T) {
 	}
 	routers := []Router{{ID: "gateway", Name: "gateway", RoleBadge: "Principal", Status: "online"}}
 	dists := []DistributionNode{{ID: "dist-gateway-lan1", Kind: "inferred", RouterID: "gateway", Port: "lan1"}}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, dists, "", nil, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, dists, "", nil, nil, nil)
 
 	var toHost []TopoLink
 	for _, l := range sem.Links {
@@ -201,7 +201,7 @@ func TestTopoSemanticsWanPeer(t *testing.T) {
 		{ID: "modem", MAC: "AA:BB:CC:00:00:01", RouterID: "gw", Band: "cable", Online: true, IP: "100.64.0.1"},
 		{ID: "nas", MAC: "AA:BB:CC:00:00:02", RouterID: "gw", Band: "cable", Online: true, IP: "192.168.1.10"},
 	}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "100.64.0.1", nil, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "100.64.0.1", nil, nil, nil)
 	if sem.WanPeer != "modem" {
 		t.Fatalf("WanPeer = %q, want modem", sem.WanPeer)
 	}
@@ -223,7 +223,7 @@ func TestTopoSemanticsWanPeer(t *testing.T) {
 		t.Fatal("falta el enlace internet→modem (wan-peer)")
 	}
 	// Sin gateway WAN no hay wan peer aunque haya dispositivos.
-	sem2 := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", nil, nil)
+	sem2 := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", nil, nil, nil)
 	if sem2.WanPeer != "" {
 		t.Fatalf("WanPeer sin gateway WAN = %q, want vacío", sem2.WanPeer)
 	}
@@ -244,7 +244,7 @@ func TestTopoSemanticsFdbUplinkParent(t *testing.T) {
 		{ID: "dev-ap1", MAC: "AA:BB:CC:00:00:03", RouterID: "sw1", Band: "cable", Online: true, Port: "5"},
 		{ID: "nas", MAC: "AA:BB:CC:00:00:09", RouterID: "gw", Band: "cable", Online: true, Port: "2"},
 	}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", nil, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", nil, nil, nil)
 	links := map[string]TopoLink{}
 	for _, l := range sem.Links {
 		if l.Kind == "uplink" {
@@ -282,7 +282,7 @@ func TestTopoSemanticsFdbEvidenceSinDevices(t *testing.T) {
 		"sw1": {parent: "gw", port: "1"},
 		"ap1": {parent: "sw1", port: "5"},
 	}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", ev, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", ev, nil, nil)
 	links := map[string]TopoLink{}
 	for _, l := range sem.Links {
 		if l.Kind == "uplink" {
@@ -308,7 +308,7 @@ func TestTopoSemanticsDeviceEvidenceManda(t *testing.T) {
 		{ID: "dev-ap1", MAC: "AA:BB:CC:00:00:03", RouterID: "gw", Band: "cable", Online: true, Port: "4"},
 	}
 	ev := map[string]topoParent{"ap1": {parent: "swX", port: "9"}}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", ev, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, nil, "", ev, nil, nil)
 	for _, l := range sem.Links {
 		if l.Kind == "uplink" && l.To == "ap1" {
 			if l.From != "gw" || l.Port != "4" {
@@ -378,7 +378,7 @@ func TestTopoSemanticsUplinkViaDistNode(t *testing.T) {
 		{ID: "dist-gw-lan1", RouterID: "gw", Kind: "inferred", Port: "lan1"},
 	}
 	ev := map[string]topoParent{"ap1": {parent: "gw", port: "lan1"}}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, dists, "", ev, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, dists, "", ev, nil, nil)
 	found := false
 	for _, l := range sem.Links {
 		if l.Kind == "uplink" && l.To == "ap1" {
@@ -464,7 +464,7 @@ func TestTopoSemanticsLldpEvidenceWins(t *testing.T) {
 	}
 	fdb := map[string]topoParent{"ap1": {parent: "gw", port: "9"}}
 	lldp := map[string]topoParent{"ap1": {parent: "sw1", port: "two-gigabitEthernet 1/0/21"}}
-	sem := BuildTopoSemantics(routers, nil, WireGuardStats{}, nil, "", fdb, lldp)
+	sem := BuildTopoSemantics(routers, nil, WireGuardStats{}, nil, "", fdb, lldp, nil)
 	for _, l := range sem.Links {
 		if l.Kind == "uplink" && l.To == "ap1" {
 			if l.From != "sw1" || l.Port != "two-gigabitEthernet 1/0/21" {
@@ -475,3 +475,25 @@ func TestTopoSemanticsLldpEvidenceWins(t *testing.T) {
 	}
 	t.Fatal("falta el uplink de ap1")
 }
+
+// #1321: el attach manual de flota manda incluso sobre la evidencia LLDP,
+// y si no fija puerto se conserva el que la inferencia hubiera dado.
+func TestTopoSemanticsOverrideEvidenceWins(t *testing.T) {
+	routers := []Router{
+		{ID: "gw", Name: "gateway", RoleBadge: "Principal", MAC: "AA:BB:CC:00:00:01"},
+		{ID: "sw1", Name: "sw1", MAC: "AA:BB:CC:00:00:02"},
+		{ID: "ap1", Name: "ap1", MAC: "AA:BB:CC:00:00:03"},
+	}
+	lldp := map[string]topoParent{"ap1": {parent: "gw", port: "lan4"}}
+	ovr := map[string]topoParent{"ap1": {parent: "sw1"}}
+	sem := BuildTopoSemantics(routers, nil, WireGuardStats{}, nil, "", nil, lldp, ovr)
+	for _, l := range sem.Links {
+		if l.Kind == "uplink" && l.To == "ap1" {
+			if l.From != "sw1" || l.Port != "lan4" {
+				t.Fatalf("el override debe mandar conservando el puerto inferido: %+v", l)
+			}
+			return
+		}
+	}
+	t.Fatal("falta el uplink de ap1")
+}

+ 45 - 0
server-go/internal/adapters/topology.go

@@ -527,3 +527,48 @@ func fillNodeSpeeds(polled map[string]*routerPolled, dists []DistributionNode) {
 		}
 	}
 }
+
+// fillUplinkSpeeds (#1321): velocidad del uplink de una unidad cuando el
+// padre la reporta en esa boca (EthPort up + parseSpeedMbps, el mismo
+// criterio conservador de fillNodeSpeeds). El From del enlace puede ser el
+// router o un distnode suyo (salto #1060); en ambos casos la boca vive en
+// el router que la sondea. Sin dato, SpeedMbps queda a 0 y el front pinta
+// "—" en vez de afirmar una velocidad que nadie midió.
+func fillUplinkSpeeds(polled map[string]*routerPolled, dists []DistributionNode, links []TopoLink) {
+	if len(links) == 0 {
+		return
+	}
+	routerOfDist := map[string]string{}
+	portOfDist := map[string]string{}
+	for _, d := range dists {
+		routerOfDist[d.ID] = d.RouterID
+		portOfDist[d.ID] = d.Port
+	}
+	for i := range links {
+		l := &links[i]
+		if l.Kind != "uplink" || l.SpeedMbps > 0 || l.Port == "" {
+			continue
+		}
+		routerID := l.From
+		if r, ok := routerOfDist[l.From]; ok {
+			routerID = r
+			if p := portOfDist[l.From]; p != "" && p != l.Port {
+				// El distnode ancla otra boca: su velocidad no describe
+				// este enlace.
+				continue
+			}
+		}
+		p := polled[routerID]
+		if p == nil {
+			continue
+		}
+		for _, ep := range p.ports {
+			if ep.ID == l.Port && ep.Up {
+				if mbps := parseSpeedMbps(ep.Speed); mbps > 0 {
+					l.SpeedMbps = mbps
+				}
+				break
+			}
+		}
+	}
+}

+ 1 - 1
server-go/internal/adapters/topology_lldp_test.go

@@ -225,7 +225,7 @@ func TestTopoSemanticsCadenaLldp(t *testing.T) {
 		{RouterID: "flint2", Band: "cable", Port: "lan3", ID: "pc1", MAC: "04:D4:C4:8B:30:A7", AttachTo: "dist-flint2-lan3", Online: true},
 		{RouterID: "swA", Band: "cable", Port: "ge5", ID: "pc2", MAC: "DC:A6:32:4F:77:02", AttachTo: "dist-swA-ge5", Online: true},
 	}
-	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, dists, "", nil, nil)
+	sem := BuildTopoSemantics(routers, devices, WireGuardStats{}, dists, "", nil, nil, nil)
 
 	var gotDist []TopoLink
 	for _, l := range sem.Links {

+ 66 - 0
server-go/internal/adapters/topology_override.go

@@ -265,3 +265,69 @@ func applyTopologyOverrides(routers []Router, devices []Device, dists []Distribu
 	}
 	return devices, dists
 }
+
+// fleetOverrideEvidence (#1321): uplinks de unidades de flota fijados a mano
+// por la capa manual (#142). Un override kind=attach cuya MAC es la MAC
+// bridge de OTRO router de la flota fija el padre de esa unidad por encima
+// de toda inferencia (LLDP > FDB > device > gateway quedan por debajo).
+// El target se resuelve en los tres formatos del parent (#690): MAC de
+// router, id de router, o "routerId:puerto" (este también fija el puerto
+// del enlace). Los overrides de clientes (MAC que no es bridge de flota)
+// los sigue aplicando la capa de devices, no esta. Con varios overrides
+// sobre la misma unidad gana el ÚLTIMO (la carga viene created_at ASC, así
+// que es el más reciente). Pure function, sin BD.
+//
+// El parseo del parent es local y NO pasa NormalizeMAC al conjunto: el
+// formato "routerId:puerto" llevaba el puerto a minúsculas y dejaba de
+// casar con el nombre real de la boca ("two-gigabitEthernet 1/0/21").
+func fleetOverrideEvidence(overrides []TopologyOverride, routers []Router) map[string]topoParent {
+	if len(overrides) == 0 {
+		return nil
+	}
+	routerByMac := map[string]string{}
+	routerByID := map[string]bool{}
+	for _, r := range routers {
+		if r.MAC != "" {
+			routerByMac[NormalizeMAC(r.MAC)] = r.ID
+		}
+		routerByID[r.ID] = true
+	}
+	out := map[string]topoParent{}
+	for _, o := range overrides {
+		if !o.Enabled || o.Kind != "attach" {
+			continue
+		}
+		rid, ok := routerByMac[NormalizeMAC(o.MAC)]
+		if !ok {
+			continue
+		}
+		p := strings.TrimSpace(o.Parent)
+		if p == "" {
+			continue
+		}
+		var parent, port string
+		switch {
+		case macRe.MatchString(strings.ToLower(p)):
+			parent = routerByMac[strings.ToLower(p)]
+			if parent == "" {
+				continue // el target no es un router de flota
+			}
+		default:
+			routerID := ""
+			if i := strings.IndexByte(p, ':'); i >= 0 {
+				routerID, port = NormalizeMAC(p[:i]), strings.TrimSpace(p[i+1:])
+			} else {
+				routerID = NormalizeMAC(p)
+			}
+			if !routerByID[routerID] {
+				continue
+			}
+			parent = routerID
+		}
+		if parent == "" || parent == rid {
+			continue
+		}
+		out[rid] = topoParent{parent: parent, port: port}
+	}
+	return out
+}

+ 73 - 0
server-go/internal/adapters/topology_override_test.go

@@ -213,3 +213,76 @@ func TestApplyAttachOverrideParentInvalido(t *testing.T) {
 		}
 	}
 }
+
+// #1321: un attach manual cuya MAC es la bridge de una unidad de flota fija
+// su uplink por encima de toda inferencia, en los tres formatos de parent.
+func TestFleetOverrideEvidence(t *testing.T) {
+	routers := []Router{
+		{ID: "gw", Name: "gateway", MAC: "AA:BB:CC:00:00:01"},
+		{ID: "sw1", Name: "sw1", MAC: "AA:BB:CC:00:00:02"},
+		{ID: "ap1", Name: "ap1", MAC: "AA:BB:CC:00:00:03"},
+	}
+	overrides := []TopologyOverride{
+		// Target por MAC del switch (el caso de pl-komuch: AP etiquetado
+		// contra el MikroTik).
+		{Kind: "attach", MAC: "aa:bb:cc:00:00:03", Parent: "AA:BB:CC:00:00:02", Enabled: true},
+		// Overrides de clientes: NO son uplinks de flota.
+		{Kind: "attach", MAC: "00:00:00:00:00:09", Parent: "sw1", Enabled: true},
+		// Sin identidad de flota en la MAC del override: fuera.
+		{Kind: "attach", MAC: "00:00:00:00:00:08", Parent: "gw", Enabled: true},
+		// Apagado: fuera.
+		{Kind: "attach", MAC: "AA:BB:CC:00:00:03", Parent: "gw", Enabled: false},
+	}
+	ev := fleetOverrideEvidence(overrides, routers)
+	if got := ev["ap1"]; got.parent != "sw1" || got.port != "" {
+		t.Fatalf("ap1: %+v, want sw1 sin puerto", got)
+	}
+	if _, ok := ev["gw"]; ok {
+		t.Fatal("gw no debe tener padre")
+	}
+	// routerId:puerto fija también el puerto (respetando su caja original).
+	overrides = append(overrides, TopologyOverride{Kind: "attach", MAC: "aa:bb:cc:00:00:03", Parent: "sw1:two-gigabitEthernet 1/0/21", Enabled: true})
+	ev = fleetOverrideEvidence(overrides, routers)
+	if got := ev["ap1"]; got.parent != "sw1" || got.port != "two-gigabitEthernet 1/0/21" {
+		t.Fatalf("ap1 (router:port): %+v, want sw1/two-gigabitEthernet 1/0/21", got)
+	}
+	// Último override gana; colgarse de sí mismo se ignora.
+	overrides = append(overrides,
+		TopologyOverride{Kind: "attach", MAC: "aa:bb:cc:00:00:02", Parent: "sw1", Enabled: true},
+		TopologyOverride{Kind: "attach", MAC: "aa:bb:cc:00:00:03", Parent: "ap1", Enabled: true},
+	)
+	ev = fleetOverrideEvidence(overrides, routers)
+	if _, ok := ev["sw1"]; ok {
+		t.Fatal("un router no puede colgarse de sí mismo vía override")
+	}
+	if got := ev["ap1"]; got.parent != "sw1" {
+		t.Fatalf("ap1 tras override colgándolo de sí mismo: %+v, want sw1 (se ignora)", got)
+	}
+}
+
+// #1321: velocidad del uplink desde la EthPort del padre (directo o vía
+// distnode con la misma boca).
+func TestFillUplinkSpeeds(t *testing.T) {
+	polled := map[string]*routerPolled{
+		"sw1": {ports: []EthPort{
+			{ID: "two-gigabitEthernet 1/0/21", Up: true, Speed: "2.5 Gbps"},
+			{ID: "lan8", Up: false, Speed: "1 Gbps"},
+		}},
+	}
+	dists := []DistributionNode{{ID: "dist-sw1-lan8", RouterID: "sw1", Port: "lan8"}}
+	links := []TopoLink{
+		{From: "sw1", To: "ap1", Kind: "uplink", Port: "two-gigabitEthernet 1/0/21"},
+		{From: "dist-sw1-lan8", To: "ap2", Kind: "uplink", Port: "lan8"}, // boca caída: sin velocidad
+		{From: "gw", To: "ap3", Kind: "uplink"},                          // sin puerto: nada que mirar
+	}
+	fillUplinkSpeeds(polled, dists, links)
+	if links[0].SpeedMbps != 2500 {
+		t.Fatalf("uplink ap1: %d, want 2500", links[0].SpeedMbps)
+	}
+	if links[1].SpeedMbps != 0 {
+		t.Fatalf("uplink ap2 (boca caída): %d, want 0", links[1].SpeedMbps)
+	}
+	if links[2].SpeedMbps != 0 {
+		t.Fatalf("uplink ap3 (sin puerto): %d, want 0", links[2].SpeedMbps)
+	}
+}

+ 4 - 0
server-go/internal/adapters/types.go

@@ -419,6 +419,10 @@ type TopoLink struct {
 	To   string `json:"to"`
 	Kind string `json:"kind"`           // "wan"|"uplink"|"wired"|"dist"|"wg"
 	Port string `json:"port,omitempty"` // puerto físico si aplica
+	// SpeedMbps del enlace cuando el padre la reporta en esa boca (#1321):
+	// el padre es un switch sondeado y su EthPort da la velocidad negociada.
+	// 0 = desconocida (el front pinta "—" en vez de inventar).
+	SpeedMbps int `json:"speedMbps,omitempty"`
 }
 
 // RoamingDaemon clasifica el daemon de roaming/band-steering activo en la