From c705d2afe8be8abfa385eeb434c4271209f731a9 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Thu, 9 Jun 2016 21:52:13 +0200 Subject: Inspector : parse ip link and show version for switches. Discovery : use switch mac for each ports. --- haircontrol/discovery.py | 18 +++++++++++++++--- haircontrol/inspectors.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/haircontrol/discovery.py b/haircontrol/discovery.py index a9639be..3180ace 100644 --- a/haircontrol/discovery.py +++ b/haircontrol/discovery.py @@ -167,13 +167,25 @@ class Discovery: # Inspect switches elif isinstance(i, ToughSwitchInspector): - result = i.command('mactable_data.cgi') - for (ifname, mac) in result: - e.add_seen_mac(ifname, mac) + result = i.command('ip-link') + switch_mac = '?' + for (ifname, mac) in result: + if ifname == 'br0': # XXX configurable filter + switch_mac = mac + result = i.command('mactable_data.cgi') + for (ifname, mac) in result: + e.add_iface(ifname, switch_mac) # XXX many non-usefull calls + e.add_seen_mac(ifname, mac) elif isinstance(i, EdgeMaxInspector): + switch_mac = '?' + result = i.command('show-version') + for (key, value) in result: + if key == 'Burned In MAC Address': + switch_mac = value result = i.command('mac-addr-table') for (mac, ifname) in result: + e.add_iface(ifname, switch_mac) # XXX many non-usefull calls e.add_seen_mac(ifname, mac) else: print("Notice: Nothing inspected on %s"%e) diff --git a/haircontrol/inspectors.py b/haircontrol/inspectors.py index 04b05c1..c5c6940 100644 --- a/haircontrol/inspectors.py +++ b/haircontrol/inspectors.py @@ -180,6 +180,13 @@ class ToughSwitchInspector(Inspector): 'cmd':'/usr/www/mactable_data.cgi', 'func': parse_mactable_data_cgi }, + 'ip-link': { + 'cmd': 'ip -o link', + 'kind': 'text', + 're': re.compile("\d+:\s+(?P[^:]*):.+\s+(?:link/ether\s+(?P[a-f0-9:]*)\s+brd|link/none)") + # 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default \ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + # 2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000\ link/ether 8c:89:a5:c7:be:88 brd ff:ff:ff:ff:ff:ff + }, } class EdgeMaxInspector(Inspector): @@ -192,6 +199,11 @@ class EdgeMaxInspector(Inspector): # 1 00:15:6D:8E:22:46 0/15 15 Learned # 1 00:27:22:0E:67:F9 0/17 17 Learned }, + 'show-version': { + 'cmd':'show version', #XXX needs "enable" mode + 're': re.compile("(?P[^\.]+)\.+ (?P.*)") + # Burned In MAC Address.......................... 44:D9:E7:51:BF:A7 + }, } #TODO Implement them -- cgit v1.1