|
|
@@ -291,3 +291,35 @@ func TestUplinkLldpIdentityFallback(t *testing.T) {
|
|
|
t.Fatal("uplink por nombre del chasis debería identificarse (fallback #252)")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// #2182: una boca que recibe varios anuncios LLDP (uplink hacia un switch)
|
|
|
+// conserva la lista completa, sin repetir el mismo chasis y sin mezclar
|
|
|
+// vecinos de otras bocas.
|
|
|
+func TestWithLldpPeersVariosVecinos(t *testing.T) {
|
|
|
+ port := EthPort{ID: "lan4", Iface: "lan4", Up: true}
|
|
|
+ nbs := []LldpNeighbor{
|
|
|
+ {Port: "lan4", ChassisMac: "AA:BB:CC:00:00:01", Chassis: "sw-patio", PortDesc: "ge1"},
|
|
|
+ {Port: "lan4", ChassisMac: "AA:BB:CC:00:00:02", Chassis: "sw-garaje", PortDesc: "ge7"},
|
|
|
+ {Port: "lan4", ChassisMac: "AA:BB:CC:00:00:01", Chassis: "sw-patio", PortDesc: "ge1"},
|
|
|
+ {Port: "lan1", ChassisMac: "AA:BB:CC:00:00:09", Chassis: "otro", PortDesc: "ge2"},
|
|
|
+ }
|
|
|
+ got := withLldpPeers(port, nbs)
|
|
|
+ if len(got.LldpPeers) != 2 {
|
|
|
+ t.Fatalf("lldpPeers=%+v, esperaba dos vecinos distintos de lan4", got.LldpPeers)
|
|
|
+ }
|
|
|
+ if got.LldpPeers[0].Chassis != "sw-patio" || got.LldpPeers[1].Chassis != "sw-garaje" {
|
|
|
+ t.Fatalf("orden o contenido inesperado: %+v", got.LldpPeers)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Un solo vecino (o ninguno) deja la respuesta como estaba: sin campo.
|
|
|
+func TestWithLldpPeersCasoNormalNoCambia(t *testing.T) {
|
|
|
+ port := EthPort{ID: "lan1", Iface: "lan1", Up: true}
|
|
|
+ one := []LldpNeighbor{{Port: "lan1", Chassis: "sw-unico", PortDesc: "ge1"}}
|
|
|
+ if got := withLldpPeers(port, one); len(got.LldpPeers) != 0 {
|
|
|
+ t.Fatalf("con un vecino no debe aparecer la lista: %+v", got.LldpPeers)
|
|
|
+ }
|
|
|
+ if got := withLldpPeers(port, nil); len(got.LldpPeers) != 0 {
|
|
|
+ t.Fatalf("sin vecinos no debe aparecer la lista: %+v", got.LldpPeers)
|
|
|
+ }
|
|
|
+}
|