blob: e3e247b44e74bcb16628ca94ed94043c22afdfe1 [file] [log] [blame]
macauley_cheng0a0a7f62015-11-06 11:36:50 +08001import logging
2import oftest.base_tests as base_tests
3from oftest import config
4from oftest.testutils import *
5from util import *
6from accton_util import convertIP4toStr as toIpV4Str
7from accton_util import convertMACtoStr as toMacStr
8
9
10class dnat(base_tests.SimpleDataPlane):
11 """
12 [DNAT]
13 DNAT (inbound)
14
15 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000
16 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.1, DIP 10.0.0.01, Sport 2828, Dport 2000
17
18 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
19 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
20 ./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
21 ./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
22 ./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
23 """
24 def runTest(self):
25 delete_all_flows(self.controller)
26 delete_all_groups(self.controller)
27
28 test_ports = sorted(config["port_map"].keys())
29
30 input_port = test_ports[0]
31 output_port = test_ports[1]
32
macauley_cheng77205a42015-11-06 15:24:21 +080033 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +080034 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x10c8/0x1fff goto:20")
35 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0x64000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
36 apply_dpctl_mod(self, config, "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=0x64000"+str(output_port))
37 apply_dpctl_mod(self, config, "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")
38 apply_dpctl_mod(self, config, "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")
39
40 input_pkt = simple_packet(
41 '00 00 00 00 02 00 00 00 00 00 02 01 81 00 00 c8 '
42 '08 00 45 00 00 2a 04 d2 00 00 7f 06 0a fa c8 00 '
43 '00 01 64 00 00 01 0b 0c 13 88 00 01 f7 fa 00 00 '
44 '00 00 50 00 04 00 69 50 00 00 00 00')
45
46 output_pkt = simple_packet(
47 '00 00 00 00 01 01 00 00 00 00 01 00 81 00 00 64 '
48 '08 00 45 00 00 2a 04 d2 00 00 7e 06 65 fa c8 00 '
49 '00 01 0a 00 00 01 0b 0c 07 d0 00 01 f7 fa 00 00 '
50 '00 00 50 00 04 00 cf 08 00 00 00 00')
51
52 self.dataplane.send(input_port, str(input_pkt))
53 verify_packet(self, str(output_pkt), output_port)
54
55
56class dnat_vrf(base_tests.SimpleDataPlane):
57 """
58 [DNAT VRF]
59 DNAT (inbound) with specified VRF
60
61 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000
62 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.1, DIP 10.0.0.01, Sport 2828, Dport 2000
63
64 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20 apply:set_field=ofdpa_vrf:3
65 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20 apply:set_field=ofdpa_vrf:3
66 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
67 ./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
68 ./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
69 ./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,ofdpa_vrf=3 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x23000001 goto:60
70 """
71 def runTest(self):
72 delete_all_flows(self.controller)
73 delete_all_groups(self.controller)
74
75 test_ports = sorted(config["port_map"].keys())
76
77 input_port = test_ports[0]
78 output_port = test_ports[1]
79
macauley_cheng77205a42015-11-06 15:24:21 +080080 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +080081 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x10c8/0x1fff goto:20 apply:set_field=ofdpa_vrf:3")
82 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(output_port)+",vlan_vid=0x1064/0x1fff goto:20 apply:set_field=ofdpa_vrf:3")
83 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0x64000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
84 apply_dpctl_mod(self, config, "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=0x64000"+str(output_port))
85 apply_dpctl_mod(self, config, "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")
86 apply_dpctl_mod(self, config, "flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000,ofdpa_vrf=3 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x23000001 goto:60")
87
88 input_pkt = simple_packet(
89 '00 00 00 00 02 00 00 00 00 00 02 01 81 00 00 c8 '
90 '08 00 45 00 00 2a 04 d2 00 00 7f 06 0a fa c8 00 '
91 '00 01 64 00 00 01 0b 0c 13 88 00 01 f7 fa 00 00 '
92 '00 00 50 00 04 00 69 50 00 00 00 00')
93
94 output_pkt = simple_packet(
95 '00 00 00 00 01 01 00 00 00 00 01 00 81 00 00 64 '
96 '08 00 45 00 00 2a 04 d2 00 00 7e 06 65 fa c8 00 '
97 '00 01 0a 00 00 01 0b 0c 07 d0 00 01 f7 fa 00 00 '
98 '00 00 50 00 04 00 cf 08 00 00 00 00')
99
100 self.dataplane.send(input_port, str(input_pkt))
101 verify_packet(self, str(output_pkt), output_port)
102
macauley_chengcc04e2f2015-11-06 15:07:51 +0800103"""
104currently this case will fail, due to packet rx SRC IP problem
105"""
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800106class dnat_ecmp(base_tests.SimpleDataPlane):
107 """
108 [DNAT ECMP]
109 DNAT (inbound) with ECMP
110
111 Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000 [increase SIP]
112 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
113 Output eth 1/5 DA000005224466, SA000005223355, Tag 2, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
114
115 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
116 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
117 ./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
118 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x20005 group=any,port=any,weight=0 output=5
119 ./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
120 ./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
121 ./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
122 ./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
123 """
124 def runTest(self):
125 delete_all_flows(self.controller)
126 delete_all_groups(self.controller)
127
128 test_ports = sorted(config["port_map"].keys())
129
130 input_port = test_ports[0]
131 output_port = test_ports[1]
132 output_port2 = test_ports[2]
133
macauley_cheng77205a42015-11-06 15:24:21 +0800134 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800135 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x10c8/0x1fff goto:20 apply:set_field=ofdpa_vrf:3")
136 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0x64000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
137 apply_dpctl_mod(self, config, "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=0x64000"+str(output_port))
138 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0x2000"+str(output_port2)+" group=any,port=any,weight=0 output="+str(output_port2))
139 apply_dpctl_mod(self, config, "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=0x2000"+str(output_port2))
140 apply_dpctl_mod(self, config, "group-mod cmd=add,type=sel,group=0x71000001 group=any,port=any,weight=0 group=0x23000001 group=any,port=any,weight=0 group=0x23000005")
141 apply_dpctl_mod(self, config, "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")
142 apply_dpctl_mod(self, config, "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")
143
144 #increased SIP
145 input_pkt = simple_packet(
146 '00 00 00 00 02 00 00 00 00 00 02 01 81 00 00 c8 '
147 '08 00 45 00 00 2a 04 d2 00 00 7f 06 0a fa c8 00 '
148 '00 01 64 00 00 01 0b 0c 13 88 00 01 f7 fa 00 00 '
149 '00 00 50 00 04 00 69 50 00 00 00 00')
150
151 #random SIP
152 output_pkt = simple_packet(
153 '00 00 00 00 01 01 00 00 00 00 01 00 81 00 00 64 '
154 '08 00 45 00 00 2a 04 d2 00 00 7e 06 65 ee c8 00 '
155 '00 0d 0a 00 00 01 0b 0c 07 d0 00 01 f7 fa 00 00 '
156 '00 00 50 00 04 00 ce fc 00 00 00 00')
157
158 #random SIP
159 output_pkt2 = simple_packet(
160 '00 00 05 22 44 66 00 00 05 22 33 55 81 00 00 02 '
161 '08 00 45 00 00 2a 04 d2 00 00 7e 06 65 ef c8 00 '
162 '00 0c 0a 00 00 01 0b 0c 07 d0 00 01 f7 fa 00 00 '
163 '00 00 50 00 04 00 ce fd 00 00 00 00')
164
165 self.dataplane.send(input_port, str(input_pkt))
166 verify_packet(self, str(output_pkt), output_port)
macauley_cheng77205a42015-11-06 15:24:21 +0800167 self.dataplane.send(input_port, str(input_pkt))
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800168 verify_packet(self, str(output_pkt2), output_port2)
169
170
171class dnat_decap_mpls(base_tests.SimpleDataPlane):
172 """
173 [Decap MPLS label and DNAT]
174 Decap MPLS label and DNAT
175
176 Inject eth 1/3 Tag 12, SA000000112233, DA000000000111, MPLS 0x1234, SIP 200.0.0.1, DIP 100.0.0.1
177 Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.1, DIP 10.0.0.01
178
179 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
180 ./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
181 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x100c/0x1fff apply:set_field=ofdpa_vrf:1 goto:20
182 ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=12/0xfff,eth_dst=00:00:00:00:01:11,eth_type=0x8847 goto:24
183 ./dpctl tcp:192.168.1.1:6633 flow-mod table=24,cmd=add,prio=204 eth_type=0x8847,mpls_label=0x1234,mpls_bos=1,ofdpa_mpls_data_first_nibble=4 apply:mpls_dec,pop_mpls=0x0800,set_field=ofdpa_vrf:1 goto:30
184 ./dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ofdpa_vrf=1 write:set_field=ip_dst:10.0.0.1,group=0x23000001 goto:60
185 """
186 def runTest(self):
187 delete_all_flows(self.controller)
188 delete_all_groups(self.controller)
189
190 test_ports = sorted(config["port_map"].keys())
191
192 input_port = test_ports[0]
193 output_port = test_ports[1]
194
macauley_cheng77205a42015-11-06 15:24:21 +0800195 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800196 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0x64000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
197 apply_dpctl_mod(self, config, "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=0x64000"+str(output_port))
198 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x100c/0x1fff apply:set_field=ofdpa_vrf:1 goto:20")
199 apply_dpctl_mod(self, config, "flow-mod table=20,cmd=add,prio=201 vlan_vid=12/0xfff,eth_dst=00:00:00:00:01:11,eth_type=0x8847 goto:24")
200 apply_dpctl_mod(self, config, "flow-mod table=24,cmd=add,prio=204 eth_type=0x8847,mpls_label=0x1234,mpls_bos=1,ofdpa_mpls_data_first_nibble=4 apply:mpls_dec,pop_mpls=0x0800,set_field=ofdpa_vrf:1 goto:30")
201 apply_dpctl_mod(self, config, "flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ofdpa_vrf=1 write:set_field=ip_dst:10.0.0.1,group=0x23000001 goto:60")
202
203 input_pkt = simple_packet(
204 '00 00 00 00 01 11 00 00 00 11 22 33 81 00 00 0c '
205 '88 47 01 23 41 3f 45 00 00 26 00 00 00 00 3f 00 '
206 '4f d6 c8 00 00 01 64 00 00 01 00 01 02 03 04 05 '
207 '06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 '
208 '16 17 18 19')
209
210 output_pkt = simple_packet(
211 '00 00 00 00 01 01 00 00 00 00 01 00 81 00 00 64 '
212 '08 00 45 00 00 26 00 00 00 00 3e 00 aa d6 c8 00 '
213 '00 01 0a 00 00 01 00 01 02 03 04 05 06 07 08 09 '
214 '0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19')
215
216 self.dataplane.send(input_port, str(input_pkt))
217 verify_packet(self, str(output_pkt), output_port)
218
219
220class snat(base_tests.SimpleDataPlane):
221 """
222 [SNAT]
223 SNAT (outbound)
224
225 Inject eth 1/1 DA000000000100, SA000000000101, Tag 100, SIP 10.0.0.1, DIP 200.0.0.01, Sport 2000, Dport 2828
226 Output eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 100.0.0.1, DIP 200.0.0.01, Sport 5000, Dport 2828
227
228 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20
229 ./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
230 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0xC80003 group=any,port=any,weight=0 output=3
231 ./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
232 ./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
233 ./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=0x22000002 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
macauley_cheng77205a42015-11-06 15:24:21 +0800244 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800245 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x1064/0x1fff goto:20")
246 apply_dpctl_mod(self, config, "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")
247 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0xC8000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
248 apply_dpctl_mod(self, config, "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=0xC8000"+str(output_port))
249 apply_dpctl_mod(self, config, "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")
250 apply_dpctl_mod(self, config, "flow-mod table=30,cmd=add,prio=301 eth_type=0x0800,ip_dst=200.0.0.1/255.255.255.0 write:group=0x22000002 goto:60")
251
252 input_pkt = simple_packet(
253 '00 00 00 00 01 00 00 00 00 00 02 00 81 00 00 64 '
254 '08 00 45 00 00 2e 04 d2 00 00 7f 06 64 f6 0a 00 '
255 '00 01 c8 00 00 01 07 d0 0b 0c 00 01 f7 fa 00 00 '
256 '00 00 50 00 04 00 cf 04 00 00 00 00 00 00 00 00')
257
258 output_pkt = simple_packet(
259 '00 00 00 00 02 01 00 00 00 00 02 00 81 00 00 c8 '
260 '08 00 45 00 00 2e 04 d2 00 00 7e 06 0b f6 64 00 '
261 '00 01 c8 00 00 01 13 88 0b 0c 00 01 f7 fa 00 00 '
262 '00 00 50 00 04 00 69 4c 00 00 00 00 00 00 00 00')
263
264 self.dataplane.send(input_port, str(input_pkt))
265 verify_packet(self, str(output_pkt), output_port)
266
267
268class snat_vrf(base_tests.SimpleDataPlane):
269 """
270 [SNAT VRF]
271 SNAT (outbound) with specified VRF
272
273 Inject eth 1/1 DA000000000100, SA000000000101, Tag 100, SIP 10.0.0.1, DIP 200.0.0.01, Sport 2000, Dport 2828
274 Output eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 100.0.0.1, DIP 200.0.0.01, Sport 5000, Dport 2828
275
276 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20 apply:set_field=ofdpa_vrf:3
277 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x10c8/0x1fff goto:20 apply:set_field=ofdpa_vrf:3
278 ./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
279 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0xC80003 group=any,port=any,weight=0 output=3
280 ./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
281 ./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,ofdpa_vrf=3 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30
282 ./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,ofdpa_vrf=3 write:group=0x22000002 goto:60
283 """
284 def runTest(self):
285 delete_all_flows(self.controller)
286 delete_all_groups(self.controller)
287
288 test_ports = sorted(config["port_map"].keys())
289
290 input_port = test_ports[0]
291 output_port = test_ports[1]
292
macauley_cheng77205a42015-11-06 15:24:21 +0800293 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800294 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x1064/0x1fff goto:20 apply:set_field=ofdpa_vrf:3")
295 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x10c8/0x1fff goto:20 apply:set_field=ofdpa_vrf:3")
296 apply_dpctl_mod(self, config, "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")
297 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0xC8000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
298 apply_dpctl_mod(self, config, "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=0xC8000"+str(output_port))
299 apply_dpctl_mod(self, config, "flow-mod table=29,cmd=add,prio=291 eth_type=0x800,ip_src=10.0.0.1,ip_proto=6,tcp_src=2000,ofdpa_vrf=3 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30")
300 apply_dpctl_mod(self, config, "flow-mod table=30,cmd=add,prio=301 eth_type=0x0800,ip_dst=200.0.0.1/255.255.255.0,ofdpa_vrf=3 write:group=0x22000002 goto:60")
301
302 input_pkt = simple_packet(
303 '00 00 00 00 01 00 00 00 00 00 02 00 81 00 00 64 '
304 '08 00 45 00 00 2e 04 d2 00 00 7f 06 64 f6 0a 00 '
305 '00 01 c8 00 00 01 07 d0 0b 0c 00 01 f7 fa 00 00 '
306 '00 00 50 00 04 00 cf 04 00 00 00 00 00 00 00 00')
307
308 output_pkt = simple_packet(
309 '00 00 00 00 02 01 00 00 00 00 02 00 81 00 00 c8 '
310 '08 00 45 00 00 2e 04 d2 00 00 7e 06 0b f6 64 00 '
311 '00 01 c8 00 00 01 13 88 0b 0c 00 01 f7 fa 00 00 '
312 '00 00 50 00 04 00 69 4c 00 00 00 00 00 00 00 00')
313
314 self.dataplane.send(input_port, str(input_pkt))
315 verify_packet(self, str(output_pkt), output_port)
316
macauley_chengcc04e2f2015-11-06 15:07:51 +0800317"""
318currently this case will fail, due to packet rx src IP problem
319"""
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800320class snat_ecmp(base_tests.SimpleDataPlane):
321 """
322 [SNAT ECMP]
323 SNAT (outbound) with ECMP
324
325 Inject eth 1/1 DA000000000100, SA000000000101, Tag 100, SIP 10.0.0.1, DIP 200.0.0.01, Sport 2000, Dport 2828 [increase DIP]
326 Output eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
327 Output eth 1/5 DA000000000500, SA000000000501, Tag 5, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
328
329 ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20
330 ./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
331 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0xC80003 group=any,port=any,weight=0 output=3
332 ./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
333 ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x50005 group=any,port=any,weight=0 output=5
334 ./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
335 ./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
336 ./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
337 ./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
338 """
339 def runTest(self):
340 delete_all_flows(self.controller)
341 delete_all_groups(self.controller)
342
343 test_ports = sorted(config["port_map"].keys())
344
345 input_port = test_ports[0]
346 output_port = test_ports[1]
347 output_port2 = test_ports[2]
348
macauley_cheng77205a42015-11-06 15:24:21 +0800349 apply_dpctl_mod(self, config, "meter-mod cmd=del,meter=0xffffffff")
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800350 apply_dpctl_mod(self, config, "flow-mod table=10,cmd=add,prio=101 in_port="+str(input_port)+",vlan_vid=0x1064/0x1fff goto:20")
351 apply_dpctl_mod(self, config, "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")
352 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0xC8000"+str(output_port)+" group=any,port=any,weight=0 output="+str(output_port))
353 apply_dpctl_mod(self, config, "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=0xC8000"+str(output_port))
354 apply_dpctl_mod(self, config, "group-mod cmd=add,type=ind,group=0x5000"+str(output_port2)+" group=any,port=any,weight=0 output="+str(output_port2))
355 apply_dpctl_mod(self, config, "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=0x5000"+str(output_port))
356 apply_dpctl_mod(self, config, "group-mod cmd=add,type=sel,group=0x71000001 group=any,port=any,weight=0 group=0x22000002 group=any,port=any,weight=0 group=0x22000005")
357 apply_dpctl_mod(self, config, "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")
358 apply_dpctl_mod(self, config, "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")
359
360 #increased DIP
361 input_pkt = simple_packet(
362 '00 00 00 00 01 00 00 00 00 00 02 00 81 00 00 64 '
363 '08 00 45 00 00 2e 04 d2 00 00 7f 06 64 f6 0a 00 '
364 '00 01 c8 00 00 01 07 d0 0b 0c 00 01 f7 fa 00 00 '
365 '00 00 50 00 04 00 cf 04 00 00 00 00 00 00 00 00')
366
367 #rnadom DIP
368 output_pkt = simple_packet(
369 '00 00 00 00 02 01 00 00 00 00 02 00 81 00 00 c8 '
370 '08 00 45 00 00 2e 04 d2 00 00 7e 06 0b e8 64 00 '
371 '00 01 c8 00 00 0f 13 88 0b 0c 00 01 f7 fa 00 00 '
372 '00 00 50 00 04 00 69 3e 00 00 00 00 00 00 00 00')
373
374 #rnadom DIP
375 output_pkt2 = simple_packet(
376 '00 00 00 00 05 01 00 00 00 00 05 00 81 00 00 05 '
377 '08 00 45 00 00 2e 04 d2 00 00 7e 06 0b f4 64 00 '
378 '00 01 c8 00 00 03 13 88 0b 0c 00 01 f7 fa 00 00 '
379 '00 00 50 00 04 00 69 4a 00 00 00 00 00 00 00 00')
380
381 self.dataplane.send(input_port, str(input_pkt))
382 verify_packet(self, str(output_pkt), output_port)
macauley_cheng77205a42015-11-06 15:24:21 +0800383 self.dataplane.send(input_port, str(input_pkt))
macauley_cheng0a0a7f62015-11-06 11:36:50 +0800384 verify_packet(self, str(output_pkt2), output_port2)