Improve pf layer
[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 | ${node['interfaces']['${int_out}']['name']}
37 | | Set NAT44 Interfaces | ${node} | ${int_in_name} | ${int_out_name}
38
39 | Configure deterministic mode for NAT44
40 | | [Documentation] | Set deterministic behaviour of NAT44.
41 | |
42 | | ... | *Arguments:*
43 | | ... | - node - DUT node to set deterministic mode for NAT44 on.
44 | | ... | Type: dictionary
45 | | ... | - ip_in - Inside IP. Type: string
46 | | ... | - subnet_in - Inside IP subnet. Type: string
47 | | ... | - ip_out - Outside IP. Type: string
48 | | ... | - subnet_out - Outside IP subnet. Type: string
49 | |
50 | | ... | *Example:*
51 | |
52 | | ... | \| Configure deterministic mode for NAT44 \| ${nodes['DUT1']} \
53 | | ... | \| 100.0.0.0 \| 12 \| 12.1.1.0 \| 24 \|
54 | |
55 | | [Arguments] | ${node} | ${ip_in} | ${subnet_in} | ${ip_out} | ${subnet_out}
56 | |
57 | | Set NAT44 deterministic | ${node} | ${ip_in} | ${subnet_in} | ${ip_out}
58 | | ... | ${subnet_out}
59
60 | Show NAT verbose
61 | | [Documentation] | Get the NAT settings on the node.
62 | |
63 | | ... | *Arguments:*
64 | | ... | - node - DUT node to show NAT. Type: dictionary
65 | |
66 | | ... | *Example:*
67 | |
68 | | ... | \| Show NAT verbose \| ${nodes['DUT1']} \|
69 | |
70 | | [Arguments] | ${node}
71 | |
72 | | Show NAT | ${node}
73
74 | Initialize NAT44 in circular topology
75 | | [Documentation] | Initialization of 2-node / 3-node topology with NAT44
76 | | ... | between DUTs:
77 | | ... | - set interfaces up
78 | | ... | - set IP addresses
79 | | ... | - set ARP
80 | | ... | - create routes
81 | | ... | - set NAT44 - only on DUT1
82 | |
83 | | ${dut2_status} | ${value}= | Run Keyword And Ignore Error
84 | | ... | Variable Should Exist | ${dut2}
85 | |
86 | | Set interfaces in path up
87 | |
88 | | VPP Interface Set IP Address | ${dut1} | ${DUT1_${int}1}[0] | 10.0.0.1 | 20
89 | | Run Keyword If | '${dut2_status}' == 'PASS'
90 | | ... | VPP Interface Set IP Address | ${dut1} | ${DUT1_${int}2}[0]
91 | | ... | 11.0.0.1 | 20
92 | | Run Keyword If | '${dut2_status}' == 'PASS'
93 | | ... | VPP Interface Set IP Address | ${dut2} | ${DUT2_${int}1}[0]
94 | | ... | 11.0.0.2 | 20
95 | | ${dut}= | Run Keyword If | '${dut2_status}' == 'PASS'
96 | | ... | Set Variable | ${dut2}
97 | | ... | ELSE | Set Variable | ${dut1}
98 | | ${dut_if2}= | Run Keyword If | '${dut2_status}' == 'PASS'
99 | | ... | Set Variable | ${DUT2_${int}1}[0]
100 | | ... | ELSE | Set Variable | ${DUT1_${int}2}[0]
101 | | VPP Interface Set IP Address | ${dut} | ${dut_if2} | 12.0.0.1 | 20
102 | |
103 | | VPP Add IP Neighbor
104 | | ... | ${dut1} | ${DUT1_${int}1}[0] | 10.0.0.2 | ${TG_pf1_mac}[0]
105 | | Run Keyword If | '${dut2_status}' == 'PASS'
106 | | ... | VPP Add IP Neighbor
107 | | ... | ${dut1} | ${DUT1_${int}2}[0] | 11.0.0.2 | ${DUT2_${int}1_mac}[0]
108 | | Run Keyword If | '${dut2_status}' == 'PASS'
109 | | ... | VPP Add IP Neighbor
110 | | ... | ${dut2} | ${DUT2_${int}1}[0] | 11.0.0.1 | ${DUT1_${int}2_mac}[0]
111 | | VPP Add IP Neighbor
112 | | ... | ${dut} | ${dut_if2} | 12.0.0.2 | ${TG_pf2_mac}[0]
113 | |
114 | | Vpp Route Add | ${dut1} | 20.0.0.0 | 18 | gateway=10.0.0.2
115 | | ... | interface=${DUT1_${int}1}[0]
116 | | Run Keyword If | '${dut2_status}' == 'PASS'
117 | | ... | Vpp Route Add | ${dut1} | 12.0.0.2 | 32 | gateway=11.0.0.2
118 | | ... | interface=${DUT1_${int}2}[0]
119 | | Run Keyword If | '${dut2_status}' == 'PASS'
120 | | ... | Vpp Route Add | ${dut2} | 12.0.0.0 | 24 | gateway=12.0.0.2
121 | | ... | interface=${DUT2_${int}2}[0]
122 | | Run Keyword If | '${dut2_status}' == 'PASS'
123 | | ... | Vpp Route Add | ${dut2} | 200.0.0.0 | 30 | gateway=11.0.0.1
124 | | ... | interface=${DUT2_${int}1}[0]
125 | |
126 | | Configure inside and outside interfaces
127 | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${DUT1_${int}2}[0]
128 | | Configure deterministic mode for NAT44
129 | | ... | ${dut1} | 20.0.0.0 | 18 | 200.0.0.0 | 30