blob: afad2b1de1ff6db1ec0c5f463a200a3115004986 [file] [log] [blame]
Klement Sekerab4d30532018-11-08 13:00:02 +01001import unittest
2
3from framework import VppTestCase, VppTestRunner
Neale Ranns8e4a89b2019-01-23 08:16:17 -08004from template_ipsec import TemplateIpsec, IPsecIPv4Params
Klement Sekerab4d30532018-11-08 13:00:02 +01005
6
7class IpsecApiTestCase(VppTestCase):
8 """ IPSec API tests """
9
Neale Ranns8e4a89b2019-01-23 08:16:17 -080010 def setUp(self):
11 super(IpsecApiTestCase, self).setUp()
12 self.create_pg_interfaces([0])
13 self.pg0.config_ip4()
14 self.pg0.admin_up()
15
16 self.vpp_esp_protocol = 1
17 self.vpp_ah_protocol = 0
18 self.ipv4_params = IPsecIPv4Params()
19
20 def tearDown(self):
21 self.pg0.unconfig_ip4()
22 self.pg0.admin_down()
23 super(IpsecApiTestCase, self).tearDown()
Klement Sekerab4d30532018-11-08 13:00:02 +010024
25 def test_backend_dump(self):
26 """ backend dump """
27 d = self.vapi.ipsec_backend_dump()
28 self.assert_equal(len(d), 2, "number of ipsec backends in dump")
Neale Ranns8e4a89b2019-01-23 08:16:17 -080029 self.assert_equal(d[0].protocol, self.vpp_ah_protocol,
Klement Sekerab4d30532018-11-08 13:00:02 +010030 "ipsec protocol in dump entry")
31 self.assert_equal(d[0].index, 0, "index in dump entry")
32 self.assert_equal(d[0].active, 1, "active flag in dump entry")
Neale Ranns8e4a89b2019-01-23 08:16:17 -080033 self.assert_equal(d[1].protocol, self.vpp_esp_protocol,
Klement Sekerab4d30532018-11-08 13:00:02 +010034 "ipsec protocol in dump entry")
35 self.assert_equal(d[1].index, 0, "index in dump entry")
36 self.assert_equal(d[1].active, 1, "active flag in dump entry")
37
38 def test_select_valid_backend(self):
39 """ select valid backend """
Neale Ranns8e4a89b2019-01-23 08:16:17 -080040 self.vapi.ipsec_select_backend(self.vpp_ah_protocol, 0)
41 self.vapi.ipsec_select_backend(self.vpp_esp_protocol, 0)
Klement Sekerab4d30532018-11-08 13:00:02 +010042
43 def test_select_invalid_backend(self):
44 """ select invalid backend """
45 with self.vapi.assert_negative_api_retval():
Neale Ranns8e4a89b2019-01-23 08:16:17 -080046 self.vapi.ipsec_select_backend(self.vpp_ah_protocol, 200)
Klement Sekerab4d30532018-11-08 13:00:02 +010047 with self.vapi.assert_negative_api_retval():
Neale Ranns8e4a89b2019-01-23 08:16:17 -080048 self.vapi.ipsec_select_backend(self.vpp_esp_protocol, 200)
Klement Sekerab4d30532018-11-08 13:00:02 +010049
50 def test_select_backend_in_use(self):
51 """ attempt to change backend while sad configured """
Neale Ranns8e4a89b2019-01-23 08:16:17 -080052 params = self.ipv4_params
Klement Sekerab4d30532018-11-08 13:00:02 +010053 addr_type = params.addr_type
54 is_ipv6 = params.is_ipv6
55 scapy_tun_sa_id = params.scapy_tun_sa_id
56 scapy_tun_spi = params.scapy_tun_spi
57 auth_algo_vpp_id = params.auth_algo_vpp_id
58 auth_key = params.auth_key
59 crypt_algo_vpp_id = params.crypt_algo_vpp_id
60 crypt_key = params.crypt_key
61
62 self.vapi.ipsec_sad_add_del_entry(scapy_tun_sa_id, scapy_tun_spi,
63 auth_algo_vpp_id, auth_key,
64 crypt_algo_vpp_id, crypt_key,
Neale Ranns8e4a89b2019-01-23 08:16:17 -080065 self.vpp_ah_protocol,
Klement Sekerab4d30532018-11-08 13:00:02 +010066 self.pg0.local_addr_n[addr_type],
67 self.pg0.remote_addr_n[addr_type],
68 is_tunnel=1, is_tunnel_ipv6=is_ipv6)
69 with self.vapi.assert_negative_api_retval():
70 self.vapi.ipsec_select_backend(
Neale Ranns8e4a89b2019-01-23 08:16:17 -080071 protocol=self.vpp_ah_protocol, index=0)
Klement Sekerab4d30532018-11-08 13:00:02 +010072
73 self.vapi.ipsec_sad_add_del_entry(scapy_tun_sa_id, scapy_tun_spi,
74 auth_algo_vpp_id, auth_key,
75 crypt_algo_vpp_id, crypt_key,
Neale Ranns8e4a89b2019-01-23 08:16:17 -080076 self.vpp_ah_protocol,
Klement Sekerab4d30532018-11-08 13:00:02 +010077 self.pg0.local_addr_n[addr_type],
78 self.pg0.remote_addr_n[addr_type],
79 is_tunnel=1, is_tunnel_ipv6=is_ipv6,
80 is_add=0)
81 self.vapi.ipsec_select_backend(
Neale Ranns8e4a89b2019-01-23 08:16:17 -080082 protocol=self.vpp_ah_protocol, index=0)
Klement Sekerab4d30532018-11-08 13:00:02 +010083
84
85if __name__ == '__main__':
86 unittest.main(testRunner=VppTestRunner)