blob: 7141e8ad99b5854da51d7c4906696362e9f97577 [file] [log] [blame]
macauley_chengb75de692015-11-09 13:50:32 +08001"""
2Nat Test
3
4Test each flow table can set entry, and packet rx correctly.
5"""
6
7import logging
8
9from oftest import config
10import oftest.base_tests as base_tests
11import ofp
12from oftest.testutils import *
13from accton_util import *
14
15class dnat(base_tests.SimpleDataPlane):
16 """
17 [DNAT]
18 DNAT (inbound)
19
20 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000
21 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.1, DIP 10.0.0.01, Sport 2828, Dport 2000
22
23 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
24 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
25 ./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
26 ./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
27 ./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
28 """
29 def runTest(self):
30 delete_all_flows(self.controller)
31 delete_all_groups(self.controller)
32
33 test_ports = sorted(config["port_map"].keys())
34
35 input_port = test_ports[0]
36 output_port = test_ports[1]
37
38 add_one_vlan_table_flow(self.controller, input_port, vlan_id=200, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False)
39 add_termination_flow(self.controller, input_port, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
40
41 add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=100, is_tagged=True, send_barrier=False)
42 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])
macauley_chengddcd9342015-11-10 11:49:35 +080043 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)
macauley_chengb75de692015-11-09 13:50:32 +080044
45 input_pkt = simple_tcp_packet(pktlen=100,
46 eth_dst="00:00:00:00:02:00",
47 eth_src="00:00:00:00:02:01",
48 dl_vlan_enable = True,
49 vlan_vid = 200,
50 ip_ttl=64,
51 ip_src="200.0.0.1",
52 ip_dst='100.0.0.1',
53 tcp_dport=5000)
54 output_pkt = simple_tcp_packet(pktlen=100,
55 eth_dst="00:00:00:00:01:01",
56 eth_src="00:00:00:00:01:00",
57 dl_vlan_enable = True,
58 vlan_vid = 100,
59 ip_ttl=63,
60 ip_src="200.0.0.1",
61 ip_dst='10.0.0.1',
62 tcp_dport=2000)
63
64 self.dataplane.send(input_port, str(input_pkt))
65 verify_packet(self, str(output_pkt), output_port)
66
67
68
69class dnatEcmp(base_tests.SimpleDataPlane):
70 """
71 [DNAT ECMP]
72 DNAT (inbound) with ECMP
73
74 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000 [increase SIP]
75 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
76 Output eth 1/5 DA000005224466, SA000005223355, Tag 2, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
77
78 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
79 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
80 ./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
81 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x20005 group=any,port=any,weight=0 output=5
82 ./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
83 ./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
84 ./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
85
86 ./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
87 """
88 def runTest(self):
89 delete_all_flows(self.controller)
90 delete_all_groups(self.controller)
91
92 test_ports = config["port_map"].keys()
93 input_port = test_ports[0]
94 output_port = test_ports[1]
95 output_port2 = test_ports[2]
96
97 add_one_vlan_table_flow(self.controller, input_port, vlan_id=200, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
98 add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=100, is_tagged=True, send_barrier=False)
99 #Bits 27:24 is for realm id, so unicast group id give 0x3000001
100 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])
101 add_one_l2_interface_grouop(self.controller, port=output_port2, vlan_id=2, is_tagged=True, send_barrier=False)
102 #Bits 27:24 is for realm id, so unicast group id give 0x3000005
103 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])
104 ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
105 add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
macauley_chengeffc20a2015-11-09 16:14:56 +0800106 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)
macauley_chengb75de692015-11-09 13:50:32 +0800107
108
109 input_pkt = simple_tcp_packet(pktlen=100,
110 eth_dst="00:00:00:00:02:00",
111 eth_src="00:00:00:00:02:01",
112 dl_vlan_enable = True,
113 vlan_vid = 200,
114 ip_ttl=64,
115 ip_src="200.0.0.1",
116 ip_dst='100.0.0.1',
117 tcp_dport=5000)
118 output_pkt = simple_tcp_packet(pktlen=100,
119 eth_dst="00:00:00:00:01:01",
120 eth_src="00:00:00:00:01:00",
121 dl_vlan_enable = True,
122 vlan_vid = 100,
123 ip_ttl=63,
124 ip_src="200.0.0.1",
125 ip_dst='10.0.0.1',
126 tcp_dport=2000)
127 output_pkt2 = simple_tcp_packet(pktlen=100,
128 eth_dst="00:00:05:22:44:66",
129 eth_src="00:00:05:22:33:55",
130 dl_vlan_enable = True,
131 vlan_vid = 2,
132 ip_ttl=63,
133 ip_src="200.0.0.1",
134 ip_dst='10.0.0.1',
135 tcp_dport=2000)
136
137 self.dataplane.send(input_port, str(input_pkt))
138 verify_packet(self, str(output_pkt2), output_port2)
139 #self.dataplane.send(input_port, str(input_pkt))
140 #verify_packet(self, str(output_pkt2), output_port2)
141
macauley_chengeffc20a2015-11-09 16:14:56 +0800142class snat_ecmp(base_tests.SimpleDataPlane):
143 """
144 [SNAT ECMP]
145 SNAT (outbound) with ECMP
146
147 Inject eth 1/1 DA000000000100, SA000000000101, Tag 100, SIP 10.0.0.1, DIP 200.0.0.01, Sport 2000, Dport 2828 [increase DIP]
148 Output eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
149 Output eth 1/5 DA000000000500, SA000000000501, Tag 5, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
150
151 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20
152 ./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
153 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0xC80003 group=any,port=any,weight=0 output=3
154 ./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
155 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x50005 group=any,port=any,weight=0 output=5
156 ./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
157
158 ./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
159 ./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
160 ./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
161 """
162 def runTest(self):
163 delete_all_flows(self.controller)
164 delete_all_groups(self.controller)
165
166 test_ports = sorted(config["port_map"].keys())
167
168 input_port = test_ports[0]
169 output_port = test_ports[1]
170 output_port2 = test_ports[2]
macauley_chengb75de692015-11-09 13:50:32 +0800171
macauley_chengeffc20a2015-11-09 16:14:56 +0800172 add_one_vlan_table_flow(self.controller, input_port, vlan_id=100, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
173 add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x01,0x00], 100, goto_table=29, send_barrier=False)
174 add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=200, is_tagged=True, send_barrier=False)
175 #Bits 27:24 is for realm id, so unicast group id give 0x2000002
176 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])
177
178 add_one_l2_interface_grouop(self.controller, port=output_port2, vlan_id=5, is_tagged=True, send_barrier=False)
179 #Bits 27:24 is for realm id, so unicast group id give 0x2000002
180 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])
181
182 ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
183 add_snat_flow(self.controller, 0x0800, 0x0a000001, 6, 2000, 0x64000001, 5000)
184 add_unicast_routing_flow(self.controller, 0x0800, 0xc8000001, 0xffffff00, ecmp.group_id, vrf=0, send_barrier=False)
185
186 input_pkt = simple_tcp_packet(pktlen=100,
187 eth_dst="00:00:00:00:01:00",
188 eth_src="00:00:00:00:01:01",
189 dl_vlan_enable = True,
190 vlan_vid = 100,
191 ip_ttl=64,
192 ip_src='10.0.0.1',
193 ip_dst="200.0.0.1",
194 tcp_sport=2000)
195 output_pkt = simple_tcp_packet(pktlen=100,
196 eth_dst="00:00:00:00:02:01",
197 eth_src="00:00:00:00:02:00",
198 dl_vlan_enable = True,
199 vlan_vid = 200,
200 ip_ttl=63,
201 ip_src="100.0.0.1",
202 ip_dst='200.0.0.1',
203 tcp_sport=5000)
204 output_pkt2 = simple_tcp_packet(pktlen=100,
205 eth_dst="00:00:00:00:05:01",
206 eth_src="00:00:00:00:05:00",
207 dl_vlan_enable = True,
208 vlan_vid = 5,
209 ip_ttl=63,
210 ip_src="100.0.0.1",
211 ip_dst='200.0.0.1',
212 tcp_sport=5000)
213
214 self.dataplane.send(input_port, str(input_pkt))
215 verify_packet(self, str(output_pkt), output_port)
216 #self.dataplane.send(input_port, str(input_pkt))
217 #verify_packet(self, str(output_pkt2), output_port2)
218
219"""just for verify it can work after nat ecmp"""
macauley_chengb75de692015-11-09 13:50:32 +0800220class l3Route(base_tests.SimpleDataPlane):
221 """
222 [L3 unicast route]
223 Do unicast route and output to specified port
224
225 Inject eth 1/3 Tag2, SA000000112233, DA7072cf7cf3a3, SIP 192.168.1.100, DIP 192.168.2.2
226 Output eth 1/1 Tag3, SA 000004223355, DA 000004224466
227
228 ./dpctl tcp:192.168.1.1:6633 flow-mod table=0,cmd=add,prio=1 in_port=0/0xffff0000 goto:10
229 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x1002/0x1fff goto:20
230 ./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
231 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x30001 group=any,port=any,weight=0 output=1
232 ./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
233 ./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
234 """
235 def runTest(self):
236 delete_all_flows(self.controller)
237 delete_all_groups(self.controller)
238
239 test_ports = sorted(config["port_map"].keys())
240
241 input_port = test_ports[0]
242 output_port = test_ports[1]
243
244 add_port_table_flow(self.controller, is_overlay=False)
245 add_one_vlan_table_flow(self.controller, input_port, vlan_id=2, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
246 add_termination_flow(self.controller, input_port, 0x0800, [0x70, 0x72, 0xcf, 0x7c, 0xf3, 0xa3], 2, send_barrier=False)
247 add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=3, is_tagged=True, send_barrier=False)
248 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])
249 add_unicast_routing_flow(self.controller, 0x0800, 0xc0a80202, 0xffffff00, msg.group_id)
250
251 #verify tx/rx packet
252 input_pkt = simple_tcp_packet(pktlen=100,
253 eth_dst="70:72:cf:7c:f3:a3",
254 eth_src="00:00:00:00:02:01",
255 dl_vlan_enable = True,
256 vlan_vid = 2,
257 ip_ttl=64,
258 ip_src="200.0.0.1",
259 ip_dst='192.168.2.2')
260 output_pkt = simple_tcp_packet(pktlen=100,
261 eth_dst="00:00:04:22:44:66",
262 eth_src="00:00:04:22:33:55",
263 dl_vlan_enable = True,
264 vlan_vid = 3,
265 ip_ttl=63,
266 ip_src="200.0.0.1",
267 ip_dst='192.168.2.2')
268
269 self.dataplane.send(input_port, str(input_pkt))
270 verify_packet(self, str(output_pkt), output_port)
271
272
273
274
275
276
277