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