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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 | Library | resources.libraries.python.NATUtil
17 | Documentation | Keywords for NAT feature in VPP.
20 | Configure inside and outside interfaces
21 | | [Documentation] | Configure inside and outside interfaces for NAT44.
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
30 | | ... | \| Configure inside and outside interfaces \| ${nodes['DUT1']} \
31 | | ... | \| FortyGigabitEtherneta/0/0 \| FortyGigabitEtherneta/0/1 \|
33 | | [Arguments] | ${node} | ${int_in} | ${int_out}
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}
40 | Initialize NAT44 endpoint-dependent mode in circular topology
41 | | [Documentation] | Initialization of NAT44 endpoint-dependent mode on DUT1
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}
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
52 | | ... | Set IPv4 forwarding for NAT44:
53 | | ... | - set interfaces up
54 | | ... | - set IP addresses
56 | | ... | - create routes
58 | | ${status} | ${value}= | Run Keyword And Ignore Error
59 | | ... | Variable Should Exist | ${dut2}
60 | | ${dut2_status}= | Set Variable If | '${status}' == 'PASS' | ${True}
63 | | Set interfaces in path up
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}
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]
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]
111 | Verify NAT44 TCP sessions number on DUT1 node
112 | | [Documentation] | Verify that all required NAT44 TCP sessions are
113 | | ... | established on DUT1 node.
115 | | Verify NAT44 sessions number | ${nodes['DUT1']} | ${n_sessions} | TCP
117 | Verify NAT44 UDP sessions number on DUT1 node
118 | | [Documentation] | Verify that all required NAT44 UDP sessions are
119 | | ... | established on DUT1 node.
121 | | Verify NAT44 sessions number | ${nodes['DUT1']} | ${n_sessions} | UDP
123 | Verify NAT44 sessions number
124 | | [Documentation] | Verify that all required NAT44 sessions of required
125 | | ... | protocol are established.
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
134 | | ... | \| Verify NAT44 sessions number \| ${nodes['DUT1']} \| ${64512} \
137 | | [Arguments] | ${node} | ${exp_n_sessions} | ${proto}
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
143 # DET44 - NAT44 deterministic
144 | Enable DET44 plugin on DUT
145 | | [Documentation] | Enable DET44 plugin on DUT.
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
157 | | ... | \| Enable DET44 plugin on all DUTs \|
159 | | [Arguments] | ${node} | ${inside_vrf}=${0} | ${outside_vrf}=${0}
161 | | Enable DET44 Plugin
162 | | ... | ${node} | inside_vrf=${inside_vrf} | outside_vrf=${outside_vrf}
164 | Configure DET44 interfaces
165 | | [Documentation] | Configure inside and outside interfaces for DET44.
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
174 | | ... | \| Configure DET44 interfaces \| ${nodes['DUT1']} \| port5 \| port6 \|
176 | | [Arguments] | ${node} | ${int_in} | ${int_out}
178 | | Set DET44 Interface | ${dut1} | ${int_in} | is_inside=${True}
179 | | Set DET44 Interface | ${dut1} | ${int_out} | is_inside=${False}
181 | Configure deterministic mode for NAT44
182 | | [Documentation] | Set deterministic behaviour of NAT44 (DET44).
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
194 | | ... | \| Configure deterministic mode for NAT44 \| ${nodes['DUT1']} \
195 | | ... | \| 100.0.0.0 \| 12 \| 12.1.1.0 \| 24 \|
197 | | [Arguments] | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
199 | | Set DET44 Mapping
200 | | ... | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
202 | Initialize NAT44 deterministic mode in circular topology
203 | | [Documentation] | Initialization of NAT44 deterministic mode (DET44)
204 | | ... | on DUT1 node.
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}
213 | | [Documentation] | Get DET44 settings on the node.
215 | | ... | *Arguments:*
216 | | ... | - node - DUT node to show NAT. Type: dictionary
220 | | ... | \| Show DET44 verbose \| ${nodes['DUT1']} \|
222 | | [Arguments] | ${node}
224 | | Show DET44 | ${node}
226 | Verify DET44 sessions number on DUT1 node
227 | | [Documentation] | Verify that all required DET44 sessions are established on
230 | | Verify DET44 sessions number | ${nodes['DUT1']} | ${n_sessions}
232 | Verify DET44 sessions number
233 | | [Documentation] | Verify that all required DET44 sessions are established.
235 | | ... | *Arguments:*
236 | | ... | - node - DUT node. Type: dictionary
237 | | ... | - exp_n_sessions - Expected number of DET44 sessions. Type: integer
241 | | ... | \| Verify DET44 sessions number \| ${nodes['DUT1']} \| ${64512} \|
243 | | [Arguments] | ${node} | ${exp_n_sessions}
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