“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1 | import socket |
Klement Sekera | 28fb03f | 2018-04-17 11:36:55 +0200 | [diff] [blame] | 2 | import unittest |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 4 | from scapy.layers.ipsec import AH |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 5 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 6 | from framework import VppTestRunner |
Neale Ranns | 2ac885c | 2019-03-20 18:24:43 +0000 | [diff] [blame] | 7 | from template_ipsec import TemplateIpsec, IpsecTra46Tests, IpsecTun46Tests, \ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 8 | config_tun_params, config_tra_params, IPsecIPv4Params, IPsecIPv6Params, \ |
| 9 | IpsecTra4, IpsecTun4, IpsecTra6, IpsecTun6 |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 10 | from template_ipsec import IpsecTcpTests |
Klement Sekera | bf61395 | 2019-01-29 11:38:08 +0100 | [diff] [blame] | 11 | from vpp_ipsec import VppIpsecSA, VppIpsecSpd, VppIpsecSpdEntry,\ |
| 12 | VppIpsecSpdItfBinding |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 13 | from vpp_ip_route import VppIpRoute, VppRoutePath |
| 14 | from vpp_ip import DpoProto |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 15 | from vpp_papi import VppEnum |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 16 | |
| 17 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 18 | class ConfigIpsecAH(TemplateIpsec): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 19 | """ |
| 20 | Basic test for IPSEC using AH transport and Tunnel mode |
| 21 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 22 | TRANSPORT MODE: |
| 23 | |
| 24 | --- encrypt --- |
| 25 | |pg2| <-------> |VPP| |
| 26 | --- decrypt --- |
| 27 | |
| 28 | TUNNEL MODE: |
| 29 | |
| 30 | --- encrypt --- plain --- |
Klement Sekera | 84c6204 | 2018-05-11 11:06:09 +0200 | [diff] [blame] | 31 | |pg0| <------- |VPP| <------ |pg1| |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 32 | --- --- --- |
| 33 | |
| 34 | --- decrypt --- plain --- |
Klement Sekera | 84c6204 | 2018-05-11 11:06:09 +0200 | [diff] [blame] | 35 | |pg0| -------> |VPP| ------> |pg1| |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 36 | --- --- --- |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 37 | """ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 38 | encryption_type = AH |
| 39 | net_objs = [] |
| 40 | tra4_encrypt_node_name = "ah4-encrypt" |
| 41 | tra4_decrypt_node_name = "ah4-decrypt" |
| 42 | tra6_encrypt_node_name = "ah6-encrypt" |
| 43 | tra6_decrypt_node_name = "ah6-decrypt" |
| 44 | tun4_encrypt_node_name = "ah4-encrypt" |
| 45 | tun4_decrypt_node_name = "ah4-decrypt" |
| 46 | tun6_encrypt_node_name = "ah6-encrypt" |
| 47 | tun6_decrypt_node_name = "ah6-decrypt" |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 48 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 49 | @classmethod |
| 50 | def setUpClass(cls): |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 51 | super(ConfigIpsecAH, cls).setUpClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 52 | |
| 53 | @classmethod |
| 54 | def tearDownClass(cls): |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 55 | super(ConfigIpsecAH, cls).tearDownClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 56 | |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 57 | def setUp(self): |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 58 | super(ConfigIpsecAH, self).setUp() |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 59 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 60 | def tearDown(self): |
| 61 | super(ConfigIpsecAH, self).tearDown() |
| 62 | |
| 63 | def config_network(self, params): |
| 64 | self.net_objs = [] |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 65 | self.tun_if = self.pg0 |
| 66 | self.tra_if = self.pg2 |
| 67 | self.logger.info(self.vapi.ppcli("show int addr")) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 68 | |
| 69 | self.tra_spd = VppIpsecSpd(self, self.tra_spd_id) |
| 70 | self.tra_spd.add_vpp_config() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 71 | self.net_objs.append(self.tra_spd) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 72 | self.tun_spd = VppIpsecSpd(self, self.tun_spd_id) |
| 73 | self.tun_spd.add_vpp_config() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 74 | self.net_objs.append(self.tun_spd) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 75 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 76 | b = VppIpsecSpdItfBinding(self, self.tra_spd, |
| 77 | self.tra_if) |
| 78 | b.add_vpp_config() |
| 79 | self.net_objs.append(b) |
| 80 | |
| 81 | b = VppIpsecSpdItfBinding(self, self.tun_spd, |
| 82 | self.tun_if) |
| 83 | b.add_vpp_config() |
| 84 | self.net_objs.append(b) |
| 85 | |
| 86 | for p in params: |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 87 | self.config_ah_tra(p) |
Neale Ranns | 2ac885c | 2019-03-20 18:24:43 +0000 | [diff] [blame] | 88 | config_tra_params(p, self.encryption_type) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 89 | for p in params: |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 90 | self.config_ah_tun(p) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 91 | for p in params: |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 92 | d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4 |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 93 | r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len, |
| 94 | [VppRoutePath(self.tun_if.remote_addr[p.addr_type], |
| 95 | 0xffffffff, |
| 96 | proto=d)], |
| 97 | is_ip6=p.is_ipv6) |
| 98 | r.add_vpp_config() |
| 99 | self.net_objs.append(r) |
| 100 | self.logger.info(self.vapi.ppcli("show ipsec all")) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 101 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 102 | def unconfig_network(self): |
| 103 | for o in reversed(self.net_objs): |
| 104 | o.remove_vpp_config() |
| 105 | self.net_objs = [] |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 106 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 107 | def config_ah_tun(self, params): |
| 108 | addr_type = params.addr_type |
| 109 | scapy_tun_sa_id = params.scapy_tun_sa_id |
| 110 | scapy_tun_spi = params.scapy_tun_spi |
| 111 | vpp_tun_sa_id = params.vpp_tun_sa_id |
| 112 | vpp_tun_spi = params.vpp_tun_spi |
| 113 | auth_algo_vpp_id = params.auth_algo_vpp_id |
| 114 | auth_key = params.auth_key |
| 115 | crypt_algo_vpp_id = params.crypt_algo_vpp_id |
| 116 | crypt_key = params.crypt_key |
| 117 | remote_tun_if_host = params.remote_tun_if_host |
| 118 | addr_any = params.addr_any |
| 119 | addr_bcast = params.addr_bcast |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 120 | flags = params.flags |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 121 | e = VppEnum.vl_api_ipsec_spd_action_t |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 122 | objs = [] |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 123 | |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 124 | params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi, |
| 125 | auth_algo_vpp_id, auth_key, |
| 126 | crypt_algo_vpp_id, crypt_key, |
| 127 | self.vpp_ah_protocol, |
| 128 | self.tun_if.local_addr[addr_type], |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 129 | self.tun_if.remote_addr[addr_type], |
| 130 | flags=flags) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 131 | |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 132 | params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi, |
| 133 | auth_algo_vpp_id, auth_key, |
| 134 | crypt_algo_vpp_id, crypt_key, |
| 135 | self.vpp_ah_protocol, |
| 136 | self.tun_if.remote_addr[addr_type], |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 137 | self.tun_if.local_addr[addr_type], |
| 138 | flags=flags) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 139 | |
| 140 | objs.append(params.tun_sa_in) |
| 141 | objs.append(params.tun_sa_out) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 142 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 143 | params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd, |
| 144 | vpp_tun_sa_id, |
| 145 | addr_any, addr_bcast, |
| 146 | addr_any, addr_bcast, |
| 147 | socket.IPPROTO_AH) |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 148 | params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd, |
| 149 | vpp_tun_sa_id, |
| 150 | addr_any, addr_bcast, |
| 151 | addr_any, addr_bcast, |
| 152 | socket.IPPROTO_AH, |
| 153 | is_outbound=0) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 154 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 155 | objs.append(params.spd_policy_out_any) |
| 156 | objs.append(params.spd_policy_in_any) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 157 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 158 | e1 = VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id, |
| 159 | remote_tun_if_host, |
| 160 | remote_tun_if_host, |
| 161 | self.pg1.remote_addr[addr_type], |
| 162 | self.pg1.remote_addr[addr_type], |
| 163 | 0, priority=10, |
| 164 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 165 | is_outbound=0) |
| 166 | e2 = VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id, |
| 167 | self.pg1.remote_addr[addr_type], |
| 168 | self.pg1.remote_addr[addr_type], |
| 169 | remote_tun_if_host, |
| 170 | remote_tun_if_host, |
| 171 | 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 172 | priority=10) |
| 173 | e3 = VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id, |
| 174 | remote_tun_if_host, |
| 175 | remote_tun_if_host, |
| 176 | self.pg0.local_addr[addr_type], |
| 177 | self.pg0.local_addr[addr_type], |
| 178 | 0, priority=20, |
| 179 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 180 | is_outbound=0) |
| 181 | e4 = VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id, |
| 182 | self.pg0.local_addr[addr_type], |
| 183 | self.pg0.local_addr[addr_type], |
| 184 | remote_tun_if_host, |
| 185 | remote_tun_if_host, |
| 186 | 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 187 | priority=20) |
| 188 | |
| 189 | objs = objs + [e1, e2, e3, e4] |
| 190 | |
| 191 | for o in objs: |
| 192 | o.add_vpp_config() |
| 193 | |
| 194 | self.net_objs = self.net_objs + objs |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 195 | |
| 196 | def config_ah_tra(self, params): |
| 197 | addr_type = params.addr_type |
| 198 | scapy_tra_sa_id = params.scapy_tra_sa_id |
| 199 | scapy_tra_spi = params.scapy_tra_spi |
| 200 | vpp_tra_sa_id = params.vpp_tra_sa_id |
| 201 | vpp_tra_spi = params.vpp_tra_spi |
| 202 | auth_algo_vpp_id = params.auth_algo_vpp_id |
| 203 | auth_key = params.auth_key |
| 204 | crypt_algo_vpp_id = params.crypt_algo_vpp_id |
| 205 | crypt_key = params.crypt_key |
| 206 | addr_any = params.addr_any |
| 207 | addr_bcast = params.addr_bcast |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 208 | flags = params.flags | (VppEnum.vl_api_ipsec_sad_flags_t. |
| 209 | IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY) |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 210 | e = VppEnum.vl_api_ipsec_spd_action_t |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 211 | objs = [] |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 212 | |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 213 | params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi, |
| 214 | auth_algo_vpp_id, auth_key, |
| 215 | crypt_algo_vpp_id, crypt_key, |
| 216 | self.vpp_ah_protocol, |
| 217 | flags=flags) |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 218 | params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi, |
| 219 | auth_algo_vpp_id, auth_key, |
| 220 | crypt_algo_vpp_id, crypt_key, |
| 221 | self.vpp_ah_protocol, |
| 222 | flags=flags) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 223 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 224 | objs.append(params.tra_sa_in) |
| 225 | objs.append(params.tra_sa_out) |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 226 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 227 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 228 | addr_any, addr_bcast, |
| 229 | addr_any, addr_bcast, |
| 230 | socket.IPPROTO_AH)) |
| 231 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id, |
| 232 | addr_any, addr_bcast, |
| 233 | addr_any, addr_bcast, |
| 234 | socket.IPPROTO_AH, |
| 235 | is_outbound=0)) |
| 236 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 237 | self.tra_if.local_addr[addr_type], |
| 238 | self.tra_if.local_addr[addr_type], |
| 239 | self.tra_if.remote_addr[addr_type], |
| 240 | self.tra_if.remote_addr[addr_type], |
| 241 | 0, priority=10, |
| 242 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 243 | is_outbound=0)) |
| 244 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id, |
| 245 | self.tra_if.local_addr[addr_type], |
| 246 | self.tra_if.local_addr[addr_type], |
| 247 | self.tra_if.remote_addr[addr_type], |
| 248 | self.tra_if.remote_addr[addr_type], |
| 249 | 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 250 | priority=10)) |
| 251 | |
| 252 | for o in objs: |
| 253 | o.add_vpp_config() |
| 254 | self.net_objs = self.net_objs + objs |
| 255 | |
| 256 | |
| 257 | class TemplateIpsecAh(ConfigIpsecAH): |
| 258 | """ |
| 259 | Basic test for IPSEC using AH transport and Tunnel mode |
| 260 | |
| 261 | TRANSPORT MODE: |
| 262 | |
| 263 | --- encrypt --- |
| 264 | |pg2| <-------> |VPP| |
| 265 | --- decrypt --- |
| 266 | |
| 267 | TUNNEL MODE: |
| 268 | |
| 269 | --- encrypt --- plain --- |
| 270 | |pg0| <------- |VPP| <------ |pg1| |
| 271 | --- --- --- |
| 272 | |
| 273 | --- decrypt --- plain --- |
| 274 | |pg0| -------> |VPP| ------> |pg1| |
| 275 | --- --- --- |
| 276 | """ |
| 277 | @classmethod |
| 278 | def setUpClass(cls): |
| 279 | super(TemplateIpsecAh, cls).setUpClass() |
| 280 | |
| 281 | @classmethod |
| 282 | def tearDownClass(cls): |
| 283 | super(TemplateIpsecAh, cls).tearDownClass() |
| 284 | |
| 285 | def setUp(self): |
| 286 | super(TemplateIpsecAh, self).setUp() |
| 287 | self.config_network(self.params.values()) |
| 288 | |
| 289 | def tearDown(self): |
| 290 | self.unconfig_network() |
| 291 | super(TemplateIpsecAh, self).tearDown() |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 292 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 293 | |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 294 | class TestIpsecAh1(TemplateIpsecAh, IpsecTcpTests): |
| 295 | """ Ipsec AH - TCP tests """ |
| 296 | pass |
| 297 | |
| 298 | |
| 299 | class TestIpsecAh2(TemplateIpsecAh, IpsecTra46Tests, IpsecTun46Tests): |
| 300 | """ Ipsec AH w/ SHA1 """ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 301 | pass |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 302 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 303 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 304 | class TestIpsecAhAll(ConfigIpsecAH, |
| 305 | IpsecTra4, IpsecTra6, |
| 306 | IpsecTun4, IpsecTun6): |
| 307 | """ Ipsec AH all Algos """ |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 308 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 309 | def setUp(self): |
| 310 | super(TestIpsecAhAll, self).setUp() |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 311 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 312 | def tearDown(self): |
| 313 | super(TestIpsecAhAll, self).tearDown() |
Neale Ranns | 3833ffd | 2019-03-21 14:34:09 +0000 | [diff] [blame] | 314 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 315 | def test_integ_algs(self): |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 316 | """All Engines SHA[1_96, 256, 394, 512] w/ & w/o ESN""" |
| 317 | # foreach VPP crypto engine |
| 318 | engines = ["ia32", "ipsecmb", "openssl"] |
| 319 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 320 | algos = [{'vpp': VppEnum.vl_api_ipsec_integ_alg_t. |
| 321 | IPSEC_API_INTEG_ALG_SHA1_96, |
| 322 | 'scapy': "HMAC-SHA1-96"}, |
| 323 | {'vpp': VppEnum.vl_api_ipsec_integ_alg_t. |
| 324 | IPSEC_API_INTEG_ALG_SHA_256_128, |
| 325 | 'scapy': "SHA2-256-128"}, |
| 326 | {'vpp': VppEnum.vl_api_ipsec_integ_alg_t. |
| 327 | IPSEC_API_INTEG_ALG_SHA_384_192, |
| 328 | 'scapy': "SHA2-384-192"}, |
| 329 | {'vpp': VppEnum.vl_api_ipsec_integ_alg_t. |
| 330 | IPSEC_API_INTEG_ALG_SHA_512_256, |
| 331 | 'scapy': "SHA2-512-256"}] |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 332 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 333 | flags = [0, (VppEnum.vl_api_ipsec_sad_flags_t. |
| 334 | IPSEC_API_SAD_FLAG_USE_ESN)] |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 335 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 336 | # |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 337 | # loop through the VPP engines |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 338 | # |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 339 | for engine in engines: |
Neale Ranns | 21ada3b | 2019-04-11 08:18:34 +0000 | [diff] [blame] | 340 | self.vapi.cli("set crypto handler all %s" % engine) |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 341 | # |
| 342 | # loop through each of the algorithms |
| 343 | # |
| 344 | for algo in algos: |
| 345 | # with self.subTest(algo=algo['scapy']): |
| 346 | for flag in flags: |
| 347 | # |
| 348 | # setup up the config paramters |
| 349 | # |
| 350 | self.ipv4_params = IPsecIPv4Params() |
| 351 | self.ipv6_params = IPsecIPv6Params() |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 352 | |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 353 | self.params = {self.ipv4_params.addr_type: |
| 354 | self.ipv4_params, |
| 355 | self.ipv6_params.addr_type: |
| 356 | self.ipv6_params} |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 357 | |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 358 | for _, p in self.params.items(): |
| 359 | p.auth_algo_vpp_id = algo['vpp'] |
| 360 | p.auth_algo = algo['scapy'] |
| 361 | p.flags = p.flags | flag |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 362 | |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 363 | # |
| 364 | # configure the SPDs. SAs, etc |
| 365 | # |
| 366 | self.config_network(self.params.values()) |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 367 | |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 368 | # |
| 369 | # run some traffic. |
| 370 | # An exhautsive 4o6, 6o4 is not necessary for each algo |
| 371 | # |
| 372 | self.verify_tra_basic6(count=17) |
| 373 | self.verify_tra_basic4(count=17) |
| 374 | self.verify_tun_66(self.params[socket.AF_INET6], count=17) |
| 375 | self.verify_tun_44(self.params[socket.AF_INET], count=17) |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 376 | |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 377 | # |
| 378 | # remove the SPDs, SAs, etc |
| 379 | # |
| 380 | self.unconfig_network() |
Neale Ranns | 1091c4a | 2019-04-08 14:48:23 +0000 | [diff] [blame] | 381 | |
| 382 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 383 | if __name__ == '__main__': |
| 384 | unittest.main(testRunner=VppTestRunner) |