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

interfaces_ip primary IP check #206

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
26 changes: 19 additions & 7 deletions napalm_base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,42 +796,54 @@ def get_interfaces_ip(self):
addresses as keys.
Each IP Address dictionary has the following keys:
* prefix_length (int)
* primary_ip (boolean)

Example::

{
u'FastEthernet8': {
u'ipv4': {
u'10.66.43.169': {
'prefix_length': 22
'prefix_length': 22,
'primary_ip': True
},
u'10.66.50.1': {
'prefix_length': 24,
'primary_ip': False
}
}
},
u'Loopback555': {
u'ipv4': {
u'192.168.1.1': {
'prefix_length': 24
'prefix_length': 24,
'primary_ip': True
}
},
u'ipv6': {
u'1::1': {
'prefix_length': 64
'prefix_length': 64,
'primary_ip': False
},
u'2001:DB8:1::1': {
'prefix_length': 64
'prefix_length': 64,
'primary_ip': True
Copy link
Member

@dbarrosop dbarrosop Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no concept of primary or secondary ip on IPv6 so I'd hardcode this to True for simplicity.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, so even when a router needs to source an IP, how does it choose which one?

Does it make sense not to include on IPv6 at all?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a whole RFC for that (surprise!): https://tools.ietf.org/html/rfc6724
Actually, IPv4 doesn't have the concept at all either. AFAICT only Cisco has the "secondary" keyword. Juniper certainly doesn't.

Does it make sense not to include on IPv6 at all?

You are probably right. You will have to slightly adapt the test so it uses two different models; one for IPv4 and one for IPv6.

},
u'2::': {
'prefix_length': 64
'prefix_length': 64,
'primary_ip': False
},
u'FE80::3': {
'prefix_length': u'N/A'
'prefix_length': u'N/A',
'primary_ip': False
}
}
},
u'Tunnel0': {
u'ipv4': {
u'10.63.100.9': {
'prefix_length': 24
'prefix_length': 24,
'primary_ip': True
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion napalm_base/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@
}

interfaces_ip = {
'prefix_length': int
'prefix_length': int,
'primary_key': bool
}

mac_address_table = {
Expand Down