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