Explorar el Código

merge: topología app — backhaul real, nodo managed, peers +N, tooltips, cosméticos (Fase 5, C1-app/C3) desde fase5/topo-gaps

agent hace 4 meses
padre
commit
522c3195ec

+ 9 - 2
app/public/locales/en/translation.json

@@ -452,17 +452,24 @@
     "dist": {
       "title": "Switch or bridge",
       "inferred": "inferred",
+      "managed": "managed switch",
       "noIp": "no IP · not directly queryable",
       "port": "Gateway port",
       "macs": "Learned MACs",
       "fdbNote": "FDB: {{count}} heterogeneous MACs on a single physical port. Probably a switch; we cannot tell for sure without LLDP."
     },
     "host": {
-      "hypervisor": "hypervisor"
+      "hypervisor": "hypervisor",
+      "note": "Hypervisor: {{count}} CTs/VMs behind its virtual bridge — not a switch"
     },
     "ct": {
       "pill": "CT",
-      "note": "Container on the hypervisor · its traffic rides the host's cable"
+      "note": "Container on the hypervisor · its traffic rides the host's cable",
+      "noteIn": "Container on {{host}} · virtual bridge ({{port}}) · traffic rides the host's cable"
+    },
+    "peers": {
+      "overflowTitle": "{{count}} more peers",
+      "overflowAria": "{{count}} additional WireGuard peers"
     }
   },
   "settings": {

+ 9 - 2
app/public/locales/es/translation.json

@@ -452,17 +452,24 @@
     "dist": {
       "title": "Switch o bridge",
       "inferred": "inferido",
+      "managed": "switch gestionado",
       "noIp": "sin IP · no consultable directamente",
       "port": "Puerto del gateway",
       "macs": "MACs aprendidas",
       "fdbNote": "FDB: {{count}} MACs heterogéneas en un solo puerto físico. Probablemente un switch; no podemos afirmarlo sin LLDP."
     },
     "host": {
-      "hypervisor": "hipervisor"
+      "hypervisor": "hipervisor",
+      "note": "Hipervisor: {{count}} CTs/VMs tras su bridge virtual — no es un switch"
     },
     "ct": {
       "pill": "CT",
-      "note": "Contenedor en el hipervisor · su tráfico viaja por el cable del host"
+      "note": "Contenedor en el hipervisor · su tráfico viaja por el cable del host",
+      "noteIn": "Contenedor en {{host}} · bridge virtual ({{port}}) · tráfico por el cable del host"
+    },
+    "peers": {
+      "overflowTitle": "{{count}} peers más",
+      "overflowAria": "{{count}} peers WireGuard adicionales"
     }
   },
   "settings": {

+ 214 - 24
app/src/components/topology/TopologyMap.tsx

@@ -13,7 +13,7 @@ import { animate, motion, useReducedMotion } from 'framer-motion'
 import { Cloud, Laptop, Router as RouterIcon, Smartphone } from 'lucide-react'
 import { useTranslation } from 'react-i18next'
 import { relTime } from '@/i18n'
-import type { DistributionNode, Router, WanInfo, WGPeer } from '@/data/mock'
+import type { Device, DistributionNode, Router, WanInfo, WGPeer } from '@/data/mock'
 import { StatusPill } from '@/components/StatusPill'
 import { DEVICE_ICONS } from '@/components/DeviceRow'
 import { cn } from '@/lib/utils'
@@ -41,6 +41,9 @@ const INITIAL_VIEW: View = { x: 0, y: 0, w: VB_W, h: VB_H }
 /** zoom 2×–0.5× */
 const MIN_W = VB_W / 2
 const MAX_W = VB_W * 2
+/** Chip "+N" de peers WG que exceden las 4 coordenadas canónicas (zona de
+ *  peers, entre la órbita de Internet y el peer interior derecho) */
+const PEERS_OVERFLOW_COORD = { x: 560, y: 26 }
 
 function clamp(v: number, min: number, max: number) {
   return Math.min(max, Math.max(min, v))
@@ -65,7 +68,18 @@ type TooltipData =
   | { kind: 'router'; id: string; router: Router; x: number; y: number }
   | { kind: 'internet'; id: string; x: number; y: number }
   | { kind: 'peer'; id: string; peer: WGPeer; x: number; y: number }
-  | { kind: 'chip'; id: string; chip: ChipNode; x: number; y: number }
+  | { kind: 'peersOverflow'; id: string; peers: WGPeer[]; x: number; y: number }
+  | {
+      kind: 'chip'
+      id: string
+      chip: ChipNode
+      /** >0 si el chip es un host hipervisor (nota "no es un switch") */
+      hostCtCount?: number
+      /** device host cuando el chip es un CT/VM anidado */
+      ctHost?: Device
+      x: number
+      y: number
+    }
   | { kind: 'dist'; id: string; node: DistributionNode; x: number; y: number }
 
 type TooltipState = TooltipData & { left: number; top: number; below: boolean }
@@ -142,8 +156,55 @@ function TooltipCard({ tip, touch, wan }: { tip: TooltipState; touch: boolean; w
           </div>
         </div>
       )}
-      {tip.kind === 'chip' && <ChipTooltip chip={tip.chip} touch={touch} />}
-      {tip.kind === 'dist' && (
+      {tip.kind === 'peersOverflow' && (
+        <div>
+          <div className="flex items-center justify-between gap-2">
+            <span className="font-display text-sm font-semibold text-text-primary">
+              {t('topology.peers.overflowTitle', { count: tip.peers.length })}
+            </span>
+            <StatusPill tone="tunnel" label={t('common.active')} pulse />
+          </div>
+          <div className="mt-2 space-y-1.5">
+            {tip.peers.map((p) => (
+              <div key={p.id} className="flex items-center justify-between gap-3 text-caption">
+                <span className="font-semibold text-text-primary">{p.name}</span>
+                <span className="font-mono text-text-muted">Handshake {relTime(p.lastHandshake)}</span>
+              </div>
+            ))}
+          </div>
+        </div>
+      )}
+      {tip.kind === 'chip' && (
+        <ChipTooltip chip={tip.chip} touch={touch} hostCtCount={tip.hostCtCount} ctHost={tip.ctHost} />
+      )}
+      {tip.kind === 'dist' && tip.node.kind === 'managed' && (
+        <div>
+          <div className="flex items-center justify-between gap-2">
+            <span className="font-display text-sm font-semibold text-text-primary">
+              {tip.node.name ?? t('topology.dist.managed')}
+            </span>
+            <StatusPill tone="accent" label="LLDP" />
+          </div>
+          <div className="mt-0.5 text-caption text-text-muted">
+            {[tip.node.ip, tip.node.port].filter(Boolean).join(' · ')}
+          </div>
+          <div className="mt-2 grid grid-cols-2 gap-1.5">
+            <MiniStat label={t('topology.dist.port')} value={tip.node.port} />
+            <MiniStat label={t('topology.dist.macs')} value={String(tip.node.macCount)} />
+          </div>
+          {tip.node.lldp && (
+            <div className="mt-2 text-caption font-semibold text-accent">
+              {t('topology.lldpIdentified', {
+                chassis: tip.node.lldp.chassis ?? '—',
+                mgmt: tip.node.lldp.mgmt ?? '—',
+                caps: tip.node.lldp.caps ?? '—',
+                port: tip.node.lldp.portDesc ?? '—',
+              })}
+            </div>
+          )}
+        </div>
+      )}
+      {tip.kind === 'dist' && tip.node.kind !== 'managed' && (
         <div>
           <div className="flex items-center justify-between gap-2">
             <span className="font-display text-sm font-semibold text-text-primary">{t('topology.dist.title')}</span>
@@ -164,7 +225,19 @@ function TooltipCard({ tip, touch, wan }: { tip: TooltipState; touch: boolean; w
 }
 
 /** Tooltip de un chip de dispositivo (cliente, hub, host hipervisor o CT). */
-function ChipTooltip({ chip, touch }: { chip: ChipNode; touch: boolean }) {
+function ChipTooltip({
+  chip,
+  touch,
+  hostCtCount = 0,
+  ctHost,
+}: {
+  chip: ChipNode
+  touch: boolean
+  /** >0 si el chip es un host hipervisor (badge +N en el mapa) */
+  hostCtCount?: number
+  /** device host cuando el chip es un CT/VM anidado */
+  ctHost?: Device
+}) {
   const { t } = useTranslation()
   const d = chip.device
   return (
@@ -200,7 +273,16 @@ function ChipTooltip({ chip, touch }: { chip: ChipNode; touch: boolean }) {
         </div>
       )}
       {chip.isCt && (
-        <div className="mt-2 text-caption leading-snug text-text-secondary">{t('topology.ct.note')}</div>
+        <div className="mt-2 text-caption leading-snug text-text-secondary">
+          {ctHost
+            ? t('topology.ct.noteIn', { host: ctHost.name, port: ctHost.port ?? '—' })
+            : t('topology.ct.note')}
+        </div>
+      )}
+      {!chip.isCt && hostCtCount > 0 && (
+        <div className="mt-2 text-caption leading-snug text-text-secondary">
+          {t('topology.host.note', { count: hostCtCount })}
+        </div>
       )}
       {!chip.isCt && chip.weak && (
         <div className="mt-1 text-caption font-semibold text-warn">{t('topology.weakSignal')}</div>
@@ -281,7 +363,7 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
   const { t } = useTranslation()
   const reduce = useReducedMotion()
   const navigate = useNavigate()
-  const { chips, ctsByHost, ctCountByHost, distNodes, internetNode, links, peerNodes, relatedTo, routerNodes, wan } = model
+  const { chips, ctsByHost, ctCountByHost, distNodes, hiddenPeers, internetNode, links, peerNodes, relatedTo, routerNodes, wan } = model
   const containerRef = useRef<HTMLDivElement>(null)
   const svgRef = useRef<SVGSVGElement>(null)
   const viewRef = useRef<View>({ ...INITIAL_VIEW })
@@ -463,7 +545,7 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
     const rect = el.getBoundingClientRect()
     const v = viewRef.current
     // nodos en la zona superior del mapa: tooltip hacia abajo
-    const below = data.kind === 'internet' || data.kind === 'peer'
+    const below = data.kind === 'internet' || data.kind === 'peer' || data.kind === 'peersOverflow'
     const left = clamp(((data.x - v.x) / v.w) * rect.width, 130, rect.width - 130)
     const rawTop = ((data.y - v.y) / v.h) * rect.height
     const top = below ? clamp(rawTop, 16, rect.height - 190) : clamp(rawTop, 190, rect.height - 20)
@@ -515,6 +597,21 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
 
   // -- atenuación por hover -----------------------------------------------------
   const related = useMemo(() => (hoverNode ? relatedTo(hoverNode) : null), [hoverNode])
+  /** chip por id (para resolver el host de un CT en tooltips) */
+  const chipById = useMemo(() => new Map(chips.map((c) => [c.id, c])), [chips])
+  /** datos del tooltip de un chip: +N si es host hipervisor, host si es CT */
+  const chipTip = useCallback(
+    (chip: ChipNode): TooltipData => ({
+      kind: 'chip',
+      id: chip.id,
+      chip,
+      hostCtCount: ctCountByHost.get(chip.id) ?? 0,
+      ctHost: chip.isCt ? chipById.get(chip.hubId)?.device : undefined,
+      x: chip.x,
+      y: chip.y - chip.size / 2 - 6,
+    }),
+    [ctCountByHost, chipById],
+  )
   const nodeOpacity = useCallback(
     (id: string) => {
       if (!related) return 1
@@ -571,9 +668,11 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
         </defs>
 
         {/* ------------------------- Anillos guía wifi ------------------------- */}
+        {/* guías para TODOS los anillos usados (el modelo añade anillos extra
+            si el wifi supera el aforo de los dos primeros) */}
         <g aria-hidden>
           {routerNodes.map((node) =>
-            (node.id === model.gatewayNode?.id ? [88, 118] : [74, 108]).map((r) => (
+            (model.ringRadii.get(node.id) ?? (node.id === model.gatewayNode?.id ? [88, 118] : [74, 108])).map((r) => (
               <circle
                 key={`${node.id}-ring-${r}`}
                 cx={node.x}
@@ -714,6 +813,14 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
                 transition={{ duration: 5, repeat: Infinity, ease: 'easeInOut' }}
               />
             )}
+            {/* anillo orbital con punto rotando 24s (mockup v5) */}
+            {!reduce && (
+              <g aria-hidden>
+                <circle r={38} fill="none" stroke={COLOR.ok} strokeWidth={1.2} strokeDasharray="3 7" opacity={0.55} />
+                <circle r={3} fill={COLOR.ok} cx={0} cy={-38} />
+                <animateTransform attributeName="transform" type="rotate" from="0" to="360" dur="24s" repeatCount="indefinite" />
+              </g>
+            )}
             <circle r={28} fill="rgb(var(--elevated))" stroke={COLOR.ok} strokeWidth={2} />
             <Cloud x={-12} y={-10} width={24} height={20} className="text-ok" strokeWidth={1.75} aria-hidden />
           </motion.g>
@@ -845,6 +952,55 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
           )
         })}
 
+        {/* ------------------------- Peers ocultos ("+N") ---------------------- */}
+        {hiddenPeers.length > 0 && (
+          <g transform={`translate(${PEERS_OVERFLOW_COORD.x} ${PEERS_OVERFLOW_COORD.y})`}>
+            <motion.g
+              initial={reduce ? { opacity: 1 } : { opacity: 0, scale: 0.6 }}
+              animate={{ opacity: nodeOpacity('peers-overflow'), scale: 1 }}
+              transition={reduce ? { duration: 0 } : { delay: 2.1 * T, duration: 0.35 }}
+              style={{ transformBox: 'fill-box', transformOrigin: 'center' }}
+            >
+              <g
+                className="cursor-pointer outline-none"
+                role="button"
+                tabIndex={0}
+                aria-label={t('topology.peers.overflowAria', { count: hiddenPeers.length })}
+                onPointerEnter={(e) =>
+                  handleNodeHover(
+                    { kind: 'peersOverflow', id: 'peers-overflow', peers: hiddenPeers, x: PEERS_OVERFLOW_COORD.x, y: PEERS_OVERFLOW_COORD.y + 30 },
+                    e,
+                  )
+                }
+                onPointerLeave={closeHover}
+                onClick={(e) =>
+                  nodeClick(
+                    e,
+                    { kind: 'peersOverflow', id: 'peers-overflow', peers: hiddenPeers, x: PEERS_OVERFLOW_COORD.x, y: PEERS_OVERFLOW_COORD.y + 30 },
+                  )
+                }
+                onKeyDown={(e) => {
+                  if (e.key === 'Enter' || e.key === ' ') {
+                    e.preventDefault()
+                    handleNodeClick({
+                      kind: 'peersOverflow',
+                      id: 'peers-overflow',
+                      peers: hiddenPeers,
+                      x: PEERS_OVERFLOW_COORD.x,
+                      y: PEERS_OVERFLOW_COORD.y + 30,
+                    })
+                  }
+                }}
+              >
+                <rect x={-15} y={-11} width={30} height={22} rx={8} fill="rgb(var(--elevated))" stroke={COLOR.tunnel} strokeWidth={1.5} />
+                <text x={0} y={3.5} textAnchor="middle" fontSize={9.5} fontWeight={700} fill={COLOR.tunnel}>
+                  +{hiddenPeers.length}
+                </text>
+              </g>
+            </motion.g>
+          </g>
+        )}
+
         {/* ------------------------- Nodos de distribución (switch inferido) --- */}
         {distNodes.map((dv, i) => (
           <DistNodeGroup
@@ -868,18 +1024,16 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
             delay={(1.6 + Math.min(i * 0.02, 0.8)) * T}
             reduce={reduce ?? false}
             opacity={nodeOpacity(chip.id)}
-            onHover={(e) =>
-              handleNodeHover({ kind: 'chip', id: chip.id, chip, x: chip.x, y: chip.y - chip.size / 2 - 6 }, e)
-            }
+            onHover={(e) => handleNodeHover(chipTip(chip), e)}
             onLeave={closeHover}
             onClick={(e) => {
               if (chip.isCt) {
-                nodeClick(e, { kind: 'chip', id: chip.id, chip, x: chip.x, y: chip.y - chip.size / 2 - 6 })
+                nodeClick(e, chipTip(chip))
                 return
               }
               nodeClick(
                 e,
-                { kind: 'chip', id: chip.id, chip, x: chip.x, y: chip.y - chip.size / 2 - 6 },
+                chipTip(chip),
                 `/devices?q=${encodeURIComponent(chip.device.mac ?? chip.device.name)}`,
               )
             }}
@@ -914,12 +1068,19 @@ export function TopologyMap({ model, apiRef, showLabels, flow, hoverLink, onHove
                 : t('common.clientsCount', { count: node.router.clients })}
               subColor={node.router.status === 'warn' ? COLOR.warn : undefined} />
           ))}
-          {/* Distnodes inferidos */}
-          {distNodes.map((dv, i) => (
-            <LabelText key={dv.id} x={dv.x} y={dv.y - 34} anchor="middle" delay={(2.15 + i * 0.03) * T}
-              reduce={reduce ?? false} title={t('topology.dist.title')}
-              sub={`${t('topology.dist.inferred')} · ${dv.node.port}`} />
-          ))}
+          {/* Distnodes (inferidos / gestionados vía LLDP) */}
+          {distNodes.map((dv, i) =>
+            dv.node.kind === 'managed' ? (
+              <LabelText key={dv.id} x={dv.x} y={dv.y - 34} anchor="middle" delay={(2.15 + i * 0.03) * T}
+                reduce={reduce ?? false} title={dv.node.name ?? t('topology.dist.managed')}
+                sub={`${[dv.node.ip ?? 'LLDP', dv.node.port].join(' · ')}`}
+                subColor={COLOR.accent} />
+            ) : (
+              <LabelText key={dv.id} x={dv.x} y={dv.y - 34} anchor="middle" delay={(2.15 + i * 0.03) * T}
+                reduce={reduce ?? false} title={t('topology.dist.title')}
+                sub={`${t('topology.dist.inferred')} · ${dv.node.port}`} />
+            ),
+          )}
           {/* Hosts hipervisores (badge +N ya en el chip; etiqueta con puerto y nº CTs) */}
           {[...ctsByHost.keys()].map((hostId, i) => {
             const host = chips.find((c) => c.id === hostId)
@@ -1029,13 +1190,18 @@ const DistNodeGroup = memo(function DistNodeGroup({
 }) {
   const { t } = useTranslation()
   const SwitchIcon = DEVICE_ICONS.switch
+  const managed = dv.node.kind === 'managed'
   return (
     <motion.g
       transform={`translate(${dv.x} ${dv.y})`}
       className="cursor-pointer outline-none"
       role="button"
       tabIndex={0}
-      aria-label={`${t('topology.dist.title')}, ${t('topology.dist.inferred')}, ${dv.node.port}`}
+      aria-label={
+        managed
+          ? `${dv.node.name ?? t('topology.dist.managed')}, LLDP, ${dv.node.ip ?? ''} ${dv.node.port}`
+          : `${t('topology.dist.title')}, ${t('topology.dist.inferred')}, ${dv.node.port}`
+      }
       animate={{ opacity }}
       transition={{ duration: 0.2 }}
       onPointerEnter={onHover}
@@ -1054,9 +1220,33 @@ const DistNodeGroup = memo(function DistNodeGroup({
         transition={reduce ? { duration: 0 } : { delay, type: 'spring', stiffness: 260, damping: 20 }}
         style={{ transformBox: 'fill-box', transformOrigin: 'center' }}
       >
-        <circle r={dv.r + 5} fill="none" stroke="rgb(var(--text-muted))" strokeWidth={1} strokeDasharray="2 5" opacity={0.6} />
-        <circle r={dv.r} fill="rgb(var(--elevated) / 0.65)" stroke="rgb(var(--text-muted))" strokeWidth={1.5} strokeDasharray="4 4" />
-        <SwitchIcon x={-10} y={-10} width={20} height={20} className="text-text-secondary" strokeWidth={1.75} aria-hidden />
+        {/* managed: sólido con borde cyan (identificado vía LLDP);
+            inferred: círculo dashed (no podemos afirmarlo) */}
+        <circle
+          r={dv.r + 5}
+          fill="none"
+          stroke={managed ? COLOR.accent : 'rgb(var(--text-muted))'}
+          strokeWidth={1}
+          strokeDasharray={managed ? undefined : '2 5'}
+          opacity={managed ? 0.5 : 0.6}
+        />
+        <circle
+          r={dv.r}
+          fill={managed ? 'rgb(var(--elevated))' : 'rgb(var(--elevated) / 0.65)'}
+          stroke={managed ? COLOR.accent : 'rgb(var(--text-muted))'}
+          strokeWidth={1.5}
+          strokeDasharray={managed ? undefined : '4 4'}
+        />
+        <SwitchIcon x={-10} y={-10} width={20} height={20} className={managed ? 'text-accent' : 'text-text-secondary'} strokeWidth={1.75} aria-hidden />
+        {/* badge LLDP (misma geometría que el badge de los chips) */}
+        {managed && (
+          <g aria-hidden>
+            <rect x={dv.r - 4} y={-dv.r - 4} width={22} height={10} rx={5} fill="rgb(var(--elevated))" stroke={COLOR.accent} strokeWidth={1} />
+            <text x={dv.r + 7} y={-dv.r + 3.4} textAnchor="middle" fontSize={6.5} fontWeight={800} fill={COLOR.accent} letterSpacing="0.04em">
+              LLDP
+            </text>
+          </g>
+        )}
       </motion.g>
     </motion.g>
   )

+ 28 - 5
app/src/components/topology/model.ts

@@ -122,12 +122,16 @@ export interface TopologyModel {
   routerNodes: RouterNode[]
   internetNode: { id: 'internet'; x: number; y: number }
   peerNodes: PeerNode[]
+  /** Peers activos que exceden las coordenadas canónicas (chip "+N") */
+  hiddenPeers: WGPeer[]
   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>
+  /** radios de los anillos wifi realmente usados por router (guías punteadas) */
+  ringRadii: Map<string, number[]>
   links: TopoLink[]
   totalPackets: number
   activeLinkCount: number
@@ -382,10 +386,12 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
 
   for (const node of routerNodes) {
     const isGw = node.id === gatewayNode?.id
-    // Solo los distnodes inferidos son anchors propios (círculo dashed); el
+    // Los distnodes inferidos y gestionados (LLDP) son anchors propios; 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 dists = distributionNodes.filter(
+      (n) => n.routerId === node.id && (n.kind === 'inferred' || n.kind === 'managed'),
+    )
     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))
@@ -450,6 +456,7 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
   })
 
   // wifi: anillos con arcos prohibidos (uplink, etiqueta, WAN, fan cableado)
+  const ringRadii = new Map<string, number[]>()
   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))
@@ -473,6 +480,7 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
       rings.push({ r: last.r + 30, cap: last.cap + 5 })
       cap = rings.reduce((a, r) => a + r.cap, 0)
     }
+    ringRadii.set(node.id, rings.map((r) => r.r))
     ringLayout(wifi, node, rings, excludes)
     // chips algo menores en anillos externos
     wifi.forEach((c, i) => {
@@ -539,6 +547,8 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
   }
 
   // -- peers WireGuard (arriba; túnel trazado vía Internet) -------------------
+  // Hay 4 coordenadas canónicas: los activos que exceden se agrupan en el
+  // chip "+N" (antes se descartaban silenciosamente).
   const activePeers = wireguard.peers.filter((p) => p.active)
   const peerNodes: PeerNode[] = activePeers.slice(0, PEER_COORDS.length).map((peer, i) => ({
     kind: 'peer',
@@ -546,6 +556,7 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
     peer,
     ...PEER_COORDS[i],
   }))
+  const hiddenPeers = activePeers.slice(PEER_COORDS.length)
 
   // -- tráfico agregado de un sub-árbol (para el flujo ∝ Mbps) ----------------
   const subtreeTraffic = (hubId: string, seen = new Set<string>()): number => {
@@ -555,6 +566,12 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
     for (const d of childrenOf(hubId)) {
       sum += d.trafficMbps + subtreeTraffic(d.id, seen)
     }
+    // distnodes que cuelgan de este hub: su sub-árbol también viaja por el
+    // enlace del hub (el hipervisor ya cuenta vía su device host).
+    for (const dn of distributionNodes) {
+      if (dn.routerId !== hubId || dn.kind === 'hypervisor') continue
+      sum += subtreeTraffic(dn.id, seen)
+    }
     const dn = distById.get(hubId)
     if (dn?.kind === 'hypervisor' && dn.hostDeviceId) {
       const host = deviceById.get(dn.hostDeviceId)
@@ -576,12 +593,16 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
   }
   apNodes.forEach((node, i) => {
     const p = UPLINK_PATHS[i]
-    const isWifi = node.id === 'patio'
+    // C1: backhaul real del router (ausente = cable); sin hardcode por id.
+    const isWifi = node.router.backhaul === 'wifi'
     const traffic = subtreeTraffic(node.id)
+    // Etiqueta wifi: genérica (no hay dato de señal en el contrato Router);
+    // cable: sufijo "· LLDP" si el AP se anuncia en el puerto del uplink (C2).
+    const label = isWifi ? 'WiFi uplink' : `Cable 1G${node.router.lldp ? ' · LLDP' : ''}`
     links.push({
       id: `uplink-${node.id}`, kind: 'uplink', wifi: isWifi,
       d: p.d, lx: p.lx, ly: p.ly,
-      label: isWifi ? 'WiFi uplink −58 dBm' : 'Cable 1G',
+      label,
       width: isWifi ? 2 : 3, ...flowFor(Math.max(traffic, isWifi ? 40 : 120)),
       from: gatewayNode?.id ?? 'internet', to: node.id,
     })
@@ -681,7 +702,7 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
     })
   }
   for (const node of apNodes) {
-    const isWifi = node.id === 'patio'
+    const isWifi = node.router.backhaul === 'wifi'
     backhauls.push({
       id: `uplink-${node.id}`, a: 'Gateway', b: node.router.name, kind: 'uplink',
       type: isWifi ? 'topology.links.wifiUplink' : 'common.cable',
@@ -732,10 +753,12 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
     routerNodes,
     internetNode,
     peerNodes,
+    hiddenPeers,
     chips,
     distNodes,
     ctsByHost,
     ctCountByHost,
+    ringRadii,
     links,
     totalPackets,
     activeLinkCount,

+ 19 - 11
app/src/data/mock.ts

@@ -63,6 +63,7 @@ export const routers: Router[] = [
     role: 'Main gateway',
     roleBadge: 'Principal',
     ip: '192.168.8.1',
+    backhaul: 'cable',
     status: 'online',
     health: 98,
     cpu: 23,
@@ -80,6 +81,8 @@ export const routers: Router[] = [
     role: 'Access point',
     roleBadge: 'AP',
     ip: '192.168.8.2',
+    backhaul: 'cable',
+    lldp: { chassis: 'AX3000T', caps: 'Bridge, Wlan', portDesc: 'eth0' },
     status: 'online',
     health: 95,
     cpu: 12,
@@ -97,6 +100,8 @@ export const routers: Router[] = [
     role: 'AP + switch',
     roleBadge: 'AP',
     ip: '192.168.8.3',
+    backhaul: 'cable',
+    lldp: { chassis: 'NanoPi-R4S', caps: 'Bridge, Router', portDesc: 'eth0' },
     status: 'online',
     health: 92,
     cpu: 18,
@@ -114,6 +119,7 @@ export const routers: Router[] = [
     role: 'Outdoor AP',
     roleBadge: 'AP',
     ip: '192.168.8.4',
+    backhaul: 'wifi',
     status: 'warn',
     health: 68,
     cpu: 31,
@@ -290,30 +296,25 @@ export const devices: Device[] = [
   // -- Fixtures de topología v5 (mockup aprobado: switch gestionado LLDP, --
   // -- hipervisor con CTs anidados, switch/bridge inferido vía FDB) ----------
 
-  // Switch gestionado identificado por LLDP + 3 clientes detrás (Salón, lan3)
-  {
-    id: 'switch-netgear', name: 'Switch Netgear', type: 'switch', manufacturer: 'Netgear GS308E',
-    ip: '192.168.8.2', mac: 'D8:B3:70:1A:2B:3C', routerId: 'living', band: 'cable',
-    signalDbm: null, trafficMbps: 3.4, online: true, port: 'lan3',
-    lldp: { chassis: 'GS308E', mgmt: '192.168.8.2', caps: 'Bridge', portDesc: 'ge5' },
-    sparkline: [2, 2.4, 2.8, 3.1, 3.3, 3.6, 3.4, 3.2, 3.4, 3.5, 3.4, 3.4],
-  },
+  // 3 clientes tras el switch gestionado GS308E (Salón, lan3) — el switch se
+  // modela como DistributionNode kind='managed' (identificado vía LLDP), igual
+  // que lo emitirá el backend demo (C2).
   {
     id: 'xbox-series-s', name: 'Xbox Series S', type: 'consola', manufacturer: 'Microsoft',
     ip: '192.168.8.35', mac: '7C:ED:8D:4A:11:22', routerId: 'living', band: 'cable',
-    signalDbm: null, trafficMbps: 9.8, online: true, attachTo: 'switch-netgear',
+    signalDbm: null, trafficMbps: 9.8, online: true, attachTo: 'dist-living-lan3',
     sparkline: [3, 5, 7, 9, 11, 12, 10, 9, 10, 9, 10, 9.8],
   },
   {
     id: 'apple-tv-4k', name: 'Apple TV 4K', type: 'tv', manufacturer: 'Apple',
     ip: '192.168.8.36', mac: 'F0:18:98:2B:33:44', routerId: 'living', band: 'cable',
-    signalDbm: null, trafficMbps: 15.2, online: true, attachTo: 'switch-netgear',
+    signalDbm: null, trafficMbps: 15.2, online: true, attachTo: 'dist-living-lan3',
     sparkline: [6, 8, 10, 12, 14, 16, 15, 14, 15, 15, 15, 15.2],
   },
   {
     id: 'receptor-denon', name: 'Receptor Denon', type: 'altavoz', manufacturer: 'Denon',
     ip: '192.168.8.37', mac: '00:05:CD:55:66:77', routerId: 'living', band: 'cable',
-    signalDbm: null, trafficMbps: 0.6, online: true, attachTo: 'switch-netgear',
+    signalDbm: null, trafficMbps: 0.6, online: true, attachTo: 'dist-living-lan3',
     sparkline: [0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6],
   },
 
@@ -369,6 +370,13 @@ export const devices: Device[] = [
 export const distributionNodes: 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' },
+  // Switch gestionado Netgear GS308E en el AP Salón (lan3), identificado vía
+  // LLDP (chasis + IP de mgmt + caps + puerto remoto). 4 MACs: switch + 3 equipos.
+  {
+    id: 'dist-living-lan3', kind: 'managed', routerId: 'living', port: 'lan3', macCount: 4,
+    name: 'GS308E', ip: '192.168.8.13',
+    lldp: { chassis: 'GS308E', mgmt: '192.168.8.13', caps: 'Bridge', portDesc: 'ge5' },
+  },
 ]
 
 // ---------------------------------------------------------------------------

+ 16 - 3
app/src/data/types.ts

@@ -38,6 +38,16 @@ export interface Router {
   clients: number
   /** Métrica en umbral (se pinta --warn), p. ej. 'temp' en Patio */
   hotMetric?: 'cpu' | 'ram' | 'temp'
+  /**
+   * Backhaul del AP (C1): 'wifi' = uplink inalámbrico (se dibuja dashed
+   * ámbar); 'cable'/ausente = cableado o desconocido.
+   */
+  backhaul?: 'cable' | 'wifi'
+  /**
+   * El AP se anuncia por LLDP en el puerto del uplink (C2): el frontend
+   * añade el sufijo "· LLDP" a la etiqueta del enlace. Ausente = sin dato.
+   */
+  lldp?: LldpInfo | null
   /** Sparkline de tráfico 24h (Mbps, 24 puntos) */
   sparkline: number[]
 }
@@ -163,11 +173,12 @@ export interface Device {
  * Nodo de distribución entre un router y varios cableados, inferido del FDB:
  * un puerto físico con varias MACs aprendidas. `inferred` = OUI heterogéneo
  * (switch o bridge desconocido, sin IP); `hypervisor` = OUI de hipervisor
- * (Proxmox/VMware/Hyper-V/KVM) → sus CTs/VMs se anidan bajo el host.
+ * (Proxmox/VMware/Hyper-V/KVM) → sus CTs/VMs se anidan bajo el host;
+ * `managed` = switch gestionado identificado vía LLDP (tiene IP de mgmt).
  */
 export interface DistributionNode {
   id: string
-  kind: 'inferred' | 'hypervisor'
+  kind: 'inferred' | 'hypervisor' | 'managed'
   routerId: string
   /** Puerto físico del router donde cuelga (lan3…). */
   port: string
@@ -175,8 +186,10 @@ export interface DistributionNode {
   macCount: number
   /** Hypervisor: id del Device host (Proxmox…), si existe como cliente. */
   hostDeviceId?: string
-  /** Nombre descriptivo (host o futura identificación LLDP). */
+  /** Nombre descriptivo (host o chasis LLDP del switch gestionado). */
   name?: string
+  /** Managed: IP de gestión anunciada por LLDP. */
+  ip?: string
   lldp?: LldpInfo | null
 }
 

+ 5 - 11
app/src/pages/devices-data.ts

@@ -3,11 +3,11 @@
  * Los 10 dispositivos destacados de `@/data/mock` se reutilizan tal cual;
  * la entrada agregada "Bombillas Ikea ×6" se expande en sus 6 bombillas
  * individuales y se añaden los clientes restantes hasta los totales del
- * canon: 47 conocidos · 39 online · 8 offline (Gateway 14, Salón 18,
+ * canon: 46 conocidos · 38 online · 8 offline (Gateway 13, Salón 18,
  * Estudio 9, Patio 6). Nada aquí contradice `@/data/mock`.
  */
 import type { LucideIcon } from 'lucide-react'
-import { BookOpen, Network, Printer } from 'lucide-react'
+import { BookOpen, Printer } from 'lucide-react'
 import type { Device } from '@/data/mock'
 import { devices as canonDevices } from '@/data/mock'
 
@@ -131,7 +131,7 @@ function bulb(n: number, name: string, ip: string, mac: string, dbm: number): Cl
 // ---------------------------------------------------------------------------
 
 const ADDITIONAL: ClientDevice[] = [
-  // —— Gateway (flint2): 14 totales (canon: pixel-8-pro, nas-synology) ——
+  // —— Gateway (flint2): 13 totales (canon: pixel-8-pro, nas-synology) ——
   {
     ...extra({ id: 'iphone-ana', name: "Ana's iPhone", type: 'movil', manufacturer: 'Apple',
       ip: '192.168.8.44', mac: 'F4:D4:88:19:C2:71', routerId: 'flint2', band: '5 GHz',
@@ -160,14 +160,8 @@ const ADDITIONAL: ClientDevice[] = [
     hostname: 'raspberrypi', dhcpLease: 'Static IP (reservation)', firstSeen: '320 days ago',
     traffic24hRx: '3.4 GB', traffic24hTx: '890 MB', adguard: true, group: 'red',
   },
-  {
-    ...extra({ id: 'switch-netgear', name: 'Netgear 8-port switch', type: 'servidor', manufacturer: 'Netgear',
-      ip: '192.168.8.13', mac: '28:C6:8E:1D:90:44', routerId: 'flint2', band: 'cable',
-      signalDbm: null, trafficMbps: 0.02, online: true, seed: 15, spread: 0.04 }),
-    hostname: 'gs308e', dhcpLease: 'Static IP (reservation)', firstSeen: '300 days ago',
-    traffic24hRx: '64 MB', traffic24hTx: '12 MB', adguard: false, group: 'red',
-    iconOverride: Network,
-  },
+  // (El switch Netgear GS308E ya no es un Device: el backend demo lo emite
+  // como DistributionNode kind='managed' — dist-living-lan3, ver mock.ts.)
   {
     ...extra({ id: 'timbre-nest', name: 'Nest doorbell', type: 'camara', manufacturer: 'Google',
       ip: '192.168.8.72', mac: 'F4:F5:D8:66:01:B8', routerId: 'flint2', band: '2.4 GHz',