Support existing test types with ASTF
[csit.git] / resources / libraries / robot / ip / nat.robot
1 # Copyright (c) 2020 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 | resources.libraries.python.NATUtil
16 |
17 | Documentation | Keywords for NAT feature in VPP.
18
19 *** Keywords ***
20 | Configure inside and outside interfaces
21 | | [Documentation] | Configure inside and outside interfaces for NAT44.
22 | |
23 | | ... | *Arguments:*
24 | | ... | - node - DUT node to set NAT44 interfaces on. Type: dictionary
25 | | ... | - int_in - Inside interface. Type: string
26 | | ... | - int_out - Outside interface. Type: string
27 | |
28 | | ... | *Example:*
29 | |
30 | | ... | \| Configure inside and outside interfaces \| ${nodes['DUT1']} \
31 | | ... | \| FortyGigabitEtherneta/0/0 \| FortyGigabitEtherneta/0/1 \|
32 | |
33 | | [Arguments] | ${node} | ${int_in} | ${int_out}
34 | |
35 | | ${int_in_name}= | Set variable | ${node['interfaces']['${int_in}']['name']}
36 | | ${int_out_name}= | Set variable
37 | | ... | ${node['interfaces']['${int_out}']['name']}
38 | | Set NAT44 Interfaces | ${node} | ${int_in_name} | ${int_out_name}
39
40 | Initialize NAT44 endpoint-dependent mode in circular topology
41 | | [Documentation] | Initialization of NAT44 endpoint-dependent mode on DUT1
42 | |
43 | | ... | This keyword also sets a test variable \${resetter}
44 | | ... | to hold a callable which resets VPP state.
45 | | ... | Keywords performing search will call it to get consistent trials.
46 | | ... | Tests which do not wish to reset NAT state should use ramp-up,
47 | | ... | so the resetter is not set if \${ramp_up_duration} variable
48 | | ... | is (defined and) nonzero.
49 | |
50 | | Configure inside and outside interfaces
51 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
52 | | ${resetter} = | Set NAT44 Address Range
53 | | ... | ${dut1} | ${out_net} | ${out_net_end}
54 | | ${ramp_up_duration} = | Get Ramp Up Duration
55 | | Return From Keyword If | ${ramp_up_duration}
56 | | Set Test Variable | \${resetter}
57
58 # TODO: Remove when 'ip4.Initialize IPv4 forwarding in circular topology' KW
59 # adapted to use IP values from variables
60 | Initialize IPv4 forwarding for NAT44 in circular topology
61 | | [Documentation]
62 | | ... | Set IPv4 forwarding for NAT44:
63 | | ... | - set interfaces up
64 | | ... | - set IP addresses
65 | | ... | - set ARP
66 | | ... | - create routes
67 | |
68 | | ${status} | ${value}= | Run Keyword And Ignore Error
69 | | ... | Variable Should Exist | ${dut2}
70 | | ${dut2_status}= | Set Variable If | '${status}' == 'PASS' | ${True}
71 | | ... | ${False}
72 | |
73 | | Set interfaces in path up
74 | |
75 | | VPP Interface Set IP Address
76 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut1_if1_ip4} | ${dut1_if1_mask}
77 | | VPP Interface Set IP Address
78 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut1_if2_ip4} | ${dut1_if2_mask}
79 | | Run Keyword If | ${dut2_status}
80 | | ... | VPP Interface Set IP Address
81 | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut2_if1_ip4} | ${dut2_if1_mask}
82 | | Run Keyword If | ${dut2_status}
83 | | ... | VPP Interface Set IP Address
84 | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${dut2_if2_ip4} | ${dut2_if2_mask}
85 | |
86 | | VPP Add IP Neighbor
87 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
88 | | Run Keyword If |  ${dut2_status}
89 | | ... | VPP Add IP Neighbor
90 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip4}
91 | | ... | ${DUT2_${int}1_mac}[0]
92 | | ... | ELSE | VPP Add IP Neighbor
93 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${tg_if2_ip4} | ${TG_pf2_mac}[0]
94 | | Run Keyword If |  ${dut2_status}
95 | | ... | VPP Add IP Neighbor
96 | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut1_if1_ip4}
97 | | ... | ${DUT1_${int}2_mac}[0]
98 | | Run Keyword If |  ${dut2_status}
99 | | ... | VPP Add IP Neighbor
100 | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${tg_if2_ip4}| ${TG_pf2_mac}[0]
101 | |
102 | | Vpp Route Add
103 | | ... | ${dut1} | ${in_net} | ${in_mask} | gateway=${tg_if1_ip4}
104 | | ... | interface=${DUT1_${int}1}[0]
105 | | Run Keyword If | ${dut2_status}
106 | | ... | Vpp Route Add
107 | | ... | ${dut1} | ${dest_net} | ${dest_mask} | gateway=${dut2_if1_ip4}
108 | | ... | interface=${DUT1_${int}2}[0]
109 | | ... | ELSE | Vpp Route Add
110 | | ... | ${dut1} | ${dest_net} | ${dest_mask} | gateway=${tg_if2_ip4}
111 | | ... | interface=${DUT1_${int}2}[0]
112 | | Run Keyword If | ${dut2_status}
113 | | ... | Vpp Route Add
114 | | ... | ${dut2} | ${dest_net} | ${dest_mask} | gateway=${tg_if2_ip4}
115 | | ... | interface=${DUT2_${int}2}[0]
116 | | Run Keyword If | ${dut2_status}
117 | | ... | Vpp Route Add
118 | | ... | ${dut2} | ${out_net} | ${out_mask} | gateway=${dut1_if2_ip4}
119 | | ... | interface=${DUT2_${int}1}[0]
120
121 | Verify NAT44 TCP sessions number on DUT1 node
122 | | [Documentation] | Verify that all required NAT44 TCP sessions are
123 | | ... | established on DUT1 node.
124 | |
125 | | Verify NAT44 sessions number | ${nodes['DUT1']} | ${n_sessions} | TCP
126
127 | Verify NAT44 UDP sessions number on DUT1 node
128 | | [Documentation] | Verify that all required NAT44 UDP sessions are
129 | | ... | established on DUT1 node.
130 | |
131 | | Verify NAT44 sessions number | ${nodes['DUT1']} | ${n_sessions} | UDP
132
133 | Verify NAT44 sessions number
134 | | [Documentation] | Verify that all required NAT44 sessions of required
135 | | ... | protocol are established.
136 | |
137 | | ... | *Arguments:*
138 | | ... | - node - DUT node. Type: dictionary
139 | | ... | - exp_n_sessions - Expected number of NAT44 sessions. Type: integer
140 | | ... | - proto - Required protocol. Type: string
141 | |
142 | | ... | *Example:*
143 | |
144 | | ... | \| Verify NAT44 sessions number \| ${nodes['DUT1']} \| ${64512} \
145 | | ... | \| UDP \|
146 | |
147 | | [Arguments] | ${node} | ${exp_n_sessions} | ${proto}
148 | |
149 | | ${nat44_sessions}= | Get NAT44 Sessions Number | ${node} | ${proto}
150 | | Should Be Equal As Integers | ${nat44_sessions} | ${exp_n_sessions}
151 | | ... | Not all NAT44 ${proto} sessions have been established
152
153 # DET44 - NAT44 deterministic
154 | Enable DET44 plugin on DUT
155 | | [Documentation] | Enable DET44 plugin on DUT.
156 | |
157 | | ... | *Arguments:*
158 | | ... | - node - DUT node to enablr DET44 on.
159 | | ... | Type: dictionary
160 | | ... | - inside_vrf - Inside VRF ID; default value: 0.
161 | | ... | Type: string or integer
162 | | ... | - outside_vrf - Outside VRF ID; default value: 0.
163 | | ... | Type: string or integer
164 | |
165 | | ... | *Example:*
166 | |
167 | | ... | \| Enable DET44 plugin on all DUTs \|
168 | |
169 | | [Arguments] | ${node} | ${inside_vrf}=${0} | ${outside_vrf}=${0}
170 | |
171 | | Enable DET44 Plugin
172 | | ... | ${node} | inside_vrf=${inside_vrf} | outside_vrf=${outside_vrf}
173
174 | Configure DET44 interfaces
175 | | [Documentation] | Configure inside and outside interfaces for DET44.
176 | |
177 | | ... | *Arguments:*
178 | | ... | - node - DUT node to set DET44 interfaces on. Type: dictionary
179 | | ... | - int_in - Inside interface key. Type: string
180 | | ... | - int_out - Outside interface key. Type: string
181 | |
182 | | ... | *Example:*
183 | |
184 | | ... | \| Configure DET44 interfaces \| ${nodes['DUT1']} \| port5 \| port6 \|
185 | |
186 | | [Arguments] | ${node} | ${int_in} | ${int_out}
187 | |
188 | | Set DET44 Interface | ${dut1} | ${int_in} | is_inside=${True}
189 | | Set DET44 Interface | ${dut1} | ${int_out} | is_inside=${False}
190
191 | Configure deterministic mode for NAT44
192 | | [Documentation] | Set deterministic behaviour of NAT44 (DET44).
193 | |
194 | | ... | This keyword also sets a test variable \${resetter}
195 | | ... | to hold a callable which resets VPP state.
196 | | ... | Keywords performing search will call it to get consistent trials.
197 | | ... | Tests which do not wish to reset NAT state should use ramp-up,
198 | | ... | so the resetter is not set if \${ramp_up_duration} variable
199 | | ... | is (defined and) nonzero.
200 | |
201 | | ... | *Arguments:*
202 | | ... | - node - DUT node to set deterministic mode for NAT44 on.
203 | | ... | Type: dictionary
204 | | ... | - ip_in - Inside IP. Type: string
205 | | ... | - subnet_in - Inside IP subnet. Type: string
206 | | ... | - ip_out - Outside IP. Type: string
207 | | ... | - subnet_out - Outside IP subnet. Type: string
208 | |
209 | | ... | *Example:*
210 | |
211 | | ... | \| Configure deterministic mode for NAT44 \| ${nodes['DUT1']} \
212 | | ... | \| 100.0.0.0 \| 12 \| 12.1.1.0 \| 24 \|
213 | |
214 | | [Arguments] | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
215 | |
216 | | ${resetter} = | Set DET44 Mapping
217 | | ... | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
218 | | ${ramp_up_duration} = | Get Ramp Up Duration
219 | | Return From Keyword If | ${ramp_up_duration}
220 | | Set Test Variable | \${resetter}
221
222 | Initialize NAT44 deterministic mode in circular topology
223 | | [Documentation] | Initialization of NAT44 deterministic mode (DET44)
224 | | ... | on DUT1 node.
225 | |
226 | | Enable DET44 plugin on DUT | ${dut1}
227 | | Configure DET44 interfaces
228 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
229 | | Configure deterministic mode for NAT44
230 | | ... | ${dut1} | ${in_net} | ${in_mask} | ${out_net} | ${out_mask}
231
232 | Show DET44 verbose
233 | | [Documentation] | Get DET44 settings on the node.
234 | |
235 | | ... | *Arguments:*
236 | | ... | - node - DUT node to show NAT. Type: dictionary
237 | |
238 | | ... | *Example:*
239 | |
240 | | ... | \| Show DET44 verbose \| ${nodes['DUT1']} \|
241 | |
242 | | [Arguments] | ${node}
243 | |
244 | | Show DET44 | ${node}
245
246 | Verify DET44 sessions number on DUT1 node
247 | | [Documentation] | Verify that all required DET44 sessions are established on
248 | | ... | DUT1 node.
249 | |
250 | | Verify DET44 sessions number | ${nodes['DUT1']} | ${n_sessions}
251
252 | Verify DET44 sessions number
253 | | [Documentation] | Verify that all required DET44 sessions are established.
254 | |
255 | | ... | *Arguments:*
256 | | ... | - node - DUT node. Type: dictionary
257 | | ... | - exp_n_sessions - Expected number of DET44 sessions. Type: integer
258 | |
259 | | ... | *Example:*
260 | |
261 | | ... | \| Verify DET44 sessions number \| ${nodes['DUT1']} \| ${64512} \|
262 | |
263 | | [Arguments] | ${node} | ${exp_n_sessions}
264 | |
265 | | ${det44_sessions}= | Get DET44 Sessions Number | ${node}
266 | | Should Be Equal As Integers | ${det44_sessions} | ${exp_n_sessions}
267 | | ... | Not all DET44 sessions have been established