| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526 |
- // client_discovery_test.go — Regla de descubrimiento de clientes por red
- // lógica de OpenWrt (y respaldo por dispositivo Linux) en el servidor: modo
- // automático, overrides explícitos ("on" / "off"), resolución cuando varias
- // redes comparten dispositivo, interacción con WanSide (#1485) en el gateway y
- // construcción de RouterDetail.Discovery.
- package adapters
- import (
- "context"
- "reflect"
- "testing"
- "time"
- "github.com/gnacho/netpulse/agent/probe"
- "github.com/gnacho/netpulse/server-go/internal/db"
- )
- func boolPtr(b bool) *bool { return &b }
- func travelNetIfaces() []probe.NetIface {
- return []probe.NetIface{
- {Name: "lan", Proto: "static", Up: true, Devices: []string{"br-lan"}},
- {Name: "wan", Proto: "dhcp", Up: false, Devices: []string{"eth0.2"}},
- {Name: "wan6", Proto: "dhcpv6", Up: false, Devices: []string{"eth0.2"}},
- {Name: "wg0", Proto: "wireguard", Up: true, Devices: []string{"wg0"}},
- {Name: "wwan", Proto: "dhcp", Up: true, Devices: []string{"phy1-sta0"}},
- }
- }
- func travelPolled(ov DiscoveryOverrides) *routerPolled {
- return &routerPolled{
- cfg: RouterConfig{
- ID: "travel",
- Name: "travel",
- Host: "192.168.2.1",
- DiscoveryOverrides: ov,
- },
- wanInfo: probe.WanInfo{Device: "phy1-sta0", Port: "phy1-sta0"},
- uplinkDevs: []string{"phy1-sta0"},
- netIfaces: travelNetIfaces(),
- arp: map[string]string{
- "AA:BB:CC:00:00:01": "10.20.0.177", // vecino en wwan (uplink)
- "AA:BB:CC:00:00:02": "192.168.2.50", // vecino en lan
- },
- arpDevs: map[string]string{
- "AA:BB:CC:00:00:01": "phy1-sta0",
- "AA:BB:CC:00:00:02": "br-lan",
- },
- }
- }
- // En un router de viaje, buildDiscoveryIfaces emite una fila por cada red en
- // orden del dump (sin filas device cuando todos los dispositivos pertenecen a
- // una red), con Auto=false solo en wwan y el conteo de vecinos confirmados
- // correcto.
- func TestClientDiscoveryTravelRouterNetworkRows(t *testing.T) {
- p := travelPolled(DiscoveryOverrides{})
- p.arp["AA:BB:CC:00:00:03"] = "10.20.0.178"
- p.arpDevs["AA:BB:CC:00:00:03"] = "phy1-sta0"
- p.arpStale = map[string]bool{"AA:BB:CC:00:00:03": true} // stale no suma
- got := buildDiscoveryIfaces(p)
- want := []DiscoveryIface{
- {Kind: "network", Name: "lan", Devices: []string{"br-lan"}, Up: boolPtr(true), Mode: "auto", Auto: true, Effective: true, Neighbours: 1},
- {Kind: "network", Name: "wan", Devices: []string{"eth0.2"}, Up: boolPtr(false), Mode: "auto", Auto: true, Effective: true, Neighbours: 0},
- {Kind: "network", Name: "wan6", Devices: []string{"eth0.2"}, Up: boolPtr(false), Mode: "auto", Auto: true, Effective: true, Neighbours: 0},
- {Kind: "network", Name: "wg0", Devices: []string{"wg0"}, Up: boolPtr(true), Mode: "auto", Auto: true, Effective: true, Neighbours: 0},
- {Kind: "network", Name: "wwan", Devices: []string{"phy1-sta0"}, Up: boolPtr(true), Mode: "auto", Auto: false, Effective: false, Neighbours: 1},
- }
- if !reflect.DeepEqual(got, want) {
- t.Fatalf("filas de descubrimiento del router de viaje:\ngot %+v\nwant %+v", got, want)
- }
- // En automático solo cuenta el vecino de br-lan, no el de phy1-sta0.
- l := NewLive(nil, nil, nil, nil)
- devs := l.buildDevices(map[string]*routerPolled{"travel": p}, "")
- if len(devs) != 1 || devs[0].MAC != "AA:BB:CC:00:00:02" {
- t.Fatalf("en automático solo debe contar el vecino de lan: %+v", devs)
- }
- }
- // Un vecino en un dispositivo que no pertenece a ninguna red (p. ej. eth3)
- // aparece como fila device y cuenta como cliente en automático.
- func TestClientDiscoveryUnassignedDeviceRow(t *testing.T) {
- p := travelPolled(DiscoveryOverrides{})
- p.arp["AA:BB:CC:00:00:09"] = "192.168.9.10"
- p.arpDevs["AA:BB:CC:00:00:09"] = "eth3"
- rows := buildDiscoveryIfaces(p)
- if len(rows) != 6 {
- t.Fatalf("esperaba 5 redes + 1 fila device, obtuve %d: %+v", len(rows), rows)
- }
- wantDev := DiscoveryIface{Kind: "device", Name: "eth3", Mode: "auto", Auto: true, Effective: true, Neighbours: 1}
- if !reflect.DeepEqual(rows[5], wantDev) {
- t.Fatalf("fila device de respaldo:\ngot %+v\nwant %+v", rows[5], wantDev)
- }
- l := NewLive(nil, nil, nil, nil)
- devs := l.buildDevices(map[string]*routerPolled{"travel": p}, "")
- gotMACs := map[string]bool{}
- for _, d := range devs {
- gotMACs[d.MAC] = true
- }
- if !gotMACs["AA:BB:CC:00:00:02"] || !gotMACs["AA:BB:CC:00:00:09"] || gotMACs["AA:BB:CC:00:00:01"] {
- t.Fatalf("esperaba clientes en br-lan y eth3 (sin phy1-sta0): %+v", devs)
- }
- }
- // Con Networks["wwan"]="on", los vecinos del uplink pasan a contar como clientes.
- func TestClientDiscoveryNetworkOverrideOnWwan(t *testing.T) {
- p := travelPolled(DiscoveryOverrides{
- Networks: map[string]DiscoveryMode{"wwan": "on"},
- })
- l := NewLive(nil, nil, nil, nil)
- devs := l.buildDevices(map[string]*routerPolled{"travel": p}, "")
- if len(devs) != 2 {
- t.Fatalf("con wwan='on' deben contar ambos vecinos (lan y wwan): %+v", devs)
- }
- }
- // Con Networks["lan"]="off", los vecinos de br-lan se descartan.
- func TestClientDiscoveryNetworkOverrideOffLan(t *testing.T) {
- p := travelPolled(DiscoveryOverrides{
- Networks: map[string]DiscoveryMode{"lan": "off"},
- })
- l := NewLive(nil, nil, nil, nil)
- if devs := l.buildDevices(map[string]*routerPolled{"travel": p}, ""); len(devs) != 0 {
- t.Fatalf("con lan='off' y wwan en automático no debe haber clientes: %+v", devs)
- }
- }
- // Dos redes que comparten dispositivo (wan y wan6 sobre eth0.2) cuando eth0.2
- // es el uplink: ambas tienen Auto=false; explícito vence a automático; entre
- // explícitos, "off" vence a "on".
- func TestClientDiscoverySharedDeviceResolution(t *testing.T) {
- makePolled := func(nets map[string]DiscoveryMode) *routerPolled {
- return &routerPolled{
- cfg: RouterConfig{
- ID: "rt",
- Name: "rt",
- Host: "192.168.1.1",
- DiscoveryOverrides: DiscoveryOverrides{Networks: nets},
- },
- wanInfo: probe.WanInfo{Device: "eth0.2"},
- netIfaces: travelNetIfaces(),
- arp: map[string]string{"AA:BB:CC:00:00:55": "198.51.100.1"},
- arpDevs: map[string]string{"AA:BB:CC:00:00:55": "eth0.2"},
- }
- }
- t.Run("automatico desactiva wan y wan6", func(t *testing.T) {
- p := makePolled(nil)
- rows := buildDiscoveryIfaces(p)
- for _, r := range rows {
- if r.Name == "wan" || r.Name == "wan6" {
- if r.Auto || r.Effective || r.Neighbours != 1 {
- t.Fatalf("fila %s esperaba Auto=false Effective=false Neighbours=1: %+v", r.Name, r)
- }
- }
- }
- if resolveDiscovery(p, "eth0.2", nil).allowed() {
- t.Fatal("eth0.2 debía quedar bloqueado en automático")
- }
- })
- t.Run("wan on con wan6 en automatico permite el dispositivo", func(t *testing.T) {
- p := makePolled(map[string]DiscoveryMode{"wan": "on"})
- if !resolveDiscovery(p, "eth0.2", nil).allowed() {
- t.Fatal("wan='on' + wan6='auto' debía permitir eth0.2 (explícito vence a automático)")
- }
- if !discoveryExplicitOn(p, "eth0.2") {
- t.Fatal("wan='on' + wan6='auto' debía considerarse explicitOn")
- }
- })
- t.Run("wan on con wan6 off bloquea el dispositivo", func(t *testing.T) {
- p := makePolled(map[string]DiscoveryMode{"wan": "on", "wan6": "off"})
- if resolveDiscovery(p, "eth0.2", nil).allowed() {
- t.Fatal("wan='on' + wan6='off' debía bloquear eth0.2 ('off' vence a 'on')")
- }
- if discoveryExplicitOn(p, "eth0.2") {
- t.Fatal("wan='on' + wan6='off' no debe ser explicitOn")
- }
- })
- // El orden de las redes no importa: un Off en la primera corta el bucle y
- // el On de la segunda no lo deshace.
- t.Run("wan off con wan6 on bloquea el dispositivo", func(t *testing.T) {
- p := makePolled(map[string]DiscoveryMode{"wan": "off", "wan6": "on"})
- if resolveDiscovery(p, "eth0.2", nil).allowed() {
- t.Fatal("wan='off' + wan6='on' debía bloquear eth0.2 ('off' vence a 'on')")
- }
- if discoveryExplicitOn(p, "eth0.2") {
- t.Fatal("wan='off' + wan6='on' no debe ser explicitOn")
- }
- })
- }
- // En el gateway, el vecino de wanPort es WanSide por defecto (#1485) y solo
- // deja de marcarse WanSide cuando hay un override explícito "on" por red.
- func TestClientDiscoveryGatewayWanPortNetworkOverride(t *testing.T) {
- gwCfg := RouterConfig{ID: "gw", Name: "gw", Host: "192.168.1.1", IsGateway: true}
- l := NewLive(nil, nil, []RouterConfig{gwCfg}, nil)
- ifaces := []probe.NetIface{
- {Name: "lan", Proto: "static", Up: true, Devices: []string{"br-lan"}},
- {Name: "wan", Proto: "dhcp", Up: true, Devices: []string{"eth0.2"}},
- {Name: "wan6", Proto: "dhcpv6", Up: true, Devices: []string{"eth0.2"}},
- }
- makeGW := func(cfg RouterConfig) map[string]*routerPolled {
- return map[string]*routerPolled{
- "gw": {
- cfg: cfg,
- wanInfo: probe.WanInfo{Device: "eth0.2", Port: "eth0.2"},
- netIfaces: ifaces,
- arp: map[string]string{"AA:BB:CC:00:00:99": "192.168.100.1"},
- arpDevs: map[string]string{"AA:BB:CC:00:00:99": "eth0.2"},
- },
- }
- }
- // Sin override: sigue siendo WanSide.
- devs := l.buildDevices(makeGW(gwCfg), "eth0.2")
- if len(devs) != 1 || !devs[0].WanSide {
- t.Fatalf("sin override el vecino de wanPort debe seguir siendo WanSide: %+v", devs)
- }
- // Con Networks["wan"]="on": deja de ser WanSide y entra como cliente normal.
- gwOn := gwCfg
- gwOn.DiscoveryOverrides = DiscoveryOverrides{Networks: map[string]DiscoveryMode{"wan": "on"}}
- l.SetRouters([]RouterConfig{gwOn})
- devs = l.buildDevices(makeGW(gwOn), "eth0.2")
- if len(devs) != 1 || devs[0].WanSide {
- t.Fatalf("con Networks['wan']='on' el vecino debe ser cliente y no WanSide: %+v", devs)
- }
- // Con wan="on" y wan6="off": off vence a on, así que no es explicitOn -> WanSide.
- gwConflict := gwCfg
- gwConflict.DiscoveryOverrides = DiscoveryOverrides{Networks: map[string]DiscoveryMode{"wan": "on", "wan6": "off"}}
- l.SetRouters([]RouterConfig{gwConflict})
- devs = l.buildDevices(makeGW(gwConflict), "eth0.2")
- if len(devs) != 1 || !devs[0].WanSide {
- t.Fatalf("con wan='on' y wan6='off' debe seguir siendo WanSide: %+v", devs)
- }
- }
- // En el gateway con IP de puerta de enlace WAN (#2183/#1791): sin override no
- // entra ni el peer de la ruta por defecto (#1791) ni el vecino del segmento
- // (wanIgnored, #2188). Con Networks["wan"]="on", el vecino confirmado pasa a
- // ser un cliente normal (WanSide=false), pero el peer sigue absorbido por #1791.
- func TestClientDiscoveryGatewayWanPortWithGatewayIP(t *testing.T) {
- const (
- peer = "0C:EF:15:00:00:01"
- neighbour = "0C:EF:15:00:00:02"
- )
- gwCfg := RouterConfig{ID: "gw", Name: "gw", Host: "192.168.1.1", IsGateway: true}
- l := NewLive(nil, nil, []RouterConfig{gwCfg}, nil)
- ifaces := []probe.NetIface{
- {Name: "lan", Proto: "static", Up: true, Devices: []string{"br-lan"}},
- {Name: "wan", Proto: "dhcp", Up: true, Devices: []string{"eth0.2"}},
- {Name: "wan6", Proto: "dhcpv6", Up: true, Devices: []string{"eth0.2"}},
- }
- makeGW := func(cfg RouterConfig) map[string]*routerPolled {
- return map[string]*routerPolled{
- "gw": {
- cfg: cfg,
- wanInfo: probe.WanInfo{Device: "eth0.2", Port: "eth0.2", Gateway: "203.0.113.1"},
- netIfaces: ifaces,
- arp: map[string]string{
- peer: "203.0.113.1",
- neighbour: "203.0.113.248",
- },
- arpDevs: map[string]string{
- peer: "eth0.2",
- neighbour: "eth0.2",
- },
- },
- }
- }
- // Sin override: el peer cae en #1791 y el vecino en wanIgnored (#2188).
- if devs := l.buildDevices(makeGW(gwCfg), "eth0.2"); len(devs) != 0 {
- t.Fatalf("sin override no debe salir ni el peer ni el vecino del segmento WAN: %+v", devs)
- }
- // Con Networks["wan"]="on": el vecino confirmado entra como cliente normal,
- // pero el peer de la ruta por defecto sigue descartado por #1791.
- gwOn := gwCfg
- gwOn.DiscoveryOverrides = DiscoveryOverrides{Networks: map[string]DiscoveryMode{"wan": "on"}}
- l.SetRouters([]RouterConfig{gwOn})
- devs := l.buildDevices(makeGW(gwOn), "eth0.2")
- if len(devs) != 1 || devs[0].MAC != neighbour || devs[0].WanSide {
- t.Fatalf("con Networks['wan']='on' solo debe entrar el vecino (%s) como cliente normal (WanSide=false): %+v", neighbour, devs)
- }
- }
- // Una MAC solo-IPv6 cuya interfaz (reportada en arpDevs tras el recheck NDP) es
- // el uplink de la unidad no se cuenta como cliente en modo automático.
- func TestClientDiscoveryIPv6OnlyOnWanSkippedInAuto(t *testing.T) {
- l := NewLive(nil, nil, nil, nil)
- polled := map[string]*routerPolled{
- "travel": {
- cfg: RouterConfig{ID: "travel", Name: "travel", Host: "192.168.2.1"},
- uplinkDevs: []string{"phy1-sta0"},
- arp: map[string]string{"BB:BB:BB:00:00:77": "fe80::1"},
- arpDevs: map[string]string{"BB:BB:BB:00:00:77": "phy1-sta0"},
- },
- }
- if devs := l.buildDevices(polled, ""); len(devs) != 0 {
- t.Fatalf("un vecino solo-IPv6 en el uplink no debe ser cliente en automático: %+v", devs)
- }
- }
- // Sin netIfaces (agente antiguo o equipo no-OpenWrt), RouterDetail.Discovery
- // produce exactamente las filas device de respaldo, ordenadas por nombre.
- func TestRouterDetailDiscoveryRowsOldAgent(t *testing.T) {
- cfg := RouterConfig{
- ID: "travel",
- Name: "travel",
- Host: "192.168.2.1",
- DiscoveryOverrides: DiscoveryOverrides{
- Devices: map[string]DiscoveryMode{
- "eth2": "off",
- "phy1-sta0": "on",
- },
- },
- }
- l := liveTestLive()
- l.SetRouters([]RouterConfig{
- {ID: "gw", Name: "gw", Host: "192.168.1.1", IsGateway: true},
- cfg,
- })
- // Unidad aún no sondeada -> Discovery es nil.
- detBefore, err := l.GetRouterDetail(context.Background(), "travel")
- if err != nil || detBefore == nil {
- t.Fatalf("GetRouterDetail sin sondeo: det=%+v err=%v", detBefore, err)
- }
- if detBefore.Discovery != nil {
- t.Fatalf("Discovery sin sondeo debe ser nil: %+v", detBefore.Discovery)
- }
- l.mu.Lock()
- l.lastPolled["travel"] = &routerPolled{
- cfg: cfg,
- uplinkDevs: []string{"phy1-sta0", "wan0"},
- arp: map[string]string{
- "AA:BB:CC:00:00:01": "192.168.2.10", // confirmada en br-lan
- "AA:BB:CC:00:00:02": "192.168.2.11", // confirmada en br-lan
- "AA:BB:CC:00:00:03": "192.168.2.12", // stale en br-lan (no cuenta)
- "AA:BB:CC:00:00:04": "10.20.0.1", // confirmada en phy1-sta0
- },
- arpStale: map[string]bool{
- "AA:BB:CC:00:00:03": true,
- },
- arpDevs: map[string]string{
- "AA:BB:CC:00:00:01": "br-lan",
- "AA:BB:CC:00:00:02": "br-lan",
- "AA:BB:CC:00:00:03": "br-lan",
- "AA:BB:CC:00:00:04": "phy1-sta0",
- },
- }
- l.mu.Unlock()
- det, err := l.GetRouterDetail(context.Background(), "travel")
- if err != nil || det == nil {
- t.Fatalf("GetRouterDetail: det=%+v err=%v", det, err)
- }
- want := []DiscoveryIface{
- {Kind: "device", Name: "br-lan", Mode: "auto", Auto: true, Effective: true, Neighbours: 2},
- {Kind: "device", Name: "eth2", Mode: "off", Auto: true, Effective: false, Neighbours: 0},
- {Kind: "device", Name: "phy1-sta0", Mode: "on", Auto: false, Effective: true, Neighbours: 1},
- {Kind: "device", Name: "wan0", Mode: "auto", Auto: false, Effective: false, Neighbours: 0},
- }
- if !reflect.DeepEqual(det.Discovery, want) {
- t.Fatalf("Discovery:\ngot %+v\nwant %+v", det.Discovery, want)
- }
- }
- // Un override guardado de una red que ahora no se reporta (un tether USB
- // desenchufado) sigue teniendo fila: si no, guardar otra fila desde el panel
- // lo borraría sin avisar.
- func TestBuildDiscoveryIfacesKeepsSavedMissingNetworkOverride(t *testing.T) {
- p := travelPolled(DiscoveryOverrides{
- Networks: map[string]DiscoveryMode{
- "wwan": DiscoveryOn,
- "usb0": DiscoveryOff, // red guardada, temporalmente ausente de netIfaces
- },
- })
- rows := buildDiscoveryIfaces(p)
- found := false
- for _, r := range rows {
- if r.Kind == DiscoveryKindNetwork && r.Name == "usb0" {
- found = true
- if r.Mode != DiscoveryOff || r.Effective {
- t.Fatalf("fila usb0 esperada mode=off effective=false, got %+v", r)
- }
- }
- }
- if !found {
- t.Fatalf("buildDiscoveryIfaces omitió el override guardado de la red ausente usb0: %+v", rows)
- }
- }
- // Las interfaces del uplink valen aunque la unidad no sea el gateway y no
- // traiga wanInfo (sondeo SSH de una unidad que no es gateway).
- func TestBuildDevicesSkipsArpOnUplinkDevs(t *testing.T) {
- l := NewLive(nil, nil, nil, nil)
- polled := map[string]*routerPolled{
- "travel": {
- cfg: RouterConfig{ID: "travel", Name: "travel", Host: "192.168.2.1"},
- uplinkDevs: []string{"phy1-sta0", "phy1-sta0"},
- arp: map[string]string{
- "AA:BB:CC:00:00:01": "10.20.0.177",
- "AA:BB:CC:00:00:02": "192.168.2.50",
- },
- arpDevs: map[string]string{
- "AA:BB:CC:00:00:01": "phy1-sta0",
- "AA:BB:CC:00:00:02": "br-lan",
- },
- },
- }
- devs := l.buildDevices(polled, "")
- if len(devs) != 1 || devs[0].MAC != "AA:BB:CC:00:00:02" {
- t.Fatalf("esperaba solo el vecino de la LAN, got %+v", devs)
- }
- }
- // Un push event-driven (solo wireless + ARP, sin sección WAN) conserva las
- // interfaces del uplink del último push completo: si no, sus vecinos salían
- // como clientes cableados en cada asociación Wi-Fi.
- func TestPolledFromAgentKeepsUplinkDevsOnEventPush(t *testing.T) {
- l := NewLive(nil, nil, []RouterConfig{{ID: "travel", Host: "192.0.2.3", Name: "travel", AgentOnly: true}}, nil)
- full := &probe.Payload{Router: "travel", Ts: 1, Version: "3.0.49",
- Data: probe.PayloadData{Wan: &probe.WanInfo{Proto: "dhcp", Device: "phy1-sta0", Port: "phy1-sta0"}}}
- _ = l.polledFromAgent(l.routers[0], full)
- event := &probe.Payload{Router: "travel", Ts: 2, Version: "3.0.49"}
- p := l.polledFromAgent(l.routers[0], event)
- if !arpUplinkDevs(p)["phy1-sta0"] {
- t.Fatalf("el push event-driven perdió el uplink: %+v", p.uplinkDevs)
- }
- if p.wanInfo.Proto != "" {
- t.Fatalf("wanInfo es dirección viva y no se recicla: %+v", p.wanInfo)
- }
- }
- // Un vecino de uplink descartado por descubrimiento no sale como fantasma
- // offline en GetOverview ni en GetDevices, pero conserva su fila previa en
- // device_seen.
- func TestDiscoverySkippedUplinkNeighbourNotGhost(t *testing.T) {
- const (
- uplinkMAC = "0C:EF:15:00:00:30"
- lanMAC = "AA:BB:CC:00:00:02"
- )
- d, err := db.Open(t.TempDir())
- if err != nil {
- t.Fatalf("db.Open: %v", err)
- }
- defer d.Close()
- for _, mac := range []string{uplinkMAC, lanMAC} {
- if _, err := d.Exec(`INSERT INTO device_seen (mac, first_seen, last_seen, name) VALUES (?, 1, 1, '')`, mac); err != nil {
- t.Fatalf("sembrar %s: %v", mac, err)
- }
- }
- routers := []RouterConfig{
- {ID: "gw", Name: "Gateway", Host: "127.0.0.1", SSHPort: 1, IsGateway: true, AgentOnly: true},
- {ID: "travel", Name: "Travel", Host: "192.168.2.1", SSHPort: 1, AgentOnly: true},
- }
- l, reg := newOverviewTestLive(t, d, routers)
- now := time.Now().Unix()
- reg.Ingest(&probe.Payload{
- Router: "gw",
- Ts: now,
- Version: "3.0.51",
- Data: probe.PayloadData{},
- })
- reg.Ingest(&probe.Payload{
- Router: "travel",
- Ts: now,
- Version: "3.0.51",
- Data: probe.PayloadData{
- Wan: &probe.WanInfo{Proto: "dhcp", Device: "phy1-sta0", Port: "phy1-sta0"},
- NetIfaces: travelNetIfaces(),
- Arp: map[string]string{
- uplinkMAC: "10.20.0.177",
- lanMAC: "192.168.2.50",
- },
- ArpDevs: map[string]string{
- uplinkMAC: "phy1-sta0",
- lanMAC: "br-lan",
- },
- },
- })
- ov, err := l.GetOverview(t.Context())
- if err != nil {
- t.Fatalf("GetOverview: %v", err)
- }
- check := func(where string, devs []Device) {
- t.Helper()
- foundLAN := false
- for _, dev := range devs {
- if dev.MAC == uplinkMAC {
- t.Errorf("%s: el vecino de uplink %s no debe aparecer como fantasma: %+v", where, dev.MAC, dev)
- }
- if dev.MAC == lanMAC {
- foundLAN = true
- }
- }
- if !foundLAN {
- t.Errorf("%s: cliente LAN %s ausente", where, lanMAC)
- }
- }
- check("GetOverview", ov.Devices)
- check("GetDevices", l.GetDevices(t.Context()))
- if n := countRows(t, d, "SELECT COUNT(*) FROM device_seen WHERE mac = ? AND first_seen = 1", uplinkMAC); n != 1 {
- t.Errorf("el vecino de uplink %s debe conservar su fila en device_seen (filas=%d)", uplinkMAC, n)
- }
- if n := countRows(t, d, "SELECT COUNT(*) FROM device_seen WHERE mac = ? AND first_seen = 1", lanMAC); n != 1 {
- t.Errorf("el cliente LAN %s debe conservar su fila con first_seen = 1 (filas=%d)", lanMAC, n)
- }
- }
|