blob: b72b7e1fe48b24fb9087a4c8830cf78d2175c100 [file] [log] [blame]
“mystarrocks”23f0c452017-12-11 07:11:51 -08001import socket
Klement Sekera28fb03f2018-04-17 11:36:55 +02002import unittest
Klement Sekera31da2e32018-06-24 22:49:55 +02003from scapy.layers.ipsec import ESP
Neale Ranns53f526b2019-02-25 14:32:02 +00004from scapy.layers.inet import UDP
“mystarrocks”23f0c452017-12-11 07:11:51 -08005
Neale Ranns00625a62019-07-31 00:13:18 -07006from parameterized import parameterized
juraj.linkes11057662019-07-08 10:22:55 +02007from framework import VppTestRunner
Neale Ranns53f526b2019-02-25 14:32:02 +00008from template_ipsec import IpsecTra46Tests, IpsecTun46Tests, TemplateIpsec, \
Neale Ranns4f33c802019-04-10 12:39:10 +00009 IpsecTcpTests, IpsecTun4Tests, IpsecTra4Tests, config_tra_params, \
10 IPsecIPv4Params, IPsecIPv6Params, \
11 IpsecTra4, IpsecTun4, IpsecTra6, IpsecTun6
Klement Sekerabf613952019-01-29 11:38:08 +010012from vpp_ipsec import VppIpsecSpd, VppIpsecSpdEntry, VppIpsecSA,\
Neale Ranns4f33c802019-04-10 12:39:10 +000013 VppIpsecSpdItfBinding
Neale Ranns311124e2019-01-24 04:52:25 -080014from vpp_ip_route import VppIpRoute, VppRoutePath
15from vpp_ip import DpoProto
Neale Ranns17dcec02019-01-09 21:22:20 -080016from vpp_papi import VppEnum
“mystarrocks”23f0c452017-12-11 07:11:51 -080017
Neale Rannsc87b66c2019-02-07 07:26:12 -080018NUM_PKTS = 67
19
“mystarrocks”23f0c452017-12-11 07:11:51 -080020
Neale Ranns4f33c802019-04-10 12:39:10 +000021class ConfigIpsecESP(TemplateIpsec):
22 encryption_type = ESP
23 tra4_encrypt_node_name = "esp4-encrypt"
24 tra4_decrypt_node_name = "esp4-decrypt"
25 tra6_encrypt_node_name = "esp6-encrypt"
26 tra6_decrypt_node_name = "esp6-decrypt"
27 tun4_encrypt_node_name = "esp4-encrypt"
28 tun4_decrypt_node_name = "esp4-decrypt"
29 tun6_encrypt_node_name = "esp6-encrypt"
30 tun6_decrypt_node_name = "esp6-decrypt"
Neale Ranns53f526b2019-02-25 14:32:02 +000031
Neale Ranns4f33c802019-04-10 12:39:10 +000032 @classmethod
33 def setUpClass(cls):
34 super(ConfigIpsecESP, cls).setUpClass()
Neale Ranns53f526b2019-02-25 14:32:02 +000035
Neale Ranns4f33c802019-04-10 12:39:10 +000036 @classmethod
37 def tearDownClass(cls):
38 super(ConfigIpsecESP, cls).tearDownClass()
Neale Ranns53f526b2019-02-25 14:32:02 +000039
Neale Ranns4f33c802019-04-10 12:39:10 +000040 def setUp(self):
41 super(ConfigIpsecESP, self).setUp()
Neale Ranns53f526b2019-02-25 14:32:02 +000042
Neale Ranns4f33c802019-04-10 12:39:10 +000043 def tearDown(self):
44 super(ConfigIpsecESP, self).tearDown()
45
46 def config_network(self, params):
47 self.net_objs = []
48 self.tun_if = self.pg0
49 self.tra_if = self.pg2
50 self.logger.info(self.vapi.ppcli("show int addr"))
51
52 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
53 self.tra_spd.add_vpp_config()
54 self.net_objs.append(self.tra_spd)
55 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
56 self.tun_spd.add_vpp_config()
57 self.net_objs.append(self.tun_spd)
58
59 b = VppIpsecSpdItfBinding(self, self.tun_spd,
60 self.tun_if)
61 b.add_vpp_config()
62 self.net_objs.append(b)
63
64 b = VppIpsecSpdItfBinding(self, self.tra_spd,
65 self.tra_if)
66 b.add_vpp_config()
67 self.net_objs.append(b)
68
69 for p in params:
70 self.config_esp_tra(p)
71 config_tra_params(p, self.encryption_type)
72 for p in params:
73 self.config_esp_tun(p)
74
75 for p in params:
76 d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4
77 r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
78 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
79 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -070080 proto=d)])
Neale Ranns4f33c802019-04-10 12:39:10 +000081 r.add_vpp_config()
82 self.net_objs.append(r)
83
84 self.logger.info(self.vapi.ppcli("show ipsec all"))
85
86 def unconfig_network(self):
87 for o in reversed(self.net_objs):
88 o.remove_vpp_config()
89 self.net_objs = []
90
91 def config_esp_tun(self, params):
92 addr_type = params.addr_type
93 scapy_tun_sa_id = params.scapy_tun_sa_id
94 scapy_tun_spi = params.scapy_tun_spi
95 vpp_tun_sa_id = params.vpp_tun_sa_id
96 vpp_tun_spi = params.vpp_tun_spi
97 auth_algo_vpp_id = params.auth_algo_vpp_id
98 auth_key = params.auth_key
99 crypt_algo_vpp_id = params.crypt_algo_vpp_id
100 crypt_key = params.crypt_key
101 remote_tun_if_host = params.remote_tun_if_host
102 addr_any = params.addr_any
103 addr_bcast = params.addr_bcast
104 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns49e7ef62019-04-10 17:24:29 +0000105 flags = params.flags
Neale Ranns80f6fd52019-04-16 02:41:34 +0000106 salt = params.salt
Neale Ranns4f33c802019-04-10 12:39:10 +0000107 objs = []
108
109 params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi,
110 auth_algo_vpp_id, auth_key,
111 crypt_algo_vpp_id, crypt_key,
112 self.vpp_esp_protocol,
113 self.tun_if.local_addr[addr_type],
Neale Ranns49e7ef62019-04-10 17:24:29 +0000114 self.tun_if.remote_addr[addr_type],
Neale Ranns80f6fd52019-04-16 02:41:34 +0000115 flags=flags,
116 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000117 params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi,
118 auth_algo_vpp_id, auth_key,
119 crypt_algo_vpp_id, crypt_key,
120 self.vpp_esp_protocol,
121 self.tun_if.remote_addr[addr_type],
Neale Ranns49e7ef62019-04-10 17:24:29 +0000122 self.tun_if.local_addr[addr_type],
Neale Ranns80f6fd52019-04-16 02:41:34 +0000123 flags=flags,
124 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000125 objs.append(params.tun_sa_in)
126 objs.append(params.tun_sa_out)
127
128 params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd,
129 scapy_tun_sa_id,
130 addr_any, addr_bcast,
131 addr_any, addr_bcast,
132 socket.IPPROTO_ESP)
133 params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd,
134 scapy_tun_sa_id,
135 addr_any, addr_bcast,
136 addr_any, addr_bcast,
137 socket.IPPROTO_ESP,
138 is_outbound=0)
139 objs.append(params.spd_policy_out_any)
140 objs.append(params.spd_policy_in_any)
141
142 objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
143 remote_tun_if_host, remote_tun_if_host,
144 self.pg1.remote_addr[addr_type],
145 self.pg1.remote_addr[addr_type],
146 0,
147 priority=10,
148 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
149 is_outbound=0))
150 objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
151 self.pg1.remote_addr[addr_type],
152 self.pg1.remote_addr[addr_type],
153 remote_tun_if_host, remote_tun_if_host,
154 0,
155 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
156 priority=10))
157 objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
158 remote_tun_if_host, remote_tun_if_host,
159 self.pg0.local_addr[addr_type],
160 self.pg0.local_addr[addr_type],
161 0,
162 priority=20,
163 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
164 is_outbound=0))
165 objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
166 self.pg0.local_addr[addr_type],
167 self.pg0.local_addr[addr_type],
168 remote_tun_if_host, remote_tun_if_host,
169 0,
170 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
171 priority=20))
172 for o in objs:
173 o.add_vpp_config()
174 self.net_objs = self.net_objs + objs
175
176 def config_esp_tra(self, params):
177 addr_type = params.addr_type
178 scapy_tra_sa_id = params.scapy_tra_sa_id
179 scapy_tra_spi = params.scapy_tra_spi
180 vpp_tra_sa_id = params.vpp_tra_sa_id
181 vpp_tra_spi = params.vpp_tra_spi
182 auth_algo_vpp_id = params.auth_algo_vpp_id
183 auth_key = params.auth_key
184 crypt_algo_vpp_id = params.crypt_algo_vpp_id
185 crypt_key = params.crypt_key
186 addr_any = params.addr_any
187 addr_bcast = params.addr_bcast
188 flags = (VppEnum.vl_api_ipsec_sad_flags_t.
189 IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
190 e = VppEnum.vl_api_ipsec_spd_action_t
191 flags = params.flags | flags
Neale Ranns80f6fd52019-04-16 02:41:34 +0000192 salt = params.salt
Neale Ranns4f33c802019-04-10 12:39:10 +0000193 objs = []
194
195 params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi,
196 auth_algo_vpp_id, auth_key,
197 crypt_algo_vpp_id, crypt_key,
198 self.vpp_esp_protocol,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000199 flags=flags,
200 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000201 params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi,
202 auth_algo_vpp_id, auth_key,
203 crypt_algo_vpp_id, crypt_key,
204 self.vpp_esp_protocol,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000205 flags=flags,
206 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000207 objs.append(params.tra_sa_in)
208 objs.append(params.tra_sa_out)
209
210 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
211 addr_any, addr_bcast,
212 addr_any, addr_bcast,
213 socket.IPPROTO_ESP))
214 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
215 addr_any, addr_bcast,
216 addr_any, addr_bcast,
217 socket.IPPROTO_ESP,
218 is_outbound=0))
219 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
220 self.tra_if.local_addr[addr_type],
221 self.tra_if.local_addr[addr_type],
222 self.tra_if.remote_addr[addr_type],
223 self.tra_if.remote_addr[addr_type],
224 0, priority=10,
225 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
226 is_outbound=0))
227 objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
228 self.tra_if.local_addr[addr_type],
229 self.tra_if.local_addr[addr_type],
230 self.tra_if.remote_addr[addr_type],
231 self.tra_if.remote_addr[addr_type],
232 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
233 priority=10))
234 for o in objs:
235 o.add_vpp_config()
236 self.net_objs = self.net_objs + objs
Neale Ranns53f526b2019-02-25 14:32:02 +0000237
238
Neale Ranns4f33c802019-04-10 12:39:10 +0000239class TemplateIpsecEsp(ConfigIpsecESP):
“mystarrocks”23f0c452017-12-11 07:11:51 -0800240 """
241 Basic test for ipsec esp sanity - tunnel and transport modes.
242
243 Below 4 cases are covered as part of this test
244 1) ipsec esp v4 transport basic test - IPv4 Transport mode
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700245 scenario using HMAC-SHA1-96 integrity algo
“mystarrocks”23f0c452017-12-11 07:11:51 -0800246 2) ipsec esp v4 transport burst test
247 Above test for 257 pkts
248 3) ipsec esp 4o4 tunnel basic test - IPv4 Tunnel mode
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700249 scenario using HMAC-SHA1-96 integrity algo
“mystarrocks”23f0c452017-12-11 07:11:51 -0800250 4) ipsec esp 4o4 tunnel burst test
251 Above test for 257 pkts
252
253 TRANSPORT MODE:
254
255 --- encrypt ---
256 |pg2| <-------> |VPP|
257 --- decrypt ---
258
259 TUNNEL MODE:
260
261 --- encrypt --- plain ---
Klement Sekera4b089f22018-04-17 18:04:57 +0200262 |pg0| <------- |VPP| <------ |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -0800263 --- --- ---
264
265 --- decrypt --- plain ---
Klement Sekera4b089f22018-04-17 18:04:57 +0200266 |pg0| -------> |VPP| ------> |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -0800267 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -0800268 """
269
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700270 @classmethod
271 def setUpClass(cls):
272 super(TemplateIpsecEsp, cls).setUpClass()
273
274 @classmethod
275 def tearDownClass(cls):
276 super(TemplateIpsecEsp, cls).tearDownClass()
277
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800278 def setUp(self):
279 super(TemplateIpsecEsp, self).setUp()
Neale Ranns4f33c802019-04-10 12:39:10 +0000280 self.config_network(self.params.values())
Klement Sekera611864f2018-09-26 11:19:00 +0200281
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800282 def tearDown(self):
Neale Ranns4f33c802019-04-10 12:39:10 +0000283 self.unconfig_network()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800284 super(TemplateIpsecEsp, self).tearDown()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800285
Klement Sekera611864f2018-09-26 11:19:00 +0200286
Neale Ranns53f526b2019-02-25 14:32:02 +0000287class TestIpsecEsp1(TemplateIpsecEsp, IpsecTra46Tests, IpsecTun46Tests):
Klement Sekera31da2e32018-06-24 22:49:55 +0200288 """ Ipsec ESP - TUN & TRA tests """
Neale Ranns4f33c802019-04-10 12:39:10 +0000289 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800290
“mystarrocks”23f0c452017-12-11 07:11:51 -0800291
Klement Sekera31da2e32018-06-24 22:49:55 +0200292class TestIpsecEsp2(TemplateIpsecEsp, IpsecTcpTests):
293 """ Ipsec ESP - TCP tests """
294 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800295
296
Neale Ranns4f33c802019-04-10 12:39:10 +0000297class TemplateIpsecEspUdp(ConfigIpsecESP):
Neale Ranns53f526b2019-02-25 14:32:02 +0000298 """
299 UDP encapped ESP
300 """
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700301
302 @classmethod
303 def setUpClass(cls):
304 super(TemplateIpsecEspUdp, cls).setUpClass()
305
306 @classmethod
307 def tearDownClass(cls):
308 super(TemplateIpsecEspUdp, cls).tearDownClass()
309
Neale Ranns53f526b2019-02-25 14:32:02 +0000310 def setUp(self):
311 super(TemplateIpsecEspUdp, self).setUp()
Neale Ranns4f33c802019-04-10 12:39:10 +0000312 self.net_objs = []
Neale Ranns53f526b2019-02-25 14:32:02 +0000313 self.tun_if = self.pg0
314 self.tra_if = self.pg2
315 self.logger.info(self.vapi.ppcli("show int addr"))
316
317 p = self.ipv4_params
318 p.flags = (VppEnum.vl_api_ipsec_sad_flags_t.
319 IPSEC_API_SAD_FLAG_UDP_ENCAP)
320 p.nat_header = UDP(sport=5454, dport=4500)
321
322 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
323 self.tra_spd.add_vpp_config()
324 VppIpsecSpdItfBinding(self, self.tra_spd,
325 self.tra_if).add_vpp_config()
326
Neale Ranns4f33c802019-04-10 12:39:10 +0000327 self.config_esp_tra(p)
Neale Ranns2ac885c2019-03-20 18:24:43 +0000328 config_tra_params(p, self.encryption_type)
Neale Ranns53f526b2019-02-25 14:32:02 +0000329
330 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
331 self.tun_spd.add_vpp_config()
332 VppIpsecSpdItfBinding(self, self.tun_spd,
333 self.tun_if).add_vpp_config()
334
Neale Ranns4f33c802019-04-10 12:39:10 +0000335 self.config_esp_tun(p)
Neale Ranns92e93842019-04-08 07:36:50 +0000336 self.logger.info(self.vapi.ppcli("show ipsec all"))
Neale Ranns53f526b2019-02-25 14:32:02 +0000337
338 d = DpoProto.DPO_PROTO_IP4
339 VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
340 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
341 0xffffffff,
342 proto=d)]).add_vpp_config()
343
344 def tearDown(self):
345 super(TemplateIpsecEspUdp, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700346
347 def show_commands_at_teardown(self):
348 self.logger.info(self.vapi.cli("show hardware"))
Neale Ranns53f526b2019-02-25 14:32:02 +0000349
350
Neale Ranns49e7ef62019-04-10 17:24:29 +0000351class TestIpsecEspUdp(TemplateIpsecEspUdp, IpsecTra4Tests):
Neale Ranns53f526b2019-02-25 14:32:02 +0000352 """ Ipsec NAT-T ESP UDP tests """
Neale Ranns53f526b2019-02-25 14:32:02 +0000353 pass
354
355
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000356class MyParameters():
357 def __init__(self):
358 self.engines = ["ia32", "ipsecmb", "openssl"]
359 flag_esn = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN
360 self.flags = [0, flag_esn]
Neale Ranns4f33c802019-04-10 12:39:10 +0000361 # foreach crypto algorithm
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000362 self.algos = {
363 'AES-GCM-128/NONE': {
364 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000365 IPSEC_API_CRYPTO_ALG_AES_GCM_128),
366 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
367 IPSEC_API_INTEG_ALG_NONE),
368 'scapy-crypto': "AES-GCM",
369 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200370 'key': b"JPjyOWBeVEQiMe7h",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000371 'salt': 0},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000372 'AES-GCM-192/NONE': {
373 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns80f6fd52019-04-16 02:41:34 +0000374 IPSEC_API_CRYPTO_ALG_AES_GCM_192),
375 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
376 IPSEC_API_INTEG_ALG_NONE),
377 'scapy-crypto': "AES-GCM",
378 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200379 'key': b"JPjyOWBeVEQiMe7h01234567",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000380 'salt': 1010},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000381 'AES-GCM-256/NONE': {
382 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000383 IPSEC_API_CRYPTO_ALG_AES_GCM_256),
384 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
385 IPSEC_API_INTEG_ALG_NONE),
386 'scapy-crypto': "AES-GCM",
387 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200388 'key': b"JPjyOWBeVEQiMe7h0123456787654321",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000389 'salt': 2020},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000390 'AES-CBC-128/MD5-96': {
391 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000392 IPSEC_API_CRYPTO_ALG_AES_CBC_128),
393 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400394 IPSEC_API_INTEG_ALG_MD5_96),
Neale Ranns47feb112019-04-11 15:14:07 +0000395 'scapy-crypto': "AES-CBC",
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400396 'scapy-integ': "HMAC-MD5-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000397 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200398 'key': b"JPjyOWBeVEQiMe7h"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000399 'AES-CBC-192/SHA1-96': {
400 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000401 IPSEC_API_CRYPTO_ALG_AES_CBC_192),
402 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
403 IPSEC_API_INTEG_ALG_SHA1_96),
404 'scapy-crypto': "AES-CBC",
405 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000406 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200407 'key': b"JPjyOWBeVEQiMe7hJPjyOWBe"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000408 'AES-CBC-256/SHA1-96': {
409 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000410 IPSEC_API_CRYPTO_ALG_AES_CBC_256),
411 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
412 IPSEC_API_INTEG_ALG_SHA1_96),
413 'scapy-crypto': "AES-CBC",
414 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000415 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200416 'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000417 '3DES-CBC/SHA1-96': {
418 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Vladimir Ratnikovf4805072019-05-17 09:17:59 -0400419 IPSEC_API_CRYPTO_ALG_3DES_CBC),
420 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
421 IPSEC_API_INTEG_ALG_SHA1_96),
422 'scapy-crypto': "3DES",
423 'scapy-integ': "HMAC-SHA1-96",
424 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200425 'key': b"JPjyOWBeVEQiMe7h00112233"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000426 'NONE/SHA1-96': {
427 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns2cdcd0c2019-08-27 12:26:14 +0000428 IPSEC_API_CRYPTO_ALG_NONE),
429 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
430 IPSEC_API_INTEG_ALG_SHA1_96),
431 'scapy-crypto': "NULL",
432 'scapy-integ': "HMAC-SHA1-96",
433 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200434 'key': b"JPjyOWBeVEQiMe7h00112233"}}
Neale Ranns4f33c802019-04-10 12:39:10 +0000435
Neale Ranns4f33c802019-04-10 12:39:10 +0000436
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000437class RunTestIpsecEspAll(ConfigIpsecESP,
438 IpsecTra4, IpsecTra6,
439 IpsecTun4, IpsecTun6):
440 """ Ipsec ESP all Algos """
441
442 def setUp(self):
443 super(RunTestIpsecEspAll, self).setUp()
444 test_args = str.split(self.__doc__, " ")
445
446 params = MyParameters()
447 self.engine = test_args[0]
448 self.flag = params.flags[0]
449 if test_args[1] == 'ESN':
450 self.flag = params.flags[1]
451
452 self.algo = params.algos[test_args[2]]
453
454 def tearDown(self):
455 super(RunTestIpsecEspAll, self).tearDown()
456
457 def run_test(self):
458 self.run_a_test(self.engine, self.flag, self.algo)
459
460 def run_a_test(self, engine, flag, algo):
Neale Ranns00625a62019-07-31 00:13:18 -0700461 self.vapi.cli("set crypto handler all %s" % engine)
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000462
463 self.ipv4_params = IPsecIPv4Params()
464 self.ipv6_params = IPsecIPv6Params()
465
466 self.params = {self.ipv4_params.addr_type:
467 self.ipv4_params,
468 self.ipv6_params.addr_type:
469 self.ipv6_params}
470
471 for _, p in self.params.items():
472 p.auth_algo_vpp_id = algo['vpp-integ']
473 p.crypt_algo_vpp_id = algo['vpp-crypto']
474 p.crypt_algo = algo['scapy-crypto']
475 p.auth_algo = algo['scapy-integ']
476 p.crypt_key = algo['key']
477 p.salt = algo['salt']
478 p.flags = p.flags | flag
479
480 self.reporter.send_keep_alive(self)
481
Neale Ranns4f33c802019-04-10 12:39:10 +0000482 #
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000483 # configure the SPDs. SAs, etc
Neale Ranns4f33c802019-04-10 12:39:10 +0000484 #
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000485 self.config_network(self.params.values())
Neale Ranns4f33c802019-04-10 12:39:10 +0000486
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000487 #
488 # run some traffic.
489 # An exhautsive 4o6, 6o4 is not necessary
490 # for each algo
491 #
492 self.verify_tra_basic6(count=NUM_PKTS)
493 self.verify_tra_basic4(count=NUM_PKTS)
494 self.verify_tun_66(self.params[socket.AF_INET6],
495 count=NUM_PKTS)
496 self.verify_tun_44(self.params[socket.AF_INET],
497 count=NUM_PKTS)
Neale Ranns4f33c802019-04-10 12:39:10 +0000498
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000499 #
500 # remove the SPDs, SAs, etc
501 #
502 self.unconfig_network()
Neale Ranns4f33c802019-04-10 12:39:10 +0000503
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000504 #
505 # reconfigure the network and SA to run the
506 # anti replay tests
507 #
508 self.config_network(self.params.values())
509 self.verify_tra_anti_replay()
510 self.unconfig_network()
juraj.linkes11057662019-07-08 10:22:55 +0200511
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000512#
513# To generate test classes, do:
514# grep '# GEN' test_ipsec_esp.py | sed -e 's/# GEN //g' | bash
515#
516# GEN for ENG in ia32 ipsecmb openssl; do \
517# GEN for FLG in noESN ESN; do for ALG in AES-GCM-128/NONE \
518# GEN AES-GCM-192/NONE AES-GCM-256/NONE AES-CBC-128/MD5-96 \
519# GEN AES-CBC-192/SHA1-96 AES-CBC-256/SHA1-96 \
520# GEN 3DES-CBC/SHA1-96 NONE/SHA1-96; do \
521# GEN echo -e "\n\nclass Test_${ENG}_${FLG}_${ALG}(RunTestIpsecEspAll):" |
522# GEN sed -e 's/-/_/g' -e 's#/#_#g' ; \
523# GEN echo ' """'$ENG $FLG $ALG IPSec test'"""' ;
524# GEN echo " def test_ipsec(self):";
525# GEN echo " self.run_test()";
526# GEN done; done; done
Neale Ranns4f33c802019-04-10 12:39:10 +0000527
Neale Ranns4f33c802019-04-10 12:39:10 +0000528
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000529class Test_ia32_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
530 """ia32 noESN AES-GCM-128/NONE IPSec test"""
531 def test_ipsec(self):
532 self.run_test()
Neale Ranns4f33c802019-04-10 12:39:10 +0000533
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000534
535class Test_ia32_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
536 """ia32 noESN AES-GCM-192/NONE IPSec test"""
537 def test_ipsec(self):
538 self.run_test()
539
540
541class Test_ia32_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
542 """ia32 noESN AES-GCM-256/NONE IPSec test"""
543 def test_ipsec(self):
544 self.run_test()
545
546
547class Test_ia32_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
548 """ia32 noESN AES-CBC-128/MD5-96 IPSec test"""
549 def test_ipsec(self):
550 self.run_test()
551
552
553class Test_ia32_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
554 """ia32 noESN AES-CBC-192/SHA1-96 IPSec test"""
555 def test_ipsec(self):
556 self.run_test()
557
558
559class Test_ia32_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
560 """ia32 noESN AES-CBC-256/SHA1-96 IPSec test"""
561 def test_ipsec(self):
562 self.run_test()
563
564
565class Test_ia32_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
566 """ia32 noESN 3DES-CBC/SHA1-96 IPSec test"""
567 def test_ipsec(self):
568 self.run_test()
569
570
571class Test_ia32_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
572 """ia32 noESN NONE/SHA1-96 IPSec test"""
573 def test_ipsec(self):
574 self.run_test()
575
576
577class Test_ia32_ESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
578 """ia32 ESN AES-GCM-128/NONE IPSec test"""
579 def test_ipsec(self):
580 self.run_test()
581
582
583class Test_ia32_ESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
584 """ia32 ESN AES-GCM-192/NONE IPSec test"""
585 def test_ipsec(self):
586 self.run_test()
587
588
589class Test_ia32_ESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
590 """ia32 ESN AES-GCM-256/NONE IPSec test"""
591 def test_ipsec(self):
592 self.run_test()
593
594
595class Test_ia32_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
596 """ia32 ESN AES-CBC-128/MD5-96 IPSec test"""
597 def test_ipsec(self):
598 self.run_test()
599
600
601class Test_ia32_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
602 """ia32 ESN AES-CBC-192/SHA1-96 IPSec test"""
603 def test_ipsec(self):
604 self.run_test()
605
606
607class Test_ia32_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
608 """ia32 ESN AES-CBC-256/SHA1-96 IPSec test"""
609 def test_ipsec(self):
610 self.run_test()
611
612
613class Test_ia32_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
614 """ia32 ESN 3DES-CBC/SHA1-96 IPSec test"""
615 def test_ipsec(self):
616 self.run_test()
617
618
619class Test_ia32_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
620 """ia32 ESN NONE/SHA1-96 IPSec test"""
621 def test_ipsec(self):
622 self.run_test()
623
624
625class Test_ipsecmb_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
626 """ipsecmb noESN AES-GCM-128/NONE IPSec test"""
627 def test_ipsec(self):
628 self.run_test()
629
630
631class Test_ipsecmb_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
632 """ipsecmb noESN AES-GCM-192/NONE IPSec test"""
633 def test_ipsec(self):
634 self.run_test()
635
636
637class Test_ipsecmb_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
638 """ipsecmb noESN AES-GCM-256/NONE IPSec test"""
639 def test_ipsec(self):
640 self.run_test()
641
642
643class Test_ipsecmb_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
644 """ipsecmb noESN AES-CBC-128/MD5-96 IPSec test"""
645 def test_ipsec(self):
646 self.run_test()
647
648
649class Test_ipsecmb_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
650 """ipsecmb noESN AES-CBC-192/SHA1-96 IPSec test"""
651 def test_ipsec(self):
652 self.run_test()
653
654
655class Test_ipsecmb_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
656 """ipsecmb noESN AES-CBC-256/SHA1-96 IPSec test"""
657 def test_ipsec(self):
658 self.run_test()
659
660
661class Test_ipsecmb_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
662 """ipsecmb noESN 3DES-CBC/SHA1-96 IPSec test"""
663 def test_ipsec(self):
664 self.run_test()
665
666
667class Test_ipsecmb_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
668 """ipsecmb noESN NONE/SHA1-96 IPSec test"""
669 def test_ipsec(self):
670 self.run_test()
671
672
673class Test_ipsecmb_ESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
674 """ipsecmb ESN AES-GCM-128/NONE IPSec test"""
675 def test_ipsec(self):
676 self.run_test()
677
678
679class Test_ipsecmb_ESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
680 """ipsecmb ESN AES-GCM-192/NONE IPSec test"""
681 def test_ipsec(self):
682 self.run_test()
683
684
685class Test_ipsecmb_ESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
686 """ipsecmb ESN AES-GCM-256/NONE IPSec test"""
687 def test_ipsec(self):
688 self.run_test()
689
690
691class Test_ipsecmb_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
692 """ipsecmb ESN AES-CBC-128/MD5-96 IPSec test"""
693 def test_ipsec(self):
694 self.run_test()
695
696
697class Test_ipsecmb_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
698 """ipsecmb ESN AES-CBC-192/SHA1-96 IPSec test"""
699 def test_ipsec(self):
700 self.run_test()
701
702
703class Test_ipsecmb_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
704 """ipsecmb ESN AES-CBC-256/SHA1-96 IPSec test"""
705 def test_ipsec(self):
706 self.run_test()
707
708
709class Test_ipsecmb_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
710 """ipsecmb ESN 3DES-CBC/SHA1-96 IPSec test"""
711 def test_ipsec(self):
712 self.run_test()
713
714
715class Test_ipsecmb_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
716 """ipsecmb ESN NONE/SHA1-96 IPSec test"""
717 def test_ipsec(self):
718 self.run_test()
719
720
721class Test_openssl_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
722 """openssl noESN AES-GCM-128/NONE IPSec test"""
723 def test_ipsec(self):
724 self.run_test()
725
726
727class Test_openssl_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
728 """openssl noESN AES-GCM-192/NONE IPSec test"""
729 def test_ipsec(self):
730 self.run_test()
731
732
733class Test_openssl_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
734 """openssl noESN AES-GCM-256/NONE IPSec test"""
735 def test_ipsec(self):
736 self.run_test()
737
738
739class Test_openssl_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
740 """openssl noESN AES-CBC-128/MD5-96 IPSec test"""
741 def test_ipsec(self):
742 self.run_test()
743
744
745class Test_openssl_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
746 """openssl noESN AES-CBC-192/SHA1-96 IPSec test"""
747 def test_ipsec(self):
748 self.run_test()
749
750
751class Test_openssl_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
752 """openssl noESN AES-CBC-256/SHA1-96 IPSec test"""
753 def test_ipsec(self):
754 self.run_test()
755
756
757class Test_openssl_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
758 """openssl noESN 3DES-CBC/SHA1-96 IPSec test"""
759 def test_ipsec(self):
760 self.run_test()
761
762
763class Test_openssl_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
764 """openssl noESN NONE/SHA1-96 IPSec test"""
765 def test_ipsec(self):
766 self.run_test()
767
768
769class Test_openssl_ESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
770 """openssl ESN AES-GCM-128/NONE IPSec test"""
771 def test_ipsec(self):
772 self.run_test()
773
774
775class Test_openssl_ESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
776 """openssl ESN AES-GCM-192/NONE IPSec test"""
777 def test_ipsec(self):
778 self.run_test()
779
780
781class Test_openssl_ESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
782 """openssl ESN AES-GCM-256/NONE IPSec test"""
783 def test_ipsec(self):
784 self.run_test()
785
786
787class Test_openssl_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
788 """openssl ESN AES-CBC-128/MD5-96 IPSec test"""
789 def test_ipsec(self):
790 self.run_test()
791
792
793class Test_openssl_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
794 """openssl ESN AES-CBC-192/SHA1-96 IPSec test"""
795 def test_ipsec(self):
796 self.run_test()
797
798
799class Test_openssl_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
800 """openssl ESN AES-CBC-256/SHA1-96 IPSec test"""
801 def test_ipsec(self):
802 self.run_test()
803
804
805class Test_openssl_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
806 """openssl ESN 3DES-CBC/SHA1-96 IPSec test"""
807 def test_ipsec(self):
808 self.run_test()
809
810
811class Test_openssl_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
812 """openssl ESN NONE/SHA1-96 IPSec test"""
813 def test_ipsec(self):
814 self.run_test()
Neale Ranns6afaae12019-07-17 15:07:14 +0000815
Neale Ranns4f33c802019-04-10 12:39:10 +0000816
“mystarrocks”23f0c452017-12-11 07:11:51 -0800817if __name__ == '__main__':
818 unittest.main(testRunner=VppTestRunner)