NAT44 EI tests
[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 | Configure deterministic mode for NAT44
41 | | [Documentation] | Set deterministic behaviour of NAT44.
42 | |
43 | | ... | *Arguments:*
44 | | ... | - node - DUT node to set deterministic mode for NAT44 on.
45 | | ... | Type: dictionary
46 | | ... | - ip_in - Inside IP. Type: string
47 | | ... | - subnet_in - Inside IP subnet. Type: string
48 | | ... | - ip_out - Outside IP. Type: string
49 | | ... | - subnet_out - Outside IP subnet. Type: string
50 | |
51 | | ... | *Example:*
52 | |
53 | | ... | \| Configure deterministic mode for NAT44 \| ${nodes['DUT1']} \
54 | | ... | \| 100.0.0.0 \| 12 \| 12.1.1.0 \| 24 \|
55 | |
56 | | [Arguments] | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
57 | |
58 | | Set NAT44 deterministic | ${node} | ${ip_in} | ${subnet_in} | ${ip_out}
59 | | ... | ${subnet_out}
60
61 | Show NAT verbose
62 | | [Documentation] | Get the NAT settings on the node.
63 | |
64 | | ... | *Arguments:*
65 | | ... | - node - DUT node to show NAT. Type: dictionary
66 | |
67 | | ... | *Example:*
68 | |
69 | | ... | \| Show NAT verbose \| ${nodes['DUT1']} \|
70 | |
71 | | [Arguments] | ${node}
72 | |
73 | | Show NAT | ${node}
74
75 | Initialize NAT44 in circular topology
76 | | [Documentation] | Initialization of 2-node / 3-node topology with NAT44
77 | | ... | between DUTs:
78 | | ... | - set interfaces up
79 | | ... | - set IP addresses
80 | | ... | - set ARP
81 | | ... | - create routes
82 | | ... | - set NAT44 - only on DUT1
83 | |
84 | | ${dut2_status} | ${value}= | Run Keyword And Ignore Error
85 | | ... | Variable Should Exist | ${dut2}
86 | |
87 | | Set interfaces in path up
88 | |
89 | | ${tg_if1_ip4}= | Get Variable Value | ${tg_if1_ip4} | 10.0.0.2
90 | | ${tg_if1_mask}= | Get Variable Value | ${tg_if1_mask} | 20
91 | | ${tg_if2_ip4}= | Get Variable Value | ${tg_if2_ip4} | 12.0.0.2
92 | | ${tg_if2_mask}= | Get Variable Value | ${tg_if2_mask} | 20
93 | | ${dut1_if1_ip4}= | Get Variable Value | ${dut1_if1_ip4} | 10.0.0.1
94 | | ${dut1_if1_mask}= | Get Variable Value | ${dut1_if1_mask} | 20
95 | | ${dut1_if2_ip4}= | Get Variable Value | ${dut1_if2_ip4} | 11.0.0.1
96 | | ${dut1_if2_mask}= | Get Variable Value | ${dut2_if2_mask} | 20
97 | | ${dut2_if1_ip4}= | Get Variable Value | ${dut2_if1_ip4} | 11.0.0.2
98 | | ${dut2_if1_mask}= | Get Variable Value | ${dut2_if1_mask} | 20
99 | | ${dut2_if2_ip4}= | Get Variable Value | ${dut2_if2_ip4} | 12.0.0.1
100 | | ${dut2_if2_mask}= | Get Variable Value | ${dut2_if2_mask} | 20
101 | | ${inside_net}= | Get Variable Value | ${inside_net} | 192.168.0.0
102 | | ${inside_mask}= | Get Variable Value | ${inside_mask} | 16
103 | | ${nat_net}= | Get Variable Value | ${nat_net} | 109.146.163.128
104 | | ${nat_mask}= | Get Variable Value | ${nat_mask} | 26
105 | | ${dest_net}= | Get Variable Value | ${dest_net} | 20.0.0.0
106 | | ${dest_mask}= | Get Variable Value | ${dest_mask} | 24
107 | |
108 | | VPP Interface Set IP Address | ${dut1} | ${DUT1_${int}1}[0]
109 | | ... | ${dut1_if1_ip4} | ${dut1_if1_mask}
110 | | Run Keyword If | '${dut2_status}' == 'PASS'
111 | | ... | VPP Interface Set IP Address | ${dut1} | ${DUT1_${int}2}[0]
112 | | ... | ${dut1_if2_ip4} | ${dut1_if2_mask}
113 | | Run Keyword If | '${dut2_status}' == 'PASS'
114 | | ... | VPP Interface Set IP Address | ${dut2} | ${DUT2_${int}1}[0]
115 | | ... | ${dut2_if1_ip4} | ${dut2_if1_mask}
116 | | ${dut}= | Run Keyword If | '${dut2_status}' == 'PASS'
117 | | ... | Set Variable | ${dut2}
118 | | ... | ELSE | Set Variable | ${dut1}
119 | | ${dut_if2}= | Run Keyword If | '${dut2_status}' == 'PASS'
120 | | ... | Set Variable | ${DUT2_${int}2}[0]
121 | | ... | ELSE | Set Variable | ${DUT1_${int}2}[0]
122 | | VPP Interface Set IP Address | ${dut} | ${dut_if2} | ${dut2_if2_ip4}
123 | | ... | ${dut2_if2_mask}
124 | |
125 | | VPP Add IP Neighbor
126 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip4} | ${TG_pf1_mac}[0]
127 | | Run Keyword If | '${dut2_status}' == 'PASS'
128 | | ... | VPP Add IP Neighbor
129 | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip4}
130 | | ... | ${DUT2_${int}1_mac}[0]
131 | | Run Keyword If | '${dut2_status}' == 'PASS'
132 | | ... | VPP Add IP Neighbor
133 | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut1_if2_ip4}
134 | | ... | ${DUT1_${int}2_mac}[0]
135 | | VPP Add IP Neighbor
136 | | ... | ${dut} | ${dut_if2} | ${tg_if2_ip4} | ${TG_pf2_mac}[0]
137 | |
138 | | Vpp Route Add | ${dut1} | ${inside_net} | ${inside_mask}
139 | | ... | gateway=${tg_if1_ip4} | interface=${DUT1_${int}1}[0]
140 | | Run Keyword If | '${dut2_status}' == 'PASS'
141 | | ... | Vpp Route Add | ${dut1} | ${dest_net} | ${dest_mask}
142 | | ... | gateway=${dut2_if1_ip4} | interface=${DUT1_${int}2}[0]
143 | | Run Keyword Unless | '${dut2_status}' == 'PASS'
144 | | ... | Vpp Route Add | ${dut1} | ${dest_net} | ${dest_mask}
145 | | ... | gateway=${tg_if2_ip4} | interface=${DUT1_${int}2}[0]
146 | | Run Keyword If | '${dut2_status}' == 'PASS'
147 | | ... | Vpp Route Add | ${dut2} | ${dest_net} | ${dest_mask}
148 | | ... | gateway=${tg_if2_ip4} | interface=${DUT2_${int}2}[0]
149 | | Run Keyword If | '${dut2_status}' == 'PASS'
150 | | ... | Vpp Route Add | ${dut2} | ${nat_net} | ${nat_mask}
151 | | ... | gateway=${dut1_if2_ip4} | interface=${DUT2_${int}1}[0]
152 | |
153 | | Configure inside and outside interfaces
154 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
155 | | Configure deterministic mode for NAT44
156 | | ... | ${dut1} | ${inside_net} | ${inside_mask} | ${nat_net} | ${nat_mask}
157