a70a34c2dbbf49dfdc8b7a3903bb0c9a5ce4c5e7
[csit.git] / resources / libraries / robot / features / acl.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 | Documentation | ACL keywords.
16
17 *** Keywords ***
18 | Configure MACIP ACLs
19 | | [Documentation]
20 | | ... | Configure MACIP ACL with required number of not-hitting permit ACEs
21 | | ... | plus two hitting ACEs for both traffic directions.
22 | | ...
23 | | ... | *Arguments:*
24 | | ... | - dut_node - DUT node. Type: dictionary
25 | | ... | - dut_if1 - DUT node interface1 name (Optional). Type: string
26 | | ... | - dut_if2 - DUT node interface2 name (Optional). Type: string
27 | | ...
28 | | ... | *Example:*
29 | | ...
30 | | ... | \| Configure MACIP ACLs \| ${nodes['DUT1']} \| GigabitEthernet0/7/0 \
31 | | ... | \| GigabitEthernet0/8/0 \|
32 | | ...
33 | | ... | _NOTE:_ This KW uses following test case variables:
34 | | ... | - src_ip_start - Source IP address start. Type: string
35 | | ... | - ip_step - IP address step. Type: string
36 | | ... | - src_mac_start - Source MAC address start in format with colons.
37 | | ... | Type: string
38 | | ... | - src_mac_step - Source MAC address step. Type: string
39 | | ... | - src_mac_mask - Source MAC address mask. 00:00:00:00:00:00 is a
40 | | ... | wildcard mask. Type: string
41 | | ... | - no_hit_aces_number - Number of not-hitting ACEs to be configured.
42 | | ... | Type: integer
43 | | ... | - acl_action - Action for the rule - deny, permit, permit+reflect.
44 | | ... | Type: string
45 | | ... | - tg_stream1_subnet - IP subnet used by TG in direction 0->1.
46 | | ... | Type: string
47 | | ... | - tg_stream2_subnet - IP subnet used by TG in direction 1->0.
48 | | ... | Type: string
49 | | ... | - tg_stream1_mac - Source MAC address of traffic stream 1.
50 | | ... | Type: string
51 | | ... | - tg_stream2_mac - Source MAC address of traffic stream 2.
52 | | ... | Type: string
53 | | ... | - tg_mac_mask - MAC address mask for traffic streams.
54 | | ... | 00:00:00:00:00:00 is a wildcard mask. Type: string
55 | | ...
56 | | [Arguments] | ${dut} | ${dut_if1}=${NONE} | ${dut_if2}=${NONE}
57 | | ...
58 | | ${src_ip_int} = | IP To Int | ${src_ip_start}
59 | | ${src_ip_int} = | Evaluate | ${src_ip_int} - ${ip_step}
60 | | ...
61 | | ${ip_limit} = | Set Variable | 255.255.255.255
62 | | ${ip_limit_int} = | IP To Int | ${ip_limit}
63 | | ...
64 | | ${src_mac_int} = | Mac To Int | ${src_mac_start}
65 | | ${src_mac_int} = | Evaluate | ${src_mac_int} - ${src_mac_step}
66 | | ...
67 | | ${mac_limit} = | Set Variable | ff:ff:ff:ff:ff:ff
68 | | ${mac_limit_int} = | Mac To Int | ${mac_limit}
69 | | ...
70 | | ${acl}= | Set Variable | ipv4 permit
71 | | :FOR | ${nr} | IN RANGE | 0 | ${no_hit_aces_number}
72 | | | ${src_ip_int} = | Evaluate | ${src_ip_int} + ${ip_step}
73 | | | ${src_mac_int} = | Evaluate | ${src_mac_int} + ${src_mac_step}
74 | | | ${ipv4_limit_reached}= | Set Variable If
75 | | | ... | ${src_ip_int} > ${ip_limit_int} | ${TRUE}
76 | | | ${mac_limit_reached}= | Set Variable If
77 | | | ... | ${src_mac_int} > ${mac_limit_int} | ${TRUE}
78 | | | Run Keyword If | '${ipv4_limit_reached}' == '${TRUE}' | Log
79 | | | ... | Can't do more iterations - IPv4 address limit has been reached.
80 | | | ... | WARN
81 | | | Run Keyword If | '${mac_limit_reached}' == '${TRUE}' | Log
82 | | | ... | Can't do more iterations - MAC address limit has been reached.
83 | | | ... | WARN
84 | | | ${src_ip} = | Run Keyword If | '${ipv4_limit_reached}' == '${TRUE}'
85 | | | ... | Set Variable | ${ip_limit}
86 | | | ... | ELSE | Int To IP | ${src_ip_int}
87 | | | ${src_mac}= | Run Keyword If | '${mac_limit_reached}' == '${TRUE}'
88 | | | ... | Set Variable | ${mac_limit}
89 | | | ... | ELSE | Int To Mac | ${src_mac_int}
90 | | | ${acl}= | Catenate | ${acl} | ip ${src_ip}/32
91 | | | ... | mac ${src_mac} | mask ${src_mac_mask},
92 | | | Exit For Loop If | '${ipv4_limit_reached}' == '${TRUE}' or '${mac_limit_reached}' == '${TRUE}'
93 | | ${acl0}= | Catenate | ${acl}
94 | | ... | ipv4 ${acl_action} ip ${tg_stream1_subnet} mac ${tg_stream1_mac}
95 | | ... | mask ${tg_mac_mask}
96 | | ${acl1}= | Catenate | ${acl}
97 | | ... | ipv4 ${acl_action} ip ${tg_stream2_subnet} mac ${tg_stream2_mac}
98 | | ... | mask ${tg_mac_mask}
99 | | Add Macip Acl Multi Entries | ${dut} | rules=${acl0}
100 | | Add Macip Acl Multi Entries | ${dut} | rules=${acl1}
101 | | ${acl_idx}= | Set Variable | 0
102 | | Run Keyword Unless | '${dut_if1}' == '${NONE}'
103 | | ... | Add Del Macip Acl Interface | ${dut} | ${dut_if1} | add | ${acl_idx}
104 | | ${acl_idx}= | Set Variable | 1
105 | | Run Keyword Unless | '${dut_if2}' == '${NONE}'
106 | | ... | Add Del Macip Acl Interface | ${dut} | ${dut_if2} | add | ${acl_idx}
107
108 | Configure IPv4 ACLs
109 | | [Documentation]
110 | | ... | Configure ACL with required number of not-hitting permit ACEs plus two
111 | | ... | hitting ACEs for both traffic directions.
112 | | ...
113 | | ... | *Arguments:*
114 | | ... | - dut_node - DUT node. Type: dictionary
115 | | ... | - dut_if1 - DUT node interface1 name (Optional). Type: string
116 | | ... | - dut_if2 - DUT node interface2 name (Optional). Type: string
117 | | ...
118 | | ... | *Example:*
119 | | ...
120 | | ... | \| Configure IPv4 ACLs \| ${nodes['DUT1']} \| GigabitEthernet0/7/0 \
121 | | ... | \| GigabitEthernet0/8/0 \|
122 | | ...
123 | | ... | _NOTE:_ This KW uses following test case variables:
124 | | ... | - src_ip_start - Source IP address start. Type: string
125 | | ... | - dst_ip_start - Destination IP address start. Type: string
126 | | ... | - ip_step - IP address step. Type: string
127 | | ... | - sport_start - Source port number start. Type: string
128 | | ... | - dport_start - Destination port number start. Type: string
129 | | ... | - port_step - Port number step. Type: string
130 | | ... | - no_hit_aces_number - Number of not-hitting ACEs to be configured.
131 | | ... | Type: integer
132 | | ... | - acl_apply_type - To what path apply the ACL - input or output.
133 | | ... | Type: string
134 | | ... | - acl_action - Action for the rule - deny, permit, permit+reflect.
135 | | ... | Type: string
136 | | ... | - trex_stream1_subnet - IP subnet used by T-Rex in direction 0->1.
137 | | ... | Type: string
138 | | ... | - trex_stream2_subnet - IP subnet used by T-Rex in direction 1->0.
139 | | ... | Type: string
140 | | ...
141 | | [Arguments] | ${dut} | ${dut_if1}=${NONE} | ${dut_if2}=${NONE}
142 | | ${src_ip_int} = | Evaluate
143 | | ... | int(ipaddress.ip_address(unicode($src_ip_start))) - $ip_step
144 | | ... | modules=ipaddress
145 | | ${dst_ip_int} = | Evaluate
146 | | ... | int(ipaddress.ip_address(unicode($dst_ip_start))) - $ip_step
147 | | ... | modules=ipaddress
148 | | ${ip_limit} = | Set Variable | 255.255.255.255
149 | | ${ip_limit_int} = | Evaluate
150 | | ... | int(ipaddress.ip_address(unicode($ip_limit))) | modules=ipaddress
151 | | ${sport}= | Evaluate | $sport_start - $port_step
152 | | ${dport}= | Evaluate | $dport_start - $port_step
153 | | ${port_limit}= | Set Variable | ${65535}
154 | | ${acl}= | Set Variable | ipv4 permit
155 | | :FOR | ${nr} | IN RANGE | 0 | ${no_hit_aces_number}
156 | | | ${src_ip_int} = | Evaluate | $src_ip_int + $ip_step
157 | | | ${dst_ip_int} = | Evaluate | $dst_ip_int + $ip_step
158 | | | ${sport}= | Evaluate | $sport + $port_step
159 | | | ${dport}= | Evaluate | $dport + $port_step
160 | | | ${ipv4_limit_reached}= | Set Variable If
161 | | | ... | $src_ip_int > $ip_limit_int or $src_ip_int > $ip_limit_int
162 | | | ... | ${TRUE}
163 | | | ${udp_limit_reached}= | Set Variable If
164 | | | ... | $sport > $port_limit or $dport > $port_limit | ${TRUE}
165 | | | Run Keyword If | $ipv4_limit_reached is True | Log
166 | | | ... | Can't do more iterations - IPv4 address limit has been reached.
167 | | | ... | WARN
168 | | | Run Keyword If | $udp_limit_reached is True | Log
169 | | | ... | Can't do more iterations - UDP port limit has been reached.
170 | | | ... | WARN
171 | | | ${src_ip} = | Run Keyword If | $ipv4_limit_reached is True
172 | | | ... | Set Variable | ${ip_limit}
173 | | | ... | ELSE | Evaluate | str(ipaddress.ip_address($src_ip_int))
174 | | | ... | modules=ipaddress
175 | | | ${dst_ip} = | Run Keyword If | $ipv4_limit_reached is True
176 | | | ... | Set Variable | ${ip_limit}
177 | | | ... | ELSE | Evaluate | str(ipaddress.ip_address($dst_ip_int))
178 | | | ... | modules=ipaddress
179 | | | ${sport}= | Set Variable If | ${sport} > $port_limit | $port_limit
180 | | | ... | ${sport}
181 | | | ${dport}= | Set Variable If | ${dport} > $port_limit | $port_limit
182 | | | ... | ${dport}
183 | | | ${acl}= | Catenate | ${acl} | src ${src_ip}/32 dst ${dst_ip}/32
184 | | | ... | sport ${sport} | dport ${dport},
185 | | | Exit For Loop If
186 | | | ... | $ipv4_limit_reached is True or $udp_limit_reached is True
187 | | ${acl}= | Catenate | ${acl}
188 | | ... | ipv4 ${acl_action} src ${trex_stream1_subnet},
189 | | ... | ipv4 ${acl_action} src ${trex_stream2_subnet}
190 | | Add Replace Acl Multi Entries | ${dut} | rules=${acl}
191 | | @{acl_list}= | Create List | ${0}
192 | | Run Keyword If | 'input' in $acl_apply_type and $dut_if1 is not None
193 | | ... | Set Acl List For Interface | ${dut} | ${dut_if1} | input | ${acl_list}
194 | | Run Keyword If | 'input' in $acl_apply_type and $dut_if2 is not None
195 | | ... | Set Acl List For Interface | ${dut} | ${dut_if2} | input | ${acl_list}
196 | | Run Keyword If | 'output' in $acl_apply_type and $dut_if1 is not None
197 | | ... | Set Acl List For Interface | ${dut} | ${dut_if1} | output
198 | | ... | ${acl_list}
199 | | Run Keyword If | 'output' in $acl_apply_type and $dut_if2 is not None
200 | | ... | Set Acl List For Interface | ${dut} | ${dut_if2} | output
201 | | ... | ${acl_list}
202
203 | Configure ACLs on a single interface
204 | | [Documentation]
205 | | ... | Configure ACL
206 | | ...
207 | | ... | *Arguments:*
208 | | ... | - dut - DUT node. Type: string
209 | | ... | - dut_if - DUT node interface name. Type: string
210 | | ... | - acl_apply_type - To what path apply the ACL - input or output.
211 | | ... | - acl_action - Action for the rule - deny, permit, permit+reflect.
212 | | ... | - subnets - Subnets to apply the specific ACL. Type: list
213 | | ...
214 | | ... | *Example:*
215 | | ...
216 | | ... | \| Configure ACLs on a single interface \| ${nodes['DUT1']}
217 | | ... | \| ... \| GigabitEthernet0/7/0 \| input \| permit | 0.0.0.0/0
218 | | ...
219 | | [Arguments] | ${dut} | ${dut_if} | ${acl_apply_type} | ${acl_action}
220 | | ... | @{subnets}
221 | | Set Test variable | ${acl} | ${EMPTY}
222 | | :FOR | ${subnet} | IN | @{subnets}
223 | | | ${acl} = | Run Keyword If | '${acl}' == '${EMPTY}'
224 | | | ... | Set Variable | ipv4 ${acl_action} src ${subnet}
225 | | | ... | ELSE
226 | | | ... | Catenate | SEPARATOR=", " | ${acl}
227 | | | ... | ipv4 ${acl_action} src ${subnet}
228 | | Add Replace Acl Multi Entries | ${dut} | rules=${acl}
229 | | @{acl_list} = | Create List | ${0}
230 | | Set Acl List For Interface | ${dut} | ${dut_if} | ${acl_apply_type}
231 | | ... | ${acl_list}
232
233 | Initialize IPv4 routing with IPv4 ACLs on DUT1 in circular topology
234 | | [Documentation]
235 | | ... | Set UP state on VPP interfaces in path on nodes in 2-node / 3-node
236 | | ... | circular topology. Get the interface MAC addresses and setup ARP on
237 | | ... | all VPP interfaces. Setup IPv4 addresses with /24 prefix on DUT-TG
238 | | ... | links. In case of 3-node topology setup IPv4 adresses with /30 prefix
239 | | ... | on DUT1-DUT2 link and set routing on both DUT nodes with prefix /24
240 | | ... | and next hop of neighbour DUT interface IPv4 address.
241 | | ... | Apply required ACL rules to DUT1 interfaces.
242 | | ...
243 | | ... | *Arguments:*
244 | | ... | - ip_nr - Number of IPs to be used. Type: integer
245 | | ...
246 | | ... | *Example:*
247 | | ...
248 | | ... | \| Initialize IPv4 routing fwith IPv4 ACLs on DUT1 \
249 | | ... | in 3-node circular topology \|
250 | | ...
251 | | [Arguments] | ${ip_nr}=${1}
252 | | ...
253 | | ${dut2_status} | ${value}= | Run Keyword And Ignore Error
254 | | ... | Variable Should Exist | ${dut2}
255 | | ${dut}= | Run Keyword If | '${dut2_status}' == 'PASS'
256 | | ... | Set Variable | ${dut2}
257 | | ... | ELSE | Set Variable | ${dut1}
258 | | ${dut_if2}= | Run Keyword If | '${dut2_status}' == 'PASS'
259 | | ... | Set Variable | ${dut2_if2}
260 | | ... | ELSE | Set Variable | ${dut1_if2}
261 | | ...
262 | | Set interfaces in path up
263 | | ...
264 | | :FOR | ${number} | IN RANGE | 2 | ${ip_nr}+2
265 | | | VPP Add IP Neighbor
266 | | | ... | ${dut1} | ${dut1_if1} | 10.10.10.${number} | ${tg_if1_mac}
267 | | | VPP Add IP Neighbor
268 | | | ... | ${dut} | ${dut_if2} | 20.20.20.${number} | ${tg_if2_mac}
269 | | Run Keyword If | '${dut2_status}' == 'PASS'
270 | | ... | VPP Add IP Neighbor
271 | | ... | ${dut1} | ${dut1_if2} | 1.1.1.2 | ${dut2_if1_mac}
272 | | Run Keyword If | '${dut2_status}' == 'PASS'
273 | | ... | VPP Add IP Neighbor
274 | | ... | ${dut2} | ${dut2_if1} | 1.1.1.1 | ${dut1_if2_mac}
275 | | ...
276 | | VPP Interface Set IP Address
277 | | ... | ${dut1} | ${dut1_if1} | 10.10.10.1 | 24
278 | | VPP Interface Set IP Address
279 | | ... | ${dut} | ${dut_if2} | 20.20.20.1 | 24
280 | | Run Keyword If | '${dut2_status}' == 'PASS'
281 | | ... | VPP Interface Set IP Address
282 | | ... | ${dut1} | ${dut1_if2} | 1.1.1.1 | 30
283 | | Run Keyword If | '${dut2_status}' == 'PASS'
284 | | ... | VPP Interface Set IP Address
285 | | ... | ${dut2} | ${dut2_if1} | 1.1.1.2 | 30
286 | | ...
287 | | Run Keyword If | '${dut2_status}' == 'PASS'
288 | | ... | Vpp Route Add | ${dut1} | 20.20.20.0 | 24 | gateway=1.1.1.2
289 | | ... | interface=${dut1_if2}
290 | | Run Keyword If | '${dut2_status}' == 'PASS'
291 | | ... | Vpp Route Add | ${dut2} | 10.10.10.0 | 24 | gateway=1.1.1.1
292 | | ... | interface=${dut2_if1}
293 | | ...
294 | | Configure IPv4 ACLs | ${dut1} | ${dut1_if1} | ${dut1_if2}