ipsec: add ipv6 support for ipsec tunnel interface
[vpp.git] / test / test_ipsec_tun_if_esp.py
1 import unittest
2 import socket
3 from scapy.layers.ipsec import ESP
4 from framework import VppTestRunner
5 from template_ipsec import TemplateIpsec, IpsecTun4Tests, IpsecTun6Tests, \
6     IpsecTcpTests
7 from vpp_ipsec_tun_interface import VppIpsecTunInterface
8 from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto
9
10
11 class TemplateIpsec4TunIfEsp(TemplateIpsec):
12     """ IPsec tunnel interface tests """
13
14     encryption_type = ESP
15
16     def setUp(self):
17         super(TemplateIpsec4TunIfEsp, self).setUp()
18
19         self.tun_if = self.pg0
20
21         p = self.ipv4_params
22         tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
23                                       p.scapy_tun_spi, p.crypt_algo_vpp_id,
24                                       p.crypt_key, p.crypt_key,
25                                       p.auth_algo_vpp_id, p.auth_key,
26                                       p.auth_key)
27         tun_if.add_vpp_config()
28         tun_if.admin_up()
29         tun_if.config_ip4()
30
31         VppIpRoute(self,  p.remote_tun_if_host, 32,
32                    [VppRoutePath(tun_if.remote_ip4,
33                                  0xffffffff)]).add_vpp_config()
34
35     def tearDown(self):
36         if not self.vpp_dead:
37             self.vapi.cli("show hardware")
38         super(TemplateIpsec4TunIfEsp, self).tearDown()
39
40
41 class TestIpsec4TunIfEsp1(TemplateIpsec4TunIfEsp, IpsecTun4Tests):
42     """ Ipsec ESP - TUN tests """
43     tun4_encrypt_node_name = "esp4-encrypt"
44     tun4_decrypt_node_name = "esp4-decrypt"
45
46
47 class TestIpsec4TunIfEsp2(TemplateIpsec4TunIfEsp, IpsecTcpTests):
48     """ Ipsec ESP - TCP tests """
49     pass
50
51
52 class TemplateIpsec6TunIfEsp(TemplateIpsec):
53     """ IPsec tunnel interface tests """
54
55     encryption_type = ESP
56
57     def setUp(self):
58         super(TemplateIpsec6TunIfEsp, self).setUp()
59
60         self.tun_if = self.pg0
61
62         p = self.ipv6_params
63         tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
64                                       p.scapy_tun_spi, p.crypt_algo_vpp_id,
65                                       p.crypt_key, p.crypt_key,
66                                       p.auth_algo_vpp_id, p.auth_key,
67                                       p.auth_key, is_ip6=True)
68         tun_if.add_vpp_config()
69         tun_if.admin_up()
70         tun_if.config_ip6()
71
72         VppIpRoute(self,  p.remote_tun_if_host, 32,
73                    [VppRoutePath(tun_if.remote_ip6,
74                                  0xffffffff,
75                                  proto=DpoProto.DPO_PROTO_IP6)],
76                    is_ip6=1).add_vpp_config()
77
78     def tearDown(self):
79         if not self.vpp_dead:
80             self.vapi.cli("show hardware")
81         super(TemplateIpsec6TunIfEsp, self).tearDown()
82
83
84 class TestIpsec6TunIfEsp1(TemplateIpsec6TunIfEsp, IpsecTun6Tests):
85     """ Ipsec ESP - TUN tests """
86     tun6_encrypt_node_name = "esp6-encrypt"
87     tun6_decrypt_node_name = "esp6-decrypt"
88
89
90 if __name__ == '__main__':
91     unittest.main(testRunner=VppTestRunner)