Просмотр исходного кода

feat(routers): campo backhaul en Router — sonda ubus network.wireless (STA asociada) + demo Patio wifi (C1-server)

agent 4 месяцев назад
Родитель
Сommit
1518b937fb

+ 5 - 0
server-go/internal/adapters/demo_dataset.go

@@ -23,18 +23,23 @@ func canonRouters() []Router {
 		{ID: "flint2", Name: "Gateway", Model: "GL.iNet Flint 2 (GL-MT6000)", ModelShort: "GL.iNet Flint 2",
 			Role: "Gateway principal", RoleBadge: "Principal", IP: "192.168.8.1", Status: "online",
 			Health: 98, CPU: iptr(23), RAM: iptr(41), Temp: iptr(54), Uptime: "32d 14h", Clients: 33,
+			Backhaul:  "cable",
 			Sparkline: []float64{8, 6, 5, 5, 6, 9, 18, 32, 41, 38, 35, 44, 52, 48, 45, 55, 68, 84, 96, 120, 150, 110, 84, 40}},
 		{ID: "living", Name: "Salón", Model: "OpenWrt AP (Xiaomi AX3000T)", ModelShort: "Xiaomi AX3000T",
 			Role: "Punto de acceso", RoleBadge: "AP", IP: "192.168.8.2", Status: "online",
 			Health: 95, CPU: iptr(12), RAM: iptr(38), Temp: iptr(47), Uptime: "32d 14h", Clients: 22,
+			Backhaul:  "cable",
 			Sparkline: []float64{4, 3, 3, 2, 3, 5, 10, 22, 28, 26, 24, 30, 38, 35, 33, 42, 55, 72, 88, 105, 132, 92, 61, 28}},
 		{ID: "estudio", Name: "Estudio", Model: "OpenWrt (NanoPi R4S)", ModelShort: "NanoPi R4S",
 			Role: "AP + switch", RoleBadge: "AP", IP: "192.168.8.3", Status: "online",
 			Health: 92, CPU: iptr(18), RAM: iptr(44), Temp: iptr(51), Uptime: "11d 3h", Clients: 9,
+			Backhaul:  "cable",
 			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}},
+		// Patio: único AP con uplink inalámbrico del dataset (backhaul "wifi").
 		{ID: "patio", Name: "Patio", Model: "OpenWrt (TP-Link EAP225)", ModelShort: "TP-Link EAP225",
 			Role: "AP exterior", RoleBadge: "AP", IP: "192.168.8.4", Status: "warn",
 			Health: 68, CPU: iptr(31), RAM: iptr(57), Temp: iptr(71), Uptime: "4d 2h", Clients: 6, HotMetric: "temp",
+			Backhaul:  "wifi",
 			Sparkline: []float64{1, 1, 1, 1, 1, 2, 3, 5, 7, 8, 8, 9, 10, 9, 8, 9, 11, 12, 13, 12, 9, 6, 4, 2}},
 	}
 }

+ 43 - 0
server-go/internal/adapters/openwrt.go

@@ -40,6 +40,9 @@ type OpenWrtClient struct {
 	sid        string     // sesión ubus HTTP cacheada
 	lastStat   *cpuSample // /proc/stat previo
 	lastNetDev *netSample // /proc/net/dev previo
+	// lldpDownUntil: indisponibilidad de lldpd cacheada (≥5 min) para no
+	// martillear con un comando que no existe. Solo lo toca el sondeo.
+	lldpDownUntil time.Time
 }
 
 type cpuSample struct{ total, idleAll float64 }
@@ -501,6 +504,46 @@ func parseWirelessClients(out string) map[string]WirelessClient {
 	return m
 }
 
+// GetWirelessUplink: true si el router tiene uplink inalámbrico (alguna
+// interfaz STA activa/asociada en `ubus call network.wireless status`).
+// Error si el router no soporta la llamada (sin wifi → el caller omite el
+// campo backhaul, nunca rompe el sondeo).
+func (c *OpenWrtClient) GetWirelessUplink() (bool, error) {
+	raw, err := c.UbusCall("network.wireless", "status", nil)
+	if err != nil {
+		return false, err
+	}
+	return parseWirelessUplink(raw)
+}
+
+// parseWirelessUplink: alguna interfaz con config.mode "sta" activa (radio
+// up e ifname asignado = asociada). Tolerante con radios/entradas raras.
+func parseWirelessUplink(raw json.RawMessage) (bool, error) {
+	var radios map[string]struct {
+		Up         bool `json:"up"`
+		Interfaces []struct {
+			Ifname string `json:"ifname"`
+			Config struct {
+				Mode string `json:"mode"`
+			} `json:"config"`
+		} `json:"interfaces"`
+	}
+	if err := json.Unmarshal(raw, &radios); err != nil {
+		return false, err
+	}
+	for _, r := range radios {
+		if !r.Up {
+			continue
+		}
+		for _, itf := range r.Interfaces {
+			if itf.Config.Mode == "sta" && itf.Ifname != "" {
+				return true, nil
+			}
+		}
+	}
+	return false, nil
+}
+
 // ---------------------------------------------------------------------------
 // Puertos
 // ---------------------------------------------------------------------------

+ 9 - 2
server-go/internal/adapters/types.go

@@ -128,6 +128,9 @@ type Router struct {
 	Clients    int       `json:"clients"`
 	HotMetric  string    `json:"hotMetric,omitempty"` // "temp" solo si temp>65
 	Sparkline  []float64 `json:"sparkline"`
+	// Backhaul: medio del uplink del router ("cable"|"wifi"). Ausente =
+	// cable/desconocido (router sin wifi o sonda no disponible).
+	Backhaul string `json:"backhaul,omitempty"`
 }
 
 // DeviceTotals del overview (quirk: NewToday=0 en live).
@@ -187,16 +190,20 @@ type LldpInfo struct {
 // DistributionNode: puerto físico con varias MACs aprendidas en el FDB.
 // "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 en el mapa.
+// CTs/VMs se anidan bajo el host en el mapa;
+// "managed" = identificado por LLDP (vecino anunciado en ese puerto cuya
+// chassis-MAC está entre las aprendidas): lleva Name (chassis), Ip (mgmt)
+// y Lldp con las capacidades/puerto remoto anunciados.
 type DistributionNode struct {
 	ID       string    `json:"id"`
-	Kind     string    `json:"kind"` // "inferred"|"hypervisor"
+	Kind     string    `json:"kind"` // "inferred"|"hypervisor"|"managed"
 	RouterID string    `json:"routerId"`
 	Port     string    `json:"port"`
 	MacCount int       `json:"macCount"`
 	// HostDeviceID: hipervisor → id del Device host (Proxmox…), si es cliente.
 	HostDeviceID string    `json:"hostDeviceId,omitempty"`
 	Name         string    `json:"name,omitempty"`
+	Ip           string    `json:"ip,omitempty"` // managed: mgmt-ip anunciada por LLDP
 	Lldp         *LldpInfo `json:"lldp,omitempty"`
 }