Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

get_ipv6_neighbors_table() #199

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions napalm_ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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"
}]
Original file line number Diff line number Diff line change
@@ -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