4
0

classify_test.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package adapters
  2. import "testing"
  3. func TestGuessDeviceType(t *testing.T) {
  4. cases := []struct {
  5. hostname, manufacturer, vendorClass, clientID, lldpCaps, want string
  6. }{
  7. {"iPhone-de-Nacho", "", "", "", "", "movil"},
  8. {"pixel-8-pro", "", "", "", "", "movil"},
  9. {"MacBook-Air", "", "", "", "", "portatil"},
  10. {"thinkpad-x1", "", "", "", "", "portatil"},
  11. {"kindle-paperwhite", "", "", "", "", "tablet"},
  12. {"iPad-de-casa", "", "", "", "", "tablet"},
  13. {"shield", "", "", "", "", "tv"},
  14. {"lg-webos-tv", "", "", "", "", "tv"},
  15. {"ps5-salon", "", "", "", "", "consola"},
  16. {"heos5", "", "", "", "", "altavoz"},
  17. {"sonos-cocina", "", "", "", "", "altavoz"},
  18. {"marantz-av", "", "", "", "", "altavoz"},
  19. {"jellyfin", "", "", "", "", "servidor"},
  20. {"transmission", "", "", "", "", "servidor"},
  21. {"homeassistant", "", "", "", "", "servidor"},
  22. {"raspberry-pi", "", "", "", "", "servidor"}, // aditivo: raspberry sigue en servidor
  23. {"rpi4", "", "", "", "", "servidor"},
  24. {"orangepi5", "", "", "", "", "placa"},
  25. {"nanopi-neo", "", "", "", "", "placa"},
  26. {"bananapi-m2", "", "", "", "", "placa"},
  27. {"rockpi-4c", "", "", "", "", "placa"},
  28. {"pihole-lan", "", "", "", "", "servidor"}, // aditivo: pihole sigue en servidor
  29. {"sbc-lab", "", "", "", "", "placa"},
  30. {"sbcglobal-01", "", "", "", "", "desconocido"}, // "sbc" interno no casa
  31. {"mac-mini-salon", "", "", "", "", "ordenador"}, // "mac-" contiene "ac-"
  32. {"pc-sobremesa", "", "", "", "", "ordenador"},
  33. {"imac-estudio", "", "", "", "", "ordenador"},
  34. {"switch-netgear", "", "", "", "", "switch"},
  35. {"gs308e", "", "", "", "", "switch"},
  36. {"roomba960", "", "", "", "", "aspirador"},
  37. {"roborock-s8-max", "", "", "", "", "aspirador"},
  38. {"deebot-n8", "", "", "", "", "aspirador"},
  39. {"switchbot-k10-pro", "", "", "", "", "aspirador"},
  40. {"zhirui-4c0268", "", "", "", "", "iot"},
  41. {"cargador-coche", "", "", "", "", "iot"},
  42. {"slzb-06m", "", "", "", "", "iot"},
  43. {"camara-porche", "", "", "", "", "camara"},
  44. {"esp32-cam-taller", "", "", "", "", "camara"},
  45. {"cctv-garaje", "", "", "", "", "camara"},
  46. {"doorbell-entrada", "", "", "", "", "videoportero"},
  47. {"timbre-salon", "", "", "", "", "videoportero"},
  48. {"ac-salon", "", "", "", "", "iot"}, // aditivo: "ac-" sigue en iot
  49. {"minisplit-hab", "", "", "", "", "clima"},
  50. {"aire-acondicionado-dormitorio", "", "", "", "", "clima"},
  51. {"clima-estudio", "", "", "", "", "clima"},
  52. {"fujitsu-split-salon", "", "", "", "", "clima"},
  53. {"aireacondicionado-2", "", "", "", "", "clima"},
  54. {"acme-router", "", "", "", "", "desconocido"}, // "ac" interno no casa
  55. {"caldera-gas", "", "", "", "", "iot"}, // aditivo: "caldera" sigue en iot
  56. {"calefaccion-suelo", "", "", "", "", "caldera"},
  57. {"calefacción-central", "", "", "", "", "caldera"}, // con tilde
  58. {"gas-boiler", "", "", "", "", "caldera"},
  59. {"radiador-bano", "", "", "", "", "caldera"},
  60. {"water-heater", "", "", "", "", "caldera"},
  61. {"termo-agua", "", "", "", "", "iot"}, // termo sigue en iot
  62. {"sonoff-mini", "", "", "", "", "iot"},
  63. {"A4:CF:12:9A:01:02", "", "", "", "", "desconocido"}, // MAC como nombre
  64. {"", "", "", "", "", "desconocido"},
  65. {"", "Espressif Inc.", "", "", "", "iot"},
  66. {"", "Tuya Smart Inc.", "", "", "", "iot"},
  67. // vendor class (option 60)
  68. {"", "", "android-dhcp-13", "", "", "movil"},
  69. {"", "", "MSFT 5.0", "", "", "ordenador"},
  70. {"", "", "Windows", "", "", "ordenador"},
  71. // client-id
  72. {"", "", "", "raspberrypi", "", "servidor"},
  73. {"", "", "", "01:raspberry-pi", "", "servidor"},
  74. // lldp caps
  75. {"", "", "", "", "bridge", "switch"},
  76. {"", "", "", "", "bridge, router", "desconocido"},
  77. {"", "", "", "", "bridge, wlan", "switch"},
  78. {"", "", "", "", "wlan", "switch"},
  79. // el hostname manda sobre el resto de señales
  80. {"macbook-air", "", "MSFT 5.0", "", "", "portatil"},
  81. }
  82. for _, c := range cases {
  83. if got := GuessDeviceType(c.hostname, c.manufacturer, c.vendorClass, c.clientID, c.lldpCaps); got != c.want {
  84. t.Errorf("GuessDeviceType(%q, %q, %q, %q, %q) = %q, esperaba %q", c.hostname, c.manufacturer, c.vendorClass, c.clientID, c.lldpCaps, got, c.want)
  85. }
  86. }
  87. }
  88. // The devices that came back unclassified from a real network, and what
  89. // each one now resolves to.
  90. func TestGuessDeviceTypeOnTheGapsFoundLive(t *testing.T) {
  91. for _, tc := range []struct{ name, hostname, manufacturer, want string }{
  92. {"smart bulb", "bulb_1a2b3c", "WiZ", "iot"},
  93. {"air conditioner", "gree", "Gree Electric Appliances,Inc. of Zhuhai", "iot"},
  94. {"connected oven", "oven-0000000000000", "BSH Hausgeräte GmbH", "iot"},
  95. // Xiaomi sells phones AND appliances under the same OUI, so the
  96. // vendor cannot decide it; the name can.
  97. {"air purifier", "AirPurifierBedroom", "Beijing Xiaomi Mobile Software", "iot"},
  98. {"a Xiaomi that is not an appliance", "mi-9t", "Beijing Xiaomi Mobile Software", "desconocido"},
  99. // A recorder is a camera, not a generic gadget.
  100. {"recorder by name", "NVR", "", "camara"},
  101. {"recorder by vendor", "", "Reolink Innovation Limited", "camara"},
  102. } {
  103. if got := GuessDeviceType(tc.hostname, tc.manufacturer, "", "", ""); got != tc.want {
  104. t.Errorf("%s: got %q, want %q", tc.name, got, tc.want)
  105. }
  106. }
  107. }
  108. // #1495: las familias de hostname de ONT se clasifican como modem; nombres
  109. // normales de la LAN no (sin adivinar por fabricante a secas).
  110. func TestGuessDeviceTypeModem(t *testing.T) {
  111. for _, h := range []string{"ZXHN-G7615V2", "f660-v6", "EG8145V5", "onu-router"} {
  112. if got := GuessDeviceType(h, "", "", "", ""); got != "modem" {
  113. t.Errorf("%s: got %q, want modem", h, got)
  114. }
  115. }
  116. for _, h := range []string{"desktop-front", "webcam", "iphone-de-nacho"} {
  117. if got := GuessDeviceType(h, "", "", "", ""); got == "modem" {
  118. t.Errorf("%s: no debe clasificarse como modem", h)
  119. }
  120. }
  121. }