summaryrefslogtreecommitdiff
path: root/haircontrol/discovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'haircontrol/discovery.py')
-rw-r--r--haircontrol/discovery.py119
1 files changed, 102 insertions, 17 deletions
diff --git a/haircontrol/discovery.py b/haircontrol/discovery.py
index 7c3c9f0..d6839b2 100644
--- a/haircontrol/discovery.py
+++ b/haircontrol/discovery.py
@@ -5,16 +5,77 @@ from haircontrol.inspectors import *
class Discovery:
def __init__(self): #, inspector):
- # XXX Use only one Inspector
+ self.net = EtherDomain()
+ self.dummy_inspector = DummyInspector()
self.linux_inspector = LinuxInspector()
self.ubnt_inspector = UbntInspector()
self.toughswitch_inspector = ToughSwitchInspector()
- self.net = EtherDomain()
+ self.edgemax_inspector = EdgeMaxInspector()
+ self.netonix_inspector = NetonixInspector()
+ self.mikrotik_inspector = MikrotikInspector()
+ self.openwrt_inspector = OpenWRTInspector()
+
+ self.inspector_by_mac = {
+ # Mikrotik
+ 'd4:ca:6d': self.mikrotik_inspector,
+ 'e4:8d:8c': self.mikrotik_inspector,
+ # Netonix
+ 'ec:13:b2': self.netonix_inspector,
+ 'ec:13:b3': self.netonix_inspector,
+ # PC
+ '0c:c4:7a': self.linux_inspector, # SuperMicro
+ '52:54:00': self.linux_inspector, # VM
+ # TP-Link
+ '10:fe:ed': self.openwrt_inspector,
+ '14:cc:20': self.openwrt_inspector,
+ '30:b5:c2': self.openwrt_inspector,
+ '54:e6:fc': self.openwrt_inspector,
+ '60:e3:27': self.openwrt_inspector,
+ '64:66:b3': self.openwrt_inspector,
+ '64:70:02': self.openwrt_inspector,
+ '90:f6:52': self.openwrt_inspector,
+ 'a0:f3:c1': self.openwrt_inspector,
+ 'b0:48:7a': self.openwrt_inspector,
+ 'c0:4a:00': self.openwrt_inspector,
+ 'c4:6e:1f': self.openwrt_inspector,
+ 'c4:e9:84': self.openwrt_inspector,
+ 'f4:ec:38': self.openwrt_inspector,
+ 'f8:1a:67': self.openwrt_inspector,
+ 'f8:d1:11': self.openwrt_inspector,
+ # Ubnt
+ '00:15:6d': self.ubnt_inspector,
+ '00:27:22': self.ubnt_inspector,
+ '04:18:d6:07': self.toughswitch_inspector,
+ '04:18:d6': self.ubnt_inspector,
+ '06:18:d6': self.ubnt_inspector, # Non globaly unique ?!
+ '24:a4:3c:05': self.toughswitch_inspector,
+ '24:a4:3c:06': self.toughswitch_inspector,
+ '24:a4:3c:07': self.toughswitch_inspector,
+ '24:a4:3c:3c': self.toughswitch_inspector,
+ '24:a4:3c:3d': self.toughswitch_inspector,
+ '24:a4:3c:b3': self.toughswitch_inspector,
+ '24:a4:3c': self.ubnt_inspector,
+ '44:d9:e7': self.edgemax_inspector,
+ 'dc:9f:db:80': self.toughswitch_inspector,
+ 'dc:9f:db:81': self.toughswitch_inspector,
+ 'dc:9f:db': self.ubnt_inspector,
+ }
+
+
+ def inspector(self, mac):
+ if mac:
+ return self.inspector_by_mac.get(mac[:11]) \
+ or self.inspector_by_mac.get(mac[:8]) \
+ or self.dummy_inspector
+ else:
+ return self.dummy_inspector
+
def discover_static_hinting(self, name_ip_tuples):
for name, ip in name_ip_tuples:
self.net.add_equipment(Equipment(name, ip))
+
def discover_lldp_hinting(self, e_lldp):
self.net.add_equipment(e_lldp)
self.linux_inspector.connect(e_lldp)
@@ -37,6 +98,7 @@ class Discovery:
self.linux_inspector.disconnect()
+
def discover_from_root(self, e_root):
self.net.add_equipment(e_root)
self.linux_inspector.connect(e_root)
@@ -49,7 +111,8 @@ class Discovery:
self.linux_inspector.disconnect()
- # Create Equipment object for all neighbours (if not already previously done by hinting)
+ # Create/Update Equipment object for all neighbours
+ # (could be already created by hinting)
for iface in e_root.ifaces.values():
local_ifname = iface.name
local_mac = iface.mac
@@ -57,10 +120,13 @@ class Discovery:
remote_ip = self.net.mac2ip.get(remote_mac)
if remote_ip:
e = self.net.equipments.get(remote_ip)
- if not e:
+ if e and not e.ifaces:
+ e.add_iface(None, remote_mac)
+ elif not e:
e = Equipment('?', remote_ip)
e.add_iface('?', remote_mac)
self.net.add_equipment(e)
+
# Inspect all non-already inspected equipement
done = False
@@ -69,28 +135,47 @@ class Discovery:
for ip,e in self.net.equipments.items():
if not e.inspected:
done = False
- # Inspect antennas bridge tables
- if ip.startswith('172.16.1'): # XXX Filter with OUI
- self.ubnt_inspector.connect(e)
+
+ # Find the right inspector from equipment's first iface mac address
+ if e.ifaces:
+ e_first_mac = next(iter(e.ifaces.values())).mac
+ i = self.inspector(e_first_mac)
+ else:
+ # XXX Custom hack
+ if e.mgmtip.startswith('172.16.1'):
+ i = self.ubnt_inspector
+ elif e.mgmtip == '172.16.30.23':
+ i = self.edgemax_inspector
+ elif e.mgmtip.startswith('172.16.3'):
+ i = self.toughswitch_inspector
+ else:
+ i = self.dummy_inspector
+
+ i.connect(e)
+
+ # Inspect antennas
+ if isinstance(i, UbntInspector):
# Learn local interfaces
- result = self.ubnt_inspector.command('status.cgi')
+ result = i.command('status.cgi')
for (ifname, mac) in result:
if ifname not in [ 'lo', 'wifi0', 'br0' ]: # XXX configurable filter
e.add_iface(ifname, mac)
# Learn bridge tables
- result = self.ubnt_inspector.command('brmacs.cgi')
+ result = i.command('brmacs.cgi')
for (ifname, mac) in result:
e.add_seen_mac(ifname, mac)
- self.ubnt_inspector.disconnect()
+
# Inspect switches
- elif ip.startswith('172.16.3'): # XXX Filter with OUI
- self.toughswitch_inspector.connect(e)
- result = self.toughswitch_inspector.command('mactable_data.cgi')
+ elif isinstance(i, ToughSwitchInspector):
+ result = i.command('mactable_data.cgi')
for (ifname, mac) in result:
e.add_seen_mac(ifname, mac)
- self.toughswitch_inspector.disconnect()
- # Flag unknowns as inspected (and warn)
+
+ elif isinstance(i, EdgeMaxInspector):
+ result = i.command('mac-addr-table')
+ for (mac, ifname) in result:
+ e.add_seen_mac(ifname, mac)
else:
- e.inspected = 'cannot'
- print("Notice: Unimplemented inspector for %s"%e)
+ print("Notice: Nothing inspected on %s"%e)
+ i.disconnect()