blob: 8aea42ab3df7ad4f0dad3db8aa87cf9c0b0671a3 [file] [log] [blame]
Klement Sekerab4d30532018-11-08 13:00:02 +01001import unittest
2
3from framework import VppTestCase, VppTestRunner
Neale Ranns17dcec02019-01-09 21:22:20 -08004from template_ipsec import TemplateIpsec, IPsecIPv4Params
5from vpp_papi import VppEnum
Klement Sekerab4d30532018-11-08 13:00:02 +01006
7
8class IpsecApiTestCase(VppTestCase):
9 """ IPSec API tests """
10
Neale Ranns8e4a89b2019-01-23 08:16:17 -080011 def setUp(self):
12 super(IpsecApiTestCase, self).setUp()
13 self.create_pg_interfaces([0])
14 self.pg0.config_ip4()
15 self.pg0.admin_up()
16
Neale Ranns17dcec02019-01-09 21:22:20 -080017 self.vpp_esp_protocol = (VppEnum.vl_api_ipsec_proto_t.
18 IPSEC_API_PROTO_ESP)
19 self.vpp_ah_protocol = (VppEnum.vl_api_ipsec_proto_t.
20 IPSEC_API_PROTO_AH)
Neale Ranns8e4a89b2019-01-23 08:16:17 -080021 self.ipv4_params = IPsecIPv4Params()
22
23 def tearDown(self):
24 self.pg0.unconfig_ip4()
25 self.pg0.admin_down()
26 super(IpsecApiTestCase, self).tearDown()
Klement Sekerab4d30532018-11-08 13:00:02 +010027
28 def test_backend_dump(self):
29 """ backend dump """
30 d = self.vapi.ipsec_backend_dump()
31 self.assert_equal(len(d), 2, "number of ipsec backends in dump")
Neale Ranns8e4a89b2019-01-23 08:16:17 -080032 self.assert_equal(d[0].protocol, self.vpp_ah_protocol,
Klement Sekerab4d30532018-11-08 13:00:02 +010033 "ipsec protocol in dump entry")
34 self.assert_equal(d[0].index, 0, "index in dump entry")
35 self.assert_equal(d[0].active, 1, "active flag in dump entry")
Neale Ranns8e4a89b2019-01-23 08:16:17 -080036 self.assert_equal(d[1].protocol, self.vpp_esp_protocol,
Klement Sekerab4d30532018-11-08 13:00:02 +010037 "ipsec protocol in dump entry")
38 self.assert_equal(d[1].index, 0, "index in dump entry")
39 self.assert_equal(d[1].active, 1, "active flag in dump entry")
40
41 def test_select_valid_backend(self):
42 """ select valid backend """
Neale Ranns8e4a89b2019-01-23 08:16:17 -080043 self.vapi.ipsec_select_backend(self.vpp_ah_protocol, 0)
44 self.vapi.ipsec_select_backend(self.vpp_esp_protocol, 0)
Klement Sekerab4d30532018-11-08 13:00:02 +010045
46 def test_select_invalid_backend(self):
47 """ select invalid backend """
48 with self.vapi.assert_negative_api_retval():
Neale Ranns8e4a89b2019-01-23 08:16:17 -080049 self.vapi.ipsec_select_backend(self.vpp_ah_protocol, 200)
Klement Sekerab4d30532018-11-08 13:00:02 +010050 with self.vapi.assert_negative_api_retval():
Neale Ranns8e4a89b2019-01-23 08:16:17 -080051 self.vapi.ipsec_select_backend(self.vpp_esp_protocol, 200)
Klement Sekerab4d30532018-11-08 13:00:02 +010052
53 def test_select_backend_in_use(self):
54 """ attempt to change backend while sad configured """
Neale Ranns8e4a89b2019-01-23 08:16:17 -080055 params = self.ipv4_params
Klement Sekerab4d30532018-11-08 13:00:02 +010056 addr_type = params.addr_type
57 is_ipv6 = params.is_ipv6
58 scapy_tun_sa_id = params.scapy_tun_sa_id
59 scapy_tun_spi = params.scapy_tun_spi
60 auth_algo_vpp_id = params.auth_algo_vpp_id
61 auth_key = params.auth_key
62 crypt_algo_vpp_id = params.crypt_algo_vpp_id
63 crypt_key = params.crypt_key
64
Neale Ranns17dcec02019-01-09 21:22:20 -080065 self.vapi.ipsec_sad_entry_add_del(scapy_tun_sa_id, scapy_tun_spi,
Klement Sekerab4d30532018-11-08 13:00:02 +010066 auth_algo_vpp_id, auth_key,
67 crypt_algo_vpp_id, crypt_key,
Neale Ranns8e4a89b2019-01-23 08:16:17 -080068 self.vpp_ah_protocol,
Neale Ranns17dcec02019-01-09 21:22:20 -080069 self.pg0.local_addr[addr_type],
70 self.pg0.remote_addr[addr_type])
Klement Sekerab4d30532018-11-08 13:00:02 +010071 with self.vapi.assert_negative_api_retval():
72 self.vapi.ipsec_select_backend(
Neale Ranns8e4a89b2019-01-23 08:16:17 -080073 protocol=self.vpp_ah_protocol, index=0)
Klement Sekerab4d30532018-11-08 13:00:02 +010074
Neale Ranns17dcec02019-01-09 21:22:20 -080075 self.vapi.ipsec_sad_entry_add_del(scapy_tun_sa_id, scapy_tun_spi,
Klement Sekerab4d30532018-11-08 13:00:02 +010076 auth_algo_vpp_id, auth_key,
77 crypt_algo_vpp_id, crypt_key,
Neale Ranns8e4a89b2019-01-23 08:16:17 -080078 self.vpp_ah_protocol,
Neale Ranns17dcec02019-01-09 21:22:20 -080079 self.pg0.local_addr[addr_type],
80 self.pg0.remote_addr[addr_type],
Klement Sekerab4d30532018-11-08 13:00:02 +010081 is_add=0)
82 self.vapi.ipsec_select_backend(
Neale Ranns8e4a89b2019-01-23 08:16:17 -080083 protocol=self.vpp_ah_protocol, index=0)
Klement Sekerab4d30532018-11-08 13:00:02 +010084
85
86if __name__ == '__main__':
87 unittest.main(testRunner=VppTestRunner)