test: nat44det - add session number check
[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 # DET44 - NAT44 deterministic
112 | Enable DET44 plugin on DUT
113 | | [Documentation] | Enable DET44 plugin on DUT.
114 | |
115 | | ... | *Arguments:*
116 | | ... | - node - DUT node to enablr DET44 on.
117 | | ... | Type: dictionary
118 | | ... | - inside_vrf - Inside VRF ID; default value: 0.
119 | | ... | Type: string or integer
120 | | ... | - outside_vrf - Outside VRF ID; default value: 0.
121 | | ... | Type: string or integer
122 | |
123 | | ... | *Example:*
124 | |
125 | | ... | \| Enable DET44 plugin on all DUTs \|
126 | |
127 | | [Arguments] | ${node} | ${inside_vrf}=${0} | ${outside_vrf}=${0}
128 | |
129 | | Enable DET44 Plugin
130 | | ... | ${node} | inside_vrf=${inside_vrf} | outside_vrf=${outside_vrf}
131
132 | Configure DET44 interfaces
133 | | [Documentation] | Configure inside and outside interfaces for DET44.
134 | |
135 | | ... | *Arguments:*
136 | | ... | - node - DUT node to set DET44 interfaces on. Type: dictionary
137 | | ... | - int_in - Inside interface key. Type: string
138 | | ... | - int_out - Outside interface key. Type: string
139 | |
140 | | ... | *Example:*
141 | |
142 | | ... | \| Configure DET44 interfaces \| ${nodes['DUT1']} \| port5 \| port6 \|
143 | |
144 | | [Arguments] | ${node} | ${int_in} | ${int_out}
145 | |
146 | | Set DET44 Interface | ${dut1} | ${int_in} | is_inside=${True}
147 | | Set DET44 Interface | ${dut1} | ${int_out} | is_inside=${False}
148
149 | Configure deterministic mode for NAT44
150 | | [Documentation] | Set deterministic behaviour of NAT44 (DET44).
151 | |
152 | | ... | *Arguments:*
153 | | ... | - node - DUT node to set deterministic mode for NAT44 on.
154 | | ... | Type: dictionary
155 | | ... | - ip_in - Inside IP. Type: string
156 | | ... | - subnet_in - Inside IP subnet. Type: string
157 | | ... | - ip_out - Outside IP. Type: string
158 | | ... | - subnet_out - Outside IP subnet. Type: string
159 | |
160 | | ... | *Example:*
161 | |
162 | | ... | \| Configure deterministic mode for NAT44 \| ${nodes['DUT1']} \
163 | | ... | \| 100.0.0.0 \| 12 \| 12.1.1.0 \| 24 \|
164 | |
165 | | [Arguments] | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
166 | |
167 | | Set DET44 Mapping
168 | | ... | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
169
170 | Initialize NAT44 deterministic mode in circular topology
171 | | [Documentation] | Initialization of NAT44 deterministic mode (DET44)
172 | | ... | on DUT1.
173 | |
174 | | Enable DET44 plugin on DUT | ${dut1}
175 | | Configure DET44 interfaces
176 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
177 | | Configure deterministic mode for NAT44
178 | | ... | ${dut1} | ${in_net} | ${in_mask} | ${out_net} | ${out_mask}
179
180 | Show DET44 verbose
181 | | [Documentation] | Get DET44 settings on the node.
182 | |
183 | | ... | *Arguments:*
184 | | ... | - node - DUT node to show NAT. Type: dictionary
185 | |
186 | | ... | *Example:*
187 | |
188 | | ... | \| Show DET44 verbose \| ${nodes['DUT1']} \|
189 | |
190 | | [Arguments] | ${node}
191 | |
192 | | Show DET44 | ${node}
193
194 | Verify DET44 sessions number
195 | | [Documentation] | Verify that all required DET44 sessions are established.
196 | |
197 | | ... | *Arguments:*
198 | | ... | - node - DUT node. Type: dictionary
199 | | ... | - exp_n_sessions - Expected number of DET44 sessions. Type: integer
200 | |
201 | | ... | *Example:*
202 | |
203 | | ... | \| Verify DET44 sessions number \| ${nodes['DUT1']} \| ${64512} \|
204 | |
205 | | [Arguments] | ${node} | ${exp_n_sessions}
206 | |
207 | | ${det44_sessions}= | Get DET44 Sessions Number | ${node}
208 | | Should Be Equal As Integers | ${det44_sessions} | ${exp_n_sessions}
209 | | ... | Not all DET44 sessions have been established