80d2937e373b31bce90d5f18fb58c1749424d7fa
[csit.git] / resources / libraries / robot / crypto / ipsec.robot
1 # Copyright (c) 2016 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 | Resource | resources/libraries/robot/shared/default.robot
16 | Library | resources.libraries.python.IPsecUtil
17 | Library | resources.libraries.python.NodePath
18 | Library | resources.libraries.python.TrafficScriptExecutor
19 | Library | resources.libraries.python.IPv4Util.IPv4Util
20 | Library | resources.libraries.python.InterfaceUtil
21 | Library | resources.libraries.python.Routing
22 | Library | String
23 | Library | resources.libraries.python.IPv6Util
24 | Library | resources.libraries.python.IPv6Setup
25 | Library | resources.libraries.python.IPv4Setup.Dut | ${nodes['DUT1']}
26 | ...     | WITH NAME | dut1_v4
27 | Documentation | *IPsec keywords.*
28
29 *** Keywords ***
30 | Generate keys for IPSec
31 | | [Documentation] | Generate keys for IPsec.
32 | | ...
33 | | ... | *Arguments:*
34 | | ... | - crypto_alg - Encryption algorithm. Type: enum
35 | | ... | - integ_alg - Integrity algorithm. Type: enum
36 | | ...
37 | | ... | _NOTE:_ This KW sets following test case variable:
38 | | ... | - encr_key - Encryption key. Type: string
39 | | ... | - auth_key - Integrity key. Type: string
40 | | ...
41 | | ... | *Example:*
42 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
43 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
44 | | ... | \| Generate keys for IPSec \| ${encr_alg} \| ${auth_alg} \|
45 | | [Arguments] | ${crypto_alg} | ${integ_alg}
46 | | ${encr_key_len}= | Get Crypto Alg Key Len | ${crypto_alg}
47 | | ${encr_key}= | Generate Random String | ${encr_key_len}
48 | | ${auth_key_len}= | Get Integ Alg Key Len | ${integ_alg}
49 | | ${auth_key}= | Generate Random String | ${auth_key_len}
50 | | Set Test Variable | ${encr_key}
51 | | Set Test Variable | ${auth_key}
52
53 | Configure path for IPSec test
54 | | [Documentation] | Setup path for IPsec testing TG<-->DUT1.
55 | | ...
56 | | ... | _NOTE:_ This KW sets following test case variable:
57 | | ... | - tg_node - TG node. Type: dictionary
58 | | ... | - tg_if - TG interface connected to DUT. Type: string
59 | | ... | - tg_if_mac - TG interface MAC. Type: string
60 | | ... | - dut_node - DUT node. Type: dictionary
61 | | ... | - dut_if - DUT interface connected to TG. Type: string
62 | | ... | - dut_if_mac - DUT interface MAC. Type: string
63 | | ... | - dut_lo - DUT loopback interface. Type: string
64 | | ...
65 | | ... | *Example:*
66 | | ... | \| Configure path for IPSec test \|
67 | | Append Nodes | ${nodes['TG']} | ${nodes['DUT1']}
68 | | Compute Path
69 | | ${tg_if} | ${tg_node}= | Next Interface
70 | | ${dut_if} | ${dut_node}= | Next Interface
71 | | ${dut_if_mac}= | Get Interface Mac | ${dut_node} | ${dut_if}
72 | | ${tg_if_mac}= | Get Interface Mac | ${tg_node} | ${tg_if}
73 | | ${dut_lo}= | Vpp Create Loopback | ${dut_node}
74 | | Set Interface State | ${dut_node} | ${dut_if} | up
75 | | Set Interface State | ${dut_node} | ${dut_lo} | up
76 | | Vpp Node Interfaces Ready Wait | ${dut_node}
77 | | Set Test Variable | ${tg_node}
78 | | Set Test Variable | ${tg_if}
79 | | Set Test Variable | ${tg_if_mac}
80 | | Set Test Variable | ${dut_node}
81 | | Set Test Variable | ${dut_if}
82 | | Set Test Variable | ${dut_if_mac}
83 | | Set Test Variable | ${dut_lo}
84
85 | Configure topology for IPv4 IPsec testing
86 | | [Documentation] | Setup topology for IPv4 IPsec testing.
87 | | ...
88 | | ... | _NOTE:_ This KW sets following test case variable:
89 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
90 | | ... | - dut_src_ip - DUT source IP address. Type: string
91 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
92 | | ... | - tg_src_ip - TG source IP address. Type: string
93 | | ...
94 | | ... | *Example:*
95 | | ... | \| Configure topology for IPv4 IPsec testing \|
96 | | Configure path for IPSec test
97 | | Set Interface Address | ${dut_node} | ${dut_if} | ${dut_if_ip4}
98 | | ... | ${ip4_plen}
99 | | Set Interface Address | ${dut_node} | ${dut_lo} | ${dut_lo_ip4}
100 | | ... | ${ip4_plen}
101 | | dut1_v4.Set Arp | ${dut_if} | ${tg_if_ip4} | ${tg_if_mac}
102 | | Vpp Route Add | ${dut_node} | ${tg_lo_ip4} | ${ip4_plen} | ${tg_if_ip4}
103 | | ... | ${dut_if}
104 | | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip4}
105 | | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip4}
106 | | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip4}
107 | | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip4}
108
109 | Configure topology for IPv6 IPsec testing
110 | | [Documentation] | Setup topology fo IPv6 IPsec testing.
111 | | ...
112 | | ... | _NOTE:_ This KW sets following test case variable:
113 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
114 | | ... | - dut_src_ip - DUT source IP address. Type: string
115 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
116 | | ... | - tg_src_ip - TG source IP address. Type: string
117 | | ...
118 | | ... | *Example:*
119 | | ... | \| Configure topology for IPv6 IPsec testing \|
120 | | Configure path for IPSec test
121 | | VPP Set If IPv6 Addr | ${dut_node} | ${dut_if} | ${dut_if_ip6} | ${ip6_plen}
122 | | VPP Set If IPv6 Addr | ${dut_node} | ${dut_lo} | ${dut_lo_ip6} | ${ip6_plen}
123 | | Add IP Neighbor | ${dut_node} | ${dut_if} | ${tg_if_ip6} | ${tg_if_mac}
124 | | Vpp All RA Suppress Link Layer | ${nodes}
125 | | Vpp Route Add | ${dut_node} | ${tg_lo_ip6} | ${ip6_plen_rt} | ${tg_if_ip6}
126 | | ... | ${dut_if}
127 | | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip6}
128 | | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip6}
129 | | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip6}
130 | | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip6}
131
132 | Configure manual keyed connection for IPSec
133 | | [Documentation] | Setup IPsec manual keyed connection on VPP node.
134 | | ...
135 | | ... | *Arguments:*
136 | | ... | - node - VPP node to setup IPsec on. Type: dictionary
137 | | ... | - interface - Interface to enable IPsec on. Type: string
138 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
139 | | ... | - crypto_key - Encryption key. Type: string
140 | | ... | - integ_alg - Integrity algorithm. Type: enum
141 | | ... | - integ_key - Integrity key. Type: string
142 | | ... | - l_spi - Local SPI. Type: integer
143 | | ... | - r_spi - Remote SPI. Type: integer
144 | | ... | - l_ip - Local IP address. Type: string
145 | | ... | - r_ip - Remote IP address. Type: string
146 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
147 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
148 | | ...
149 | | ... | _NOTE:_ This KW sets following test case variables:
150 | | ... | - l_sa_id
151 | | ... | - r_sa_id
152 | | ...
153 | | ... | *Example:*
154 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
155 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
156 | | ... | \| Configure manual keyed connection for IPSec \| ${nodes['DUT1']} \
157 | | ... | \| GigabitEthernet0/8/0 \| ${encr_alg} \| sixteenbytes_key \
158 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1000} \| ${1001} \
159 | | ... | \| 192.168.4.4 \| 192.168.3.3 \| 192.168.100.3 \| 192.168.100.2 \|
160 | | [Arguments] | ${node} | ${interface} | ${crypto_alg} | ${crypto_key}
161 | | ... | ${integ_alg} | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip}
162 | | ... | ${r_ip} | ${l_tunnel}=${None} | ${r_tunnel}=${None}
163 | | Set Test Variable | ${l_sa_id} | ${10}
164 | | Set Test Variable | ${r_sa_id} | ${20}
165 | | ${spd_id}= | Set Variable | ${1}
166 | | ${p_hi}= | Set Variable | ${100}
167 | | ${p_lo}= | Set Variable | ${10}
168 | | VPP IPsec Add SAD Entry | ${node} | ${l_sa_id} | ${l_spi} | ${crypto_alg}
169 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
170 | | ... | ${l_tunnel} | ${r_tunnel}
171 | | VPP IPsec Add SAD Entry | ${node} | ${r_sa_id} | ${r_spi} | ${crypto_alg}
172 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
173 | | ... | ${r_tunnel} | ${l_tunnel}
174 | | VPP IPsec Add SPD | ${node} | ${spd_id}
175 | | VPP IPsec SPD Add If | ${node} | ${spd_id} | ${interface}
176 | | ${action}= | Policy Action Bypass
177 | | VPP IPsec SPD Add Entry | ${node} | ${spd_id} | ${p_hi} | ${action}
178 | | ... | inbound=${TRUE} | proto=${ESP_PROTO}
179 | | VPP IPsec SPD Add Entry | ${node} | ${spd_id} | ${p_hi} | ${action}
180 | | ... | inbound=${FALSE} | proto=${ESP_PROTO}
181 | | ${action}= | Policy Action Protect
182 | | VPP IPsec SPD Add Entry | ${node} | ${spd_id} | ${p_lo} | ${action}
183 | | ... | sa_id=${r_sa_id} | laddr_range=${l_ip}
184 | | ... | raddr_range=${r_ip} | inbound=${TRUE}
185 | | VPP IPsec SPD Add Entry | ${node} | ${spd_id} | ${p_lo} | ${action}
186 | | ... | sa_id=${l_sa_id} | laddr_range=${l_ip}
187 | | ... | raddr_range=${r_ip} | inbound=${FALSE}
188
189 | Update IPSec SA keys
190 | | [Documentation] | Update IPsec SA keys on VPP node.
191 | | ...
192 | | ... | *Arguments:*
193 | | ... | - node - VPP node to update SA keys. Type: dictionary
194 | | ... | - l_sa_id - Local SA ID. Type: string
195 | | ... | - r_sa_id - Remote SA ID. Type: string
196 | | ... | - crypto_key - Encryption key. Type: string
197 | | ... | - integ_key - Integrity key. Type: string
198 | | ...
199 | | ... | *Example:*
200 | | ... | \| Update IPSec SA keys \| ${nodes['DUT1']} \
201 | | ... | \| 10 \| 20 \| sixteenbytes_key \| twentybytessecretkey \|
202 | | [Arguments] | ${node} | ${l_sa_id} | ${r_sa_id} | ${crypto_key}
203 | | ... | ${integ_key}
204 | | VPP IPsec SA Set Key | ${dut_node} | ${l_sa_id} | ${crypto_key}
205 | | ... | ${integ_key}
206 | | VPP IPsec SA Set Key | ${dut_node} | ${r_sa_id} | ${crypto_key}
207 | | ... | ${integ_key}
208
209 | Send IPsec Packet and verify ESP encapsulation in received packet
210 | | [Documentation] | Send IPsec packet from TG to DUT. Receive IPsec packet\
211 | | ... | from DUT on TG and verify ESP encapsulation.
212 | | ...
213 | | ... | *Arguments:*
214 | | ... | - node - TG node. Type: dictionary
215 | | ... | - interface - TG Interface. Type: string
216 | | ... | - dst_mac - Destination MAC. Type: string
217 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
218 | | ... | - crypto_key - Encryption key. Type: string
219 | | ... | - integ_alg - Integrity algorithm. Type: enum
220 | | ... | - integ_key - Integrity key. Type: string
221 | | ... | - l_spi - Local SPI. Type: integer
222 | | ... | - r_spi - Remote SPI. Type: integer
223 | | ... | - l_ip - Local IP address. Type: string
224 | | ... | - r_ip - Remote IP address. Type: string
225 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
226 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
227 | | ...
228 | | ... | *Example:*
229 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
230 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
231 | | ... | \| Send IPsec Packet and verify ESP encapsulation in received packet\
232 | | ... | \| ${nodes['TG']} \| eth1 \
233 | | ... | \| 52:54:00:d4:d8:22 \| ${encr_alg} \| sixteenbytes_key \
234 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1001} \| ${1000} \
235 | | ... | \| 192.168.3.3 \| 192.168.4.4 \| 192.168.100.2 \| 192.168.100.3 \|
236 | | [Arguments] | ${node} | ${interface} | ${dst_mac} | ${crypto_alg}
237 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key} | ${l_spi}
238 | | ... | ${r_spi} | ${l_ip} | ${r_ip} | ${l_tunnel}=${None}
239 | | ... | ${r_tunnel}=${None}
240 | | ${src_mac}= | Get Interface Mac | ${node} | ${interface}
241 | | ${if_name}= | Get Interface Name | ${node} | ${interface}
242 | | ${args}= | Traffic Script Gen Arg | ${if_name} | ${if_name} | ${src_mac}
243 | | ... | ${dst_mac} | ${l_ip} | ${r_ip}
244 | | ${crypto_alg_str}= | Get Crypto Alg Scapy Name | ${crypto_alg}
245 | | ${integ_alg_str}= | Get Integ Alg Scapy Name | ${integ_alg}
246 | | ${args}= | Catenate | ${args} | --crypto_alg ${crypto_alg_str}
247 | | ... | --crypto_key ${crypto_key} | --integ_alg ${integ_alg_str}
248 | | ... | --integ_key ${integ_key} | --l_spi ${l_spi} | --r_spi ${r_spi}
249 | | ${args}= | Set Variable If | "${l_tunnel}" == "${None}" | ${args}
250 | | ... | ${args} --src_tun ${l_tunnel}
251 | | ${args}= | Set Variable If | "${r_tunnel}" == "${None}" | ${args}
252 | | ... | ${args} --dst_tun ${r_tunnel}
253 | | Run Traffic Script On Node | ipsec.py | ${node} | ${args}
254
255 | Set up IPv4 IPSec functional test
256 | | [Documentation]
257 | | ... | Set up IPv4 IPSec functional test.
258 | | ...
259 | | Set up functional test
260 | | Configure topology for IPv4 IPsec testing
261
262 | Set up IPv6 IPSec functional test
263 | | [Documentation]
264 | | ... | Set up IPv6 IPSec functional test.
265 | | ...
266 | | Set up functional test
267 | | Configure topology for IPv6 IPsec testing
268
269 | Tear down IPSec functional test
270 | | [Documentation]
271 | | ... | Tear down IPSec functional test.
272 | | ...
273 | | ... | *Example:*
274 | | ...
275 | | ... | \| Tear down IPSec functional test \| ${dut_node} \|
276 | | ...
277 | | [Arguments] | ${dut_node}
278 | | ...
279 | | VPP IPsec Show | ${dut_node}
280 | | Tear down functional test
281
282 | Set up IPSec SW device functional test
283 | | [Documentation]
284 | | ... | Set up IPSec SW device functional test for required IP version.
285 | | ...
286 | | ... | *Arguments:*
287 | | ... | - ${ip_version} - IP version: IPv4 or IPv6. Type: string
288 | | ...
289 | | ... | *Example:*
290 | | ...
291 | | ... | \| Set up IPSec SW device functional test \| IPv4 \|
292 | | ...
293 | | [Arguments] | ${ip_version}
294 | | ...
295 | | ${duts}= | Get Matches | ${nodes} | DUT*
296 | | :FOR | ${dut} | IN | @{duts}
297 | | | Import Library | resources.libraries.python.VppConfigGenerator
298 | | | ... | WITH NAME | ${dut}
299 | | | Run keyword | ${dut}.Set Node | ${nodes['${dut}']}
300 | | | Run keyword | ${dut}.Set Vpp Startup Conf Backup
301 | | | Run keyword | ${dut}.Set Vpp Logfile | /tmp/vpp.log
302 | | | Run keyword | ${dut}.Add Unix Nodaemon
303 | | | Run keyword | ${dut}.Add Unix Log
304 | | | Run keyword | ${dut}.Add Unix Coredump
305 | | | Run keyword | ${dut}.Add Unix CLI Listen | /run/vpp/cli.sock
306 | | | Run keyword | ${dut}.Add Unix Gid
307 | | | Run keyword | ${dut}.Add Api Segment Gid
308 | | | Run keyword | ${dut}.Add DPDK SW Cryptodev | ${1}
309 | | Apply startup configuration on all VPP DUTs | restart_vpp=${FALSE}
310 | | Set up functional test
311 | | Run Keyword | Configure topology for ${ip_version} IPsec testing
312
313 | Tear down IPSec SW device functional test
314 | | [Documentation]
315 | | ... | Tear down IPSec SW device functional test.
316 | | ...
317 | | ${duts}= | Get Matches | ${nodes} | DUT*
318 | | :FOR | ${dut} | IN | @{duts}
319 | | | VPP IPsec Show | ${nodes['${dut}']}
320 | | | Run keyword | ${dut}.Restore Config
321 | | Tear down functional test