Forráskód Böngészése

feat(demo): nodo managed GS308E en el canon — el switch deja de ser Device y pasa a DistributionNode managed (Salón lan3) con xbox/apple-tv/denon en abanico; el fantasma del gateway se mantiene (inferido vs identificado). Canon 67→66 devices

agent 4 hónapja
szülő
commit
352bfe7bc6

+ 56 - 3
server-go/internal/adapters/adapters_test.go

@@ -52,7 +52,7 @@ func TestDemoPrimerSnapshotEsCanon(t *testing.T) {
 		t.Fatalf("peer0: %+v", p0)
 	}
 	// DeviceTotals
-	if ov.DeviceTotals != (DeviceTotals{Total: 67, Online: 59, KnownOffline: 8, NewToday: 3}) {
+	if ov.DeviceTotals != (DeviceTotals{Total: 66, Online: 58, KnownOffline: 8, NewToday: 3}) {
 		t.Fatalf("deviceTotals: %+v", ov.DeviceTotals)
 	}
 	// Health
@@ -69,10 +69,10 @@ func TestDemoPrimerSnapshotEsCanon(t *testing.T) {
 	}
 }
 
-func TestDemoDevices67YTop(t *testing.T) {
+func TestDemoDevices66YTop(t *testing.T) {
 	d := NewDemo()
 	devs := d.GetDevices(context.Background())
-	if len(devs) != 67 {
+	if len(devs) != 66 {
 		t.Fatalf("devices: %d", len(devs))
 	}
 	offline := 0
@@ -473,3 +473,56 @@ func TestDemoBackhaulCanon(t *testing.T) {
 		}
 	}
 }
+
+// Canon demo del nodo "managed" (Fase 5): el GS308E del Salón es un
+// DistributionNode identificado por LLDP (NO un Device), con sus 3 clientes
+// en abanico. El fantasma inferido del gateway se mantiene (las dos
+// historias: inferido vs identificado).
+func TestDemoNodoManagedCanon(t *testing.T) {
+	d := NewDemo()
+	ov, err := d.GetOverview(context.Background())
+	if err != nil {
+		t.Fatal(err)
+	}
+	var managed, inferred *DistributionNode
+	for i := range ov.DistributionNodes {
+		switch ov.DistributionNodes[i].ID {
+		case "dist-living-lan3":
+			managed = &ov.DistributionNodes[i]
+		case "dist-flint2-lan3":
+			inferred = &ov.DistributionNodes[i]
+		}
+	}
+	if inferred == nil || inferred.Kind != "inferred" {
+		t.Fatalf("el fantasma del gateway se mantiene: %+v", inferred)
+	}
+	if managed == nil {
+		t.Fatalf("falta el nodo managed: %+v", ov.DistributionNodes)
+	}
+	if managed.Kind != "managed" || managed.RouterID != "living" || managed.Port != "lan3" || managed.MacCount != 4 {
+		t.Fatalf("nodo managed: %+v", managed)
+	}
+	if managed.Name != "GS308E" || managed.Ip != "192.168.8.13" {
+		t.Fatalf("name/ip: %+v", managed)
+	}
+	if managed.Lldp == nil || managed.Lldp.Chassis != "GS308E" || managed.Lldp.Mgmt != "192.168.8.13" ||
+		managed.Lldp.Caps != "Bridge" || managed.Lldp.PortDesc != "ge5" {
+		t.Fatalf("lldp del nodo: %+v", managed.Lldp)
+	}
+	// El GS308E ya no es un Device; sus 3 clientes cuelgan del nodo
+	fan := 0
+	for _, dev := range d.GetDevices(context.Background()) {
+		if dev.ID == "switch-netgear" {
+			t.Fatal("switch-netgear no debe existir como Device (es el nodo managed)")
+		}
+		if dev.AttachTo == "dist-living-lan3" {
+			fan++
+			if dev.RouterID != "living" {
+				t.Fatalf("cliente del managed con routerId raro: %+v", dev)
+			}
+		}
+	}
+	if fan != 3 {
+		t.Fatalf("abanico del managed: %d (esperaba 3)", fan)
+	}
+}

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

@@ -178,7 +178,7 @@ func (d *Demo) buildOverview() *Overview {
 		Adguard:      d.adguard,
 		Wireguard:    d.wireguardSnapshot(),
 		Routers:      d.routersCopy(),
-		DeviceTotals: DeviceTotals{Total: 67, Online: 59, KnownOffline: 8, NewToday: 3},
+		DeviceTotals: DeviceTotals{Total: 66, Online: 58, KnownOffline: 8, NewToday: 3},
 		TopDevices:   d.topDevices(5),
 		Alerts:       d.alertsCopy(),
 		UnreadAlerts: unread,
@@ -292,7 +292,7 @@ func (d *Demo) GetRouterDetail(_ context.Context, id string) (*RouterDetail, err
 	return detail, nil
 }
 
-// GetDevices devuelve copia de los 47 dispositivos.
+// GetDevices devuelve copia de los 66 dispositivos.
 func (d *Demo) GetDevices(context.Context) []Device {
 	d.mu.Lock()
 	defer d.mu.Unlock()

+ 25 - 18
server-go/internal/adapters/demo_dataset.go

@@ -1,7 +1,7 @@
 // demo_dataset.go — Dataset demo canónico COMPLETO (port literal de
 // server/src/demo/dataset.js, SPEC §7.1): 4 routers, WAN, trafficByRange,
-// health score, AdGuard, WireGuard, alertas, los 47 dispositivos (10
-// canónicos + 37 adicionales, sparklines deterministas con el mismo LCG),
+// health score, AdGuard, WireGuard, alertas, los 66 dispositivos (canon +
+// adicionales + fixtures topología v5, sparklines deterministas con el LCG),
 // routerExtras, perfSeries, WAN_LATENCY_24H, adguardSeries24h, wgPeerExtras
 // y WG_TOTALS_30D. Cada llamada a los builders devuelve estructuras NUEVAS
 // (el adapter muta su copia con el random walk; el canon no se toca).
@@ -274,12 +274,10 @@ func additionalDevices() []Device {
 			IP: "192.168.8.12", MAC: "DC:A6:32:4F:77:02", RouterID: "flint2", Band: "cable",
 			SignalDbm: nil, TrafficMbps: 0.8, Online: true, AttachTo: "dist-flint2-lan3"}, 14, 0),
 			"raspberrypi", "IP fija (reserva)", "hace 320 días", "3,4 GB", "890 MB", true, "red", ""),
-		// Switch gestionado identificado por LLDP (topología v5: type switch + Salón lan3)
-		withDetails(devExtra(Device{ID: "switch-netgear", Name: "Switch Netgear", Type: "switch", Manufacturer: "Netgear GS308E",
-			IP: "192.168.8.13", MAC: "28:C6:8E:1D:90:44", RouterID: "living", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 0.02, Online: true, Port: "lan3",
-			Lldp: &LldpInfo{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge5"}}, 15, 0.04),
-			"gs308e", "IP fija (reserva)", "hace 300 días", "64 MB", "12 MB", false, "red", "Network"),
+		// NOTA (Fase 5): el switch gestionado GS308E (Salón lan3) ya NO es un
+		// Device: se representa como DistributionNode "managed" (ver
+		// canonDistributionNodes), con xbox/apple-tv/denon en abanico — la
+		// historia del mockup "identificado por LLDP" sin duplicar el chip.
 		withDetails(devExtra(Device{ID: "timbre-nest", Name: "Timbre Nest", Type: "camara", Manufacturer: "Google",
 			IP: "192.168.8.72", MAC: "F4:F5:D8:66:01:B8", RouterID: "flint2", Band: "2.4 GHz",
 			SignalDbm: iptr(-58), TrafficMbps: 0.6, Online: true}, 16, 0),
@@ -412,9 +410,10 @@ func withDetails(d Device, hostname, lease, firstSeen, rx, tx string, adguard bo
 	return d
 }
 
-// canonAllDevices: los 67 clientes (canon expandido + adicionales + fixtures
-// de topología v5: switch gestionado LLDP, hipervisor con CTs, switch
-// inferido FDB — espejo del mock front app/src/data/mock.ts).
+// canonAllDevices: los 66 clientes (canon expandido + adicionales + fixtures
+// de topología v5: hipervisor con CTs, clientes tras switch inferido FDB y
+// tras el switch gestionado — espejo del mock front app/src/data/mock.ts).
+// Fase 5: el GS308E deja de ser Device (es el DistributionNode managed).
 func canonAllDevices() []Device {
 	out := canonDevices()
 	out = append(out, additionalDevices()...)
@@ -423,24 +422,26 @@ func canonAllDevices() []Device {
 }
 
 // topologyDevices: fixtures NUEVAS de topología v5 (mockup aprobado
-// 2-Ago-2026). Los 3 clientes preexistentes (switch-netgear, pc-sobremesa,
-// raspberry-pi) se enriquecen in situ en additionalDevices — no se duplican.
+// 2-Ago-2026). Los clientes preexistentes (pc-sobremesa, raspberry-pi) se
+// enriquecen in situ en additionalDevices — no se duplican. El GS308E NO
+// existe como Device: es el DistributionNode "managed" (Fase 5).
 func topologyDevices() []Device {
 	out := []Device{
-		// 3 clientes detrás del switch gestionado (Salón)
+		// 3 clientes detrás del switch gestionado identificado por LLDP
+		// (nodo managed dist-living-lan3, Salón)
 		withDetails(Device{ID: "xbox-series-s", Name: "Xbox Series S", Type: "consola", Manufacturer: "Microsoft",
 			IP: "192.168.8.35", MAC: "7C:ED:8D:4A:11:22", RouterID: "living", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 9.8, Online: true, AttachTo: "switch-netgear",
+			SignalDbm: nil, TrafficMbps: 9.8, Online: true, AttachTo: "dist-living-lan3",
 			Sparkline: []float64{3, 5, 7, 9, 11, 12, 10, 9, 10, 9, 10, 9.8}},
 			"xbox-series-s", "renueva en 4 h 12 min", "hace 140 días", "31 GB", "1,9 GB", true, "tv", ""),
 		withDetails(Device{ID: "apple-tv-4k", Name: "Apple TV 4K", Type: "tv", Manufacturer: "Apple",
 			IP: "192.168.8.36", MAC: "F0:18:98:2B:33:44", RouterID: "living", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 15.2, Online: true, AttachTo: "switch-netgear",
+			SignalDbm: nil, TrafficMbps: 15.2, Online: true, AttachTo: "dist-living-lan3",
 			Sparkline: []float64{6, 8, 10, 12, 14, 16, 15, 14, 15, 15, 15, 15.2}},
 			"apple-tv-4k", "renueva en 6 h 3 min", "hace 210 días", "88 GB", "3,4 GB", true, "tv", ""),
 		withDetails(Device{ID: "receptor-denon", Name: "Receptor Denon", Type: "altavoz", Manufacturer: "Denon",
 			IP: "192.168.8.37", MAC: "00:05:CD:55:66:77", RouterID: "living", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 0.6, Online: true, AttachTo: "switch-netgear",
+			SignalDbm: nil, TrafficMbps: 0.6, Online: true, AttachTo: "dist-living-lan3",
 			Sparkline: []float64{0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6}},
 			"denon-avr", "IP fija (reserva)", "hace 320 días", "640 MB", "42 MB", true, "iot", ""),
 		// Hipervisor Proxmox (gateway lan2); sus 10 CTs se anidan (OUI BC:24:11)
@@ -517,11 +518,17 @@ func topologyDevices() []Device {
 	return out
 }
 
-// canonDistributionNodes: distnodes demo (en live los infiere el colector FDB).
+// canonDistributionNodes: distnodes demo (en live los infiere el colector
+// FDB/LLDP). Las DOS historias de switch: fantasma inferido (gateway lan3)
+// vs gestionado identificado por LLDP (Salón lan3, el GS308E del mockup con
+// sus 3 clientes en abanico; Fase 5: ya no existe como Device suelto).
 func canonDistributionNodes() []DistributionNode {
 	return []DistributionNode{
 		{ID: "dist-flint2-lan3", Kind: "inferred", RouterID: "flint2", Port: "lan3", MacCount: 8},
 		{ID: "dist-pve", Kind: "hypervisor", RouterID: "flint2", Port: "lan2", MacCount: 11, HostDeviceID: "pve", Name: "Proxmox pve"},
+		{ID: "dist-living-lan3", Kind: "managed", RouterID: "living", Port: "lan3", MacCount: 4,
+			Name: "GS308E", Ip: "192.168.8.13",
+			Lldp: &LldpInfo{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge5"}},
 	}
 }
 

+ 6 - 5
server-go/internal/httpapi/httpapi_test.go

@@ -490,10 +490,11 @@ func TestDevicesPaginacionYFiltros(t *testing.T) {
 	srv := makeTestServer(t)
 	_, cookie, _ := loginCookie(t, srv.URL, "admin", "test1234")
 
-	// Paginación: 67 dispositivos del dataset canónico (47 base + 20 fixtures topología v5)
+	// Paginación: 66 dispositivos del dataset canónico (47 base − GS308E, que
+	// ahora es nodo managed, + 20 fixtures topología v5)
 	res := get(t, srv.URL, "/api/devices?page=1&pageSize=10", cookie)
 	body := readJSON(t, res)
-	if body["total"].(float64) != 67 || len(body["items"].([]any)) != 10 {
+	if body["total"].(float64) != 66 || len(body["items"].([]any)) != 10 {
 		t.Fatalf("page1: %v items, total %v", len(body["items"].([]any)), body["total"])
 	}
 	if body["page"].(float64) != 1 || body["pageSize"].(float64) != 10 {
@@ -501,7 +502,7 @@ func TestDevicesPaginacionYFiltros(t *testing.T) {
 	}
 	res = get(t, srv.URL, "/api/devices?page=7&pageSize=10", cookie)
 	body = readJSON(t, res)
-	if len(body["items"].([]any)) != 7 {
+	if len(body["items"].([]any)) != 6 {
 		t.Fatalf("page7 (resto): %v", len(body["items"].([]any)))
 	}
 	// Sin solape con la página anterior
@@ -525,7 +526,7 @@ func TestDevicesPaginacionYFiltros(t *testing.T) {
 	// Filtros
 	res = get(t, srv.URL, "/api/devices?routerId=living", cookie)
 	body = readJSON(t, res)
-	if body["total"].(float64) != 22 { // 18 base + switch-netgear + 3 clientes detrás
+	if body["total"].(float64) != 21 { // 18 base + 3 clientes del switch gestionado (nodo managed)
 		t.Fatalf("routerId=living: %v", body["total"])
 	}
 	res = get(t, srv.URL, "/api/devices?band=cable", cookie)
@@ -535,7 +536,7 @@ func TestDevicesPaginacionYFiltros(t *testing.T) {
 			t.Fatalf("band=cable con item de otra banda: %v", it)
 		}
 	}
-	if body["total"].(float64) != 27 { // 7 base + 20 fixtures cable (3 netgear + pve + 10 CTs + 6 tras switch)
+	if body["total"].(float64) != 26 { // 6 base + 20 fixtures cable (3 netgear + pve + 10 CTs + 6 tras switch)
 		t.Fatalf("band=cable: %v", body["total"])
 	}
 	res = get(t, srv.URL, "/api/devices?status=offline", cookie)