IPsec: add nth SPD entry outbound flow cache TCs
[csit.git] / resources / libraries / robot / crypto / ipsec.robot
1 # Copyright (c) 2021 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 *** Settings ***
15 | Library | String
16 | Library | resources.libraries.python.InterfaceUtil
17 | Library | resources.libraries.python.IPsecUtil
18 | Library | resources.libraries.python.IPUtil
19 | Library | resources.libraries.python.IPv6Util
20 |
21 | Documentation | IPsec keywords.
22
23 *** Keywords ***
24 | Generate keys for IPSec
25 | | [Documentation] | Generate keys for IPsec.
26 | |
27 | | ... | *Arguments:*
28 | | ... | - crypto_alg - Encryption algorithm. Type: enum
29 | | ... | - integ_alg - Integrity algorithm. Type: enum
30 | |
31 | | ... | _NOTE:_ This KW sets following test case variable:
32 | | ... | - encr_key - Encryption key. Type: string
33 | | ... | - auth_key - Integrity key. Type: string
34 | |
35 | | ... | *Example:*
36 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
37 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
38 | | ... | \| Generate keys for IPSec \| ${encr_alg} \| ${auth_alg} \|
39 | |
40 | | [Arguments] | ${crypto_alg} | ${integ_alg}
41 | |
42 | | ${encr_key_len}= | Get Crypto Alg Key Len | ${crypto_alg}
43 | | ${encr_key}= | Generate Random String | ${encr_key_len}
44 | | ${auth_key_len}= | Get Integ Alg Key Len | ${integ_alg}
45 | | ${auth_key}= | Generate Random String | ${auth_key_len}
46 | | Set Test Variable | ${encr_key}
47 | | Set Test Variable | ${auth_key}
48
49 | Configure topology for IPv4 IPsec testing
50 | | [Documentation] | Setup topology for IPv4 IPsec testing.
51 | |
52 | | ... | _NOTE:_ This KW sets following test case variable:
53 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
54 | | ... | - dut_src_ip - DUT source IP address. Type: string
55 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
56 | | ... | - tg_src_ip - TG source IP address. Type: string
57 | |
58 | | ... | *Example:*
59 | | ... | \| Configure topology for IPv4 IPsec testing \|
60 | |
61 | | Set interfaces in path up
62 | | VPP Interface Set IP Address
63 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut_if1_ip4} | ${ip4_plen}
64 | | VPP Interface Set IP Address
65 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut_if2_ip4} | ${ip4_plen}
66 | | VPP Add IP Neighbor
67 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
68 | | VPP Add IP Neighbor
69 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${tg_if2_ip4} | ${TG_pf2_mac}[0]
70 | | Vpp Route Add
71 | | ... | ${dut1} | ${tg_host_ip4} | ${ip4_plen} | gateway=${tg_if1_ip4}
72 | | ... | interface=${DUT1_${int}1}[0] | strict=${False}
73 | | Set Test Variable | ${dut_tun_ip} | ${dut_if1_ip4}
74 | | Set Test Variable | ${tg_tun_ip} | ${tg_if1_ip4}
75 | | Set Test Variable | ${tg_src_ip} | ${tg_host_ip4}
76 | | Set Test Variable | ${tg_dst_ip} | ${tg_if2_ip4}
77
78 | Configure topology for IPv6 IPsec testing
79 | | [Documentation] | Setup topology fo IPv6 IPsec testing.
80 | |
81 | | ... | _NOTE:_ This KW sets following test case variable:
82 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
83 | | ... | - dut_src_ip - DUT source IP address. Type: string
84 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
85 | | ... | - tg_src_ip - TG source IP address. Type: string
86 | |
87 | | ... | *Example:*
88 | | ... | \| Configure topology for IPv6 IPsec testing \|
89 | |
90 | | Set interfaces in path up
91 | | VPP Interface Set IP Address
92 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut_if1_ip6} | ${ip6_plen}
93 | | VPP Interface Set IP Address
94 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut_if2_ip6} | ${ip6_plen}
95 | | VPP Add IP Neighbor
96 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip6} | ${TG_pf1_mac}[0]
97 | | VPP Add IP Neighbor
98 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${tg_if2_ip6} | ${TG_pf2_mac}[0]
99 | | Vpp Interfaces RA Suppress On All Nodes | ${nodes}
100 | | Vpp Route Add
101 | | ... | ${dut1} | ${tg_host_ip6} | ${ip6_plen_rt} | gateway=${tg_if1_ip6}
102 | | ... | interface=${DUT1_${int}1}[0]
103 | | Set Test Variable | ${dut_tun_ip} | ${dut_if1_ip6}
104 | | Set Test Variable | ${tg_tun_ip} | ${tg_if1_ip6}
105 | | Set Test Variable | ${tg_src_ip} | ${tg_host_ip6}
106 | | Set Test Variable | ${tg_dst_ip} | ${tg_if2_ip6}
107
108 | Configure manual keyed connection for IPSec
109 | | [Documentation] | Setup IPsec manual keyed connection on VPP node.
110 | |
111 | | ... | *Arguments:*
112 | | ... | - node - VPP node to setup IPsec on. Type: dictionary
113 | | ... | - interface - Interface to enable IPsec on. Type: string
114 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
115 | | ... | - crypto_key - Encryption key. Type: string
116 | | ... | - integ_alg - Integrity algorithm. Type: enum
117 | | ... | - integ_key - Integrity key. Type: string
118 | | ... | - l_spi - Local SPI. Type: integer
119 | | ... | - r_spi - Remote SPI. Type: integer
120 | | ... | - l_ip - Local IP address. Type: string
121 | | ... | - r_ip - Remote IP address. Type: string
122 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
123 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
124 | |
125 | | ... | _NOTE:_ This KW sets following test case variables:
126 | | ... | - l_sa_id
127 | | ... | - r_sa_id
128 | |
129 | | ... | *Example:*
130 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
131 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
132 | | ... | \| Configure manual keyed connection for IPSec \| ${nodes['DUT1']} \
133 | | ... | \| GigabitEthernet0/8/0 \| ${encr_alg} \| sixteenbytes_key \
134 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1000} \| ${1001} \
135 | | ... | \| 192.168.4.4 \| 192.168.3.3 \| 192.168.100.3 \| 192.168.100.2 \|
136 | |
137 | | [Arguments] | ${node} | ${interface} | ${crypto_alg} | ${crypto_key}
138 | | ... | ${integ_alg} | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip}
139 | | ... | ${r_ip} | ${l_tunnel}=${None} | ${r_tunnel}=${None}
140 | | ... | ${is_ipv6}=${FALSE}
141 | |
142 | | Set Test Variable | ${l_sa_id} | ${10}
143 | | Set Test Variable | ${r_sa_id} | ${20}
144 | | ${spd_id}= | Set Variable | ${1}
145 | | ${p_hi}= | Set Variable | ${100}
146 | | ${p_lo}= | Set Variable | ${10}
147 | | VPP IPsec Add SAD Entry | ${node} | ${l_sa_id} | ${l_spi} | ${crypto_alg}
148 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
149 | | ... | ${l_tunnel} | ${r_tunnel}
150 | | VPP IPsec Add SAD Entry | ${node} | ${r_sa_id} | ${r_spi} | ${crypto_alg}
151 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
152 | | ... | ${r_tunnel} | ${l_tunnel}
153 | | VPP IPsec Add SPD | ${node} | ${spd_id}
154 | | VPP IPsec SPD Add If | ${node} | ${spd_id} | ${interface}
155 | | ${action}= | Policy Action Bypass
156 | | VPP IPsec Add SPD Entry | ${node} | ${spd_id} | ${p_hi} | ${action}
157 | | ... | inbound=${TRUE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
158 | | ... | laddr_range=${tg_tun_ip} | raddr_range=${dut_tun_ip}
159 | | VPP IPsec Add SPD Entry | ${node} | ${spd_id} | ${p_hi} | ${action}
160 | | ... | inbound=${FALSE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
161 | | ... | laddr_range=${dut_tun_ip} | raddr_range=${tg_tun_ip}
162 | | ${action}= | Policy Action Protect
163 | | VPP IPsec Add SPD Entry | ${node} | ${spd_id} | ${p_lo} | ${action}
164 | | ... | sa_id=${r_sa_id} | laddr_range=${l_ip}
165 | | ... | raddr_range=${r_ip} | inbound=${TRUE}
166 | | VPP IPsec Add SPD Entry | ${node} | ${spd_id} | ${p_lo} | ${action}
167 | | ... | sa_id=${l_sa_id} | laddr_range=${l_ip}
168 | | ... | raddr_range=${r_ip} | inbound=${FALSE}
169
170 | Initialize IPSec in 3-node circular topology
171 | | [Documentation]
172 | | ... | Set UP state on VPP interfaces in path on nodes in 3-node circular
173 | | ... | topology. Get the interface MAC addresses and setup ARP on VPP
174 | | ... | interfaces towards TG. Setup IPv4 addresses with /24 prefix on DUT-TG
175 | | ... | links. Set routing for decrypted traffic on both DUT nodes
176 | | ... | with prefix /8 and next hop of neighbour TG interface IPv4 address.
177 | |
178 | | Set interfaces in path up
179 | | VPP Interface Set IP Address
180 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut1_if1_ip4} | 24
181 | | VPP Interface Set IP Address
182 | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${dut2_if2_ip4} | 24
183 | | VPP Add IP Neighbor
184 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
185 | | VPP Add IP Neighbor
186 | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${tg_if2_ip4} | ${TG_pf2_mac}[0]
187 | | Vpp Route Add | ${dut1} | ${laddr_ip4} | 8 | gateway=${tg_if1_ip4}
188 | | ... | interface=${DUT1_${int}1}[0]
189 | | Vpp Route Add | ${dut2} | ${raddr_ip4} | 8 | gateway=${tg_if2_ip4}
190 | | ... | interface=${DUT2_${int}2}[0]
191
192 | Initialize IPSec in 3-node circular container topology
193 | | [Documentation]
194 | | ... | Set UP state on VPP interfaces in path on nodes in 3-node circular
195 | | ... | topology. Get the interface MAC addresses and setup ARP on all VPP
196 | | ... | interfaces. Setup IPv4 addresses with /24 prefix on DUT-TG and
197 | | ... | DUT1-DUT2 links. Set routing for encrypted traffic on both DUT nodes
198 | | ... | with prefix /8 and next hop of neighbour DUT or TG interface IPv4
199 | | ... | address.
200 | |
201 | | Set interfaces in path up on DUT | DUT1
202 | | VPP Interface Set IP Address
203 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut1_if1_ip4} | 24
204 | | VPP Add IP Neighbor
205 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
206 | | Vpp Route Add
207 | | ... | ${dut1} | ${laddr_ip4} | 8 | gateway=${tg_if1_ip4}
208 | | ... | interface=${DUT1_${int}1}[0]
209
210 | Initialize IPSec in 2-node circular topology
211 | | [Documentation]
212 | | ... | Set UP state on VPP interfaces in path on node in 2-node circular
213 | | ... | topology. Get the interface MAC address and setup ARP on VPP
214 | | ... | interface towards TG. Setup IPv4 address with /24 prefix on one
215 | | ... | DUT-TG link. Set routing for decrypted traffic on DUT
216 | | ... | with prefix /8 and next hop of neighbour TG interface IPv4 address.
217 | |
218 | | Set interfaces in path up
219 | | VPP Interface Set IP Address
220 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut1_if1_ip4} | 24
221 | | VPP Add IP Neighbor
222 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
223 | | Vpp Route Add
224 | | ... | ${dut1} | ${laddr_ip4} | 8 | gateway=${tg_if1_ip4}
225 | | ... | interface=${DUT1_${int}1}[0]
226
227 | Enable IPSec Async Mode on all VPP DUTs
228 | | [Documentation]
229 | | ... | Set IPsec async mode on for all DUT nodes.
230 | |
231 | | FOR | ${dut} | IN | @{duts}
232 | | | VPP Ipsec Set Async Mode | ${nodes['${dut}']}
233 | | END
234
235 | Set Data Plane And Feature Plane Workers for IPsec on all VPP DUTs
236 | | [Documentation]
237 | | ... | Disable crypto work for specified data plane CPU cores
238 | | ... | on all DUT nodes (leaving feature plane workers enabled).
239 | | ... | Set Round Robin interface RX placement on data plane CPU cores
240 | | ... | on all DUT nodes (leaving feature plane workers disabled).
241 | |
242 | | VPP Round Robin Rx Placement on all DUTs
243 | | ... | ${nodes} | prefix=${EMPTY} | workers=${cpu_dp}
244 | | VPP IPSec Crypto SW Scheduler Set Worker on all DUTs
245 | | ... | ${nodes} | workers=${cpu_dp} | crypto_enable=${False}
246
247 | Enable SPD flow cache IPv4 Outbound
248 | | [Documentation]
249 | | ... | Enable IPv4 Outbound SPD flow cache in VPP configuration file.
250 | |
251 | | FOR | ${dut} | IN | @{duts}
252 | | | Run Keyword | ${dut}.Add SPD Flow Cache IPv4 Outbound