blob: 77d22b95a33e2a3f44037d5885f0263f42b6c613 [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
Neale Ranns4f33c802019-04-10 12:39:10 +0000356class TestIpsecEspAll(ConfigIpsecESP,
357 IpsecTra4, IpsecTra6,
358 IpsecTun4, IpsecTun6):
359 """ Ipsec ESP all Algos """
360
361 def setUp(self):
362 super(TestIpsecEspAll, self).setUp()
363
364 def tearDown(self):
365 super(TestIpsecEspAll, self).tearDown()
366
Neale Ranns00625a62019-07-31 00:13:18 -0700367 @parameterized.expand(["ia32", "ipsecmb", "openssl"])
368 def test_crypto_algs(self, engine):
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400369 """AES-[CBC, GCM]-[128, 192, 256] 3DES-CBC SHA1 MD5 w/ & w/o ESN"""
Neale Ranns4f33c802019-04-10 12:39:10 +0000370
371 # foreach crypto algorithm
Neale Ranns47feb112019-04-11 15:14:07 +0000372 algos = [{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
373 IPSEC_API_CRYPTO_ALG_AES_GCM_128),
374 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
375 IPSEC_API_INTEG_ALG_NONE),
376 'scapy-crypto': "AES-GCM",
377 'scapy-integ': "NULL",
378 'key': "JPjyOWBeVEQiMe7h",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000379 'salt': 0},
380 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
381 IPSEC_API_CRYPTO_ALG_AES_GCM_192),
382 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
383 IPSEC_API_INTEG_ALG_NONE),
384 'scapy-crypto': "AES-GCM",
385 'scapy-integ': "NULL",
386 'key': "JPjyOWBeVEQiMe7h01234567",
387 'salt': 1010},
Neale Ranns47feb112019-04-11 15:14:07 +0000388 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
389 IPSEC_API_CRYPTO_ALG_AES_GCM_256),
390 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
391 IPSEC_API_INTEG_ALG_NONE),
392 'scapy-crypto': "AES-GCM",
393 'scapy-integ': "NULL",
394 'key': "JPjyOWBeVEQiMe7h0123456787654321",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000395 'salt': 2020},
Neale Ranns47feb112019-04-11 15:14:07 +0000396 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
397 IPSEC_API_CRYPTO_ALG_AES_CBC_128),
398 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400399 IPSEC_API_INTEG_ALG_MD5_96),
Neale Ranns47feb112019-04-11 15:14:07 +0000400 'scapy-crypto': "AES-CBC",
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400401 'scapy-integ': "HMAC-MD5-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000402 'salt': 0,
Neale Ranns4f33c802019-04-10 12:39:10 +0000403 'key': "JPjyOWBeVEQiMe7h"},
Neale Ranns47feb112019-04-11 15:14:07 +0000404 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
405 IPSEC_API_CRYPTO_ALG_AES_CBC_192),
406 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
407 IPSEC_API_INTEG_ALG_SHA1_96),
408 'scapy-crypto': "AES-CBC",
409 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000410 'salt': 0,
Neale Ranns4f33c802019-04-10 12:39:10 +0000411 'key': "JPjyOWBeVEQiMe7hJPjyOWBe"},
Neale Ranns47feb112019-04-11 15:14:07 +0000412 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
413 IPSEC_API_CRYPTO_ALG_AES_CBC_256),
414 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
415 IPSEC_API_INTEG_ALG_SHA1_96),
416 'scapy-crypto': "AES-CBC",
417 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000418 'salt': 0,
Vladimir Ratnikovf4805072019-05-17 09:17:59 -0400419 'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
420 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
421 IPSEC_API_CRYPTO_ALG_3DES_CBC),
422 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
423 IPSEC_API_INTEG_ALG_SHA1_96),
424 'scapy-crypto': "3DES",
425 'scapy-integ': "HMAC-SHA1-96",
426 'salt': 0,
Neale Ranns2cdcd0c2019-08-27 12:26:14 +0000427 'key': "JPjyOWBeVEQiMe7h00112233"},
428 {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
429 IPSEC_API_CRYPTO_ALG_NONE),
430 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
431 IPSEC_API_INTEG_ALG_SHA1_96),
432 'scapy-crypto': "NULL",
433 'scapy-integ': "HMAC-SHA1-96",
434 'salt': 0,
Vladimir Ratnikovf4805072019-05-17 09:17:59 -0400435 'key': "JPjyOWBeVEQiMe7h00112233"}]
Neale Ranns4f33c802019-04-10 12:39:10 +0000436
Neale Ranns49e7ef62019-04-10 17:24:29 +0000437 # with and without ESN
438 flags = [0,
439 VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN]
Neale Ranns4f33c802019-04-10 12:39:10 +0000440
Neale Ranns00625a62019-07-31 00:13:18 -0700441 self.vapi.cli("set crypto handler all %s" % engine)
Neale Ranns4f33c802019-04-10 12:39:10 +0000442 #
Neale Ranns00625a62019-07-31 00:13:18 -0700443 # loop through each of the algorithms
Neale Ranns4f33c802019-04-10 12:39:10 +0000444 #
Neale Ranns00625a62019-07-31 00:13:18 -0700445 for algo in algos:
446 # with self.subTest(algo=algo['scapy']):
447 for flag in flags:
448 #
449 # setup up the config paramters
450 #
451 self.ipv4_params = IPsecIPv4Params()
452 self.ipv6_params = IPsecIPv6Params()
Neale Ranns4f33c802019-04-10 12:39:10 +0000453
Neale Ranns00625a62019-07-31 00:13:18 -0700454 self.params = {self.ipv4_params.addr_type:
455 self.ipv4_params,
456 self.ipv6_params.addr_type:
457 self.ipv6_params}
Neale Ranns4f33c802019-04-10 12:39:10 +0000458
Neale Ranns00625a62019-07-31 00:13:18 -0700459 for _, p in self.params.items():
460 p.auth_algo_vpp_id = algo['vpp-integ']
461 p.crypt_algo_vpp_id = algo['vpp-crypto']
462 p.crypt_algo = algo['scapy-crypto']
463 p.auth_algo = algo['scapy-integ']
464 p.crypt_key = algo['key']
465 p.salt = algo['salt']
466 p.flags = p.flags | flag
Neale Ranns4f33c802019-04-10 12:39:10 +0000467
Neale Ranns00625a62019-07-31 00:13:18 -0700468 self.reporter.send_keep_alive(self)
juraj.linkes11057662019-07-08 10:22:55 +0200469
Neale Ranns00625a62019-07-31 00:13:18 -0700470 #
471 # configure the SPDs. SAs, etc
472 #
473 self.config_network(self.params.values())
Neale Ranns4f33c802019-04-10 12:39:10 +0000474
Neale Ranns00625a62019-07-31 00:13:18 -0700475 #
476 # run some traffic.
477 # An exhautsive 4o6, 6o4 is not necessary
478 # for each algo
479 #
480 self.verify_tra_basic6(count=NUM_PKTS)
481 self.verify_tra_basic4(count=NUM_PKTS)
482 self.verify_tun_66(self.params[socket.AF_INET6],
483 count=NUM_PKTS)
484 self.verify_tun_44(self.params[socket.AF_INET],
485 count=NUM_PKTS)
Neale Ranns4f33c802019-04-10 12:39:10 +0000486
Neale Ranns00625a62019-07-31 00:13:18 -0700487 #
488 # remove the SPDs, SAs, etc
489 #
490 self.unconfig_network()
Neale Ranns4f33c802019-04-10 12:39:10 +0000491
Neale Ranns00625a62019-07-31 00:13:18 -0700492 #
493 # reconfigure the network and SA to run the
494 # anti replay tests
495 #
496 self.config_network(self.params.values())
497 self.verify_tra_anti_replay()
498 self.unconfig_network()
Neale Ranns6afaae12019-07-17 15:07:14 +0000499
Neale Ranns4f33c802019-04-10 12:39:10 +0000500
“mystarrocks”23f0c452017-12-11 07:11:51 -0800501if __name__ == '__main__':
502 unittest.main(testRunner=VppTestRunner)