Clean: Various libraries
[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 | ...
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 path for IPSec test
50 | | [Documentation] | Setup path for IPsec testing TG<-->DUT1.
51 | | ...
52 | | ... | _NOTE:_ This KW sets following test case variable:
53 | | ... | - dut_lo - DUT loopback interface. Type: string
54 | | ...
55 | | ... | *Example:*
56 | | ... | \| Configure path for IPSec test \|
57 | | ...
58 | | ${dut1_lo1}= | Vpp Create Loopback | ${dut1}
59 | | Set Interface State | ${dut1} | ${dut1_if1} | up
60 | | Set Interface State | ${dut1} | ${dut1_lo1} | up
61 | | Vpp Node Interfaces Ready Wait | ${dut1}
62 | | Set Test Variable | ${dut1_lo1}
63
64 | Configure topology for IPv4 IPsec testing
65 | | [Documentation] | Setup topology for IPv4 IPsec testing.
66 | | ...
67 | | ... | _NOTE:_ This KW sets following test case variable:
68 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
69 | | ... | - dut_src_ip - DUT source IP address. Type: string
70 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
71 | | ... | - tg_src_ip - TG source IP address. Type: string
72 | | ...
73 | | ... | *Example:*
74 | | ... | \| Configure topology for IPv4 IPsec testing \|
75 | | ...
76 | | Configure path for IPSec test
77 | | VPP Interface Set IP Address
78 | | ... | ${dut1} | ${dut1_if1} | ${dut_if_ip4} | ${ip4_plen}
79 | | VPP Interface Set IP Address
80 | | ... | ${dut1} | ${dut1_lo1} | ${dut_lo_ip4} | ${ip4_plen}
81 | | VPP Add IP Neighbor
82 | | ... | ${dut1} | ${dut1_if1} | ${tg_if_ip4} | ${tg_if1_mac}
83 | | Vpp Route Add
84 | | ... | ${dut1} | ${tg_lo_ip4} | ${ip4_plen} | gateway=${tg_if_ip4}
85 | | ... | interface=${dut1_if1}
86 | | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip4}
87 | | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip4}
88 | | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip4}
89 | | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip4}
90
91 | Configure topology for IPv6 IPsec testing
92 | | [Documentation] | Setup topology fo IPv6 IPsec testing.
93 | | ...
94 | | ... | _NOTE:_ This KW sets following test case variable:
95 | | ... | - dut_tun_ip - DUT tunnel IP address. Type: string
96 | | ... | - dut_src_ip - DUT source IP address. Type: string
97 | | ... | - tg_tun_ip - TG tunnel IP address. Type: string
98 | | ... | - tg_src_ip - TG source IP address. Type: string
99 | | ...
100 | | ... | *Example:*
101 | | ... | \| Configure topology for IPv6 IPsec testing \|
102 | | ...
103 | | Configure path for IPSec test
104 | | VPP Interface Set IP Address
105 | | ... | ${dut1} | ${dut1_if1} | ${dut_if_ip6} | ${ip6_plen}
106 | | VPP Interface Set IP Address
107 | | ... | ${dut1} | ${dut1_lo1} | ${dut_lo_ip6} | ${ip6_plen}
108 | | VPP Add IP Neighbor
109 | | ... | ${dut1} | ${dut1_if1} | ${tg_if_ip6} | ${tg_if1_mac}
110 | | Vpp All RA Suppress Link Layer | ${nodes}
111 | | Vpp Route Add
112 | | ... | ${dut1} | ${tg_lo_ip6} | ${ip6_plen_rt} | gateway=${tg_if_ip6}
113 | | ... | interface=${dut1_if1}
114 | | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip6}
115 | | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip6}
116 | | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip6}
117 | | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip6}
118
119 | Configure manual keyed connection for IPSec
120 | | [Documentation] | Setup IPsec manual keyed connection on VPP node.
121 | | ...
122 | | ... | *Arguments:*
123 | | ... | - node - VPP node to setup IPsec on. Type: dictionary
124 | | ... | - interface - Interface to enable IPsec on. Type: string
125 | | ... | - crypto_alg - Encrytion algorithm. Type: enum
126 | | ... | - crypto_key - Encryption key. Type: string
127 | | ... | - integ_alg - Integrity algorithm. Type: enum
128 | | ... | - integ_key - Integrity key. Type: string
129 | | ... | - l_spi - Local SPI. Type: integer
130 | | ... | - r_spi - Remote SPI. Type: integer
131 | | ... | - l_ip - Local IP address. Type: string
132 | | ... | - r_ip - Remote IP address. Type: string
133 | | ... | - l_tunnel - Local tunnel IP address (optional). Type: string
134 | | ... | - r_tunnel - Remote tunnel IP address (optional). Type: string
135 | | ...
136 | | ... | _NOTE:_ This KW sets following test case variables:
137 | | ... | - l_sa_id
138 | | ... | - r_sa_id
139 | | ...
140 | | ... | *Example:*
141 | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \|
142 | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \|
143 | | ... | \| Configure manual keyed connection for IPSec \| ${nodes['DUT1']} \
144 | | ... | \| GigabitEthernet0/8/0 \| ${encr_alg} \| sixteenbytes_key \
145 | | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1000} \| ${1001} \
146 | | ... | \| 192.168.4.4 \| 192.168.3.3 \| 192.168.100.3 \| 192.168.100.2 \|
147 | | ...
148 | | [Arguments] | ${node} | ${interface} | ${crypto_alg} | ${crypto_key}
149 | | ... | ${integ_alg} | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip}
150 | | ... | ${r_ip} | ${l_tunnel}=${None} | ${r_tunnel}=${None}
151 | | ... | ${is_ipv6}=${FALSE}
152 | | ...
153 | | Set Test Variable | ${l_sa_id} | ${10}
154 | | Set Test Variable | ${r_sa_id} | ${20}
155 | | ${spd_id}= | Set Variable | ${1}
156 | | ${p_hi}= | Set Variable | ${100}
157 | | ${p_lo}= | Set Variable | ${10}
158 | | VPP IPsec Add SAD Entry | ${node} | ${l_sa_id} | ${l_spi} | ${crypto_alg}
159 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
160 | | ... | ${l_tunnel} | ${r_tunnel}
161 | | VPP IPsec Add SAD Entry | ${node} | ${r_sa_id} | ${r_spi} | ${crypto_alg}
162 | | ... | ${crypto_key} | ${integ_alg} | ${integ_key}
163 | | ... | ${r_tunnel} | ${l_tunnel}
164 | | VPP IPsec Add SPD | ${node} | ${spd_id}
165 | | VPP IPsec SPD Add If | ${node} | ${spd_id} | ${interface}
166 | | ${action}= | Policy Action Bypass
167 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_hi} | ${action}
168 | | ... | inbound=${TRUE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
169 | | ... | laddr_range=${tg_tun_ip} | raddr_range=${dut_tun_ip}
170 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_hi} | ${action}
171 | | ... | inbound=${FALSE} | proto=${ESP_PROTO} | is_ipv6=${is_ipv6}
172 | | ... | laddr_range=${dut_tun_ip} | raddr_range=${tg_tun_ip}
173 | | ${action}= | Policy Action Protect
174 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_lo} | ${action}
175 | | ... | sa_id=${r_sa_id} | laddr_range=${l_ip}
176 | | ... | raddr_range=${r_ip} | inbound=${TRUE}
177 | | VPP IPsec Policy Add | ${node} | ${spd_id} | ${p_lo} | ${action}
178 | | ... | sa_id=${l_sa_id} | laddr_range=${l_ip}
179 | | ... | raddr_range=${r_ip} | inbound=${FALSE}
180
181 | Initialize IPSec in 3-node circular topology
182 | | [Documentation]
183 | | ... | Set UP state on VPP interfaces in path on nodes in 3-node circular
184 | | ... | topology. Get the interface MAC addresses and setup ARP on all VPP
185 | | ... | interfaces. Setup IPv4 addresses with /24 prefix on DUT-TG and
186 | | ... | DUT1-DUT2 links. Set routing for encrypted traffic on both DUT nodes
187 | | ... | with prefix /8 and next hop of neighbour DUT or TG interface IPv4
188 | | ... | address.
189 | | ...
190 | | Set interfaces in path up
191 | | VPP Interface Set IP Address | ${dut1} | ${dut1_if1}
192 | | ... | ${dut1_if1_ip4} | 24
193 | | VPP Interface Set IP Address | ${dut2} | ${dut2_if2}
194 | | ... | ${dut2_if2_ip4} | 24
195 | | VPP Add IP Neighbor | ${dut1} | ${dut1_if1} | ${tg_if1_ip4} | ${tg_if1_mac}
196 | | VPP Add IP Neighbor | ${dut2} | ${dut2_if2} | ${tg_if2_ip4} | ${tg_if2_mac}
197 | | Vpp Route Add | ${dut1} | ${laddr_ip4} | 8 | gateway=${tg_if1_ip4}
198 | | ... | interface=${dut1_if1}
199 | | Vpp Route Add | ${dut2} | ${raddr_ip4} | 8 | gateway=${tg_if2_ip4}
200 | | ... | interface=${dut2_if2}