“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 |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 3 | import struct |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 4 | from scapy.layers.ipsec import ESP |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 5 | from scapy.layers.inet import UDP |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 6 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 7 | from framework import VppTestRunner |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 8 | from template_ipsec import IpsecTra46Tests, IpsecTun46Tests, TemplateIpsec, \ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 9 | IpsecTcpTests, IpsecTun4Tests, IpsecTra4Tests, config_tra_params, \ |
| 10 | IPsecIPv4Params, IPsecIPv6Params, \ |
| 11 | IpsecTra4, IpsecTun4, IpsecTra6, IpsecTun6 |
Klement Sekera | bf61395 | 2019-01-29 11:38:08 +0100 | [diff] [blame] | 12 | from vpp_ipsec import VppIpsecSpd, VppIpsecSpdEntry, VppIpsecSA,\ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 13 | VppIpsecSpdItfBinding |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 14 | from vpp_ip_route import VppIpRoute, VppRoutePath |
| 15 | from vpp_ip import DpoProto |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 16 | from vpp_papi import VppEnum |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 17 | |
| 18 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 19 | class ConfigIpsecESP(TemplateIpsec): |
| 20 | encryption_type = ESP |
| 21 | tra4_encrypt_node_name = "esp4-encrypt" |
| 22 | tra4_decrypt_node_name = "esp4-decrypt" |
| 23 | tra6_encrypt_node_name = "esp6-encrypt" |
| 24 | tra6_decrypt_node_name = "esp6-decrypt" |
| 25 | tun4_encrypt_node_name = "esp4-encrypt" |
| 26 | tun4_decrypt_node_name = "esp4-decrypt" |
| 27 | tun6_encrypt_node_name = "esp6-encrypt" |
| 28 | tun6_decrypt_node_name = "esp6-decrypt" |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 29 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 30 | @classmethod |
| 31 | def setUpClass(cls): |
| 32 | super(ConfigIpsecESP, cls).setUpClass() |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 33 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 34 | @classmethod |
| 35 | def tearDownClass(cls): |
| 36 | super(ConfigIpsecESP, cls).tearDownClass() |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 37 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 38 | def setUp(self): |
| 39 | super(ConfigIpsecESP, self).setUp() |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 40 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 41 | def tearDown(self): |
| 42 | super(ConfigIpsecESP, self).tearDown() |
| 43 | |
| 44 | def config_network(self, params): |
| 45 | self.net_objs = [] |
| 46 | self.tun_if = self.pg0 |
| 47 | self.tra_if = self.pg2 |
| 48 | self.logger.info(self.vapi.ppcli("show int addr")) |
| 49 | |
| 50 | self.tra_spd = VppIpsecSpd(self, self.tra_spd_id) |
| 51 | self.tra_spd.add_vpp_config() |
| 52 | self.net_objs.append(self.tra_spd) |
| 53 | self.tun_spd = VppIpsecSpd(self, self.tun_spd_id) |
| 54 | self.tun_spd.add_vpp_config() |
| 55 | self.net_objs.append(self.tun_spd) |
| 56 | |
| 57 | b = VppIpsecSpdItfBinding(self, self.tun_spd, |
| 58 | self.tun_if) |
| 59 | b.add_vpp_config() |
| 60 | self.net_objs.append(b) |
| 61 | |
| 62 | b = VppIpsecSpdItfBinding(self, self.tra_spd, |
| 63 | self.tra_if) |
| 64 | b.add_vpp_config() |
| 65 | self.net_objs.append(b) |
| 66 | |
| 67 | for p in params: |
| 68 | self.config_esp_tra(p) |
| 69 | config_tra_params(p, self.encryption_type) |
| 70 | for p in params: |
| 71 | self.config_esp_tun(p) |
| 72 | |
| 73 | for p in params: |
| 74 | d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4 |
| 75 | r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len, |
| 76 | [VppRoutePath(self.tun_if.remote_addr[p.addr_type], |
| 77 | 0xffffffff, |
| 78 | proto=d)], |
| 79 | is_ip6=p.is_ipv6) |
| 80 | r.add_vpp_config() |
| 81 | self.net_objs.append(r) |
| 82 | |
| 83 | self.logger.info(self.vapi.ppcli("show ipsec all")) |
| 84 | |
| 85 | def unconfig_network(self): |
| 86 | for o in reversed(self.net_objs): |
| 87 | o.remove_vpp_config() |
| 88 | self.net_objs = [] |
| 89 | |
| 90 | def config_esp_tun(self, params): |
| 91 | addr_type = params.addr_type |
| 92 | scapy_tun_sa_id = params.scapy_tun_sa_id |
| 93 | scapy_tun_spi = params.scapy_tun_spi |
| 94 | vpp_tun_sa_id = params.vpp_tun_sa_id |
| 95 | vpp_tun_spi = params.vpp_tun_spi |
| 96 | auth_algo_vpp_id = params.auth_algo_vpp_id |
| 97 | auth_key = params.auth_key |
| 98 | crypt_algo_vpp_id = params.crypt_algo_vpp_id |
| 99 | crypt_key = params.crypt_key |
| 100 | remote_tun_if_host = params.remote_tun_if_host |
| 101 | addr_any = params.addr_any |
| 102 | addr_bcast = params.addr_bcast |
| 103 | e = VppEnum.vl_api_ipsec_spd_action_t |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 104 | flags = params.flags |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 105 | objs = [] |
| 106 | |
| 107 | params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi, |
| 108 | auth_algo_vpp_id, auth_key, |
| 109 | crypt_algo_vpp_id, crypt_key, |
| 110 | self.vpp_esp_protocol, |
| 111 | self.tun_if.local_addr[addr_type], |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 112 | self.tun_if.remote_addr[addr_type], |
| 113 | flags=flags) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 114 | params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi, |
| 115 | auth_algo_vpp_id, auth_key, |
| 116 | crypt_algo_vpp_id, crypt_key, |
| 117 | self.vpp_esp_protocol, |
| 118 | self.tun_if.remote_addr[addr_type], |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 119 | self.tun_if.local_addr[addr_type], |
| 120 | flags=flags) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 121 | objs.append(params.tun_sa_in) |
| 122 | objs.append(params.tun_sa_out) |
| 123 | |
| 124 | params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd, |
| 125 | scapy_tun_sa_id, |
| 126 | addr_any, addr_bcast, |
| 127 | addr_any, addr_bcast, |
| 128 | socket.IPPROTO_ESP) |
| 129 | params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd, |
| 130 | scapy_tun_sa_id, |
| 131 | addr_any, addr_bcast, |
| 132 | addr_any, addr_bcast, |
| 133 | socket.IPPROTO_ESP, |
| 134 | is_outbound=0) |
| 135 | objs.append(params.spd_policy_out_any) |
| 136 | objs.append(params.spd_policy_in_any) |
| 137 | |
| 138 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id, |
| 139 | remote_tun_if_host, remote_tun_if_host, |
| 140 | self.pg1.remote_addr[addr_type], |
| 141 | self.pg1.remote_addr[addr_type], |
| 142 | 0, |
| 143 | priority=10, |
| 144 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 145 | is_outbound=0)) |
| 146 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id, |
| 147 | self.pg1.remote_addr[addr_type], |
| 148 | self.pg1.remote_addr[addr_type], |
| 149 | remote_tun_if_host, remote_tun_if_host, |
| 150 | 0, |
| 151 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 152 | priority=10)) |
| 153 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id, |
| 154 | remote_tun_if_host, remote_tun_if_host, |
| 155 | self.pg0.local_addr[addr_type], |
| 156 | self.pg0.local_addr[addr_type], |
| 157 | 0, |
| 158 | priority=20, |
| 159 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 160 | is_outbound=0)) |
| 161 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id, |
| 162 | self.pg0.local_addr[addr_type], |
| 163 | self.pg0.local_addr[addr_type], |
| 164 | remote_tun_if_host, remote_tun_if_host, |
| 165 | 0, |
| 166 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 167 | priority=20)) |
| 168 | for o in objs: |
| 169 | o.add_vpp_config() |
| 170 | self.net_objs = self.net_objs + objs |
| 171 | |
| 172 | def config_esp_tra(self, params): |
| 173 | addr_type = params.addr_type |
| 174 | scapy_tra_sa_id = params.scapy_tra_sa_id |
| 175 | scapy_tra_spi = params.scapy_tra_spi |
| 176 | vpp_tra_sa_id = params.vpp_tra_sa_id |
| 177 | vpp_tra_spi = params.vpp_tra_spi |
| 178 | auth_algo_vpp_id = params.auth_algo_vpp_id |
| 179 | auth_key = params.auth_key |
| 180 | crypt_algo_vpp_id = params.crypt_algo_vpp_id |
| 181 | crypt_key = params.crypt_key |
| 182 | addr_any = params.addr_any |
| 183 | addr_bcast = params.addr_bcast |
| 184 | flags = (VppEnum.vl_api_ipsec_sad_flags_t. |
| 185 | IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY) |
| 186 | e = VppEnum.vl_api_ipsec_spd_action_t |
| 187 | flags = params.flags | flags |
| 188 | objs = [] |
| 189 | |
| 190 | params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi, |
| 191 | auth_algo_vpp_id, auth_key, |
| 192 | crypt_algo_vpp_id, crypt_key, |
| 193 | self.vpp_esp_protocol, |
| 194 | flags=flags) |
| 195 | params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi, |
| 196 | auth_algo_vpp_id, auth_key, |
| 197 | crypt_algo_vpp_id, crypt_key, |
| 198 | self.vpp_esp_protocol, |
| 199 | flags=flags) |
| 200 | objs.append(params.tra_sa_in) |
| 201 | objs.append(params.tra_sa_out) |
| 202 | |
| 203 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 204 | addr_any, addr_bcast, |
| 205 | addr_any, addr_bcast, |
| 206 | socket.IPPROTO_ESP)) |
| 207 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 208 | addr_any, addr_bcast, |
| 209 | addr_any, addr_bcast, |
| 210 | socket.IPPROTO_ESP, |
| 211 | is_outbound=0)) |
| 212 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 213 | self.tra_if.local_addr[addr_type], |
| 214 | self.tra_if.local_addr[addr_type], |
| 215 | self.tra_if.remote_addr[addr_type], |
| 216 | self.tra_if.remote_addr[addr_type], |
| 217 | 0, priority=10, |
| 218 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 219 | is_outbound=0)) |
| 220 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id, |
| 221 | self.tra_if.local_addr[addr_type], |
| 222 | self.tra_if.local_addr[addr_type], |
| 223 | self.tra_if.remote_addr[addr_type], |
| 224 | self.tra_if.remote_addr[addr_type], |
| 225 | 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 226 | priority=10)) |
| 227 | for o in objs: |
| 228 | o.add_vpp_config() |
| 229 | self.net_objs = self.net_objs + objs |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 230 | |
| 231 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 232 | class TemplateIpsecEsp(ConfigIpsecESP): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 233 | """ |
| 234 | Basic test for ipsec esp sanity - tunnel and transport modes. |
| 235 | |
| 236 | Below 4 cases are covered as part of this test |
| 237 | 1) ipsec esp v4 transport basic test - IPv4 Transport mode |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 238 | scenario using HMAC-SHA1-96 integrity algo |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 239 | 2) ipsec esp v4 transport burst test |
| 240 | Above test for 257 pkts |
| 241 | 3) ipsec esp 4o4 tunnel basic test - IPv4 Tunnel mode |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 242 | scenario using HMAC-SHA1-96 integrity algo |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 243 | 4) ipsec esp 4o4 tunnel burst test |
| 244 | Above test for 257 pkts |
| 245 | |
| 246 | TRANSPORT MODE: |
| 247 | |
| 248 | --- encrypt --- |
| 249 | |pg2| <-------> |VPP| |
| 250 | --- decrypt --- |
| 251 | |
| 252 | TUNNEL MODE: |
| 253 | |
| 254 | --- encrypt --- plain --- |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 255 | |pg0| <------- |VPP| <------ |pg1| |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 256 | --- --- --- |
| 257 | |
| 258 | --- decrypt --- plain --- |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 259 | |pg0| -------> |VPP| ------> |pg1| |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 260 | --- --- --- |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 261 | """ |
| 262 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 263 | @classmethod |
| 264 | def setUpClass(cls): |
| 265 | super(TemplateIpsecEsp, cls).setUpClass() |
| 266 | |
| 267 | @classmethod |
| 268 | def tearDownClass(cls): |
| 269 | super(TemplateIpsecEsp, cls).tearDownClass() |
| 270 | |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 271 | def setUp(self): |
| 272 | super(TemplateIpsecEsp, self).setUp() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 273 | self.config_network(self.params.values()) |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 274 | |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 275 | def tearDown(self): |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 276 | self.unconfig_network() |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 277 | super(TemplateIpsecEsp, self).tearDown() |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 278 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 279 | |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 280 | class TestIpsecEsp1(TemplateIpsecEsp, IpsecTra46Tests, IpsecTun46Tests): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 281 | """ Ipsec ESP - TUN & TRA tests """ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 282 | pass |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 283 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 284 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 285 | class TestIpsecEsp2(TemplateIpsecEsp, IpsecTcpTests): |
| 286 | """ Ipsec ESP - TCP tests """ |
| 287 | pass |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 288 | |
| 289 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 290 | class TemplateIpsecEspUdp(ConfigIpsecESP): |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 291 | """ |
| 292 | UDP encapped ESP |
| 293 | """ |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 294 | |
| 295 | @classmethod |
| 296 | def setUpClass(cls): |
| 297 | super(TemplateIpsecEspUdp, cls).setUpClass() |
| 298 | |
| 299 | @classmethod |
| 300 | def tearDownClass(cls): |
| 301 | super(TemplateIpsecEspUdp, cls).tearDownClass() |
| 302 | |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 303 | def setUp(self): |
| 304 | super(TemplateIpsecEspUdp, self).setUp() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 305 | self.net_objs = [] |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 306 | self.tun_if = self.pg0 |
| 307 | self.tra_if = self.pg2 |
| 308 | self.logger.info(self.vapi.ppcli("show int addr")) |
| 309 | |
| 310 | p = self.ipv4_params |
| 311 | p.flags = (VppEnum.vl_api_ipsec_sad_flags_t. |
| 312 | IPSEC_API_SAD_FLAG_UDP_ENCAP) |
| 313 | p.nat_header = UDP(sport=5454, dport=4500) |
| 314 | |
| 315 | self.tra_spd = VppIpsecSpd(self, self.tra_spd_id) |
| 316 | self.tra_spd.add_vpp_config() |
| 317 | VppIpsecSpdItfBinding(self, self.tra_spd, |
| 318 | self.tra_if).add_vpp_config() |
| 319 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 320 | self.config_esp_tra(p) |
Neale Ranns | 2ac885c | 2019-03-20 18:24:43 +0000 | [diff] [blame] | 321 | config_tra_params(p, self.encryption_type) |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 322 | |
| 323 | self.tun_spd = VppIpsecSpd(self, self.tun_spd_id) |
| 324 | self.tun_spd.add_vpp_config() |
| 325 | VppIpsecSpdItfBinding(self, self.tun_spd, |
| 326 | self.tun_if).add_vpp_config() |
| 327 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 328 | self.config_esp_tun(p) |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 329 | self.logger.info(self.vapi.ppcli("show ipsec all")) |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 330 | |
| 331 | d = DpoProto.DPO_PROTO_IP4 |
| 332 | VppIpRoute(self, p.remote_tun_if_host, p.addr_len, |
| 333 | [VppRoutePath(self.tun_if.remote_addr[p.addr_type], |
| 334 | 0xffffffff, |
| 335 | proto=d)]).add_vpp_config() |
| 336 | |
| 337 | def tearDown(self): |
| 338 | super(TemplateIpsecEspUdp, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 339 | |
| 340 | def show_commands_at_teardown(self): |
| 341 | self.logger.info(self.vapi.cli("show hardware")) |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 342 | |
| 343 | |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 344 | class TestIpsecEspUdp(TemplateIpsecEspUdp, IpsecTra4Tests): |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 345 | """ Ipsec NAT-T ESP UDP tests """ |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 346 | pass |
| 347 | |
| 348 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 349 | class TestIpsecEspAll(ConfigIpsecESP, |
| 350 | IpsecTra4, IpsecTra6, |
| 351 | IpsecTun4, IpsecTun6): |
| 352 | """ Ipsec ESP all Algos """ |
| 353 | |
| 354 | def setUp(self): |
| 355 | super(TestIpsecEspAll, self).setUp() |
| 356 | |
| 357 | def tearDown(self): |
| 358 | super(TestIpsecEspAll, self).tearDown() |
| 359 | |
| 360 | def test_crypto_algs(self): |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 361 | """All engines AES-[CBC, GCM]-[128, 192, 256] w/ & w/o ESN""" |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 362 | |
| 363 | # foreach VPP crypto engine |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 364 | engines = ["ia32", "ipsecmb", "openssl"] |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 365 | |
| 366 | # foreach crypto algorithm |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 367 | algos = [{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 368 | IPSEC_API_CRYPTO_ALG_AES_GCM_128), |
| 369 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 370 | IPSEC_API_INTEG_ALG_NONE), |
| 371 | 'scapy-crypto': "AES-GCM", |
| 372 | 'scapy-integ': "NULL", |
| 373 | 'key': "JPjyOWBeVEQiMe7h", |
| 374 | 'salt': struct.pack("!L", 0)}, |
| 375 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 376 | IPSEC_API_CRYPTO_ALG_AES_GCM_256), |
| 377 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 378 | IPSEC_API_INTEG_ALG_NONE), |
| 379 | 'scapy-crypto': "AES-GCM", |
| 380 | 'scapy-integ': "NULL", |
| 381 | 'key': "JPjyOWBeVEQiMe7h0123456787654321", |
| 382 | 'salt': struct.pack("!L", 0)}, |
| 383 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 384 | IPSEC_API_CRYPTO_ALG_AES_CBC_128), |
| 385 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 386 | IPSEC_API_INTEG_ALG_SHA1_96), |
| 387 | 'scapy-crypto': "AES-CBC", |
| 388 | 'scapy-integ': "HMAC-SHA1-96", |
| 389 | 'salt': '', |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 390 | 'key': "JPjyOWBeVEQiMe7h"}, |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 391 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 392 | IPSEC_API_CRYPTO_ALG_AES_CBC_192), |
| 393 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 394 | IPSEC_API_INTEG_ALG_SHA1_96), |
| 395 | 'scapy-crypto': "AES-CBC", |
| 396 | 'scapy-integ': "HMAC-SHA1-96", |
| 397 | 'salt': '', |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 398 | 'key': "JPjyOWBeVEQiMe7hJPjyOWBe"}, |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 399 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 400 | IPSEC_API_CRYPTO_ALG_AES_CBC_256), |
| 401 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 402 | IPSEC_API_INTEG_ALG_SHA1_96), |
| 403 | 'scapy-crypto': "AES-CBC", |
| 404 | 'scapy-integ': "HMAC-SHA1-96", |
| 405 | 'salt': '', |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 406 | 'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"}] |
| 407 | |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 408 | # with and without ESN |
| 409 | flags = [0, |
| 410 | VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN] |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 411 | |
| 412 | # |
| 413 | # loop through the VPP engines |
| 414 | # |
| 415 | for engine in engines: |
Neale Ranns | 21ada3b | 2019-04-11 08:18:34 +0000 | [diff] [blame] | 416 | self.vapi.cli("set crypto handler all %s" % engine) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 417 | |
| 418 | # |
| 419 | # loop through each of the algorithms |
| 420 | # |
| 421 | for algo in algos: |
| 422 | # with self.subTest(algo=algo['scapy']): |
| 423 | for flag in flags: |
| 424 | # |
| 425 | # setup up the config paramters |
| 426 | # |
| 427 | self.ipv4_params = IPsecIPv4Params() |
| 428 | self.ipv6_params = IPsecIPv6Params() |
| 429 | |
| 430 | self.params = {self.ipv4_params.addr_type: |
| 431 | self.ipv4_params, |
| 432 | self.ipv6_params.addr_type: |
| 433 | self.ipv6_params} |
| 434 | |
| 435 | for _, p in self.params.items(): |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 436 | p.auth_algo_vpp_id = algo['vpp-integ'] |
| 437 | p.crypt_algo_vpp_id = algo['vpp-crypto'] |
| 438 | p.crypt_algo = algo['scapy-crypto'] |
| 439 | p.auth_algo = algo['scapy-integ'] |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 440 | p.crypt_key = algo['key'] |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 441 | p.crypt_salt = algo['salt'] |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 442 | p.flags = p.flags | flag |
| 443 | |
| 444 | # |
| 445 | # configure the SPDs. SAs, etc |
| 446 | # |
| 447 | self.config_network(self.params.values()) |
| 448 | |
| 449 | # |
| 450 | # run some traffic. |
| 451 | # An exhautsive 4o6, 6o4 is not necessary |
| 452 | # for each algo |
| 453 | # |
| 454 | self.verify_tra_basic6(count=17) |
| 455 | self.verify_tra_basic4(count=17) |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 456 | self.verify_tun_66(self.params[socket.AF_INET6], 17) |
| 457 | self.verify_tun_44(self.params[socket.AF_INET], 17) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 458 | |
| 459 | # |
| 460 | # remove the SPDs, SAs, etc |
| 461 | # |
| 462 | self.unconfig_network() |
| 463 | |
| 464 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 465 | if __name__ == '__main__': |
| 466 | unittest.main(testRunner=VppTestRunner) |