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>
This commit is contained in:
Paul Vinciguerra
2020-05-02 22:34:40 -04:00
parent 0b0a84c403
commit 2f1563129a
14 changed files with 86 additions and 120 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import socket import socket
from util import ip4n_range, ip4_range from util import ip4_range
import unittest import unittest
from framework import VppTestCase, VppTestRunner from framework import VppTestCase, VppTestRunner
from template_bd import BridgeDomain from template_bd import BridgeDomain
@ -12,6 +12,8 @@ from scapy.layers.inet import IP, UDP
from scapy.layers.inet6 import IPv6 from scapy.layers.inet6 import IPv6
from scapy.contrib.gtp import GTP_U_Header from scapy.contrib.gtp import GTP_U_Header
from scapy.utils import atol from scapy.utils import atol
import util
from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_ip import INVALID_INDEX from vpp_ip import INVALID_INDEX
@ -238,7 +240,7 @@ class TestGtpu(BridgeDomain, VppTestCase):
next_hop_address = cls.pg0.remote_ip4 next_hop_address = cls.pg0.remote_ip4
for dest_ip4 in ip4_range(next_hop_address, ip_range_start, for dest_ip4 in ip4_range(next_hop_address, ip_range_start,
ip_range_end): 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, rip = VppIpRoute(cls, dest_ip4, 32,
[VppRoutePath(next_hop_address, [VppRoutePath(next_hop_address,
INVALID_INDEX)], INVALID_INDEX)],
@ -335,10 +337,7 @@ class TestGtpu(BridgeDomain, VppTestCase):
# Our Multicast address # Our Multicast address
cls.mcast_ip4 = '239.1.1.1' cls.mcast_ip4 = '239.1.1.1'
cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) cls.mcast_mac = util.mcast_ip_to_mac(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)
# Create GTPU VTEP on VPP pg0, and put gtpu_tunnel0 and pg1 # Create GTPU VTEP on VPP pg0, and put gtpu_tunnel0 and pg1
# into BD. # into BD.

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import ipaddress
import socket import socket
import unittest import unittest
import struct import struct
@ -857,7 +858,8 @@ class MethodHolder(VppTestCase):
else: else:
nat44_ses_delete_num += 1 nat44_ses_delete_num += 1
# sourceIPv4Address # sourceIPv4Address
self.assertEqual(self.pg0.remote_ip4n, record[8]) self.assertEqual(self.pg0.remote_ip4,
str(ipaddress.IPv4Address(record[8])))
# postNATSourceIPv4Address # postNATSourceIPv4Address
self.assertEqual(socket.inet_pton(socket.AF_INET, self.nat_addr), self.assertEqual(socket.inet_pton(socket.AF_INET, self.nat_addr),
record[225]) record[225])
@ -945,7 +947,7 @@ class MethodHolder(VppTestCase):
else: else:
self.assertEqual(scapy.compat.orb(record[230]), 11) self.assertEqual(scapy.compat.orb(record[230]), 11)
# sourceIPv6Address # sourceIPv6Address
self.assertEqual(src_addr, record[27]) self.assertEqual(src_addr, str(ipaddress.IPv6Address(record[27])))
# postNATSourceIPv4Address # postNATSourceIPv4Address
self.assertEqual(self.nat_addr_n, record[225]) self.assertEqual(self.nat_addr_n, record[225])
# protocolIdentifier # protocolIdentifier
@ -976,7 +978,7 @@ class MethodHolder(VppTestCase):
else: else:
self.assertEqual(scapy.compat.orb(record[230]), 7) self.assertEqual(scapy.compat.orb(record[230]), 7)
# sourceIPv6Address # sourceIPv6Address
self.assertEqual(src_addr, record[27]) self.assertEqual(src_addr, str(ipaddress.IPv6Address(record[27])))
# destinationIPv6Address # destinationIPv6Address
self.assertEqual(socket.inet_pton(socket.AF_INET6, self.assertEqual(socket.inet_pton(socket.AF_INET6,
self.compose_ip6(dst_addr, self.compose_ip6(dst_addr,
@ -7973,19 +7975,19 @@ class TestNAT64(MethodHolder):
self.vapi.nat64_add_del_interface(is_add=1, flags=0, self.vapi.nat64_add_del_interface(is_add=1, flags=0,
sw_if_index=self.pg1.sw_if_index) 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, o_addr=self.nat_addr,
i_port=self.tcp_port_in, i_port=self.tcp_port_in,
o_port=self.tcp_port_out, o_port=self.tcp_port_out,
proto=IP_PROTOS.tcp, vrf_id=0, proto=IP_PROTOS.tcp, vrf_id=0,
is_add=1) 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, o_addr=self.nat_addr,
i_port=self.udp_port_in, i_port=self.udp_port_in,
o_port=self.udp_port_out, o_port=self.udp_port_out,
proto=IP_PROTOS.udp, vrf_id=0, proto=IP_PROTOS.udp, vrf_id=0,
is_add=1) 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, o_addr=self.nat_addr,
i_port=self.icmp_id_in, i_port=self.icmp_id_in,
o_port=self.icmp_id_out, o_port=self.icmp_id_out,
@ -8876,11 +8878,11 @@ class TestNAT64(MethodHolder):
if p.haslayer(Data): if p.haslayer(Data):
data = ipfix.decode_data_set(p.getlayer(Set)) data = ipfix.decode_data_set(p.getlayer(Set))
if scapy.compat.orb(data[0][230]) == 10: 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: elif scapy.compat.orb(data[0][230]) == 6:
self.verify_ipfix_nat64_ses(data, self.verify_ipfix_nat64_ses(data,
1, 1,
self.pg0.remote_ip6n, self.pg0.remote_ip6,
self.pg1.remote_ip4, self.pg1.remote_ip4,
25) 25)
else: else:
@ -8906,11 +8908,11 @@ class TestNAT64(MethodHolder):
if p.haslayer(Data): if p.haslayer(Data):
data = ipfix.decode_data_set(p.getlayer(Set)) data = ipfix.decode_data_set(p.getlayer(Set))
if scapy.compat.orb(data[0][230]) == 11: 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: elif scapy.compat.orb(data[0][230]) == 7:
self.verify_ipfix_nat64_ses(data, self.verify_ipfix_nat64_ses(data,
0, 0,
self.pg0.remote_ip6n, self.pg0.remote_ip6,
self.pg1.remote_ip4, self.pg1.remote_ip4,
25) 25)
else: else:
@ -9054,7 +9056,7 @@ class TestNAT66(MethodHolder):
self.vapi.nat66_add_del_interface(is_add=1, self.vapi.nat66_add_del_interface(is_add=1,
sw_if_index=self.pg1.sw_if_index) sw_if_index=self.pg1.sw_if_index)
self.vapi.nat66_add_del_static_mapping( 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, external_ip_address=self.nat_addr,
is_add=1) is_add=1)
@ -9133,7 +9135,7 @@ class TestNAT66(MethodHolder):
self.vapi.nat66_add_del_interface(is_add=1, flags=flags, self.vapi.nat66_add_del_interface(is_add=1, flags=flags,
sw_if_index=self.pg1.sw_if_index) sw_if_index=self.pg1.sw_if_index)
self.vapi.nat66_add_del_static_mapping( 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, external_ip_address=self.nat_addr,
is_add=1) is_add=1)

View File

@ -406,9 +406,9 @@ class TestClassifier(VppTestCase):
""" """
addr_len = 24 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, 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) table_id=self.pbr_vrfid, is_add=is_add)
def verify_vrf(self, vrf_id): def verify_vrf(self, vrf_id):

View File

@ -5,6 +5,7 @@ from __future__ import division
import binascii import binascii
import hashlib import hashlib
import ipaddress
import time import time
import unittest import unittest
from random import randint, shuffle, getrandbits from random import randint, shuffle, getrandbits
@ -283,8 +284,8 @@ class BFDAPITestCase(VppTestCase):
self.assertFalse(echo_source.have_usable_ip6) self.assertFalse(echo_source.have_usable_ip6)
self.loopback0.config_ip4() self.loopback0.config_ip4()
unpacked = unpack("!L", self.loopback0.local_ip4n) echo_ip4 = ipaddress.IPv4Address(int(ipaddress.IPv4Address(
echo_ip4 = pack("!L", unpacked[0] ^ 1) self.loopback0.local_ip4)) ^ 1).packed
echo_source = self.vapi.bfd_udp_get_echo_source() echo_source = self.vapi.bfd_udp_get_echo_source()
self.assertTrue(echo_source.is_set) self.assertTrue(echo_source.is_set)
self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) 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.assertFalse(echo_source.have_usable_ip6)
self.loopback0.config_ip6() self.loopback0.config_ip6()
unpacked = unpack("!LLLL", self.loopback0.local_ip6n) echo_ip6 = ipaddress.IPv6Address(int(ipaddress.IPv6Address(
echo_ip6 = pack("!LLLL", unpacked[0], unpacked[1], unpacked[2], self.loopback0.local_ip6)) ^ 1).packed
unpacked[3] ^ 1)
echo_source = self.vapi.bfd_udp_get_echo_source() echo_source = self.vapi.bfd_udp_get_echo_source()
self.assertTrue(echo_source.is_set) self.assertTrue(echo_source.is_set)
self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) 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" % "IPv6 address usable as echo source: none" %
self.loopback0.name) self.loopback0.name)
self.loopback0.config_ip4() self.loopback0.config_ip4()
unpacked = unpack("!L", self.loopback0.local_ip4n) echo_ip4 = str(ipaddress.IPv4Address(int(ipaddress.IPv4Address(
echo_ip4 = inet_ntop(AF_INET, pack("!L", unpacked[0] ^ 1)) self.loopback0.local_ip4)) ^ 1))
self.cli_verify_response("show bfd echo-source", self.cli_verify_response("show bfd echo-source",
"UDP echo source is: %s\n" "UDP echo source is: %s\n"
"IPv4 address usable as echo source: %s\n" "IPv4 address usable as echo source: %s\n"
"IPv6 address usable as echo source: none" % "IPv6 address usable as echo source: none" %
(self.loopback0.name, echo_ip4)) (self.loopback0.name, echo_ip4))
unpacked = unpack("!LLLL", self.loopback0.local_ip6n) echo_ip6 = str(ipaddress.IPv6Address(int(ipaddress.IPv6Address(
echo_ip6 = inet_ntop(AF_INET6, pack("!LLLL", unpacked[0], unpacked[1], self.loopback0.local_ip6)) ^ 1))
unpacked[2], unpacked[3] ^ 1))
self.loopback0.config_ip6() self.loopback0.config_ip6()
self.cli_verify_response("show bfd echo-source", self.cli_verify_response("show bfd echo-source",
"UDP echo source is: %s\n" "UDP echo source is: %s\n"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import socket import socket
from util import ip4_range, ip4_range from util import ip4_range
import unittest import unittest
from framework import VppTestCase, VppTestRunner from framework import VppTestCase, VppTestRunner
from template_bd import BridgeDomain from template_bd import BridgeDomain
@ -9,7 +9,8 @@ from template_bd import BridgeDomain
from scapy.layers.l2 import Ether from scapy.layers.l2 import Ether
from scapy.layers.inet import IP, UDP from scapy.layers.inet import IP, UDP
from scapy.contrib.geneve import GENEVE from scapy.contrib.geneve import GENEVE
from scapy.utils import atol
import util
from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_ip import INVALID_INDEX from vpp_ip import INVALID_INDEX
@ -176,9 +177,7 @@ class TestGeneve(BridgeDomain, VppTestCase):
# Our Multicast address # Our Multicast address
cls.mcast_ip4 = '239.1.1.1' cls.mcast_ip4 = '239.1.1.1'
iplong = atol(cls.mcast_ip4) cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4)
cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % (
(iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF)
# Create GENEVE VTEP on VPP pg0, and put geneve_tunnel0 and pg1 # Create GENEVE VTEP on VPP pg0, and put geneve_tunnel0 and pg1
# into BD. # into BD.

View File

@ -182,8 +182,6 @@ class TestIp4VrfMultiInst(VppTestCase):
for i in range(count): for i in range(count):
vrf_id = i + start vrf_id = i + start
pg_if = self.pg_if_by_vrf_id[vrf_id][0] 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.vapi.ip_table_add_del(is_add=1, table={'table_id': vrf_id})
self.logger.info("IPv4 VRF ID %d created" % vrf_id) self.logger.info("IPv4 VRF ID %d created" % vrf_id)
if vrf_id not in self.vrf_list: if vrf_id not in self.vrf_list:

View File

@ -193,8 +193,6 @@ class TestIP6VrfMultiInst(VppTestCase):
for i in range(count): for i in range(count):
vrf_id = i + start vrf_id = i + start
pg_if = self.pg_if_by_vrf_id[vrf_id][0] 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, self.vapi.ip_table_add_del(is_add=1,
table={'table_id': vrf_id, 'is_ip6': 1}) table={'table_id': vrf_id, 'is_ip6': 1})
self.logger.info("IPv6 VRF ID %d created" % vrf_id) self.logger.info("IPv6 VRF ID %d created" % vrf_id)

View File

@ -103,8 +103,8 @@ class TestSyslog(VppTestCase):
def test_syslog(self): def test_syslog(self):
""" Syslog Protocol test """ """ Syslog Protocol test """
self.vapi.syslog_set_sender(src_address=self.pg0.local_ip4n, self.vapi.syslog_set_sender(src_address=self.pg0.local_ip4,
collector_address=self.pg0.remote_ip4n) collector_address=self.pg0.remote_ip4)
config = self.vapi.syslog_get_sender() config = self.vapi.syslog_get_sender()
self.assertEqual(str(config.collector_address), self.assertEqual(str(config.collector_address),
self.pg0.remote_ip4) self.pg0.remote_ip4)
@ -178,8 +178,8 @@ class TestSyslog(VppTestCase):
sd1, sd1,
msg) msg)
self.vapi.syslog_set_sender(self.pg0.local_ip4n, self.vapi.syslog_set_sender(self.pg0.local_ip4,
self.pg0.remote_ip4n, self.pg0.remote_ip4,
collector_port=12345) collector_port=12345)
config = self.vapi.syslog_get_sender() config = self.vapi.syslog_get_sender()
self.assertEqual(config.collector_port, 12345) self.assertEqual(config.collector_port, 12345)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import socket import socket
from util import ip4n_range, ip4_range, reassemble4 from util import ip4_range, reassemble4
import unittest import unittest
from framework import VppTestCase, VppTestRunner from framework import VppTestCase, VppTestRunner
from template_bd import BridgeDomain from template_bd import BridgeDomain
@ -10,7 +10,8 @@ from scapy.layers.l2 import Ether
from scapy.packet import Raw from scapy.packet import Raw
from scapy.layers.inet import IP, UDP from scapy.layers.inet import IP, UDP
from scapy.layers.vxlan import VXLAN from scapy.layers.vxlan import VXLAN
from scapy.utils import atol
import util
from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_vxlan_tunnel import VppVxlanTunnel from vpp_vxlan_tunnel import VppVxlanTunnel
from vpp_ip import INVALID_INDEX from vpp_ip import INVALID_INDEX
@ -91,13 +92,12 @@ class TestVxlan(BridgeDomain, VppTestCase):
next_hop_address = cls.pg0.remote_ip4 next_hop_address = cls.pg0.remote_ip4
for dest_ip4 in ip4_range(next_hop_address, ip_range_start, for dest_ip4 in ip4_range(next_hop_address, ip_range_start,
ip_range_end): 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, rip = VppIpRoute(cls, dest_ip4, 32,
[VppRoutePath(next_hop_address, [VppRoutePath(next_hop_address,
INVALID_INDEX)], INVALID_INDEX)],
register=False) register=False)
rip.add_vpp_config() rip.add_vpp_config()
dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4)
r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
dst=dest_ip4, vni=vni) dst=dest_ip4, vni=vni)
@ -183,13 +183,9 @@ class TestVxlan(BridgeDomain, VppTestCase):
# Our Multicast address # Our Multicast address
cls.mcast_ip4 = '239.1.1.1' cls.mcast_ip4 = '239.1.1.1'
cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) cls.mcast_mac = util.mcast_ip_to_mac(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)
except Exception: except Exception:
super(TestVxlan, cls).tearDownClass() cls.tearDownClass()
raise raise
@classmethod @classmethod

View File

@ -8,7 +8,8 @@ from template_bd import BridgeDomain
from scapy.layers.l2 import Ether from scapy.layers.l2 import Ether
from scapy.layers.inet6 import IPv6, UDP from scapy.layers.inet6 import IPv6, UDP
from scapy.layers.vxlan import VXLAN from scapy.layers.vxlan import VXLAN
from scapy.utils import atol
import util
from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_vxlan_tunnel import VppVxlanTunnel from vpp_vxlan_tunnel import VppVxlanTunnel
from vpp_ip import INVALID_INDEX from vpp_ip import INVALID_INDEX
@ -125,16 +126,15 @@ class TestVxlan6(BridgeDomain, VppTestCase):
for pg in cls.pg_interfaces: for pg in cls.pg_interfaces:
pg.admin_up() pg.admin_up()
# Configure IPv4 addresses on VPP pg0. # Configure IPv6 addresses on VPP pg0.
cls.pg0.config_ip6() cls.pg0.config_ip6()
# Resolve MAC address for VPP's IP address on pg0. # Resolve MAC address for VPP's IP address on pg0.
cls.pg0.resolve_ndp() cls.pg0.resolve_ndp()
# Our Multicast address
cls.mcast_ip6 = 'ff0e::1' cls.mcast_ip6 = 'ff0e::1'
cls.mcast_ip6n = socket.inet_pton(socket.AF_INET6, cls.mcast_ip6) cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip6)
cls.mcast_mac = "33:33:00:00:00:%02x" % (1)
except Exception: except Exception:
super(TestVxlan6, cls).tearDownClass() super(TestVxlan6, cls).tearDownClass()
raise raise

View File

@ -10,7 +10,7 @@ from scapy.layers.l2 import Ether
from scapy.packet import Raw from scapy.packet import Raw
from scapy.layers.inet import IP, UDP from scapy.layers.inet import IP, UDP
from scapy.layers.vxlan import VXLAN from scapy.layers.vxlan import VXLAN
from scapy.utils import atol
from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_ip import INVALID_INDEX from vpp_ip import INVALID_INDEX
@ -96,7 +96,7 @@ class TestVxlanGbp(VppTestCase):
for dest_ip4 in ip4_range(cls.pg0.remote_ip4, for dest_ip4 in ip4_range(cls.pg0.remote_ip4,
ip_range_start, ip_range_start,
ip_range_end): 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, rip = VppIpRoute(cls, dest_ip4, 32,
[VppRoutePath(next_hop_address, [VppRoutePath(next_hop_address,
INVALID_INDEX)], INVALID_INDEX)],

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import socket import socket
from util import ip4n_range, ip4_range from util import ip4_range
import unittest import unittest
from framework import VppTestCase, VppTestRunner, running_extended_tests from framework import VppTestCase, VppTestRunner, running_extended_tests
from template_bd import BridgeDomain from template_bd import BridgeDomain
@ -10,8 +10,10 @@ from scapy.layers.l2 import Ether
from scapy.packet import Raw from scapy.packet import Raw
from scapy.layers.inet import IP, UDP from scapy.layers.inet import IP, UDP
from scapy.layers.vxlan import VXLAN from scapy.layers.vxlan import VXLAN
from scapy.utils import atol
import util
from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_ip import INVALID_INDEX from vpp_ip import INVALID_INDEX
@ -95,11 +97,10 @@ class TestVxlanGpe(BridgeDomain, VppTestCase):
INVALID_INDEX)], INVALID_INDEX)],
register=False) register=False)
rip.add_vpp_config() rip.add_vpp_config()
dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4)
r = cls.vapi.vxlan_gpe_add_del_tunnel( r = cls.vapi.vxlan_gpe_add_del_tunnel(
src_addr=cls.pg0.local_ip4n, src_addr=cls.pg0.local_ip4,
dst_addr=dest_ip4n, dst_addr=dest_ip4,
vni=vni) vni=vni)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
bd_id=vni) bd_id=vni)
@ -115,8 +116,8 @@ class TestVxlanGpe(BridgeDomain, VppTestCase):
vni_end = vni_start + n_shared_dst_tunnels vni_end = vni_start + n_shared_dst_tunnels
for vni in range(vni_start, vni_end): for vni in range(vni_start, vni_end):
r = cls.vapi.vxlan_gpe_add_del_tunnel( r = cls.vapi.vxlan_gpe_add_del_tunnel(
src_addr=cls.pg0.local_ip4n, local=cls.pg0.local_ip4,
dst_addr=cls.mcast_ip4n, remote=cls.mcast_ip4,
mcast_sw_if_index=1, mcast_sw_if_index=1,
vni=vni, vni=vni,
is_add=is_add) is_add=is_add)
@ -139,12 +140,12 @@ class TestVxlanGpe(BridgeDomain, VppTestCase):
n_distinct_dst_tunnels = 20 n_distinct_dst_tunnels = 20
ip_range_start = 10 ip_range_start = 10
ip_range_end = ip_range_start + n_distinct_dst_tunnels ip_range_end = ip_range_start + n_distinct_dst_tunnels
for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start, for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start,
ip_range_end): ip_range_end):
vni = bytearray(dest_ip4n)[3] vni = int(dest_ip4.split(".")[3])
cls.vapi.vxlan_gpe_add_del_tunnel( cls.vapi.vxlan_gpe_add_del_tunnel(
src_addr=cls.pg0.local_ip4n, src_addr=cls.pg0.local_ip4,
dst_addr=dest_ip4n, dst_addr=dest_ip4,
mcast_sw_if_index=1, mcast_sw_if_index=1,
vni=vni, vni=vni,
is_add=is_add) is_add=is_add)
@ -183,18 +184,15 @@ class TestVxlanGpe(BridgeDomain, VppTestCase):
# Our Multicast address # Our Multicast address
cls.mcast_ip4 = '239.1.1.1' cls.mcast_ip4 = '239.1.1.1'
cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) cls.mcast_mac = util.mcast_ip_to_mac(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)
# Create VXLAN-GPE VTEP on VPP pg0, and put vxlan_gpe_tunnel0 # Create VXLAN-GPE VTEP on VPP pg0, and put vxlan_gpe_tunnel0
# and pg1 into BD. # and pg1 into BD.
cls.single_tunnel_vni = 0xabcde cls.single_tunnel_vni = 0xabcde
cls.single_tunnel_bd = 11 cls.single_tunnel_bd = 11
r = cls.vapi.vxlan_gpe_add_del_tunnel( r = cls.vapi.vxlan_gpe_add_del_tunnel(
src_addr=cls.pg0.local_ip4n, src_addr=cls.pg0.local_ip4,
dst_addr=cls.pg0.remote_ip4n, dst_addr=cls.pg0.remote_ip4,
vni=cls.single_tunnel_vni) vni=cls.single_tunnel_vni)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
bd_id=cls.single_tunnel_bd) 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.create_vxlan_gpe_flood_test_bd(cls.mcast_flood_bd,
cls.n_ucast_tunnels) cls.n_ucast_tunnels)
r = cls.vapi.vxlan_gpe_add_del_tunnel( r = cls.vapi.vxlan_gpe_add_del_tunnel(
src_addr=cls.pg0.local_ip4n, src_addr=cls.pg0.local_ip4,
dst_addr=cls.mcast_ip4n, dst_addr=cls.mcast_ip4,
mcast_sw_if_index=1, mcast_sw_if_index=1,
vni=cls.mcast_flood_bd) vni=cls.mcast_flood_bd)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,

View File

@ -1,6 +1,7 @@
""" test framework utilities """ """ test framework utilities """
import abc import abc
import ipaddress
import socket import socket
from socket import AF_INET6 from socket import AF_INET6
import six import six
@ -50,10 +51,21 @@ def ip4_range(ip4, s, e):
return ("%s.%d" % (tmp, i) for i in range(s, e)) return ("%s.%d" % (tmp, i) for i in range(s, e))
def ip4n_range(ip4n, s, e): def mcast_ip_to_mac(ip):
ip4 = socket.inet_ntop(socket.AF_INET, ip4n) ip = ipaddress.ip_address(ip)
return (socket.inet_pton(socket.AF_INET, ip) if not ip.is_multicast:
for ip in ip4_range(ip4, s, e)) 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. # wrapper around scapy library function.

View File

@ -65,23 +65,11 @@ class VppInterface(object):
"""Local IPv4 prefix """ """Local IPv4 prefix """
return ("%s/%d" % (self._local_ip4, self._local_ip4_len)) 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 @property
def remote_ip4(self): def remote_ip4(self):
"""IPv4 address of remote peer "connected" to this interface.""" """IPv4 address of remote peer "connected" to this interface."""
return self._remote_hosts[0].ip4 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 @property
def local_ip6(self): def local_ip6(self):
"""Local IPv6 address on VPP interface (string).""" """Local IPv6 address on VPP interface (string)."""
@ -105,46 +93,22 @@ class VppInterface(object):
"""Local IPv4 prefix """ """Local IPv4 prefix """
return ("%s/%d" % (self._local_ip6, self._local_ip6_len)) 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 @property
def remote_ip6(self): def remote_ip6(self):
"""IPv6 address of remote peer "connected" to this interface.""" """IPv6 address of remote peer "connected" to this interface."""
return self._remote_hosts[0].ip6 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 @property
def local_ip6_ll(self): def local_ip6_ll(self):
"""Local IPv6 link-local address on VPP interface (string).""" """Local IPv6 link-local address on VPP interface (string)."""
return self._local_ip6_ll 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 @property
def remote_ip6_ll(self): def remote_ip6_ll(self):
"""Link-local IPv6 address of remote peer """Link-local IPv6 address of remote peer
"connected" to this interface.""" "connected" to this interface."""
return self._remote_ip6_ll 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 @property
def name(self): def name(self):
"""Name of the interface.""" """Name of the interface."""