diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 2447e73..7d4e9c9 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -2191,3 +2191,75 @@ def dest_file_system(self): if self.device and self._dest_file_system is None: self._dest_file_system = self._discover_file_system() return self._dest_file_system + + def get_ipv6_neighbors_table(self): + """ + Get IPv6 neighbors table information. + + Return a list of dictionaries having the following set of keys: + * interface (string) + * mac (string) + * ip (string) + * age (float) + * state (string) + + For example:: + [ + { + 'interface' : 'MgmtEth0/RSP0/CPU0/0', + 'mac' : '5c:5e:ab:da:3c:f0', + 'ip' : '2001:db8:1:1::1', + 'age' : 1454496274.84, + 'state' : 'REACH' + }, + { + 'interface': 'MgmtEth0/RSP0/CPU0/0', + 'mac' : '66:0e:94:96:e0:ff', + 'ip' : '2001:db8:1:1::2', + 'age' : 1435641582.49, + 'state' : 'STALE' + } + ] + """ + ipv6_neighbors_table = [] + + command = 'show ipv6 neighbors' + output = self._send_command(command) + + # Skip the first line which is a header + output = output.split('\n') + output = output[1:] + + for line in output: + if len(line) == 0: + return {} + if len(line.split()) == 5: + address, age, mac, state, interface = line.split() + else: + raise ValueError("Unexpected output from: {}".format(line.split())) + + # 2001:DB8:1:2::3:4 0 - INCMP Gi0/0/2 + if mac == '-' and state == 'INCMP': + continue + + try: + if age == '-': + age = 0 + age = float(age) * 60 + except ValueError: + raise ValueError("Unable to convert age value to float: {}".format(age)) + + # Validate we matched correctly + if not re.search(IPV6_ADDR_REGEX, address): + raise ValueError("Invalid IPv6 Address detected: {}".format(address)) + if not re.search(RE_MAC, mac): + raise ValueError("Invalid MAC Address detected: {}".format(mac)) + entry = { + 'interface': interface, + 'mac': napalm_base.helpers.mac(mac), + 'ip': address, + 'age': age, + 'state': state + } + ipv6_neighbors_table.append(entry) + return ipv6_neighbors_table diff --git a/test/unit/mocked_data/test_get_ipv6_neighbors_table/normal/expected_result.json b/test/unit/mocked_data/test_get_ipv6_neighbors_table/normal/expected_result.json new file mode 100644 index 0000000..2b49284 --- /dev/null +++ b/test/unit/mocked_data/test_get_ipv6_neighbors_table/normal/expected_result.json @@ -0,0 +1,19 @@ +[{ + "interface": "Ethernet2", + "ip": "2000:0:0:4::2", + "mac": "00:03:A0:D6:14:1E", + "age": 60, + "state": "REACH" +}, { + "interface": "Ethernet2", + "ip": "FE80::203:A0FF:FED6:141E", + "mac": "00:03:A0:D6:14:1E", + "age": 0, + "state": "REACH" +}, { + "interface": "Ethernet2", + "ip": "3001:1::45a", + "mac": "00:02:7D:1A:94:72", + "age": 0, + "state": "REACH" +}] diff --git a/test/unit/mocked_data/test_get_ipv6_neighbors_table/normal/show_ipv6_neighbors.txt b/test/unit/mocked_data/test_get_ipv6_neighbors_table/normal/show_ipv6_neighbors.txt new file mode 100644 index 0000000..2827817 --- /dev/null +++ b/test/unit/mocked_data/test_get_ipv6_neighbors_table/normal/show_ipv6_neighbors.txt @@ -0,0 +1,4 @@ +IPv6 Address Age Link-layer Addr State Interface +2000:0:0:4::2 1 0003.a0d6.141e REACH Ethernet2 +FE80::203:A0FF:FED6:141E 0 0003.a0d6.141e REACH Ethernet2 +3001:1::45a - 0002.7d1a.9472 REACH Ethernet2