Add OXM_OF_METADATA field as a step toward OpenFlow 1.1 support.
[openvswitch] / tests / ofproto.at
1 AT_BANNER([ofproto])
2
3 AT_SETUP([ofproto - echo request])
4 OVS_VSWITCHD_START
5 AT_CHECK([ovs-ofctl -vwarn probe br0])
6 OVS_VSWITCHD_STOP
7 AT_CLEANUP
8
9 AT_SETUP([ofproto - feature request, config request])
10 OVS_VSWITCHD_START
11 AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
12 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
13 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
14 n_tables:255, n_buffers:256
15 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
16 actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DST SET_NW_SRC SET_NW_DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE
17  LOCAL(br0): addr:aa:55:aa:55:00:00
18      config:     PORT_DOWN
19      state:      LINK_DOWN
20      speed: 100 Mbps now, 100 Mbps max
21 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
22 ])
23 OVS_VSWITCHD_STOP
24 AT_CLEANUP
25
26 dnl This is really bare-bones.
27 dnl It at least checks request and reply serialization and deserialization.
28 AT_SETUP([ofproto - port stats])
29 OVS_VSWITCHD_START
30 AT_CHECK([ovs-ofctl -vwarn dump-ports br0], [0], [stdout])
31 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
32 OFPST_PORT reply: 1 ports
33   port 65534: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
34            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
35 ])
36 OVS_VSWITCHD_STOP
37 AT_CLEANUP
38
39 dnl This is really bare-bones.
40 dnl It at least checks request and reply serialization and deserialization.
41 AT_SETUP([ofproto - port-desc stats])
42 OVS_VSWITCHD_START
43 AT_CHECK([ovs-ofctl -vwarn dump-ports-desc br0], [0], [stdout])
44 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
45 OFPST_PORT_DESC reply:
46  LOCAL(br0): addr:aa:55:aa:55:00:00
47      config:     PORT_DOWN
48      state:      LINK_DOWN
49      speed: 100 Mbps now, 100 Mbps max
50 ])
51 OVS_VSWITCHD_STOP
52 AT_CLEANUP
53
54 dnl This is really bare-bones.
55 dnl It at least checks request and reply serialization and deserialization.
56 AT_SETUP([ofproto - queue stats])
57 OVS_VSWITCHD_START
58 AT_CHECK([ovs-ofctl -vwarn queue-stats br0], [0], [stdout])
59 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
60 OFPST_QUEUE reply: 0 queues
61 ])
62 OVS_VSWITCHD_STOP
63 AT_CLEANUP
64
65 AT_SETUP([ofproto - mod-port])
66 OVS_VSWITCHD_START
67 for command_config_state in \
68     'up 0 0' \
69     'noflood NO_FLOOD 0' \
70     'down PORT_DOWN,NO_FLOOD LINK_DOWN' \
71     'flood PORT_DOWN LINK_DOWN' \
72     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
73     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
74     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
75     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
76     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
77     'up NO_RECV 0' \
78     'receive 0 0'
79 do
80     set $command_config_state
81     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
82     AT_CHECK([ovs-ofctl -vwarn mod-port br0 br0 $command])
83     AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
84     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
85 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
86 n_tables:255, n_buffers:256
87 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
88 actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DST SET_NW_SRC SET_NW_DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE
89  LOCAL(br0): addr:aa:55:aa:55:00:00
90      config:     $config
91      state:      $state
92      speed: 100 Mbps now, 100 Mbps max
93 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
94 ])
95 done
96 OVS_VSWITCHD_STOP
97 AT_CLEANUP
98
99 AT_SETUP([ofproto - basic flow_mod commands (NXM)])
100 OVS_VSWITCHD_START
101 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
102 ])
103 AT_CHECK([echo 'in_port=1,actions=0' | ovs-ofctl add-flows br0 -])
104 AT_CHECK([ovs-ofctl add-flow br0 in_port=0,actions=1])
105 AT_CHECK([ovs-ofctl -F nxm add-flow br0 table=1,in_port=3,actions=2])
106 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
107  in_port=0 actions=output:1
108  in_port=1 actions=output:0
109  table=1, in_port=3 actions=output:2
110 NXST_FLOW reply:
111 ])
112 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
113 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
114 ])
115 AT_CHECK([ovs-ofctl del-flows br0])
116 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
117 ])
118 OVS_VSWITCHD_STOP
119 AT_CLEANUP
120
121 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.0)])
122 OVS_VSWITCHD_START
123 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
124 ])
125 AT_CHECK([echo 'in_port=1,actions=0' | ovs-ofctl -F openflow10 add-flows br0 -])
126 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 in_port=0,actions=1])
127 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 table=1,in_port=3,actions=2])
128 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
129  in_port=0 actions=output:1
130  in_port=1 actions=output:0
131  table=1, in_port=3 actions=output:2
132 OFPST_FLOW reply:
133 ])
134 AT_CHECK([ovs-ofctl -F openflow10 dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
135 OFPST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
136 ])
137 AT_CHECK([ovs-ofctl -F openflow10 del-flows br0])
138 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
139 ])
140 OVS_VSWITCHD_STOP
141 AT_CLEANUP
142
143 AT_SETUP([ofproto - dump flows with cookie])
144 OVS_VSWITCHD_START
145 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
146 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
147 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
148 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
149  cookie=0x1, in_port=1 actions=output:0
150  cookie=0x2, in_port=2 actions=output:0
151  cookie=0x3, in_port=3 actions=output:0
152 NXST_FLOW reply:
153 ])
154 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
155 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=3
156 ])
157 AT_CHECK([ovs-ofctl dump-flows br0 cookie=0x3/-1 | ofctl_strip | sort], [0], [dnl
158  cookie=0x3, in_port=3 actions=output:0
159 NXST_FLOW reply:
160 ])
161 AT_CHECK([ovs-ofctl dump-aggregate br0 cookie=0x3/-1 | STRIP_XIDS], [0], [dnl
162 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=1
163 ])
164 OVS_VSWITCHD_STOP
165 AT_CLEANUP
166
167 AT_SETUP([ofproto - dump flows with cookie mask])
168 OVS_VSWITCHD_START
169 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
170 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
171 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
172 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
173  cookie=0x1, in_port=1 actions=output:0
174  cookie=0x2, in_port=2 actions=output:0
175  cookie=0x3, in_port=3 actions=output:0
176 NXST_FLOW reply:
177 ])
178 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
179 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=3
180 ])
181 AT_CHECK([ovs-ofctl dump-flows br0 cookie=0x3/0x1 | ofctl_strip | sort], [0], [dnl
182  cookie=0x1, in_port=1 actions=output:0
183  cookie=0x3, in_port=3 actions=output:0
184 NXST_FLOW reply:
185 ])
186 AT_CHECK([ovs-ofctl dump-aggregate br0 cookie=0x3/0x1 | STRIP_XIDS], [0], [dnl
187 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
188 ])
189 OVS_VSWITCHD_STOP
190 AT_CLEANUP
191
192 AT_SETUP([ofproto - mod flow with cookie change (OpenFlow 1.0)])
193 OVS_VSWITCHD_START
194 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 cookie=0x1,in_port=1,actions=0])
195 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
196  cookie=0x1, in_port=1 actions=output:0
197 OFPST_FLOW reply:
198 ])
199
200 AT_CHECK([ovs-ofctl -F openflow10 mod-flows br0 cookie=0x2,in_port=1,actions=0])
201 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
202  cookie=0x2, in_port=1 actions=output:0
203 OFPST_FLOW reply:
204 ])
205 OVS_VSWITCHD_STOP
206 AT_CLEANUP
207
208 AT_SETUP([ofproto - mod flow with cookie change (NXM)])
209 OVS_VSWITCHD_START
210 AT_CHECK([ovs-ofctl -F nxm add-flow br0 cookie=0x1,in_port=1,actions=0])
211 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
212  cookie=0x1, in_port=1 actions=output:0
213 NXST_FLOW reply:
214 ])
215
216 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x2,in_port=1,actions=0])
217 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
218  cookie=0x2, in_port=1 actions=output:0
219 NXST_FLOW reply:
220 ])
221 OVS_VSWITCHD_STOP
222 AT_CLEANUP
223
224 AT_SETUP([ofproto - mod flows based on cookie mask])
225 OVS_VSWITCHD_START
226 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
227 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=0])
228 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=0])
229 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
230  cookie=0x1, in_port=1 actions=output:0
231  cookie=0x1, in_port=2 actions=output:0
232  cookie=0x2, in_port=3 actions=output:0
233 NXST_FLOW reply:
234 ])
235
236 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x1/0xff,actions=4])
237 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
238  cookie=0x1, in_port=1 actions=output:4
239  cookie=0x1, in_port=2 actions=output:4
240  cookie=0x2, in_port=3 actions=output:0
241 NXST_FLOW reply:
242 ])
243 OVS_VSWITCHD_STOP
244 AT_CLEANUP
245
246 AT_SETUP([ofproto - mod flows based on cookie mask with cookie change])
247 OVS_VSWITCHD_START
248 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
249 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=0])
250 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=0])
251 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
252  cookie=0x1, in_port=1 actions=output:0
253  cookie=0x1, in_port=2 actions=output:0
254  cookie=0x2, in_port=3 actions=output:0
255 NXST_FLOW reply:
256 ])
257
258 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/-1,cookie=4,actions=4])
259 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
260  cookie=0x2, in_port=3 actions=output:0
261  cookie=0x4, in_port=1 actions=output:4
262  cookie=0x4, in_port=2 actions=output:4
263 NXST_FLOW reply:
264 ])
265 OVS_VSWITCHD_STOP
266 AT_CLEANUP
267
268 AT_SETUP([ofproto - mod flow with cookie miss (mask==0)])
269 OVS_VSWITCHD_START
270 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 in_port=1,actions=0])
271 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
272  in_port=1 actions=output:0
273 NXST_FLOW reply:
274 ])
275 OVS_VSWITCHD_STOP
276 AT_CLEANUP
277
278 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0)])
279 OVS_VSWITCHD_START
280 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/1,in_port=1,actions=0])
281 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
282 NXST_FLOW reply:
283 ])
284 OVS_VSWITCHD_STOP
285 AT_CLEANUP
286
287 AT_SETUP([ofproto - del flows with cookies])
288 OVS_VSWITCHD_START
289 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
290 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
291 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
292 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
293  cookie=0x1, in_port=1 actions=output:0
294  cookie=0x2, in_port=2 actions=output:0
295  cookie=0x3, in_port=3 actions=output:0
296 NXST_FLOW reply:
297 ])
298
299 AT_CHECK([ovs-ofctl del-flows br0])
300 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
301 NXST_FLOW reply:
302 ])
303 OVS_VSWITCHD_STOP
304 AT_CLEANUP
305
306 AT_SETUP([ofproto - del flows based on cookie])
307 OVS_VSWITCHD_START
308 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
309 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
310 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
311 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
312  cookie=0x1, in_port=1 actions=output:0
313  cookie=0x2, in_port=2 actions=output:0
314  cookie=0x3, in_port=3 actions=output:0
315 NXST_FLOW reply:
316 ])
317
318 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/-1])
319 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
320  cookie=0x1, in_port=1 actions=output:0
321  cookie=0x2, in_port=2 actions=output:0
322 NXST_FLOW reply:
323 ])
324 OVS_VSWITCHD_STOP
325 AT_CLEANUP
326
327 AT_SETUP([ofproto - del flows based on cookie mask])
328 OVS_VSWITCHD_START
329 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
330 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
331 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
332 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
333  cookie=0x1, in_port=1 actions=output:0
334  cookie=0x2, in_port=2 actions=output:0
335  cookie=0x3, in_port=3 actions=output:0
336 NXST_FLOW reply:
337 ])
338 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/0x1])
339 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
340  cookie=0x2, in_port=2 actions=output:0
341 NXST_FLOW reply:
342 ])
343 OVS_VSWITCHD_STOP
344 AT_CLEANUP
345
346 AT_SETUP([ofproto - flow table configuration])
347 OVS_VSWITCHD_START
348 # Check the default configuration.
349 (echo "OFPST_TABLE reply (xid=0x1): 255 tables
350   0: classifier: wild=0x3fffff, max=1000000, active=0
351                lookup=0, matched=0"
352  x=1
353  while test $x -lt 254; do
354    printf "  %d: %-8s: wild=0x3fffff, max=1000000, active=0
355                lookup=0, matched=0
356 " $x table$x
357    x=`expr $x + 1`
358  done
359  echo "  254: table254: wild=0x3fffff, max=1000000, active=2
360                lookup=0, matched=0") > expout
361 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
362 # Change the configuration.
363 AT_CHECK(
364   [ovs-vsctl \
365      -- --id=@t0 create Flow_Table name=main \
366      -- --id=@t1 create Flow_Table flow-limit=1024 \
367      -- set bridge br0 'flow_tables={1=@t1,0=@t0}' \
368    | perl $srcdir/uuidfilt.pl],
369   [0], [<0>
370 <1>
371 ])
372 # Check that the configuration was updated.
373 mv expout orig-expout
374 (echo "OFPST_TABLE reply (xid=0x1): 255 tables
375   0: main    : wild=0x3fffff, max=1000000, active=0
376                lookup=0, matched=0
377   1: table1  : wild=0x3fffff, max=  1024, active=0
378                lookup=0, matched=0"
379  tail -n +6 orig-expout) > expout
380 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
381 OVS_VSWITCHD_STOP
382 AT_CLEANUP
383
384 AT_SETUP([ofproto - hard limits on flow table size])
385 OVS_VSWITCHD_START
386 # Configure a maximum of 4 flows.
387 AT_CHECK(
388   [ovs-vsctl \
389      -- --id=@t0 create Flow_Table flow-limit=4 \
390      -- set bridge br0 flow_tables:0=@t0 \
391    | perl $srcdir/uuidfilt.pl],
392   [0], [<0>
393 ])
394 # Add 4 flows.
395 for in_port in 1 2 3 4; do
396     ovs-ofctl add-flow br0 in_port=$in_port,actions=drop
397 done
398 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
399  in_port=1 actions=drop
400  in_port=2 actions=drop
401  in_port=3 actions=drop
402  in_port=4 actions=drop
403 NXST_FLOW reply:
404 ])
405 # Adding another flow will be refused.
406 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop], [1], [], [stderr])
407 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
408   [OFPT_ERROR: OFPFMFC_ALL_TABLES_FULL
409 ])
410 # Also a mod-flow that would add a flow will be refused.
411 AT_CHECK([ovs-ofctl mod-flows br0 in_port=5,actions=drop], [1], [], [stderr])
412 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
413   [OFPT_ERROR: OFPFMFC_ALL_TABLES_FULL
414 ])
415 # Replacing or modifying an existing flow is allowed.
416 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
417 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
418 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
419  in_port=1 actions=drop
420  in_port=2 actions=drop
421  in_port=3 actions=output:1
422  in_port=4 actions=NORMAL
423 NXST_FLOW reply:
424 ])
425 OVS_VSWITCHD_STOP
426 AT_CLEANUP
427
428 AT_SETUP([ofproto - eviction upon table overflow])
429 OVS_VSWITCHD_START
430 # Configure a maximum of 4 flows.
431 AT_CHECK(
432   [ovs-vsctl \
433      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
434      -- set bridge br0 flow_tables:0=@t0 \
435    | perl $srcdir/uuidfilt.pl],
436   [0], [<0>
437 ])
438 # Add 4 flows.
439 for in_port in 4 3 2 1; do
440     ovs-ofctl add-flow br0 idle_timeout=${in_port}0,in_port=$in_port,actions=drop
441 done
442 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
443  idle_timeout=10, in_port=1 actions=drop
444  idle_timeout=20, in_port=2 actions=drop
445  idle_timeout=30, in_port=3 actions=drop
446  idle_timeout=40, in_port=4 actions=drop
447 NXST_FLOW reply:
448 ])
449 # Adding another flow will cause the one that expires soonest to be evicted.
450 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop])
451 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
452  idle_timeout=20, in_port=2 actions=drop
453  idle_timeout=30, in_port=3 actions=drop
454  idle_timeout=40, in_port=4 actions=drop
455  in_port=5 actions=drop
456 NXST_FLOW reply:
457 ])
458 # A mod-flow that adds a flow also causes eviction, but replacing or
459 # modifying an existing flow doesn't.
460 AT_CHECK([ovs-ofctl mod-flows br0 in_port=6,actions=drop])
461 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
462 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
463 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
464  idle_timeout=30, in_port=3 actions=output:1
465  in_port=4 actions=NORMAL
466  in_port=5 actions=drop
467  in_port=6 actions=drop
468 NXST_FLOW reply:
469 ])
470 # Flows with no timeouts at all cannot be evicted.
471 AT_CHECK([ovs-ofctl add-flow br0 in_port=7,actions=normal])
472 AT_CHECK([ovs-ofctl add-flow br0 in_port=8,actions=drop], [1], [], [stderr])
473 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
474   [OFPT_ERROR: OFPFMFC_ALL_TABLES_FULL
475 ])
476 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
477  in_port=4 actions=NORMAL
478  in_port=5 actions=drop
479  in_port=6 actions=drop
480  in_port=7 actions=NORMAL
481 NXST_FLOW reply:
482 ])
483 OVS_VSWITCHD_STOP
484 AT_CLEANUP
485
486 AT_SETUP([ofproto - eviction upon table overflow, with fairness])
487 OVS_VSWITCHD_START
488 # Configure a maximum of 4 flows.
489 AT_CHECK(
490   [ovs-vsctl \
491      -- --id=@t0 create Flow_Table name=evict flow-limit=4 \
492                                    overflow-policy=evict \
493                                    groups='"NXM_OF_IN_PORT[[]]"' \
494      -- set bridge br0 flow_tables:0=@t0 \
495    | perl $srcdir/uuidfilt.pl],
496   [0], [<0>
497 ])
498 # Add 4 flows.
499 ovs-ofctl add-flows br0 - <<EOF
500 idle_timeout=10 in_port=2 dl_src=00:44:55:66:77:88 actions=drop
501 idle_timeout=20 in_port=1 dl_src=00:11:22:33:44:55 actions=drop
502 idle_timeout=30 in_port=1 dl_src=00:22:33:44:55:66 actions=drop
503 idle_timeout=40 in_port=1 dl_src=00:33:44:55:66:77 actions=drop
504 EOF
505 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
506  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
507  idle_timeout=20, in_port=1,dl_src=00:11:22:33:44:55 actions=drop
508  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
509  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
510 NXST_FLOW reply:
511 ])
512 # Adding another flow will cause the one that expires soonest within
513 # the largest group (those with in_port=1) to be evicted.  In this
514 # case this is not the same as the one that expires soonest overall
515 # (which is what makes the test interesting):
516 AT_CHECK([ovs-ofctl add-flow br0 in_port=2,dl_src=00:55:66:77:88:99,actions=drop])
517 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
518  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
519  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
520  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
521  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
522 NXST_FLOW reply:
523 ])
524 # Enlarge the flow limit, change the eviction policy back to strictly
525 # based on expiration, and and add some flows.
526 AT_CHECK([ovs-vsctl set Flow_Table evict groups='[[]]' flow-limit=7])
527 ovs-ofctl add-flows br0 - <<EOF
528 idle_timeout=50 in_port=2 dl_src=00:66:77:88:99:aa actions=drop
529 idle_timeout=60 in_port=2 dl_src=00:77:88:99:aa:bb actions=drop
530 idle_timeout=70 in_port=2 dl_src=00:88:99:aa:bb:cc actions=drop
531 EOF
532 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
533  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
534  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
535  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
536  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
537  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
538  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
539  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
540 NXST_FLOW reply:
541 ])
542 # Adding another flow will cause the one that expires soonest overall
543 # to be evicted.
544 AT_CHECK([ovs-ofctl add-flow br0 'idle_timeout=80 in_port=2 dl_src=00:99:aa:bb:cc:dd actions=drop'])
545 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
546  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
547  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
548  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
549  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
550  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
551  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
552  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
553 NXST_FLOW reply:
554 ])
555 # Reducing the flow limit also causes the flows that expire soonest
556 # overall to be evicted.
557 AT_CHECK([ovs-vsctl set Flow_Table evict flow-limit=4])
558 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
559  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
560  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
561  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
562  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
563 NXST_FLOW reply:
564 ])
565 OVS_VSWITCHD_STOP
566 AT_CLEANUP
567
568 AT_SETUP([ofproto - asynchronous message control])
569 OVS_VSWITCHD_START
570 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
571 check_async () {
572     printf '\n\n--- check_async %d ---\n\n\n' $1
573     shift
574
575     ovs-appctl -t ovs-ofctl ofctl/barrier
576     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
577     : > expout
578
579     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
580     ovs-ofctl -v packet-out br0 none controller '0001020304050010203040501234'
581     if test X"$1" = X"OFPR_ACTION"; then shift;
582         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=NONE (via action) data_len=14 (unbuffered)
583 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)"
584     fi
585
586     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
587     ovs-ofctl -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
588     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
589         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=NONE (via no_match) data_len=14 (unbuffered)
590 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)"
591     fi
592
593     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
594     ovs-ofctl packet-out br0 none dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
595     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
596         echo >>expout "OFPT_PACKET_IN: total_len=76 in_port=NONE (via invalid_ttl) data_len=76 (unbuffered)
597 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:26:b9:8c:b0:f9->00:25:83:df:b4:00) type:0800 proto:17 tos:0 ttl:0 ip(172.17.55.13->172.16.0.2) port(55155->53) udp_csum:8f6d"
598     fi
599
600     # OFPT_PORT_STATUS, OFPPR_ADD
601     ovs-vsctl add-port br0 test -- set Interface test type=dummy
602     if test X"$1" = X"OFPPR_ADD"; then shift;
603         echo >>expout "OFPT_PORT_STATUS: ADD: 1(test): addr:aa:55:aa:55:00:0x
604      config:     PORT_DOWN
605      state:      LINK_DOWN
606      speed: 100 Mbps now, 100 Mbps max"
607     fi
608
609     # OFPT_PORT_STATUS, OFPPR_DELETE
610     ovs-vsctl del-port br0 test
611     if test X"$1" = X"OFPPR_DELETE"; then shift;
612         echo >>expout "OFPT_PORT_STATUS: DEL: 1(test): addr:aa:55:aa:55:00:0x
613      config:     PORT_DOWN
614      state:      LINK_DOWN
615      speed: 100 Mbps now, 100 Mbps max"
616     fi
617
618     # OFPT_FLOW_REMOVED, OFPRR_DELETE
619     ovs-ofctl add-flow br0 send_flow_rem,actions=drop
620     ovs-ofctl --strict del-flows br0 ''
621     if test X"$1" = X"OFPRR_DELETE"; then shift;
622         echo >>expout "OFPT_FLOW_REMOVED:  reason=delete"
623     fi
624     AT_FAIL_IF([test X"$1" != X])
625
626     ovs-appctl -t ovs-ofctl ofctl/barrier
627     echo >>expout "OFPT_BARRIER_REPLY:"
628
629     AT_CHECK(
630       [[sed '
631 s/ (xid=0x[0-9a-fA-F]*)//
632 s/ *duration.*//
633 s/00:0.$/00:0x/' < monitor.log]],
634       [0], [expout])
635 }
636
637 # It's a service connection so initially there should be no async messages.
638 check_async 1
639
640 # Set miss_send_len to 128, turning on packet-ins for our service connection.
641 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
642 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
643
644 # Set miss_send_len to 128 and enable invalid_ttl.
645 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700040080
646 check_async 3 OFPR_ACTION OFPR_INVALID_TTL OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
647
648 # Become slave, which should disable everything except port status.
649 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000002
650 check_async 4 OFPPR_ADD OFPPR_DELETE
651
652 # Use NXT_SET_ASYNC_CONFIG to enable a patchwork of asynchronous messages.
653 ovs-appctl -t ovs-ofctl ofctl/send 01040028000000020000232000000013000000020000000500000005000000020000000200000005
654 check_async 5 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
655
656 # Set controller ID 123.
657 ovs-appctl -t ovs-ofctl ofctl/send 01040018000000030000232000000014000000000000007b
658 check_async 6 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
659
660 # Restore controller ID 0.
661 ovs-appctl -t ovs-ofctl ofctl/send 010400180000000300002320000000140000000000000000
662
663 # Become master.
664 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000001
665 check_async 7 OFPR_ACTION OFPPR_ADD
666
667 ovs-appctl -t ovs-ofctl exit
668 OVS_VSWITCHD_STOP
669 AT_CLEANUP
670
671 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
672 dnl specified by OpenFlow 1.0) and OFPP_CONTROLLER (used by some
673 dnl controllers despite the spec) as meaning a packet that was generated
674 dnl by the controller.
675 AT_SETUP([ofproto - packet-out from controller])
676 OVS_VSWITCHD_START
677
678 # Start a monitor listening for packet-ins.
679 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
680 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
681 ovs-appctl -t ovs-ofctl ofctl/barrier
682 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
683 AT_CAPTURE_FILE([monitor.log])
684
685 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
686 AT_CHECK([ovs-ofctl packet-out br0 none controller '0001020304050010203040501234'])
687 AT_CHECK([ovs-ofctl packet-out br0 65533 controller '0001020304050010203040505678'])
688
689 # Stop the monitor and check its output.
690 ovs-appctl -t ovs-ofctl ofctl/barrier
691 ovs-appctl -t ovs-ofctl exit
692
693 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
694 OFPT_PACKET_IN: total_len=14 in_port=NONE (via action) data_len=14 (unbuffered)
695 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
696 OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
697 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:5678 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
698 OFPT_BARRIER_REPLY:
699 ])
700
701 OVS_VSWITCHD_STOP
702 AT_CLEANUP
703
704 dnl This test checks that metadata is encoded in packet_in structures,
705 dnl supported by NXAST.
706 AT_SETUP([ofproto - packet-out with metadata (NXM)])
707 OVS_VSWITCHD_START
708
709 # Start a monitor listening for packet-ins.
710 AT_CHECK([ovs-ofctl -P nxm monitor br0 --detach --no-chdir --pidfile])
711 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
712 ovs-appctl -t ovs-ofctl ofctl/barrier
713 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
714 AT_CAPTURE_FILE([monitor.log])
715
716 # Send a packet-out with a load action to set some metadata, and forward to controller
717 AT_CHECK([ovs-ofctl packet-out br0 none 'load(0xfafafafa5a5a5a5a->OXM_OF_METADATA[[0..63]]), controller' '0001020304050010203040501234'])
718
719 # Stop the monitor and check its output.
720 ovs-appctl -t ovs-ofctl ofctl/barrier
721 ovs-appctl -t ovs-ofctl exit
722
723 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
724 NXT_PACKET_IN: total_len=14 in_port=NONE tun_id=0x0 metadata=0xfafafafa5a5a5a5a reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 (via action) data_len=14 (unbuffered)
725 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
726 OFPT_BARRIER_REPLY:
727 ])
728
729 OVS_VSWITCHD_STOP
730 AT_CLEANUP