summaryrefslogtreecommitdiffstats
path: root/test/util.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2020-05-02 22:34:40 -0400
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2020-05-03 15:21:42 -0400
commit2f1563129ad8d34d365f5ef8620ff76ff7b08e70 (patch)
tree43493a0b1a729d12e04af7c94ddfad86c1d75248 /test/util.py
parent0b0a84c403ba5fb1473f8d34745ad2ce0dbb2d45 (diff)
tests: vpp_interface remove deprecated packed properties
The api no longer requires packed ip addresses. Type: test Change-Id: If67365d86b7c3189f871a58234e99f9c8f875371 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/util.py')
-rw-r--r--test/util.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/test/util.py b/test/util.py
index 39f063e7f15..c86d602d792 100644
--- a/test/util.py
+++ b/test/util.py
@@ -1,6 +1,7 @@
""" test framework utilities """
import abc
+import ipaddress
import socket
from socket import AF_INET6
import six
@@ -50,10 +51,21 @@ def ip4_range(ip4, s, e):
return ("%s.%d" % (tmp, i) for i in range(s, e))
-def ip4n_range(ip4n, s, e):
- ip4 = socket.inet_ntop(socket.AF_INET, ip4n)
- return (socket.inet_pton(socket.AF_INET, ip)
- for ip in ip4_range(ip4, s, e))
+def mcast_ip_to_mac(ip):
+ ip = ipaddress.ip_address(ip)
+ if not ip.is_multicast:
+ raise ValueError("Must be multicast address.")
+ ip_as_int = int(ip)
+ if ip.version == 4:
+ mcast_mac = "01:00:5e:%02x:%02x:%02x" % ((ip_as_int >> 16) & 0x7f,
+ (ip_as_int >> 8) & 0xff,
+ ip_as_int & 0xff)
+ else:
+ mcast_mac = "33:33:%02x:%02x:%02x:%02x" % ((ip_as_int >> 24) & 0xff,
+ (ip_as_int >> 16) & 0xff,
+ (ip_as_int >> 8) & 0xff,
+ ip_as_int & 0xff)
+ return mcast_mac
# wrapper around scapy library function.