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