5c0fc863a617695ddee2c7b531f30f69290982cf
[csit.git] / resources / libraries / robot / crypto / ipsec.robot
1 # Copyright (c) 2019 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}
103 | | ... | gateway=${tg_if_ip4} | interface=${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}
126 | | ... | gateway=${tg_if_ip6} | interface=${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 | | ...
161 | | [Arguments] | ${node} | ${interface} | ${crypto_alg} | ${crypto_key}
162 | | ... | ${integ_alg} | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip}
163 | | ... | ${r_ip} | ${l_tunnel}=${None} | ${r_tunnel}=${None}
164 | | ... | ${is_ipv6}=${FALSE}
165 | | ...
166 | | Set Test Variable | ${l_sa_id} | ${10}
167 | | Set Test Variable | ${r_sa_id} | ${20}
168 | | ${spd_id}= | Set Variable | ${1}
169 | | ${p_hi}= | Set Variable | ${100}
170 | | ${p_lo}= | Set Variable | ${10}
171 | | VPP IPsec Add SAD Entry | ${node} | ${l_sa_id} | ${l_spi} | ${crypto_alg}
172 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
173 | | ... | ${l_tunnel} | ${r_tunnel}
174 | | VPP IPsec Add SAD Entry | ${node} | ${r_sa_id} | ${r_spi} | ${crypto_alg}
175 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
176 | | ... | ${r_tunnel} | ${l_tunnel}
177 | | VPP IPsec Add SPD | ${node} | ${spd_id}
178 | | VPP IPsec SPD Add If | ${node} | ${spd_id} | ${interface}
179 | | ${action}= | Policy Action Bypass
180 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_hi} | ${action}
181 | | ... | inbound=${TRUE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
182 | | ... | laddr_range=${tg_tun_ip} | raddr_range=${dut_tun_ip}
183 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_hi} | ${action}
184 | | ... | inbound=${FALSE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
185 | | ... | laddr_range=${dut_tun_ip} | raddr_range=${tg_tun_ip}
186 | | ${action}= | Policy Action Protect
187 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_lo} | ${action}
188 | | ... | sa_id=${r_sa_id} | laddr_range=${l_ip}
189 | | ... | raddr_range=${r_ip} | inbound=${TRUE}
190 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_lo} | ${action}
191 | | ... | sa_id=${l_sa_id} | laddr_range=${l_ip}
192 | | ... | raddr_range=${r_ip} | inbound=${FALSE}
193
194 | Send IPsec Packet and verify ESP encapsulation in received packet
195 | | [Documentation] | Send IPsec packet from TG to DUT. Receive IPsec packet\
196 | | ... | from DUT on TG and verify ESP encapsulation.
197 | | ...
198 | | ... | *Arguments:*
199 | | ... | - node - TG node. Type: dictionary
200 | | ... | - interface - TG Interface. Type: string
201 | | ... | - dst_mac - Destination MAC. Type: string
202 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
203 | | ... | - crypto_key - Encryption key. Type: string
204 | | ... | - integ_alg - Integrity algorithm. Type: enum
205 | | ... | - integ_key - Integrity key. Type: string
206 | | ... | - l_spi - Local SPI. Type: integer
207 | | ... | - r_spi - Remote SPI. Type: integer
208 | | ... | - l_ip - Local IP address. Type: string
209 | | ... | - r_ip - Remote IP address. Type: string
210 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
211 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
212 | | ...
213 | | ... | *Example:*
214 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
215 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
216 | | ... | \| Send IPsec Packet and verify ESP encapsulation in received packet\
217 | | ... | \| ${nodes['TG']} \| eth1 \
218 | | ... | \| 52:54:00:d4:d8:22 \| ${encr_alg} \| sixteenbytes_key \
219 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1001} \| ${1000} \
220 | | ... | \| 192.168.3.3 \| 192.168.4.4 \| 192.168.100.2 \| 192.168.100.3 \|
221 | | [Arguments] | ${node} | ${interface} | ${dst_mac} | ${crypto_alg}
222 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key} | ${l_spi}
223 | | ... | ${r_spi} | ${l_ip} | ${r_ip} | ${l_tunnel}=${None}
224 | | ... | ${r_tunnel}=${None}
225 | | ${src_mac}= | Get Interface Mac | ${node} | ${interface}
226 | | ${if_name}= | Get Interface Name | ${node} | ${interface}
227 | | ${args}= | Traffic Script Gen Arg | ${if_name} | ${if_name} | ${src_mac}
228 | | ... | ${dst_mac} | ${l_ip} | ${r_ip}
229 | | ${crypto_alg_str}= | Get Crypto Alg Scapy Name | ${crypto_alg}
230 | | ${integ_alg_str}= | Get Integ Alg Scapy Name | ${integ_alg}
231 | | ${args}= | Catenate | ${args} | --crypto_alg ${crypto_alg_str}
232 | | ... | --crypto_key ${crypto_key} | --integ_alg ${integ_alg_str}
233 | | ... | --integ_key ${integ_key} | --l_spi ${l_spi} | --r_spi ${r_spi}
234 | | ${args}= | Set Variable If | "${l_tunnel}" == "${None}" | ${args}
235 | | ... | ${args} --src_tun ${l_tunnel}
236 | | ${args}= | Set Variable If | "${r_tunnel}" == "${None}" | ${args}
237 | | ... | ${args} --dst_tun ${r_tunnel}
238 | | Run Traffic Script On Node | ipsec.py | ${node} | ${args}
239
240 | Set up IPSec SW device functional test
241 | | [Documentation]
242 | | ... | Set up IPSec SW device functional test for required IP version.
243 | | ...
244 | | ... | *Arguments:*
245 | | ... | - ${ip_version} - IP version: IPv4 or IPv6. Type: string
246 | | ...
247 | | ... | *Example:*
248 | | ...
249 | | ... | \| Set up IPSec SW device functional test \| IPv4 \|
250 | | ...
251 | | [Arguments] | ${ip_version}
252 | | ...
253 | | ${duts}= | Get Matches | ${nodes} | DUT*
254 | | :FOR | ${dut} | IN | @{duts}
255 | | | Import Library | resources.libraries.python.VppConfigGenerator
256 | | | ... | WITH NAME | ${dut}
257 | | | Run keyword | ${dut}.Set Node | ${nodes['${dut}']}
258 | | | Run keyword | ${dut}.Set Vpp Startup Conf Backup
259 | | | Run keyword | ${dut}.Set Vpp Logfile | /tmp/vpp.log
260 | | | Run keyword | ${dut}.Add Unix Nodaemon
261 | | | Run keyword | ${dut}.Add Unix Log
262 | | | Run keyword | ${dut}.Add Unix Coredump
263 | | | Run keyword | ${dut}.Add Unix CLI Listen | /run/vpp/cli.sock
264 | | | Run keyword | ${dut}.Add Unix Gid
265 | | | Run keyword | ${dut}.Add Api Segment Gid
266 | | | ${socket_id}= | Set Variable | ${0}
267 | | | ${sw_dev_count}= | Set Variable | ${1}
268 | | | Run keyword | ${dut}.Add DPDK SW Cryptodev | aesni_mb | ${socket_id}
269 | | | ... | ${sw_dev_count}
270 | | | Run keyword | ${dut}.Add DPDK SW Cryptodev | aesni_gcm | ${socket_id}
271 | | | ... | ${sw_dev_count}
272 | | Write startup configuration on all VPP DUTs
273 | | Set up VPP device test
274 | | Run Keyword | Configure topology for ${ip_version} IPsec testing
275
276 | Tear down IPSec SW device functional test
277 | | [Documentation]
278 | | ... | Tear down IPSec SW device functional test.
279 | | ...
280 | | ${duts}= | Get Matches | ${nodes} | DUT*
281 | | :FOR | ${dut} | IN | @{duts}
282 | | | Run keyword | ${dut}.Restore Config
283 | | Tear down VPP device test