ip: test support python3
[vpp.git] / test / test_ipsec_tun_if_esp.py
index 00c1d14..971ec79 100644 (file)
@@ -312,7 +312,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
         #
         # change the key and the SPI
         #
-        p.crypt_key = 'X' + p.crypt_key[1:]
+        p.crypt_key = b'X' + p.crypt_key[1:]
         p.scapy_tun_spi += 1
         p.scapy_tun_sa_id += 1
         p.vpp_tun_spi += 1
@@ -370,7 +370,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                                 IPSEC_API_INTEG_ALG_NONE),
                   'scapy-crypto': "AES-GCM",
                   'scapy-integ': "NULL",
-                  'key': "JPjyOWBeVEQiMe7h",
+                  'key': b"JPjyOWBeVEQiMe7h",
                   'salt': 3333},
                  {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
                                  IPSEC_API_CRYPTO_ALG_AES_GCM_192),
@@ -378,7 +378,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                                 IPSEC_API_INTEG_ALG_NONE),
                   'scapy-crypto': "AES-GCM",
                   'scapy-integ': "NULL",
-                  'key': "JPjyOWBeVEQiMe7hJPjyOWBe",
+                  'key': b"JPjyOWBeVEQiMe7hJPjyOWBe",
                   'salt': 0},
                  {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
                                  IPSEC_API_CRYPTO_ALG_AES_GCM_256),
@@ -386,7 +386,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                                 IPSEC_API_INTEG_ALG_NONE),
                   'scapy-crypto': "AES-GCM",
                   'scapy-integ': "NULL",
-                  'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
+                  'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
                   'salt': 9999},
                  {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
                                  IPSEC_API_CRYPTO_ALG_AES_CBC_128),
@@ -395,7 +395,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                   'scapy-crypto': "AES-CBC",
                   'scapy-integ': "HMAC-SHA1-96",
                   'salt': 0,
-                  'key': "JPjyOWBeVEQiMe7h"},
+                  'key': b"JPjyOWBeVEQiMe7h"},
                  {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
                                  IPSEC_API_CRYPTO_ALG_AES_CBC_192),
                   'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
@@ -403,7 +403,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                   'scapy-crypto': "AES-CBC",
                   'scapy-integ': "HMAC-SHA1-96",
                   'salt': 0,
-                  'key': "JPjyOWBeVEQiMe7hJPjyOWBe"},
+                  'key': b"JPjyOWBeVEQiMe7hJPjyOWBe"},
                  {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
                                  IPSEC_API_CRYPTO_ALG_AES_CBC_256),
                   'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
@@ -411,7 +411,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                   'scapy-crypto': "AES-CBC",
                   'scapy-integ': "HMAC-SHA1-96",
                   'salt': 0,
-                  'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
+                  'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
                  {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
                                  IPSEC_API_CRYPTO_ALG_NONE),
                   'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
@@ -419,7 +419,7 @@ class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
                   'scapy-crypto': "NULL",
                   'scapy-integ': "HMAC-SHA1-96",
                   'salt': 0,
-                  'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"}]
+                  'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"}]
 
         for engine in engines:
             self.vapi.cli("set crypto handler all %s" % engine)
@@ -785,11 +785,17 @@ class TemplateIpsec4TunProtect(object):
         p.tun_if.add_vpp_config()
         p.tun_if.admin_up()
         p.tun_if.config_ip4()
+        p.tun_if.config_ip6()
 
         p.route = VppIpRoute(self, p.remote_tun_if_host, 32,
                              [VppRoutePath(p.tun_if.remote_ip4,
                                            0xffffffff)])
         p.route.add_vpp_config()
+        r = VppIpRoute(self, p.remote_tun_if_host6, 128,
+                       [VppRoutePath(p.tun_if.remote_ip6,
+                                     0xffffffff,
+                                     proto=DpoProto.DPO_PROTO_IP6)])
+        r.add_vpp_config()
 
     def unconfig_network(self, p):
         p.route.remove_vpp_config()
@@ -831,9 +837,16 @@ class TestIpsec4TunProtect(TemplateIpsec,
         c = p.tun_if.get_tx_stats()
         self.assertEqual(c['packets'], 127)
 
+        self.vapi.cli("clear ipsec sa")
+        self.verify_tun_64(p, count=127)
+        c = p.tun_if.get_rx_stats()
+        self.assertEqual(c['packets'], 254)
+        c = p.tun_if.get_tx_stats()
+        self.assertEqual(c['packets'], 254)
+
         # rekey - create new SAs and update the tunnel protection
         np = copy.copy(p)
-        np.crypt_key = 'X' + p.crypt_key[1:]
+        np.crypt_key = b'X' + p.crypt_key[1:]
         np.scapy_tun_spi += 100
         np.scapy_tun_sa_id += 1
         np.vpp_tun_spi += 100
@@ -847,9 +860,9 @@ class TestIpsec4TunProtect(TemplateIpsec,
 
         self.verify_tun_44(np, count=127)
         c = p.tun_if.get_rx_stats()
-        self.assertEqual(c['packets'], 254)
+        self.assertEqual(c['packets'], 381)
         c = p.tun_if.get_tx_stats()
-        self.assertEqual(c['packets'], 254)
+        self.assertEqual(c['packets'], 381)
 
         # teardown
         self.unconfig_protect(np)
@@ -977,7 +990,7 @@ class TestIpsec4TunProtectTun(TemplateIpsec,
 
         # rekey - create new SAs and update the tunnel protection
         np = copy.copy(p)
-        np.crypt_key = 'X' + p.crypt_key[1:]
+        np.crypt_key = b'X' + p.crypt_key[1:]
         np.scapy_tun_spi += 100
         np.scapy_tun_sa_id += 1
         np.vpp_tun_spi += 100
@@ -1052,12 +1065,17 @@ class TemplateIpsec6TunProtect(object):
         p.tun_if.add_vpp_config()
         p.tun_if.admin_up()
         p.tun_if.config_ip6()
+        p.tun_if.config_ip4()
 
         p.route = VppIpRoute(self, p.remote_tun_if_host, 128,
                              [VppRoutePath(p.tun_if.remote_ip6,
                                            0xffffffff,
                                            proto=DpoProto.DPO_PROTO_IP6)])
         p.route.add_vpp_config()
+        r = VppIpRoute(self, p.remote_tun_if_host4, 32,
+                       [VppRoutePath(p.tun_if.remote_ip4,
+                                     0xffffffff)])
+        r.add_vpp_config()
 
     def unconfig_network(self, p):
         p.route.remove_vpp_config()
@@ -1105,7 +1123,7 @@ class TestIpsec6TunProtect(TemplateIpsec,
 
         # rekey - create new SAs and update the tunnel protection
         np = copy.copy(p)
-        np.crypt_key = 'X' + p.crypt_key[1:]
+        np.crypt_key = b'X' + p.crypt_key[1:]
         np.scapy_tun_spi += 100
         np.scapy_tun_sa_id += 1
         np.vpp_tun_spi += 100
@@ -1128,7 +1146,7 @@ class TestIpsec6TunProtect(TemplateIpsec,
         #  2) swap output SA to [new]
         #  3) use only [new] input SA
         np3 = copy.copy(np)
-        np3.crypt_key = 'Z' + p.crypt_key[1:]
+        np3.crypt_key = b'Z' + p.crypt_key[1:]
         np3.scapy_tun_spi += 100
         np3.scapy_tun_sa_id += 1
         np3.vpp_tun_spi += 100
@@ -1167,6 +1185,26 @@ class TestIpsec6TunProtect(TemplateIpsec,
         self.unconfig_sa(np3)
         self.unconfig_network(p)
 
+    def test_tun_46(self):
+        """IPSEC tunnel protect"""
+
+        p = self.ipv6_params
+
+        self.config_network(p)
+        self.config_sa_tra(p)
+        self.config_protect(p)
+
+        self.verify_tun_46(p, count=127)
+        c = p.tun_if.get_rx_stats()
+        self.assertEqual(c['packets'], 127)
+        c = p.tun_if.get_tx_stats()
+        self.assertEqual(c['packets'], 127)
+
+        # teardown
+        self.unconfig_protect(p)
+        self.unconfig_sa(p)
+        self.unconfig_network(p)
+
 
 class TestIpsec6TunProtectTun(TemplateIpsec,
                               TemplateIpsec6TunProtect,
@@ -1247,7 +1285,7 @@ class TestIpsec6TunProtectTun(TemplateIpsec,
 
         # rekey - create new SAs and update the tunnel protection
         np = copy.copy(p)
-        np.crypt_key = 'X' + p.crypt_key[1:]
+        np.crypt_key = b'X' + p.crypt_key[1:]
         np.scapy_tun_spi += 100
         np.scapy_tun_sa_id += 1
         np.vpp_tun_spi += 100