aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-11-05 16:26:46 -0800
committerFlorin Coras <florin.coras@gmail.com>2017-11-07 16:13:42 +0000
commit810086d8fd08445919ae03bf36161037e53a712a (patch)
tree76a91d3ed49759ef3adae32066f9dcedd75df889 /test
parent595992c5c3b5abbdb7e90e61acbee212f25ad59f (diff)
UDP Encapsulation.
A UDP-encap object that particiapates in the FIB graph and contributes DPO to teh output chain. It thereofre resembles a tunnel but without the interface. FIB paths (and henace routes) can then be created to egress through the UDP-encap. Said routes can have MPLS labels, hence this also allows MPLSoUPD. Encap is uni-directional. For decap, one still registers with the UDP port dispatcher. Change-Id: I23bd345523b20789a1de1b02022ea1148ca50797 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_udp.py235
-rw-r--r--test/vpp_ip_route.py8
-rw-r--r--test/vpp_papi_provider.py39
-rw-r--r--test/vpp_udp_encap.py73
4 files changed, 355 insertions, 0 deletions
diff --git a/test/test_udp.py b/test/test_udp.py
new file mode 100644
index 00000000000..7853ac3b3f4
--- /dev/null
+++ b/test/test_udp.py
@@ -0,0 +1,235 @@
+#!/usr/bin/env python
+
+from framework import VppTestCase, VppTestRunner
+from vpp_udp_encap import *
+from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable
+
+from scapy.packet import Raw
+from scapy.layers.l2 import Ether, ARP
+from scapy.layers.inet import IP, UDP
+from scapy.layers.inet6 import IPv6
+from scapy.contrib.mpls import MPLS
+
+
+class TestUdpEncap(VppTestCase):
+ """ UDP Encap Test Case """
+
+ def setUp(self):
+ super(TestUdpEncap, self).setUp()
+
+ # create 2 pg interfaces
+ self.create_pg_interfaces(range(4))
+
+ # setup interfaces
+ # assign them different tables.
+ table_id = 0
+ self.tables = []
+
+ for i in self.pg_interfaces:
+ i.admin_up()
+
+ if table_id != 0:
+ tbl = VppIpTable(self, table_id)
+ tbl.add_vpp_config()
+ self.tables.append(tbl)
+ tbl = VppIpTable(self, table_id, is_ip6=1)
+ tbl.add_vpp_config()
+ self.tables.append(tbl)
+
+ i.set_table_ip4(table_id)
+ i.set_table_ip6(table_id)
+ i.config_ip4()
+ i.resolve_arp()
+ i.config_ip6()
+ i.resolve_ndp()
+ table_id += 1
+
+ def tearDown(self):
+ for i in self.pg_interfaces:
+ i.unconfig_ip4()
+ i.unconfig_ip6()
+ i.ip6_disable()
+ i.set_table_ip4(0)
+ i.set_table_ip6(0)
+ i.admin_down()
+ super(TestUdpEncap, self).tearDown()
+
+ def validate_outer4(self, rx, encap_obj):
+ self.assertEqual(rx[IP].src, encap_obj.src_ip_s)
+ self.assertEqual(rx[IP].dst, encap_obj.dst_ip_s)
+ self.assertEqual(rx[UDP].sport, encap_obj.src_port)
+ self.assertEqual(rx[UDP].dport, encap_obj.dst_port)
+
+ def validate_outer6(self, rx, encap_obj):
+ self.assertEqual(rx[IPv6].src, encap_obj.src_ip_s)
+ self.assertEqual(rx[IPv6].dst, encap_obj.dst_ip_s)
+ self.assertEqual(rx[UDP].sport, encap_obj.src_port)
+ self.assertEqual(rx[UDP].dport, encap_obj.dst_port)
+
+ def validate_inner4(self, rx, tx, ttl=None):
+ self.assertEqual(rx.src, tx[IP].src)
+ self.assertEqual(rx.dst, tx[IP].dst)
+ if ttl:
+ self.assertEqual(rx.ttl, ttl)
+ else:
+ self.assertEqual(rx.ttl, tx[IP].ttl)
+
+ def validate_inner6(self, rx, tx):
+ self.assertEqual(rx.src, tx[IPv6].src)
+ self.assertEqual(rx.dst, tx[IPv6].dst)
+ self.assertEqual(rx.hlim, tx[IPv6].hlim)
+
+ def send_and_expect(self, input, output, pkts):
+ self.vapi.cli("clear trace")
+ input.add_stream(pkts)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+ rx = output.get_capture(len(pkts))
+ return rx
+
+ def test_udp_encap(self):
+ """ UDP Encap test
+ """
+
+ #
+ # construct a UDP encap object through each of the peers
+ # v4 through the first two peears, v6 through the second.
+ #
+ udp_encap_0 = VppUdpEncap(self, 0,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4,
+ 330, 440)
+ udp_encap_1 = VppUdpEncap(self, 1,
+ self.pg1.local_ip4,
+ self.pg1.remote_ip4,
+ 331, 441,
+ table_id=1)
+ udp_encap_2 = VppUdpEncap(self, 2,
+ self.pg2.local_ip6,
+ self.pg2.remote_ip6,
+ 332, 442,
+ table_id=2,
+ is_ip6=1)
+ udp_encap_3 = VppUdpEncap(self, 3,
+ self.pg3.local_ip6,
+ self.pg3.remote_ip6,
+ 333, 443,
+ table_id=3,
+ is_ip6=1)
+ udp_encap_0.add_vpp_config()
+ udp_encap_1.add_vpp_config()
+ udp_encap_2.add_vpp_config()
+ udp_encap_3.add_vpp_config()
+
+ #
+ # Routes via each UDP encap object - all combinations of v4 and v6.
+ #
+ route_4o4 = VppIpRoute(self, "1.1.0.1", 32,
+ [VppRoutePath("0.0.0.0",
+ 0xFFFFFFFF,
+ is_udp_encap=1,
+ next_hop_id=0)])
+ route_4o6 = VppIpRoute(self, "1.1.2.1", 32,
+ [VppRoutePath("0.0.0.0",
+ 0xFFFFFFFF,
+ is_udp_encap=1,
+ next_hop_id=2)])
+ route_6o4 = VppIpRoute(self, "2001::1", 128,
+ [VppRoutePath("0.0.0.0",
+ 0xFFFFFFFF,
+ is_udp_encap=1,
+ next_hop_id=1)],
+ is_ip6=1)
+ route_6o6 = VppIpRoute(self, "2001::3", 128,
+ [VppRoutePath("0.0.0.0",
+ 0xFFFFFFFF,
+ is_udp_encap=1,
+ next_hop_id=3)],
+ is_ip6=1)
+ route_4o4.add_vpp_config()
+ route_4o6.add_vpp_config()
+ route_6o6.add_vpp_config()
+ route_6o4.add_vpp_config()
+
+ #
+ # 4o4 encap
+ #
+ p_4o4 = (Ether(src=self.pg0.remote_mac,
+ dst=self.pg0.local_mac) /
+ IP(src="2.2.2.2", dst="1.1.0.1") /
+ UDP(sport=1234, dport=1234) /
+ Raw('\xa5' * 100))
+ rx = self.send_and_expect(self.pg0, self.pg0, p_4o4*65)
+ for p in rx:
+ self.validate_outer4(p, udp_encap_0)
+ p = IP(p["UDP"].payload.load)
+ self.validate_inner4(p, p_4o4)
+
+ #
+ # 4o6 encap
+ #
+ p_4o6 = (Ether(src=self.pg0.remote_mac,
+ dst=self.pg0.local_mac) /
+ IP(src="2.2.2.2", dst="1.1.2.1") /
+ UDP(sport=1234, dport=1234) /
+ Raw('\xa5' * 100))
+ rx = self.send_and_expect(self.pg0, self.pg2, p_4o6*65)
+ for p in rx:
+ self.validate_outer6(p, udp_encap_2)
+ p = IP(p["UDP"].payload.load)
+ self.validate_inner4(p, p_4o6)
+
+ #
+ # 6o4 encap
+ #
+ p_6o4 = (Ether(src=self.pg0.remote_mac,
+ dst=self.pg0.local_mac) /
+ IPv6(src="2001::100", dst="2001::1") /
+ UDP(sport=1234, dport=1234) /
+ Raw('\xa5' * 100))
+ rx = self.send_and_expect(self.pg0, self.pg1, p_6o4*65)
+ for p in rx:
+ self.validate_outer4(p, udp_encap_1)
+ p = IPv6(p["UDP"].payload.load)
+ self.validate_inner6(p, p_6o4)
+
+ #
+ # 6o6 encap
+ #
+ p_6o6 = (Ether(src=self.pg0.remote_mac,
+ dst=self.pg0.local_mac) /
+ IPv6(src="2001::100", dst="2001::3") /
+ UDP(sport=1234, dport=1234) /
+ Raw('\xa5' * 100))
+ rx = self.send_and_expect(self.pg0, self.pg3, p_6o6*65)
+ for p in rx:
+ self.validate_outer6(p, udp_encap_3)
+ p = IPv6(p["UDP"].payload.load)
+ self.validate_inner6(p, p_6o6)
+
+ #
+ # A route with an output label
+ # the TTL of the inner packet is decremented on LSP ingress
+ #
+ route_4oMPLSo4 = VppIpRoute(self, "1.1.2.22", 32,
+ [VppRoutePath("0.0.0.0",
+ 0xFFFFFFFF,
+ is_udp_encap=1,
+ next_hop_id=1,
+ labels=[66])])
+ route_4oMPLSo4.add_vpp_config()
+
+ p_4omo4 = (Ether(src=self.pg0.remote_mac,
+ dst=self.pg0.local_mac) /
+ IP(src="2.2.2.2", dst="1.1.2.22") /
+ UDP(sport=1234, dport=1234) /
+ Raw('\xa5' * 100))
+ rx = self.send_and_expect(self.pg0, self.pg1, p_4omo4*65)
+ for p in rx:
+ self.validate_outer4(p, udp_encap_1)
+ p = MPLS(p["UDP"].payload.load)
+ self.validate_inner4(p, p_4omo4, ttl=63)
+
+
+if __name__ == '__main__':
+ unittest.main(testRunner=VppTestRunner)
diff --git a/test/vpp_ip_route.py b/test/vpp_ip_route.py
index 7501146e96a..34aa5428d18 100644
--- a/test/vpp_ip_route.py
+++ b/test/vpp_ip_route.py
@@ -108,6 +108,8 @@ class VppRoutePath(object):
is_resolve_host=0,
is_resolve_attached=0,
is_source_lookup=0,
+ is_udp_encap=0,
+ next_hop_id=0xffffffff,
proto=DpoProto.DPO_PROTO_IP4):
self.nh_itf = nh_sw_if_index
self.nh_table_id = nh_table_id
@@ -130,6 +132,8 @@ class VppRoutePath(object):
if rpf_id != 0:
self.is_rpf_id = 1
self.nh_itf = rpf_id
+ self.is_udp_encap = is_udp_encap
+ self.next_hop_id = next_hop_id
class VppMRoutePath(VppRoutePath):
@@ -194,12 +198,14 @@ class VppIpRoute(VppObject):
path.nh_labels),
next_hop_via_label=path.nh_via_label,
next_hop_table_id=path.nh_table_id,
+ next_hop_id=path.next_hop_id,
is_ipv6=self.is_ip6,
is_l2_bridged=1
if path.proto == DpoProto.DPO_PROTO_ETHERNET else 0,
is_resolve_host=path.is_resolve_host,
is_resolve_attached=path.is_resolve_attached,
is_source_lookup=path.is_source_lookup,
+ is_udp_encap=path.is_udp_encap,
is_multipath=1 if len(self.paths) > 1 else 0)
self._test.registry.register(self, self._test.logger)
@@ -226,7 +232,9 @@ class VppIpRoute(VppObject):
table_id=self.table_id,
next_hop_table_id=path.nh_table_id,
next_hop_via_label=path.nh_via_label,
+ next_hop_id=path.next_hop_id,
is_add=0,
+ is_udp_encap=path.is_udp_encap,
is_ipv6=self.is_ip6)
def query_vpp_config(self):
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 468cf83d57b..31d7ac48d1f 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -735,6 +735,7 @@ class VppPapiProvider(object):
next_hop_n_out_labels=0,
next_hop_out_label_stack=[],
next_hop_via_label=MPLS_LABEL_INVALID,
+ next_hop_id=0xFFFFFFFF,
is_resolve_host=0,
is_resolve_attached=0,
classify_table_index=0xFFFFFFFF,
@@ -747,6 +748,7 @@ class VppPapiProvider(object):
is_classify=0,
is_multipath=0,
is_l2_bridged=0,
+ is_udp_encap=0,
is_source_lookup=0):
"""
@@ -790,9 +792,11 @@ class VppPapiProvider(object):
'is_resolve_attached': is_resolve_attached,
'is_l2_bridged': is_l2_bridged,
'is_source_lookup': is_source_lookup,
+ 'is_udp_encap': is_udp_encap,
'next_hop_weight': next_hop_weight,
'dst_address_length': dst_address_length,
'dst_address': dst_address,
+ 'next_hop_id': next_hop_id,
'next_hop_address': next_hop_address,
'next_hop_n_out_labels': next_hop_n_out_labels,
'next_hop_via_label': next_hop_via_label,
@@ -980,6 +984,41 @@ class VppPapiProvider(object):
'outer_fib_id': outer_fib_id}
)
+ def udp_encap_add_del(self,
+ id,
+ src_ip,
+ dst_ip,
+ src_port,
+ dst_port,
+ table_id=0,
+ is_add=1,
+ is_ip6=0):
+ """ Add a GRE tunnel
+ :param id: user provided ID
+ :param src_ip:
+ :param dst_ip:
+ :param src_port:
+ :param dst_port:
+ :param outer_fib_id: (Default value = 0)
+ :param is_add: (Default value = 1)
+ :param is_ipv6: (Default value = 0)
+ """
+
+ return self.api(
+ self.papi.udp_encap_add_del,
+ {'id': id,
+ 'is_add': is_add,
+ 'is_ip6': is_ip6,
+ 'src_ip': src_ip,
+ 'dst_ip': dst_ip,
+ 'src_port': src_port,
+ 'dst_port': dst_port,
+ 'table_id': table_id}
+ )
+
+ def udp_encap_dump(self):
+ return self.api(self.papi.udp_encap_dump, {})
+
def mpls_fib_dump(self):
return self.api(self.papi.mpls_fib_dump, {})
diff --git a/test/vpp_udp_encap.py b/test/vpp_udp_encap.py
new file mode 100644
index 00000000000..56d23cc45dc
--- /dev/null
+++ b/test/vpp_udp_encap.py
@@ -0,0 +1,73 @@
+"""
+ UDP encap objects
+"""
+
+from vpp_object import *
+from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
+
+
+def find_udp_encap(test, id):
+ encaps = test.vapi.udp_encap_dump()
+ for e in encaps:
+ if id == e.id:
+ return True
+ return False
+
+
+class VppUdpEncap(VppObject):
+
+ def __init__(self,
+ test,
+ id,
+ src_ip,
+ dst_ip,
+ src_port,
+ dst_port,
+ table_id=0,
+ is_ip6=0):
+ self._test = test
+ self.id = id
+ self.table_id = table_id
+ self.is_ip6 = is_ip6
+ self.src_ip_s = src_ip
+ self.dst_ip_s = dst_ip
+ if is_ip6:
+ self.src_ip = inet_pton(AF_INET6, src_ip)
+ self.dst_ip = inet_pton(AF_INET6, dst_ip)
+ else:
+ self.src_ip = inet_pton(AF_INET, src_ip)
+ self.dst_ip = inet_pton(AF_INET, dst_ip)
+ self.src_port = src_port
+ self.dst_port = dst_port
+
+ def add_vpp_config(self):
+ self._test.vapi.udp_encap_add_del(
+ self.id,
+ self.src_ip,
+ self.dst_ip,
+ self.src_port,
+ self.dst_port,
+ self.table_id,
+ is_ip6=self.is_ip6,
+ is_add=1)
+ self._test.registry.register(self, self._test.logger)
+
+ def remove_vpp_config(self):
+ self._test.vapi.udp_encap_add_del(
+ self.id,
+ self.src_ip,
+ self.dst_ip,
+ self.src_port,
+ self.dst_port,
+ self.table_id,
+ is_ip6=self.is_ip6,
+ is_add=0)
+
+ def query_vpp_config(self):
+ return find_udp_encap(self._test, self.id)
+
+ def __str__(self):
+ return self.object_id()
+
+ def object_id(self):
+ return ("udp-encap-%d" % self.id)