blob: 5557d60f21a3dd8f9e0fcf4ff4dfa017eee21903 [file] [log] [blame]
Sreeju Sreedhare3fefd92019-04-02 15:57:15 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17"""
18Nat Test
19
20Test each flow table can set entry, and packet rx correctly.
21"""
22
23import logging
24
25from oftest import config
26import oftest.base_tests as base_tests
27import ofp
28from oftest.testutils import *
29from accton_util import *
30
31class dnat(base_tests.SimpleDataPlane):
32 """
33 [DNAT]
34 DNAT (inbound)
35
36 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000
37 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.1, DIP 10.0.0.01, Sport 2828, Dport 2000
38
39 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
40 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
41 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x23000001 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:01:00,set_field=eth_dst=00:00:00:00:01:01,set_field=vlan_vid=100,group=0x640001
42 ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=200/0xfff,eth_dst=00:00:00:00:02:00,eth_type=0x0800 goto:28
43 ./dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x23000001 goto:60
44 """
45 def runTest(self):
46 delete_all_flows(self.controller)
47 delete_all_groups(self.controller)
48
49 test_ports = sorted(config["port_map"].keys())
50
51 input_port = test_ports[0]
52 output_port = test_ports[1]
53
54 add_one_vlan_table_flow(self.controller, input_port, vlan_id=200, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False)
55 add_termination_flow(self.controller, input_port, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
56
57 add_one_l2_interface_group(self.controller, port=output_port, vlan_id=100, is_tagged=True, send_barrier=False)
58 msg1=add_l3_unicast_group(self.controller, port=output_port, vlanid=100, id=0x3000001, src_mac=[0x00,0x00,0x00,0x00,0x01,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x01,0x01])
59 add_dnat_flow(self.controller, eth_type=0x0800, ip_dst=0x64000001, ip_proto=6, tcp_dst=5000, set_ip_dst=0x0a000001, set_tcp_dst=2000, action_group_id=msg1.group_id)
60
61 input_pkt = simple_tcp_packet(pktlen=100,
62 eth_dst="00:00:00:00:02:00",
63 eth_src="00:00:00:00:02:01",
64 dl_vlan_enable = True,
65 vlan_vid = 200,
66 ip_ttl=64,
67 ip_src="200.0.0.1",
68 ip_dst='100.0.0.1',
69 tcp_dport=5000)
70 output_pkt = simple_tcp_packet(pktlen=100,
71 eth_dst="00:00:00:00:01:01",
72 eth_src="00:00:00:00:01:00",
73 dl_vlan_enable = True,
74 vlan_vid = 100,
75 ip_ttl=63,
76 ip_src="200.0.0.1",
77 ip_dst='10.0.0.1',
78 tcp_dport=2000)
79
80 self.dataplane.send(input_port, str(input_pkt))
81 verify_packet(self, str(output_pkt), output_port)
82
83
84
85class dnatEcmp(base_tests.SimpleDataPlane):
86 """
87 [DNAT ECMP]
88 DNAT (inbound) with ECMP
89
90 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000 [increase SIP]
91 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
92 Output eth 1/5 DA000005224466, SA000005223355, Tag 2, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
93
94 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
95 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
96 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x23000001 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:01:00,set_field=eth_dst=00:00:00:00:01:01,set_field=vlan_vid=100,group=0x640001
97 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x20005 group=any,port=any,weight=0 output=5
98 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x23000005 group=any,port=any,weight=0 set_field=eth_src=00:00:05:22:33:55,set_field=eth_dst=00:00:05:22:44:66,set_field=vlan_vid=2,group=0x20005
99 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=sel,group=0x71000001 group=any,port=any,weight=0 group=0x23000001 group=any,port=any,weight=0 group=0x23000005
100 ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=200/0xfff,eth_dst=00:00:00:00:02:00,eth_type=0x0800 goto:28
101
102 ./dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x71000001 goto:60
103 """
104 def runTest(self):
105 delete_all_flows(self.controller)
106 delete_all_groups(self.controller)
107
108 test_ports = config["port_map"].keys()
109 input_port = test_ports[0]
110 output_port = test_ports[1]
111 output_port2 = test_ports[2]
112
113 add_one_vlan_table_flow(self.controller, input_port, vlan_id=200, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
114 add_one_l2_interface_group(self.controller, port=output_port, vlan_id=100, is_tagged=True, send_barrier=False)
115 #Bits 27:24 is for realm id, so unicast group id give 0x3000001
116 msg1=add_l3_unicast_group(self.controller, port=output_port, vlanid=100, id=0x3000001, src_mac=[0x00,0x00,0x00,0x00,0x01,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x01,0x01])
117 add_one_l2_interface_group(self.controller, port=output_port2, vlan_id=2, is_tagged=True, send_barrier=False)
118 #Bits 27:24 is for realm id, so unicast group id give 0x3000005
119 msg2=add_l3_unicast_group(self.controller, port=output_port2, vlanid=2, id=0x3000005, src_mac=[0x00,0x00,0x05,0x22,0x33,0x55], dst_mac=[0x00,0x00,0x05,0x22,0x44,0x66])
120 ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
121 add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
122 add_dnat_flow(self.controller, eth_type=0x0800, ip_dst=0x64000001, ip_proto=6, tcp_dst=5000, set_ip_dst=0x0a000001, set_tcp_dst=2000, action_group_id=ecmp.group_id)
123
124
125 input_pkt = simple_tcp_packet(pktlen=100,
126 eth_dst="00:00:00:00:02:00",
127 eth_src="00:00:00:00:02:01",
128 dl_vlan_enable = True,
129 vlan_vid = 200,
130 ip_ttl=64,
131 ip_src="200.0.0.1",
132 ip_dst='100.0.0.1',
133 tcp_dport=5000)
134 output_pkt = simple_tcp_packet(pktlen=100,
135 eth_dst="00:00:00:00:01:01",
136 eth_src="00:00:00:00:01:00",
137 dl_vlan_enable = True,
138 vlan_vid = 100,
139 ip_ttl=63,
140 ip_src="200.0.0.1",
141 ip_dst='10.0.0.1',
142 tcp_dport=2000)
143 output_pkt2 = simple_tcp_packet(pktlen=100,
144 eth_dst="00:00:05:22:44:66",
145 eth_src="00:00:05:22:33:55",
146 dl_vlan_enable = True,
147 vlan_vid = 2,
148 ip_ttl=63,
149 ip_src="200.0.0.1",
150 ip_dst='10.0.0.1',
151 tcp_dport=2000)
152
153 self.dataplane.send(input_port, str(input_pkt))
154 verify_packet(self, str(output_pkt2), output_port2)
155 #self.dataplane.send(input_port, str(input_pkt))
156 #verify_packet(self, str(output_pkt2), output_port2)
157
158class snat_ecmp(base_tests.SimpleDataPlane):
159 """
160 [SNAT ECMP]
161 SNAT (outbound) with ECMP
162
163 Inject eth 1/1 DA000000000100, SA000000000101, Tag 100, SIP 10.0.0.1, DIP 200.0.0.01, Sport 2000, Dport 2828 [increase DIP]
164 Output eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
165 Output eth 1/5 DA000000000500, SA000000000501, Tag 5, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
166
167 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20
168 ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=100/0xfff,eth_dst=00:00:00:00:01:00,eth_type=0x0800 goto:29
169 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0xC80003 group=any,port=any,weight=0 output=3
170 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x22000002 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:02:00,set_field=eth_dst=00:00:00:00:02:01,set_field=vlan_vid=200,group=0xC80003
171 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x50005 group=any,port=any,weight=0 output=5
172 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x22000005 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:05:00,set_field=eth_dst=00:00:00:00:05:01,set_field=vlan_vid=5,group=0x50005
173
174 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=sel,group=0x71000001 group=any,port=any,weight=0 group=0x22000002 group=any,port=any,weight=0 group=0x22000005
175 ./dpctl tcp:192.168.1.1:6633 flow-mod table=29,cmd=add,prio=291 eth_type=0x800,ip_src=10.0.0.1,ip_proto=6,tcp_src=2000 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30
176 ./dpctl tcp:192.168.1.1:6633 flow-mod table=30,cmd=add,prio=301 eth_type=0x0800,ip_dst=200.0.0.1/255.255.255.0 write:group=0x71000001 goto:60
177 """
178 def runTest(self):
179 delete_all_flows(self.controller)
180 delete_all_groups(self.controller)
181
182 test_ports = sorted(config["port_map"].keys())
183
184 input_port = test_ports[0]
185 output_port = test_ports[1]
186 output_port2 = test_ports[2]
187
188 add_one_vlan_table_flow(self.controller, input_port, vlan_id=100, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
189 add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x01,0x00], 100, goto_table=29, send_barrier=False)
190 add_one_l2_interface_group(self.controller, port=output_port, vlan_id=200, is_tagged=True, send_barrier=False)
191 #Bits 27:24 is for realm id, so unicast group id give 0x2000002
192 msg1=add_l3_unicast_group(self.controller, port=output_port, vlanid=200, id=0x2000002, src_mac=[0x00,0x00,0x00,0x00,0x02,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x02,0x01])
193
194 add_one_l2_interface_group(self.controller, port=output_port2, vlan_id=5, is_tagged=True, send_barrier=False)
195 #Bits 27:24 is for realm id, so unicast group id give 0x2000002
196 msg2=add_l3_unicast_group(self.controller, port=output_port2, vlanid=5, id=0x2000005, src_mac=[0x00,0x00,0x00,0x00,0x05,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x05,0x01])
197
198 ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
199 add_snat_flow(self.controller, 0x0800, 0x0a000001, 6, 2000, 0x64000001, 5000)
200 add_unicast_routing_flow(self.controller, 0x0800, 0xc8000001, 0xffffff00, ecmp.group_id, vrf=0, send_barrier=False)
201
202 input_pkt = simple_tcp_packet(pktlen=100,
203 eth_dst="00:00:00:00:01:00",
204 eth_src="00:00:00:00:01:01",
205 dl_vlan_enable = True,
206 vlan_vid = 100,
207 ip_ttl=64,
208 ip_src='10.0.0.1',
209 ip_dst="200.0.0.1",
210 tcp_sport=2000)
211 output_pkt = simple_tcp_packet(pktlen=100,
212 eth_dst="00:00:00:00:02:01",
213 eth_src="00:00:00:00:02:00",
214 dl_vlan_enable = True,
215 vlan_vid = 200,
216 ip_ttl=63,
217 ip_src="100.0.0.1",
218 ip_dst='200.0.0.1',
219 tcp_sport=5000)
220 output_pkt2 = simple_tcp_packet(pktlen=100,
221 eth_dst="00:00:00:00:05:01",
222 eth_src="00:00:00:00:05:00",
223 dl_vlan_enable = True,
224 vlan_vid = 5,
225 ip_ttl=63,
226 ip_src="100.0.0.1",
227 ip_dst='200.0.0.1',
228 tcp_sport=5000)
229
230 self.dataplane.send(input_port, str(input_pkt))
231 verify_packet(self, str(output_pkt), output_port)
232 #self.dataplane.send(input_port, str(input_pkt))
233 #verify_packet(self, str(output_pkt2), output_port2)
234
235"""just for verify it can work after nat ecmp"""
236class l3Route(base_tests.SimpleDataPlane):
237 """
238 [L3 unicast route]
239 Do unicast route and output to specified port
240
241 Inject eth 1/3 Tag2, SA000000112233, DA7072cf7cf3a3, SIP 192.168.1.100, DIP 192.168.2.2
242 Output eth 1/1 Tag3, SA 000004223355, DA 000004224466
243
244 ./dpctl tcp:192.168.1.1:6633 flow-mod table=0,cmd=add,prio=1 in_port=0/0xffff0000 goto:10
245 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x1002/0x1fff goto:20
246 ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 in_port=3,vlan_vid=2/0xfff,eth_dst=70:72:cf:7c:f3:a3,eth_type=0x0800 goto:30
247 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x30001 group=any,port=any,weight=0 output=1
248 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x20000003 group=any,port=any,weight=0 set_field=eth_src=00:00:04:22:33:55,set_field=eth_dst=00:00:04:22:44:66,set_field=vlan_vid=3,group=0x30001
249 ./dpctl tcp:192.168.1.1:6633 flow-mod table=30,cmd=add,prio=301 eth_type=0x0800,ip_dst=192.168.2.2/255.255.255.0 write:group=0x20000003 goto:60
250 """
251 def runTest(self):
252 delete_all_flows(self.controller)
253 delete_all_groups(self.controller)
254
255 test_ports = sorted(config["port_map"].keys())
256
257 input_port = test_ports[0]
258 output_port = test_ports[1]
259
260 add_port_table_flow(self.controller, is_overlay=False)
261 add_one_vlan_table_flow(self.controller, input_port, vlan_id=2, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
262 add_termination_flow(self.controller, input_port, 0x0800, [0x70, 0x72, 0xcf, 0x7c, 0xf3, 0xa3], 2, send_barrier=False)
263 add_one_l2_interface_group(self.controller, port=output_port, vlan_id=3, is_tagged=True, send_barrier=False)
264 msg=add_l3_unicast_group(self.controller, port=output_port, vlanid=3, id=3, src_mac=[0x00,0x00,0x04,0x22,0x33,0x55], dst_mac=[0x00,0x00,0x04,0x22,0x44,0x66])
265 add_unicast_routing_flow(self.controller, 0x0800, 0xc0a80202, 0xffffff00, msg.group_id)
266
267 #verify tx/rx packet
268 input_pkt = simple_tcp_packet(pktlen=100,
269 eth_dst="70:72:cf:7c:f3:a3",
270 eth_src="00:00:00:00:02:01",
271 dl_vlan_enable = True,
272 vlan_vid = 2,
273 ip_ttl=64,
274 ip_src="200.0.0.1",
275 ip_dst='192.168.2.2')
276 output_pkt = simple_tcp_packet(pktlen=100,
277 eth_dst="00:00:04:22:44:66",
278 eth_src="00:00:04:22:33:55",
279 dl_vlan_enable = True,
280 vlan_vid = 3,
281 ip_ttl=63,
282 ip_src="200.0.0.1",
283 ip_dst='192.168.2.2')
284
285 self.dataplane.send(input_port, str(input_pkt))
286 verify_packet(self, str(output_pkt), output_port)
287
288
289
290
291
292
293