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