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