Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3936819
D3077.id7852.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3077.id7852.diff
View Options
diff --git a/_modules/network_utils.py b/_modules/network_utils.py
--- a/_modules/network_utils.py
+++ b/_modules/network_utils.py
@@ -8,6 +8,7 @@
# -------------------------------------------------------------
+import ipaddress
import re
@@ -44,3 +45,20 @@
#
# There is 24 "1" in this expression, that's 24 is our CIDR prefix.
return sum([bin(int(octet)).count("1") for octet in netmask.split(".")])
+
+
+# -------------------------------------------------------------
+# IPv6 prefixes
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def _ipv6_address_to_prefix(address, prefixlen):
+ return ipaddress.IPv6Network((address, prefixlen), strict=False)
+
+
+def can_directly_be_discovered(gateway, address, prefixlen):
+ """Determines if the gateway belong to the same prefix than the address,
+ and so can be directly be discovered in NDP."""
+ return _ipv6_address_to_prefix(gateway, prefixlen) == _ipv6_address_to_prefix(
+ address, prefixlen
+ )
diff --git a/_tests/modules/test_network.py b/_tests/modules/test_network.py
--- a/_tests/modules/test_network.py
+++ b/_tests/modules/test_network.py
@@ -48,6 +48,28 @@
def test_is_valid_netmask_when_it_is_not(self, netmask):
self.assertFalse(network.is_valid_netmask(netmask))
+ def test_ipv6_address_to_prefix(self):
+ prefix = network._ipv6_address_to_prefix(
+ "2001:41d0:0303:d9ff:00ff:00ff:00ff:00ff", 64
+ )
+ self.assertEqual("2001:41d0:303:d9ff::", prefix.network_address.compressed)
+
+ def test_can_directly_be_discovered(self):
+ self.assertFalse(
+ network.can_directly_be_discovered(
+ "2001:41d0:0303:d9ff:00ff:00ff:00ff:00ff",
+ "2001:41d0:303:d971::517e:c0de",
+ 64,
+ )
+ )
+ self.assertTrue(
+ network.can_directly_be_discovered(
+ "2001:41d0:0303:d971:00ff:00ff:00ff:00ff",
+ "2001:41d0:303:d971::517e:c0de",
+ 64,
+ )
+ )
+
if __name__ == "__main__":
unittest.main()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 13:33 (19 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2313873
Default Alt Text
D3077.id7852.diff (2 KB)
Attached To
Mode
D3077: Allow to determine IPv6 routing strategy
Attached
Detach File
Event Timeline
Log In to Comment