probe_1949_lan_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // probe_1949_lan_test.go — AP con una sola boca física: su uplink es la LAN y
  2. // no debe salir como WAN (#1949). El AP multi-boca conserva la atribución del
  3. // miembro que mira al core (#1500).
  4. package probe
  5. import "testing"
  6. // WAX220: board.json solo declara la LAN (device eth0), así que no hay layout
  7. // de puertos y manda el fallback. Una boca física es eth0 dentro de br-lan.
  8. func TestBuildEthPortsSinglePortApKeepsItsName(t *testing.T) {
  9. layout, err := ParsePortLayout(`{"network":{"lan":{"device":"eth0","protocol":"static"}}}`)
  10. if err != nil {
  11. t.Fatalf("layout: %v", err)
  12. }
  13. if len(layout) != 0 {
  14. t.Fatalf("este board.json no declara puertos, layout = %+v", layout)
  15. }
  16. states := ParsePortStates("br-lan up 1000\neth0 up 2500 - 1 -\n")
  17. ifaces := map[string]IfRate{"eth0": {IfCounters: IfCounters{Rx: 190045434383, Tx: 1866622728826}}}
  18. for _, uplink := range []string{"br-lan", "eth0"} {
  19. ports := BuildEthPorts(layout, states, map[string]bool{"eth0": true}, ifaces, uplink)
  20. if len(ports) != 1 {
  21. t.Fatalf("uplink %q: una sola boca física, got %+v", uplink, ports)
  22. }
  23. if ports[0].ID != "eth0" || ports[0].Label != "ETH 0" {
  24. t.Fatalf("uplink %q: la boca debía llamarse ETH 0, got %+v", uplink, ports[0])
  25. }
  26. if ports[0].RxBytes != 190045434383 {
  27. t.Fatalf("uplink %q: las estadísticas son de eth0, got %+v", uplink, ports[0])
  28. }
  29. }
  30. }
  31. // Control de #1500: con varias bocas el miembro del bridge que mira al core
  32. // sigue saliendo como WAN, que es lo que distingue el uplink del resto.
  33. func TestBuildEthPortsMultiPortApKeepsUplinkAsWan(t *testing.T) {
  34. states := ParsePortStates("br0 up 1000\neth0 up 2500 - 1 -\neth1 up 1000 - 1 -\neth3 up 1000 - 1 -\n")
  35. members := map[string]bool{"eth0": true, "eth1": true, "eth3": true}
  36. ifaces := map[string]IfRate{
  37. "eth0": {IfCounters: IfCounters{Rx: 188583580}},
  38. "eth3": {IfCounters: IfCounters{Rx: 619101463}},
  39. }
  40. ports := BuildEthPorts(nil, states, members, ifaces, "eth0")
  41. if len(ports) != 3 {
  42. t.Fatalf("bocas: %+v", ports)
  43. }
  44. if ports[0].ID != "wan" || ports[0].Iface != "eth0" {
  45. t.Fatalf("el uplink del AP multi-boca sigue siendo WAN: %+v", ports[0])
  46. }
  47. }