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