]> git.proxmox.com Git - mirror_ovs.git/blame - tests/classifier.at
flow: Support extra padding length.
[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],
3bbe9a1f 9 [versioned many-rules-in-one-list],
3223e977 10 [many-rules-in-one-table],
3bbe9a1f 11 [versioned many-rules-in-one-table],
b5d97350 12 [many-rules-in-two-tables],
3bbe9a1f
JR
13 [versioned many-rules-in-two-tables],
14 [many-rules-in-five-tables],
15 [versioned many-rules-in-five-tables]],
3223e977 16 [AT_SETUP([flow classifier - m4_bpatsubst(testname, [-], [ ])])
3bbe9a1f 17 AT_CHECK([ovstest test-classifier m4_bpatsubst(testname, [versioned], [--versioned])], [0], [], [])
3223e977 18 AT_CLEANUP])])
5cb7a798
BP
19
20AT_BANNER([miniflow unit tests])
21m4_foreach(
22 [testname],
23 [[miniflow],
24 [minimask_has_extra],
25 [minimask_combine]],
26 [AT_SETUP([miniflow - m4_bpatsubst(testname, [-], [ ])])
eadd1644 27 AT_CHECK([ovstest test-classifier testname], [0], [], [])
5cb7a798 28 AT_CLEANUP])])
476f36e8
JR
29
30AT_BANNER([flow classifier lookup segmentation])
31AT_SETUP([flow classifier - lookup segmentation])
32OVS_VSWITCHD_START
ca5792f0 33add_of_ports br0 1 2 3
476f36e8
JR
34AT_DATA([flows.txt], [dnl
35table=0 in_port=1 priority=16,tcp,nw_dst=10.1.0.0/255.255.0.0,action=output(3)
36table=0 in_port=1 priority=32,tcp,nw_dst=10.1.2.15,action=output(2)
37table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=80,action=drop
38table=0 in_port=1 priority=0,ip,action=drop
39table=0 in_port=2 priority=16,tcp,nw_dst=192.168.0.0/255.255.0.0,action=output(1)
40table=0 in_port=2 priority=0,ip,action=drop
41table=0 in_port=3 priority=16,tcp,nw_src=10.1.0.0/255.255.0.0,action=output(1)
42table=0 in_port=3 priority=0,ip,action=drop
43])
44AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
45AT_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])
46AT_CHECK([tail -2 stdout], [0],
e3981271 47 [Megaflow: recirc_id=0,eth,tcp,in_port=2,nw_dst=192.168.0.0/16,nw_frag=no
476f36e8
JR
48Datapath actions: 1
49])
66e1d955 50AT_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 51AT_CHECK([tail -2 stdout], [0],
e3981271 52 [Megaflow: recirc_id=0,eth,ip,in_port=1,nw_dst=11.0.0.0/8,nw_frag=no
476f36e8
JR
53Datapath actions: drop
54])
55AT_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])
56AT_CHECK([tail -2 stdout], [0],
e3981271 57 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_dst=80
476f36e8
JR
58Datapath actions: drop
59])
60AT_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])
61AT_CHECK([tail -2 stdout], [0],
e3981271 62 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_dst=0x40/0xfff0
476f36e8
JR
63Datapath actions: 2
64])
65OVS_VSWITCHD_STOP
66AT_CLEANUP
13751fd8
JR
67
68AT_BANNER([flow classifier prefix lookup])
69AT_SETUP([flow classifier - prefix lookup])
70OVS_VSWITCHD_START
ca5792f0 71add_of_ports br0 1 2 3
13751fd8 72AT_CHECK([ovs-vsctl set Bridge br0 flow_tables:0=@N1 -- --id=@N1 create Flow_Table name=t0], [0], [ignore], [])
13751fd8
JR
73AT_DATA([flows.txt], [dnl
74table=0 in_port=1 priority=16,tcp,nw_dst=10.1.0.0/255.255.0.0,action=output(3)
75table=0 in_port=1 priority=32,tcp,nw_dst=10.1.2.0/255.255.255.0,tp_src=79,action=output(2)
76table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=80,action=drop
69d6040e
JR
77table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=8080,action=output(2)
78table=0 in_port=1 priority=33,tcp,nw_dst=10.1.2.15,tp_dst=192,action=output(2)
13751fd8
JR
79table=0 in_port=1 priority=0,ip,action=drop
80table=0 in_port=2 priority=16,tcp,nw_dst=192.168.0.0/255.255.0.0,action=output(1)
81table=0 in_port=2 priority=0,ip,action=drop
82table=0 in_port=3 priority=16,tcp,nw_src=10.1.0.0/255.255.0.0,action=output(1)
83table=0 in_port=3 priority=0,ip,action=drop
84])
85AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
f017d986
JR
86
87# nw_dst and nw_src should be on by default
88AT_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])
89AT_CHECK([tail -2 stdout], [0],
e3981271 90 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=192.168.0.0/16,nw_frag=no
f017d986
JR
91Datapath actions: drop
92])
93
94AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=ipv6_label], [0])
95AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=nw_dst,nw_src,tun_dst,tun_src], [1], [],
96[ovs-vsctl: nw_dst,nw_src,tun_dst,tun_src: 4 value(s) specified but the maximum number is 3
97])
98AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=nw_dst,nw_dst], [1], [],
99[ovs-vsctl: nw_dst,nw_dst: set contains duplicate value
100])
101
102AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=nw_dst], [0])
13751fd8
JR
103AT_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])
104AT_CHECK([tail -2 stdout], [0],
e3981271 105 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=192.168.0.0/16,nw_frag=no
13751fd8
JR
106Datapath actions: drop
107])
108AT_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])
109AT_CHECK([tail -2 stdout], [0],
e3981271 110 [Megaflow: recirc_id=0,eth,tcp,in_port=2,nw_dst=192.168.0.0/16,nw_frag=no
13751fd8
JR
111Datapath actions: 1
112])
113AT_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])
114AT_CHECK([tail -2 stdout], [0],
e3981271 115 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_dst=80
13751fd8
JR
116Datapath actions: drop
117])
118AT_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])
119AT_CHECK([tail -2 stdout], [0],
e3981271 120 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=10.1.2.15,nw_frag=no,tp_src=0x0/0xffc0,tp_dst=0x40/0xfff0
13751fd8
JR
121Datapath actions: 3
122])
f017d986
JR
123AT_CHECK([ovs-vsctl set Flow_Table t0 prefixes=none], [0])
124AT_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])
125AT_CHECK([tail -2 stdout], [0],
e3981271 126 [Megaflow: recirc_id=0,eth,tcp,in_port=1,nw_dst=10.1.3.16,nw_frag=no
f017d986
JR
127Datapath actions: 3
128])
13751fd8
JR
129OVS_VSWITCHD_STOP(["/'prefixes' with incompatible field: ipv6_label/d"])
130AT_CLEANUP
18080541
BP
131
132AT_BANNER([conjunctive match])
133
134AT_SETUP([single conjunctive match])
135OVS_VSWITCHD_START
ca5792f0 136add_of_ports br0 1 2 3 4 5
18080541
BP
137AT_DATA([flows.txt], [dnl
138conj_id=1,actions=3
139priority=100,ip,ip_src=10.0.0.1,actions=conjunction(1,1/2)
140priority=100,ip,ip_src=10.0.0.4,actions=conjunction(1,1/2)
141priority=100,ip,ip_src=10.0.0.6,actions=conjunction(1,1/2)
142priority=100,ip,ip_src=10.0.0.7,actions=conjunction(1,1/2)
143priority=100,ip,ip_dst=10.0.0.2,actions=conjunction(1,2/2)
144priority=100,ip,ip_dst=10.0.0.5,actions=conjunction(1,2/2)
145priority=100,ip,ip_dst=10.0.0.7,actions=conjunction(1,2/2)
146priority=100,ip,ip_dst=10.0.0.8,actions=conjunction(1,2/2)
147priority=100,ip,ip_src=10.0.0.1,ip_dst=10.0.0.4,actions=4
148priority=100,ip,ip_src=10.0.0.3,ip_dst=10.0.0.5,actions=5
149
150priority=0 actions=2
151])
152AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
153for src in 0 1 2 3 4 5 6 7; do
154 for dst in 0 1 2 3 4 5 6 7; do
155 if test $src$dst = 14; then
156 out=4
157 elif test $src$dst = 35; then
158 out=5
159 else
160 out=2
161 case $src in [[1467]]) case $dst in [[2578]]) out=3 ;; esac ;; esac
162 fi
163 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])
164 AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $out
165])
166 done
167done
168OVS_VSWITCHD_STOP
169AT_CLEANUP
170
171AT_SETUP([multiple conjunctive match])
172OVS_VSWITCHD_START
ca5792f0 173add_of_ports br0 1 2 3 4 5
18080541
BP
174AT_DATA([flows.txt], [dnl
175conj_id=1,actions=1
176conj_id=2,actions=2
177conj_id=3,actions=3
178
179priority=5,ip,ip_src=20.0.0.0/8,actions=conjunction(1,1/2),conjunction(2,1/2)
180priority=5,ip,ip_src=10.1.0.0/16,actions=conjunction(1,1/2),conjunction(3,2/3)
181priority=5,ip,ip_src=10.2.0.0/16,actions=conjunction(1,1/2),conjunction(2,1/2)
182priority=5,ip,ip_src=10.1.3.0/24,actions=conjunction(1,1/2),conjunction(3,2/3)
183priority=5,ip,ip_src=10.1.4.5/32,actions=conjunction(1,1/2),conjunction(2,1/2)
184
185priority=5,ip,ip_dst=20.0.0.0/8,actions=conjunction(1,2/2)
186priority=5,ip,ip_dst=10.1.0.0/16,actions=conjunction(1,2/2)
187priority=5,ip,ip_dst=10.2.0.0/16,actions=conjunction(1,2/2)
188priority=5,ip,ip_dst=10.1.3.0/24,actions=conjunction(1,2/2)
189priority=5,ip,ip_dst=10.1.4.5/32,actions=conjunction(1,2/2)
190priority=5,ip,ip_dst=30.0.0.0/8,actions=conjunction(2,2/2),conjunction(3,1/3)
191priority=5,ip,ip_dst=40.5.0.0/16,actions=conjunction(2,2/2),conjunction(3,1/3)
192
193priority=5,tcp,tcp_dst=80,actions=conjunction(3,3/3)
194priority=5,tcp,tcp_dst=443,actions=conjunction(3,3/3)
195
196priority=5,tcp,tcp_src=80,actions=conjunction(3,3/3)
197priority=5,tcp,tcp_src=443,actions=conjunction(3,3/3)
198
199priority=0,actions=4
200])
201AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
202for a0 in \
203 '1 20.0.0.1' \
204 '2 10.1.0.1' \
205 '3 10.2.0.1' \
206 '4 10.1.3.1' \
207 '5 10.1.4.5' \
208 '6 1.2.3.4'
209do
210 for b0 in \
211 '1 20.0.0.1' \
212 '2 10.1.0.1' \
213 '3 10.2.0.1' \
214 '4 10.1.3.1' \
215 '5 10.1.4.5' \
216 '6 30.0.0.1' \
217 '7 40.5.0.1' \
218 '8 1.2.3.4'
219 do
220 for c0 in '1 80' '2 443' '3 8080'; do
221 for d0 in '1 80' '2 443' '3 8080'; do
222 set $a0; a=$1 ip_src=$2
223 set $b0; b=$1 ip_dst=$2
224 set $c0; c=$1 tcp_src=$2
225 set $d0; d=$1 tcp_dst=$2
226 case $a$b$c$d in
227 [[12345]][[12345]]??) out=1 ;;
228 [[135]][[67]]??) out=2 ;;
229 [[24]][[67]][[12]]? | [[24]][[67]]?[[12]]) out=3 ;;
230 *) out=4
231 esac
232 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])
233 AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $out
234])
235 done
236 done
237 done
238done
239OVS_VSWITCHD_STOP
240AT_CLEANUP
241
242# In conjunctive match, we can find some soft matches that turn out not to be a
243# real match. Usually, that's the end of the road--there is no real match.
244# But if there is a flow identical to one of the flows that was a soft match,
245# except with a lower priority, then we have to try again with that lower
246# priority flow. This test checks this special case.
247AT_SETUP([conjunctive match priority fallback])
248OVS_VSWITCHD_START
ca5792f0 249add_of_ports br0 1 2 3 4 5 6 7
18080541
BP
250AT_DATA([flows.txt], [dnl
251conj_id=1,actions=1
252conj_id=3,actions=3
253
254priority=5,ip,ip_src=10.0.0.1,actions=conjunction(1,1/2)
255priority=5,ip,ip_src=10.0.0.2,actions=conjunction(1,1/2)
256priority=5,ip,ip_dst=10.0.0.1,actions=conjunction(1,2/2)
257priority=5,ip,ip_dst=10.0.0.2,actions=conjunction(1,2/2)
258priority=5,ip,ip_dst=10.0.0.3,actions=conjunction(1,2/2)
259
260priority=4,ip,ip_src=10.0.0.3,ip_dst=10.0.0.2,actions=2
261
262priority=3,ip,ip_src=10.0.0.1,actions=conjunction(3,1/2)
263priority=3,ip,ip_src=10.0.0.3,actions=conjunction(3,1/2)
264priority=3,ip,ip_dst=10.0.0.2,actions=conjunction(3,2/2)
265priority=3,ip,ip_dst=10.0.0.3,actions=conjunction(3,2/2)
266priority=3,ip,ip_dst=10.0.0.4,actions=conjunction(3,2/2)
267
268priority=2,ip,ip_dst=10.0.0.1,actions=4
269
270priority=1,ip,ip_src=10.0.0.1,ip_dst=10.0.0.5,actions=5
271
272priority=0,actions=6
273])
274AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
275for src in 0 1 2 3; do
276 for dst in 0 1 2 3 4 5; do
277 case $src$dst in
278 [[12]][[123]]) out=1 ;;
279 32) out=2 ;;
280 [[13]][[234]]) out=3 ;;
5a0e4aec 281 ?1) out=4 ;;
18080541
BP
282 15) out=5 ;;
283 *) out=6
284 esac
285 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])
286 AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $out
287])
288 done
289done
290OVS_VSWITCHD_STOP
291AT_CLEANUP
f08e39dd
BP
292
293AT_SETUP([conjunctive match and other actions])
294OVS_VSWITCHD_START
295# It's OK to use "conjunction" actions with "note" actions.
296AT_CHECK([ovs-ofctl add-flow br0 'actions=conjunction(3,1/2),note:41.42.43.44.45.46'])
297AT_CHECK([ovs-ofctl add-flow br0 'actions=note:41.42.43.44.45.46,conjunction(3,1/2)'])
298# It's not OK to use "conjunction" actions with other types of actions.
299AT_CHECK([ovs-ofctl '-vPATTERN:console:%c|%p|%m' add-flow br0 'actions=output:1,conjunction(3,1/2)'], [1], [], [dnl
2e7ac3e0 300ovs-ofctl: "conjunction" actions may be used along with "note" but not any other kind of action (such as the "output" action used here)
f08e39dd
BP
301])
302AT_CHECK([ovs-ofctl '-vPATTERN:console:%c|%p|%m' add-flow br0 'actions=conjunction(3,1/2),output:1'], [1], [], [dnl
2e7ac3e0 303ovs-ofctl: "conjunction" actions may be used along with "note" but not any other kind of action (such as the "output" action used here)
f08e39dd
BP
304])
305OVS_VSWITCHD_STOP
306AT_CLEANUP
79349cba
FL
307
308# Flow classifier a packet with excess of padding.
309AT_SETUP([flow classifier - packet with extra padding])
310OVS_VSWITCHD_START
311add_of_ports br0 1 2
312AT_DATA([flows.txt], [dnl
313priority=5,ip,ip_dst=1.1.1.1,actions=1
314priority=5,ip,ip_dst=1.1.1.2,actions=2
315priority=0,actions=drop
316])
317AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
318packet=00020202020000010101010008004500001c00010000401176cc01010101010101020d6a00350008ee3a
319AT_CHECK([ovs-appctl ofproto/trace br0 in_port=1 $packet] , [0], [stdout])
320AT_CHECK([tail -2 stdout], [0],
321 [Megaflow: recirc_id=0,eth,ip,in_port=1,nw_dst=1.1.1.2,nw_frag=no
322Datapath actions: 2
323])
324# normal packet plus 255 bytes of padding (8bit padding).
325# 255 * 2 = 510
326padding=$(printf '%*s' 510 | tr ' ' '0')
327AT_CHECK([ovs-appctl ofproto/trace br0 in_port=1 ${packet}${padding}] , [0], [stdout])
328AT_CHECK([tail -2 stdout], [0],
329 [Megaflow: recirc_id=0,eth,ip,in_port=1,nw_dst=1.1.1.2,nw_frag=no
330Datapath actions: 2
331])
332# normal packet plus padding up to 65535 bytes of length (16bit limit).
333# 65535 - 43 = 65492
334# 65492 * 2 = 130984
335padding=$(printf '%*s' 130984 | tr ' ' '0')
336AT_CHECK([ovs-appctl ofproto/trace br0 in_port=1 ${packet}${padding}], [0], [stdout])
337AT_CHECK([tail -2 stdout], [0],
338 [Megaflow: recirc_id=0,eth,ip,in_port=1,nw_dst=1.1.1.2,nw_frag=no
339Datapath actions: 2
340])
341OVS_VSWITCHD_STOP
342AT_CLEANUP