2018-03-14 20:39:40 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""IP{4,6} over IP{v,6} tunnel functional tests"""
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
import unittest
|
2018-09-19 12:38:51 +02:00
|
|
|
from scapy.layers.inet6 import IPv6, Ether, IP, UDP, IPv6ExtHdrFragment
|
|
|
|
from scapy.all import fragment, fragment6, RandShort, defragment6
|
2018-03-14 20:39:40 +01:00
|
|
|
from framework import VppTestCase, VppTestRunner
|
2018-09-05 15:42:26 -07:00
|
|
|
from vpp_ip import DpoProto
|
2018-05-01 05:17:55 -07:00
|
|
|
from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, FibPathProto
|
2018-03-14 20:39:40 +01:00
|
|
|
from socket import AF_INET, AF_INET6, inet_pton
|
2018-12-06 17:35:12 +01:00
|
|
|
from util import reassemble4
|
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
""" Testipip is a subclass of VPPTestCase classes.
|
|
|
|
|
|
|
|
IPIP tests.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-05-26 11:34:27 -07:00
|
|
|
def ipip_add_tunnel(test, src, dst, table_id=0, tc_tos=0xff):
|
|
|
|
""" Add a IPIP tunnel """
|
|
|
|
return test.vapi.ipip_add_tunnel(
|
|
|
|
tunnel={
|
|
|
|
'src': src,
|
|
|
|
'dst': dst,
|
|
|
|
'table_id': table_id,
|
|
|
|
'instance': 0xffffffff,
|
|
|
|
'tc_tos': tc_tos
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
class TestIPIP(VppTestCase):
|
|
|
|
""" IPIP Test Case """
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestIPIP, cls).setUpClass()
|
2018-03-14 20:39:40 +01:00
|
|
|
cls.create_pg_interfaces(range(2))
|
|
|
|
cls.interfaces = list(cls.pg_interfaces)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
2019-03-12 19:23:27 -07:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestIPIP, cls).tearDownClass()
|
|
|
|
|
2018-11-27 06:01:22 -08:00
|
|
|
def setUp(self):
|
|
|
|
super(TestIPIP, self).setUp()
|
|
|
|
for i in self.interfaces:
|
2018-03-14 20:39:40 +01:00
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.config_ip6()
|
|
|
|
i.disable_ipv6_ra()
|
|
|
|
i.resolve_arp()
|
|
|
|
i.resolve_ndp()
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIPIP, self).tearDown()
|
|
|
|
if not self.vpp_dead:
|
2018-03-14 20:39:40 +01:00
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.unconfig_ip4()
|
|
|
|
i.unconfig_ip6()
|
|
|
|
i.admin_down()
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
def validate(self, rx, expected):
|
2018-12-06 17:35:12 +01:00
|
|
|
self.assertEqual(rx, expected.__class__(expected))
|
2018-03-08 12:30:43 +01:00
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
def generate_ip4_frags(self, payload_length, fragment_size):
|
2018-08-10 14:39:48 +02:00
|
|
|
p_ether = Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac)
|
|
|
|
p_payload = UDP(sport=1234, dport=1234) / self.payload(payload_length)
|
|
|
|
p_ip4 = IP(src="1.2.3.4", dst=self.pg0.remote_ip4)
|
|
|
|
outer_ip4 = (p_ether / IP(src=self.pg1.remote_ip4,
|
|
|
|
id=RandShort(),
|
|
|
|
dst=self.pg0.local_ip4) / p_ip4 / p_payload)
|
|
|
|
frags = fragment(outer_ip4, fragment_size)
|
|
|
|
p4_reply = (p_ip4 / p_payload)
|
|
|
|
p4_reply.ttl -= 1
|
|
|
|
return frags, p4_reply
|
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
def test_ipip4(self):
|
|
|
|
""" ip{v4,v6} over ip4 test """
|
|
|
|
p_ether = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
2018-05-24 13:21:43 +02:00
|
|
|
p_ip6 = IPv6(src="1::1", dst="DEAD::1", nh='UDP', tc=42)
|
|
|
|
p_ip4 = IP(src="1.2.3.4", dst="130.67.0.1", tos=42)
|
2018-04-13 19:43:39 +02:00
|
|
|
p_payload = UDP(sport=1234, dport=1234)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
# IPv4 transport
|
2019-05-26 11:34:27 -07:00
|
|
|
rv = ipip_add_tunnel(self,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg1.remote_ip4,
|
|
|
|
tc_tos=0xFF)
|
2018-03-08 12:30:43 +01:00
|
|
|
sw_if_index = rv.sw_if_index
|
|
|
|
|
|
|
|
# Set interface up and enable IP on it
|
2018-03-14 20:39:40 +01:00
|
|
|
self.vapi.sw_interface_set_flags(sw_if_index, 1)
|
|
|
|
self.vapi.sw_interface_set_unnumbered(
|
2019-03-05 16:58:24 +01:00
|
|
|
sw_if_index=self.pg0.sw_if_index,
|
|
|
|
unnumbered_sw_if_index=sw_if_index)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
# Add IPv4 and IPv6 routes via tunnel interface
|
|
|
|
ip4_via_tunnel = VppIpRoute(
|
|
|
|
self, "130.67.0.0", 16,
|
|
|
|
[VppRoutePath("0.0.0.0",
|
|
|
|
sw_if_index,
|
2018-05-01 05:17:55 -07:00
|
|
|
proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)])
|
2018-03-08 12:30:43 +01:00
|
|
|
ip4_via_tunnel.add_vpp_config()
|
|
|
|
|
|
|
|
ip6_via_tunnel = VppIpRoute(
|
|
|
|
self, "dead::", 16,
|
|
|
|
[VppRoutePath("::",
|
|
|
|
sw_if_index,
|
2018-05-01 05:17:55 -07:00
|
|
|
proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
|
2018-03-08 12:30:43 +01:00
|
|
|
ip6_via_tunnel.add_vpp_config()
|
|
|
|
|
|
|
|
# IPv6 in to IPv4 tunnel
|
|
|
|
p6 = (p_ether / p_ip6 / p_payload)
|
|
|
|
p_inner_ip6 = p_ip6
|
|
|
|
p_inner_ip6.hlim -= 1
|
|
|
|
p6_reply = (IP(src=self.pg0.local_ip4, dst=self.pg1.remote_ip4,
|
2018-05-24 13:21:43 +02:00
|
|
|
proto='ipv6', id=0, tos=42) / p_inner_ip6 / p_payload)
|
2018-03-08 12:30:43 +01:00
|
|
|
p6_reply.ttl -= 1
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg0, p6 * 10, self.pg1)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p6_reply)
|
|
|
|
|
|
|
|
# IPv4 in to IPv4 tunnel
|
|
|
|
p4 = (p_ether / p_ip4 / p_payload)
|
|
|
|
p_ip4_inner = p_ip4
|
|
|
|
p_ip4_inner.ttl -= 1
|
2018-05-24 13:21:43 +02:00
|
|
|
p4_reply = (IP(src=self.pg0.local_ip4, dst=self.pg1.remote_ip4,
|
|
|
|
tos=42) /
|
|
|
|
p_ip4_inner / p_payload)
|
2018-03-08 12:30:43 +01:00
|
|
|
p4_reply.ttl -= 1
|
|
|
|
p4_reply.id = 0
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg0, p4 * 10, self.pg1)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p4_reply)
|
|
|
|
|
|
|
|
# Decapsulation
|
|
|
|
p_ether = Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac)
|
|
|
|
|
|
|
|
# IPv4 tunnel to IPv4
|
|
|
|
p_ip4 = IP(src="1.2.3.4", dst=self.pg0.remote_ip4)
|
|
|
|
p4 = (p_ether / IP(src=self.pg1.remote_ip4,
|
|
|
|
dst=self.pg0.local_ip4) / p_ip4 / p_payload)
|
|
|
|
p4_reply = (p_ip4 / p_payload)
|
|
|
|
p4_reply.ttl -= 1
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg1, p4 * 10, self.pg0)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p4_reply)
|
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
err = self.statistics.get_err_counter(
|
2018-09-04 13:19:12 +02:00
|
|
|
'/err/ipip4-input/packets decapsulated')
|
|
|
|
self.assertEqual(err, 10)
|
2018-08-31 00:29:48 +02:00
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
# IPv4 tunnel to IPv6
|
|
|
|
p_ip6 = IPv6(src="1:2:3::4", dst=self.pg0.remote_ip6)
|
|
|
|
p6 = (p_ether / IP(src=self.pg1.remote_ip4,
|
|
|
|
dst=self.pg0.local_ip4) / p_ip6 / p_payload)
|
|
|
|
p6_reply = (p_ip6 / p_payload)
|
|
|
|
p6_reply.hlim = 63
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg1, p6 * 10, self.pg0)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p6_reply)
|
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
err = self.statistics.get_err_counter(
|
2018-09-04 13:19:12 +02:00
|
|
|
'/err/ipip4-input/packets decapsulated')
|
|
|
|
self.assertEqual(err, 20)
|
2018-08-31 00:29:48 +02:00
|
|
|
|
2018-08-10 14:39:48 +02:00
|
|
|
#
|
2018-08-08 22:23:19 +02:00
|
|
|
# Fragmentation / Reassembly and Re-fragmentation
|
2018-08-10 14:39:48 +02:00
|
|
|
#
|
2018-08-08 22:23:19 +02:00
|
|
|
rv = self.vapi.ip_reassembly_enable_disable(
|
|
|
|
sw_if_index=self.pg1.sw_if_index,
|
|
|
|
enable_ip4=1)
|
|
|
|
|
2019-05-16 14:35:46 +02:00
|
|
|
self.vapi.ip_reassembly_set(timeout_ms=1000, max_reassemblies=1000,
|
|
|
|
max_reassembly_length=1000,
|
|
|
|
expire_walk_interval_ms=10000,
|
|
|
|
is_ip6=0)
|
|
|
|
|
2018-08-10 14:39:48 +02:00
|
|
|
# Send lots of fragments, verify reassembled packet
|
2018-09-19 12:38:51 +02:00
|
|
|
frags, p4_reply = self.generate_ip4_frags(3131, 1400)
|
2018-08-10 14:39:48 +02:00
|
|
|
f = []
|
|
|
|
for i in range(0, 1000):
|
|
|
|
f.extend(frags)
|
|
|
|
self.pg1.add_stream(f)
|
2018-08-08 22:23:19 +02:00
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg_start()
|
2018-08-10 14:39:48 +02:00
|
|
|
rx = self.pg0.get_capture(1000)
|
|
|
|
|
2018-08-08 22:23:19 +02:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p4_reply)
|
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
err = self.statistics.get_err_counter(
|
2018-09-04 13:19:12 +02:00
|
|
|
'/err/ipip4-input/packets decapsulated')
|
|
|
|
self.assertEqual(err, 1020)
|
2018-08-31 00:29:48 +02:00
|
|
|
|
2018-08-10 14:39:48 +02:00
|
|
|
f = []
|
|
|
|
r = []
|
|
|
|
for i in range(1, 90):
|
2018-09-19 12:38:51 +02:00
|
|
|
frags, p4_reply = self.generate_ip4_frags(i * 100, 1000)
|
2018-08-10 14:39:48 +02:00
|
|
|
f.extend(frags)
|
|
|
|
r.extend(p4_reply)
|
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg1.add_stream(f)
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg0.get_capture(89)
|
|
|
|
i = 0
|
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], r[i])
|
|
|
|
i += 1
|
|
|
|
|
2018-08-08 22:23:19 +02:00
|
|
|
# Now try with re-fragmentation
|
2018-08-10 14:39:48 +02:00
|
|
|
#
|
|
|
|
# Send fragments to tunnel head-end, for the tunnel head end
|
|
|
|
# to reassemble and then refragment
|
|
|
|
#
|
2018-08-08 22:23:19 +02:00
|
|
|
self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [576, 0, 0, 0])
|
2018-09-19 12:38:51 +02:00
|
|
|
frags, p4_reply = self.generate_ip4_frags(3123, 1200)
|
2018-08-08 22:23:19 +02:00
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg1.add_stream(frags)
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg0.get_capture(6)
|
2018-12-06 17:35:12 +01:00
|
|
|
reass_pkt = reassemble4(rx)
|
2018-08-08 22:23:19 +02:00
|
|
|
p4_reply.ttl -= 1
|
|
|
|
p4_reply.id = 256
|
|
|
|
self.validate(reass_pkt, p4_reply)
|
|
|
|
|
2018-08-10 14:39:48 +02:00
|
|
|
self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [1600, 0, 0, 0])
|
2018-09-19 12:38:51 +02:00
|
|
|
frags, p4_reply = self.generate_ip4_frags(3123, 1200)
|
2018-08-10 14:39:48 +02:00
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg1.add_stream(frags)
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg0.get_capture(2)
|
2018-12-06 17:35:12 +01:00
|
|
|
reass_pkt = reassemble4(rx)
|
2018-08-10 14:39:48 +02:00
|
|
|
p4_reply.ttl -= 1
|
|
|
|
p4_reply.id = 512
|
|
|
|
self.validate(reass_pkt, p4_reply)
|
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
def test_ipip_create(self):
|
|
|
|
""" ipip create / delete interface test """
|
2019-05-26 11:34:27 -07:00
|
|
|
rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5')
|
2018-09-19 12:38:51 +02:00
|
|
|
sw_if_index = rv.sw_if_index
|
|
|
|
self.vapi.ipip_del_tunnel(sw_if_index)
|
|
|
|
|
|
|
|
def test_ipip_vrf_create(self):
|
|
|
|
""" ipip create / delete interface VRF test """
|
|
|
|
|
|
|
|
t = VppIpTable(self, 20)
|
|
|
|
t.add_vpp_config()
|
2019-05-26 11:34:27 -07:00
|
|
|
rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5', table_id=20)
|
2018-09-19 12:38:51 +02:00
|
|
|
sw_if_index = rv.sw_if_index
|
|
|
|
self.vapi.ipip_del_tunnel(sw_if_index)
|
|
|
|
|
|
|
|
def payload(self, len):
|
|
|
|
return 'x' * len
|
2018-03-08 12:30:43 +01:00
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
|
|
|
|
class TestIPIP6(VppTestCase):
|
|
|
|
""" IPIP6 Test Case """
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestIPIP6, cls).setUpClass()
|
|
|
|
cls.create_pg_interfaces(range(2))
|
|
|
|
cls.interfaces = list(cls.pg_interfaces)
|
|
|
|
|
2019-03-12 19:23:27 -07:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestIPIP6, cls).tearDownClass()
|
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
def setUp(self):
|
2019-01-25 14:05:48 -08:00
|
|
|
super(TestIPIP6, self).setUp()
|
2018-09-19 12:38:51 +02:00
|
|
|
for i in self.interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.config_ip6()
|
|
|
|
i.disable_ipv6_ra()
|
|
|
|
i.resolve_arp()
|
|
|
|
i.resolve_ndp()
|
|
|
|
self.setup_tunnel()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if not self.vpp_dead:
|
|
|
|
self.destroy_tunnel()
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.unconfig_ip4()
|
|
|
|
i.unconfig_ip6()
|
|
|
|
i.admin_down()
|
|
|
|
super(TestIPIP6, self).tearDown()
|
|
|
|
|
|
|
|
def setup_tunnel(self):
|
2018-03-08 12:30:43 +01:00
|
|
|
# IPv6 transport
|
2019-05-26 11:34:27 -07:00
|
|
|
rv = ipip_add_tunnel(self,
|
|
|
|
self.pg0.local_ip6,
|
|
|
|
self.pg1.remote_ip6,
|
|
|
|
tc_tos=255)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
sw_if_index = rv.sw_if_index
|
2018-09-19 12:38:51 +02:00
|
|
|
self.tunnel_if_index = sw_if_index
|
2018-03-14 20:39:40 +01:00
|
|
|
self.vapi.sw_interface_set_flags(sw_if_index, 1)
|
|
|
|
self.vapi.sw_interface_set_unnumbered(
|
2019-03-05 16:58:24 +01:00
|
|
|
sw_if_index=self.pg0.sw_if_index,
|
|
|
|
unnumbered_sw_if_index=sw_if_index)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
# Add IPv4 and IPv6 routes via tunnel interface
|
|
|
|
ip4_via_tunnel = VppIpRoute(
|
|
|
|
self, "130.67.0.0", 16,
|
|
|
|
[VppRoutePath("0.0.0.0",
|
|
|
|
sw_if_index,
|
2018-05-01 05:17:55 -07:00
|
|
|
proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)])
|
2018-03-08 12:30:43 +01:00
|
|
|
ip4_via_tunnel.add_vpp_config()
|
|
|
|
|
|
|
|
ip6_via_tunnel = VppIpRoute(
|
|
|
|
self, "dead::", 16,
|
|
|
|
[VppRoutePath("::",
|
|
|
|
sw_if_index,
|
2018-05-01 05:17:55 -07:00
|
|
|
proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
|
2018-03-08 12:30:43 +01:00
|
|
|
ip6_via_tunnel.add_vpp_config()
|
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
self.tunnel_ip6_via_tunnel = ip6_via_tunnel
|
|
|
|
self.tunnel_ip4_via_tunnel = ip4_via_tunnel
|
|
|
|
|
|
|
|
def destroy_tunnel(self):
|
|
|
|
# IPv6 transport
|
|
|
|
self.tunnel_ip4_via_tunnel.remove_vpp_config()
|
|
|
|
self.tunnel_ip6_via_tunnel.remove_vpp_config()
|
|
|
|
|
|
|
|
rv = self.vapi.ipip_del_tunnel(sw_if_index=self.tunnel_if_index)
|
|
|
|
|
|
|
|
def validate(self, rx, expected):
|
2018-12-06 17:35:12 +01:00
|
|
|
self.assertEqual(rx, expected.__class__(expected))
|
2018-09-19 12:38:51 +02:00
|
|
|
|
|
|
|
def generate_ip6_frags(self, payload_length, fragment_size):
|
|
|
|
p_ether = Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac)
|
|
|
|
p_payload = UDP(sport=1234, dport=1234) / self.payload(payload_length)
|
|
|
|
p_ip6 = IPv6(src="1::1", dst=self.pg0.remote_ip6)
|
|
|
|
outer_ip6 = (p_ether / IPv6(src=self.pg1.remote_ip6,
|
|
|
|
dst=self.pg0.local_ip6) /
|
|
|
|
IPv6ExtHdrFragment() / p_ip6 / p_payload)
|
|
|
|
frags = fragment6(outer_ip6, fragment_size)
|
|
|
|
p6_reply = (p_ip6 / p_payload)
|
|
|
|
p6_reply.hlim -= 1
|
|
|
|
return frags, p6_reply
|
|
|
|
|
|
|
|
def generate_ip6_hairpin_frags(self, payload_length, fragment_size):
|
|
|
|
p_ether = Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac)
|
|
|
|
p_payload = UDP(sport=1234, dport=1234) / self.payload(payload_length)
|
|
|
|
p_ip6 = IPv6(src="1::1", dst="dead::1")
|
|
|
|
outer_ip6 = (p_ether / IPv6(src=self.pg1.remote_ip6,
|
|
|
|
dst=self.pg0.local_ip6) /
|
|
|
|
IPv6ExtHdrFragment() / p_ip6 / p_payload)
|
|
|
|
frags = fragment6(outer_ip6, fragment_size)
|
|
|
|
p_ip6.hlim -= 1
|
|
|
|
p6_reply = (IPv6(src=self.pg0.local_ip6, dst=self.pg1.remote_ip6,
|
|
|
|
hlim=63) / p_ip6 / p_payload)
|
|
|
|
|
|
|
|
return frags, p6_reply
|
|
|
|
|
|
|
|
def test_encap(self):
|
|
|
|
""" ip{v4,v6} over ip6 test encap """
|
|
|
|
p_ether = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
p_ip6 = IPv6(src="1::1", dst="DEAD::1", tc=42, nh='UDP')
|
|
|
|
p_ip4 = IP(src="1.2.3.4", dst="130.67.0.1", tos=42)
|
|
|
|
p_payload = UDP(sport=1234, dport=1234)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
# Encapsulation
|
2018-03-08 12:30:43 +01:00
|
|
|
# IPv6 in to IPv6 tunnel
|
|
|
|
p6 = (p_ether / p_ip6 / p_payload)
|
2018-05-24 13:21:43 +02:00
|
|
|
p6_reply = (IPv6(src=self.pg0.local_ip6, dst=self.pg1.remote_ip6,
|
2018-09-19 12:38:51 +02:00
|
|
|
hlim=64, tc=42) /
|
2018-05-24 13:21:43 +02:00
|
|
|
p_ip6 / p_payload)
|
2018-03-08 12:30:43 +01:00
|
|
|
p6_reply[1].hlim -= 1
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg0, p6 * 11, self.pg1)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p6_reply)
|
|
|
|
|
|
|
|
# IPv4 in to IPv6 tunnel
|
|
|
|
p4 = (p_ether / p_ip4 / p_payload)
|
|
|
|
p4_reply = (IPv6(src=self.pg0.local_ip6,
|
2018-09-19 12:38:51 +02:00
|
|
|
dst=self.pg1.remote_ip6, hlim=64, tc=42) /
|
2018-05-24 13:21:43 +02:00
|
|
|
p_ip4 / p_payload)
|
2018-03-08 12:30:43 +01:00
|
|
|
p4_reply[1].ttl -= 1
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg0, p4 * 11, self.pg1)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p4_reply)
|
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
def test_decap(self):
|
|
|
|
""" ip{v4,v6} over ip6 test decap """
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
p_ether = Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac)
|
2018-09-19 12:38:51 +02:00
|
|
|
p_ip6 = IPv6(src="1::1", dst="DEAD::1", tc=42, nh='UDP')
|
|
|
|
p_ip4 = IP(src="1.2.3.4", dst=self.pg0.remote_ip4)
|
|
|
|
p_payload = UDP(sport=1234, dport=1234)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
# Decapsulation
|
2018-03-08 12:30:43 +01:00
|
|
|
# IPv6 tunnel to IPv4
|
2018-09-19 12:38:51 +02:00
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
p4 = (p_ether / IPv6(src=self.pg1.remote_ip6,
|
|
|
|
dst=self.pg0.local_ip6) / p_ip4 / p_payload)
|
|
|
|
p4_reply = (p_ip4 / p_payload)
|
|
|
|
p4_reply.ttl -= 1
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg1, p4 * 11, self.pg0)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p4_reply)
|
|
|
|
|
|
|
|
# IPv6 tunnel to IPv6
|
|
|
|
p_ip6 = IPv6(src="1:2:3::4", dst=self.pg0.remote_ip6)
|
|
|
|
p6 = (p_ether / IPv6(src=self.pg1.remote_ip6,
|
|
|
|
dst=self.pg0.local_ip6) / p_ip6 / p_payload)
|
|
|
|
p6_reply = (p_ip6 / p_payload)
|
|
|
|
p6_reply.hlim = 63
|
2019-03-05 16:58:24 +01:00
|
|
|
rx = self.send_and_expect(self.pg1, p6 * 11, self.pg0)
|
2018-03-08 12:30:43 +01:00
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p6_reply)
|
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
def test_frag(self):
|
|
|
|
""" ip{v4,v6} over ip6 test frag """
|
|
|
|
|
|
|
|
p_ether = Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac)
|
|
|
|
p_ip6 = IPv6(src="1::1", dst="DEAD::1", tc=42, nh='UDP')
|
|
|
|
p_ip4 = IP(src="1.2.3.4", dst=self.pg0.remote_ip4)
|
|
|
|
p_payload = UDP(sport=1234, dport=1234)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Fragmentation / Reassembly and Re-fragmentation
|
|
|
|
#
|
|
|
|
rv = self.vapi.ip_reassembly_enable_disable(
|
|
|
|
sw_if_index=self.pg1.sw_if_index,
|
|
|
|
enable_ip6=1)
|
|
|
|
|
2019-05-16 14:35:46 +02:00
|
|
|
self.vapi.ip_reassembly_set(timeout_ms=1000, max_reassemblies=1000,
|
|
|
|
max_reassembly_length=1000,
|
|
|
|
expire_walk_interval_ms=10000,
|
|
|
|
is_ip6=1)
|
|
|
|
|
2018-09-19 12:38:51 +02:00
|
|
|
# Send lots of fragments, verify reassembled packet
|
2019-05-16 15:01:34 +02:00
|
|
|
before_cnt = self.statistics.get_err_counter(
|
2018-09-19 12:38:51 +02:00
|
|
|
'/err/ipip6-input/packets decapsulated')
|
|
|
|
frags, p6_reply = self.generate_ip6_frags(3131, 1400)
|
|
|
|
f = []
|
|
|
|
for i in range(0, 1000):
|
|
|
|
f.extend(frags)
|
|
|
|
self.pg1.add_stream(f)
|
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg0.get_capture(1000)
|
|
|
|
|
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], p6_reply)
|
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
cnt = self.statistics.get_err_counter(
|
2018-09-19 12:38:51 +02:00
|
|
|
'/err/ipip6-input/packets decapsulated')
|
|
|
|
self.assertEqual(cnt, before_cnt + 1000)
|
|
|
|
|
|
|
|
f = []
|
|
|
|
r = []
|
|
|
|
# TODO: Check out why reassembly of atomic fragments don't work
|
|
|
|
for i in range(10, 90):
|
|
|
|
frags, p6_reply = self.generate_ip6_frags(i * 100, 1000)
|
|
|
|
f.extend(frags)
|
|
|
|
r.extend(p6_reply)
|
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg1.add_stream(f)
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg0.get_capture(80)
|
|
|
|
i = 0
|
|
|
|
for p in rx:
|
|
|
|
self.validate(p[1], r[i])
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
# Simple fragmentation
|
|
|
|
p_ether = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1280, 0, 0, 0])
|
|
|
|
|
|
|
|
# IPv6 in to IPv6 tunnel
|
|
|
|
p_payload = UDP(sport=1234, dport=1234) / self.payload(1300)
|
|
|
|
|
|
|
|
p6 = (p_ether / p_ip6 / p_payload)
|
|
|
|
p6_reply = (IPv6(src=self.pg0.local_ip6, dst=self.pg1.remote_ip6,
|
|
|
|
hlim=63, tc=42) /
|
|
|
|
p_ip6 / p_payload)
|
|
|
|
p6_reply[1].hlim -= 1
|
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg0.add_stream(p6)
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg1.get_capture(2)
|
|
|
|
|
|
|
|
# Scapy defragment doesn't deal well with multiple layers
|
2019-03-27 11:25:48 -07:00
|
|
|
# of same type / Ethernet header first
|
2018-09-19 12:38:51 +02:00
|
|
|
f = [p[1] for p in rx]
|
|
|
|
reass_pkt = defragment6(f)
|
|
|
|
self.validate(reass_pkt, p6_reply)
|
|
|
|
|
|
|
|
# Now try with re-fragmentation
|
|
|
|
#
|
|
|
|
# Send large fragments to tunnel head-end, for the tunnel head end
|
|
|
|
# to reassemble and then refragment out the tunnel again.
|
|
|
|
# Hair-pinning
|
|
|
|
#
|
|
|
|
self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1280, 0, 0, 0])
|
|
|
|
frags, p6_reply = self.generate_ip6_hairpin_frags(8000, 1200)
|
|
|
|
self.pg_enable_capture()
|
|
|
|
self.pg1.add_stream(frags)
|
|
|
|
self.pg_start()
|
|
|
|
rx = self.pg1.get_capture(7)
|
|
|
|
f = [p[1] for p in rx]
|
|
|
|
reass_pkt = defragment6(f)
|
|
|
|
p6_reply.id = 256
|
|
|
|
self.validate(reass_pkt, p6_reply)
|
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
def test_ipip_create(self):
|
|
|
|
""" ipip create / delete interface test """
|
2019-05-26 11:34:27 -07:00
|
|
|
rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5')
|
2018-03-08 12:30:43 +01:00
|
|
|
sw_if_index = rv.sw_if_index
|
2018-03-14 20:39:40 +01:00
|
|
|
self.vapi.ipip_del_tunnel(sw_if_index)
|
2018-03-08 12:30:43 +01:00
|
|
|
|
2018-08-22 00:21:14 -07:00
|
|
|
def test_ipip_vrf_create(self):
|
|
|
|
""" ipip create / delete interface VRF test """
|
|
|
|
|
|
|
|
t = VppIpTable(self, 20)
|
|
|
|
t.add_vpp_config()
|
2019-05-26 11:34:27 -07:00
|
|
|
rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5', table_id=20)
|
2018-08-22 00:21:14 -07:00
|
|
|
sw_if_index = rv.sw_if_index
|
|
|
|
self.vapi.ipip_del_tunnel(sw_if_index)
|
|
|
|
|
2018-08-08 22:23:19 +02:00
|
|
|
def payload(self, len):
|
|
|
|
return 'x' * len
|
|
|
|
|
2018-03-08 12:30:43 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(testRunner=VppTestRunner)
|