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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 | Documentation | ACL keywords.
18 | Configure MACIP ACLs
20 | | ... | Configure MACIP ACL with required number of not-hitting permit ACEs
21 | | ... | plus two hitting ACEs for both traffic directions.
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
30 | | ... | \| Configure MACIP ACLs \| ${nodes['DUT1']} \| GigabitEthernet0/7/0 \
31 | | ... | \| GigabitEthernet0/8/0 \|
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
56 | | [Arguments] | ${dut} | ${dut_if1}=${NONE} | ${dut_if2}=${NONE}
58 | | ${src_ip_int} = | IP To Int | ${src_ip_start}
59 | | ${src_ip_int} = | Evaluate | ${src_ip_int} - ${ip_step}
61 | | ${ip_limit} = | Set Variable | 255.255.255.255
62 | | ${ip_limit_int} = | IP To Int | ${ip_limit}
64 | | ${src_mac_int} = | Mac To Int | ${src_mac_start}
65 | | ${src_mac_int} = | Evaluate | ${src_mac_int} - ${src_mac_step}
67 | | ${mac_limit} = | Set Variable | ff:ff:ff:ff:ff:ff
68 | | ${mac_limit_int} = | Mac To Int | ${mac_limit}
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.
81 | | | Run Keyword If | '${mac_limit_reached}' == '${TRUE}' | Log
82 | | | ... | Can't do more iterations - MAC address limit has been reached.
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}'
94 | | ${acl0}= | Catenate | ${acl}
95 | | ... | ipv4 ${acl_action} ip ${tg_stream1_subnet} mac ${tg_stream1_mac}
96 | | ... | mask ${tg_mac_mask}
97 | | ${acl1}= | Catenate | ${acl}
98 | | ... | ipv4 ${acl_action} ip ${tg_stream2_subnet} mac ${tg_stream2_mac}
99 | | ... | mask ${tg_mac_mask}
100 | | Add Macip Acl Multi Entries | ${dut} | rules=${acl0}
101 | | Add Macip Acl Multi Entries | ${dut} | rules=${acl1}
102 | | ${acl_idx}= | Set Variable | 0
103 | | Run Keyword Unless | '${dut_if1}' == '${NONE}'
104 | | ... | Add Del Macip Acl Interface | ${dut} | ${dut_if1} | add | ${acl_idx}
105 | | ${acl_idx}= | Set Variable | 1
106 | | Run Keyword Unless | '${dut_if2}' == '${NONE}'
107 | | ... | Add Del Macip Acl Interface | ${dut} | ${dut_if2} | add | ${acl_idx}
109 | Configure IPv4 ACLs
111 | | ... | Configure ACL with required number of not-hitting permit ACEs plus two
112 | | ... | hitting ACEs for both traffic directions.
114 | | ... | *Arguments:*
115 | | ... | - dut_node - DUT node. Type: dictionary
116 | | ... | - dut_if1 - DUT node interface1 name (Optional). Type: string
117 | | ... | - dut_if2 - DUT node interface2 name (Optional). Type: string
121 | | ... | \| Configure IPv4 ACLs \| ${nodes['DUT1']} \| GigabitEthernet0/7/0 \
122 | | ... | \| GigabitEthernet0/8/0 \|
124 | | ... | _NOTE:_ This KW uses following test case variables:
125 | | ... | - src_ip_start - Source IP address start. Type: string
126 | | ... | - dst_ip_start - Destination IP address start. Type: string
127 | | ... | - ip_step - IP address step. Type: string
128 | | ... | - sport_start - Source port number start. Type: string
129 | | ... | - dport_start - Destination port number start. Type: string
130 | | ... | - port_step - Port number step. Type: string
131 | | ... | - no_hit_aces_number - Number of not-hitting ACEs to be configured.
132 | | ... | Type: integer
133 | | ... | - acl_apply_type - To what path apply the ACL - input or output.
134 | | ... | Type: string
135 | | ... | - acl_action - Action for the rule - deny, permit, permit+reflect.
136 | | ... | Type: string
137 | | ... | - trex_stream1_subnet - IP subnet used by T-Rex in direction 0->1.
138 | | ... | Type: string
139 | | ... | - trex_stream2_subnet - IP subnet used by T-Rex in direction 1->0.
140 | | ... | Type: string
142 | | [Arguments] | ${dut} | ${dut_if1}=${NONE} | ${dut_if2}=${NONE}
143 | | ${src_ip_int} = | Evaluate
144 | | ... | int(ipaddress.ip_address($src_ip_start)) - $ip_step
145 | | ... | modules=ipaddress
146 | | ${dst_ip_int} = | Evaluate
147 | | ... | int(ipaddress.ip_address($dst_ip_start)) - $ip_step
148 | | ... | modules=ipaddress
149 | | ${ip_limit} = | Set Variable | 255.255.255.255
150 | | ${ip_limit_int} = | Evaluate
151 | | ... | int(ipaddress.ip_address($ip_limit)) | modules=ipaddress
152 | | ${sport}= | Evaluate | $sport_start - $port_step
153 | | ${dport}= | Evaluate | $dport_start - $port_step
154 | | ${port_limit}= | Set Variable | ${65535}
155 | | ${acl}= | Set Variable | ipv4 permit
156 | | FOR | ${nr} | IN RANGE | 0 | ${no_hit_aces_number}
157 | | | ${src_ip_int} = | Evaluate | $src_ip_int + $ip_step
158 | | | ${dst_ip_int} = | Evaluate | $dst_ip_int + $ip_step
159 | | | ${sport}= | Evaluate | $sport + $port_step
160 | | | ${dport}= | Evaluate | $dport + $port_step
161 | | | ${ipv4_limit_reached}= | Set Variable If
162 | | | ... | $src_ip_int > $ip_limit_int or $src_ip_int > $ip_limit_int
164 | | | ${udp_limit_reached}= | Set Variable If
165 | | | ... | $sport > $port_limit or $dport > $port_limit | ${TRUE}
166 | | | Run Keyword If | $ipv4_limit_reached is True | Log
167 | | | ... | Can't do more iterations - IPv4 address limit has been reached.
169 | | | Run Keyword If | $udp_limit_reached is True | Log
170 | | | ... | Can't do more iterations - UDP port limit has been reached.
172 | | | ${src_ip} = | Run Keyword If | $ipv4_limit_reached is True
173 | | | ... | Set Variable | ${ip_limit}
174 | | | ... | ELSE | Evaluate | str(ipaddress.ip_address($src_ip_int))
175 | | | ... | modules=ipaddress
176 | | | ${dst_ip} = | Run Keyword If | $ipv4_limit_reached is True
177 | | | ... | Set Variable | ${ip_limit}
178 | | | ... | ELSE | Evaluate | str(ipaddress.ip_address($dst_ip_int))
179 | | | ... | modules=ipaddress
180 | | | ${sport}= | Set Variable If | ${sport} > $port_limit | $port_limit
182 | | | ${dport}= | Set Variable If | ${dport} > $port_limit | $port_limit
184 | | | ${acl}= | Catenate | ${acl} | src ${src_ip}/32 dst ${dst_ip}/32
185 | | | ... | sport ${sport} | dport ${dport},
186 | | | Exit For Loop If
187 | | | ... | $ipv4_limit_reached is True or $udp_limit_reached is True
189 | | ${acl}= | Catenate | ${acl}
190 | | ... | ipv4 ${acl_action} src ${trex_stream1_subnet},
191 | | ... | ipv4 ${acl_action} src ${trex_stream2_subnet}
192 | | Add Replace Acl Multi Entries | ${dut} | rules=${acl}
193 | | @{acl_list}= | Create List | ${0}
194 | | Run Keyword If | 'input' in $acl_apply_type and $dut_if1 is not None
195 | | ... | Set Acl List For Interface | ${dut} | ${dut_if1} | input | ${acl_list}
196 | | Run Keyword If | 'input' in $acl_apply_type and $dut_if2 is not None
197 | | ... | Set Acl List For Interface | ${dut} | ${dut_if2} | input | ${acl_list}
198 | | Run Keyword If | 'output' in $acl_apply_type and $dut_if1 is not None
199 | | ... | Set Acl List For Interface | ${dut} | ${dut_if1} | output
200 | | ... | ${acl_list}
201 | | Run Keyword If | 'output' in $acl_apply_type and $dut_if2 is not None
202 | | ... | Set Acl List For Interface | ${dut} | ${dut_if2} | output
203 | | ... | ${acl_list}
205 | Configure ACLs on a single interface
207 | | ... | Configure ACL
209 | | ... | *Arguments:*
210 | | ... | - dut - DUT node. Type: string
211 | | ... | - dut_if - DUT node interface name. Type: string
212 | | ... | - acl_apply_type - To what path apply the ACL - input or output.
213 | | ... | - acl_action - Action for the rule - deny, permit, permit+reflect.
214 | | ... | - subnets - Subnets to apply the specific ACL. Type: list
218 | | ... | \| Configure ACLs on a single interface \| ${nodes['DUT1']}
219 | | ... | \| ... \| GigabitEthernet0/7/0 \| input \| permit | 0.0.0.0/0
221 | | [Arguments] | ${dut} | ${dut_if} | ${acl_apply_type} | ${acl_action}
223 | | Set Test variable | ${acl} | ${EMPTY}
224 | | FOR | ${subnet} | IN | @{subnets}
225 | | | ${acl} = | Run Keyword If | '${acl}' == '${EMPTY}'
226 | | | ... | Set Variable | ipv4 ${acl_action} src ${subnet}
228 | | | ... | Catenate | SEPARATOR=", " | ${acl}
229 | | | ... | ipv4 ${acl_action} src ${subnet}
231 | | Add Replace Acl Multi Entries | ${dut} | rules=${acl}
232 | | @{acl_list} = | Create List | ${0}
233 | | Set Acl List For Interface | ${dut} | ${dut_if} | ${acl_apply_type}
234 | | ... | ${acl_list}
236 | Initialize IPv4 routing with IPv4 ACLs on DUT1 in circular topology
238 | | ... | Set UP state on VPP interfaces in path on nodes in 2-node / 3-node
239 | | ... | circular topology. Get the interface MAC addresses and setup ARP on
240 | | ... | all VPP interfaces. Setup IPv4 addresses with /24 prefix on DUT-TG
241 | | ... | links. In case of 3-node topology setup IPv4 adresses with /30 prefix
242 | | ... | on DUT1-DUT2 link and set routing on both DUT nodes with prefix /24
243 | | ... | and next hop of neighbour DUT interface IPv4 address.
244 | | ... | Apply required ACL rules to DUT1 interfaces.
246 | | ... | *Arguments:*
247 | | ... | - ip_nr - Number of IPs to be used. Type: integer
251 | | ... | \| Initialize IPv4 routing fwith IPv4 ACLs on DUT1 \
252 | | ... | in 3-node circular topology \|
254 | | [Arguments] | ${ip_nr}=${1}
256 | | ${dut2_status} | ${value}= | Run Keyword And Ignore Error
257 | | ... | Variable Should Exist | ${dut2}
258 | | ${dut}= | Run Keyword If | '${dut2_status}' == 'PASS'
259 | | ... | Set Variable | ${dut2}
260 | | ... | ELSE | Set Variable | ${dut1}
261 | | ${dut_if2}= | Run Keyword If | '${dut2_status}' == 'PASS'
262 | | ... | Set Variable | ${dut2_if2}
263 | | ... | ELSE | Set Variable | ${dut1_if2}
265 | | Set interfaces in path up
267 | | FOR | ${number} | IN RANGE | 2 | ${ip_nr}+2
268 | | | VPP Add IP Neighbor
269 | | | ... | ${dut1} | ${dut1_if1} | 10.10.10.${number} | ${tg_if1_mac}
270 | | | VPP Add IP Neighbor
271 | | | ... | ${dut} | ${dut_if2} | 20.20.20.${number} | ${tg_if2_mac}
273 | | Run Keyword If | '${dut2_status}' == 'PASS'
274 | | ... | VPP Add IP Neighbor
275 | | ... | ${dut1} | ${dut1_if2} | 1.1.1.2 | ${dut2_if1_mac}
276 | | Run Keyword If | '${dut2_status}' == 'PASS'
277 | | ... | VPP Add IP Neighbor
278 | | ... | ${dut2} | ${dut2_if1} | 1.1.1.1 | ${dut1_if2_mac}
280 | | VPP Interface Set IP Address
281 | | ... | ${dut1} | ${dut1_if1} | 10.10.10.1 | 24
282 | | VPP Interface Set IP Address
283 | | ... | ${dut} | ${dut_if2} | 20.20.20.1 | 24
284 | | Run Keyword If | '${dut2_status}' == 'PASS'
285 | | ... | VPP Interface Set IP Address
286 | | ... | ${dut1} | ${dut1_if2} | 1.1.1.1 | 30
287 | | Run Keyword If | '${dut2_status}' == 'PASS'
288 | | ... | VPP Interface Set IP Address
289 | | ... | ${dut2} | ${dut2_if1} | 1.1.1.2 | 30
291 | | Run Keyword If | '${dut2_status}' == 'PASS'
292 | | ... | Vpp Route Add | ${dut1} | 20.20.20.0 | 24 | gateway=1.1.1.2
293 | | ... | interface=${dut1_if2}
294 | | Run Keyword If | '${dut2_status}' == 'PASS'
295 | | ... | Vpp Route Add | ${dut2} | 10.10.10.0 | 24 | gateway=1.1.1.1
296 | | ... | interface=${dut2_if1}
298 | | Configure IPv4 ACLs | ${dut1} | ${dut1_if1} | ${dut1_if2}