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