summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-02-07 07:26:12 -0800
committerDamjan Marion <dmarion@me.com>2019-06-18 13:54:35 +0000
commitc87b66c86201458c0475d50c6e93f1497f9eec2e (patch)
tree57bf69c2adb85a93b26a86b5a1110e4290e7f391 /test
parent097fa66b986f06281f603767d321ab13ab6c88c3 (diff)
ipsec: ipsec-tun protect
please consult the new tunnel proposal at: https://wiki.fd.io/view/VPP/IPSec Type: feature Change-Id: I52857fc92ae068b85f59be08bdbea1bd5932e291 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/template_ipsec.py98
-rw-r--r--test/test_ipsec_esp.py16
-rw-r--r--test/test_ipsec_tun_if_esp.py659
-rw-r--r--test/vpp_ipip_tun_interface.py40
-rw-r--r--test/vpp_ipsec.py50
-rw-r--r--test/vpp_ipsec_tun_interface.py45
-rw-r--r--test/vpp_papi_provider.py13
7 files changed, 792 insertions, 129 deletions
diff --git a/test/template_ipsec.py b/test/template_ipsec.py
index 87565edfdd7..d714a93d378 100644
--- a/test/template_ipsec.py
+++ b/test/template_ipsec.py
@@ -656,59 +656,85 @@ class IpsecTun4Tests(IpsecTun4):
class IpsecTun6(object):
""" verify methods for Tunnel v6 """
- def verify_counters6(self, p, count):
- if (hasattr(p, "tun_sa_in")):
- pkts = p.tun_sa_in.get_stats()['packets']
+ def verify_counters6(self, p_in, p_out, count):
+ if (hasattr(p_in, "tun_sa_in")):
+ pkts = p_in.tun_sa_in.get_stats()['packets']
self.assertEqual(pkts, count,
"incorrect SA in counts: expected %d != %d" %
(count, pkts))
- pkts = p.tun_sa_out.get_stats()['packets']
+ if (hasattr(p_out, "tun_sa_out")):
+ pkts = p_out.tun_sa_out.get_stats()['packets']
self.assertEqual(pkts, count,
"incorrect SA out counts: expected %d != %d" %
(count, pkts))
self.assert_packet_counter_equal(self.tun6_encrypt_node_name, count)
self.assert_packet_counter_equal(self.tun6_decrypt_node_name, count)
- def verify_tun_66(self, p, count=1):
- """ ipsec 6o6 tunnel basic test """
+ def verify_decrypted6(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[IPv6].src, p.remote_tun_if_host)
+ self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
+ self.assert_packet_checksums_valid(rx)
+
+ def verify_encrypted6(self, p, sa, rxs):
+ for rx in rxs:
+ self.assert_packet_checksums_valid(rx)
+ self.assertEqual(len(rx) - len(Ether()) - len(IPv6()),
+ rx[IPv6].plen)
+ try:
+ decrypt_pkt = p.vpp_tun_sa.decrypt(rx[IPv6])
+ if not decrypt_pkt.haslayer(IPv6):
+ decrypt_pkt = IPv6(decrypt_pkt[Raw].load)
+ self.assert_packet_checksums_valid(decrypt_pkt)
+ self.assert_equal(decrypt_pkt.src, self.pg1.remote_ip6)
+ self.assert_equal(decrypt_pkt.dst, p.remote_tun_if_host)
+ except:
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", decrypt_pkt))
+ except:
+ pass
+ raise
+
+ def verify_drop_tun_66(self, p_in, count=1, payload_size=64):
self.vapi.cli("clear errors")
+ self.vapi.cli("clear ipsec sa")
+
+ config_tun_params(p_in, self.encryption_type, self.tun_if)
+ send_pkts = self.gen_encrypt_pkts6(p_in.scapy_tun_sa, self.tun_if,
+ src=p_in.remote_tun_if_host,
+ dst=self.pg1.remote_ip6,
+ count=count)
+ self.send_and_assert_no_replies(self.tun_if, send_pkts)
+ self.logger.info(self.vapi.cli("sh punt stats"))
+
+ def verify_tun_66(self, p_in, p_out=None, count=1, payload_size=64):
+ self.vapi.cli("clear errors")
+ self.vapi.cli("clear ipsec sa")
+ if not p_out:
+ p_out = p_in
try:
- config_tun_params(p, self.encryption_type, self.tun_if)
- send_pkts = self.gen_encrypt_pkts6(p.scapy_tun_sa, self.tun_if,
- src=p.remote_tun_if_host,
+ config_tun_params(p_in, self.encryption_type, self.tun_if)
+ config_tun_params(p_out, self.encryption_type, self.tun_if)
+ send_pkts = self.gen_encrypt_pkts6(p_in.scapy_tun_sa, self.tun_if,
+ src=p_in.remote_tun_if_host,
dst=self.pg1.remote_ip6,
count=count)
recv_pkts = self.send_and_expect(self.tun_if, send_pkts, self.pg1)
- for recv_pkt in recv_pkts:
- self.assert_equal(recv_pkt[IPv6].src, p.remote_tun_if_host)
- self.assert_equal(recv_pkt[IPv6].dst, self.pg1.remote_ip6)
- self.assert_packet_checksums_valid(recv_pkt)
+ self.verify_decrypted6(p_in, recv_pkts)
+
send_pkts = self.gen_pkts6(self.pg1, src=self.pg1.remote_ip6,
- dst=p.remote_tun_if_host,
- count=count)
- recv_pkts = self.send_and_expect(self.pg1, send_pkts, self.tun_if)
- for recv_pkt in recv_pkts:
- self.assertEqual(len(recv_pkt) - len(Ether()) - len(IPv6()),
- recv_pkt[IPv6].plen)
- try:
- decrypt_pkt = p.vpp_tun_sa.decrypt(recv_pkt[IPv6])
- if not decrypt_pkt.haslayer(IPv6):
- decrypt_pkt = IPv6(decrypt_pkt[Raw].load)
- self.assert_equal(decrypt_pkt.src, self.pg1.remote_ip6)
- self.assert_equal(decrypt_pkt.dst, p.remote_tun_if_host)
- self.assert_packet_checksums_valid(decrypt_pkt)
- except:
- self.logger.debug(ppp("Unexpected packet:", recv_pkt))
- try:
- self.logger.debug(
- ppp("Decrypted packet:", decrypt_pkt))
- except:
- pass
- raise
+ dst=p_out.remote_tun_if_host,
+ count=count,
+ payload_size=payload_size)
+ recv_pkts = self.send_and_expect(self.pg1, send_pkts,
+ self.tun_if)
+ self.verify_encrypted6(p_out, p_out.vpp_tun_sa, recv_pkts)
+
finally:
self.logger.info(self.vapi.ppcli("show error"))
self.logger.info(self.vapi.ppcli("show ipsec all"))
- self.verify_counters6(p, count)
+ self.verify_counters6(p_in, p_out, count)
def verify_tun_46(self, p, count=1):
""" ipsec 4o6 tunnel basic test """
@@ -747,7 +773,7 @@ class IpsecTun6(object):
finally:
self.logger.info(self.vapi.ppcli("show error"))
self.logger.info(self.vapi.ppcli("show ipsec all"))
- self.verify_counters6(p, count)
+ self.verify_counters6(p, p, count)
class IpsecTun6Tests(IpsecTun6):
diff --git a/test/test_ipsec_esp.py b/test/test_ipsec_esp.py
index 8ed80c3d8de..96787716fb4 100644
--- a/test/test_ipsec_esp.py
+++ b/test/test_ipsec_esp.py
@@ -3,7 +3,7 @@ import unittest
from scapy.layers.ipsec import ESP
from scapy.layers.inet import UDP
-from framework import VppTestRunner
+from framework import VppTestRunner, is_skip_aarch64_set, is_platform_aarch64
from template_ipsec import IpsecTra46Tests, IpsecTun46Tests, TemplateIpsec, \
IpsecTcpTests, IpsecTun4Tests, IpsecTra4Tests, config_tra_params, \
IPsecIPv4Params, IPsecIPv6Params, \
@@ -14,6 +14,8 @@ from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_ip import DpoProto
from vpp_papi import VppEnum
+NUM_PKTS = 67
+
class ConfigIpsecESP(TemplateIpsec):
encryption_type = ESP
@@ -350,6 +352,8 @@ class TestIpsecEspUdp(TemplateIpsecEspUdp, IpsecTra4Tests):
pass
+@unittest.skipIf(is_skip_aarch64_set and is_platform_aarch64,
+ "test doesn't work on aarch64")
class TestIpsecEspAll(ConfigIpsecESP,
IpsecTra4, IpsecTra6,
IpsecTun4, IpsecTun6):
@@ -470,10 +474,12 @@ class TestIpsecEspAll(ConfigIpsecESP,
# An exhautsive 4o6, 6o4 is not necessary
# for each algo
#
- self.verify_tra_basic6(count=17)
- self.verify_tra_basic4(count=17)
- self.verify_tun_66(self.params[socket.AF_INET6], 17)
- self.verify_tun_44(self.params[socket.AF_INET], 17)
+ self.verify_tra_basic6(count=NUM_PKTS)
+ self.verify_tra_basic4(count=NUM_PKTS)
+ self.verify_tun_66(self.params[socket.AF_INET6],
+ count=NUM_PKTS)
+ self.verify_tun_44(self.params[socket.AF_INET],
+ count=NUM_PKTS)
#
# remove the SPDs, SAs, etc
diff --git a/test/test_ipsec_tun_if_esp.py b/test/test_ipsec_tun_if_esp.py
index 5ef0bdbb8c6..cc220d5a0a4 100644
--- a/test/test_ipsec_tun_if_esp.py
+++ b/test/test_ipsec_tun_if_esp.py
@@ -5,13 +5,15 @@ import copy
from scapy.layers.ipsec import ESP
from scapy.layers.l2 import Ether, Raw, GRE
from scapy.layers.inet import IP, UDP
+from scapy.layers.inet6 import IPv6
from framework import VppTestRunner, is_skip_aarch64_set, is_platform_aarch64
from template_ipsec import TemplateIpsec, IpsecTun4Tests, IpsecTun6Tests, \
IpsecTun4, IpsecTun6, IpsecTcpTests, config_tun_params
-from vpp_ipsec_tun_interface import VppIpsecTunInterface, \
- VppIpsecGRETunInterface
+from vpp_ipsec_tun_interface import VppIpsecTunInterface
+from vpp_gre_interface import VppGreInterface
+from vpp_ipip_tun_interface import VppIpIpTunInterface
from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto
-from vpp_ipsec import VppIpsecSA
+from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect
from vpp_l2 import VppBridgeDomain, VppBridgeDomainPort
from util import ppp
from vpp_papi import VppEnum
@@ -58,8 +60,6 @@ class TemplateIpsec4TunIfEsp(TemplateIpsec):
r.add_vpp_config()
def tearDown(self):
- if not self.vpp_dead:
- self.vapi.cli("show hardware")
super(TemplateIpsec4TunIfEsp, self).tearDown()
@@ -131,8 +131,6 @@ class TemplateIpsec6TunIfEsp(TemplateIpsec):
r.add_vpp_config()
def tearDown(self):
- if not self.vpp_dead:
- self.vapi.cli("show hardware")
super(TemplateIpsec6TunIfEsp, self).tearDown()
@@ -198,8 +196,6 @@ class TestIpsec4MultiTunIfEsp(TemplateIpsec, IpsecTun4):
0xffffffff)]).add_vpp_config()
def tearDown(self):
- if not self.vpp_dead:
- self.vapi.cli("show hardware")
super(TestIpsec4MultiTunIfEsp, self).tearDown()
def test_tun_44(self):
@@ -442,8 +438,6 @@ class TestIpsec6MultiTunIfEsp(TemplateIpsec, IpsecTun6):
r.add_vpp_config()
def tearDown(self):
- if not self.vpp_dead:
- self.vapi.cli("show hardware")
super(TestIpsec6MultiTunIfEsp, self).tearDown()
def test_tun_66(self):
@@ -456,9 +450,13 @@ class TestIpsec6MultiTunIfEsp(TemplateIpsec, IpsecTun6):
self.assertEqual(c['packets'], 127)
-class TemplateIpsecGRETunIfEsp(TemplateIpsec):
- """ IPsec GRE tunnel interface tests """
-
+@unittest.skipIf(is_skip_aarch64_set and is_platform_aarch64,
+ "test doesn't work on aarch64")
+class TestIpsecGreTebIfEsp(TemplateIpsec,
+ IpsecTun4Tests):
+ """ Ipsec GRE TEB ESP - TUN tests """
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
encryption_type = ESP
omac = "00:11:22:33:44:55"
@@ -509,7 +507,7 @@ class TemplateIpsecGRETunIfEsp(TemplateIpsec):
raise
def setUp(self):
- super(TemplateIpsecGRETunIfEsp, self).setUp()
+ super(TestIpsecGreTebIfEsp, self).setUp()
self.tun_if = self.pg0
@@ -534,33 +532,634 @@ class TemplateIpsecGRETunIfEsp(TemplateIpsec):
self.pg0.local_ip4)
p.tun_sa_in.add_vpp_config()
- self.tun = VppIpsecGRETunInterface(self, self.pg0,
- p.tun_sa_out.id,
- p.tun_sa_in.id)
-
+ self.tun = VppGreInterface(self,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4,
+ type=(VppEnum.vl_api_gre_tunnel_type_t.
+ GRE_API_TUNNEL_TYPE_TEB))
self.tun.add_vpp_config()
+
+ p.tun_protect = VppIpsecTunProtect(self,
+ self.tun,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+
+ p.tun_protect.add_vpp_config()
+
self.tun.admin_up()
self.tun.config_ip4()
- VppIpRoute(self, p.remote_tun_if_host, 32,
- [VppRoutePath(self.tun.remote_ip4,
- 0xffffffff)]).add_vpp_config()
VppBridgeDomainPort(self, bd1, self.tun).add_vpp_config()
VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
+ self.vapi.cli("clear ipsec sa")
+
def tearDown(self):
- if not self.vpp_dead:
- self.vapi.cli("show hardware")
self.tun.unconfig_ip4()
- super(TemplateIpsecGRETunIfEsp, self).tearDown()
+ super(TestIpsecGreTebIfEsp, self).tearDown()
-@unittest.skipIf(is_skip_aarch64_set and is_platform_aarch64,
- "test doesn't work on aarch64")
-class TestIpsecGRETunIfEsp1(TemplateIpsecGRETunIfEsp, IpsecTun4Tests):
+class TestIpsecGreIfEsp(TemplateIpsec,
+ IpsecTun4Tests):
""" Ipsec GRE ESP - TUN tests """
- tun4_encrypt_node_name = "esp4-encrypt"
- tun4_decrypt_node_name = "esp4-decrypt"
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+ encryption_type = ESP
+
+ def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=self.pg0.remote_ip4,
+ dst=self.pg0.local_ip4) /
+ GRE() /
+ IP(src=self.pg1.local_ip4,
+ dst=self.pg1.remote_ip4) /
+ UDP(sport=1144, dport=2233) /
+ Raw('X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw('X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
+ self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
+
+ def verify_encrypted(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IP])
+ if not pkt.haslayer(IP):
+ pkt = IP(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
+ self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
+ self.assertTrue(pkt.haslayer(GRE))
+ e = pkt[GRE]
+ self.assertEqual(e[IP].dst, "1.1.1.2")
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def setUp(self):
+ super(TestIpsecGreIfEsp, self).setUp()
+
+ self.tun_if = self.pg0
+
+ p = self.ipv4_params
+
+ bd1 = VppBridgeDomain(self, 1)
+ bd1.add_vpp_config()
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.pg0.remote_ip4,
+ self.pg0.local_ip4)
+ p.tun_sa_in.add_vpp_config()
+
+ self.tun = VppGreInterface(self,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4)
+ self.tun.add_vpp_config()
+
+ p.tun_protect = VppIpsecTunProtect(self,
+ self.tun,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+ p.tun_protect.add_vpp_config()
+
+ self.tun.admin_up()
+ self.tun.config_ip4()
+
+ VppIpRoute(self, "1.1.1.2", 32,
+ [VppRoutePath(self.tun.remote_ip4,
+ 0xffffffff)]).add_vpp_config()
+
+ def tearDown(self):
+ self.tun.unconfig_ip4()
+ super(TestIpsecGreIfEsp, self).tearDown()
+
+
+class TemplateIpsec4TunProtect(object):
+ """ IPsec IPv4 Tunnel protect """
+
+ def config_sa_tra(self, p):
+ config_tun_params(p, self.encryption_type, self.tun_if)
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_in.add_vpp_config()
+
+ def config_sa_tun(self, p):
+ config_tun_params(p, self.encryption_type, self.tun_if)
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.tun_if.remote_addr[p.addr_type],
+ self.tun_if.local_addr[p.addr_type])
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.tun_if.remote_addr[p.addr_type],
+ self.tun_if.local_addr[p.addr_type])
+ p.tun_sa_in.add_vpp_config()
+
+ def config_protect(self, p):
+ p.tun_protect = VppIpsecTunProtect(self,
+ p.tun_if,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+ p.tun_protect.add_vpp_config()
+
+ def config_network(self, p):
+ p.tun_if = VppIpIpTunInterface(self, self.pg0,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4)
+ p.tun_if.add_vpp_config()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+
+ p.route = VppIpRoute(self, p.remote_tun_if_host, 32,
+ [VppRoutePath(p.tun_if.remote_ip4,
+ 0xffffffff)])
+ p.route.add_vpp_config()
+
+ def unconfig_network(self, p):
+ p.route.remove_vpp_config()
+ p.tun_if.remove_vpp_config()
+
+ def unconfig_protect(self, p):
+ p.tun_protect.remove_vpp_config()
+
+ def unconfig_sa(self, p):
+ p.tun_sa_out.remove_vpp_config()
+ p.tun_sa_in.remove_vpp_config()
+
+
+class TestIpsec4TunProtect(TemplateIpsec,
+ TemplateIpsec4TunProtect,
+ IpsecTun4):
+ """ IPsec IPv4 Tunnel protect - transport mode"""
+
+ encryption_type = ESP
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+
+ def setUp(self):
+ super(TestIpsec4TunProtect, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec4TunProtect, self).tearDown()
+
+ def test_tun_44(self):
+ """IPSEC tunnel protect"""
+
+ p = self.ipv4_params
+
+ self.config_network(p)
+ self.config_sa_tra(p)
+ self.config_protect(p)
+
+ self.verify_tun_44(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)
+
+ # rekey - create new SAs and update the tunnel protection
+ np = copy.copy(p)
+ np.crypt_key = 'X' + p.crypt_key[1:]
+ np.scapy_tun_spi += 100
+ np.scapy_tun_sa_id += 1
+ np.vpp_tun_spi += 100
+ np.vpp_tun_sa_id += 1
+ np.tun_if.local_spi = p.vpp_tun_spi
+ np.tun_if.remote_spi = p.scapy_tun_spi
+
+ self.config_sa_tra(np)
+ self.config_protect(np)
+ self.unconfig_sa(p)
+
+ self.verify_tun_44(np, 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)
+
+ # teardown
+ self.unconfig_protect(np)
+ self.unconfig_sa(np)
+ self.unconfig_network(p)
+
+
+class TestIpsec4TunProtectTun(TemplateIpsec,
+ TemplateIpsec4TunProtect,
+ IpsecTun4):
+ """ IPsec IPv4 Tunnel protect - tunnel mode"""
+
+ encryption_type = ESP
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+
+ def setUp(self):
+ super(TestIpsec4TunProtectTun, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec4TunProtectTun, self).tearDown()
+
+ def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=sw_intf.remote_ip4,
+ dst=sw_intf.local_ip4) /
+ IP(src=src, dst=dst) /
+ UDP(sport=1144, dport=2233) /
+ Raw('X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ IP(src=src, dst=dst) /
+ UDP(sport=1144, dport=2233) /
+ Raw('X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
+ self.assert_equal(rx[IP].src, p.remote_tun_if_host)
+ self.assert_packet_checksums_valid(rx)
+
+ def verify_encrypted(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IP])
+ if not pkt.haslayer(IP):
+ pkt = IP(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
+ self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
+ inner = pkt[IP].payload
+ self.assertEqual(inner[IP][IP].dst, p.remote_tun_if_host)
+
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def test_tun_44(self):
+ """IPSEC tunnel protect """
+
+ p = self.ipv4_params
+
+ self.config_network(p)
+ self.config_sa_tun(p)
+ self.config_protect(p)
+
+ self.verify_tun_44(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)
+
+ # rekey - create new SAs and update the tunnel protection
+ np = copy.copy(p)
+ np.crypt_key = 'X' + p.crypt_key[1:]
+ np.scapy_tun_spi += 100
+ np.scapy_tun_sa_id += 1
+ np.vpp_tun_spi += 100
+ np.vpp_tun_sa_id += 1
+ np.tun_if.local_spi = p.vpp_tun_spi
+ np.tun_if.remote_spi = p.scapy_tun_spi
+
+ self.config_sa_tun(np)
+ self.config_protect(np)
+ self.unconfig_sa(p)
+
+ self.verify_tun_44(np, 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)
+
+ # teardown
+ self.unconfig_protect(np)
+ self.unconfig_sa(np)
+ self.unconfig_network(p)
+
+
+class TemplateIpsec6TunProtect(object):
+ """ IPsec IPv6 Tunnel protect """
+
+ def config_sa_tra(self, p):
+ config_tun_params(p, self.encryption_type, self.tun_if)
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_in.add_vpp_config()
+
+ def config_sa_tun(self, p):
+ config_tun_params(p, self.encryption_type, self.tun_if)
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.tun_if.remote_addr[p.addr_type],
+ self.tun_if.local_addr[p.addr_type])
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.tun_if.remote_addr[p.addr_type],
+ self.tun_if.local_addr[p.addr_type])
+ p.tun_sa_in.add_vpp_config()
+
+ def config_protect(self, p):
+ p.tun_protect = VppIpsecTunProtect(self,
+ p.tun_if,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+ p.tun_protect.add_vpp_config()
+
+ def config_network(self, p):
+ p.tun_if = VppIpIpTunInterface(self, self.pg0,
+ self.pg0.local_ip6,
+ self.pg0.remote_ip6)
+ p.tun_if.add_vpp_config()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip6()
+
+ p.route = VppIpRoute(self, p.remote_tun_if_host, 128,
+ [VppRoutePath(p.tun_if.remote_ip6,
+ 0xffffffff,
+ proto=DpoProto.DPO_PROTO_IP6)],
+ is_ip6=1)
+ p.route.add_vpp_config()
+
+ def unconfig_network(self, p):
+ p.route.remove_vpp_config()
+ p.tun_if.remove_vpp_config()
+
+ def unconfig_protect(self, p):
+ p.tun_protect.remove_vpp_config()
+
+ def unconfig_sa(self, p):
+ p.tun_sa_out.remove_vpp_config()
+ p.tun_sa_in.remove_vpp_config()
+
+
+class TestIpsec6TunProtect(TemplateIpsec,
+ TemplateIpsec6TunProtect,
+ IpsecTun6):
+ """ IPsec IPv6 Tunnel protect - transport mode"""
+
+ encryption_type = ESP
+ tun6_encrypt_node_name = "esp6-encrypt-tun"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
+
+ def setUp(self):
+ super(TestIpsec6TunProtect, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec6TunProtect, self).tearDown()
+
+ def test_tun_66(self):
+ """IPSEC tunnel protect"""
+
+ p = self.ipv6_params
+
+ self.config_network(p)
+ self.config_sa_tra(p)
+ self.config_protect(p)
+
+ self.verify_tun_66(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)
+
+ # rekey - create new SAs and update the tunnel protection
+ np = copy.copy(p)
+ np.crypt_key = 'X' + p.crypt_key[1:]
+ np.scapy_tun_spi += 100
+ np.scapy_tun_sa_id += 1
+ np.vpp_tun_spi += 100
+ np.vpp_tun_sa_id += 1
+ np.tun_if.local_spi = p.vpp_tun_spi
+ np.tun_if.remote_spi = p.scapy_tun_spi
+
+ self.config_sa_tra(np)
+ self.config_protect(np)
+ self.unconfig_sa(p)
+
+ self.verify_tun_66(np, 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)
+
+ # 3 phase rekey
+ # 1) add two input SAs [old, new]
+ # 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.scapy_tun_spi += 100
+ np3.scapy_tun_sa_id += 1
+ np3.vpp_tun_spi += 100
+ np3.vpp_tun_sa_id += 1
+ np3.tun_if.local_spi = p.vpp_tun_spi
+ np3.tun_if.remote_spi = p.scapy_tun_spi
+
+ self.config_sa_tra(np3)
+
+ # step 1;
+ p.tun_protect.update_vpp_config(np.tun_sa_out,
+ [np.tun_sa_in, np3.tun_sa_in])
+ self.verify_tun_66(np, np, count=127)
+ self.verify_tun_66(np3, np, count=127)
+
+ # step 2;
+ p.tun_protect.update_vpp_config(np3.tun_sa_out,
+ [np.tun_sa_in, np3.tun_sa_in])
+ self.verify_tun_66(np, np3, count=127)
+ self.verify_tun_66(np3, np3, count=127)
+
+ # step 1;
+ p.tun_protect.update_vpp_config(np3.tun_sa_out,
+ [np3.tun_sa_in])
+ self.verify_tun_66(np3, np3, count=127)
+ self.verify_drop_tun_66(np, count=127)
+
+ c = p.tun_if.get_rx_stats()
+ self.assertEqual(c['packets'], 127*7)
+ c = p.tun_if.get_tx_stats()
+ self.assertEqual(c['packets'], 127*7)
+ self.unconfig_sa(np)
+
+ # teardown
+ self.unconfig_protect(np3)
+ self.unconfig_sa(np3)
+ self.unconfig_network(p)
+
+
+class TestIpsec6TunProtectTun(TemplateIpsec,
+ TemplateIpsec6TunProtect,
+ IpsecTun6):
+ """ IPsec IPv6 Tunnel protect - tunnel mode"""
+
+ encryption_type = ESP
+ tun6_encrypt_node_name = "esp6-encrypt-tun"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
+
+ def setUp(self):
+ super(TestIpsec6TunProtectTun, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec6TunProtectTun, self).tearDown()
+
+ def gen_encrypt_pkts6(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IPv6(src=sw_intf.remote_ip6,
+ dst=sw_intf.local_ip6) /
+ IPv6(src=src, dst=dst) /
+ UDP(sport=1166, dport=2233) /
+ Raw('X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts6(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ IPv6(src=src, dst=dst) /
+ UDP(sport=1166, dport=2233) /
+ Raw('X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted6(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
+ self.assert_equal(rx[IPv6].src, p.remote_tun_if_host)
+ self.assert_packet_checksums_valid(rx)
+
+ def verify_encrypted6(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IPv6])
+ if not pkt.haslayer(IPv6):
+ pkt = IPv6(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assert_equal(pkt[IPv6].dst, self.pg0.remote_ip6)
+ self.assert_equal(pkt[IPv6].src, self.pg0.local_ip6)
+ inner = pkt[IPv6].payload
+ self.assertEqual(inner[IPv6][IPv6].dst, p.remote_tun_if_host)
+
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def test_tun_66(self):
+ """IPSEC tunnel protect """
+
+ p = self.ipv6_params
+
+ self.config_network(p)
+ self.config_sa_tun(p)
+ self.config_protect(p)
+
+ self.verify_tun_66(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)
+
+ # rekey - create new SAs and update the tunnel protection
+ np = copy.copy(p)
+ np.crypt_key = 'X' + p.crypt_key[1:]
+ np.scapy_tun_spi += 100
+ np.scapy_tun_sa_id += 1
+ np.vpp_tun_spi += 100
+ np.vpp_tun_sa_id += 1
+ np.tun_if.local_spi = p.vpp_tun_spi
+ np.tun_if.remote_spi = p.scapy_tun_spi
+
+ self.config_sa_tun(np)
+ self.config_protect(np)
+ self.unconfig_sa(p)
+
+ self.verify_tun_66(np, 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)
+
+ # teardown
+ self.unconfig_protect(np)
+ self.unconfig_sa(np)
+ self.unconfig_network(p)
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/vpp_ipip_tun_interface.py b/test/vpp_ipip_tun_interface.py
new file mode 100644
index 00000000000..6e5ade6eb3d
--- /dev/null
+++ b/test/vpp_ipip_tun_interface.py
@@ -0,0 +1,40 @@
+from vpp_tunnel_interface import VppTunnelInterface
+from ipaddress import ip_address
+
+
+class VppIpIpTunInterface(VppTunnelInterface):
+ """
+ VPP IP-IP Tunnel interface
+ """
+
+ def __init__(self, test, parent_if, src, dst):
+ super(VppIpIpTunInterface, self).__init__(test, parent_if)
+ self.src = src
+ self.dst = dst
+
+ def add_vpp_config(self):
+ r = self.test.vapi.ipip_add_tunnel(
+ tunnel={
+ 'src': self.src,
+ 'dst': self.dst,
+ 'table_id': 0,
+ 'instance': 0xffffffff,
+ })
+ self.set_sw_if_index(r.sw_if_index)
+ self.test.registry.register(self, self.test.logger)
+
+ def remove_vpp_config(self):
+ self.test.vapi.ipip_del_tunnel(sw_if_index=self._sw_if_index)
+
+ def query_vpp_config(self):
+ ts = self.test.vapi.ipip_tunnel_dump(sw_if_index=0xffffffff)
+ for t in ts:
+ if t.tunnel.sw_if_index == self._sw_if_index:
+ return True
+ return False
+
+ def __str__(self):
+ return self.object_id()
+
+ def object_id(self):
+ return "ipip-%d" % self._sw_if_index
diff --git a/test/vpp_ipsec.py b/test/vpp_ipsec.py
index 77a9d74edf3..0df8cb2a88a 100644
--- a/test/vpp_ipsec.py
+++ b/test/vpp_ipsec.py
@@ -247,3 +247,53 @@ class VppIpsecSA(VppObject):
def get_stats(self):
c = self.test.statistics.get_counter("/net/ipsec/sa")
return c[0][self.stat_index]
+
+
+class VppIpsecTunProtect(VppObject):
+ """
+ VPP IPSEC tunnel protection
+ """
+
+ def __init__(self, test, itf, sa_out, sas_in):
+ self.test = test
+ self.itf = itf
+ self.sas_in = []
+ for sa in sas_in:
+ self.sas_in.append(sa.id)
+ self.sa_out = sa_out.id
+
+ def update_vpp_config(self, sa_out, sas_in):
+ self.sas_in = []
+ for sa in sas_in:
+ self.sas_in.append(sa.id)
+ self.sa_out = sa_out.id
+ self.test.vapi.ipsec_tunnel_protect_update(
+ tunnel={
+ 'sw_if_index': self.itf._sw_if_index,
+ 'n_sa_in': len(self.sas_in),
+ 'sa_out': self.sa_out,
+ 'sa_in': self.sas_in})
+
+ def object_id(self):
+ return "ipsec-tun-protect-%s" % self.itf
+
+ def add_vpp_config(self):
+ self.test.vapi.ipsec_tunnel_protect_update(
+ tunnel={
+ 'sw_if_index': self.itf._sw_if_index,
+ 'n_sa_in': len(self.sas_in),
+ 'sa_out': self.sa_out,
+ 'sa_in': self.sas_in})
+ self.test.registry.register(self, self.test.logger)
+
+ def remove_vpp_config(self):
+ self.test.vapi.ipsec_tunnel_protect_del(
+ sw_if_index=self.itf.sw_if_index)
+
+ def query_vpp_config(self):
+ bs = self.test.vapi.ipsec_tunnel_protect_dump(
+ sw_if_index=self.itf.sw_if_index)
+ for b in bs:
+ if b.tun.sw_if_index == self.itf.sw_if_index:
+ return True
+ return False
diff --git a/test/vpp_ipsec_tun_interface.py b/test/vpp_ipsec_tun_interface.py
index 223ea4df154..97359b13281 100644
--- a/test/vpp_ipsec_tun_interface.py
+++ b/test/vpp_ipsec_tun_interface.py
@@ -51,48 +51,3 @@ class VppIpsecTunInterface(VppTunnelInterface):
def object_id(self):
return "ipsec-tun-if-%d" % self._sw_if_index
-
-
-class VppIpsecGRETunInterface(VppTunnelInterface):
- """
- VPP IPsec GRE Tunnel interface
- this creates headers
- IP / ESP / IP / GRE / payload
- i.e. it's GRE over IPSEC, rather than IPSEC over GRE.
- """
-
- def __init__(self, test, parent_if, sa_out, sa_in):
- super(VppIpsecGRETunInterface, self).__init__(test, parent_if)
- self.sa_in = sa_in
- self.sa_out = sa_out
-
- def add_vpp_config(self):
- r = self.test.vapi.ipsec_gre_tunnel_add_del(
- self.parent_if.local_ip4n,
- self.parent_if.remote_ip4n,
- self.sa_out,
- self.sa_in)
- self.set_sw_if_index(r.sw_if_index)
- self.generate_remote_hosts()
- self.test.registry.register(self, self.test.logger)
-
- def remove_vpp_config(self):
- self.test.vapi.ipsec_gre_tunnel_add_del(
- self.parent_if.local_ip4n,
- self.parent_if.remote_ip4n,
- self.sa_out,
- self.sa_in,
- is_add=0)
-
- def query_vpp_config(self):
- ts = self.test.vapi.ipsec_gre_tunnel_dump(sw_if_index=0xffffffff)
- for t in ts:
- if t.tunnel.sw_if_index == self._sw_if_index:
- return True
- return False
-
- def __str__(self):
- return self.object_id()
-
- def object_id(self):
- return "ipsec-gre-tun-if-%d" % self._sw_if_index
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 038a3718dde..75ec57f8221 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -1968,19 +1968,6 @@ class VppPapiProvider(object):
'salt': salt
})
- def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
- sa_out, sa_in, is_add=1):
- return self.api(self.papi.ipsec_gre_tunnel_add_del,
- {
- 'is_add': is_add,
- 'tunnel': {
- 'src': local_ip,
- 'dst': remote_ip,
- 'local_sa_id': sa_out,
- 'remote_sa_id': sa_in
- }
- })
-
def ipsec_select_backend(self, protocol, index):
return self.api(self.papi.ipsec_select_backend,
{'protocol': protocol, 'index': index})