Small fixies in IPSEC resources
[csit.git] / resources / libraries / robot / 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/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
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 | IPsec Generate Keys
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 | | ... | \| IPsec Generate Keys \| ${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 | Setup Path for IPsec testing
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 | | ... | \| Setup Path for IPsec testing \|
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 | Setup 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 | | ... | \| Setup Topology for IPv4 IPsec testing \|
96 | | Setup Path for IPsec testing
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 | Setup 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 | | ... | \| Setup Topology for IPv6 IPsec testing \|
120 | | Setup Path for IPsec testing
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} | ${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 | VPP Setup IPsec Manual Keyed Connection
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 | | ... | *Example:*
150 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
151 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
152 | | ... | \| VPP Setup IPsec Manual Keyed Connection \| ${nodes['DUT1']} \
153 | | ... | \| GigabitEthernet0/8/0 \| ${encr_alg} \| sixteenbytes_key \
154 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1000} \| ${1001} \
155 | | ... | \| 192.168.4.4 \| 192.168.3.3 \| 192.168.100.3 \| 192.168.100.2 \|
156 | | [Arguments] | ${node} | ${interface} | ${crypto_alg} | ${crypto_key}
157 | | ...         | ${integ_alg} | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip}
158 | | ...         | ${r_ip} | ${l_tunnel}=${None} | ${r_tunnel}=${None}
159 | | ${l_sa_id}= | Set Variable | ${10}
160 | | ${r_sa_id}= | Set Variable | ${20}
161 | | ${spd_id}= | Set Variable | ${1}
162 | | ${p_hi}= | Set Variable | ${100}
163 | | ${p_lo}= | Set Variable | ${10}
164 | | VPP IPsec Add SAD Entry | ${node} | ${l_sa_id} | ${l_spi} | ${crypto_alg}
165 | | ...                     | ${crypto_key} | ${integ_alg} | ${integ_key}
166 | | ...                     | ${l_tunnel} | ${r_tunnel}
167 | | VPP IPsec Add SAD Entry | ${node} | ${r_sa_id} | ${r_spi} | ${crypto_alg}
168 | | ...                     | ${crypto_key} | ${integ_alg} | ${integ_key}
169 | | ...                     | ${r_tunnel} | ${l_tunnel}
170 | | VPP IPsec Add SPD | ${node} | ${spd_id}
171 | | VPP IPsec SPD Add If | ${node} | ${spd_id} | ${interface}
172 | | ${action}= | Policy Action Bypass
173 | | VPP IPsec SPD Add Entry | ${node} | ${spd_id} | ${p_hi} | ${action}
174 | | ...                     | inbound=${TRUE} | proto=${ESP_PROTO}
175 | | VPP IPsec SPD Add Entry | ${node} | ${spd_id} | ${p_hi} | ${action}
176 | | ...                     | inbound=${FALSE} | proto=${ESP_PROTO}
177 | | ${action}= | Policy Action Protect
178 | | VPP IPsec SPD Add Entry | ${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 SPD Add Entry | ${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 and Receive IPsec 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 and Receive IPsec Packet \| ${nodes['TG']} \| eth1 \
208 | | ... | \| 52:54:00:d4:d8:22 \| ${encr_alg} \| sixteenbytes_key \
209 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1001} \| ${1000} \
210 | | ... | \| 192.168.3.3 \| 192.168.4.4 \| 192.168.100.2 \| 192.168.100.3 \|
211 | | [Arguments] | ${node} | ${interface} | ${dst_mac} | ${crypto_alg}
212 | | ...         | ${crypto_key} | ${integ_alg} | ${integ_key} | ${l_spi}
213 | | ...         | ${r_spi} | ${l_ip} | ${r_ip} | ${l_tunnel}=${None}
214 | | ...         | ${r_tunnel}=${None}
215 | | ${src_mac}= | Get Interface Mac | ${node} | ${interface}
216 | | ${if_name}= | Get Interface Name | ${node} | ${interface}
217 | | ${args}= | Traffic Script Gen Arg | ${if_name} | ${if_name} | ${src_mac}
218 | | ...      | ${dst_mac} | ${l_ip} | ${r_ip}
219 | | ${crypto_alg_str}= | Get Crypto Alg Scapy Name | ${crypto_alg}
220 | | ${integ_alg_str}= | Get Integ Alg Scapy Name | ${integ_alg}
221 | | ${args}= | Catenate | ${args} | --crypto_alg ${crypto_alg_str}
222 | | ...      | --crypto_key ${crypto_key} | --integ_alg ${integ_alg_str}
223 | | ...      | --integ_key ${integ_key} | --l_spi ${l_spi} | --r_spi ${r_spi}
224 | | ${args}= | Set Variable If | "${l_tunnel}" == "${None}" | ${args}
225 | | ... | ${args} --src_tun ${l_tunnel}
226 | | ${args}= | Set Variable If | "${r_tunnel}" == "${None}" | ${args}
227 | | ... | ${args} --dst_tun ${r_tunnel}
228 | | Run Traffic Script On Node | ipsec.py | ${node} | ${args}