diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2020-05-02 22:34:40 -0400 |
---|---|---|
committer | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2020-05-03 15:21:42 -0400 |
commit | 2f1563129ad8d34d365f5ef8620ff76ff7b08e70 (patch) | |
tree | 43493a0b1a729d12e04af7c94ddfad86c1d75248 | |
parent | 0b0a84c403ba5fb1473f8d34745ad2ce0dbb2d45 (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>
-rw-r--r-- | src/plugins/gtpu/test/test_gtpu.py | 11 | ||||
-rw-r--r-- | src/plugins/nat/test/test_nat.py | 26 | ||||
-rw-r--r-- | test/template_classifier.py | 4 | ||||
-rw-r--r-- | test/test_bfd.py | 20 | ||||
-rw-r--r-- | test/test_geneve.py | 9 | ||||
-rw-r--r-- | test/test_ip4_vrf_multi_instance.py | 2 | ||||
-rw-r--r-- | test/test_ip6_vrf_multi_instance.py | 2 | ||||
-rw-r--r-- | test/test_syslog.py | 8 | ||||
-rw-r--r-- | test/test_vxlan.py | 16 | ||||
-rw-r--r-- | test/test_vxlan6.py | 10 | ||||
-rw-r--r-- | test/test_vxlan_gbp.py | 4 | ||||
-rw-r--r-- | test/test_vxlan_gpe.py | 38 | ||||
-rw-r--r-- | test/util.py | 20 | ||||
-rw-r--r-- | test/vpp_interface.py | 36 |
14 files changed, 86 insertions, 120 deletions
diff --git a/src/plugins/gtpu/test/test_gtpu.py b/src/plugins/gtpu/test/test_gtpu.py index 6f5c8e2bdb6..f68c86fbc04 100644 --- a/src/plugins/gtpu/test/test_gtpu.py +++ b/src/plugins/gtpu/test/test_gtpu.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import socket -from util import ip4n_range, ip4_range +from util import ip4_range import unittest from framework import VppTestCase, VppTestRunner from template_bd import BridgeDomain @@ -12,6 +12,8 @@ from scapy.layers.inet import IP, UDP from scapy.layers.inet6 import IPv6 from scapy.contrib.gtp import GTP_U_Header from scapy.utils import atol + +import util from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip import INVALID_INDEX @@ -238,7 +240,7 @@ class TestGtpu(BridgeDomain, VppTestCase): next_hop_address = cls.pg0.remote_ip4 for dest_ip4 in ip4_range(next_hop_address, ip_range_start, ip_range_end): - # add host route so dest_ip4n will not be resolved + # add host route so dest_ip4 will not be resolved rip = VppIpRoute(cls, dest_ip4, 32, [VppRoutePath(next_hop_address, INVALID_INDEX)], @@ -335,10 +337,7 @@ class TestGtpu(BridgeDomain, VppTestCase): # Our Multicast address cls.mcast_ip4 = '239.1.1.1' - cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) - iplong = atol(cls.mcast_ip4) - cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % ( - (iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF) + cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4) # Create GTPU VTEP on VPP pg0, and put gtpu_tunnel0 and pg1 # into BD. diff --git a/src/plugins/nat/test/test_nat.py b/src/plugins/nat/test/test_nat.py index 214daf8a43a..19e4c50e8f0 100644 --- a/src/plugins/nat/test/test_nat.py +++ b/src/plugins/nat/test/test_nat.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import ipaddress import socket import unittest import struct @@ -857,7 +858,8 @@ class MethodHolder(VppTestCase): else: nat44_ses_delete_num += 1 # sourceIPv4Address - self.assertEqual(self.pg0.remote_ip4n, record[8]) + self.assertEqual(self.pg0.remote_ip4, + str(ipaddress.IPv4Address(record[8]))) # postNATSourceIPv4Address self.assertEqual(socket.inet_pton(socket.AF_INET, self.nat_addr), record[225]) @@ -945,7 +947,7 @@ class MethodHolder(VppTestCase): else: self.assertEqual(scapy.compat.orb(record[230]), 11) # sourceIPv6Address - self.assertEqual(src_addr, record[27]) + self.assertEqual(src_addr, str(ipaddress.IPv6Address(record[27]))) # postNATSourceIPv4Address self.assertEqual(self.nat_addr_n, record[225]) # protocolIdentifier @@ -976,7 +978,7 @@ class MethodHolder(VppTestCase): else: self.assertEqual(scapy.compat.orb(record[230]), 7) # sourceIPv6Address - self.assertEqual(src_addr, record[27]) + self.assertEqual(src_addr, str(ipaddress.IPv6Address(record[27]))) # destinationIPv6Address self.assertEqual(socket.inet_pton(socket.AF_INET6, self.compose_ip6(dst_addr, @@ -7973,19 +7975,19 @@ class TestNAT64(MethodHolder): self.vapi.nat64_add_del_interface(is_add=1, flags=0, sw_if_index=self.pg1.sw_if_index) - self.vapi.nat64_add_del_static_bib(i_addr=self.pg0.remote_ip6n, + self.vapi.nat64_add_del_static_bib(i_addr=self.pg0.remote_ip6, o_addr=self.nat_addr, i_port=self.tcp_port_in, o_port=self.tcp_port_out, proto=IP_PROTOS.tcp, vrf_id=0, is_add=1) - self.vapi.nat64_add_del_static_bib(i_addr=self.pg0.remote_ip6n, + self.vapi.nat64_add_del_static_bib(i_addr=self.pg0.remote_ip6, o_addr=self.nat_addr, i_port=self.udp_port_in, o_port=self.udp_port_out, proto=IP_PROTOS.udp, vrf_id=0, is_add=1) - self.vapi.nat64_add_del_static_bib(i_addr=self.pg0.remote_ip6n, + self.vapi.nat64_add_del_static_bib(i_addr=self.pg0.remote_ip6, o_addr=self.nat_addr, i_port=self.icmp_id_in, o_port=self.icmp_id_out, @@ -8876,11 +8878,11 @@ class TestNAT64(MethodHolder): if p.haslayer(Data): data = ipfix.decode_data_set(p.getlayer(Set)) if scapy.compat.orb(data[0][230]) == 10: - self.verify_ipfix_bib(data, 1, self.pg0.remote_ip6n) + self.verify_ipfix_bib(data, 1, self.pg0.remote_ip6) elif scapy.compat.orb(data[0][230]) == 6: self.verify_ipfix_nat64_ses(data, 1, - self.pg0.remote_ip6n, + self.pg0.remote_ip6, self.pg1.remote_ip4, 25) else: @@ -8906,11 +8908,11 @@ class TestNAT64(MethodHolder): if p.haslayer(Data): data = ipfix.decode_data_set(p.getlayer(Set)) if scapy.compat.orb(data[0][230]) == 11: - self.verify_ipfix_bib(data, 0, self.pg0.remote_ip6n) + self.verify_ipfix_bib(data, 0, self.pg0.remote_ip6) elif scapy.compat.orb(data[0][230]) == 7: self.verify_ipfix_nat64_ses(data, 0, - self.pg0.remote_ip6n, + self.pg0.remote_ip6, self.pg1.remote_ip4, 25) else: @@ -9054,7 +9056,7 @@ class TestNAT66(MethodHolder): self.vapi.nat66_add_del_interface(is_add=1, sw_if_index=self.pg1.sw_if_index) self.vapi.nat66_add_del_static_mapping( - local_ip_address=self.pg0.remote_ip6n, + local_ip_address=self.pg0.remote_ip6, external_ip_address=self.nat_addr, is_add=1) @@ -9133,7 +9135,7 @@ class TestNAT66(MethodHolder): self.vapi.nat66_add_del_interface(is_add=1, flags=flags, sw_if_index=self.pg1.sw_if_index) self.vapi.nat66_add_del_static_mapping( - local_ip_address=self.pg0.remote_ip6n, + local_ip_address=self.pg0.remote_ip6, external_ip_address=self.nat_addr, is_add=1) diff --git a/test/template_classifier.py b/test/template_classifier.py index 49cb3b369c3..3ba985bbe33 100644 --- a/test/template_classifier.py +++ b/test/template_classifier.py @@ -406,9 +406,9 @@ class TestClassifier(VppTestCase): """ addr_len = 24 - self.vapi.ip_add_del_route(dst_address=intf.local_ip4n, + self.vapi.ip_add_del_route(dst_address=intf.local_ip4, dst_address_length=addr_len, - next_hop_address=intf.remote_ip4n, + next_hop_address=intf.remote_ip4, table_id=self.pbr_vrfid, is_add=is_add) def verify_vrf(self, vrf_id): diff --git a/test/test_bfd.py b/test/test_bfd.py index e78ad0c4064..67b62766c21 100644 --- a/test/test_bfd.py +++ b/test/test_bfd.py @@ -5,6 +5,7 @@ from __future__ import division import binascii import hashlib +import ipaddress import time import unittest from random import randint, shuffle, getrandbits @@ -283,8 +284,8 @@ class BFDAPITestCase(VppTestCase): self.assertFalse(echo_source.have_usable_ip6) self.loopback0.config_ip4() - unpacked = unpack("!L", self.loopback0.local_ip4n) - echo_ip4 = pack("!L", unpacked[0] ^ 1) + echo_ip4 = ipaddress.IPv4Address(int(ipaddress.IPv4Address( + self.loopback0.local_ip4)) ^ 1).packed echo_source = self.vapi.bfd_udp_get_echo_source() self.assertTrue(echo_source.is_set) self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) @@ -293,9 +294,9 @@ class BFDAPITestCase(VppTestCase): self.assertFalse(echo_source.have_usable_ip6) self.loopback0.config_ip6() - unpacked = unpack("!LLLL", self.loopback0.local_ip6n) - echo_ip6 = pack("!LLLL", unpacked[0], unpacked[1], unpacked[2], - unpacked[3] ^ 1) + echo_ip6 = ipaddress.IPv6Address(int(ipaddress.IPv6Address( + self.loopback0.local_ip6)) ^ 1).packed + echo_source = self.vapi.bfd_udp_get_echo_source() self.assertTrue(echo_source.is_set) self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) @@ -2728,16 +2729,15 @@ class BFDCLITestCase(VppTestCase): "IPv6 address usable as echo source: none" % self.loopback0.name) self.loopback0.config_ip4() - unpacked = unpack("!L", self.loopback0.local_ip4n) - echo_ip4 = inet_ntop(AF_INET, pack("!L", unpacked[0] ^ 1)) + echo_ip4 = str(ipaddress.IPv4Address(int(ipaddress.IPv4Address( + self.loopback0.local_ip4)) ^ 1)) self.cli_verify_response("show bfd echo-source", "UDP echo source is: %s\n" "IPv4 address usable as echo source: %s\n" "IPv6 address usable as echo source: none" % (self.loopback0.name, echo_ip4)) - unpacked = unpack("!LLLL", self.loopback0.local_ip6n) - echo_ip6 = inet_ntop(AF_INET6, pack("!LLLL", unpacked[0], unpacked[1], - unpacked[2], unpacked[3] ^ 1)) + echo_ip6 = str(ipaddress.IPv6Address(int(ipaddress.IPv6Address( + self.loopback0.local_ip6)) ^ 1)) self.loopback0.config_ip6() self.cli_verify_response("show bfd echo-source", "UDP echo source is: %s\n" diff --git a/test/test_geneve.py b/test/test_geneve.py index 7eb23f27f9b..16cb6c26642 100644 --- a/test/test_geneve.py +++ b/test/test_geneve.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import socket -from util import ip4_range, ip4_range +from util import ip4_range import unittest from framework import VppTestCase, VppTestRunner from template_bd import BridgeDomain @@ -9,7 +9,8 @@ from template_bd import BridgeDomain from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP from scapy.contrib.geneve import GENEVE -from scapy.utils import atol + +import util from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip import INVALID_INDEX @@ -176,9 +177,7 @@ class TestGeneve(BridgeDomain, VppTestCase): # Our Multicast address cls.mcast_ip4 = '239.1.1.1' - iplong = atol(cls.mcast_ip4) - cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % ( - (iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF) + cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4) # Create GENEVE VTEP on VPP pg0, and put geneve_tunnel0 and pg1 # into BD. diff --git a/test/test_ip4_vrf_multi_instance.py b/test/test_ip4_vrf_multi_instance.py index 79e5ef72aa0..6444b97a3aa 100644 --- a/test/test_ip4_vrf_multi_instance.py +++ b/test/test_ip4_vrf_multi_instance.py @@ -182,8 +182,6 @@ class TestIp4VrfMultiInst(VppTestCase): for i in range(count): vrf_id = i + start pg_if = self.pg_if_by_vrf_id[vrf_id][0] - dest_addr = pg_if.local_ip4n - dest_addr_len = 24 self.vapi.ip_table_add_del(is_add=1, table={'table_id': vrf_id}) self.logger.info("IPv4 VRF ID %d created" % vrf_id) if vrf_id not in self.vrf_list: diff --git a/test/test_ip6_vrf_multi_instance.py b/test/test_ip6_vrf_multi_instance.py index c23e3015351..16069b260a2 100644 --- a/test/test_ip6_vrf_multi_instance.py +++ b/test/test_ip6_vrf_multi_instance.py @@ -193,8 +193,6 @@ class TestIP6VrfMultiInst(VppTestCase): for i in range(count): vrf_id = i + start pg_if = self.pg_if_by_vrf_id[vrf_id][0] - dest_addr = pg_if.local_ip6n - dest_addr_len = 64 self.vapi.ip_table_add_del(is_add=1, table={'table_id': vrf_id, 'is_ip6': 1}) self.logger.info("IPv6 VRF ID %d created" % vrf_id) diff --git a/test/test_syslog.py b/test/test_syslog.py index 3d20291e51d..b084a1d1846 100644 --- a/test/test_syslog.py +++ b/test/test_syslog.py @@ -103,8 +103,8 @@ class TestSyslog(VppTestCase): def test_syslog(self): """ Syslog Protocol test """ - self.vapi.syslog_set_sender(src_address=self.pg0.local_ip4n, - collector_address=self.pg0.remote_ip4n) + self.vapi.syslog_set_sender(src_address=self.pg0.local_ip4, + collector_address=self.pg0.remote_ip4) config = self.vapi.syslog_get_sender() self.assertEqual(str(config.collector_address), self.pg0.remote_ip4) @@ -178,8 +178,8 @@ class TestSyslog(VppTestCase): sd1, msg) - self.vapi.syslog_set_sender(self.pg0.local_ip4n, - self.pg0.remote_ip4n, + self.vapi.syslog_set_sender(self.pg0.local_ip4, + self.pg0.remote_ip4, collector_port=12345) config = self.vapi.syslog_get_sender() self.assertEqual(config.collector_port, 12345) diff --git a/test/test_vxlan.py b/test/test_vxlan.py index d66b34d2def..1793e494251 100644 --- a/test/test_vxlan.py +++ b/test/test_vxlan.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import socket -from util import ip4n_range, ip4_range, reassemble4 +from util import ip4_range, reassemble4 import unittest from framework import VppTestCase, VppTestRunner from template_bd import BridgeDomain @@ -10,7 +10,8 @@ from scapy.layers.l2 import Ether from scapy.packet import Raw from scapy.layers.inet import IP, UDP from scapy.layers.vxlan import VXLAN -from scapy.utils import atol + +import util from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_vxlan_tunnel import VppVxlanTunnel from vpp_ip import INVALID_INDEX @@ -91,13 +92,12 @@ class TestVxlan(BridgeDomain, VppTestCase): next_hop_address = cls.pg0.remote_ip4 for dest_ip4 in ip4_range(next_hop_address, ip_range_start, ip_range_end): - # add host route so dest_ip4n will not be resolved + # add host route so dest_ip4 will not be resolved rip = VppIpRoute(cls, dest_ip4, 32, [VppRoutePath(next_hop_address, INVALID_INDEX)], register=False) rip.add_vpp_config() - dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4) r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, dst=dest_ip4, vni=vni) @@ -183,13 +183,9 @@ class TestVxlan(BridgeDomain, VppTestCase): # Our Multicast address cls.mcast_ip4 = '239.1.1.1' - cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) - iplong = atol(cls.mcast_ip4) - cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % ( - (iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF) - + cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4) except Exception: - super(TestVxlan, cls).tearDownClass() + cls.tearDownClass() raise @classmethod diff --git a/test/test_vxlan6.py b/test/test_vxlan6.py index b582d38eb74..3a11ea91db1 100644 --- a/test/test_vxlan6.py +++ b/test/test_vxlan6.py @@ -8,7 +8,8 @@ from template_bd import BridgeDomain from scapy.layers.l2 import Ether from scapy.layers.inet6 import IPv6, UDP from scapy.layers.vxlan import VXLAN -from scapy.utils import atol + +import util from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_vxlan_tunnel import VppVxlanTunnel from vpp_ip import INVALID_INDEX @@ -125,16 +126,15 @@ class TestVxlan6(BridgeDomain, VppTestCase): for pg in cls.pg_interfaces: pg.admin_up() - # Configure IPv4 addresses on VPP pg0. + # Configure IPv6 addresses on VPP pg0. cls.pg0.config_ip6() # Resolve MAC address for VPP's IP address on pg0. cls.pg0.resolve_ndp() + # Our Multicast address cls.mcast_ip6 = 'ff0e::1' - cls.mcast_ip6n = socket.inet_pton(socket.AF_INET6, cls.mcast_ip6) - cls.mcast_mac = "33:33:00:00:00:%02x" % (1) - + cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip6) except Exception: super(TestVxlan6, cls).tearDownClass() raise diff --git a/test/test_vxlan_gbp.py b/test/test_vxlan_gbp.py index d3cd7aa6fdc..79eb23d45a4 100644 --- a/test/test_vxlan_gbp.py +++ b/test/test_vxlan_gbp.py @@ -10,7 +10,7 @@ from scapy.layers.l2 import Ether from scapy.packet import Raw from scapy.layers.inet import IP, UDP from scapy.layers.vxlan import VXLAN -from scapy.utils import atol + from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip import INVALID_INDEX @@ -96,7 +96,7 @@ class TestVxlanGbp(VppTestCase): for dest_ip4 in ip4_range(cls.pg0.remote_ip4, ip_range_start, ip_range_end): - # add host route so dest_ip4n will not be resolved + # add host route so dest_ip4 will not be resolved rip = VppIpRoute(cls, dest_ip4, 32, [VppRoutePath(next_hop_address, INVALID_INDEX)], diff --git a/test/test_vxlan_gpe.py b/test/test_vxlan_gpe.py index 3d6e26024c9..5c3ac16640c 100644 --- a/test/test_vxlan_gpe.py +++ b/test/test_vxlan_gpe.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import socket -from util import ip4n_range, ip4_range +from util import ip4_range import unittest from framework import VppTestCase, VppTestRunner, running_extended_tests from template_bd import BridgeDomain @@ -10,8 +10,10 @@ from scapy.layers.l2 import Ether from scapy.packet import Raw from scapy.layers.inet import IP, UDP from scapy.layers.vxlan import VXLAN -from scapy.utils import atol + +import util from vpp_ip_route import VppIpRoute, VppRoutePath + from vpp_ip import INVALID_INDEX @@ -95,11 +97,10 @@ class TestVxlanGpe(BridgeDomain, VppTestCase): INVALID_INDEX)], register=False) rip.add_vpp_config() - dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4) r = cls.vapi.vxlan_gpe_add_del_tunnel( - src_addr=cls.pg0.local_ip4n, - dst_addr=dest_ip4n, + src_addr=cls.pg0.local_ip4, + dst_addr=dest_ip4, vni=vni) cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, bd_id=vni) @@ -115,8 +116,8 @@ class TestVxlanGpe(BridgeDomain, VppTestCase): vni_end = vni_start + n_shared_dst_tunnels for vni in range(vni_start, vni_end): r = cls.vapi.vxlan_gpe_add_del_tunnel( - src_addr=cls.pg0.local_ip4n, - dst_addr=cls.mcast_ip4n, + local=cls.pg0.local_ip4, + remote=cls.mcast_ip4, mcast_sw_if_index=1, vni=vni, is_add=is_add) @@ -139,12 +140,12 @@ class TestVxlanGpe(BridgeDomain, VppTestCase): n_distinct_dst_tunnels = 20 ip_range_start = 10 ip_range_end = ip_range_start + n_distinct_dst_tunnels - for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start, - ip_range_end): - vni = bytearray(dest_ip4n)[3] + for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start, + ip_range_end): + vni = int(dest_ip4.split(".")[3]) cls.vapi.vxlan_gpe_add_del_tunnel( - src_addr=cls.pg0.local_ip4n, - dst_addr=dest_ip4n, + src_addr=cls.pg0.local_ip4, + dst_addr=dest_ip4, mcast_sw_if_index=1, vni=vni, is_add=is_add) @@ -183,18 +184,15 @@ class TestVxlanGpe(BridgeDomain, VppTestCase): # Our Multicast address cls.mcast_ip4 = '239.1.1.1' - cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) - iplong = atol(cls.mcast_ip4) - cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % ( - (iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF) + cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4) # Create VXLAN-GPE VTEP on VPP pg0, and put vxlan_gpe_tunnel0 # and pg1 into BD. cls.single_tunnel_vni = 0xabcde cls.single_tunnel_bd = 11 r = cls.vapi.vxlan_gpe_add_del_tunnel( - src_addr=cls.pg0.local_ip4n, - dst_addr=cls.pg0.remote_ip4n, + src_addr=cls.pg0.local_ip4, + dst_addr=cls.pg0.remote_ip4, vni=cls.single_tunnel_vni) cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, bd_id=cls.single_tunnel_bd) @@ -207,8 +205,8 @@ class TestVxlanGpe(BridgeDomain, VppTestCase): cls.create_vxlan_gpe_flood_test_bd(cls.mcast_flood_bd, cls.n_ucast_tunnels) r = cls.vapi.vxlan_gpe_add_del_tunnel( - src_addr=cls.pg0.local_ip4n, - dst_addr=cls.mcast_ip4n, + src_addr=cls.pg0.local_ip4, + dst_addr=cls.mcast_ip4, mcast_sw_if_index=1, vni=cls.mcast_flood_bd) cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, 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. diff --git a/test/vpp_interface.py b/test/vpp_interface.py index a344ec613b0..2d991ede06c 100644 --- a/test/vpp_interface.py +++ b/test/vpp_interface.py @@ -66,23 +66,11 @@ class VppInterface(object): return ("%s/%d" % (self._local_ip4, self._local_ip4_len)) @property - def local_ip4n(self): - """DEPRECATED """ - """Local IPv4 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET, self._local_ip4) - - @property def remote_ip4(self): """IPv4 address of remote peer "connected" to this interface.""" return self._remote_hosts[0].ip4 @property - def remote_ip4n(self): - """DEPRECATED """ - """Local IPv6 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET, self._remote_hosts[0].ip4) - - @property def local_ip6(self): """Local IPv6 address on VPP interface (string).""" return self._local_ip6 @@ -106,46 +94,22 @@ class VppInterface(object): return ("%s/%d" % (self._local_ip6, self._local_ip6_len)) @property - def local_ip6n(self): - """DEPRECATED """ - """Local IPv6 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET6, self._local_ip6) - - @property def remote_ip6(self): """IPv6 address of remote peer "connected" to this interface.""" return self._remote_hosts[0].ip6 @property - def remote_ip6n(self): - """DEPRECATED """ - """Local IPv6 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET6, self._remote_hosts[0].ip6) - - @property def local_ip6_ll(self): """Local IPv6 link-local address on VPP interface (string).""" return self._local_ip6_ll @property - def local_ip6n_ll(self): - """DEPRECATED """ - """Local IPv6 link-local address on VPP interface (string).""" - return socket.inet_pton(socket.AF_INET6, self._local_ip6_ll.address) - - @property def remote_ip6_ll(self): """Link-local IPv6 address of remote peer "connected" to this interface.""" return self._remote_ip6_ll @property - def remote_ip6n_ll(self): - """DEPRECATED """ - """Local IPv6 link-local address on VPP interface (string).""" - return socket.inet_pton(socket.AF_INET6, self._remote_ip6_ll) - - @property def name(self): """Name of the interface.""" return self._name |