aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_ipsec_tun_if_esp.py
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-03-29 20:23:58 +0000
committerDamjan Marion <dmarion@me.com>2019-04-02 14:10:28 +0000
commitf05e732e4af604d37de5b665436594e8e2eee45d (patch)
tree015c62c1c60c22e6dcd8edc8ccf0bdca75cd2ac9 /test/test_ipsec_tun_if_esp.py
parent2b5ba9501c3dda3645bf01eb53b2821471f2a946 (diff)
IPSEC-GRE; tests
failing test disabled on ARM Change-Id: I6b7535cd8f51fdaf9786ba77f9f61a7d8d049bbd Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'test/test_ipsec_tun_if_esp.py')
-rw-r--r--test/test_ipsec_tun_if_esp.py116
1 files changed, 114 insertions, 2 deletions
diff --git a/test/test_ipsec_tun_if_esp.py b/test/test_ipsec_tun_if_esp.py
index 5af37bfac73..8d01185aa68 100644
--- a/test/test_ipsec_tun_if_esp.py
+++ b/test/test_ipsec_tun_if_esp.py
@@ -2,11 +2,17 @@ import unittest
import socket
import copy
from scapy.layers.ipsec import ESP
-from framework import VppTestRunner
+from scapy.layers.l2 import Ether, Raw, GRE
+from scapy.layers.inet import IP, UDP
+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
+from vpp_ipsec_tun_interface import VppIpsecTunInterface, \
+ VppIpsecGRETunInterface
from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto
+from vpp_ipsec import VppIpsecSA
+from vpp_l2 import VppBridgeDomain, VppBridgeDomainPort
+from util import ppp
class TemplateIpsec4TunIfEsp(TemplateIpsec):
@@ -248,5 +254,111 @@ class TestIpsec6MultiTunIfEsp(TemplateIpsec, IpsecTun6):
self.assertEqual(c['packets'], 127)
+class TemplateIpsecGRETunIfEsp(TemplateIpsec):
+ """ IPsec GRE tunnel interface tests """
+
+ encryption_type = ESP
+ omac = "00:11:22:33:44:55"
+
+ 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() /
+ Ether(dst=self.omac) /
+ 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 gen_pkts(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(dst=self.omac) /
+ 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.omac)
+ self.assert_equal(rx[IP].dst, "1.1.1.2")
+
+ 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[Ether]
+ self.assertEqual(e[Ether].dst, self.omac)
+ 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(TemplateIpsecGRETunIfEsp, 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 = VppIpsecGRETunInterface(self, self.pg0,
+ p.tun_sa_out.id,
+ p.tun_sa_in.id)
+
+ self.tun.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()
+
+ def tearDown(self):
+ if not self.vpp_dead:
+ self.vapi.cli("show hardware")
+ self.tun.unconfig_ip4()
+ super(TemplateIpsecGRETunIfEsp, self).tearDown()
+
+
+@unittest.skipIf(is_skip_aarch64_set and is_platform_aarch64,
+ "test doesn't work on aarch64")
+class TestIpsecGRETunIfEsp1(TemplateIpsecGRETunIfEsp, IpsecTun4Tests):
+ """ Ipsec GRE ESP - TUN tests """
+ tun4_encrypt_node_name = "esp4-encrypt"
+ tun4_decrypt_node_name = "esp4-decrypt"
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)