|
@@ -1,24 +1,33 @@
|
|
|
/**
|
|
/**
|
|
|
- * NetPulse — Modelo del mapa de topología (topology.md §②).
|
|
|
|
|
|
|
+ * NetPulse — Modelo del mapa de topología (v5, mockup aprobado 2-Ago-2026).
|
|
|
|
|
+ *
|
|
|
* `buildTopologyModel` deriva todo del bundle del DataProvider (mock en demo,
|
|
* `buildTopologyModel` deriva todo del bundle del DataProvider (mock en demo,
|
|
|
- * API en live). Las posiciones del lienzo son fijas por rol: gateway al
|
|
|
|
|
- * centro y hasta 3 APs en las coordenadas canónicas.
|
|
|
|
|
|
|
+ * API en live). Vocabulario visual:
|
|
|
|
|
+ * - Chip por dispositivo: 26px cable (con puerto FDB) / 24px wifi (badge de
|
|
|
|
|
+ * banda; ámbar si señal débil). Badge "LLDP" si el vecino se anuncia.
|
|
|
|
|
+ * - Verde sólido = cable físico (WAN, uplinks cableados, cableados, CTs);
|
|
|
|
|
+ * discontinuo = inalámbrico (uplink wifi ámbar) o túnel (WG violeta).
|
|
|
|
|
+ * - DistributionNode: puerto con varias MACs en el FDB → OUI heterogéneo =
|
|
|
|
|
+ * "Switch o bridge (inferido)" (círculo dashed); OUI de hipervisor =
|
|
|
|
|
+ * host con badge +N y sus CTs/VMs anidados en grid.
|
|
|
|
|
+ * - Túneles WG trazados peer → Internet (el camino físico real es la nube).
|
|
|
|
|
+ * Layout: gateway/APs en coordenadas canónicas; wifi en anillos concéntricos
|
|
|
|
|
+ * con arcos prohibidos (uplink, etiqueta, WAN, abanico cableado); cableados
|
|
|
|
|
+ * en abanicos por hub; CTs en grid bajo el host.
|
|
|
*/
|
|
*/
|
|
|
-import type { Band, Device, Router, WanInfo, WGPeer, WireGuardStats } from '@/data/mock'
|
|
|
|
|
|
|
+import type { Band, Device, DistributionNode, Router, WanInfo, WGPeer, WireGuardStats } from '@/data/mock'
|
|
|
|
|
|
|
|
/** viewBox del lienzo SVG */
|
|
/** viewBox del lienzo SVG */
|
|
|
export const VB_W = 1000
|
|
export const VB_W = 1000
|
|
|
export const VB_H = 680
|
|
export const VB_H = 680
|
|
|
|
|
|
|
|
-export const MAX_CLUSTER_DOTS = 12
|
|
|
|
|
-
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// Tipos
|
|
// Tipos
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export interface RouterNode {
|
|
export interface RouterNode {
|
|
|
kind: 'router'
|
|
kind: 'router'
|
|
|
- id: string // router id
|
|
|
|
|
|
|
+ id: string
|
|
|
router: Router
|
|
router: Router
|
|
|
x: number
|
|
x: number
|
|
|
y: number
|
|
y: number
|
|
@@ -35,44 +44,51 @@ export interface PeerNode {
|
|
|
y: number
|
|
y: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface ClientDot {
|
|
|
|
|
- id: string
|
|
|
|
|
|
|
+/** Chip de un dispositivo cliente (wifi o cableado). */
|
|
|
|
|
+export interface ChipNode {
|
|
|
|
|
+ kind: 'chip'
|
|
|
|
|
+ id: string // device id
|
|
|
|
|
+ device: Device
|
|
|
x: number
|
|
x: number
|
|
|
y: number
|
|
y: number
|
|
|
|
|
+ /** lado del chip en px (26 cable, 24/22 wifi según anillo) */
|
|
|
|
|
+ size: number
|
|
|
|
|
+ wired: boolean
|
|
|
band: Band
|
|
band: Band
|
|
|
weak: boolean
|
|
weak: boolean
|
|
|
- device?: Device
|
|
|
|
|
- /** radio del dot (menor cuantos más clientes) */
|
|
|
|
|
- r?: number
|
|
|
|
|
|
|
+ /** hub del que cuelga: router id | distnode id | device id (host/switch) */
|
|
|
|
|
+ hubId: string
|
|
|
|
|
+ /** CT/VM anidado bajo un hipervisor (grid, sin enlace propio al router) */
|
|
|
|
|
+ isCt: boolean
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface Cluster {
|
|
|
|
|
- id: string // `cluster-${routerId}`
|
|
|
|
|
- routerId: string
|
|
|
|
|
- cx: number
|
|
|
|
|
- cy: number
|
|
|
|
|
- dots: ClientDot[]
|
|
|
|
|
- /** clientes no representados (badge "+N") */
|
|
|
|
|
- extra: number
|
|
|
|
|
|
|
+/** Vista de un DistributionNode kind=inferred (círculo dashed, sin IP). */
|
|
|
|
|
+export interface DistNodeView {
|
|
|
|
|
+ kind: 'dist'
|
|
|
|
|
+ id: string
|
|
|
|
|
+ node: DistributionNode
|
|
|
|
|
+ x: number
|
|
|
|
|
+ y: number
|
|
|
|
|
+ r: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export type TopoLinkKind = 'wan' | 'uplink' | 'cluster' | 'wg'
|
|
|
|
|
|
|
+export type TopoLinkKind = 'wan' | 'uplink' | 'wired' | 'dist' | 'wg'
|
|
|
|
|
|
|
|
export interface TopoLink {
|
|
export interface TopoLink {
|
|
|
id: string
|
|
id: string
|
|
|
kind: TopoLinkKind
|
|
kind: TopoLinkKind
|
|
|
d: string
|
|
d: string
|
|
|
- /** posición de la etiqueta del enlace */
|
|
|
|
|
|
|
+ /** uplink inalámbrico (backhaul wifi): dashed ámbar */
|
|
|
|
|
+ wifi?: boolean
|
|
|
|
|
+ /** posición de la etiqueta del enlace (sin etiqueta si label='') */
|
|
|
lx: number
|
|
lx: number
|
|
|
ly: number
|
|
ly: number
|
|
|
label: string
|
|
label: string
|
|
|
- /** grosor ∝ tráfico (2px base, hasta ~5px) */
|
|
|
|
|
width: number
|
|
width: number
|
|
|
- /** nº de paquetes animados simultáneos (guardrail ≤14 total) */
|
|
|
|
|
|
|
+ /** nº de paquetes animados simultáneos (∝ Mbps; guardrail global ≤60) */
|
|
|
packets: number
|
|
packets: number
|
|
|
/** duración del viaje del paquete (s); menor = más tráfico */
|
|
/** duración del viaje del paquete (s); menor = más tráfico */
|
|
|
packetDur: number
|
|
packetDur: number
|
|
|
- /** nodos extremos (para coordinación hover) */
|
|
|
|
|
from: string
|
|
from: string
|
|
|
to: string
|
|
to: string
|
|
|
}
|
|
}
|
|
@@ -97,6 +113,7 @@ export interface TopologyInput {
|
|
|
devices: Device[]
|
|
devices: Device[]
|
|
|
wan: WanInfo
|
|
wan: WanInfo
|
|
|
wireguard: WireGuardStats
|
|
wireguard: WireGuardStats
|
|
|
|
|
+ distributionNodes?: DistributionNode[]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface TopologyModel {
|
|
export interface TopologyModel {
|
|
@@ -105,7 +122,12 @@ export interface TopologyModel {
|
|
|
routerNodes: RouterNode[]
|
|
routerNodes: RouterNode[]
|
|
|
internetNode: { id: 'internet'; x: number; y: number }
|
|
internetNode: { id: 'internet'; x: number; y: number }
|
|
|
peerNodes: PeerNode[]
|
|
peerNodes: PeerNode[]
|
|
|
- clusters: Cluster[]
|
|
|
|
|
|
|
+ chips: ChipNode[]
|
|
|
|
|
+ distNodes: DistNodeView[]
|
|
|
|
|
+ /** CTs/VMs anidados por host hipervisor (hostId → chips en grid) */
|
|
|
|
|
+ ctsByHost: Map<string, ChipNode[]>
|
|
|
|
|
+ /** nº de CTs por host (badge +N) */
|
|
|
|
|
+ ctCountByHost: Map<string, number>
|
|
|
links: TopoLink[]
|
|
links: TopoLink[]
|
|
|
totalPackets: number
|
|
totalPackets: number
|
|
|
activeLinkCount: number
|
|
activeLinkCount: number
|
|
@@ -141,167 +163,482 @@ export function statusColor(status: Router['status']): string {
|
|
|
return COLOR.ok
|
|
return COLOR.ok
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/** Color del enlace según tipo (verde = cable físico; ámbar = uplink wifi). */
|
|
|
|
|
+export function linkColor(link: Pick<TopoLink, 'kind' | 'wifi'>): string {
|
|
|
|
|
+ if (link.kind === 'wg') return COLOR.tunnel
|
|
|
|
|
+ if (link.kind === 'uplink' && link.wifi) return COLOR.warn
|
|
|
|
|
+ return COLOR.ok
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
-// Coordenadas canónicas del lienzo (gateway centrado + 3 APs + 2 peers VPN)
|
|
|
|
|
|
|
+// Coordenadas canónicas del lienzo (mockup v5: QA de colisiones hecha)
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-const GATEWAY_COORD = { x: 500, y: 246, r: 40, label: { x: 556, y: 240, anchor: 'start' as const } }
|
|
|
|
|
|
|
+const GATEWAY_COORD = { x: 500, y: 250, r: 40, label: { x: 446, y: 312, anchor: 'end' as const } }
|
|
|
const AP_COORDS = [
|
|
const AP_COORDS = [
|
|
|
- { x: 210, y: 452, r: 32, label: { x: 158, y: 446, anchor: 'end' as const } },
|
|
|
|
|
- { x: 500, y: 478, r: 32, label: { x: 546, y: 472, anchor: 'start' as const } },
|
|
|
|
|
- { x: 790, y: 452, r: 32, label: { x: 836, y: 446, anchor: 'start' as const } },
|
|
|
|
|
-]
|
|
|
|
|
-const CLUSTER_COORDS = [
|
|
|
|
|
- { cx: 210, cy: 580 },
|
|
|
|
|
- { cx: 500, cy: 606 },
|
|
|
|
|
- { cx: 790, cy: 580 },
|
|
|
|
|
|
|
+ { x: 195, y: 470, r: 32, label: { x: 124, y: 464, anchor: 'end' as const } },
|
|
|
|
|
+ { x: 500, y: 505, r: 32, label: { x: 554, y: 500, anchor: 'start' as const } },
|
|
|
|
|
+ { x: 805, y: 470, r: 32, label: { x: 858, y: 464, anchor: 'start' as const } },
|
|
|
]
|
|
]
|
|
|
-const GATEWAY_CLUSTER = { cx: 210, cy: 246 }
|
|
|
|
|
|
|
+const INTERNET_COORD = { x: 500, y: 58 }
|
|
|
const PEER_COORDS = [
|
|
const PEER_COORDS = [
|
|
|
- { x: 96, y: 120 },
|
|
|
|
|
- { x: 240, y: 56 },
|
|
|
|
|
|
|
+ { x: 265, y: 26 },
|
|
|
|
|
+ { x: 735, y: 26 },
|
|
|
|
|
+ { x: 140, y: 26 },
|
|
|
|
|
+ { x: 860, y: 26 },
|
|
|
]
|
|
]
|
|
|
|
|
+/** Uplinks canónicos gateway→AP (cúbicas QA-das en el mockup) */
|
|
|
const UPLINK_PATHS = [
|
|
const UPLINK_PATHS = [
|
|
|
- { d: 'M 468 276 C 400 330, 300 380, 224 420', lx: 322, ly: 340, width: 4.5, packets: 3, packetDur: 2.8 },
|
|
|
|
|
- { d: 'M 500 288 C 500 350, 500 390, 500 434', lx: 514, ly: 360, width: 2.5, packets: 2, packetDur: 3.4 },
|
|
|
|
|
- { d: 'M 532 276 C 600 330, 700 380, 776 420', lx: 668, ly: 340, width: 2, packets: 1, packetDur: 4 },
|
|
|
|
|
-]
|
|
|
|
|
-const CLUSTER_PATHS = [
|
|
|
|
|
- 'M 210 492 C 210 516, 210 528, 210 550',
|
|
|
|
|
- 'M 500 518 C 500 542, 500 554, 500 576',
|
|
|
|
|
- 'M 790 492 C 790 516, 790 528, 790 550',
|
|
|
|
|
|
|
+ { d: 'M 464 282 C 390 340, 290 400, 224 440', lx: 292, ly: 366 },
|
|
|
|
|
+ { d: 'M 500 292 C 500 360, 500 420, 500 468', lx: 514, ly: 418 },
|
|
|
|
|
+ { d: 'M 536 282 C 610 340, 710 400, 776 440', lx: 664, ly: 366 },
|
|
|
]
|
|
]
|
|
|
|
|
+/** Túneles WG canónicos peer→Internet */
|
|
|
const WG_PATHS = [
|
|
const WG_PATHS = [
|
|
|
- { d: 'M 120 134 C 240 210, 360 220, 458 236', lx: 268, ly: 200, packetDur: 3 },
|
|
|
|
|
- { d: 'M 264 70 C 360 110, 430 160, 468 210', lx: 356, ly: 122, packetDur: 3.4 },
|
|
|
|
|
|
|
+ { d: 'M 272 44 C 330 82, 410 94, 474 80', dur: 3 },
|
|
|
|
|
+ { d: 'M 728 44 C 670 82, 590 94, 526 80', dur: 3.4 },
|
|
|
|
|
+]
|
|
|
|
|
+/** Anillos wifi (v5: separados de los nodos; chips no "tocan" el router) */
|
|
|
|
|
+const GATEWAY_RINGS = [
|
|
|
|
|
+ { r: 88, cap: 5 },
|
|
|
|
|
+ { r: 118, cap: 8 },
|
|
|
|
|
+]
|
|
|
|
|
+const AP_RINGS = [
|
|
|
|
|
+ { r: 74, cap: 7 },
|
|
|
|
|
+ { r: 108, cap: 13 },
|
|
|
]
|
|
]
|
|
|
|
|
+/** Abanicos cableados: gateway tiene sector este (switch inferido) y oeste */
|
|
|
|
|
+const GW_EAST_FAN: [number, number] = [336, 24] // wrap (a1 < a0)
|
|
|
|
|
+const GW_WEST_FAN: [number, number] = [150, 210]
|
|
|
|
|
+const AP_WIRED_FAN: [number, number] = [50, 130]
|
|
|
|
|
+const DIST_FAN_RADIUS = 82
|
|
|
|
|
+const HUB_FAN_RADIUS = 56
|
|
|
|
|
+const ROUTER_FAN_RADIUS = 134
|
|
|
|
|
+/** Hosts hipervisores del gateway: lejos (su grid de CTs necesita espacio) */
|
|
|
|
|
+const HYPERVISOR_FAN_RADIUS = 300
|
|
|
|
|
+/** Grid de CTs bajo el host hipervisor */
|
|
|
|
|
+const CT_COLS = 5
|
|
|
|
|
+const CT_DX = 42
|
|
|
|
|
+const CT_DY = 38
|
|
|
|
|
+const CT_OFFSET_Y = 56
|
|
|
|
|
+
|
|
|
|
|
+// ---------------------------------------------------------------------------
|
|
|
|
|
+// Utilidades de ángulos y layout (portadas del mockup aprobado)
|
|
|
|
|
+// ---------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+const rad = (d: number) => (d * Math.PI) / 180
|
|
|
|
|
+const norm = (a: number) => ((a % 360) + 360) % 360
|
|
|
|
|
+const angleTo = (x: number, y: number, tx: number, ty: number) => norm((Math.atan2(ty - y, tx - x) * 180) / Math.PI)
|
|
|
|
|
+const pos = (cx: number, cy: number, degA: number, r: number) => ({
|
|
|
|
|
+ x: Math.round((cx + r * Math.cos(rad(degA))) * 10) / 10,
|
|
|
|
|
+ y: Math.round((cy + r * Math.sin(rad(degA))) * 10) / 10,
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+/** Arco [±half] alrededor de `center`, como hasta 2 intervalos sin wrap. */
|
|
|
|
|
+function arcAround(center: number, half: number): [number, number][] {
|
|
|
|
|
+ const s = norm(center - half)
|
|
|
|
|
+ const e = norm(center + half)
|
|
|
|
|
+ return s <= e ? [[s, e]] : [[s, 360], [0, e]]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** arcos libres = [0,360) menos exclusiones (intervalos sin wrap) */
|
|
|
|
|
+function freeArcs(excludes: [number, number][]): [number, number][] {
|
|
|
|
|
+ const ex = excludes
|
|
|
|
|
+ .map(([s, e]): [number, number] => [Math.max(0, s), Math.min(360, e)])
|
|
|
|
|
+ .filter(([s, e]) => e > s)
|
|
|
|
|
+ .sort((a, b) => a[0] - b[0])
|
|
|
|
|
+ const free: [number, number][] = []
|
|
|
|
|
+ let cur = 0
|
|
|
|
|
+ for (const [s, e] of ex) {
|
|
|
|
|
+ if (s > cur) free.push([cur, s])
|
|
|
|
|
+ cur = Math.max(cur, e)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (cur < 360) free.push([cur, 360])
|
|
|
|
|
+ return free
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** reparte items en anillos concéntricos evitando arcos prohibidos */
|
|
|
|
|
+function ringLayout<T extends { x: number; y: number }>(
|
|
|
|
|
+ items: T[],
|
|
|
|
|
+ node: { x: number; y: number },
|
|
|
|
|
+ rings: { r: number; cap: number }[],
|
|
|
|
|
+ excludes: [number, number][],
|
|
|
|
|
+): void {
|
|
|
|
|
+ const free = freeArcs(excludes)
|
|
|
|
|
+ const total = free.reduce((a, [s, e]) => a + (e - s), 0)
|
|
|
|
|
+ if (total <= 0) return
|
|
|
|
|
+ let idx = 0
|
|
|
|
|
+ for (const ring of rings) {
|
|
|
|
|
+ if (idx >= items.length) break
|
|
|
|
|
+ const n = Math.min(ring.cap, items.length - idx)
|
|
|
|
|
+ let placed = 0
|
|
|
|
|
+ for (let ai = 0; ai < free.length && placed < n; ai++) {
|
|
|
|
|
+ const [s, e] = free[ai]
|
|
|
|
|
+ let k = Math.min(Math.round((n * (e - s)) / total), n - placed)
|
|
|
|
|
+ if (ai === free.length - 1) k = n - placed
|
|
|
|
|
+ for (let i = 0; i < k; i++) {
|
|
|
|
|
+ const a = s + ((e - s) * (i + 0.5)) / k
|
|
|
|
|
+ const p = pos(node.x, node.y, a, ring.r)
|
|
|
|
|
+ Object.assign(items[idx++], p)
|
|
|
|
|
+ placed++
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** abanico de items en un arco (soporta wrap: a1 < a0) */
|
|
|
|
|
+function fanLayout<T extends { x: number; y: number }>(
|
|
|
|
|
+ items: T[],
|
|
|
|
|
+ node: { x: number; y: number },
|
|
|
|
|
+ r: number,
|
|
|
|
|
+ a0: number,
|
|
|
|
|
+ a1: number,
|
|
|
|
|
+): void {
|
|
|
|
|
+ if (a1 < a0) a1 += 360
|
|
|
|
|
+ const n = items.length
|
|
|
|
|
+ items.forEach((d, i) => {
|
|
|
|
|
+ const a = a0 + ((a1 - a0) * (n === 1 ? 0.5 : i / (n - 1)))
|
|
|
|
|
+ Object.assign(d, pos(node.x, node.y, norm(a), r))
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** flujo de paquetes ∝ tráfico (mockup: umbrales 35/15/2 Mbps, guardrail 60) */
|
|
|
|
|
+function flowFor(mbps: number): { packets: number; packetDur: number } {
|
|
|
|
|
+ const packets = mbps >= 35 ? 3 : mbps >= 15 ? 2 : mbps >= 2 ? 1 : 0
|
|
|
|
|
+ return { packets, packetDur: Math.max(1.6, 5 - mbps / 12) }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
// Builder
|
|
// Builder
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-export function buildTopologyModel({ routers, devices, wan, wireguard }: TopologyInput): TopologyModel {
|
|
|
|
|
|
|
+export function buildTopologyModel({ routers, devices, wan, wireguard, distributionNodes = [] }: TopologyInput): TopologyModel {
|
|
|
const gateway = routers.find((r) => r.roleBadge === 'Principal') ?? routers[0]
|
|
const gateway = routers.find((r) => r.roleBadge === 'Principal') ?? routers[0]
|
|
|
const aps = routers.filter((r) => r.id !== gateway?.id).slice(0, AP_COORDS.length)
|
|
const aps = routers.filter((r) => r.id !== gateway?.id).slice(0, AP_COORDS.length)
|
|
|
|
|
|
|
|
const gatewayNode: RouterNode | null = gateway
|
|
const gatewayNode: RouterNode | null = gateway
|
|
|
- ? { kind: 'router', id: gateway.id, router: gateway, x: GATEWAY_COORD.x, y: GATEWAY_COORD.y, r: GATEWAY_COORD.r, label: GATEWAY_COORD.label }
|
|
|
|
|
|
|
+ ? { kind: 'router', id: gateway.id, router: gateway, ...GATEWAY_COORD }
|
|
|
: null
|
|
: null
|
|
|
- const apNodes: RouterNode[] = aps.map((router, i) => ({
|
|
|
|
|
- kind: 'router',
|
|
|
|
|
- id: router.id,
|
|
|
|
|
- router,
|
|
|
|
|
- x: AP_COORDS[i].x,
|
|
|
|
|
- y: AP_COORDS[i].y,
|
|
|
|
|
- r: AP_COORDS[i].r,
|
|
|
|
|
- label: AP_COORDS[i].label,
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ const apNodes: RouterNode[] = aps.map((router, i) => ({ kind: 'router', id: router.id, router, ...AP_COORDS[i] }))
|
|
|
const routerNodes: RouterNode[] = gatewayNode ? [gatewayNode, ...apNodes] : apNodes
|
|
const routerNodes: RouterNode[] = gatewayNode ? [gatewayNode, ...apNodes] : apNodes
|
|
|
|
|
+ const routerById = new Map(routerNodes.map((n) => [n.id, n]))
|
|
|
|
|
+
|
|
|
|
|
+ const internetNode = { id: 'internet' as const, ...INTERNET_COORD }
|
|
|
|
|
+
|
|
|
|
|
+ const online = devices.filter((d) => d.online)
|
|
|
|
|
+ const deviceById = new Map(online.map((d) => [d.id, d]))
|
|
|
|
|
+ const distById = new Map(distributionNodes.map((n) => [n.id, n]))
|
|
|
|
|
+ /** hub al que cuelga un dispositivo: attachTo (si existe y resuelve) o su router */
|
|
|
|
|
+ const hubOf = (d: Device): string => {
|
|
|
|
|
+ if (d.attachTo && (routerById.has(d.attachTo) || distById.has(d.attachTo) || deviceById.has(d.attachTo))) {
|
|
|
|
|
+ return d.attachTo
|
|
|
|
|
+ }
|
|
|
|
|
+ return d.routerId
|
|
|
|
|
+ }
|
|
|
|
|
+ const childrenOf = (hubId: string) => online.filter((d) => hubOf(d) === hubId)
|
|
|
|
|
+ const isWired = (d: Device) => d.band === 'cable'
|
|
|
|
|
+
|
|
|
|
|
+ /** Hubs que son dispositivos con hijos propios (switch gestionado, hipervisor) */
|
|
|
|
|
+ const deviceHubs = new Set<string>()
|
|
|
|
|
+ for (const d of online) {
|
|
|
|
|
+ const h = d.attachTo
|
|
|
|
|
+ if (h && deviceById.has(h)) deviceHubs.add(h)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const internetNode = { id: 'internet' as const, x: 500, y: 132 }
|
|
|
|
|
|
|
+ // -- posicionamiento de hubs cableados (distnodes + device-hubs) y anchors --
|
|
|
|
|
+ const distNodes: DistNodeView[] = []
|
|
|
|
|
+ const anchorPos = new Map<string, { x: number; y: number }>() // hubId → pos
|
|
|
|
|
+ const fanArcByRouter = new Map<string, [number, number][]>() // arcos ocupados por cableados (prohibidos para wifi)
|
|
|
|
|
+ /** hosts hipervisores (distnode kind=hypervisor con hostDeviceId) */
|
|
|
|
|
+ const hypervisorHosts = new Set(
|
|
|
|
|
+ distributionNodes.filter((n) => n.kind === 'hypervisor' && n.hostDeviceId).map((n) => n.hostDeviceId!),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ for (const node of routerNodes) {
|
|
|
|
|
+ const isGw = node.id === gatewayNode?.id
|
|
|
|
|
+ // Solo los distnodes inferidos son anchors propios (círculo dashed); el
|
|
|
|
|
+ // hipervisor se posiciona vía su device host (hub), el distnode solo
|
|
|
|
|
+ // aporta metadatos (puerto, macCount).
|
|
|
|
|
+ const dists = distributionNodes.filter((n) => n.routerId === node.id && n.kind === 'inferred')
|
|
|
|
|
+ const directWired = childrenOf(node.id).filter(isWired)
|
|
|
|
|
+ const hubs = directWired.filter((d) => deviceHubs.has(d.id))
|
|
|
|
|
+ const plain = directWired.filter((d) => !deviceHubs.has(d.id))
|
|
|
|
|
+
|
|
|
|
|
+ // Anchors: todo cuelga de abanicos; gateway separa este/oeste
|
|
|
|
|
+ const anchors: { id: string; kind: 'dist' | 'hub' | 'dev'; ref: DistributionNode | Device }[] = [
|
|
|
|
|
+ ...dists.map((n) => ({ id: n.id, kind: 'dist' as const, ref: n })),
|
|
|
|
|
+ ...hubs.map((d) => ({ id: d.id, kind: 'hub' as const, ref: d })),
|
|
|
|
|
+ ...plain.map((d) => ({ id: d.id, kind: 'dev' as const, ref: d })),
|
|
|
|
|
+ ]
|
|
|
|
|
+ if (anchors.length === 0) continue
|
|
|
|
|
+
|
|
|
|
|
+ const placed: { id: string; kind: 'dist' | 'hub' | 'dev'; ref: DistributionNode | Device; x: number; y: number }[] = []
|
|
|
|
|
+ if (isGw) {
|
|
|
|
|
+ // distnodes (switch inferido) al ESTE r134; hosts hipervisores al OESTE
|
|
|
|
|
+ // r300 (su grid de CTs necesita espacio, mockup: pve a ~310px); resto OESTE r134
|
|
|
|
|
+ const east = anchors.filter((a) => a.kind === 'dist')
|
|
|
|
|
+ const farWest = anchors.filter((a) => a.kind === 'hub' && hypervisorHosts.has(a.id))
|
|
|
|
|
+ const west = anchors.filter((a) => a.kind !== 'dist' && !farWest.includes(a))
|
|
|
|
|
+ const eastItems = east.map((a) => ({ ...a, x: 0, y: 0 }))
|
|
|
|
|
+ const farWestItems = farWest.map((a) => ({ ...a, x: 0, y: 0 }))
|
|
|
|
|
+ const westItems = west.map((a) => ({ ...a, x: 0, y: 0 }))
|
|
|
|
|
+ fanLayout(eastItems, node, ROUTER_FAN_RADIUS, GW_EAST_FAN[0], GW_EAST_FAN[1])
|
|
|
|
|
+ fanLayout(farWestItems, node, HYPERVISOR_FAN_RADIUS, 160, 200)
|
|
|
|
|
+ fanLayout(westItems, node, ROUTER_FAN_RADIUS, GW_WEST_FAN[0], GW_WEST_FAN[1])
|
|
|
|
|
+ placed.push(...eastItems, ...farWestItems, ...westItems)
|
|
|
|
|
+ fanArcByRouter.set(node.id, [...arcAround(0, 26), [GW_WEST_FAN[0] - 8, GW_WEST_FAN[1] + 8]])
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const items = anchors.map((a) => ({ ...a, x: 0, y: 0 }))
|
|
|
|
|
+ fanLayout(items, node, ROUTER_FAN_RADIUS, AP_WIRED_FAN[0], AP_WIRED_FAN[1])
|
|
|
|
|
+ placed.push(...items)
|
|
|
|
|
+ fanArcByRouter.set(node.id, [[AP_WIRED_FAN[0] - 8, AP_WIRED_FAN[1] + 8]])
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ for (const p of placed) {
|
|
|
|
|
+ anchorPos.set(p.id, { x: p.x, y: p.y })
|
|
|
|
|
+ if (p.kind === 'dist') {
|
|
|
|
|
+ const dn = p.ref as DistributionNode
|
|
|
|
|
+ distNodes.push({ kind: 'dist', id: dn.id, node: dn, x: p.x, y: p.y, r: 20 })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // -- chips de dispositivos --------------------------------------------------
|
|
|
|
|
+ const chips: ChipNode[] = []
|
|
|
|
|
+ const mkChip = (d: Device, hubId: string, isCt = false): ChipNode => ({
|
|
|
|
|
+ kind: 'chip',
|
|
|
|
|
+ id: d.id,
|
|
|
|
|
+ device: d,
|
|
|
|
|
+ x: 0,
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ size: isWired(d) ? 26 : 24,
|
|
|
|
|
+ wired: isWired(d),
|
|
|
|
|
+ band: d.band,
|
|
|
|
|
+ weak: d.signalDbm != null && d.signalDbm <= -65,
|
|
|
|
|
+ hubId,
|
|
|
|
|
+ isCt,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // wifi: anillos con arcos prohibidos (uplink, etiqueta, WAN, fan cableado)
|
|
|
|
|
+ for (const node of routerNodes) {
|
|
|
|
|
+ const isGw = node.id === gatewayNode?.id
|
|
|
|
|
+ const wifi = childrenOf(node.id).filter((d) => !isWired(d)).map((d) => mkChip(d, node.id))
|
|
|
|
|
+ if (wifi.length === 0) continue
|
|
|
|
|
+ const excludes: [number, number][] = []
|
|
|
|
|
+ if (isGw) {
|
|
|
|
|
+ excludes.push(...arcAround(270, 14)) // WAN hacia Internet
|
|
|
|
|
+ if (gatewayNode) excludes.push(...arcAround(angleTo(gatewayNode.x, gatewayNode.y, gatewayNode.label.x, gatewayNode.label.y), 22))
|
|
|
|
|
+ for (const ap of apNodes) excludes.push(...arcAround(angleTo(node.x, node.y, ap.x, ap.y), 15))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (gatewayNode) excludes.push(...arcAround(angleTo(node.x, node.y, gatewayNode.x, gatewayNode.y), 27))
|
|
|
|
|
+ excludes.push(...arcAround(angleTo(node.x, node.y, node.label.x, node.label.y), 22))
|
|
|
|
|
+ }
|
|
|
|
|
+ excludes.push(...(fanArcByRouter.get(node.id) ?? []))
|
|
|
|
|
+ const baseRings = isGw ? GATEWAY_RINGS : AP_RINGS
|
|
|
|
|
+ // anillos extra si el wifi supera el aforo de los dos primeros
|
|
|
|
|
+ const rings = [...baseRings]
|
|
|
|
|
+ let cap = rings.reduce((a, r) => a + r.cap, 0)
|
|
|
|
|
+ while (cap < wifi.length) {
|
|
|
|
|
+ const last = rings[rings.length - 1]
|
|
|
|
|
+ rings.push({ r: last.r + 30, cap: last.cap + 5 })
|
|
|
|
|
+ cap = rings.reduce((a, r) => a + r.cap, 0)
|
|
|
|
|
+ }
|
|
|
|
|
+ ringLayout(wifi, node, rings, excludes)
|
|
|
|
|
+ // chips algo menores en anillos externos
|
|
|
|
|
+ wifi.forEach((c, i) => {
|
|
|
|
|
+ if (i >= baseRings[0].cap) c.size = 22
|
|
|
|
|
+ })
|
|
|
|
|
+ chips.push(...wifi)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // cableados directos del router: ya tienen anchorPos
|
|
|
|
|
+ for (const node of routerNodes) {
|
|
|
|
|
+ for (const d of childrenOf(node.id).filter(isWired)) {
|
|
|
|
|
+ if (deviceHubs.has(d.id)) continue // el hub se renderiza como chip con hijos
|
|
|
|
|
+ const p = anchorPos.get(d.id)
|
|
|
|
|
+ if (!p) continue
|
|
|
|
|
+ const c = mkChip(d, node.id)
|
|
|
|
|
+ Object.assign(c, p)
|
|
|
|
|
+ chips.push(c)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // hijos de device-hubs (switch gestionado): abanico alrededor del hub
|
|
|
|
|
+ const hubChips: ChipNode[] = []
|
|
|
|
|
+ for (const hubId of deviceHubs) {
|
|
|
|
|
+ const hubDev = deviceById.get(hubId)
|
|
|
|
|
+ if (!hubDev) continue
|
|
|
|
|
+ const parentHub = hubOf(hubDev)
|
|
|
|
|
+ const p = anchorPos.get(hubId)
|
|
|
|
|
+ if (!p) continue
|
|
|
|
|
+ const hc = mkChip(hubDev, parentHub)
|
|
|
|
|
+ Object.assign(hc, p)
|
|
|
|
|
+ hubChips.push(hc)
|
|
|
|
|
+ const kids = childrenOf(hubId).map((d) => mkChip(d, hubId))
|
|
|
|
|
+ const center = angleTo(routerById.get(parentHub)?.x ?? p.x, routerById.get(parentHub)?.y ?? p.y, p.x, p.y)
|
|
|
|
|
+ fanLayout(kids, p, HUB_FAN_RADIUS, center - 45, center + 45)
|
|
|
|
|
+ chips.push(...kids)
|
|
|
|
|
+ }
|
|
|
|
|
+ chips.push(...hubChips)
|
|
|
|
|
+
|
|
|
|
|
+ // hijos de distnodes inferidos: abanico alrededor del círculo dashed
|
|
|
|
|
+ for (const dv of distNodes) {
|
|
|
|
|
+ const kids = childrenOf(dv.id).map((d) => mkChip(d, dv.id))
|
|
|
|
|
+ const rn = routerById.get(dv.node.routerId)
|
|
|
|
|
+ const center = rn ? angleTo(rn.x, rn.y, dv.x, dv.y) : 0
|
|
|
|
|
+ fanLayout(kids, dv, DIST_FAN_RADIUS, center - 68, center + 68)
|
|
|
|
|
+ chips.push(...kids)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // CTs de hipervisores: grid bajo el host (badge +N en el chip del host)
|
|
|
|
|
+ const ctsByHost = new Map<string, ChipNode[]>()
|
|
|
|
|
+ const ctCountByHost = new Map<string, number>()
|
|
|
|
|
+ for (const dn of distributionNodes.filter((n) => n.kind === 'hypervisor' && n.hostDeviceId)) {
|
|
|
|
|
+ const hostId = dn.hostDeviceId!
|
|
|
|
|
+ const hostChip = chips.find((c) => c.id === hostId)
|
|
|
|
|
+ const kids = childrenOf(hostId).map((d) => mkChip(d, hostId, true))
|
|
|
|
|
+ if (!hostChip || kids.length === 0) continue
|
|
|
|
|
+ kids.forEach((c, i) => {
|
|
|
|
|
+ c.x = hostChip.x - ((Math.min(kids.length, CT_COLS) - 1) * CT_DX) / 2 + (i % CT_COLS) * CT_DX
|
|
|
|
|
+ c.y = hostChip.y + CT_OFFSET_Y + Math.floor(i / CT_COLS) * CT_DY
|
|
|
|
|
+ c.size = 22
|
|
|
|
|
+ })
|
|
|
|
|
+ ctsByHost.set(hostId, kids)
|
|
|
|
|
+ ctCountByHost.set(hostId, kids.length)
|
|
|
|
|
+ chips.push(...kids)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // -- peers WireGuard (arriba; túnel trazado vía Internet) -------------------
|
|
|
const activePeers = wireguard.peers.filter((p) => p.active)
|
|
const activePeers = wireguard.peers.filter((p) => p.active)
|
|
|
const peerNodes: PeerNode[] = activePeers.slice(0, PEER_COORDS.length).map((peer, i) => ({
|
|
const peerNodes: PeerNode[] = activePeers.slice(0, PEER_COORDS.length).map((peer, i) => ({
|
|
|
kind: 'peer',
|
|
kind: 'peer',
|
|
|
id: `peer-${peer.id}`,
|
|
id: `peer-${peer.id}`,
|
|
|
peer,
|
|
peer,
|
|
|
- x: PEER_COORDS[i].x,
|
|
|
|
|
- y: PEER_COORDS[i].y,
|
|
|
|
|
|
|
+ ...PEER_COORDS[i],
|
|
|
}))
|
|
}))
|
|
|
|
|
|
|
|
- // Clusters de clientes: UN DOT POR CLIENTE (sin cap), tamaño según densidad
|
|
|
|
|
- const mkCluster = (node: RouterNode, cx: number, cy: number): Cluster => {
|
|
|
|
|
- const named = devices.filter((d) => d.routerId === node.id && d.online)
|
|
|
|
|
- const count = named.length
|
|
|
|
|
- const dotR = count <= 8 ? 6 : count <= 16 ? 5 : count <= 30 ? 4 : 3
|
|
|
|
|
- const dots: ClientDot[] = named.map((device, j) => {
|
|
|
|
|
- // 8 en el anillo interior, el resto en el exterior
|
|
|
|
|
- const inner = j >= 8
|
|
|
|
|
- const idx = inner ? j - 8 : j
|
|
|
|
|
- const n = inner ? Math.max(count - 8, 1) : Math.min(count, 8)
|
|
|
|
|
- const radius = inner ? 26 : 54
|
|
|
|
|
- const angle = (-90 + (360 / n) * idx + (inner ? 20 : 0)) * (Math.PI / 180)
|
|
|
|
|
- const weak = device?.signalDbm != null ? device.signalDbm <= -65 : false
|
|
|
|
|
- return {
|
|
|
|
|
- id: `${node.id}-dot-${j}`,
|
|
|
|
|
- x: Math.round((cx + radius * Math.cos(angle)) * 10) / 10,
|
|
|
|
|
- y: Math.round((cy + radius * Math.sin(angle)) * 10) / 10,
|
|
|
|
|
- band: device?.band ?? 'cable',
|
|
|
|
|
- weak,
|
|
|
|
|
- device,
|
|
|
|
|
- r: dotR,
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- return {
|
|
|
|
|
- id: `cluster-${node.id}`,
|
|
|
|
|
- routerId: node.id,
|
|
|
|
|
- cx,
|
|
|
|
|
- cy,
|
|
|
|
|
- dots,
|
|
|
|
|
- extra: 0,
|
|
|
|
|
|
|
+ // -- tráfico agregado de un sub-árbol (para el flujo ∝ Mbps) ----------------
|
|
|
|
|
+ const subtreeTraffic = (hubId: string, seen = new Set<string>()): number => {
|
|
|
|
|
+ if (seen.has(hubId)) return 0
|
|
|
|
|
+ seen.add(hubId)
|
|
|
|
|
+ let sum = 0
|
|
|
|
|
+ for (const d of childrenOf(hubId)) {
|
|
|
|
|
+ sum += d.trafficMbps + subtreeTraffic(d.id, seen)
|
|
|
}
|
|
}
|
|
|
|
|
+ const dn = distById.get(hubId)
|
|
|
|
|
+ if (dn?.kind === 'hypervisor' && dn.hostDeviceId) {
|
|
|
|
|
+ const host = deviceById.get(dn.hostDeviceId)
|
|
|
|
|
+ if (host) sum += host.trafficMbps
|
|
|
|
|
+ }
|
|
|
|
|
+ return sum
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const clusters: Cluster[] = apNodes.map((node, i) => {
|
|
|
|
|
- const { cx, cy } = CLUSTER_COORDS[i]
|
|
|
|
|
- return mkCluster(node, cx, cy)
|
|
|
|
|
- })
|
|
|
|
|
- // El gateway también tiene clientes (cable + wifi)
|
|
|
|
|
- if (gatewayNode) {
|
|
|
|
|
- clusters.unshift(mkCluster(gatewayNode, GATEWAY_CLUSTER.cx, GATEWAY_CLUSTER.cy))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Enlaces
|
|
|
|
|
|
|
+ // -- enlaces -----------------------------------------------------------------
|
|
|
const links: TopoLink[] = []
|
|
const links: TopoLink[] = []
|
|
|
if (gatewayNode) {
|
|
if (gatewayNode) {
|
|
|
links.push({
|
|
links.push({
|
|
|
id: 'wan', kind: 'wan',
|
|
id: 'wan', kind: 'wan',
|
|
|
- d: 'M 500 164 C 500 178, 500 190, 500 204',
|
|
|
|
|
|
|
+ d: 'M 500 92 C 500 122, 500 162, 500 208',
|
|
|
lx: 518, ly: 162, label: `Fibra ${wan.plan} · ${wan.latencyMs} ms`,
|
|
lx: 518, ly: 162, label: `Fibra ${wan.plan} · ${wan.latencyMs} ms`,
|
|
|
- width: 3, packets: 3, packetDur: 2.4,
|
|
|
|
|
|
|
+ width: 3, ...flowFor(600),
|
|
|
from: 'internet', to: gatewayNode.id,
|
|
from: 'internet', to: gatewayNode.id,
|
|
|
})
|
|
})
|
|
|
- // Enlace gateway → su cluster de clientes
|
|
|
|
|
- links.push({
|
|
|
|
|
- id: `cluster-${gatewayNode.id}`, kind: 'cluster',
|
|
|
|
|
- d: `M ${GATEWAY_COORD.x - GATEWAY_COORD.r} ${GATEWAY_COORD.y} L ${GATEWAY_CLUSTER.cx + 46} ${GATEWAY_CLUSTER.cy}`,
|
|
|
|
|
- lx: 0, ly: 0, label: '',
|
|
|
|
|
- width: 1.5, packets: 0, packetDur: 0,
|
|
|
|
|
- from: gatewayNode.id, to: `cluster-${gatewayNode.id}`,
|
|
|
|
|
- })
|
|
|
|
|
}
|
|
}
|
|
|
apNodes.forEach((node, i) => {
|
|
apNodes.forEach((node, i) => {
|
|
|
const p = UPLINK_PATHS[i]
|
|
const p = UPLINK_PATHS[i]
|
|
|
const isWifi = node.id === 'patio'
|
|
const isWifi = node.id === 'patio'
|
|
|
|
|
+ const traffic = subtreeTraffic(node.id)
|
|
|
links.push({
|
|
links.push({
|
|
|
- id: `uplink-${node.id}`, kind: 'uplink',
|
|
|
|
|
|
|
+ id: `uplink-${node.id}`, kind: 'uplink', wifi: isWifi,
|
|
|
d: p.d, lx: p.lx, ly: p.ly,
|
|
d: p.d, lx: p.lx, ly: p.ly,
|
|
|
label: isWifi ? 'WiFi uplink −58 dBm' : 'Cable 1G',
|
|
label: isWifi ? 'WiFi uplink −58 dBm' : 'Cable 1G',
|
|
|
- width: p.width, packets: p.packets, packetDur: p.packetDur,
|
|
|
|
|
|
|
+ width: isWifi ? 2 : 3, ...flowFor(Math.max(traffic, isWifi ? 40 : 120)),
|
|
|
from: gatewayNode?.id ?? 'internet', to: node.id,
|
|
from: gatewayNode?.id ?? 'internet', to: node.id,
|
|
|
})
|
|
})
|
|
|
|
|
+ })
|
|
|
|
|
+ // enlaces router → distnode / device-hub / cableado directo
|
|
|
|
|
+ for (const dv of distNodes) {
|
|
|
|
|
+ const rn = routerById.get(dv.node.routerId)
|
|
|
|
|
+ if (!rn) continue
|
|
|
|
|
+ const edge = pos(rn.x, rn.y, angleTo(rn.x, rn.y, dv.x, dv.y), rn.r + 2)
|
|
|
|
|
+ const mid = { x: (edge.x + dv.x) / 2, y: (edge.y + dv.y) / 2 }
|
|
|
links.push({
|
|
links.push({
|
|
|
- id: `cluster-${node.id}`, kind: 'cluster',
|
|
|
|
|
- d: CLUSTER_PATHS[i], lx: 0, ly: 0, label: '',
|
|
|
|
|
- width: 1.5, packets: 0, packetDur: 0,
|
|
|
|
|
- from: node.id, to: `cluster-${node.id}`,
|
|
|
|
|
|
|
+ id: `dist-${dv.id}`, kind: 'dist',
|
|
|
|
|
+ d: `M ${edge.x} ${edge.y} Q ${mid.x + 6} ${mid.y - 6}, ${dv.x} ${dv.y}`,
|
|
|
|
|
+ lx: 0, ly: 0, label: '',
|
|
|
|
|
+ width: 2.5, ...flowFor(subtreeTraffic(dv.id)),
|
|
|
|
|
+ from: dv.node.routerId, to: dv.id,
|
|
|
})
|
|
})
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ const chipById = new Map(chips.map((c) => [c.id, c]))
|
|
|
|
|
+ const hubPos = (hubId: string): { x: number; y: number; r: number } | null => {
|
|
|
|
|
+ const rn = routerById.get(hubId)
|
|
|
|
|
+ if (rn) return { x: rn.x, y: rn.y, r: rn.r }
|
|
|
|
|
+ const dv = distNodes.find((n) => n.id === hubId)
|
|
|
|
|
+ if (dv) return { x: dv.x, y: dv.y, r: dv.r }
|
|
|
|
|
+ const c = chipById.get(hubId)
|
|
|
|
|
+ if (c) return { x: c.x, y: c.y, r: c.size / 2 }
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const chip of chips) {
|
|
|
|
|
+ if (chip.isCt || !chip.wired) continue // wifi "va suelto" (sin línea); CTs cuelgan del host
|
|
|
|
|
+ const hub = hubPos(chip.hubId)
|
|
|
|
|
+ if (!hub) continue
|
|
|
|
|
+ const a = angleTo(hub.x, hub.y, chip.x, chip.y)
|
|
|
|
|
+ const edge = pos(hub.x, hub.y, a, hub.r + 2)
|
|
|
|
|
+ const dx = chip.x - edge.x
|
|
|
|
|
+ const dy = chip.y - edge.y
|
|
|
|
|
+ const c1x = edge.x + dx * 0.5 - dy * 0.1
|
|
|
|
|
+ const c1y = edge.y + dy * 0.5 + dx * 0.1
|
|
|
|
|
+ const mbps = deviceHubs.has(chip.id) ? chip.device.trafficMbps + subtreeTraffic(chip.id) : chip.device.trafficMbps
|
|
|
|
|
+ links.push({
|
|
|
|
|
+ id: `wired-${chip.id}`, kind: 'wired',
|
|
|
|
|
+ d: `M ${edge.x} ${edge.y} Q ${c1x} ${c1y}, ${chip.x} ${chip.y}`,
|
|
|
|
|
+ lx: 0, ly: 0, label: '',
|
|
|
|
|
+ width: 1.4, ...flowFor(mbps),
|
|
|
|
|
+ from: chip.hubId, to: chip.id,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ // CTs: línea sólida desde el host (su tráfico viaja por el cable del host)
|
|
|
|
|
+ for (const [hostId, cts] of ctsByHost) {
|
|
|
|
|
+ const hostChip = chipById.get(hostId)
|
|
|
|
|
+ if (!hostChip) continue
|
|
|
|
|
+ for (const ct of cts) {
|
|
|
|
|
+ links.push({
|
|
|
|
|
+ id: `wired-${ct.id}`, kind: 'wired',
|
|
|
|
|
+ d: `M ${hostChip.x} ${hostChip.y + hostChip.size / 2} L ${ct.x} ${ct.y - ct.size / 2}`,
|
|
|
|
|
+ lx: 0, ly: 0, label: '',
|
|
|
|
|
+ width: 1.2, ...flowFor(ct.device.trafficMbps),
|
|
|
|
|
+ from: hostId, to: ct.id,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
peerNodes.forEach((node, i) => {
|
|
peerNodes.forEach((node, i) => {
|
|
|
- const p = WG_PATHS[i]
|
|
|
|
|
|
|
+ const p = WG_PATHS[i] ?? { d: '', dur: 3.2 }
|
|
|
|
|
+ const d = p.d || `M ${node.x + 7} ${node.y + 18} C ${node.x + 60} ${node.y + 56}, ${internetNode.x - 40} ${internetNode.y + 36}, ${internetNode.x - 26} ${internetNode.y + 22}`
|
|
|
links.push({
|
|
links.push({
|
|
|
id: `wg-${node.peer.id}`, kind: 'wg',
|
|
id: `wg-${node.peer.id}`, kind: 'wg',
|
|
|
- d: p.d, lx: p.lx, ly: p.ly, label: 'VPN',
|
|
|
|
|
- width: 2, packets: 1, packetDur: p.packetDur,
|
|
|
|
|
- from: node.id, to: gatewayNode?.id ?? 'internet',
|
|
|
|
|
|
|
+ d, lx: 0, ly: 0, label: '',
|
|
|
|
|
+ width: 2, packets: 1, packetDur: p.dur,
|
|
|
|
|
+ from: node.id, to: 'internet',
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- /** Guardrail de rendimiento: máx ~14 dots de paquetes simultáneos */
|
|
|
|
|
- const totalPackets = links.reduce((acc, l) => acc + l.packets, 0)
|
|
|
|
|
|
|
+ /** Guardrail de rendimiento: máx ~60 paquetes simultáneos (mockup) */
|
|
|
|
|
+ let totalPackets = links.reduce((acc, l) => acc + l.packets, 0)
|
|
|
|
|
+ if (totalPackets > 60) {
|
|
|
|
|
+ for (const l of [...links].sort((a, b) => b.packets - a.packets)) {
|
|
|
|
|
+ if (totalPackets <= 60) break
|
|
|
|
|
+ const cut = Math.min(l.packets - 1, totalPackets - 60)
|
|
|
|
|
+ if (cut > 0) {
|
|
|
|
|
+ l.packets -= cut
|
|
|
|
|
+ totalPackets -= cut
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- /** Enlaces activos de la red (WAN + uplinks), sin túneles */
|
|
|
|
|
- const activeLinkCount = links.filter((l) => l.kind === 'wan' || l.kind === 'uplink').length
|
|
|
|
|
|
|
+ /** Enlaces activos de la red (WAN + uplinks + distribución), sin túneles */
|
|
|
|
|
+ const activeLinkCount = links.filter((l) => l.kind === 'wan' || l.kind === 'uplink' || l.kind === 'dist').length
|
|
|
|
|
|
|
|
// Tabla de backhauls (topology.md §④)
|
|
// Tabla de backhauls (topology.md §④)
|
|
|
const backhauls: BackhaulRow[] = []
|
|
const backhauls: BackhaulRow[] = []
|
|
@@ -365,7 +702,10 @@ export function buildTopologyModel({ routers, devices, wan, wireguard }: Topolog
|
|
|
routerNodes,
|
|
routerNodes,
|
|
|
internetNode,
|
|
internetNode,
|
|
|
peerNodes,
|
|
peerNodes,
|
|
|
- clusters,
|
|
|
|
|
|
|
+ chips,
|
|
|
|
|
+ distNodes,
|
|
|
|
|
+ ctsByHost,
|
|
|
|
|
+ ctCountByHost,
|
|
|
links,
|
|
links,
|
|
|
totalPackets,
|
|
totalPackets,
|
|
|
activeLinkCount,
|
|
activeLinkCount,
|