e80e1e1c85457583eff1644f68bbc7e96d5253b5
[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 | | Configure inside and outside interfaces
44 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
45 | | Set NAT44 Address Range
46 | | ... | ${dut1} | ${out_net} | ${out_net_end}
47
48 # TODO: Remove when 'ip4.Initialize IPv4 forwarding in circular topology' KW
49 # adapted to use IP values from variables
50 | Initialize IPv4 forwarding for NAT44 in circular topology
51 | | [Documentation]
52 | | ... | Set IPv4 forwarding for NAT44:
53 | | ... | - set interfaces up
54 | | ... | - set IP addresses
55 | | ... | - set ARP
56 | | ... | - create routes
57 | |
58 | | ${status} | ${value}= | Run Keyword And Ignore Error
59 | | ... | Variable Should Exist | ${dut2}
60 | | ${dut2_status}= | Set Variable If | '${status}' == 'PASS' | ${True}
61 | | ... | ${False}
62 | |
63 | | Set interfaces in path up
64 | |
65 | | VPP Interface Set IP Address
66 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut1_if1_ip4} | ${dut1_if1_mask}
67 | | VPP Interface Set IP Address
68 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut1_if2_ip4} | ${dut1_if2_mask}
69 | | Run Keyword If | ${dut2_status}
70 | | ... | VPP Interface Set IP Address
71 | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut2_if1_ip4} | ${dut2_if1_mask}
72 | | Run Keyword If | ${dut2_status}
73 | | ... | VPP Interface Set IP Address
74 | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${dut2_if2_ip4} | ${dut2_if2_mask}
75 | |
76 | | VPP Add IP Neighbor
77 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
78 | | Run Keyword If |  ${dut2_status}
79 | | ... | VPP Add IP Neighbor
80 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip4}
81 | | ... | ${DUT2_${int}1_mac}[0]
82 | | ... | ELSE | VPP Add IP Neighbor
83 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${tg_if2_ip4} | ${TG_pf2_mac}[0]
84 | | Run Keyword If |  ${dut2_status}
85 | | ... | VPP Add IP Neighbor
86 | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut1_if1_ip4}
87 | | ... | ${DUT1_${int}2_mac}[0]
88 | | Run Keyword If |  ${dut2_status}
89 | | ... | VPP Add IP Neighbor
90 | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${tg_if2_ip4}| ${TG_pf2_mac}[0]
91 | |
92 | | Vpp Route Add
93 | | ... | ${dut1} | ${in_net} | ${in_mask} | gateway=${tg_if1_ip4}
94 | | ... | interface=${DUT1_${int}1}[0]
95 | | Run Keyword If | ${dut2_status}
96 | | ... | Vpp Route Add
97 | | ... | ${dut1} | ${dest_net} | ${dest_mask} | gateway=${dut2_if1_ip4}
98 | | ... | interface=${DUT1_${int}2}[0]
99 | | ... | ELSE | Vpp Route Add
100 | | ... | ${dut1} | ${dest_net} | ${dest_mask} | gateway=${tg_if2_ip4}
101 | | ... | interface=${DUT1_${int}2}[0]
102 | | Run Keyword If | ${dut2_status}
103 | | ... | Vpp Route Add
104 | | ... | ${dut2} | ${dest_net} | ${dest_mask} | gateway=${tg_if2_ip4}
105 | | ... | interface=${DUT2_${int}2}[0]
106 | | Run Keyword If | ${dut2_status}
107 | | ... | Vpp Route Add
108 | | ... | ${dut2} | ${out_net} | ${out_mask} | gateway=${dut1_if2_ip4}
109 | | ... | interface=${DUT2_${int}1}[0]
110
111 | Verify NAT44 TCP sessions number on DUT1 node
112 | | [Documentation] | Verify that all required NAT44 TCP sessions are
113 | | ... | established on DUT1 node.
114 | |
115 | | Verify NAT44 sessions number | ${nodes['DUT1']} | ${n_sessions} | TCP
116
117 | Verify NAT44 UDP sessions number on DUT1 node
118 | | [Documentation] | Verify that all required NAT44 UDP sessions are
119 | | ... | established on DUT1 node.
120 | |
121 | | Verify NAT44 sessions number | ${nodes['DUT1']} | ${n_sessions} | UDP
122
123 | Verify NAT44 sessions number
124 | | [Documentation] | Verify that all required NAT44 sessions of required
125 | | ... | protocol are established.
126 | |
127 | | ... | *Arguments:*
128 | | ... | - node - DUT node. Type: dictionary
129 | | ... | - exp_n_sessions - Expected number of NAT44 sessions. Type: integer
130 | | ... | - proto - Required protocol. Type: string
131 | |
132 | | ... | *Example:*
133 | |
134 | | ... | \| Verify NAT44 sessions number \| ${nodes['DUT1']} \| ${64512} \
135 | | ... | \| UDP \|
136 | |
137 | | [Arguments] | ${node} | ${exp_n_sessions} | ${proto}
138 | |
139 | | ${nat44_sessions}= | Get NAT44 Sessions Number | ${node} | ${proto}
140 | | Should Be Equal As Integers | ${nat44_sessions} | ${exp_n_sessions}
141 | | ... | Not all NAT44 ${proto} sessions have been established
142
143 # DET44 - NAT44 deterministic
144 | Enable DET44 plugin on DUT
145 | | [Documentation] | Enable DET44 plugin on DUT.
146 | |
147 | | ... | *Arguments:*
148 | | ... | - node - DUT node to enablr DET44 on.
149 | | ... | Type: dictionary
150 | | ... | - inside_vrf - Inside VRF ID; default value: 0.
151 | | ... | Type: string or integer
152 | | ... | - outside_vrf - Outside VRF ID; default value: 0.
153 | | ... | Type: string or integer
154 | |
155 | | ... | *Example:*
156 | |
157 | | ... | \| Enable DET44 plugin on all DUTs \|
158 | |
159 | | [Arguments] | ${node} | ${inside_vrf}=${0} | ${outside_vrf}=${0}
160 | |
161 | | Enable DET44 Plugin
162 | | ... | ${node} | inside_vrf=${inside_vrf} | outside_vrf=${outside_vrf}
163
164 | Configure DET44 interfaces
165 | | [Documentation] | Configure inside and outside interfaces for DET44.
166 | |
167 | | ... | *Arguments:*
168 | | ... | - node - DUT node to set DET44 interfaces on. Type: dictionary
169 | | ... | - int_in - Inside interface key. Type: string
170 | | ... | - int_out - Outside interface key. Type: string
171 | |
172 | | ... | *Example:*
173 | |
174 | | ... | \| Configure DET44 interfaces \| ${nodes['DUT1']} \| port5 \| port6 \|
175 | |
176 | | [Arguments] | ${node} | ${int_in} | ${int_out}
177 | |
178 | | Set DET44 Interface | ${dut1} | ${int_in} | is_inside=${True}
179 | | Set DET44 Interface | ${dut1} | ${int_out} | is_inside=${False}
180
181 | Configure deterministic mode for NAT44
182 | | [Documentation] | Set deterministic behaviour of NAT44 (DET44).
183 | |
184 | | ... | *Arguments:*
185 | | ... | - node - DUT node to set deterministic mode for NAT44 on.
186 | | ... | Type: dictionary
187 | | ... | - ip_in - Inside IP. Type: string
188 | | ... | - subnet_in - Inside IP subnet. Type: string
189 | | ... | - ip_out - Outside IP. Type: string
190 | | ... | - subnet_out - Outside IP subnet. Type: string
191 | |
192 | | ... | *Example:*
193 | |
194 | | ... | \| Configure deterministic mode for NAT44 \| ${nodes['DUT1']} \
195 | | ... | \| 100.0.0.0 \| 12 \| 12.1.1.0 \| 24 \|
196 | |
197 | | [Arguments] | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
198 | |
199 | | Set DET44 Mapping
200 | | ... | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
201
202 | Initialize NAT44 deterministic mode in circular topology
203 | | [Documentation] | Initialization of NAT44 deterministic mode (DET44)
204 | | ... | on DUT1 node.
205 | |
206 | | Enable DET44 plugin on DUT | ${dut1}
207 | | Configure DET44 interfaces
208 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
209 | | Configure deterministic mode for NAT44
210 | | ... | ${dut1} | ${in_net} | ${in_mask} | ${out_net} | ${out_mask}
211
212 | Show DET44 verbose
213 | | [Documentation] | Get DET44 settings on the node.
214 | |
215 | | ... | *Arguments:*
216 | | ... | - node - DUT node to show NAT. Type: dictionary
217 | |
218 | | ... | *Example:*
219 | |
220 | | ... | \| Show DET44 verbose \| ${nodes['DUT1']} \|
221 | |
222 | | [Arguments] | ${node}
223 | |
224 | | Show DET44 | ${node}
225
226 | Verify DET44 sessions number on DUT1 node
227 | | [Documentation] | Verify that all required DET44 sessions are established on
228 | | ... | DUT1 node.
229 | |
230 | | Verify DET44 sessions number | ${nodes['DUT1']} | ${n_sessions}
231
232 | Verify DET44 sessions number
233 | | [Documentation] | Verify that all required DET44 sessions are established.
234 | |
235 | | ... | *Arguments:*
236 | | ... | - node - DUT node. Type: dictionary
237 | | ... | - exp_n_sessions - Expected number of DET44 sessions. Type: integer
238 | |
239 | | ... | *Example:*
240 | |
241 | | ... | \| Verify DET44 sessions number \| ${nodes['DUT1']} \| ${64512} \|
242 | |
243 | | [Arguments] | ${node} | ${exp_n_sessions}
244 | |
245 | | ${det44_sessions}= | Get DET44 Sessions Number | ${node}
246 | | Should Be Equal As Integers | ${det44_sessions} | ${exp_n_sessions}
247 | | ... | Not all DET44 sessions have been established