Sfoglia il codice sorgente

fix(rack): the managed switch's own FDB drives the auto-cabling (#1188)

Follow-up to #1187: the depth-escalation over the FDB learner graph produced a daisy chain (flooded broadcast frames teach every unit every other MAC on its uplink port). The rack uplinks now pick the infrastructure unit (the non-root member whose FDB learns the most fleet bridge MACs on distinct ports) and derive the cables from its FDB, including the gateway uplink. Flat networks without an aggregation unit produce no links instead of invented ones.
Nacho 2 mesi fa
parent
commit
0d55296cdf
1 ha cambiato i file con 69 aggiunte e 5 eliminazioni
  1. 69 5
      server-go/internal/adapters/live.go

+ 69 - 5
server-go/internal/adapters/live.go

@@ -507,16 +507,80 @@ func (l *Live) loadRouterMacs() {
 // Mode: "live".
 func (l *Live) Mode() string { return "live" }
 
-// FleetFdbUplinks (rack canvas): evidencia FDB de uplinks entre miembros
-// de flota, para el auto-cableado del canvas. Usa el último sondeo.
+// FleetFdbUplinks (rack canvas): enlaces derivados del FDB para el
+// auto-cableado. #1186: la unidad no-root cuyo FDB aprende más MACs bridge
+// de flota en puertos DISTINTOS es el switch gestionado (patrón de acceso:
+// una MAC por puerto); sus entradas FDB dan los cables exactos
+// switch(puerto) ↔ unidad(puerto) - incluido el propio gateway. Sin
+// candidato a switch (red plana) devuelve vacío: el auto-cableado no
+// inventa nada.
 func (l *Live) FleetFdbUplinks() map[string]FdbUplink {
-	out := map[string]FdbUplink{}
 	gw := ""
 	if l.gatewayCfg != nil {
 		gw = l.gatewayCfg.ID
 	}
-	for child, up := range fleetFdbEvidence(l.lastPolled, gw) {
-		out[child] = FdbUplink{ChildID: child, ParentID: up.parent, Port: up.port, ChildPort: up.childPort}
+	// Cobertura por unidad: MACs bridge de flota en su FDB y en cuántos
+	// puertos distintos.
+	type cover struct {
+		macs  map[string]bool
+		ports map[string]bool
+	}
+	cov := map[string]*cover{}
+	brMacOf := map[string]string{}
+	for id, p := range l.lastPolled {
+		if p == nil {
+			continue
+		}
+		if p.brMac != "" {
+			brMacOf[id] = strings.ToUpper(p.brMac)
+		}
+		c := &cover{macs: map[string]bool{}, ports: map[string]bool{}}
+		for mac := range p.fdb {
+			upper := strings.ToUpper(mac)
+			if owner, ok := brMacOf[upper]; ok && owner == id {
+				continue // la propia MAC bridge no es "cobertura"
+			}
+			c.macs[upper] = true
+			c.ports[p.fdb[mac]] = true
+		}
+		if len(c.macs) > 0 {
+			cov[id] = c
+		}
+	}
+	// Infraestructura: la unidad no-root con más MACs de flota aprendidas en
+	// ≥ 2 puertos distintos (el patrón del switch: un vecino por puerto).
+	infra, best := "", 0
+	ids := make([]string, 0, len(cov))
+	for id := range cov {
+		ids = append(ids, id)
+	}
+	sort.Strings(ids)
+	for _, id := range ids {
+		if id == gw {
+			continue
+		}
+		if n := len(cov[id].macs); n > best && len(cov[id].ports) >= 2 {
+			infra, best = id, n
+		}
+	}
+	if infra == "" {
+		return map[string]FdbUplink{}
+	}
+	// Cables: cada MAC de flota aprendida por la infra en un puerto = un
+	// cable infra(puerto) ↔ unidad(puerto hacia la infra). El root (gateway)
+	// también sale: su enlace al switch es el uplink de toda la casa.
+	infraBr := brMacOf[infra]
+	out := map[string]FdbUplink{}
+	for mac, port := range l.lastPolled[infra].fdb {
+		owner, ok := brMacOf[strings.ToUpper(mac)]
+		if !ok || owner == infra {
+			continue
+		}
+		childPort := ""
+		if lm, ok := l.lastPolled[owner]; ok && lm != nil {
+			childPort = lm.fdb[infraBr]
+		}
+		out[owner] = FdbUplink{ChildID: owner, ParentID: infra, Port: port, ChildPort: childPort}
 	}
 	return out
 }