X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_udp.py;h=3281c0d9df6276052900c80ea72766249a715f83;hb=8a6f5d394;hp=96375f056f75427d2e24c16c4fec73f0cf104120;hpb=a279d9cf615bd60439085ba103125e6f2fa3b27c;p=vpp.git diff --git a/test/test_udp.py b/test/test_udp.py index 96375f056f7..3281c0d9df6 100644 --- a/test/test_udp.py +++ b/test/test_udp.py @@ -1,19 +1,36 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest +from framework import tag_fixme_vpp_workers from framework import VppTestCase, VppTestRunner + from vpp_udp_encap import find_udp_encap, VppUdpEncap -from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, VppMplsLabel +from vpp_udp_decap import VppUdpDecap +from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, VppMplsLabel, \ + VppMplsTable, VppMplsRoute, FibPathType, FibPathProto +from vpp_neighbor import VppNeighbor +from vpp_papi import VppEnum from scapy.packet import Raw from scapy.layers.l2 import Ether -from scapy.layers.inet import IP, UDP +from scapy.layers.inet import IP, UDP, ICMP from scapy.layers.inet6 import IPv6 from scapy.contrib.mpls import MPLS +NUM_PKTS = 67 + +@tag_fixme_vpp_workers class TestUdpEncap(VppTestCase): """ UDP Encap Test Case """ + @classmethod + def setUpClass(cls): + super(TestUdpEncap, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + super(TestUdpEncap, cls).tearDownClass() + def setUp(self): super(TestUdpEncap, self).setUp() @@ -48,7 +65,6 @@ class TestUdpEncap(VppTestCase): 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() @@ -74,10 +90,13 @@ class TestUdpEncap(VppTestCase): else: self.assertEqual(rx[IP].ttl, tx[IP].ttl) - def validate_inner6(self, rx, tx): + def validate_inner6(self, rx, tx, hlim=None): self.assertEqual(rx.src, tx[IPv6].src) self.assertEqual(rx.dst, tx[IPv6].dst) - self.assertEqual(rx.hlim, tx[IPv6].hlim) + if hlim: + self.assertEqual(rx.hlim, hlim) + else: + self.assertEqual(rx.hlim, tx[IPv6].hlim) def test_udp_encap(self): """ UDP Encap test @@ -85,7 +104,7 @@ class TestUdpEncap(VppTestCase): # # construct a UDP encap object through each of the peers - # v4 through the first two peears, v6 through the second. + # v4 through the first two peers, v6 through the second. # udp_encap_0 = VppUdpEncap(self, self.pg0.local_ip4, @@ -121,32 +140,34 @@ class TestUdpEncap(VppTestCase): # # 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=udp_encap_0.id)]) - route_4o6 = VppIpRoute(self, "1.1.2.1", 32, - [VppRoutePath("0.0.0.0", - 0xFFFFFFFF, - is_udp_encap=1, - next_hop_id=udp_encap_2.id)]) - route_6o4 = VppIpRoute(self, "2001::1", 128, - [VppRoutePath("0.0.0.0", - 0xFFFFFFFF, - is_udp_encap=1, - next_hop_id=udp_encap_1.id)], - is_ip6=1) - route_6o6 = VppIpRoute(self, "2001::3", 128, - [VppRoutePath("0.0.0.0", - 0xFFFFFFFF, - is_udp_encap=1, - next_hop_id=udp_encap_3.id)], - is_ip6=1) - route_4o4.add_vpp_config() + route_4o4 = VppIpRoute( + self, "1.1.0.1", 32, + [VppRoutePath("0.0.0.0", + 0xFFFFFFFF, + type=FibPathType.FIB_PATH_TYPE_UDP_ENCAP, + next_hop_id=udp_encap_0.id)]) + route_4o6 = VppIpRoute( + self, "1.1.2.1", 32, + [VppRoutePath("0.0.0.0", + 0xFFFFFFFF, + type=FibPathType.FIB_PATH_TYPE_UDP_ENCAP, + next_hop_id=udp_encap_2.id)]) + route_6o4 = VppIpRoute( + self, "2001::1", 128, + [VppRoutePath("0.0.0.0", + 0xFFFFFFFF, + type=FibPathType.FIB_PATH_TYPE_UDP_ENCAP, + next_hop_id=udp_encap_1.id)]) + route_6o6 = VppIpRoute( + self, "2001::3", 128, + [VppRoutePath("0.0.0.0", + 0xFFFFFFFF, + type=FibPathType.FIB_PATH_TYPE_UDP_ENCAP, + next_hop_id=udp_encap_3.id)]) route_4o6.add_vpp_config() route_6o6.add_vpp_config() route_6o4.add_vpp_config() + route_4o4.add_vpp_config() # # 4o4 encap @@ -155,13 +176,13 @@ class TestUdpEncap(VppTestCase): 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, p_4o4*65, self.pg0) + Raw(b'\xa5' * 100)) + rx = self.send_and_expect(self.pg0, p_4o4*NUM_PKTS, self.pg0) for p in rx: self.validate_outer4(p, udp_encap_0) p = IP(p["UDP"].payload.load) self.validate_inner4(p, p_4o4) - self.assertEqual(udp_encap_0.get_stats()['packets'], 65) + self.assertEqual(udp_encap_0.get_stats()['packets'], NUM_PKTS) # # 4o6 encap @@ -170,13 +191,13 @@ class TestUdpEncap(VppTestCase): 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, p_4o6*65, self.pg2) + Raw(b'\xa5' * 100)) + rx = self.send_and_expect(self.pg0, p_4o6*NUM_PKTS, self.pg2) for p in rx: self.validate_outer6(p, udp_encap_2) p = IP(p["UDP"].payload.load) self.validate_inner4(p, p_4o6) - self.assertEqual(udp_encap_2.get_stats()['packets'], 65) + self.assertEqual(udp_encap_2.get_stats()['packets'], NUM_PKTS) # # 6o4 encap @@ -185,13 +206,13 @@ class TestUdpEncap(VppTestCase): 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, p_6o4*65, self.pg1) + Raw(b'\xa5' * 100)) + rx = self.send_and_expect(self.pg0, p_6o4*NUM_PKTS, self.pg1) for p in rx: self.validate_outer4(p, udp_encap_1) p = IPv6(p["UDP"].payload.load) self.validate_inner6(p, p_6o4) - self.assertEqual(udp_encap_1.get_stats()['packets'], 65) + self.assertEqual(udp_encap_1.get_stats()['packets'], NUM_PKTS) # # 6o6 encap @@ -200,39 +221,175 @@ class TestUdpEncap(VppTestCase): 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, p_6o6*65, self.pg3) + Raw(b'\xa5' * 100)) + rx = self.send_and_expect(self.pg0, p_6o6*NUM_PKTS, self.pg3) for p in rx: self.validate_outer6(p, udp_encap_3) p = IPv6(p["UDP"].payload.load) self.validate_inner6(p, p_6o6) - self.assertEqual(udp_encap_3.get_stats()['packets'], 65) + self.assertEqual(udp_encap_3.get_stats()['packets'], NUM_PKTS) # # 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=[VppMplsLabel(66)])]) + route_4oMPLSo4 = VppIpRoute( + self, "1.1.2.22", 32, + [VppRoutePath("0.0.0.0", + 0xFFFFFFFF, + type=FibPathType.FIB_PATH_TYPE_UDP_ENCAP, + next_hop_id=1, + labels=[VppMplsLabel(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, p_4omo4*65, self.pg1) + Raw(b'\xa5' * 100)) + rx = self.send_and_expect(self.pg0, p_4omo4*NUM_PKTS, self.pg1) 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) - self.assertEqual(udp_encap_1.get_stats()['packets'], 130) + self.assertEqual(udp_encap_1.get_stats()['packets'], 2*NUM_PKTS) + + def test_udp_decap(self): + """ UDP Decap test + """ + # + # construct a UDP decap object for each type of protocol + # + + # IPv4 + udp_api_proto = VppEnum.vl_api_udp_decap_next_proto_t + next_proto = udp_api_proto.UDP_API_DECAP_PROTO_IP4 + udp_decap_0 = VppUdpDecap(self, 1, 220, next_proto) + + # IPv6 + next_proto = udp_api_proto.UDP_API_DECAP_PROTO_IP6 + udp_decap_1 = VppUdpDecap(self, 0, 221, next_proto) + + # MPLS + next_proto = udp_api_proto.UDP_API_DECAP_PROTO_MPLS + udp_decap_2 = VppUdpDecap(self, 1, 222, next_proto) + + udp_decap_0.add_vpp_config() + udp_decap_1.add_vpp_config() + udp_decap_2.add_vpp_config() + + # + # Routes via the corresponding pg after the UDP decap + # + route_4 = VppIpRoute( + self, "1.1.1.1", 32, + [VppRoutePath("0.0.0.0", self.pg0.sw_if_index)], + table_id=0) + + route_6 = VppIpRoute( + self, "2001::1", 128, + [VppRoutePath("::", self.pg1.sw_if_index)], + table_id=1) + + route_mo4 = VppIpRoute( + self, "3.3.3.3", 32, + [VppRoutePath("0.0.0.0", self.pg2.sw_if_index)], + table_id=2) + route_4.add_vpp_config() + route_6.add_vpp_config() + route_mo4.add_vpp_config() + # + # Adding neighbors to route the packets + # + n_4 = VppNeighbor(self, + self.pg0.sw_if_index, + "00:11:22:33:44:55", + "1.1.1.1") + n_6 = VppNeighbor(self, + self.pg1.sw_if_index, + "11:22:33:44:55:66", + "2001::1") + n_mo4 = VppNeighbor(self, + self.pg2.sw_if_index, + "22:33:44:55:66:77", + "3.3.3.3") + + n_4.add_vpp_config() + n_6.add_vpp_config() + n_mo4.add_vpp_config() + + # + # MPLS decapsulation config + # + mpls_table = VppMplsTable(self, 0) + mpls_table.add_vpp_config() + mpls_route = VppMplsRoute( + self, 77, 1, + [VppRoutePath("0.0.0.0", + 0xFFFFFFFF, + nh_table_id=2, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)]) + mpls_route.add_vpp_config() + + # + # UDP over ipv4 decap + # + p_4 = (Ether(src=self.pg0.remote_mac, + dst=self.pg0.local_mac) / + IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / + UDP(sport=1111, dport=220) / + IP(src="2.2.2.2", dst="1.1.1.1") / + UDP(sport=1234, dport=4321) / + Raw(b'\xa5' * 100)) + + rx = self.send_and_expect(self.pg0, p_4*NUM_PKTS, self.pg0) + p_4 = IP(p_4["UDP"].payload) + for p in rx: + p = IP(p["Ether"].payload) + self.validate_inner4(p, p_4, ttl=63) + + # + # UDP over ipv6 decap + # + p_6 = (Ether(src=self.pg1.remote_mac, + dst=self.pg1.local_mac) / + IPv6(src=self.pg1.remote_ip6, dst=self.pg1.local_ip6) / + UDP(sport=2222, dport=221) / + IPv6(src="2001::100", dst="2001::1") / + UDP(sport=1234, dport=4321) / + Raw(b'\xa5' * 100)) + + rx = self.send_and_expect(self.pg1, p_6*NUM_PKTS, self.pg1) + p_6 = IPv6(p_6["UDP"].payload) + p = IPv6(rx[0]["Ether"].payload) + for p in rx: + p = IPv6(p["Ether"].payload) + self.validate_inner6(p, p_6, hlim=63) + + # + # UDP over mpls decap + # + p_mo4 = (Ether(src=self.pg2.remote_mac, + dst=self.pg2.local_mac) / + IP(src=self.pg2.remote_ip4, dst=self.pg2.local_ip4) / + UDP(sport=3333, dport=222) / + MPLS(label=77, ttl=1) / + IP(src="4.4.4.4", dst="3.3.3.3") / + UDP(sport=1234, dport=4321) / + Raw(b'\xa5' * 100)) + + self.pg2.enable_mpls() + rx = self.send_and_expect(self.pg2, p_mo4*NUM_PKTS, self.pg2) + self.pg2.disable_mpls() + p_mo4 = IP(MPLS(p_mo4["UDP"].payload).payload) + for p in rx: + p = IP(p["Ether"].payload) + self.validate_inner4(p, p_mo4, ttl=63) + + +@tag_fixme_vpp_workers class TestUDP(VppTestCase): """ UDP Test Case """ @@ -240,9 +397,13 @@ class TestUDP(VppTestCase): def setUpClass(cls): super(TestUDP, cls).setUpClass() + @classmethod + def tearDownClass(cls): + super(TestUDP, cls).tearDownClass() + def setUp(self): super(TestUDP, self).setUp() - self.vapi.session_enable_disable(is_enabled=1) + self.vapi.session_enable_disable(is_enable=1) self.create_loopback_interfaces(2) table_id = 0 @@ -259,17 +420,17 @@ class TestUDP(VppTestCase): table_id += 1 # Configure namespaces - self.vapi.app_namespace_add(namespace_id="0", - sw_if_index=self.loop0.sw_if_index) - self.vapi.app_namespace_add(namespace_id="1", - sw_if_index=self.loop1.sw_if_index) + self.vapi.app_namespace_add_del(namespace_id="0", + sw_if_index=self.loop0.sw_if_index) + self.vapi.app_namespace_add_del(namespace_id="1", + sw_if_index=self.loop1.sw_if_index) def tearDown(self): for i in self.lo_interfaces: i.unconfig_ip4() i.set_table_ip4(0) i.admin_down() - self.vapi.session_enable_disable(is_enabled=0) + self.vapi.session_enable_disable(is_enable=0) super(TestUDP, self).tearDown() def test_udp_transfer(self): @@ -293,14 +454,16 @@ class TestUDP(VppTestCase): "uri " + uri) if error: self.logger.critical(error) - self.assertEqual(error.find("failed"), -1) + self.assertNotIn("failed", error) error = self.vapi.cli("test echo client mbytes 10 appns 1 " + "fifo-size 4 no-output test-bytes " + "syn-timeout 2 no-return uri " + uri) if error: self.logger.critical(error) - self.assertEqual(error.find("failed"), -1) + self.assertNotIn("failed", error) + + self.logger.debug(self.vapi.cli("show session verbose 2")) # Delete inter-table routes ip_t01.remove_vpp_config()