CSIT-1539 Aligning FUNC/PERF keywords - Phase III
[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 | 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 | Library | resources.libraries.python.NodePath
21 | Library | resources.libraries.python.TrafficScriptExecutor
22 | ...
23 | Resource | resources/libraries/robot/shared/default.robot
24 | ...
25 | Documentation | IPsec keywords
26
27 *** Keywords ***
28 | Generate keys for IPSec
29 | | [Documentation] | Generate keys for IPsec.
30 | | ...
31 | | ... | *Arguments:*
32 | | ... | - crypto_alg - Encryption algorithm. Type: enum
33 | | ... | - integ_alg - Integrity algorithm. Type: enum
34 | | ...
35 | | ... | _NOTE:_ This KW sets following test case variable:
36 | | ... | - encr_key - Encryption key. Type: string
37 | | ... | - auth_key - Integrity key. Type: string
38 | | ...
39 | | ... | *Example:*
40 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
41 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
42 | | ... | \| Generate keys for IPSec \| ${encr_alg} \| ${auth_alg} \|
43 | | ...
44 | | [Arguments] | ${crypto_alg} | ${integ_alg}
45 | | ...
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 | | ... | - dut_lo - DUT loopback interface. Type: string
58 | | ...
59 | | ... | *Example:*
60 | | ... | \| Configure path for IPSec test \|
61 | | ...
62 | | ${dut1_lo1}= | Vpp Create Loopback | ${dut1}
63 | | Set Interface State | ${dut1} | ${dut1_if1} | up
64 | | Set Interface State | ${dut1} | ${dut1_lo1} | up
65 | | Vpp Node Interfaces Ready Wait | ${dut1}
66 | | Set Test Variable | ${dut1_lo1}
67
68 | Configure topology for IPv4 IPsec testing
69 | | [Documentation] | Setup topology for IPv4 IPsec testing.
70 | | ...
71 | | ... | _NOTE:_ This KW sets following test case variable:
72 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
73 | | ... | - dut_src_ip - DUT source IP address. Type: string
74 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
75 | | ... | - tg_src_ip - TG source IP address. Type: string
76 | | ...
77 | | ... | *Example:*
78 | | ... | \| Configure topology for IPv4 IPsec testing \|
79 | | ...
80 | | Configure path for IPSec test
81 | | VPP Interface Set IP Address
82 | | ... | ${dut1} | ${dut1_if1} | ${dut_if_ip4} | ${ip4_plen}
83 | | VPP Interface Set IP Address
84 | | ... | ${dut1} | ${dut1_lo1} | ${dut_lo_ip4} | ${ip4_plen}
85 | | VPP Add IP Neighbor
86 | | ... | ${dut1} | ${dut1_if1} | ${tg_if_ip4} | ${tg_if1_mac}
87 | | Vpp Route Add
88 | | ... | ${dut1} | ${tg_lo_ip4} | ${ip4_plen} | gateway=${tg_if_ip4}
89 | | ... | interface=${dut1_if1}
90 | | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip4}
91 | | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip4}
92 | | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip4}
93 | | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip4}
94
95 | Configure topology for IPv6 IPsec testing
96 | | [Documentation] | Setup topology fo IPv6 IPsec testing.
97 | | ...
98 | | ... | _NOTE:_ This KW sets following test case variable:
99 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
100 | | ... | - dut_src_ip - DUT source IP address. Type: string
101 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
102 | | ... | - tg_src_ip - TG source IP address. Type: string
103 | | ...
104 | | ... | *Example:*
105 | | ... | \| Configure topology for IPv6 IPsec testing \|
106 | | ...
107 | | Configure path for IPSec test
108 | | VPP Interface Set IP Address
109 | | ... | ${dut1} | ${dut1_if1} | ${dut_if_ip6} | ${ip6_plen}
110 | | VPP Interface Set IP Address
111 | | ... | ${dut1} | ${dut1_lo1} | ${dut_lo_ip6} | ${ip6_plen}
112 | | VPP Add IP Neighbor
113 | | ... | ${dut1} | ${dut1_if1} | ${tg_if_ip6} | ${tg_if1_mac}
114 | | Vpp All RA Suppress Link Layer | ${nodes}
115 | | Vpp Route Add
116 | | ... | ${dut1} | ${tg_lo_ip6} | ${ip6_plen_rt} | gateway=${tg_if_ip6}
117 | | ... | interface=${dut1_if1}
118 | | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip6}
119 | | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip6}
120 | | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip6}
121 | | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip6}
122
123 | Configure manual keyed connection for IPSec
124 | | [Documentation] | Setup IPsec manual keyed connection on VPP node.
125 | | ...
126 | | ... | *Arguments:*
127 | | ... | - node - VPP node to setup IPsec on. Type: dictionary
128 | | ... | - interface - Interface to enable IPsec on. Type: string
129 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
130 | | ... | - crypto_key - Encryption key. Type: string
131 | | ... | - integ_alg - Integrity algorithm. Type: enum
132 | | ... | - integ_key - Integrity key. Type: string
133 | | ... | - l_spi - Local SPI. Type: integer
134 | | ... | - r_spi - Remote SPI. Type: integer
135 | | ... | - l_ip - Local IP address. Type: string
136 | | ... | - r_ip - Remote IP address. Type: string
137 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
138 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
139 | | ...
140 | | ... | _NOTE:_ This KW sets following test case variables:
141 | | ... | - l_sa_id
142 | | ... | - r_sa_id
143 | | ...
144 | | ... | *Example:*
145 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
146 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
147 | | ... | \| Configure manual keyed connection for IPSec \| ${nodes['DUT1']} \
148 | | ... | \| GigabitEthernet0/8/0 \| ${encr_alg} \| sixteenbytes_key \
149 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1000} \| ${1001} \
150 | | ... | \| 192.168.4.4 \| 192.168.3.3 \| 192.168.100.3 \| 192.168.100.2 \|
151 | | ...
152 | | [Arguments] | ${node} | ${interface} | ${crypto_alg} | ${crypto_key}
153 | | ... | ${integ_alg} | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip}
154 | | ... | ${r_ip} | ${l_tunnel}=${None} | ${r_tunnel}=${None}
155 | | ... | ${is_ipv6}=${FALSE}
156 | | ...
157 | | Set Test Variable | ${l_sa_id} | ${10}
158 | | Set Test Variable | ${r_sa_id} | ${20}
159 | | ${spd_id}= | Set Variable | ${1}
160 | | ${p_hi}= | Set Variable | ${100}
161 | | ${p_lo}= | Set Variable | ${10}
162 | | VPP IPsec Add SAD Entry | ${node} | ${l_sa_id} | ${l_spi} | ${crypto_alg}
163 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
164 | | ... | ${l_tunnel} | ${r_tunnel}
165 | | VPP IPsec Add SAD Entry | ${node} | ${r_sa_id} | ${r_spi} | ${crypto_alg}
166 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
167 | | ... | ${r_tunnel} | ${l_tunnel}
168 | | VPP IPsec Add SPD | ${node} | ${spd_id}
169 | | VPP IPsec SPD Add If | ${node} | ${spd_id} | ${interface}
170 | | ${action}= | Policy Action Bypass
171 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_hi} | ${action}
172 | | ... | inbound=${TRUE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
173 | | ... | laddr_range=${tg_tun_ip} | raddr_range=${dut_tun_ip}
174 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_hi} | ${action}
175 | | ... | inbound=${FALSE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
176 | | ... | laddr_range=${dut_tun_ip} | raddr_range=${tg_tun_ip}
177 | | ${action}= | Policy Action Protect
178 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_lo} | ${action}
179 | | ... | sa_id=${r_sa_id} | laddr_range=${l_ip}
180 | | ... | raddr_range=${r_ip} | inbound=${TRUE}
181 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_lo} | ${action}
182 | | ... | sa_id=${l_sa_id} | laddr_range=${l_ip}
183 | | ... | raddr_range=${r_ip} | inbound=${FALSE}
184
185 | Send IPsec Packet and verify ESP encapsulation in received packet
186 | | [Documentation] | Send IPsec packet from TG to DUT. Receive IPsec packet\
187 | | ... | from DUT on TG and verify ESP encapsulation.
188 | | ...
189 | | ... | *Arguments:*
190 | | ... | - node - TG node. Type: dictionary
191 | | ... | - interface - TG Interface. Type: string
192 | | ... | - dst_mac - Destination MAC. Type: string
193 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
194 | | ... | - crypto_key - Encryption key. Type: string
195 | | ... | - integ_alg - Integrity algorithm. Type: enum
196 | | ... | - integ_key - Integrity key. Type: string
197 | | ... | - l_spi - Local SPI. Type: integer
198 | | ... | - r_spi - Remote SPI. Type: integer
199 | | ... | - l_ip - Local IP address. Type: string
200 | | ... | - r_ip - Remote IP address. Type: string
201 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
202 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
203 | | ...
204 | | ... | *Example:*
205 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
206 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
207 | | ... | \| Send IPsec Packet and verify ESP encapsulation in received packet\
208 | | ... | \| ${nodes['TG']} \| eth1 \
209 | | ... | \| 52:54:00:d4:d8:22 \| ${encr_alg} \| sixteenbytes_key \
210 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1001} \| ${1000} \
211 | | ... | \| 192.168.3.3 \| 192.168.4.4 \| 192.168.100.2 \| 192.168.100.3 \|
212 | | ...
213 | | [Arguments] | ${node} | ${interface} | ${dst_mac} | ${crypto_alg}
214 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key} | ${l_spi}
215 | | ... | ${r_spi} | ${l_ip} | ${r_ip} | ${l_tunnel}=${None}
216 | | ... | ${r_tunnel}=${None}
217 | | ...
218 | | ${src_mac}= | Get Interface Mac | ${node} | ${interface}
219 | | ${if_name}= | Get Interface Name | ${node} | ${interface}
220 | | ${args}= | Traffic Script Gen Arg | ${if_name} | ${if_name} | ${src_mac}
221 | | ... | ${dst_mac} | ${l_ip} | ${r_ip}
222 | | ${crypto_alg_str}= | Get Crypto Alg Scapy Name | ${crypto_alg}
223 | | ${integ_alg_str}= | Get Integ Alg Scapy Name | ${integ_alg}
224 | | ${args}= | Catenate | ${args} | --crypto_alg ${crypto_alg_str}
225 | | ... | --crypto_key ${crypto_key} | --integ_alg ${integ_alg_str}
226 | | ... | --integ_key ${integ_key} | --l_spi ${l_spi} | --r_spi ${r_spi}
227 | | ${args}= | Set Variable If | "${l_tunnel}" == "${None}" | ${args}
228 | | ... | ${args} --src_tun ${l_tunnel}
229 | | ${args}= | Set Variable If | "${r_tunnel}" == "${None}" | ${args}
230 | | ... | ${args} --dst_tun ${r_tunnel}
231 | | Run Traffic Script On Node | ipsec.py | ${node} | ${args}