]> git.proxmox.com Git - mirror_ovs.git/blame - tests/classifier.at
dpif_packet: Rename to dp_packet
[mirror_ovs.git] / tests / classifier.at
CommitLineData
3223e977
BP
1AT_BANNER([flow classifier unit tests])
2m4_foreach(
3 [testname],
4 [[empty],
5 [destroy-null],
6 [single-rule],
7 [rule-replacement],
b5d97350 8 [many-rules-in-one-list],
3223e977 9 [many-rules-in-one-table],
b5d97350
BP
10 [many-rules-in-two-tables],
11 [many-rules-in-five-tables]],
3223e977 12 [AT_SETUP([flow classifier - m4_bpatsubst(testname, [-], [ ])])
eadd1644 13 AT_CHECK([ovstest test-classifier testname], [0], [], [])
3223e977 14 AT_CLEANUP])])
5cb7a798
BP
15
16AT_BANNER([miniflow unit tests])
17m4_foreach(
18 [testname],
19 [[miniflow],
20 [minimask_has_extra],
21 [minimask_combine]],
22 [AT_SETUP([miniflow - m4_bpatsubst(testname, [-], [ ])])
eadd1644 23 AT_CHECK([ovstest test-classifier testname], [0], [], [])
5cb7a798 24 AT_CLEANUP])])
476f36e8
JR
25
26AT_BANNER([flow classifier lookup segmentation])
27AT_SETUP([flow classifier - lookup segmentation])
28OVS_VSWITCHD_START
29ADD_OF_PORTS([br0], [1], [2], [3])
30AT_DATA([flows.txt], [dnl
31table=0 in_port=1 priority=16,tcp,nw_dst=10.1.0.0/255.255.0.0,action=output(3)
32table=0 in_port=1 priority=32,tcp,nw_dst=10.1.2.15,action=output(2)
33table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=80,action=drop
34table=0 in_port=1 priority=0,ip,action=drop
35table=0 in_port=2 priority=16,tcp,nw_dst=192.168.0.0/255.255.0.0,action=output(1)
36table=0 in_port=2 priority=0,ip,action=drop
37table=0 in_port=3 priority=16,tcp,nw_src=10.1.0.0/255.255.0.0,action=output(1)
38table=0 in_port=3 priority=0,ip,action=drop
39])
40AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
41AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=2,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
42AT_CHECK([tail -2 stdout], [0],
16194afd 43 [Megaflow: recirc_id=0,tcp,in_port=2,nw_dst=192.168.0.0/16,nw_frag=no
476f36e8
JR
44Datapath actions: 1
45])
66e1d955 46AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=11.1.2.15,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
476f36e8 47AT_CHECK([tail -2 stdout], [0],
66e1d955 48 [Megaflow: recirc_id=0,ip,in_port=1,nw_dst=1.0.0.0/1.0.0.0,nw_frag=no
476f36e8
JR
49Datapath actions: drop
50])
51AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=10.1.2.15,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
52AT_CHECK([tail -2 stdout], [0],
16194afd 53 [Megaflow: recirc_id=0,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_dst=80
476f36e8
JR
54Datapath actions: drop
55])
56AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=10.1.2.15,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=79'], [0], [stdout])
57AT_CHECK([tail -2 stdout], [0],
16194afd 58 [Megaflow: recirc_id=0,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_dst=0x1/0x1
476f36e8
JR
59Datapath actions: 2
60])
61OVS_VSWITCHD_STOP
62AT_CLEANUP
13751fd8
JR
63
64AT_BANNER([flow classifier prefix lookup])
65AT_SETUP([flow classifier - prefix lookup])
66OVS_VSWITCHD_START
67ADD_OF_PORTS([br0], [1], [2], [3])
68AT_CHECK([ovs-vsctl set Bridge br0 flow_tables:0=@N1 -- --id=@N1 create Flow_Table name=t0], [0], [ignore], [])
13751fd8
JR
69AT_DATA([flows.txt], [dnl
70table=0 in_port=1 priority=16,tcp,nw_dst=10.1.0.0/255.255.0.0,action=output(3)
71table=0 in_port=1 priority=32,tcp,nw_dst=10.1.2.0/255.255.255.0,tp_src=79,action=output(2)
72table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=80,action=drop
69d6040e
JR
73table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=8080,action=output(2)
74table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=192,action=output(2)
13751fd8
JR
75table=0 in_port=1 priority=0,ip,action=drop
76table=0 in_port=2 priority=16,tcp,nw_dst=192.168.0.0/255.255.0.0,action=output(1)
77table=0 in_port=2 priority=0,ip,action=drop
78table=0 in_port=3 priority=16,tcp,nw_src=10.1.0.0/255.255.0.0,action=output(1)
79table=0 in_port=3 priority=0,ip,action=drop
80])
81AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
f017d986
JR
82
83# nw_dst and nw_src should be on by default
84AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
85AT_CHECK([tail -2 stdout], [0],
16194afd 86 [Megaflow: recirc_id=0,ip,in_port=1,nw_dst=192.168.0.0/16,nw_frag=no
f017d986
JR
87Datapath actions: drop
88])
89
90AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=ipv6_label], [0])
91AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=nw_dst,nw_src,tun_dst,tun_src], [1], [],
92[ovs-vsctl: nw_dst,nw_src,tun_dst,tun_src: 4 value(s) specified but the maximum number is 3
93])
94AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=nw_dst,nw_dst], [1], [],
95[ovs-vsctl: nw_dst,nw_dst: set contains duplicate value
96])
97
98AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=nw_dst], [0])
13751fd8
JR
99AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
100AT_CHECK([tail -2 stdout], [0],
16194afd 101 [Megaflow: recirc_id=0,ip,in_port=1,nw_dst=192.168.0.0/16,nw_frag=no
13751fd8
JR
102Datapath actions: drop
103])
104AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=2,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
105AT_CHECK([tail -2 stdout], [0],
16194afd 106 [Megaflow: recirc_id=0,tcp,in_port=2,nw_dst=192.168.0.0/16,nw_frag=no
13751fd8
JR
107Datapath actions: 1
108])
109AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=10.1.2.15,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=80'], [0], [stdout])
110AT_CHECK([tail -2 stdout], [0],
16194afd 111 [Megaflow: recirc_id=0,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_dst=80
13751fd8
JR
112Datapath actions: drop
113])
114AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=10.1.2.15,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=79'], [0], [stdout])
115AT_CHECK([tail -2 stdout], [0],
16194afd 116 [Megaflow: recirc_id=0,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_src=0x0/0x1,tp_dst=0x40/0xfff0
13751fd8
JR
117Datapath actions: 3
118])
f017d986
JR
119AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=none], [0])
120AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=10.1.3.16,nw_proto=6,nw_tos=0,nw_ttl=128,tp_src=8,tp_dst=79'], [0], [stdout])
121AT_CHECK([tail -2 stdout], [0],
16194afd 122 [Megaflow: recirc_id=0,tcp,in_port=1,nw_dst=10.1.3.16,nw_frag=no
f017d986
JR
123Datapath actions: 3
124])
13751fd8
JR
125OVS_VSWITCHD_STOP(["/'prefixes' with incompatible field: ipv6_label/d"])
126AT_CLEANUP
18080541
BP
127
128AT_BANNER([conjunctive match])
129
130AT_SETUP([single conjunctive match])
131OVS_VSWITCHD_START
132ADD_OF_PORTS([br0], 1, 2, 3, 4, 5)
133AT_DATA([flows.txt], [dnl
134conj_id=1,actions=3
135priority=100,ip,ip_src=10.0.0.1,actions=conjunction(1,1/2)
136priority=100,ip,ip_src=10.0.0.4,actions=conjunction(1,1/2)
137priority=100,ip,ip_src=10.0.0.6,actions=conjunction(1,1/2)
138priority=100,ip,ip_src=10.0.0.7,actions=conjunction(1,1/2)
139priority=100,ip,ip_dst=10.0.0.2,actions=conjunction(1,2/2)
140priority=100,ip,ip_dst=10.0.0.5,actions=conjunction(1,2/2)
141priority=100,ip,ip_dst=10.0.0.7,actions=conjunction(1,2/2)
142priority=100,ip,ip_dst=10.0.0.8,actions=conjunction(1,2/2)
143priority=100,ip,ip_src=10.0.0.1,ip_dst=10.0.0.4,actions=4
144priority=100,ip,ip_src=10.0.0.3,ip_dst=10.0.0.5,actions=5
145
146priority=0 actions=2
147])
148AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
149for src in 0 1 2 3 4 5 6 7; do
150 for dst in 0 1 2 3 4 5 6 7; do
151 if test $src$dst = 14; then
152 out=4
153 elif test $src$dst = 35; then
154 out=5
155 else
156 out=2
157 case $src in [[1467]]) case $dst in [[2578]]) out=3 ;; esac ;; esac
158 fi
159 AT_CHECK([ovs-appctl ofproto/trace br0 "in_port=1,dl_type=0x0800,nw_src=10.0.0.$src,nw_dst=10.0.0.$dst"], [0], [stdout])
160 AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $out
161])
162 done
163done
164OVS_VSWITCHD_STOP
165AT_CLEANUP
166
167AT_SETUP([multiple conjunctive match])
168OVS_VSWITCHD_START
169ADD_OF_PORTS([br0], 1, 2, 3, 4, 5)
170AT_DATA([flows.txt], [dnl
171conj_id=1,actions=1
172conj_id=2,actions=2
173conj_id=3,actions=3
174
175priority=5,ip,ip_src=20.0.0.0/8,actions=conjunction(1,1/2),conjunction(2,1/2)
176priority=5,ip,ip_src=10.1.0.0/16,actions=conjunction(1,1/2),conjunction(3,2/3)
177priority=5,ip,ip_src=10.2.0.0/16,actions=conjunction(1,1/2),conjunction(2,1/2)
178priority=5,ip,ip_src=10.1.3.0/24,actions=conjunction(1,1/2),conjunction(3,2/3)
179priority=5,ip,ip_src=10.1.4.5/32,actions=conjunction(1,1/2),conjunction(2,1/2)
180
181priority=5,ip,ip_dst=20.0.0.0/8,actions=conjunction(1,2/2)
182priority=5,ip,ip_dst=10.1.0.0/16,actions=conjunction(1,2/2)
183priority=5,ip,ip_dst=10.2.0.0/16,actions=conjunction(1,2/2)
184priority=5,ip,ip_dst=10.1.3.0/24,actions=conjunction(1,2/2)
185priority=5,ip,ip_dst=10.1.4.5/32,actions=conjunction(1,2/2)
186priority=5,ip,ip_dst=30.0.0.0/8,actions=conjunction(2,2/2),conjunction(3,1/3)
187priority=5,ip,ip_dst=40.5.0.0/16,actions=conjunction(2,2/2),conjunction(3,1/3)
188
189priority=5,tcp,tcp_dst=80,actions=conjunction(3,3/3)
190priority=5,tcp,tcp_dst=443,actions=conjunction(3,3/3)
191
192priority=5,tcp,tcp_src=80,actions=conjunction(3,3/3)
193priority=5,tcp,tcp_src=443,actions=conjunction(3,3/3)
194
195priority=0,actions=4
196])
197AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
198for a0 in \
199 '1 20.0.0.1' \
200 '2 10.1.0.1' \
201 '3 10.2.0.1' \
202 '4 10.1.3.1' \
203 '5 10.1.4.5' \
204 '6 1.2.3.4'
205do
206 for b0 in \
207 '1 20.0.0.1' \
208 '2 10.1.0.1' \
209 '3 10.2.0.1' \
210 '4 10.1.3.1' \
211 '5 10.1.4.5' \
212 '6 30.0.0.1' \
213 '7 40.5.0.1' \
214 '8 1.2.3.4'
215 do
216 for c0 in '1 80' '2 443' '3 8080'; do
217 for d0 in '1 80' '2 443' '3 8080'; do
218 set $a0; a=$1 ip_src=$2
219 set $b0; b=$1 ip_dst=$2
220 set $c0; c=$1 tcp_src=$2
221 set $d0; d=$1 tcp_dst=$2
222 case $a$b$c$d in
223 [[12345]][[12345]]??) out=1 ;;
224 [[135]][[67]]??) out=2 ;;
225 [[24]][[67]][[12]]? | [[24]][[67]]?[[12]]) out=3 ;;
226 *) out=4
227 esac
228 AT_CHECK([ovs-appctl ofproto/trace br0 "in_port=5,dl_type=0x0800,nw_proto=6,nw_src=$ip_src,nw_dst=$ip_dst,tcp_src=$tcp_src,tcp_dst=$tcp_dst"], [0], [stdout])
229 AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $out
230])
231 done
232 done
233 done
234done
235OVS_VSWITCHD_STOP
236AT_CLEANUP
237
238# In conjunctive match, we can find some soft matches that turn out not to be a
239# real match. Usually, that's the end of the road--there is no real match.
240# But if there is a flow identical to one of the flows that was a soft match,
241# except with a lower priority, then we have to try again with that lower
242# priority flow. This test checks this special case.
243AT_SETUP([conjunctive match priority fallback])
244OVS_VSWITCHD_START
245ADD_OF_PORTS([br0], 1, 2, 3, 4, 5, 6, 7)
246AT_DATA([flows.txt], [dnl
247conj_id=1,actions=1
248conj_id=3,actions=3
249
250priority=5,ip,ip_src=10.0.0.1,actions=conjunction(1,1/2)
251priority=5,ip,ip_src=10.0.0.2,actions=conjunction(1,1/2)
252priority=5,ip,ip_dst=10.0.0.1,actions=conjunction(1,2/2)
253priority=5,ip,ip_dst=10.0.0.2,actions=conjunction(1,2/2)
254priority=5,ip,ip_dst=10.0.0.3,actions=conjunction(1,2/2)
255
256priority=4,ip,ip_src=10.0.0.3,ip_dst=10.0.0.2,actions=2
257
258priority=3,ip,ip_src=10.0.0.1,actions=conjunction(3,1/2)
259priority=3,ip,ip_src=10.0.0.3,actions=conjunction(3,1/2)
260priority=3,ip,ip_dst=10.0.0.2,actions=conjunction(3,2/2)
261priority=3,ip,ip_dst=10.0.0.3,actions=conjunction(3,2/2)
262priority=3,ip,ip_dst=10.0.0.4,actions=conjunction(3,2/2)
263
264priority=2,ip,ip_dst=10.0.0.1,actions=4
265
266priority=1,ip,ip_src=10.0.0.1,ip_dst=10.0.0.5,actions=5
267
268priority=0,actions=6
269])
270AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
271for src in 0 1 2 3; do
272 for dst in 0 1 2 3 4 5; do
273 case $src$dst in
274 [[12]][[123]]) out=1 ;;
275 32) out=2 ;;
276 [[13]][[234]]) out=3 ;;
277 ?1) out=4 ;;
278 15) out=5 ;;
279 *) out=6
280 esac
281 AT_CHECK([ovs-appctl ofproto/trace br0 "in_port=7,dl_type=0x0800,nw_src=10.0.0.$src,nw_dst=10.0.0.$dst"], [0], [stdout])
282 AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $out
283])
284 done
285done
286OVS_VSWITCHD_STOP
287AT_CLEANUP