blob: 8f8b2bf15509185aa030be6ae3cb6055bad980de [file] [log] [blame]
“mystarrocks”23f0c452017-12-11 07:11:51 -08001import socket
Klement Sekera28fb03f2018-04-17 11:36:55 +02002import unittest
“mystarrocks”23f0c452017-12-11 07:11:51 -08003
Klement Sekera31da2e32018-06-24 22:49:55 +02004from scapy.layers.ipsec import AH
Neale Ranns041add72020-01-02 04:06:10 +00005from scapy.layers.inet import IP, UDP
6from scapy.layers.inet6 import IPv6
7from scapy.layers.l2 import Ether
8from scapy.packet import Raw
“mystarrocks”23f0c452017-12-11 07:11:51 -08009
Klement Sekera31da2e32018-06-24 22:49:55 +020010from framework import VppTestRunner
Neale Ranns2ac885c2019-03-20 18:24:43 +000011from template_ipsec import TemplateIpsec, IpsecTra46Tests, IpsecTun46Tests, \
Neale Ranns4f33c802019-04-10 12:39:10 +000012 config_tun_params, config_tra_params, IPsecIPv4Params, IPsecIPv6Params, \
Neale Ranns4a56f4e2019-12-23 04:10:25 +000013 IpsecTra4, IpsecTun4, IpsecTra6, IpsecTun6, \
14 IpsecTun6HandoffTests, IpsecTun4HandoffTests
Klement Sekera31da2e32018-06-24 22:49:55 +020015from template_ipsec import IpsecTcpTests
Klement Sekerabf613952019-01-29 11:38:08 +010016from vpp_ipsec import VppIpsecSA, VppIpsecSpd, VppIpsecSpdEntry,\
17 VppIpsecSpdItfBinding
Neale Ranns311124e2019-01-24 04:52:25 -080018from vpp_ip_route import VppIpRoute, VppRoutePath
19from vpp_ip import DpoProto
Neale Ranns17dcec02019-01-09 21:22:20 -080020from vpp_papi import VppEnum
“mystarrocks”23f0c452017-12-11 07:11:51 -080021
22
Neale Ranns4f33c802019-04-10 12:39:10 +000023class ConfigIpsecAH(TemplateIpsec):
“mystarrocks”23f0c452017-12-11 07:11:51 -080024 """
25 Basic test for IPSEC using AH transport and Tunnel mode
26
Dave Wallaced1706812021-08-12 18:36:02 -040027 TRANSPORT MODE::
“mystarrocks”23f0c452017-12-11 07:11:51 -080028
Dave Wallaced1706812021-08-12 18:36:02 -040029 --- encrypt ---
30 |pg2| <-------> |VPP|
31 --- decrypt ---
“mystarrocks”23f0c452017-12-11 07:11:51 -080032
Dave Wallaced1706812021-08-12 18:36:02 -040033 TUNNEL MODE::
“mystarrocks”23f0c452017-12-11 07:11:51 -080034
Dave Wallaced1706812021-08-12 18:36:02 -040035 --- encrypt --- plain ---
36 |pg0| <------- |VPP| <------ |pg1|
37 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -080038
Dave Wallaced1706812021-08-12 18:36:02 -040039 --- decrypt --- plain ---
40 |pg0| -------> |VPP| ------> |pg1|
41 --- --- ---
42
“mystarrocks”23f0c452017-12-11 07:11:51 -080043 """
Neale Ranns4f33c802019-04-10 12:39:10 +000044 encryption_type = AH
45 net_objs = []
46 tra4_encrypt_node_name = "ah4-encrypt"
Neale Ranns8c609af2021-02-25 10:05:32 +000047 tra4_decrypt_node_name = ["ah4-decrypt", "ah4-decrypt"]
Neale Ranns4f33c802019-04-10 12:39:10 +000048 tra6_encrypt_node_name = "ah6-encrypt"
Neale Ranns8c609af2021-02-25 10:05:32 +000049 tra6_decrypt_node_name = ["ah6-decrypt", "ah6-decrypt"]
Neale Ranns4f33c802019-04-10 12:39:10 +000050 tun4_encrypt_node_name = "ah4-encrypt"
Neale Ranns8c609af2021-02-25 10:05:32 +000051 tun4_decrypt_node_name = ["ah4-decrypt", "ah4-decrypt"]
Neale Ranns4f33c802019-04-10 12:39:10 +000052 tun6_encrypt_node_name = "ah6-encrypt"
Neale Ranns8c609af2021-02-25 10:05:32 +000053 tun6_decrypt_node_name = ["ah6-decrypt", "ah6-decrypt"]
“mystarrocks”23f0c452017-12-11 07:11:51 -080054
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070055 @classmethod
56 def setUpClass(cls):
Neale Ranns4f33c802019-04-10 12:39:10 +000057 super(ConfigIpsecAH, cls).setUpClass()
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070058
59 @classmethod
60 def tearDownClass(cls):
Neale Ranns4f33c802019-04-10 12:39:10 +000061 super(ConfigIpsecAH, cls).tearDownClass()
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070062
Neale Ranns8e4a89b2019-01-23 08:16:17 -080063 def setUp(self):
Neale Ranns4f33c802019-04-10 12:39:10 +000064 super(ConfigIpsecAH, self).setUp()
“mystarrocks”23f0c452017-12-11 07:11:51 -080065
Neale Ranns4f33c802019-04-10 12:39:10 +000066 def tearDown(self):
67 super(ConfigIpsecAH, self).tearDown()
68
69 def config_network(self, params):
70 self.net_objs = []
Neale Ranns8e4a89b2019-01-23 08:16:17 -080071 self.tun_if = self.pg0
72 self.tra_if = self.pg2
73 self.logger.info(self.vapi.ppcli("show int addr"))
Neale Ranns311124e2019-01-24 04:52:25 -080074
75 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
76 self.tra_spd.add_vpp_config()
Neale Ranns4f33c802019-04-10 12:39:10 +000077 self.net_objs.append(self.tra_spd)
Neale Ranns311124e2019-01-24 04:52:25 -080078 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
79 self.tun_spd.add_vpp_config()
Neale Ranns4f33c802019-04-10 12:39:10 +000080 self.net_objs.append(self.tun_spd)
Neale Ranns311124e2019-01-24 04:52:25 -080081
Neale Ranns4f33c802019-04-10 12:39:10 +000082 b = VppIpsecSpdItfBinding(self, self.tra_spd,
83 self.tra_if)
84 b.add_vpp_config()
85 self.net_objs.append(b)
86
87 b = VppIpsecSpdItfBinding(self, self.tun_spd,
88 self.tun_if)
89 b.add_vpp_config()
90 self.net_objs.append(b)
91
92 for p in params:
Neale Ranns8e4a89b2019-01-23 08:16:17 -080093 self.config_ah_tra(p)
Neale Ranns2ac885c2019-03-20 18:24:43 +000094 config_tra_params(p, self.encryption_type)
Neale Ranns4f33c802019-04-10 12:39:10 +000095 for p in params:
Neale Ranns8e4a89b2019-01-23 08:16:17 -080096 self.config_ah_tun(p)
Neale Ranns12989b52019-09-26 16:20:19 +000097 config_tun_params(p, self.encryption_type, self.tun_if)
Neale Ranns4f33c802019-04-10 12:39:10 +000098 for p in params:
Neale Ranns311124e2019-01-24 04:52:25 -080099 d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4
Neale Ranns4f33c802019-04-10 12:39:10 +0000100 r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
101 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
102 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -0700103 proto=d)])
Neale Ranns4f33c802019-04-10 12:39:10 +0000104 r.add_vpp_config()
105 self.net_objs.append(r)
106 self.logger.info(self.vapi.ppcli("show ipsec all"))
“mystarrocks”23f0c452017-12-11 07:11:51 -0800107
Neale Ranns4f33c802019-04-10 12:39:10 +0000108 def unconfig_network(self):
109 for o in reversed(self.net_objs):
110 o.remove_vpp_config()
111 self.net_objs = []
“mystarrocks”23f0c452017-12-11 07:11:51 -0800112
Neale Ranns311124e2019-01-24 04:52:25 -0800113 def config_ah_tun(self, params):
114 addr_type = params.addr_type
115 scapy_tun_sa_id = params.scapy_tun_sa_id
116 scapy_tun_spi = params.scapy_tun_spi
117 vpp_tun_sa_id = params.vpp_tun_sa_id
118 vpp_tun_spi = params.vpp_tun_spi
119 auth_algo_vpp_id = params.auth_algo_vpp_id
120 auth_key = params.auth_key
121 crypt_algo_vpp_id = params.crypt_algo_vpp_id
122 crypt_key = params.crypt_key
123 remote_tun_if_host = params.remote_tun_if_host
124 addr_any = params.addr_any
125 addr_bcast = params.addr_bcast
Neale Ranns3833ffd2019-03-21 14:34:09 +0000126 flags = params.flags
Neale Ranns041add72020-01-02 04:06:10 +0000127 tun_flags = params.tun_flags
Neale Ranns17dcec02019-01-09 21:22:20 -0800128 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns4f33c802019-04-10 12:39:10 +0000129 objs = []
Neale Ranns9ec846c2021-02-09 14:04:02 +0000130 params.outer_hop_limit = 253
131 params.outer_flow_label = 0x12345
Neale Ranns17dcec02019-01-09 21:22:20 -0800132
Neale Rannseba31ec2019-02-17 18:04:27 +0000133 params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi,
134 auth_algo_vpp_id, auth_key,
135 crypt_algo_vpp_id, crypt_key,
136 self.vpp_ah_protocol,
137 self.tun_if.local_addr[addr_type],
Neale Ranns3833ffd2019-03-21 14:34:09 +0000138 self.tun_if.remote_addr[addr_type],
Neale Ranns041add72020-01-02 04:06:10 +0000139 tun_flags=tun_flags,
140 flags=flags,
141 dscp=params.dscp)
Neale Ranns4f33c802019-04-10 12:39:10 +0000142
Neale Rannseba31ec2019-02-17 18:04:27 +0000143 params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi,
144 auth_algo_vpp_id, auth_key,
145 crypt_algo_vpp_id, crypt_key,
146 self.vpp_ah_protocol,
147 self.tun_if.remote_addr[addr_type],
Neale Ranns3833ffd2019-03-21 14:34:09 +0000148 self.tun_if.local_addr[addr_type],
Neale Ranns041add72020-01-02 04:06:10 +0000149 tun_flags=tun_flags,
150 flags=flags,
151 dscp=params.dscp)
Neale Ranns4f33c802019-04-10 12:39:10 +0000152
153 objs.append(params.tun_sa_in)
154 objs.append(params.tun_sa_out)
Neale Ranns311124e2019-01-24 04:52:25 -0800155
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800156 params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd,
157 vpp_tun_sa_id,
158 addr_any, addr_bcast,
159 addr_any, addr_bcast,
160 socket.IPPROTO_AH)
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800161 params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd,
162 vpp_tun_sa_id,
163 addr_any, addr_bcast,
164 addr_any, addr_bcast,
165 socket.IPPROTO_AH,
166 is_outbound=0)
Neale Ranns311124e2019-01-24 04:52:25 -0800167
Neale Ranns4f33c802019-04-10 12:39:10 +0000168 objs.append(params.spd_policy_out_any)
169 objs.append(params.spd_policy_in_any)
Neale Ranns311124e2019-01-24 04:52:25 -0800170
Neale Ranns4f33c802019-04-10 12:39:10 +0000171 e1 = VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
172 remote_tun_if_host,
173 remote_tun_if_host,
174 self.pg1.remote_addr[addr_type],
175 self.pg1.remote_addr[addr_type],
176 0, priority=10,
177 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
178 is_outbound=0)
179 e2 = VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
180 self.pg1.remote_addr[addr_type],
181 self.pg1.remote_addr[addr_type],
182 remote_tun_if_host,
183 remote_tun_if_host,
184 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
185 priority=10)
186 e3 = VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
187 remote_tun_if_host,
188 remote_tun_if_host,
189 self.pg0.local_addr[addr_type],
190 self.pg0.local_addr[addr_type],
191 0, priority=20,
192 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
193 is_outbound=0)
194 e4 = VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
195 self.pg0.local_addr[addr_type],
196 self.pg0.local_addr[addr_type],
197 remote_tun_if_host,
198 remote_tun_if_host,
199 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
200 priority=20)
201
202 objs = objs + [e1, e2, e3, e4]
203
204 for o in objs:
205 o.add_vpp_config()
206
207 self.net_objs = self.net_objs + objs
Neale Ranns311124e2019-01-24 04:52:25 -0800208
209 def config_ah_tra(self, params):
210 addr_type = params.addr_type
211 scapy_tra_sa_id = params.scapy_tra_sa_id
212 scapy_tra_spi = params.scapy_tra_spi
213 vpp_tra_sa_id = params.vpp_tra_sa_id
214 vpp_tra_spi = params.vpp_tra_spi
215 auth_algo_vpp_id = params.auth_algo_vpp_id
216 auth_key = params.auth_key
217 crypt_algo_vpp_id = params.crypt_algo_vpp_id
218 crypt_key = params.crypt_key
219 addr_any = params.addr_any
220 addr_bcast = params.addr_bcast
Neale Ranns3833ffd2019-03-21 14:34:09 +0000221 flags = params.flags | (VppEnum.vl_api_ipsec_sad_flags_t.
222 IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
Neale Ranns17dcec02019-01-09 21:22:20 -0800223 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns4f33c802019-04-10 12:39:10 +0000224 objs = []
Neale Ranns311124e2019-01-24 04:52:25 -0800225
Neale Rannseba31ec2019-02-17 18:04:27 +0000226 params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi,
227 auth_algo_vpp_id, auth_key,
228 crypt_algo_vpp_id, crypt_key,
229 self.vpp_ah_protocol,
230 flags=flags)
Neale Rannseba31ec2019-02-17 18:04:27 +0000231 params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi,
232 auth_algo_vpp_id, auth_key,
233 crypt_algo_vpp_id, crypt_key,
234 self.vpp_ah_protocol,
235 flags=flags)
Neale Ranns311124e2019-01-24 04:52:25 -0800236
Neale Ranns4f33c802019-04-10 12:39:10 +0000237 objs.append(params.tra_sa_in)
238 objs.append(params.tra_sa_out)
Neale Ranns311124e2019-01-24 04:52:25 -0800239
Neale Ranns4f33c802019-04-10 12:39:10 +0000240 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
241 addr_any, addr_bcast,
242 addr_any, addr_bcast,
243 socket.IPPROTO_AH))
244 objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
245 addr_any, addr_bcast,
246 addr_any, addr_bcast,
247 socket.IPPROTO_AH,
248 is_outbound=0))
249 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
250 self.tra_if.local_addr[addr_type],
251 self.tra_if.local_addr[addr_type],
252 self.tra_if.remote_addr[addr_type],
253 self.tra_if.remote_addr[addr_type],
254 0, priority=10,
255 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
256 is_outbound=0))
257 objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
258 self.tra_if.local_addr[addr_type],
259 self.tra_if.local_addr[addr_type],
260 self.tra_if.remote_addr[addr_type],
261 self.tra_if.remote_addr[addr_type],
262 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
263 priority=10))
264
265 for o in objs:
266 o.add_vpp_config()
267 self.net_objs = self.net_objs + objs
268
269
270class TemplateIpsecAh(ConfigIpsecAH):
271 """
272 Basic test for IPSEC using AH transport and Tunnel mode
273
Dave Wallaced1706812021-08-12 18:36:02 -0400274 TRANSPORT MODE::
Neale Ranns4f33c802019-04-10 12:39:10 +0000275
Dave Wallaced1706812021-08-12 18:36:02 -0400276 --- encrypt ---
277 |pg2| <-------> |VPP|
278 --- decrypt ---
Neale Ranns4f33c802019-04-10 12:39:10 +0000279
Dave Wallaced1706812021-08-12 18:36:02 -0400280 TUNNEL MODE::
Neale Ranns4f33c802019-04-10 12:39:10 +0000281
Dave Wallaced1706812021-08-12 18:36:02 -0400282 --- encrypt --- plain ---
283 |pg0| <------- |VPP| <------ |pg1|
284 --- --- ---
Neale Ranns4f33c802019-04-10 12:39:10 +0000285
Dave Wallaced1706812021-08-12 18:36:02 -0400286 --- decrypt --- plain ---
287 |pg0| -------> |VPP| ------> |pg1|
288 --- --- ---
289
Neale Ranns4f33c802019-04-10 12:39:10 +0000290 """
291 @classmethod
292 def setUpClass(cls):
293 super(TemplateIpsecAh, cls).setUpClass()
294
295 @classmethod
296 def tearDownClass(cls):
297 super(TemplateIpsecAh, cls).tearDownClass()
298
299 def setUp(self):
300 super(TemplateIpsecAh, self).setUp()
301 self.config_network(self.params.values())
302
303 def tearDown(self):
304 self.unconfig_network()
305 super(TemplateIpsecAh, self).tearDown()
Neale Ranns311124e2019-01-24 04:52:25 -0800306
“mystarrocks”23f0c452017-12-11 07:11:51 -0800307
Neale Ranns1091c4a2019-04-08 14:48:23 +0000308class TestIpsecAh1(TemplateIpsecAh, IpsecTcpTests):
309 """ Ipsec AH - TCP tests """
310 pass
311
312
313class TestIpsecAh2(TemplateIpsecAh, IpsecTra46Tests, IpsecTun46Tests):
314 """ Ipsec AH w/ SHA1 """
Neale Ranns4f33c802019-04-10 12:39:10 +0000315 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800316
“mystarrocks”23f0c452017-12-11 07:11:51 -0800317
Neale Ranns041add72020-01-02 04:06:10 +0000318class TestIpsecAhTun(TemplateIpsecAh, IpsecTun46Tests):
319 """ Ipsec AH - TUN encap tests """
320
321 def setUp(self):
322 self.ipv4_params = IPsecIPv4Params()
323 self.ipv6_params = IPsecIPv6Params()
324
325 c = (VppEnum.vl_api_tunnel_encap_decap_flags_t.
326 TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
327 c1 = c | (VppEnum.vl_api_tunnel_encap_decap_flags_t.
328 TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
329
330 self.ipv4_params.tun_flags = c
331 self.ipv6_params.tun_flags = c1
332
333 super(TestIpsecAhTun, self).setUp()
334
335 def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=54):
336 # set the DSCP + ECN - flags are set to copy only DSCP
337 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
338 IP(src=src, dst=dst, tos=5) /
339 UDP(sport=4444, dport=4444) /
340 Raw(b'X' * payload_size)
341 for i in range(count)]
342
Neale Ranns9ec846c2021-02-09 14:04:02 +0000343 def gen_pkts6(self, p, sw_intf, src, dst, count=1, payload_size=54):
Neale Ranns041add72020-01-02 04:06:10 +0000344 # set the DSCP + ECN - flags are set to copy both
345 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
346 IPv6(src=src, dst=dst, tc=5) /
347 UDP(sport=4444, dport=4444) /
348 Raw(b'X' * payload_size)
349 for i in range(count)]
350
351 def verify_encrypted(self, p, sa, rxs):
352 # just check that only the DSCP is copied
353 for rx in rxs:
354 self.assertEqual(rx[IP].tos, 4)
355
356 def verify_encrypted6(self, p, sa, rxs):
357 # just check that the DSCP & ECN are copied
358 for rx in rxs:
359 self.assertEqual(rx[IPv6].tc, 5)
360
361
362class TestIpsecAhTun2(TemplateIpsecAh, IpsecTun46Tests):
363 """ Ipsec AH - TUN encap tests """
364
365 def setUp(self):
366 self.ipv4_params = IPsecIPv4Params()
367 self.ipv6_params = IPsecIPv6Params()
368
369 self.ipv4_params.dscp = 3
370 self.ipv6_params.dscp = 4
371
372 super(TestIpsecAhTun2, self).setUp()
373
374 def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=54):
375 # set the DSCP + ECN - flags are set to copy only DSCP
376 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
377 IP(src=src, dst=dst, tos=0) /
378 UDP(sport=4444, dport=4444) /
379 Raw(b'X' * payload_size)
380 for i in range(count)]
381
Neale Ranns9ec846c2021-02-09 14:04:02 +0000382 def gen_pkts6(self, p, sw_intf, src, dst, count=1, payload_size=54):
Neale Ranns041add72020-01-02 04:06:10 +0000383 # set the DSCP + ECN - flags are set to copy both
384 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
385 IPv6(src=src, dst=dst, tc=0) /
386 UDP(sport=4444, dport=4444) /
387 Raw(b'X' * payload_size)
388 for i in range(count)]
389
390 def verify_encrypted(self, p, sa, rxs):
391 # just check that only the DSCP is copied
392 for rx in rxs:
393 self.assertEqual(rx[IP].tos, 0xc)
394
395 def verify_encrypted6(self, p, sa, rxs):
396 # just check that the DSCP & ECN are copied
397 for rx in rxs:
398 self.assertEqual(rx[IPv6].tc, 0x10)
399
400
Neale Ranns4a56f4e2019-12-23 04:10:25 +0000401class TestIpsecAhHandoff(TemplateIpsecAh,
402 IpsecTun6HandoffTests,
403 IpsecTun4HandoffTests):
404 """ Ipsec AH Handoff """
405 pass
406
407
Neale Ranns4f33c802019-04-10 12:39:10 +0000408class TestIpsecAhAll(ConfigIpsecAH,
409 IpsecTra4, IpsecTra6,
410 IpsecTun4, IpsecTun6):
411 """ Ipsec AH all Algos """
Neale Ranns3833ffd2019-03-21 14:34:09 +0000412
Neale Ranns4f33c802019-04-10 12:39:10 +0000413 def setUp(self):
414 super(TestIpsecAhAll, self).setUp()
Neale Ranns3833ffd2019-03-21 14:34:09 +0000415
Neale Ranns4f33c802019-04-10 12:39:10 +0000416 def tearDown(self):
417 super(TestIpsecAhAll, self).tearDown()
Neale Ranns3833ffd2019-03-21 14:34:09 +0000418
Neale Ranns4f33c802019-04-10 12:39:10 +0000419 def test_integ_algs(self):
Damjan Marion4cb83812019-04-24 17:32:01 +0200420 """All Engines SHA[1_96, 256, 384, 512] w/ & w/o ESN"""
Neale Ranns92e93842019-04-08 07:36:50 +0000421 # foreach VPP crypto engine
422 engines = ["ia32", "ipsecmb", "openssl"]
423
Neale Ranns4f33c802019-04-10 12:39:10 +0000424 algos = [{'vpp': VppEnum.vl_api_ipsec_integ_alg_t.
425 IPSEC_API_INTEG_ALG_SHA1_96,
426 'scapy': "HMAC-SHA1-96"},
427 {'vpp': VppEnum.vl_api_ipsec_integ_alg_t.
428 IPSEC_API_INTEG_ALG_SHA_256_128,
429 'scapy': "SHA2-256-128"},
430 {'vpp': VppEnum.vl_api_ipsec_integ_alg_t.
431 IPSEC_API_INTEG_ALG_SHA_384_192,
432 'scapy': "SHA2-384-192"},
433 {'vpp': VppEnum.vl_api_ipsec_integ_alg_t.
434 IPSEC_API_INTEG_ALG_SHA_512_256,
435 'scapy': "SHA2-512-256"}]
Neale Ranns1091c4a2019-04-08 14:48:23 +0000436
Neale Ranns4f33c802019-04-10 12:39:10 +0000437 flags = [0, (VppEnum.vl_api_ipsec_sad_flags_t.
438 IPSEC_API_SAD_FLAG_USE_ESN)]
Neale Ranns1091c4a2019-04-08 14:48:23 +0000439
Neale Ranns4f33c802019-04-10 12:39:10 +0000440 #
Neale Ranns92e93842019-04-08 07:36:50 +0000441 # loop through the VPP engines
Neale Ranns4f33c802019-04-10 12:39:10 +0000442 #
Neale Ranns92e93842019-04-08 07:36:50 +0000443 for engine in engines:
Neale Ranns21ada3b2019-04-11 08:18:34 +0000444 self.vapi.cli("set crypto handler all %s" % engine)
Neale Ranns92e93842019-04-08 07:36:50 +0000445 #
446 # loop through each of the algorithms
447 #
448 for algo in algos:
449 # with self.subTest(algo=algo['scapy']):
450 for flag in flags:
451 #
452 # setup up the config paramters
453 #
454 self.ipv4_params = IPsecIPv4Params()
455 self.ipv6_params = IPsecIPv6Params()
Neale Ranns1091c4a2019-04-08 14:48:23 +0000456
Neale Ranns92e93842019-04-08 07:36:50 +0000457 self.params = {self.ipv4_params.addr_type:
458 self.ipv4_params,
459 self.ipv6_params.addr_type:
460 self.ipv6_params}
Neale Ranns1091c4a2019-04-08 14:48:23 +0000461
Neale Ranns92e93842019-04-08 07:36:50 +0000462 for _, p in self.params.items():
463 p.auth_algo_vpp_id = algo['vpp']
464 p.auth_algo = algo['scapy']
465 p.flags = p.flags | flag
Neale Ranns1091c4a2019-04-08 14:48:23 +0000466
Neale Ranns92e93842019-04-08 07:36:50 +0000467 #
468 # configure the SPDs. SAs, etc
469 #
470 self.config_network(self.params.values())
Neale Ranns1091c4a2019-04-08 14:48:23 +0000471
Neale Ranns92e93842019-04-08 07:36:50 +0000472 #
473 # run some traffic.
474 # An exhautsive 4o6, 6o4 is not necessary for each algo
475 #
476 self.verify_tra_basic6(count=17)
477 self.verify_tra_basic4(count=17)
478 self.verify_tun_66(self.params[socket.AF_INET6], count=17)
479 self.verify_tun_44(self.params[socket.AF_INET], count=17)
Neale Ranns1091c4a2019-04-08 14:48:23 +0000480
Neale Ranns92e93842019-04-08 07:36:50 +0000481 #
482 # remove the SPDs, SAs, etc
483 #
484 self.unconfig_network()
Neale Ranns1091c4a2019-04-08 14:48:23 +0000485
486
“mystarrocks”23f0c452017-12-11 07:11:51 -0800487if __name__ == '__main__':
488 unittest.main(testRunner=VppTestRunner)