demo_dataset.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. // demo_dataset.go — Dataset demo canónico COMPLETO (port literal de
  2. // server/src/demo/dataset.js, SPEC §7.1): 4 routers, WAN, trafficByRange,
  3. // health score, AdGuard, WireGuard, alertas, los 65 dispositivos (canon +
  4. // adicionales + fixtures topología v5, sparklines deterministas con el LCG),
  5. // routerExtras, perfSeries, WAN_LATENCY_24H, adguardSeries24h, wgPeerExtras
  6. // y WG_TOTALS_30D. Cada llamada a los builders devuelve estructuras NUEVAS
  7. // (el adapter muta su copia con el random walk; el canon no se toca).
  8. // SPEC-CANON (fase 6): D1 switch gestionado = Device + distnode managed;
  9. // D3 una sola identidad por ID; D4 puertos del gateway; D5 totales
  10. // DERIVADOS del dataset (deviceTotalsOf / onlineClientsOf), no literales.
  11. // SPEC-65 D65-2: Device.Infra sellado en el canon (pve=hypervisor, sus
  12. // CTs/VMs=ct, switch-netgear=managed-switch).
  13. // ALERTAS BILINGÜES (issue #239): el canon de alertas guarda title/description
  14. // en es/en (canonAlertSpecs). El seed de NewDemo sirve EN, el idioma canónico
  15. // (#1014; sin contexto de
  16. // petición); localizedCanonAlerts(lang) permite servir la lengua activa cuando
  17. // el handler la propague.
  18. //
  19. //go:generate go run ../../cmd/gen-demo-canon
  20. package adapters
  21. import (
  22. "fmt"
  23. "math"
  24. "time"
  25. "github.com/gnacho/netpulse/server-go/internal/alerts"
  26. )
  27. func iptr(v int) *int { return &v }
  28. // ---------------------------------------------------------------------------
  29. // Routers / WAN / tráfico / health / AdGuard / WireGuard / alertas (canon)
  30. // ---------------------------------------------------------------------------
  31. // canonRouters: SPEC-CANON D5 — Clients es el recuento real de clientes
  32. // ONLINE por router del dataset (NewDemo lo re-deriva con onlineClientsOf;
  33. // estos literales solo documentan el canon y deben coincidir con él).
  34. func canonRouters() []Router {
  35. return []Router{
  36. {ID: "flint2", Name: "Gateway", Model: "GL.iNet Flint 2 (GL-MT6000)", ModelShort: "GL.iNet Flint 2",
  37. Role: "Gateway principal", RoleBadge: "Principal", IP: "192.168.8.1", Status: "online",
  38. Health: 98, CPU: iptr(23), RAM: iptr(41), Temp: iptr(54), Uptime: "32d 14h", Clients: 26,
  39. Backhaul: "cable",
  40. 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}},
  41. {ID: "living", Name: "Salón", Model: "OpenWrt AP (Xiaomi AX3000T)", ModelShort: "Xiaomi AX3000T",
  42. Role: "Punto de acceso", RoleBadge: "AP", IP: "192.168.8.2", Status: "online",
  43. Health: 95, CPU: iptr(12), RAM: iptr(38), Temp: iptr(47), Uptime: "32d 14h", Clients: 20,
  44. Backhaul: "cable",
  45. // Uplink cableado al gateway identificado por LLDP (sufijo "· LLDP")
  46. Lldp: &LldpInfo{Chassis: "Flint 2", Mgmt: "192.168.8.1", Caps: "Bridge, Router", PortDesc: "lan1"},
  47. 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}},
  48. {ID: "estudio", Name: "Estudio", Model: "OpenWrt (NanoPi R4S)", ModelShort: "NanoPi R4S",
  49. Role: "AP + switch", RoleBadge: "AP", IP: "192.168.8.3", Status: "online",
  50. Health: 92, CPU: iptr(18), RAM: iptr(44), Temp: iptr(51), Uptime: "11d 3h", Clients: 8,
  51. Backhaul: "cable",
  52. // Uplink cableado al gateway identificado por LLDP (sufijo "· LLDP")
  53. Lldp: &LldpInfo{Chassis: "Flint 2", Mgmt: "192.168.8.1", Caps: "Bridge, Router", PortDesc: "lan2"},
  54. Sparkline: []float64{2, 2, 1, 1, 2, 4, 8, 15, 22, 25, 24, 22, 26, 24, 21, 24, 28, 31, 29, 24, 18, 12, 8, 4}},
  55. // Patio: único AP con uplink inalámbrico del dataset (backhaul "wifi").
  56. {ID: "patio", Name: "Patio", Model: "OpenWrt (TP-Link EAP225)", ModelShort: "TP-Link EAP225",
  57. Role: "AP exterior", RoleBadge: "AP", IP: "192.168.8.4", Status: "warn",
  58. Health: 68, CPU: iptr(31), RAM: iptr(57), Temp: iptr(71), Uptime: "4d 2h", Clients: 5, HotMetric: "temp",
  59. Backhaul: "wifi",
  60. 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}},
  61. }
  62. }
  63. func canonWAN() WAN {
  64. return WAN{
  65. Plan: "600/600 Mbps", DownMbps: 84.2, UpMbps: 12.6, LatencyMs: 8, LossPct: 0,
  66. PublicIP: "84.122.x.x", Isp: "Digi", PeakTodayMbps: 412, PeakTodayTime: "21:14",
  67. AvgDownMbps: 61, Total24h: 1.32e12,
  68. // #2047: el resumen por rango de la demo, coherente con sus series
  69. // (pico mayor cuanto más larga la ventana, total proporcional).
  70. RangeStats: map[string]WANRangeStat{
  71. "1h": {PeakMbps: 118, AvgMbps: 74, TotalBytes: 33.3e9, Samples: 60},
  72. "24h": {PeakMbps: 412, AvgMbps: 61, TotalBytes: 1.32e12, Samples: 1440},
  73. "7d": {PeakMbps: 486, AvgMbps: 58, TotalBytes: 8.8e12, Samples: 10080},
  74. "30d": {PeakMbps: 512, AvgMbps: 55, TotalBytes: 35.6e12, Samples: 43200},
  75. },
  76. }
  77. }
  78. func tp(t string, down, up float64) TrafficPoint { return TrafficPoint{T: t, Down: down, Up: up} }
  79. func canonTraffic() TrafficByRange {
  80. return TrafficByRange{
  81. H1: []TrafficPoint{
  82. tp("21:30", 68, 9), tp("21:33", 74, 10), tp("21:36", 81, 11), tp("21:39", 92, 12),
  83. tp("21:42", 88, 10), tp("21:45", 96, 13), tp("21:48", 104, 14), tp("21:51", 98, 12),
  84. tp("21:54", 90, 11), tp("21:57", 86, 10), tp("22:00", 82, 11), tp("22:03", 78, 12),
  85. tp("22:06", 84, 13), tp("22:09", 91, 14), tp("22:12", 88, 12), tp("22:15", 84, 11),
  86. tp("22:18", 80, 10), tp("22:21", 83, 12), tp("22:24", 86, 13), tp("22:27", 84, 12.6),
  87. },
  88. H24: []TrafficPoint{
  89. tp("00", 42, 8), tp("01", 28, 6), tp("02", 15, 5), tp("03", 9, 4),
  90. tp("04", 7, 4), tp("05", 8, 5), tp("06", 14, 6), tp("07", 32, 9),
  91. tp("08", 58, 14), tp("09", 74, 18), tp("10", 88, 21), tp("11", 96, 24),
  92. tp("12", 112, 26), tp("13", 124, 28), tp("14", 118, 25), tp("15", 132, 27),
  93. tp("16", 148, 30), tp("17", 176, 34), tp("18", 224, 42), tp("19", 298, 55),
  94. tp("20", 356, 71), tp("21", 412, 96), tp("22", 284, 48), tp("23", 122, 21),
  95. },
  96. D7: []TrafficPoint{
  97. tp("Lun", 61, 12), tp("Mar", 58, 11), tp("Mié", 64, 13), tp("Jue", 71, 15),
  98. tp("Vie", 88, 19), tp("Sáb", 96, 22), tp("Dom", 84, 18),
  99. },
  100. D30: []TrafficPoint{
  101. tp("1", 54, 10), tp("4", 58, 11), tp("7", 62, 12), tp("10", 57, 11),
  102. tp("13", 66, 13), tp("16", 72, 15), tp("19", 68, 14), tp("22", 75, 16),
  103. tp("25", 81, 18), tp("28", 78, 17), tp("30", 84, 19),
  104. },
  105. }
  106. }
  107. func canonHealthScore() HealthScore {
  108. return HealthScore{
  109. Score: 92, Label: "Excelente", Caption: "Puntuación de salud de la red",
  110. Note: "Penalizado por la temperatura del Patio.",
  111. Breakdown: []HealthDelta{
  112. {Label: "temp. Patio", Delta: -4},
  113. {Label: "cobertura Patio", Delta: -2},
  114. {Label: "canal 2.4 GHz congestionado", Delta: -2},
  115. },
  116. Subscores: []Subscore{
  117. {Key: "wan", Label: "WAN", Score: 98},
  118. {Key: "wifi", Label: "WiFi", Score: 88},
  119. {Key: "infra", Label: "Infra", Score: 92},
  120. {Key: "services", Label: "Servicios", Score: 100},
  121. },
  122. }
  123. }
  124. func canonAdguard() AdGuardStats {
  125. return AdGuardStats{
  126. Host: "192.168.8.1", Port: 3000, Status: "active",
  127. Queries24h: 84312, Blocked24h: 15687, BlockedPct: 18.6, TrackersBlocked: 9204,
  128. // ClientsTotal = IDs únicos del dataset (D5; NewDemo lo re-deriva).
  129. DNSLatencyMs: 14, ClientsUsing: 60, ClientsTotal: 65,
  130. TopBlocked: []TopBlocked{
  131. {Domain: "graph.facebook.com", Count: 1204},
  132. {Domain: "adservice.google.com", Count: 986},
  133. {Domain: "metrics.icloud.com", Count: 731},
  134. {Domain: "telemetry.nvidia.com", Count: 512},
  135. {Domain: "ads.tiktok.com", Count: 448},
  136. },
  137. FilterLists: 6, Rules: 218442,
  138. }
  139. }
  140. func canonWireguard() WireGuardStats {
  141. return WireGuardStats{
  142. Interface: "wg0", Subnet: "10.0.0.1/24", Status: "active",
  143. // Key: identificador estable del peer (#1441). En el demo son ids sintéticos
  144. // legibles para no parecer secretos ante el escáner (gitleaks).
  145. // Urgent: el túnel site-to-site es el único que avisa si se cae; los
  146. // portátiles y móviles son rutina (el resto, false).
  147. Peers: []WGPeer{
  148. {ID: "pixel-8-pro", Key: "demo-pixel-8-pro", Name: "Pixel 8 Pro", Type: "movil", TunnelIP: "10.0.0.2", Active: true, LastHandshake: "hace 38 s", Rx: "1,2 GB", Tx: "214 MB"},
  149. {ID: "macbook-air", Key: "demo-macbook-air", Name: "MacBook Air", Type: "portatil", TunnelIP: "10.0.0.3", Active: true, LastHandshake: "hace 1 min", Rx: "640 MB", Tx: "88 MB"},
  150. {ID: "ipad-air", Key: "demo-ipad-air", Name: "iPad Air", Type: "tablet", TunnelIP: "10.0.0.4", Active: false, LastHandshake: "hace 2 días", Rx: "3,1 GB", Tx: "402 MB"},
  151. {ID: "portatil-trabajo", Key: "demo-portatil-trabajo", Name: "Portátil trabajo", Type: "portatil", TunnelIP: "10.0.0.5", Active: false, LastHandshake: "hace 6 h", Rx: "812 MB", Tx: "121 MB"},
  152. {ID: "casa-familia", Key: "demo-casa-familia", Name: "Casa familia", Type: "sitio", TunnelIP: "10.0.0.6", Active: false, LastHandshake: "hace 9 días", Rx: "12 GB", Tx: "4,2 GB", Urgent: true},
  153. },
  154. }
  155. }
  156. // alertText: pareja de textos de una alerta demo en es/en (issue #239). El
  157. // canon de alertas es bilingüe; la lengua se elige al construir el evento.
  158. type alertText struct {
  159. Es string
  160. En string
  161. }
  162. // alertSpec describe una alerta canónica con textos bilingües. tsOffset es el
  163. // escalonado hacia atrás desde now ("hace 12 min" → now-720, ...).
  164. type alertSpec struct {
  165. id, category, severity, routerID string
  166. urgent, read bool
  167. tsOffset int64
  168. title, description alertText
  169. time string
  170. }
  171. // canonAlertSpecs: las 5 alertas canónicas (SPEC-ALERTAS §1 y §5), con title/
  172. // description en es/en. Time es el string legado de display.
  173. var canonAlertSpecs = []alertSpec{
  174. {
  175. id: "alert-temp-patio", category: alerts.CatRouter, severity: "warn", routerID: "patio",
  176. urgent: true, tsOffset: 12 * 60, time: "hace 12 min",
  177. title: alertText{Es: "Temperatura alta en Patio", En: "High temperature on Patio"},
  178. description: alertText{Es: "71 °C, por encima del umbral (65 °C)", En: "71 °C, above the threshold (65 °C)"},
  179. },
  180. {
  181. id: "alert-firmware-estudio", category: alerts.CatSystem, severity: "warn", routerID: "estudio",
  182. tsOffset: 3 * 3600, time: "hace 3 h",
  183. title: alertText{Es: "Firmware disponible", En: "Firmware available"},
  184. description: alertText{Es: "OpenWrt 24.10.1 para Estudio", En: "OpenWrt 24.10.1 for Study"},
  185. },
  186. {
  187. id: "alert-nuevo-tab", category: alerts.CatClients, severity: "info", routerID: "living",
  188. read: true, tsOffset: 26 * 60, time: "hace 26 min",
  189. title: alertText{Es: "Nuevo dispositivo", En: "New device"},
  190. description: alertText{Es: "'Galaxy Tab S9' se ha unido a Salón", En: "'Galaxy Tab S9' joined Living Room"},
  191. },
  192. {
  193. id: "alert-handshake-wg", category: alerts.CatVPN, severity: "info", routerID: "flint2",
  194. read: true, tsOffset: 38, time: "hace 38 s",
  195. title: alertText{Es: "Handshake WireGuard", En: "WireGuard handshake"},
  196. description: alertText{Es: "Pixel 8 Pro conectado desde 5.224.x.x", En: "Pixel 8 Pro connected from 5.224.x.x"},
  197. },
  198. {
  199. id: "alert-backup-adguard", category: alerts.CatSystem, severity: "ok", routerID: "flint2",
  200. read: true, tsOffset: 24 * 3600, time: "hace 1 día",
  201. title: alertText{Es: "Copia de AdGuard completada", En: "AdGuard backup completed"},
  202. description: alertText{Es: "Configuración y listas respaldadas en el NAS", En: "Configuration and lists backed up to the NAS"},
  203. },
  204. }
  205. // pickText selecciona el texto de una alerta por lengua ("es" → español,
  206. // cualquier otra → inglés).
  207. func pickText(t alertText, lang string) string {
  208. if lang == "es" {
  209. return t.Es
  210. }
  211. return t.En
  212. }
  213. // buildCanonAlerts construye las 5 alertas canónicas en la lengua dada. Los
  214. // Ts son unix SEGUNDOS escalonados en coherencia con el string legado
  215. // ("hace 38 s" → now-38, "hace 12 min" → now-720, ...).
  216. func buildCanonAlerts(lang string) []AlertEvent {
  217. now := time.Now().Unix()
  218. out := make([]AlertEvent, 0, len(canonAlertSpecs))
  219. for _, s := range canonAlertSpecs {
  220. out = append(out, AlertEvent{
  221. ID: s.id, Category: s.category, Urgent: s.urgent, Severity: s.severity,
  222. Title: pickText(s.title, lang), Description: pickText(s.description, lang),
  223. Time: s.time, Ts: now - s.tsOffset, Read: s.read, RouterID: s.routerID,
  224. })
  225. }
  226. return out
  227. }
  228. // canonAlerts: las 5 alertas canónicas (SPEC-ALERTAS §1 y §5) en inglés, el
  229. // idioma canónico de las alertas desde #1014. El seed corre en NewDemo sin
  230. // contexto de petición, por eso el canon sirve EN; la localización por lengua
  231. // de la petición se puede conectar pasando la lengua a localizedCanonAlerts
  232. // desde el handler (issue #239).
  233. func canonAlerts() []AlertEvent {
  234. return buildCanonAlerts("en")
  235. }
  236. // localizedCanonAlerts: alertas canónicas en la lengua de la petición ("es" →
  237. // español, resto → inglés). Punto de entrada para localizar el dataset demo
  238. // server-side cuando el handler propague la lengua (issue #239).
  239. func localizedCanonAlerts(lang string) []AlertEvent {
  240. return buildCanonAlerts(lang)
  241. }
  242. // ---------------------------------------------------------------------------
  243. // Dispositivos: sparkline determinista (mismo LCG que devices-data.ts) y
  244. // helpers extra()/bulb() del dataset.js
  245. // ---------------------------------------------------------------------------
  246. // spark replica spark(seed, base, spread) de dataset.js: LCG
  247. // s = (s*9301 + 49297) % 233280, 12 puntos, el último es `base`.
  248. func spark(seed int, base, spread float64) []float64 {
  249. s := seed
  250. out := make([]float64, 0, 12)
  251. for i := 0; i < 12; i++ {
  252. s = (s*9301 + 49297) % 233280
  253. r := float64(s) / 233280
  254. v := base + (r-0.45)*spread
  255. v = math.Round(v*100) / 100 // toFixed(2)
  256. if v < 0 {
  257. v = 0
  258. }
  259. out = append(out, v)
  260. }
  261. out[len(out)-1] = base
  262. return out
  263. }
  264. // devExtra replica extra(spec): sparkline vacío ([]) si offline.
  265. func devExtra(d Device, seed int, spread float64) Device {
  266. if d.Online {
  267. if spread == 0 {
  268. spread = d.TrafficMbps * 0.8
  269. }
  270. d.Sparkline = spark(seed, d.TrafficMbps, spread)
  271. } else {
  272. d.Sparkline = []float64{}
  273. }
  274. return d
  275. }
  276. // bulb replica bulb(n, name, ip, mac, dbm) del dataset.js.
  277. func bulb(n int, name, ip, mac string, dbm int) Device {
  278. return Device{
  279. ID: fmt.Sprintf("bombilla-%d", n), Name: name, Type: "iot", Manufacturer: "Ikea Trådfri",
  280. IP: ip, MAC: mac, RouterID: "living", Band: "2.4 GHz", SignalDbm: iptr(dbm),
  281. TrafficMbps: 0, Online: true, Sparkline: spark(40+n, 0.005, 0.02),
  282. Hostname: fmt.Sprintf("tradfri-%d", n), DHCPLease: "renueva en 12 h 0 min", FirstSeenMs: seenDaysAgo(280), LastSeenMs: demoSeenBaseMs,
  283. Traffic24hRx: "4 MB", Traffic24hTx: "1 MB", Adguard: boolp(true), Group: "iot",
  284. }
  285. }
  286. // canonDevices son los 10 destacados (el agregado bombillas-ikea NO está:
  287. // se expande en 6 bulb()), ya fusionados con CANON_DETAILS.
  288. func canonDevices() []Device {
  289. return []Device{
  290. {ID: "imac-salon", Name: "iMac Salón", Type: "ordenador", Manufacturer: "Apple",
  291. IP: "192.168.8.21", MAC: "A4:83:E7:21:0B:3C", RouterID: "living", Band: "5 GHz",
  292. SignalDbm: iptr(-48), TrafficMbps: 32.4, Online: true,
  293. Sparkline: []float64{12, 15, 18, 22, 26, 30, 34, 32, 28, 30, 32, 31},
  294. Hostname: "imac-de-marc", DHCPLease: "IP fija (reserva)", FirstSeenMs: seenDaysAgo(320), LastSeenMs: demoSeenBaseMs,
  295. Traffic24hRx: "38 GB", Traffic24hTx: "2,1 GB", Adguard: boolp(true), Group: "ordenadores"},
  296. {ID: "tv-samsung", Name: "TV Samsung", Type: "tv", Manufacturer: "Samsung",
  297. IP: "192.168.8.34", MAC: "8C:EA:48:5D:2F:91", RouterID: "living", Band: "5 GHz",
  298. SignalDbm: iptr(-52), TrafficMbps: 18.1, Online: true,
  299. Sparkline: []float64{8, 10, 14, 16, 18, 20, 19, 18, 17, 18, 18, 18},
  300. Hostname: "samsung-tv-salon", DHCPLease: "renueva en 7 h 48 min", FirstSeenMs: seenDaysAgo(290), LastSeenMs: demoSeenBaseMs,
  301. Traffic24hRx: "54 GB", Traffic24hTx: "1,2 GB", Adguard: boolp(true), Group: "tv"},
  302. {ID: "pixel-8-pro", Name: "Pixel 8 Pro", Type: "movil", Manufacturer: "Google",
  303. IP: "192.168.8.45", MAC: "F2:6D:19:A8:44:C2", RouterID: "flint2", Band: "5 GHz",
  304. SignalDbm: iptr(-41), TrafficMbps: 6.2, Online: true,
  305. Sparkline: []float64{3, 4, 5, 7, 6, 8, 6, 5, 7, 6, 6, 6},
  306. Hostname: "pixel-8-pro", DHCPLease: "renueva en 9 h 12 min", FirstSeenMs: seenDaysAgo(214), LastSeenMs: demoSeenBaseMs,
  307. Traffic24hRx: "4,2 GB", Traffic24hTx: "310 MB", Adguard: boolp(true), Group: "moviles"},
  308. {ID: "macbook-air", Name: "MacBook Air", Type: "portatil", Manufacturer: "Apple",
  309. IP: "192.168.8.23", MAC: "3C:22:FB:71:9E:05", RouterID: "estudio", Band: "5 GHz",
  310. SignalDbm: iptr(-45), TrafficMbps: 4.8, Online: true,
  311. Sparkline: []float64{2, 3, 4, 5, 5, 6, 5, 4, 5, 5, 5, 5},
  312. Hostname: "macbook-air-de-ana", DHCPLease: "renueva en 5 h 31 min", FirstSeenMs: seenDaysAgo(260), LastSeenMs: demoSeenBaseMs,
  313. Traffic24hRx: "18 GB", Traffic24hTx: "2,2 GB", Adguard: boolp(true), Group: "ordenadores"},
  314. {ID: "ps5", Name: "PS5", Type: "consola", Manufacturer: "Sony",
  315. IP: "192.168.8.31", MAC: "78:C8:81:0A:6B:D4", RouterID: "living", Band: "cable",
  316. SignalDbm: nil, TrafficMbps: 12.7, Online: true, Port: "lan1",
  317. Sparkline: []float64{4, 6, 8, 10, 12, 14, 13, 12, 13, 12, 13, 13},
  318. Hostname: "ps5-salon", DHCPLease: "IP fija (reserva)", FirstSeenMs: seenDaysAgo(300), LastSeenMs: demoSeenBaseMs,
  319. Traffic24hRx: "92 GB", Traffic24hTx: "4,8 GB", Adguard: boolp(true), Group: "tv"},
  320. {ID: "robot-aspirador", Name: "Robot aspirador", Type: "iot", Manufacturer: "Roborock",
  321. IP: "192.168.8.61", MAC: "B0:4A:39:2E:77:10", RouterID: "patio", Band: "2.4 GHz",
  322. SignalDbm: iptr(-67), TrafficMbps: 0.02, Online: true,
  323. Sparkline: []float64{0.01, 0.02, 0.02, 0.03, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02},
  324. Hostname: "roborock-s8", DHCPLease: "renueva en 10 h 2 min", FirstSeenMs: seenDaysAgo(180), LastSeenMs: demoSeenBaseMs,
  325. Traffic24hRx: "340 MB", Traffic24hTx: "28 MB", Adguard: boolp(true), Group: "iot"},
  326. {ID: "camara-porche", Name: "Cámara porche", Type: "camara", Manufacturer: "Reolink",
  327. IP: "192.168.8.71", MAC: "EC:71:DB:44:12:8A", RouterID: "patio", Band: "2.4 GHz",
  328. SignalDbm: iptr(-72), TrafficMbps: 1.1, Online: true,
  329. Sparkline: []float64{1, 1.1, 1.1, 1.2, 1.1, 1, 1.1, 1.1, 1.2, 1.1, 1.1, 1.1},
  330. Hostname: "reolink-porche", DHCPLease: "renueva en 3 h 57 min", FirstSeenMs: seenDaysAgo(150), LastSeenMs: demoSeenBaseMs,
  331. Traffic24hRx: "11 GB", Traffic24hTx: "640 MB", Adguard: boolp(true), Group: "iot"},
  332. {ID: "nest-mini", Name: "Nest Mini", Type: "altavoz", Manufacturer: "Google",
  333. IP: "192.168.8.52", MAC: "1A:2B:3C:4D:5E:6F", RouterID: "estudio", Band: "2.4 GHz",
  334. SignalDbm: iptr(-55), TrafficMbps: 0.4, Online: true,
  335. Sparkline: []float64{0.3, 0.4, 0.4, 0.5, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4},
  336. Hostname: "nest-mini-estudio", DHCPLease: "renueva en 8 h 20 min", FirstSeenMs: seenDaysAgo(240), LastSeenMs: demoSeenBaseMs,
  337. Traffic24hRx: "1,4 GB", Traffic24hTx: "88 MB", Adguard: boolp(true), Group: "iot"},
  338. {ID: "nas-synology", Name: "NAS Synology", Type: "servidor", Manufacturer: "Synology",
  339. IP: "192.168.8.10", MAC: "00:11:32:9C:51:B7", RouterID: "flint2", Band: "cable",
  340. SignalDbm: nil, TrafficMbps: 2.3, Online: true, Port: "lan4",
  341. Sparkline: []float64{1, 1.5, 2, 2.5, 3, 2.8, 2.4, 2.2, 2.3, 2.3, 2.3, 2.3},
  342. Hostname: "diskstation", DHCPLease: "IP fija (reserva)", FirstSeenMs: seenDaysAgo(320), LastSeenMs: demoSeenBaseMs,
  343. Traffic24hRx: "96 GB", Traffic24hTx: "1,1 TB", Adguard: boolp(true), Group: "red"},
  344. {ID: "galaxy-tab-s9", Name: "Galaxy Tab S9", Type: "tablet", Manufacturer: "Samsung",
  345. IP: "192.168.8.48", MAC: "D6:91:2F:07:B3:55", RouterID: "living", Band: "5 GHz",
  346. SignalDbm: iptr(-50), TrafficMbps: 1.8, Online: true, IsNew: true,
  347. Sparkline: []float64{0, 0, 0, 0, 0, 0, 0, 0, 0.5, 1.2, 1.6, 1.8},
  348. Hostname: "galaxy-tab-s9", DHCPLease: "renueva en 11 h 5 min", FirstSeenMs: seenDaysAgo(0), LastSeenMs: demoSeenBaseMs,
  349. Traffic24hRx: "640 MB", Traffic24hTx: "48 MB", Adguard: boolp(true), Group: "moviles", NewThisWeek: true},
  350. }
  351. }
  352. // additionalDevices: ADDITIONAL (flint2) + LIVING + ESTUDIO + PATIO.
  353. func additionalDevices() []Device {
  354. out := []Device{
  355. // —— Gateway (flint2) ——
  356. withDetails(devExtra(Device{ID: "iphone-ana", Name: "iPhone de Ana", Type: "movil", Manufacturer: "Apple",
  357. IP: "192.168.8.44", MAC: "F4:D4:88:19:C2:71", RouterID: "flint2", Band: "5 GHz",
  358. SignalDbm: iptr(-46), TrafficMbps: 2.1, Online: true}, 11, 0),
  359. "iphone-de-ana", "renueva en 6 h 40 min", 190, "2,8 GB", "240 MB", true, "moviles", ""),
  360. withDetails(devExtra(Device{ID: "macbook-pro", Name: "MacBook Pro de Marc", Type: "portatil", Manufacturer: "Apple",
  361. IP: "192.168.8.26", MAC: "F0:18:98:5A:11:E9", RouterID: "flint2", Band: "5 GHz",
  362. SignalDbm: iptr(-44), TrafficMbps: 8.6, Online: true}, 12, 0),
  363. "macbook-pro-marc", "renueva en 4 h 16 min", 230, "12,4 GB", "1,9 GB", true, "ordenadores", ""),
  364. withDetails(devExtra(Device{ID: "pc-sobremesa", Name: "PC de sobremesa", Type: "ordenador", Manufacturer: "ASUSTeK",
  365. IP: "192.168.8.11", MAC: "04:D4:C4:8B:30:A7", RouterID: "flint2", Band: "cable",
  366. SignalDbm: nil, TrafficMbps: 21.3, Online: true, AttachTo: "dist-flint2-lan3"}, 13, 0),
  367. "desktop-8f2k1", "IP fija (reserva)", 310, "84 GB", "6,2 GB", true, "ordenadores", ""),
  368. withDetails(devExtra(Device{ID: "raspberry-pi", Name: "Raspberry Pi 4", Type: "servidor", Manufacturer: "Raspberry Pi",
  369. IP: "192.168.8.12", MAC: "DC:A6:32:4F:77:02", RouterID: "flint2", Band: "cable",
  370. SignalDbm: nil, TrafficMbps: 0.8, Online: true, AttachTo: "dist-flint2-lan3"}, 14, 0),
  371. "raspberrypi", "IP fija (reserva)", 320, "3,4 GB", "890 MB", true, "red", ""),
  372. // NOTA (SPEC-CANON D1): el switch gestionado GS308E (Salón lan3)
  373. // vuelve a ser Device — ver topologyDevices, junto a sus clientes —
  374. // ADEMÁS de seguir siendo el DistributionNode "managed"
  375. // dist-living-lan3. La app excluye su chip del mapa cruzando
  376. // Device.MAC con DistributionNode.Mac.
  377. withDetails(devExtra(Device{ID: "timbre-nest", Name: "Timbre Nest", Type: "camara", Manufacturer: "Google",
  378. IP: "192.168.8.72", MAC: "F4:F5:D8:66:01:B8", RouterID: "flint2", Band: "2.4 GHz",
  379. SignalDbm: iptr(-58), TrafficMbps: 0.6, Online: true}, 16, 0),
  380. "nest-doorbell", "renueva en 9 h 44 min", 170, "1,2 GB", "140 MB", true, "iot", ""),
  381. withDetails(devExtra(Device{ID: "enchufe-lavadora", Name: "Enchufe lavadora", Type: "iot", Manufacturer: "TP-Link",
  382. IP: "192.168.8.81", MAC: "50:C7:BF:22:E1:9C", RouterID: "flint2", Band: "2.4 GHz",
  383. SignalDbm: iptr(-62), TrafficMbps: 0.01, Online: true}, 17, 0.02),
  384. "tapo-p110-lavadora", "renueva en 12 h 0 min", 140, "8 MB", "2 MB", false, "iot", ""),
  385. withDetails(devExtra(Device{ID: "pixel-7", Name: "Pixel 7", Type: "movil", Manufacturer: "Google",
  386. IP: "192.168.8.46", MAC: "3C:5A:B4:08:D7:5E", RouterID: "flint2", Band: "5 GHz",
  387. SignalDbm: iptr(-49), TrafficMbps: 1.4, Online: true}, 18, 0),
  388. "pixel-7", "renueva en 7 h 3 min", 205, "1,9 GB", "180 MB", true, "moviles", ""),
  389. // SPEC-CANON D3: la identidad vieja wifi/offline de impresora-hp se
  390. // elimina — la única es la cableada al switch inferido
  391. // (topologyDevices, attachTo dist-flint2-lan3).
  392. withDetails(devExtra(Device{ID: "ipad-air", Name: "iPad Air", Type: "tablet", Manufacturer: "Apple",
  393. IP: "192.168.8.47", MAC: "8C:85:90:2F:B4:11", RouterID: "flint2", Band: "5 GHz",
  394. SignalDbm: iptr(-54), TrafficMbps: 0, Online: false}, 1, 0),
  395. "ipad-air", "Expirado", 260, "6,4 GB", "520 MB", true, "moviles", ""),
  396. withDetails(devExtra(Device{ID: "portatil-trabajo", Name: "Portátil trabajo", Type: "portatil", Manufacturer: "Lenovo",
  397. IP: "192.168.8.27", MAC: "54:EE:75:9A:03:F1", RouterID: "flint2", Band: "5 GHz",
  398. SignalDbm: iptr(-50), TrafficMbps: 0, Online: false}, 1, 0),
  399. "thinkpad-t14", "Expirado", 160, "812 MB", "121 MB", true, "ordenadores", ""),
  400. withDetails(devExtra(Device{ID: "kindle", Name: "Kindle Paperwhite", Type: "desconocido", Manufacturer: "Amazon",
  401. IP: "192.168.8.49", MAC: "44:65:0D:71:28:C3", RouterID: "flint2", Band: "2.4 GHz",
  402. SignalDbm: iptr(-58), TrafficMbps: 0, Online: false}, 1, 0),
  403. "kindle-paperwhite", "Expirado", 220, "220 MB", "8 MB", true, "otros", "BookOpen"),
  404. // —— Salón (living) ——
  405. bulb(1, "Bombilla salón 1", "192.168.8.90", "CC:86:EC:10:04:21", -58),
  406. bulb(2, "Bombilla salón 2", "192.168.8.91", "CC:86:EC:10:04:22", -59),
  407. bulb(3, "Bombilla lámpara pie", "192.168.8.92", "CC:86:EC:10:04:23", -61),
  408. bulb(4, "Bombilla entrada", "192.168.8.93", "CC:86:EC:10:04:24", -64),
  409. bulb(5, "Bombilla pasillo", "192.168.8.94", "CC:86:EC:10:04:25", -66),
  410. bulb(6, "Bombilla cocina", "192.168.8.95", "CC:86:EC:10:04:26", -60),
  411. withDetails(devExtra(Device{ID: "chromecast", Name: "Chromecast HD", Type: "tv", Manufacturer: "Google",
  412. IP: "192.168.8.36", MAC: "54:60:09:E3:5B:0A", RouterID: "living", Band: "5 GHz",
  413. SignalDbm: iptr(-54), TrafficMbps: 3.9, Online: true}, 21, 0),
  414. "chromecast-hd", "renueva en 6 h 12 min", 200, "21 GB", "380 MB", true, "tv", ""),
  415. withDetails(devExtra(Device{ID: "homepod-mini", Name: "HomePod mini", Type: "altavoz", Manufacturer: "Apple",
  416. IP: "192.168.8.53", MAC: "F0:D1:A9:3E:77:5C", RouterID: "living", Band: "5 GHz",
  417. SignalDbm: iptr(-47), TrafficMbps: 0.3, Online: true}, 22, 0),
  418. "homepod-mini", "renueva en 10 h 41 min", 190, "2,2 GB", "96 MB", true, "iot", ""),
  419. withDetails(devExtra(Device{ID: "galaxy-s23", Name: "Galaxy S23", Type: "movil", Manufacturer: "Samsung",
  420. IP: "192.168.8.42", MAC: "5C:0A:5B:88:1D:E4", RouterID: "living", Band: "5 GHz",
  421. SignalDbm: iptr(-51), TrafficMbps: 0.9, Online: true}, 23, 0),
  422. "galaxy-s23", "renueva en 8 h 55 min", 175, "3,2 GB", "290 MB", true, "moviles", ""),
  423. withDetails(devExtra(Device{ID: "echo-dot", Name: "Echo Dot", Type: "altavoz", Manufacturer: "Amazon",
  424. IP: "192.168.8.54", MAC: "74:C2:46:19:F0:6B", RouterID: "living", Band: "2.4 GHz",
  425. SignalDbm: iptr(-56), TrafficMbps: 0.2, Online: true}, 24, 0),
  426. "echo-dot-cocina", "renueva en 11 h 18 min", 210, "1,1 GB", "74 MB", true, "iot", ""),
  427. withDetails(devExtra(Device{ID: "nintendo-switch", Name: "Nintendo Switch", Type: "consola", Manufacturer: "Nintendo",
  428. IP: "192.168.8.33", MAC: "58:BD:A3:4C:E2:09", RouterID: "living", Band: "5 GHz",
  429. SignalDbm: iptr(-53), TrafficMbps: 0.1, Online: true}, 25, 0.3),
  430. "switch-oled", "renueva en 5 h 47 min", 240, "8,6 GB", "310 MB", true, "tv", ""),
  431. withDetails(devExtra(Device{ID: "portatil-invitado", Name: "Portátil invitado", Type: "portatil", Manufacturer: "",
  432. IP: "192.168.8.29", MAC: "A2:7E:9C:41:0B:6D", RouterID: "living", Band: "5 GHz",
  433. SignalDbm: iptr(-58), TrafficMbps: 0.7, Online: true, IsNew: true}, 26, 0),
  434. "unknown-7f2a", "renueva en 2 h 9 min", 0, "480 MB", "62 MB", false, "ordenadores", ""),
  435. // SPEC-CANON D3: la identidad vieja wifi/offline de xbox-series-s se
  436. // elimina — la única es la cableada al GS308E (topologyDevices,
  437. // attachTo dist-living-lan3).
  438. withDetails(devExtra(Device{ID: "portatil-antiguo", Name: "Portátil antiguo", Type: "portatil", Manufacturer: "HP",
  439. IP: "192.168.8.28", MAC: "3C:52:82:5D:90:17", RouterID: "living", Band: "2.4 GHz",
  440. SignalDbm: iptr(-62), TrafficMbps: 0, Online: false}, 1, 0),
  441. "hp-pavilion-15", "Expirado", 300, "0 MB", "0 MB", true, "ordenadores", ""),
  442. // —— Estudio ——
  443. withDetails(devExtra(Device{ID: "mac-mini", Name: "Mac mini", Type: "ordenador", Manufacturer: "Apple",
  444. IP: "192.168.8.22", MAC: "A4:83:E7:66:2C:98", RouterID: "estudio", Band: "cable",
  445. SignalDbm: nil, TrafficMbps: 1.9, Online: true}, 31, 0),
  446. "mac-mini", "IP fija (reserva)", 280, "44 GB", "5,6 GB", true, "ordenadores", ""),
  447. withDetails(devExtra(Device{ID: "enchufe-ventilador", Name: "Enchufe ventilador", Type: "iot", Manufacturer: "TP-Link",
  448. IP: "192.168.8.82", MAC: "9C:53:22:B1:4E:70", RouterID: "estudio", Band: "2.4 GHz",
  449. SignalDbm: iptr(-59), TrafficMbps: 0.01, Online: true}, 32, 0.02),
  450. "tapo-p110-ventilador", "renueva en 12 h 0 min", 120, "7 MB", "2 MB", true, "iot", ""),
  451. withDetails(devExtra(Device{ID: "ipad-pro", Name: "iPad Pro", Type: "tablet", Manufacturer: "Apple",
  452. IP: "192.168.8.51", MAC: "F0:18:98:91:5A:2B", RouterID: "estudio", Band: "5 GHz",
  453. SignalDbm: iptr(-49), TrafficMbps: 0.8, Online: true}, 33, 0),
  454. "ipad-pro", "renueva en 9 h 26 min", 160, "5,1 GB", "390 MB", true, "moviles", ""),
  455. withDetails(devExtra(Device{ID: "hue-hub", Name: "Hub Philips Hue", Type: "iot", Manufacturer: "Signify",
  456. IP: "192.168.8.15", MAC: "00:17:88:2A:91:CE", RouterID: "estudio", Band: "cable",
  457. SignalDbm: nil, TrafficMbps: 0.02, Online: true}, 34, 0.04),
  458. "philips-hue-bridge", "IP fija (reserva)", 280, "96 MB", "22 MB", false, "iot", ""),
  459. withDetails(devExtra(Device{ID: "sonos-one", Name: "Sonos One", Type: "altavoz", Manufacturer: "Sonos",
  460. IP: "192.168.8.55", MAC: "48:A6:B8:14:72:E0", RouterID: "estudio", Band: "2.4 GHz",
  461. SignalDbm: iptr(-57), TrafficMbps: 0.5, Online: true}, 35, 0),
  462. "sonos-one-estudio", "renueva en 10 h 4 min", 195, "3,8 GB", "110 MB", true, "iot", ""),
  463. withDetails(devExtra(Device{ID: "iphone-trabajo", Name: "iPhone de trabajo", Type: "movil", Manufacturer: "Apple",
  464. IP: "192.168.8.50", MAC: "8C:85:90:47:C1:93", RouterID: "estudio", Band: "5 GHz",
  465. SignalDbm: iptr(-47), TrafficMbps: 0.3, Online: true, IsNew: true}, 36, 0),
  466. "iphone-15-pro-work", "renueva en 3 h 38 min", 0, "320 MB", "41 MB", true, "moviles", ""),
  467. withDetails(devExtra(Device{ID: "macbook-viejo", Name: "MacBook viejo", Type: "portatil", Manufacturer: "Apple",
  468. IP: "192.168.8.25", MAC: "3C:22:FB:0E:66:A1", RouterID: "estudio", Band: "2.4 GHz",
  469. SignalDbm: iptr(-60), TrafficMbps: 0, Online: false}, 1, 0),
  470. "macbook-pro-2015", "Expirado", 320, "0 MB", "0 MB", true, "ordenadores", ""),
  471. // —— Patio ——
  472. withDetails(devExtra(Device{ID: "camara-jardin", Name: "Cámara jardín", Type: "camara", Manufacturer: "Reolink",
  473. IP: "192.168.8.73", MAC: "EC:71:DB:44:12:9B", RouterID: "patio", Band: "2.4 GHz",
  474. SignalDbm: iptr(-74), TrafficMbps: 1.4, Online: true}, 41, 0),
  475. "reolink-jardin", "renueva en 8 h 49 min", 4, "14 GB", "820 MB", true, "iot", ""),
  476. withDetails(devExtra(Device{ID: "sensor-riego", Name: "Sensor de riego", Type: "iot", Manufacturer: "Tuya",
  477. IP: "192.168.8.89", MAC: "D8:1F:12:5B:08:44", RouterID: "patio", Band: "2.4 GHz",
  478. SignalDbm: iptr(-71), TrafficMbps: 0.01, Online: true}, 42, 0.02),
  479. "tuya-riego-01", "renueva en 12 h 0 min", 5, "2 MB", "1 MB", false, "iot", ""),
  480. withDetails(devExtra(Device{ID: "enchufe-calefactor", Name: "Enchufe calefactor", Type: "iot", Manufacturer: "TP-Link",
  481. IP: "192.168.8.80", MAC: "50:C7:BF:31:7A:05", RouterID: "patio", Band: "2.4 GHz",
  482. SignalDbm: iptr(-75), TrafficMbps: 0.02, Online: true}, 43, 0.03),
  483. "tapo-p110-calefactor", "renueva en 12 h 0 min", 96, "6 MB", "2 MB", true, "iot", ""),
  484. withDetails(devExtra(Device{ID: "camara-garaje", Name: "Cámara garaje", Type: "camara", Manufacturer: "Reolink",
  485. IP: "192.168.8.74", MAC: "EC:71:DB:44:13:02", RouterID: "patio", Band: "2.4 GHz",
  486. SignalDbm: iptr(-78), TrafficMbps: 0, Online: false}, 1, 0),
  487. "reolink-garaje", "Expirado", 130, "0 MB", "0 MB", false, "iot", ""),
  488. }
  489. // newThisWeek (queda fuera de CANON_DETAILS en el JS)
  490. for i := range out {
  491. switch out[i].ID {
  492. case "portatil-invitado", "iphone-trabajo", "camara-jardin", "sensor-riego":
  493. out[i].NewThisWeek = true
  494. }
  495. }
  496. return out
  497. }
  498. // demoSeenBaseMs: base fija para los first/last seen del dataset demo
  499. // (#954). El canon exige epochs deterministas; la app formatea el relativo
  500. // ("hace N días") en render con el locale del usuario, así que el texto
  501. // deriva despacio con el tiempo, que es lo esperado en una demo.
  502. const demoSeenBaseMs = int64(1788220800000) // 2026-09-01 00:00:00 UTC
  503. // seenDaysAgo devuelve el epoch ms de hace N días respecto a la base demo.
  504. func seenDaysAgo(days int) int64 { return demoSeenBaseMs - int64(days)*86400000 }
  505. // withDetails fusiona los literales de detalle (segundo objeto del spread JS).
  506. // firstSeenDays son los días desde la base demo (#954); el last seen demo es
  507. // la propia base (todos los clientes del canon están online).
  508. func withDetails(d Device, hostname, lease string, firstSeenDays int, rx, tx string, adguard bool, group, icon string) Device {
  509. d.Hostname, d.DHCPLease = hostname, lease
  510. d.FirstSeenMs, d.LastSeenMs = seenDaysAgo(firstSeenDays), demoSeenBaseMs
  511. d.Traffic24hRx, d.Traffic24hTx = rx, tx
  512. d.Adguard, d.Group, d.IconOverride = &adguard, group, icon
  513. return d
  514. }
  515. // canonAllDevices: los 65 clientes (canon expandido + adicionales + fixtures
  516. // de topología v5: hipervisor con CTs, clientes tras switch inferido FDB y
  517. // tras el switch gestionado — espejo del mock front app/src/data/mock.ts).
  518. // SPEC-CANON D1/D3: el GS308E vuelve a ser Device (además del distnode
  519. // managed) y xbox-series-s/impresora-hp tienen UNA sola identidad.
  520. func canonAllDevices() []Device {
  521. out := canonDevices()
  522. out = append(out, additionalDevices()...)
  523. out = append(out, topologyDevices()...)
  524. return out
  525. }
  526. // topologyDevices: fixtures NUEVAS de topología v5 (mockup aprobado
  527. // 2-Ago-2026). Los clientes preexistentes (pc-sobremesa, raspberry-pi) se
  528. // enriquecen in situ en additionalDevices — no se duplican. SPEC-CANON D1:
  529. // el GS308E existe como Device (badge "Switch gestionado", con Lldp,
  530. // attachTo al router Salón y port de su uplink) Y como DistributionNode
  531. // managed dist-living-lan3; la app no renderiza su chip cruzando MACs.
  532. func topologyDevices() []Device {
  533. out := []Device{
  534. // Switch gestionado Netgear GS308E (Salón lan3), identificado por
  535. // LLDP. Device + nodo managed a la vez (SPEC-CANON D1): attachTo al
  536. // router y port de uplink — NUNCA cuelga de su propio nodo (D2).
  537. withDetails(devExtra(Device{ID: "switch-netgear", Name: "Switch GS308E", Type: "switch", Manufacturer: "Netgear",
  538. IP: "192.168.8.13", MAC: "28:C6:8E:1D:90:44", RouterID: "living", Band: "cable",
  539. SignalDbm: nil, TrafficMbps: 0.02, Online: true, AttachTo: "living", Port: "lan3",
  540. Infra: "managed-switch",
  541. Lldp: &LldpInfo{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge5"}}, 15, 0.04),
  542. "gs308e", "IP fija (reserva)", 300, "64 MB", "12 MB", false, "red", "Network"),
  543. // 3 clientes detrás del switch gestionado identificado por LLDP
  544. // (nodo managed dist-living-lan3, Salón)
  545. withDetails(Device{ID: "xbox-series-s", Name: "Xbox Series S", Type: "consola", Manufacturer: "Microsoft",
  546. IP: "192.168.8.35", MAC: "7C:ED:8D:4A:11:22", RouterID: "living", Band: "cable",
  547. SignalDbm: nil, TrafficMbps: 9.8, Online: true, AttachTo: "dist-living-lan3",
  548. Sparkline: []float64{3, 5, 7, 9, 11, 12, 10, 9, 10, 9, 10, 9.8}},
  549. "xbox-series-s", "renueva en 4 h 12 min", 140, "31 GB", "1,9 GB", true, "tv", ""),
  550. withDetails(Device{ID: "apple-tv-4k", Name: "Apple TV 4K", Type: "tv", Manufacturer: "Apple",
  551. IP: "192.168.8.36", MAC: "F0:18:98:2B:33:44", RouterID: "living", Band: "cable",
  552. SignalDbm: nil, TrafficMbps: 15.2, Online: true, AttachTo: "dist-living-lan3",
  553. Sparkline: []float64{6, 8, 10, 12, 14, 16, 15, 14, 15, 15, 15, 15.2}},
  554. "apple-tv-4k", "renueva en 6 h 3 min", 210, "88 GB", "3,4 GB", true, "tv", ""),
  555. withDetails(Device{ID: "receptor-denon", Name: "Receptor Denon", Type: "altavoz", Manufacturer: "Denon",
  556. IP: "192.168.8.37", MAC: "00:05:CD:55:66:77", RouterID: "living", Band: "cable",
  557. SignalDbm: nil, TrafficMbps: 0.6, Online: true, AttachTo: "dist-living-lan3",
  558. 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}},
  559. "denon-avr", "IP fija (reserva)", 320, "640 MB", "42 MB", true, "iot", ""),
  560. // Hipervisor Proxmox (gateway lan5, 2.5G — SPEC-CANON D4); sus 10 CTs
  561. // se anidan (OUI BC:24:11)
  562. withDetails(Device{ID: "pve", Name: "Proxmox pve", Type: "servidor", Manufacturer: "Supermicro",
  563. IP: "192.168.8.5", MAC: "3C:52:82:10:20:30", RouterID: "flint2", Band: "cable",
  564. SignalDbm: nil, TrafficMbps: 12.3, Online: true, Port: "lan5", Infra: "hypervisor", SpeedMbps: 2500,
  565. Sparkline: []float64{8, 9, 10, 11, 12, 13, 12, 12, 12, 12, 12, 12.3}},
  566. "pve", "IP fija (reserva)", 400, "1,2 TB", "96 GB", true, "red", ""),
  567. }
  568. cts := []struct {
  569. id, name, typ, ip string
  570. mbps float64
  571. }{
  572. {"ct-pihole", "Pi-hole", "servidor", "192.168.8.41", 6.1},
  573. {"ct-home-assistant", "Home Assistant", "iot", "192.168.8.42", 4.2},
  574. {"ct-nextcloud", "Nextcloud", "servidor", "192.168.8.43", 7.8},
  575. {"ct-jellyfin", "Jellyfin", "servidor", "192.168.8.44", 9.4},
  576. {"ct-immich", "Immich", "servidor", "192.168.8.45", 3.3},
  577. {"ct-gitea", "Gitea", "servidor", "192.168.8.46", 1.2},
  578. {"ct-uptime-kuma", "Uptime Kuma", "iot", "192.168.8.47", 0.4},
  579. {"ct-adguard-sync", "AdGuard sync", "servidor", "192.168.8.48", 0.8},
  580. {"ct-postgres", "Postgres", "servidor", "192.168.8.49", 2.1},
  581. {"ct-redis", "Redis", "servidor", "192.168.8.50", 0.9},
  582. }
  583. for i, c := range cts {
  584. mbps := c.mbps
  585. sp := make([]float64, 12)
  586. for j := range sp {
  587. sp[j] = max(0.1, mbps-2+float64((i+j)%5))
  588. }
  589. out = append(out, withDetails(Device{
  590. ID: c.id, Name: c.name, Type: c.typ, Manufacturer: "Proxmox VE (CT)",
  591. IP: c.ip, MAC: fmt.Sprintf("BC:24:11:00:2%d:%02X", i, 0x10+i), RouterID: "flint2", Band: "cable",
  592. SignalDbm: nil, TrafficMbps: mbps, Online: true, AttachTo: "pve", Infra: "ct", Sparkline: sp},
  593. c.id, "renueva en 3 h 10 min", 90, "1,1 GB", "88 MB", true, "red", ""))
  594. }
  595. // Tras el switch/bridge inferido (gateway lan3, OUI heterogéneo, sin IP).
  596. // pc-sobremesa y raspberry-pi ya existen (enriquecidos con AttachTo en
  597. // additionalDevices): aquí solo los 6 nuevos.
  598. behind := []struct {
  599. id, name, typ, man, mac, ip string
  600. mbps float64
  601. }{
  602. {"tv-salon-cable", "TV Salón (cable)", "tv", "Samsung", "8C:EA:48:AA:02:02", "192.168.8.61", 24.4},
  603. {"impresora-hp", "Impresora HP", "iot", "HP", "3C:D9:2B:AA:03:03", "192.168.8.62", 0.1},
  604. {"xbox-one", "Xbox One", "consola", "Microsoft", "7C:ED:8D:AA:05:05", "192.168.8.64", 4.2},
  605. {"receptor-av", "Receptor AV", "altavoz", "Denon", "00:05:CD:AA:06:06", "192.168.8.65", 0.3},
  606. {"deco-orange", "Deco Orange", "tv", "Sagemcom", "48:83:B4:AA:07:07", "192.168.8.66", 1.1},
  607. {"pc-invitado", "PC invitado", "ordenador", "—", "A2:F4:11:AA:08:08", "192.168.8.67", 0.8},
  608. }
  609. for i, b := range behind {
  610. mbps := b.mbps
  611. sp := make([]float64, 12)
  612. for j := range sp {
  613. sp[j] = max(0.05, mbps-1.5+float64((i+j)%4)*0.5)
  614. }
  615. grp := "otros"
  616. switch b.typ {
  617. case "ordenador":
  618. grp = "ordenadores"
  619. case "tv":
  620. grp = "tv"
  621. case "iot":
  622. grp = "iot"
  623. case "altavoz":
  624. grp = "iot"
  625. }
  626. icon := ""
  627. if b.id == "impresora-hp" {
  628. icon = "Printer" // paridad con el mock viejo (devices-data.ts)
  629. }
  630. out = append(out, withDetails(Device{
  631. ID: b.id, Name: b.name, Type: b.typ, Manufacturer: b.man,
  632. IP: b.ip, MAC: b.mac, RouterID: "flint2", Band: "cable",
  633. SignalDbm: nil, TrafficMbps: mbps, Online: true, AttachTo: "dist-flint2-lan3", Sparkline: sp},
  634. b.id, "renueva en 5 h 22 min", 60, "2,4 GB", "120 MB", true, grp, icon))
  635. }
  636. return out
  637. }
  638. // canonDistributionNodes: distnodes demo (en live los infiere el colector
  639. // FDB/LLDP). Las DOS historias de switch: fantasma inferido (gateway lan3)
  640. // vs gestionado identificado por LLDP (Salón lan3, el GS308E del mockup con
  641. // sus 3 clientes en abanico). SPEC-CANON D1: el nodo managed lleva Mac
  642. // (chassis-MAC) para que la app excluya el chip del Device del switch.
  643. func canonDistributionNodes() []DistributionNode {
  644. return []DistributionNode{
  645. {ID: "dist-flint2-lan3", Kind: "inferred", RouterID: "flint2", Port: "lan3", MacCount: 8, SpeedMbps: 1000},
  646. {ID: "dist-pve", Kind: "hypervisor", RouterID: "flint2", Port: "lan5", MacCount: 11, HostDeviceID: "pve", Name: "Proxmox pve"},
  647. {ID: "dist-living-lan3", Kind: "managed", RouterID: "living", Port: "lan3", MacCount: 4, SpeedMbps: 1000,
  648. Name: "GS308E", Ip: "192.168.8.13", Mac: "28:C6:8E:1D:90:44",
  649. Lldp: &LldpInfo{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge5"}},
  650. }
  651. }
  652. // boolp: los literales demo fijan adguard explícito (true/false) como en el
  653. // dataset JS; live lo deja nil para omitir el campo.
  654. func boolp(b bool) *bool { return &b }
  655. // ---------------------------------------------------------------------------
  656. // D5 — totales DERIVADOS del dataset (nunca literales escritos a mano)
  657. // ---------------------------------------------------------------------------
  658. // deviceTotalsOf enumera el dataset y deriva deviceTotals: total = IDs
  659. // únicos del dataset reconciliado, online/offline por estado, newToday =
  660. // dispositivos con IsNew.
  661. func deviceTotalsOf(devices []Device) DeviceTotals {
  662. t := DeviceTotals{Total: len(devices)}
  663. for _, d := range devices {
  664. if d.Online {
  665. t.Online++
  666. } else {
  667. t.KnownOffline++
  668. }
  669. if d.IsNew {
  670. t.NewToday++
  671. }
  672. }
  673. return t
  674. }
  675. // onlineClientsOf: recuento real de clientes ONLINE de un router
  676. // (router.clients — SPEC-CANON D5).
  677. func onlineClientsOf(devices []Device, routerID string) int {
  678. n := 0
  679. for _, d := range devices {
  680. if d.RouterID == routerID && d.Online {
  681. n++
  682. }
  683. }
  684. return n
  685. }