misc: Fix python scripts shebang line
[vpp.git] / src / plugins / map / test / test_map.py
index cf1e6f8..a7e5f16 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import ipaddress
 import unittest
@@ -7,7 +7,7 @@ from ipaddress import IPv6Network, IPv4Network
 from framework import VppTestCase, VppTestRunner
 from vpp_ip import DpoProto
 from vpp_ip_route import VppIpRoute, VppRoutePath
-from util import fragment_rfc791
+from util import fragment_rfc791, fragment_rfc8200
 
 import scapy.compat
 from scapy.layers.l2 import Ether, Raw
@@ -139,41 +139,36 @@ class TestMAP(VppTestCase):
         v4 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
               IP(src=self.pg0.remote_ip4, dst=self.pg0.remote_ip4) /
               UDP(sport=20000, dport=10000) /
-              Raw('\xa5' * 100))
+              Raw(b'\xa5' * 100))
         rx = self.send_and_expect(self.pg0, v4*1, self.pg0)
         v4_reply = v4[1]
         v4_reply.ttl -= 1
         for p in rx:
             self.validate(p[1], v4_reply)
 
-        self.logger.debug("show trace")
-
         #
         # Fire in a v4 packet that will be encapped to the BR
         #
         v4 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
               IP(src=self.pg0.remote_ip4, dst='192.168.1.1') /
               UDP(sport=20000, dport=10000) /
-              Raw('\xa5' * 100))
+              Raw(b'\xa5' * 100))
 
         self.send_and_assert_encapped_one(v4, "3000::1", map_translated_addr)
 
-        self.logger.debug("show trace")
         #
         # Verify reordered fragments are able to pass as well
         #
         v4 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
               IP(id=1, src=self.pg0.remote_ip4, dst='192.168.1.1') /
               UDP(sport=20000, dport=10000) /
-              Raw('\xa5' * 1000))
+              Raw(b'\xa5' * 1000))
 
         frags = fragment_rfc791(v4, 400)
         frags.reverse()
 
         self.send_and_assert_encapped(frags, "3000::1", map_translated_addr)
 
-        self.logger.debug("show trace")
-
         # Enable MAP on interface.
         self.vapi.map_if_enable_disable(is_enable=1,
                                         sw_if_index=self.pg1.sw_if_index,
@@ -183,7 +178,7 @@ class TestMAP(VppTestCase):
         v6 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
               IPv6(src=self.pg1.remote_ip6, dst=self.pg1.remote_ip6) /
               UDP(sport=20000, dport=10000) /
-              Raw('\xa5' * 100))
+              Raw(b'\xa5' * 100))
         rx = self.send_and_expect(self.pg1, v6*1, self.pg1)
         v6_reply = v6[1]
         v6_reply.hlim -= 1
@@ -198,7 +193,7 @@ class TestMAP(VppTestCase):
              IPv6(dst='3000::1', src=map_translated_addr) /
              IP(dst=self.pg0.remote_ip4, src='192.168.1.1') /
              UDP(sport=10000, dport=20000) /
-             Raw('\xa5' * 100))
+             Raw(b'\xa5' * 100))
 
         self.pg1.add_stream(p)
 
@@ -217,7 +212,7 @@ class TestMAP(VppTestCase):
         #
         p = (IP(id=1, dst=self.pg0.remote_ip4, src='192.168.1.1') /
              UDP(sport=10000, dport=20000) /
-             Raw('\xa5' * 1500))
+             Raw(b'\xa5' * 1500))
         frags = fragment_rfc791(p, 400)
         frags.reverse()
 
@@ -237,7 +232,28 @@ class TestMAP(VppTestCase):
             self.assertEqual(r[IP].src, p[IP].src)
             self.assertEqual(r[IP].dst, p[IP].dst)
 
-        return
+        # Verify that fragments pass even if ipv6 layer is fragmented
+        stream = (IPv6(dst='3000::1', src=map_translated_addr) / x
+                  for x in frags)
+
+        v6_stream = [
+            Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / x
+            for i in range(len(frags))
+            for x in fragment_rfc8200(
+                IPv6(dst='3000::1', src=map_translated_addr) / frags[i],
+                i, 200)]
+
+        self.pg1.add_stream(v6_stream)
+
+        self.pg_enable_capture(self.pg_interfaces)
+        self.pg_start()
+
+        rx = self.pg0.get_capture(len(frags))
+
+        for r in rx:
+            self.assertFalse(r.haslayer(IPv6))
+            self.assertEqual(r[IP].src, p[IP].src)
+            self.assertEqual(r[IP].dst, p[IP].dst)
 
         #
         # Pre-resolve. No API for this!!
@@ -257,7 +273,7 @@ class TestMAP(VppTestCase):
         pre_res_route.add_vpp_config()
 
         self.send_and_assert_encapped_one(v4, "3000::1",
-                                          "2001::c0a8:0:0",
+                                          map_translated_addr,
                                           dmac=self.pg1.remote_hosts[2].mac)
 
         #
@@ -268,7 +284,7 @@ class TestMAP(VppTestCase):
         pre_res_route.add_vpp_config()
 
         self.send_and_assert_encapped_one(v4, "3000::1",
-                                          "2001::c0a8:0:0",
+                                          map_translated_addr,
                                           dmac=self.pg1.remote_hosts[3].mac)
 
         #
@@ -316,7 +332,7 @@ class TestMAP(VppTestCase):
         v4 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
               IP(src=self.pg0.remote_ip4, dst=self.pg0.remote_ip4) /
               UDP(sport=20000, dport=10000) /
-              Raw('\xa5' * 100))
+              Raw(b'\xa5' * 100))
         rx = self.send_and_expect(self.pg0, v4*1, self.pg0)
         v4_reply = v4[1]
         v4_reply.ttl -= 1
@@ -326,7 +342,7 @@ class TestMAP(VppTestCase):
         v6 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
               IPv6(src=self.pg1.remote_ip6, dst=self.pg1.remote_ip6) /
               UDP(sport=20000, dport=10000) /
-              Raw('\xa5' * 100))
+              Raw(b'\xa5' * 100))
         rx = self.send_and_expect(self.pg1, v6*1, self.pg1)
         v6_reply = v6[1]
         v6_reply.hlim -= 1
@@ -447,6 +463,7 @@ class TestMAP(VppTestCase):
         for p in rx:
             pass
             # p.show2()
+
         # reass_pkt = reassemble(rx)
         # p4_reply.ttl -= 1
         # p4_reply.id = 256