Browse Source

feat(demo): SPEC-CANON D1/D3/D4/D5 — canon reconciliado (65 IDs)

- D1: GS308E vuelve a ser Device (switch-netgear: type switch, ip .13,
  lldp, attachTo living, port lan3) además del distnode managed, que ahora
  lleva Mac=28:C6:8E:1D:90:44.
- D3: eliminadas las identidades viejas wifi/offline de xbox-series-s e
  impresora-hp (una sola por ID, cableadas).
- D4: NAS lan1→lan4; pve lan2→lan5; dist-pve port lan5; PS5 lan2→lan1;
  ethPorts reescritos (flint2 lan3=switch sin gestión, lan4=NAS, lan5=pve
  2.5G; living lan3=GS308E up; estudio lan1=switch sin gestión solo-panel).
- D5: deviceTotals/adguard.clientsTotal/router.clients DERIVADOS del
  dataset (deviceTotalsOf/onlineClientsOf): 65 total, 59 online, 6 offline,
  3 nuevos; routers 26/20/8/5.
- Tests: demo_canon_test.go nuevo (duplicados, totales, GS308E, puertos);
  adapters/httpapi tests actualizados al canon 65.
agent 4 tháng trước cách đây
mục cha
commit
d6304fa34c

+ 36 - 9
server-go/internal/adapters/adapters_test.go

@@ -29,7 +29,7 @@ func TestDemoPrimerSnapshotEsCanon(t *testing.T) {
 	if *flint.CPU != 23 || *flint.RAM != 41 || *flint.Temp != 54 {
 		t.Fatalf("flint2 cpu/ram/temp: %v/%v/%v", *flint.CPU, *flint.RAM, *flint.Temp)
 	}
-	if flint.Clients != 33 || flint.Health != 98 {
+	if flint.Clients != 26 || flint.Health != 98 {
 		t.Fatalf("flint2 clients/health: %v/%v", flint.Clients, flint.Health)
 	}
 	// WAN
@@ -51,10 +51,13 @@ func TestDemoPrimerSnapshotEsCanon(t *testing.T) {
 	if p0.ID != "pixel-8-pro" || !p0.Active || p0.Rx != "1,2 GB" || p0.Tx != "214 MB" || p0.LastHandshake != "hace 38 s" {
 		t.Fatalf("peer0: %+v", p0)
 	}
-	// DeviceTotals
-	if ov.DeviceTotals != (DeviceTotals{Total: 66, Online: 58, KnownOffline: 8, NewToday: 3}) {
+	// DeviceTotals (D5: derivados del dataset reconciliado — 65 IDs únicos)
+	if ov.DeviceTotals != (DeviceTotals{Total: 65, Online: 59, KnownOffline: 6, NewToday: 3}) {
 		t.Fatalf("deviceTotals: %+v", ov.DeviceTotals)
 	}
+	if ov.Adguard.ClientsTotal != 65 {
+		t.Fatalf("adguard clientsTotal: %v", ov.Adguard.ClientsTotal)
+	}
 	// Health
 	if ov.Health.Score != 92 || ov.Health.Label != "Excelente" || len(ov.Health.Breakdown) != 3 {
 		t.Fatalf("health: %+v", ov.Health)
@@ -69,10 +72,10 @@ func TestDemoPrimerSnapshotEsCanon(t *testing.T) {
 	}
 }
 
-func TestDemoDevices66YTop(t *testing.T) {
+func TestDemoDevices65YTop(t *testing.T) {
 	d := NewDemo()
 	devs := d.GetDevices(context.Background())
-	if len(devs) != 66 {
+	if len(devs) != 65 {
 		t.Fatalf("devices: %d", len(devs))
 	}
 	offline := 0
@@ -84,7 +87,7 @@ func TestDemoDevices66YTop(t *testing.T) {
 			t.Fatalf("sparkline offline debe ser [] no null: %s", dev.ID)
 		}
 	}
-	if offline != 8 {
+	if offline != 6 {
 		t.Fatalf("offline: %d", offline)
 	}
 	ov, _ := d.GetOverview(context.Background())
@@ -509,11 +512,20 @@ func TestDemoNodoManagedCanon(t *testing.T) {
 		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
+	// SPEC-CANON D1: el nodo managed lleva la chassis-MAC del switch.
+	if managed.Mac != "28:C6:8E:1D:90:44" {
+		t.Fatalf("mac del nodo managed: %q", managed.Mac)
+	}
+	// SPEC-CANON D1/D2: el GS308E existe A LA VEZ como Device (con lldp,
+	// attachTo al router y port de uplink — NUNCA a su propio nodo) y sus
+	// 3 clientes cuelgan del nodo.
 	fan := 0
-	for _, dev := range d.GetDevices(context.Background()) {
+	var sw *Device
+	devices := d.GetDevices(context.Background())
+	for i := range devices {
+		dev := &devices[i]
 		if dev.ID == "switch-netgear" {
-			t.Fatal("switch-netgear no debe existir como Device (es el nodo managed)")
+			sw = dev
 		}
 		if dev.AttachTo == "dist-living-lan3" {
 			fan++
@@ -525,6 +537,21 @@ func TestDemoNodoManagedCanon(t *testing.T) {
 	if fan != 3 {
 		t.Fatalf("abanico del managed: %d (esperaba 3)", fan)
 	}
+	if sw == nil {
+		t.Fatal("switch-netgear debe existir como Device (SPEC-CANON D1)")
+	}
+	if sw.Type != "switch" || !sw.Online || sw.IP != "192.168.8.13" {
+		t.Fatalf("GS308E device: %+v", sw)
+	}
+	if sw.Lldp == nil || sw.Lldp.Chassis != "GS308E" {
+		t.Fatalf("GS308E device sin lldp: %+v", sw.Lldp)
+	}
+	if sw.AttachTo == "dist-living-lan3" {
+		t.Fatalf("el switch NO cuelga de su propio nodo: %+v", sw)
+	}
+	if sw.AttachTo != "living" || sw.Port != "lan3" {
+		t.Fatalf("GS308E attachTo/port de uplink: %+v", sw)
+	}
 }
 
 // Canon demo de Router.Lldp (Fase 5, ítem 4 de C2): los AP cableados

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

@@ -67,6 +67,12 @@ func NewDemo() *Demo {
 	for _, p := range wg.Peers {
 		d.wgBytes[p.ID] = &wgByteCounter{rx: parseBytes(p.Rx), tx: parseBytes(p.Tx), active: p.Active}
 	}
+	// SPEC-CANON D5: totales y clientes por router DERIVADOS del dataset
+	// (los literales de canonRouters/canonAdguard son solo el canon base).
+	for i := range d.routers {
+		d.routers[i].Clients = onlineClientsOf(d.devices, d.routers[i].ID)
+	}
+	d.adguard.ClientsTotal = len(d.devices)
 	return d
 }
 
@@ -178,7 +184,7 @@ func (d *Demo) buildOverview() *Overview {
 		Adguard:      d.adguard,
 		Wireguard:    d.wireguardSnapshot(),
 		Routers:      d.routersCopy(),
-		DeviceTotals: DeviceTotals{Total: 66, Online: 58, KnownOffline: 8, NewToday: 3},
+		DeviceTotals: deviceTotalsOf(d.devices), // D5: derivado del dataset
 		TopDevices:   d.topDevices(5),
 		Alerts:       d.alertsCopy(),
 		UnreadAlerts: unread,

+ 187 - 0
server-go/internal/adapters/demo_canon_test.go

@@ -0,0 +1,187 @@
+package adapters
+
+import (
+	"context"
+	"testing"
+)
+
+// Tests del canon reconciliado (SPEC-CANON fase 6, D1/D3/D4/D5). Fijan la
+// enumeración del dataset: sin IDs duplicadas, totales derivados, el switch
+// gestionado como Device + distnode managed y los puertos del gateway.
+
+func deviceByID(t *testing.T, devices []Device, id string) Device {
+	t.Helper()
+	for _, d := range devices {
+		if d.ID == id {
+			return d
+		}
+	}
+	t.Fatalf("device %q no existe en el dataset", id)
+	return Device{}
+}
+
+// D3: una sola identidad por ID en el dataset reconciliado.
+func TestCanonDatasetSinIDsDuplicadas(t *testing.T) {
+	devices := canonAllDevices()
+	seen := map[string]int{}
+	for _, d := range devices {
+		seen[d.ID]++
+	}
+	for id, n := range seen {
+		if n != 1 {
+			t.Fatalf("ID duplicada %q: %d definiciones", id, n)
+		}
+	}
+	// Las dos identidades reconciliadas, en su versión final:
+	xbox := deviceByID(t, devices, "xbox-series-s")
+	if !xbox.Online || xbox.Band != "cable" || xbox.AttachTo != "dist-living-lan3" {
+		t.Fatalf("xbox-series-s debería ser la cableada al GS308E: %+v", xbox)
+	}
+	hp := deviceByID(t, devices, "impresora-hp")
+	if !hp.Online || hp.Band != "cable" || hp.AttachTo != "dist-flint2-lan3" {
+		t.Fatalf("impresora-hp debería ser la cableada al switch inferido: %+v", hp)
+	}
+}
+
+// D5: los totales se derivan del dataset — la enumeración manda.
+func TestCanonTotalesDerivadosDelDataset(t *testing.T) {
+	devices := canonAllDevices()
+	totals := deviceTotalsOf(devices)
+	// Enumeración del canon reconciliado: 65 IDs únicos, 59 online, 6
+	// offline conocidos, 3 nuevos hoy.
+	if totals != (DeviceTotals{Total: 65, Online: 59, KnownOffline: 6, NewToday: 3}) {
+		t.Fatalf("enumeración del dataset: %+v", totals)
+	}
+
+	d := NewDemo()
+	ov, err := d.GetOverview(context.Background())
+	if err != nil {
+		t.Fatal(err)
+	}
+	if ov.DeviceTotals != totals {
+		t.Fatalf("overview.deviceTotals no derivado del dataset: %+v vs %+v", ov.DeviceTotals, totals)
+	}
+	if ov.Adguard.ClientsTotal != totals.Total {
+		t.Fatalf("adguard.clientsTotal=%d, dataset=%d", ov.Adguard.ClientsTotal, totals.Total)
+	}
+	// router.clients = recuento real online por router; la suma = online.
+	sum := 0
+	porRouter := map[string]int{}
+	for _, r := range ov.Routers {
+		porRouter[r.ID] = r.Clients
+		sum += r.Clients
+		if want := onlineClientsOf(devices, r.ID); r.Clients != want {
+			t.Fatalf("router %s clients=%d, enumeración=%d", r.ID, r.Clients, want)
+		}
+	}
+	if sum != totals.Online {
+		t.Fatalf("suma de clients por router=%d, online=%d", sum, totals.Online)
+	}
+	// Canon fijado: flint2/living/estudio/patio = 26/20/8/5.
+	want := map[string]int{"flint2": 26, "living": 20, "estudio": 8, "patio": 5}
+	for id, w := range want {
+		if porRouter[id] != w {
+			t.Fatalf("router %s clients=%d, canon=%d", id, porRouter[id], w)
+		}
+	}
+}
+
+// D1: el switch gestionado GS308E es Device (type switch, lldp, attachTo al
+// router, port de uplink) Y DistributionNode managed con Mac — y su Device
+// NO cuelga de su propio nodo (D2, paridad con inferTopology).
+func TestCanonSwitchGestionadoDeviceYNodo(t *testing.T) {
+	devices := canonAllDevices()
+	sw := deviceByID(t, devices, "switch-netgear")
+	if sw.Type != "switch" || sw.IP != "192.168.8.13" || !sw.Online {
+		t.Fatalf("GS308E device: %+v", sw)
+	}
+	if sw.RouterID != "living" || sw.AttachTo != "living" || sw.Port != "lan3" {
+		t.Fatalf("GS308E attachTo/port de uplink: %+v", sw)
+	}
+	if sw.Lldp == nil || sw.Lldp.Chassis != "GS308E" || sw.Lldp.Mgmt != "192.168.8.13" {
+		t.Fatalf("GS308E device sin lldp: %+v", sw.Lldp)
+	}
+
+	var managed *DistributionNode
+	for i, dn := range canonDistributionNodes() {
+		if dn.Kind == "managed" {
+			if managed != nil {
+				t.Fatalf("más de un distnode managed")
+			}
+			managed = &canonDistributionNodes()[i]
+		}
+	}
+	if managed == nil {
+		t.Fatal("no hay distnode managed")
+	}
+	if managed.ID != "dist-living-lan3" || managed.Mac == "" {
+		t.Fatalf("distnode managed sin mac: %+v", managed)
+	}
+	if managed.Mac != sw.MAC {
+		t.Fatalf("distnode.Mac=%q ≠ device.MAC=%q (la app cruza ambas para ocultar el chip)", managed.Mac, sw.MAC)
+	}
+	if sw.AttachTo == managed.ID {
+		t.Fatalf("el switch NO debe colgar de su propio nodo: %+v", sw)
+	}
+	// Y llega por el adapter demo (overview + devices).
+	d := NewDemo()
+	ov, _ := d.GetOverview(context.Background())
+	found := false
+	for _, dn := range ov.DistributionNodes {
+		if dn.ID == "dist-living-lan3" {
+			found = true
+			if dn.Mac != "28:C6:8E:1D:90:44" {
+				t.Fatalf("overview distnode managed mac: %q", dn.Mac)
+			}
+		}
+	}
+	if !found {
+		t.Fatal("overview sin dist-living-lan3")
+	}
+	deviceByID(t, d.GetDevices(context.Background()), "switch-netgear")
+}
+
+// D4: puertos del gateway y del Salón en devices y distnodes.
+func TestCanonPuertosD4(t *testing.T) {
+	devices := canonAllDevices()
+	if d := deviceByID(t, devices, "nas-synology"); d.Port != "lan4" {
+		t.Fatalf("NAS port: %q (D4: lan4)", d.Port)
+	}
+	if d := deviceByID(t, devices, "pve"); d.Port != "lan5" {
+		t.Fatalf("pve port: %q (D4: lan5)", d.Port)
+	}
+	if d := deviceByID(t, devices, "ps5"); d.Port != "lan1" {
+		t.Fatalf("PS5 port: %q (D4: lan1)", d.Port)
+	}
+	for _, dn := range canonDistributionNodes() {
+		if dn.ID == "dist-pve" && dn.Port != "lan5" {
+			t.Fatalf("dist-pve port: %q (D4: lan5)", dn.Port)
+		}
+		if dn.ID == "dist-flint2-lan3" && dn.Port != "lan3" {
+			t.Fatalf("dist-flint2-lan3 port: %q", dn.Port)
+		}
+	}
+	// Panel ethPorts del gateway cuadra con la tabla D4.
+	extras := canonRouterExtras()["flint2"]
+	ports := map[string]EthPort{}
+	for _, p := range extras.EthPorts {
+		ports[p.ID] = p
+	}
+	if ports["lan3"].ConnectedTo != "Switch sin gestión" || !ports["lan3"].Up {
+		t.Fatalf("flint2 lan3 (switch inferido): %+v", ports["lan3"])
+	}
+	if ports["lan4"].ConnectedTo != "NAS Synology" || !ports["lan4"].Up {
+		t.Fatalf("flint2 lan4 (NAS): %+v", ports["lan4"])
+	}
+	if ports["lan5"].ConnectedTo != "Proxmox pve" || ports["lan5"].Speed != "2.5 Gbps" || !ports["lan5"].Up {
+		t.Fatalf("flint2 lan5 (pve 2.5G): %+v", ports["lan5"])
+	}
+	// Salón: lan3 = GS308E UP (antes "libre/down").
+	living := map[string]EthPort{}
+	for _, p := range canonRouterExtras()["living"].EthPorts {
+		living[p.ID] = p
+	}
+	if !living["lan3"].Up || living["lan3"].ConnectedTo != "GS308E" {
+		t.Fatalf("living lan3 (GS308E up): %+v", living["lan3"])
+	}
+}

+ 82 - 29
server-go/internal/adapters/demo_dataset.go

@@ -1,10 +1,13 @@
 // 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 66 dispositivos (canon +
+// health score, AdGuard, WireGuard, alertas, los 65 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).
+// SPEC-CANON (fase 6): D1 switch gestionado = Device + distnode managed;
+// D3 una sola identidad por ID; D4 puertos del gateway; D5 totales
+// DERIVADOS del dataset (deviceTotalsOf / onlineClientsOf), no literales.
 package adapters
 
 import (
@@ -18,23 +21,26 @@ func iptr(v int) *int { return &v }
 // Routers / WAN / tráfico / health / AdGuard / WireGuard / alertas (canon)
 // ---------------------------------------------------------------------------
 
+// canonRouters: SPEC-CANON D5 — Clients es el recuento real de clientes
+// ONLINE por router del dataset (NewDemo lo re-deriva con onlineClientsOf;
+// estos literales solo documentan el canon y deben coincidir con él).
 func canonRouters() []Router {
 	return []Router{
 		{ID: "flint2", Name: "Gateway", Model: "GL.iNet Flint 2 (GL-MT6000)", ModelShort: "GL.iNet Flint 2",
 			Role: "Gateway principal", RoleBadge: "Principal", IP: "192.168.8.1", Status: "online",
-			Health: 98, CPU: iptr(23), RAM: iptr(41), Temp: iptr(54), Uptime: "32d 14h", Clients: 33,
+			Health: 98, CPU: iptr(23), RAM: iptr(41), Temp: iptr(54), Uptime: "32d 14h", Clients: 26,
 			Backhaul:  "cable",
 			Sparkline: []float64{8, 6, 5, 5, 6, 9, 18, 32, 41, 38, 35, 44, 52, 48, 45, 55, 68, 84, 96, 120, 150, 110, 84, 40}},
 		{ID: "living", Name: "Salón", Model: "OpenWrt AP (Xiaomi AX3000T)", ModelShort: "Xiaomi AX3000T",
 			Role: "Punto de acceso", RoleBadge: "AP", IP: "192.168.8.2", Status: "online",
-			Health: 95, CPU: iptr(12), RAM: iptr(38), Temp: iptr(47), Uptime: "32d 14h", Clients: 22,
+			Health: 95, CPU: iptr(12), RAM: iptr(38), Temp: iptr(47), Uptime: "32d 14h", Clients: 20,
 			Backhaul: "cable",
 			// Uplink cableado al gateway identificado por LLDP (sufijo "· LLDP")
 			Lldp:      &LldpInfo{Chassis: "Flint 2", Mgmt: "192.168.8.1", Caps: "Bridge, Router", PortDesc: "lan1"},
 			Sparkline: []float64{4, 3, 3, 2, 3, 5, 10, 22, 28, 26, 24, 30, 38, 35, 33, 42, 55, 72, 88, 105, 132, 92, 61, 28}},
 		{ID: "estudio", Name: "Estudio", Model: "OpenWrt (NanoPi R4S)", ModelShort: "NanoPi R4S",
 			Role: "AP + switch", RoleBadge: "AP", IP: "192.168.8.3", Status: "online",
-			Health: 92, CPU: iptr(18), RAM: iptr(44), Temp: iptr(51), Uptime: "11d 3h", Clients: 9,
+			Health: 92, CPU: iptr(18), RAM: iptr(44), Temp: iptr(51), Uptime: "11d 3h", Clients: 8,
 			Backhaul: "cable",
 			// Uplink cableado al gateway identificado por LLDP (sufijo "· LLDP")
 			Lldp:      &LldpInfo{Chassis: "Flint 2", Mgmt: "192.168.8.1", Caps: "Bridge, Router", PortDesc: "lan2"},
@@ -42,7 +48,7 @@ func canonRouters() []Router {
 		// Patio: único AP con uplink inalámbrico del dataset (backhaul "wifi").
 		{ID: "patio", Name: "Patio", Model: "OpenWrt (TP-Link EAP225)", ModelShort: "TP-Link EAP225",
 			Role: "AP exterior", RoleBadge: "AP", IP: "192.168.8.4", Status: "warn",
-			Health: 68, CPU: iptr(31), RAM: iptr(57), Temp: iptr(71), Uptime: "4d 2h", Clients: 6, HotMetric: "temp",
+			Health: 68, CPU: iptr(31), RAM: iptr(57), Temp: iptr(71), Uptime: "4d 2h", Clients: 5, HotMetric: "temp",
 			Backhaul:  "wifi",
 			Sparkline: []float64{1, 1, 1, 1, 1, 2, 3, 5, 7, 8, 8, 9, 10, 9, 8, 9, 11, 12, 13, 12, 9, 6, 4, 2}},
 	}
@@ -103,7 +109,8 @@ func canonAdguard() AdGuardStats {
 	return AdGuardStats{
 		Host: "192.168.8.1", Port: 3000, Status: "active",
 		Queries24h: 84312, Blocked24h: 15687, BlockedPct: 18.6, TrackersBlocked: 9204,
-		DNSLatencyMs: 14, ClientsUsing: 60, ClientsTotal: 67,
+		// ClientsTotal = IDs únicos del dataset (D5; NewDemo lo re-deriva).
+		DNSLatencyMs: 14, ClientsUsing: 60, ClientsTotal: 65,
 		TopBlocked: []TopBlocked{
 			{Domain: "graph.facebook.com", Count: 1204},
 			{Domain: "adservice.google.com", Count: 986},
@@ -221,7 +228,7 @@ func canonDevices() []Device {
 			Traffic24hRx: "18 GB", Traffic24hTx: "2,2 GB", Adguard: boolp(true), Group: "ordenadores"},
 		{ID: "ps5", Name: "PS5", Type: "consola", Manufacturer: "Sony",
 			IP: "192.168.8.31", MAC: "78:C8:81:0A:6B:D4", RouterID: "living", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 12.7, Online: true, Port: "lan2",
+			SignalDbm: nil, TrafficMbps: 12.7, Online: true, Port: "lan1",
 			Sparkline: []float64{4, 6, 8, 10, 12, 14, 13, 12, 13, 12, 13, 13},
 			Hostname:  "ps5-salon", DHCPLease: "IP fija (reserva)", FirstSeen: "hace 300 días",
 			Traffic24hRx: "92 GB", Traffic24hTx: "4,8 GB", Adguard: boolp(true), Group: "tv"},
@@ -245,7 +252,7 @@ func canonDevices() []Device {
 			Traffic24hRx: "1,4 GB", Traffic24hTx: "88 MB", Adguard: boolp(true), Group: "iot"},
 		{ID: "nas-synology", Name: "NAS Synology", Type: "servidor", Manufacturer: "Synology",
 			IP: "192.168.8.10", MAC: "00:11:32:9C:51:B7", RouterID: "flint2", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 2.3, Online: true, Port: "lan1",
+			SignalDbm: nil, TrafficMbps: 2.3, Online: true, Port: "lan4",
 			Sparkline: []float64{1, 1.5, 2, 2.5, 3, 2.8, 2.4, 2.2, 2.3, 2.3, 2.3, 2.3},
 			Hostname:  "diskstation", DHCPLease: "IP fija (reserva)", FirstSeen: "hace 320 días",
 			Traffic24hRx: "96 GB", Traffic24hTx: "1,1 TB", Adguard: boolp(true), Group: "red"},
@@ -278,10 +285,11 @@ 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", ""),
-		// 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.
+		// NOTA (SPEC-CANON D1): el switch gestionado GS308E (Salón lan3)
+		// vuelve a ser Device — ver topologyDevices, junto a sus clientes —
+		// ADEMÁS de seguir siendo el DistributionNode "managed"
+		// dist-living-lan3. La app excluye su chip del mapa cruzando
+		// Device.MAC con DistributionNode.Mac.
 		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),
@@ -294,10 +302,9 @@ func additionalDevices() []Device {
 			IP: "192.168.8.46", MAC: "3C:5A:B4:08:D7:5E", RouterID: "flint2", Band: "5 GHz",
 			SignalDbm: iptr(-49), TrafficMbps: 1.4, Online: true}, 18, 0),
 			"pixel-7", "renueva en 7 h 3 min", "hace 205 días", "1,9 GB", "180 MB", true, "moviles", ""),
-		withDetails(devExtra(Device{ID: "impresora-hp", Name: "Impresora HP", Type: "desconocido", Manufacturer: "HP",
-			IP: "192.168.8.14", MAC: "3C:52:82:AB:19:60", RouterID: "flint2", Band: "2.4 GHz",
-			SignalDbm: iptr(-60), TrafficMbps: 0, Online: false}, 1, 0),
-			"hp-laserjet-m209", "Expirado", "hace 250 días", "0 MB", "0 MB", true, "otros", "Printer"),
+		// SPEC-CANON D3: la identidad vieja wifi/offline de impresora-hp se
+		// elimina — la única es la cableada al switch inferido
+		// (topologyDevices, attachTo dist-flint2-lan3).
 		withDetails(devExtra(Device{ID: "ipad-air", Name: "iPad Air", Type: "tablet", Manufacturer: "Apple",
 			IP: "192.168.8.47", MAC: "8C:85:90:2F:B4:11", RouterID: "flint2", Band: "5 GHz",
 			SignalDbm: iptr(-54), TrafficMbps: 0, Online: false}, 1, 0),
@@ -341,10 +348,9 @@ func additionalDevices() []Device {
 			IP: "192.168.8.29", MAC: "A2:7E:9C:41:0B:6D", RouterID: "living", Band: "5 GHz",
 			SignalDbm: iptr(-58), TrafficMbps: 0.7, Online: true, IsNew: true}, 26, 0),
 			"unknown-7f2a", "renueva en 2 h 9 min", "hoy", "480 MB", "62 MB", false, "ordenadores", ""),
-		withDetails(devExtra(Device{ID: "xbox-series-s", Name: "Xbox Series S", Type: "consola", Manufacturer: "Microsoft",
-			IP: "192.168.8.32", MAC: "7C:1E:52:06:AA:3F", RouterID: "living", Band: "5 GHz",
-			SignalDbm: iptr(-55), TrafficMbps: 0, Online: false}, 1, 0),
-			"xbox-series-s", "Expirado", "hace 230 días", "0 MB", "0 MB", true, "tv", ""),
+		// SPEC-CANON D3: la identidad vieja wifi/offline de xbox-series-s se
+		// elimina — la única es la cableada al GS308E (topologyDevices,
+		// attachTo dist-living-lan3).
 		withDetails(devExtra(Device{ID: "portatil-antiguo", Name: "Portátil antiguo", Type: "portatil", Manufacturer: "HP",
 			IP: "192.168.8.28", MAC: "3C:52:82:5D:90:17", RouterID: "living", Band: "2.4 GHz",
 			SignalDbm: iptr(-62), TrafficMbps: 0, Online: false}, 1, 0),
@@ -414,10 +420,11 @@ func withDetails(d Device, hostname, lease, firstSeen, rx, tx string, adguard bo
 	return d
 }
 
-// canonAllDevices: los 66 clientes (canon expandido + adicionales + fixtures
+// canonAllDevices: los 65 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).
+// SPEC-CANON D1/D3: el GS308E vuelve a ser Device (además del distnode
+// managed) y xbox-series-s/impresora-hp tienen UNA sola identidad.
 func canonAllDevices() []Device {
 	out := canonDevices()
 	out = append(out, additionalDevices()...)
@@ -427,10 +434,20 @@ func canonAllDevices() []Device {
 
 // topologyDevices: fixtures NUEVAS de topología v5 (mockup aprobado
 // 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).
+// enriquecen in situ en additionalDevices — no se duplican. SPEC-CANON D1:
+// el GS308E existe como Device (badge "Switch gestionado", con Lldp,
+// attachTo al router Salón y port de su uplink) Y como DistributionNode
+// managed dist-living-lan3; la app no renderiza su chip cruzando MACs.
 func topologyDevices() []Device {
 	out := []Device{
+		// Switch gestionado Netgear GS308E (Salón lan3), identificado por
+		// LLDP. Device + nodo managed a la vez (SPEC-CANON D1): attachTo al
+		// router y port de uplink — NUNCA cuelga de su propio nodo (D2).
+		withDetails(devExtra(Device{ID: "switch-netgear", Name: "Switch GS308E", Type: "switch", Manufacturer: "Netgear",
+			IP: "192.168.8.13", MAC: "28:C6:8E:1D:90:44", RouterID: "living", Band: "cable",
+			SignalDbm: nil, TrafficMbps: 0.02, Online: true, AttachTo: "living", 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"),
 		// 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",
@@ -448,10 +465,11 @@ func topologyDevices() []Device {
 			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)
+		// Hipervisor Proxmox (gateway lan5, 2.5G — SPEC-CANON D4); sus 10 CTs
+		// se anidan (OUI BC:24:11)
 		withDetails(Device{ID: "pve", Name: "Proxmox pve", Type: "servidor", Manufacturer: "Supermicro",
 			IP: "192.168.8.5", MAC: "3C:52:82:10:20:30", RouterID: "flint2", Band: "cable",
-			SignalDbm: nil, TrafficMbps: 12.3, Online: true, Port: "lan2",
+			SignalDbm: nil, TrafficMbps: 12.3, Online: true, Port: "lan5",
 			Sparkline: []float64{8, 9, 10, 11, 12, 13, 12, 12, 12, 12, 12, 12.3}},
 			"pve", "IP fija (reserva)", "hace 400 días", "1,2 TB", "96 GB", true, "red", ""),
 	}
@@ -525,13 +543,14 @@ func topologyDevices() []Device {
 // 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).
+// sus 3 clientes en abanico). SPEC-CANON D1: el nodo managed lleva Mac
+// (chassis-MAC) para que la app excluya el chip del Device del switch.
 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-pve", Kind: "hypervisor", RouterID: "flint2", Port: "lan5", 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",
+			Name: "GS308E", Ip: "192.168.8.13", Mac: "28:C6:8E:1D:90:44",
 			Lldp: &LldpInfo{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge5"}},
 	}
 }
@@ -539,3 +558,37 @@ func canonDistributionNodes() []DistributionNode {
 // boolp: los literales demo fijan adguard explícito (true/false) como en el
 // dataset JS; live lo deja nil para omitir el campo.
 func boolp(b bool) *bool { return &b }
+
+// ---------------------------------------------------------------------------
+// D5 — totales DERIVADOS del dataset (nunca literales escritos a mano)
+// ---------------------------------------------------------------------------
+
+// deviceTotalsOf enumera el dataset y deriva deviceTotals: total = IDs
+// únicos del dataset reconciliado, online/offline por estado, newToday =
+// dispositivos con IsNew.
+func deviceTotalsOf(devices []Device) DeviceTotals {
+	t := DeviceTotals{Total: len(devices)}
+	for _, d := range devices {
+		if d.Online {
+			t.Online++
+		} else {
+			t.KnownOffline++
+		}
+		if d.IsNew {
+			t.NewToday++
+		}
+	}
+	return t
+}
+
+// onlineClientsOf: recuento real de clientes ONLINE de un router
+// (router.clients — SPEC-CANON D5).
+func onlineClientsOf(devices []Device, routerID string) int {
+	n := 0
+	for _, d := range devices {
+		if d.RouterID == routerID && d.Online {
+			n++
+		}
+	}
+	return n
+}

+ 16 - 10
server-go/internal/adapters/demo_extras.go

@@ -65,7 +65,9 @@ func canonRouterExtras() map[string]*demoExtras {
 			Soc: "MediaTek MT7986A", Flash: "8 GB eMMC", RamMb: 512,
 			BandSplit: demoBandSplit{Band24: 4, Band5: 10, Cable: 3},
 			TrafficNow: 84.2,
-			// GL-MT6000: 1× WAN 2.5G + 4× LAN 1G
+			// GL-MT6000: 1× WAN 2.5G + 4× LAN 1G + 1× LAN 2.5G.
+			// SPEC-CANON D4: lan1/lan2 = uplinks LLDP (Salón/Estudio),
+			// lan3 = switch tonto inferido, lan4 = NAS, lan5 = pve 2.5G.
 			GatewayLatencySpark: []float64{},
 			BackhaulSignal:      []float64{},
 			Radios:              []Radio{},
@@ -73,9 +75,10 @@ func canonRouterExtras() map[string]*demoExtras {
 			EthPorts: []EthPort{
 				{ID: "wan", Label: "WAN", Up: true, Speed: "2.5 Gbps", ConnectedTo: "ONT fibra · Digi", Detail: "84.122.x.x · full duplex"},
 				{ID: "lan1", Label: "LAN 1", Up: true, Speed: "1 Gbps", ConnectedTo: "Salón · AX3000T", Detail: "Uplink AP Salón (192.168.8.2)"},
-				{ID: "lan2", Label: "LAN 2", Up: true, Speed: "1 Gbps", ConnectedTo: "NAS Synology", Detail: "192.168.8.10 · cable"},
-				{ID: "lan3", Label: "LAN 3", Up: true, Speed: "1 Gbps", ConnectedTo: "Estudio · NanoPi R4S", Detail: "Uplink AP Estudio (192.168.8.3)"},
-				{ID: "lan4", Label: "LAN 4", Up: false},
+				{ID: "lan2", Label: "LAN 2", Up: true, Speed: "1 Gbps", ConnectedTo: "Estudio · NanoPi R4S", Detail: "Uplink AP Estudio (192.168.8.3)"},
+				{ID: "lan3", Label: "LAN 3", Up: true, Speed: "1 Gbps", ConnectedTo: "Switch sin gestión", Detail: "Inferido por FDB · 8 MACs"},
+				{ID: "lan4", Label: "LAN 4", Up: true, Speed: "1 Gbps", ConnectedTo: "NAS Synology", Detail: "192.168.8.10 · cable"},
+				{ID: "lan5", Label: "LAN 5", Up: true, Speed: "2.5 Gbps", ConnectedTo: "Proxmox pve", Detail: "192.168.8.5 · hipervisor · 10 CT"},
 			},
 		},
 		"living": {
@@ -98,12 +101,13 @@ func canonRouterExtras() map[string]*demoExtras {
 				{Name: "phy0-ap0", Up: true, Speed: "—", Role: "Radio 2.4 GHz"},
 				{Name: "phy1-ap0", Up: true, Speed: "—", Role: "Radio 5 GHz"},
 			},
-			// AX3000T: 1× WAN + 3× LAN
+			// AX3000T: 1× WAN + 3× LAN (SPEC-CANON D4: lan1 = PS5,
+			// lan3 = GS308E UP — el switch gestionado, dist-living-lan3)
 			EthPorts: []EthPort{
 				{ID: "wan", Label: "WAN", Up: true, Speed: "1 Gbps", ConnectedTo: "Uplink → Gateway", Detail: "Gateway · LAN 1 (192.168.8.1)"},
 				{ID: "lan1", Label: "LAN 1", Up: true, Speed: "1 Gbps", ConnectedTo: "PS5", Detail: "192.168.8.31 · cable"},
 				{ID: "lan2", Label: "LAN 2", Up: false},
-				{ID: "lan3", Label: "LAN 3", Up: false},
+				{ID: "lan3", Label: "LAN 3", Up: true, Speed: "1 Gbps", ConnectedTo: "GS308E", Detail: "Switch gestionado · 192.168.8.13 · LLDP"},
 			},
 		},
 		"estudio": {
@@ -122,14 +126,16 @@ func canonRouterExtras() map[string]*demoExtras {
 			Ports: []demoPortState{
 				{Name: "br-lan", Up: true, Speed: "—", Role: "Bridge LAN"},
 				{Name: "eth0", Up: true, Speed: "1 Gbps", Role: "Uplink al Gateway"},
-				{Name: "eth1", Up: true, Speed: "1 Gbps", Role: "Switch estudio"},
+				{Name: "eth1", Up: true, Speed: "1 Gbps", Role: "Switch sin gestión"},
 				{Name: "phy0-ap0", Up: true, Speed: "—", Role: "Radio 2.4 GHz"},
 				{Name: "phy1-ap0", Up: true, Speed: "—", Role: "Radio 5 GHz"},
 			},
-			// NanoPi R4S: 2× 1G (WAN + LAN)
+			// NanoPi R4S: 2× 1G (WAN + LAN). SPEC-CANON D4: lan1 = switch sin
+			// gestión — SOLO panel; la topología no lo muestra (los nodos
+			// "inferred" solo se anclan en el gateway, ver topology.go).
 			EthPorts: []EthPort{
-				{ID: "wan", Label: "WAN", Up: true, Speed: "1 Gbps", ConnectedTo: "Uplink → Gateway", Detail: "Gateway · LAN 3 (192.168.8.1)"},
-				{ID: "lan1", Label: "LAN 1", Up: true, Speed: "1 Gbps", ConnectedTo: "Switch estudio", Detail: "Switch 8 puertos · 4 en uso"},
+				{ID: "wan", Label: "WAN", Up: true, Speed: "1 Gbps", ConnectedTo: "Uplink → Gateway", Detail: "Gateway · LAN 2 (192.168.8.1)"},
+				{ID: "lan1", Label: "LAN 1", Up: true, Speed: "1 Gbps", ConnectedTo: "Switch sin gestión", Detail: "Switch 8 puertos · 4 en uso"},
 			},
 		},
 		"patio": {

+ 7 - 7
server-go/internal/httpapi/httpapi_test.go

@@ -490,11 +490,11 @@ func TestDevicesPaginacionYFiltros(t *testing.T) {
 	srv := makeTestServer(t)
 	_, cookie, _ := loginCookie(t, srv.URL, "admin", "test1234")
 
-	// Paginación: 66 dispositivos del dataset canónico (47 base − GS308E, que
-	// ahora es nodo managed, + 20 fixtures topología v5)
+	// Paginación: 65 dispositivos del dataset canónico reconciliado
+	// (SPEC-CANON D1/D3/D5: GS308E de vuelta como Device, sin IDs duplicadas)
 	res := get(t, srv.URL, "/api/devices?page=1&pageSize=10", cookie)
 	body := readJSON(t, res)
-	if body["total"].(float64) != 66 || len(body["items"].([]any)) != 10 {
+	if body["total"].(float64) != 65 || 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 {
@@ -502,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)) != 6 {
+	if len(body["items"].([]any)) != 5 {
 		t.Fatalf("page7 (resto): %v", len(body["items"].([]any)))
 	}
 	// Sin solape con la página anterior
@@ -526,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) != 21 { // 18 base + 3 clientes del switch gestionado (nodo managed)
+	if body["total"].(float64) != 21 { // 17 base + GS308E (Device, D1) + 3 clientes del switch gestionado
 		t.Fatalf("routerId=living: %v", body["total"])
 	}
 	res = get(t, srv.URL, "/api/devices?band=cable", cookie)
@@ -536,12 +536,12 @@ func TestDevicesPaginacionYFiltros(t *testing.T) {
 			t.Fatalf("band=cable con item de otra banda: %v", it)
 		}
 	}
-	if body["total"].(float64) != 26 { // 6 base + 20 fixtures cable (3 netgear + pve + 10 CTs + 6 tras switch)
+	if body["total"].(float64) != 27 { // 6 base + 21 fixtures cable (GS308E + 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)
 	body = readJSON(t, res)
-	if body["total"].(float64) != 8 {
+	if body["total"].(float64) != 6 {
 		t.Fatalf("status=offline: %v", body["total"])
 	}
 	res = get(t, srv.URL, "/api/devices?type=movil", cookie)