ofp-actions: Fix error code for invalid table id.
[cascardo/ovs.git] / 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 - handling messages with bad version])
10 OVS_VSWITCHD_START
11
12 # Start a monitor running OpenFlow 1.0, then send the switch an OF1.1 features
13 # request
14 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
15 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
16 AT_CAPTURE_FILE([monitor.log])
17 ovs-appctl -t ovs-ofctl ofctl/send 0205000801234567
18 ovs-appctl -t ovs-ofctl ofctl/barrier
19 ovs-appctl -t ovs-ofctl exit
20
21 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//
22 /ECHO/d' monitor.log], [0], [dnl
23 send: OFPT_FEATURES_REQUEST (OF1.1):
24 OFPT_ERROR (OF1.1): OFPBRC_BAD_VERSION
25 OFPT_FEATURES_REQUEST (OF1.1):
26 OFPT_BARRIER_REPLY:
27 ])
28
29 OVS_VSWITCHD_STOP(["/received OpenFlow version 0x02 != expected 01/d"])
30 AT_CLEANUP
31
32 AT_SETUP([ofproto - feature request, config request])
33 OVS_VSWITCHD_START
34 AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
35 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
36 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
37 n_tables:254, n_buffers:256
38 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
39 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
40  LOCAL(br0): addr:aa:55:aa:55:00:00
41      config:     PORT_DOWN
42      state:      LINK_DOWN
43      speed: 0 Mbps now, 0 Mbps max
44 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
45 ])
46 OVS_VSWITCHD_STOP
47 AT_CLEANUP
48
49 AT_SETUP([ofproto - set OpenFlow port number])
50 OVS_VSWITCHD_START(
51        [add-port br0 p1 -- set Interface p1 type=dummy --\
52         add-port br0 p2 -- set Interface p2 type=dummy ofport_request=99])
53 AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
54 AT_CHECK([[sed '
55 s/ (xid=0x[0-9a-fA-F]*)//
56 s/00:0.$/00:0x/' < stdout]],
57       [0], [dnl
58 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
59 n_tables:254, n_buffers:256
60 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
61 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
62  1(p1): addr:aa:55:aa:55:00:0x
63      config:     PORT_DOWN
64      state:      LINK_DOWN
65      speed: 0 Mbps now, 0 Mbps max
66  99(p2): addr:aa:55:aa:55:00:0x
67      config:     PORT_DOWN
68      state:      LINK_DOWN
69      speed: 0 Mbps now, 0 Mbps max
70  LOCAL(br0): addr:aa:55:aa:55:00:0x
71      config:     PORT_DOWN
72      state:      LINK_DOWN
73      speed: 0 Mbps now, 0 Mbps max
74 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
75 ])
76
77 OVS_VSWITCHD_STOP
78 AT_CLEANUP
79
80 dnl This is really bare-bones.
81 dnl It at least checks request and reply serialization and deserialization.
82 AT_SETUP([ofproto - port stats - (OpenFlow 1.0)])
83 OVS_VSWITCHD_START
84 AT_CHECK([ovs-ofctl -vwarn dump-ports br0], [0], [stdout])
85 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
86 OFPST_PORT reply: 1 ports
87   port LOCAL: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
88            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
89 ])
90 OVS_VSWITCHD_STOP
91 AT_CLEANUP
92
93 AT_SETUP([ofproto - port stats - (OpenFlow 1.2)])
94 OVS_VSWITCHD_START
95 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn dump-ports br0], [0], [stdout])
96 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
97 OFPST_PORT reply (OF1.2): 1 ports
98   port LOCAL: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
99            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
100 ])
101 OVS_VSWITCHD_STOP
102 AT_CLEANUP
103
104 AT_SETUP([ofproto - port stats - (OpenFlow 1.4)])
105 OVS_VSWITCHD_START
106 AT_CHECK([ovs-ofctl -O OpenFlow14 -vwarn dump-ports br0], [0], [stdout])
107 AT_CHECK([STRIP_XIDS stdout | sed 's/duration=[[0-9.]]*s/duration=?s/'],
108   [0], [dnl
109 OFPST_PORT reply (OF1.4): 1 ports
110   port LOCAL: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
111            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
112            duration=?s
113 ])
114 OVS_VSWITCHD_STOP
115 AT_CLEANUP
116
117 dnl This is really bare-bones.
118 dnl It at least checks request and reply serialization and deserialization.
119 AT_SETUP([ofproto - port-desc stats (OpenFlow 1.0)])
120 OVS_VSWITCHD_START
121 AT_CHECK([ovs-ofctl -vwarn dump-ports-desc br0], [0], [stdout])
122 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
123 OFPST_PORT_DESC reply:
124  LOCAL(br0): addr:aa:55:aa:55:00:00
125      config:     PORT_DOWN
126      state:      LINK_DOWN
127      speed: 0 Mbps now, 0 Mbps max
128 ])
129 OVS_VSWITCHD_STOP
130 AT_CLEANUP
131
132 dnl This is really bare-bones.
133 dnl It at least checks request and reply serialization and deserialization.
134 AT_SETUP([ofproto - port-desc stats (OpenFlow 1.2)])
135 OVS_VSWITCHD_START
136 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn dump-ports-desc br0], [0], [stdout])
137 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
138 OFPST_PORT_DESC reply (OF1.2):
139  LOCAL(br0): addr:aa:55:aa:55:00:00
140      config:     PORT_DOWN
141      state:      LINK_DOWN
142      speed: 0 Mbps now, 0 Mbps max
143 ])
144 OVS_VSWITCHD_STOP
145 AT_CLEANUP
146
147 AT_SETUP([ofproto - port-desc stats (OpenFlow 1.5)])
148 OVS_VSWITCHD_START
149 ADD_OF_PORTS([br0], 1, 2, 3)
150 AT_CHECK([ovs-ofctl -F OXM-OpenFlow15 -O OpenFlow15 -vwarn dump-ports-desc br0], [0], [stdout])
151 AT_CHECK([STRIP_XIDS stdout | sed 's/00:0./00:0x/'], [0], [dnl
152 OFPST_PORT_DESC reply (OF1.5):
153  1(p1): addr:aa:55:aa:55:00:0x
154      config:     PORT_DOWN
155      state:      LINK_DOWN
156      speed: 0 Mbps now, 0 Mbps max
157  2(p2): addr:aa:55:aa:55:00:0x
158      config:     PORT_DOWN
159      state:      LINK_DOWN
160      speed: 0 Mbps now, 0 Mbps max
161  3(p3): addr:aa:55:aa:55:00:0x
162      config:     PORT_DOWN
163      state:      LINK_DOWN
164      speed: 0 Mbps now, 0 Mbps max
165  LOCAL(br0): addr:aa:55:aa:55:00:0x
166      config:     PORT_DOWN
167      state:      LINK_DOWN
168      speed: 0 Mbps now, 0 Mbps max
169 ])
170 AT_CHECK([ovs-ofctl -F OXM-OpenFlow15 -O OpenFlow15 -vwarn dump-ports-desc br0 2], [0], [stdout])
171 AT_CHECK([STRIP_XIDS stdout | sed 's/00:0./00:0x/'], [0], [dnl
172 OFPST_PORT_DESC reply (OF1.5):
173  2(p2): addr:aa:55:aa:55:00:0x
174      config:     PORT_DOWN
175      state:      LINK_DOWN
176      speed: 0 Mbps now, 0 Mbps max
177 ])
178 OVS_VSWITCHD_STOP
179 AT_CLEANUP
180
181 dnl This is really bare-bones.
182 dnl It at least checks request and reply serialization and deserialization.
183 AT_SETUP([ofproto - queue stats - (OpenFlow 1.0)])
184 OVS_VSWITCHD_START
185 AT_CHECK([ovs-ofctl -vwarn queue-stats br0], [0], [stdout])
186 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
187 OFPST_QUEUE reply: 0 queues
188 ])
189 AT_CHECK([ovs-ofctl -vwarn queue-stats br0 ANY 5], [0],
190   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_QUEUE
191 OFPST_QUEUE request (xid=0x2):port=ANY queue=5
192 ])
193 AT_CHECK([ovs-ofctl -vwarn queue-stats br0 10], [0],
194   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_PORT
195 OFPST_QUEUE request (xid=0x2):port=10 queue=ALL
196 ])
197 OVS_VSWITCHD_STOP
198 AT_CLEANUP
199
200 AT_SETUP([ofproto - queue stats - (OpenFlow 1.2)])
201 OVS_VSWITCHD_START
202 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn queue-stats br0], [0], [stdout])
203 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
204 OFPST_QUEUE reply (OF1.2): 0 queues
205 ])
206 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn queue-stats br0 ALL 5], [0],
207   [OFPT_ERROR (OF1.2) (xid=0x2): OFPQOFC_BAD_QUEUE
208 OFPST_QUEUE request (OF1.2) (xid=0x2):port=ANY queue=5
209 ])
210 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn queue-stats br0 10], [0],
211   [OFPT_ERROR (OF1.2) (xid=0x2): OFPQOFC_BAD_PORT
212 OFPST_QUEUE request (OF1.2) (xid=0x2):port=10 queue=ALL
213 ])
214 OVS_VSWITCHD_STOP
215 AT_CLEANUP
216
217 AT_SETUP([ofproto - queue stats - (OpenFlow 1.4)])
218 OVS_VSWITCHD_START
219 AT_CHECK([ovs-ofctl -O OpenFlow14 -vwarn queue-stats br0], [0], [stdout])
220 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
221 OFPST_QUEUE reply (OF1.4): 0 queues
222 ])
223 AT_CHECK([ovs-ofctl -O OpenFlow14 -vwarn queue-stats br0 ALL 5], [0],
224   [OFPT_ERROR (OF1.4) (xid=0x2): OFPQOFC_BAD_QUEUE
225 OFPST_QUEUE request (OF1.4) (xid=0x2):port=ANY queue=5
226 ])
227 AT_CHECK([ovs-ofctl -O OpenFlow14 -vwarn queue-stats br0 10], [0],
228   [OFPT_ERROR (OF1.4) (xid=0x2): OFPQOFC_BAD_PORT
229 OFPST_QUEUE request (OF1.4) (xid=0x2):port=10 queue=ALL
230 ])
231 OVS_VSWITCHD_STOP
232 AT_CLEANUP
233
234 dnl This is really bare-bones.
235 dnl It at least checks request and reply serialization and deserialization.
236 AT_SETUP([ofproto - queue configuration - (OpenFlow 1.0)])
237 OVS_VSWITCHD_START
238 ADD_OF_PORTS([br0], [1], [2])
239 AT_CHECK([ovs-ofctl queue-get-config br0 1], [0], [stdout])
240 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
241 OFPT_QUEUE_GET_CONFIG_REPLY: port=1
242 ])
243 AT_CHECK([ovs-ofctl queue-get-config br0 10], [0],
244   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_PORT
245 OFPT_QUEUE_GET_CONFIG_REQUEST (xid=0x2): port=10
246 ])
247 OVS_VSWITCHD_STOP
248 AT_CLEANUP
249
250 AT_SETUP([ofproto - queue configuration - (OpenFlow 1.2)])
251 OVS_VSWITCHD_START
252 ADD_OF_PORTS([br0], [1], [2])
253 AT_CHECK([ovs-ofctl -O OpenFlow12 queue-get-config br0 1], [0], [stdout])
254 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
255 OFPT_QUEUE_GET_CONFIG_REPLY (OF1.2): port=1
256 ])
257 AT_CHECK([ovs-ofctl -O OpenFlow12 queue-get-config br0 10], [0],
258   [OFPT_ERROR (OF1.2) (xid=0x2): OFPQOFC_BAD_PORT
259 OFPT_QUEUE_GET_CONFIG_REQUEST (OF1.2) (xid=0x2): port=10
260 ])
261 OVS_VSWITCHD_STOP
262 AT_CLEANUP
263
264 dnl This is really bare-bones.
265 dnl It at least checks request and reply serialization and deserialization.
266 AT_SETUP([ofproto - del group])
267 OVS_VSWITCHD_START
268 AT_DATA([groups.txt], [dnl
269 group_id=1234,type=all,bucket=output:10
270 group_id=1235,type=all,bucket=output:10
271 ])
272 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-groups br0 groups.txt])
273 AT_CHECK([ovs-ofctl -F OXM-OpenFlow15 -O OpenFlow15 -vwarn dump-groups br0 1234], [0], [stdout])
274 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
275 OFPST_GROUP_DESC reply (OF1.5):
276  group_id=1234,type=all,bucket=actions=output:10
277 ])
278 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn del-groups br0 group_id=1234])
279 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-groups br0], [0], [stdout])
280 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
281 OFPST_GROUP_DESC reply (OF1.1):
282  group_id=1235,type=all,bucket=actions=output:10
283 ])
284 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn del-groups br0 group_id=1234])
285 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-groups br0], [0], [stdout])
286 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
287 OFPST_GROUP_DESC reply (OF1.1):
288  group_id=1235,type=all,bucket=actions=output:10
289 ])
290 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn del-groups br0], [0])
291 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-groups br0], [0], [stdout])
292 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
293 OFPST_GROUP_DESC reply (OF1.1):
294 ])
295 OVS_VSWITCHD_STOP
296 AT_CLEANUP
297
298 dnl This is really bare-bones.
299 dnl It at least checks request and reply serialization and deserialization.
300 AT_SETUP([ofproto - del group deletes flows])
301 OVS_VSWITCHD_START
302 AT_DATA([groups.txt], [dnl
303 group_id=1234,type=all,bucket=output:10
304 group_id=1235,type=all,bucket=output:10
305 ])
306 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-groups br0 groups.txt])
307 AT_DATA([flows.txt], [dnl
308 tcp actions=group:1234
309 udp actions=group:1235
310 ])
311 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flows br0 flows.txt])
312 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-flows br0 | ofctl_strip | sort],
313 [0], [dnl
314  tcp actions=group:1234
315  udp actions=group:1235
316 OFPST_FLOW reply (OF1.1):
317 ])
318 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn del-groups br0 group_id=1234])
319 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-flows br0 | ofctl_strip | sort],
320 [0], [dnl
321  udp actions=group:1235
322 OFPST_FLOW reply (OF1.1):
323 ])
324 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn del-groups br0 group_id=1234])
325 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-flows br0 | ofctl_strip | sort],
326 [0], [dnl
327  udp actions=group:1235
328 OFPST_FLOW reply (OF1.1):
329 ])
330 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn del-groups br0])
331 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-flows br0 | ofctl_strip | sort],
332 [0], [dnl
333 OFPST_FLOW reply (OF1.1):
334 ])
335 OVS_VSWITCHD_STOP
336 AT_CLEANUP
337
338 dnl This is really bare-bones.
339 dnl It at least checks request and reply serialization and deserialization.
340 AT_SETUP([ofproto - flow mod checks group availability])
341 OVS_VSWITCHD_START
342 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-group br0 group_id=1234,type=all,bucket=output:10])
343 AT_DATA([flows.txt], [dnl
344 tcp actions=group:1234
345 udp actions=group:1235
346 ])
347 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=group:1234'])
348 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=group:1235'], [1], [], [stderr])
349
350 # The output should look like this:
351 #
352 # 00000000  02 0e 00 98 00 00 00 02-00 00 00 00 00 00 00 00 |................|
353 # 00000010  00 00 00 00 00 00 00 00-ff 00 00 00 00 00 80 00 |................|
354 # 00000020  ff ff ff ff ff ff ff ff-ff ff ff ff 00 00 00 00 |................|
355 # 00000030  00 00 00 58 00 00 00 00-00 00 03 d7 00 00 00 00 |...X............|
356 #
357 # This 'sed' command captures the error message but drops details.
358 AT_CHECK([sed '/truncated/d
359 /^000000.0/d' stderr | STRIP_XIDS], [0],
360   [OFPT_ERROR (OF1.1): OFPBAC_BAD_OUT_GROUP
361 OFPT_FLOW_MOD (OF1.1):
362 ])
363 OVS_VSWITCHD_STOP
364 AT_CLEANUP
365
366 dnl This is really bare-bones.
367 dnl It at least checks request and reply serialization and deserialization.
368 AT_SETUP([ofproto - group description])
369 OVS_VSWITCHD_START
370 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-group br0 group_id=1234,type=all,bucket=output:10], [0], [stdout])
371 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-groups br0], [0], [stdout])
372 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
373 OFPST_GROUP_DESC reply (OF1.1):
374  group_id=1234,type=all,bucket=actions=output:10
375 ])
376 OVS_VSWITCHD_STOP
377 AT_CLEANUP
378
379 dnl This is really bare-bones.
380 dnl It at least checks request and reply serialization and deserialization.
381 AT_SETUP([ofproto - group description])
382 OVS_VSWITCHD_START
383 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-group br0 group_id=1234,type=all,bucket=output:10])
384 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-groups br0], [0], [stdout])
385 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
386 OFPST_GROUP_DESC reply (OF1.1):
387  group_id=1234,type=all,bucket=actions=output:10
388 ])
389 OVS_VSWITCHD_STOP
390 AT_CLEANUP
391
392 dnl This is really bare-bones.
393 dnl It at least checks request and reply serialization and deserialization.
394 AT_SETUP([ofproto - group features])
395 OVS_VSWITCHD_START
396 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn dump-group-features br0], [0], [stdout])
397 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
398 OFPST_GROUP_FEATURES reply (OF1.2):
399  Group table:
400     Types:  0x0
401     Capabilities:  0x7
402 ])
403 OVS_VSWITCHD_STOP
404 AT_CLEANUP
405
406 dnl This is really bare-bones.
407 dnl It at least checks request and reply serialization and deserialization.
408 AT_SETUP([ofproto - group stats])
409 OVS_VSWITCHD_START
410 AT_DATA([groups.txt], [dnl
411 group_id=1234,type=all,bucket=output:10
412 group_id=1235,type=all,bucket=output:10
413 ])
414 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-groups br0 groups.txt])
415 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=group:1234'])
416 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-group-stats br0 group_id=1234], [0], [stdout])
417 AT_CHECK([STRIP_XIDS stdout | sort], [0], [dnl
418  group_id=1234,ref_count=1,packet_count=0,byte_count=0,bucket0:packet_count=0,byte_count=0
419 OFPST_GROUP reply (OF1.1):
420 ])
421 AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn dump-group-stats br0], [0], [stdout])
422 AT_CHECK([STRIP_XIDS stdout | sort], [0], [dnl
423  group_id=1234,ref_count=1,packet_count=0,byte_count=0,bucket0:packet_count=0,byte_count=0
424  group_id=1235,ref_count=0,packet_count=0,byte_count=0,bucket0:packet_count=0,byte_count=0
425 OFPST_GROUP reply (OF1.1):
426 ])
427 OVS_VSWITCHD_STOP
428 AT_CLEANUP
429
430 AT_SETUP([ofproto - mod-port (OpenFlow 1.0)])
431 OVS_VSWITCHD_START
432 for command_config_state in \
433     'up 0 0' \
434     'noflood NO_FLOOD 0' \
435     'down PORT_DOWN,NO_FLOOD LINK_DOWN' \
436     'flood PORT_DOWN LINK_DOWN' \
437     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
438     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
439     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
440     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
441     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
442     'up NO_RECV 0' \
443     'receive 0 0'
444 do
445     set $command_config_state
446     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
447     AT_CHECK([ovs-ofctl -vwarn mod-port br0 br0 $command])
448     AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
449     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
450 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
451 n_tables:254, n_buffers:256
452 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
453 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
454  LOCAL(br0): addr:aa:55:aa:55:00:00
455      config:     $config
456      state:      $state
457      speed: 0 Mbps now, 0 Mbps max
458 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
459 ])
460 done
461 OVS_VSWITCHD_STOP
462 AT_CLEANUP
463
464 AT_SETUP([ofproto - mod-port (OpenFlow 1.2)])
465 OVS_VSWITCHD_START
466 for command_config_state in \
467     'up 0 0' \
468     'down PORT_DOWN LINK_DOWN' \
469     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
470     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
471     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
472     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
473     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
474     'up NO_RECV 0' \
475     'receive 0 0'
476 do
477     set $command_config_state
478     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
479     AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn mod-port br0 br0 $command])
480     AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn show br0], [0], [stdout])
481     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
482 OFPT_FEATURES_REPLY (OF1.2): dpid:fedcba9876543210
483 n_tables:254, n_buffers:256
484 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS
485  LOCAL(br0): addr:aa:55:aa:55:00:00
486      config:     $config
487      state:      $state
488      speed: 0 Mbps now, 0 Mbps max
489 OFPT_GET_CONFIG_REPLY (OF1.2): frags=normal miss_send_len=0
490 ])
491 done
492 OVS_VSWITCHD_STOP
493 AT_CLEANUP
494
495 AT_SETUP([ofproto - mod-port (OpenFlow 1.4)])
496 OVS_VSWITCHD_START
497 for command_config_state in \
498     'up 0 0' \
499     'down PORT_DOWN LINK_DOWN' \
500     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
501     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
502     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
503     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
504     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
505     'up NO_RECV 0' \
506     'receive 0 0'
507 do
508     set $command_config_state
509     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
510     AT_CHECK([ovs-ofctl -O OpenFlow14 -vwarn mod-port br0 br0 $command])
511     AT_CHECK([ovs-ofctl -O OpenFlow14 -vwarn show br0], [0], [stdout])
512     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
513 OFPT_FEATURES_REPLY (OF1.4): dpid:fedcba9876543210
514 n_tables:254, n_buffers:256
515 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS
516 OFPST_PORT_DESC reply (OF1.4):
517  LOCAL(br0): addr:aa:55:aa:55:00:00
518      config:     $config
519      state:      $state
520      speed: 0 Mbps now, 0 Mbps max
521 OFPT_GET_CONFIG_REPLY (OF1.4): frags=normal miss_send_len=0
522 ])
523 done
524 OVS_VSWITCHD_STOP
525 AT_CLEANUP
526
527 AT_SETUP([ofproto - basic flow_mod commands (NXM)])
528 OVS_VSWITCHD_START
529 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
530 ])
531 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl add-flows br0 -])
532 AT_CHECK([ovs-ofctl add-flow br0 in_port=1,actions=2])
533 AT_CHECK([ovs-ofctl -F nxm add-flow br0 table=1,in_port=4,actions=3])
534 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
535  in_port=1 actions=output:2
536  in_port=2 actions=output:1
537  table=1, in_port=4 actions=output:3
538 NXST_FLOW reply:
539 ])
540 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
541 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
542 ])
543 AT_CHECK([ovs-ofctl del-flows br0])
544 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
545 ])
546 OVS_VSWITCHD_STOP
547 AT_CLEANUP
548
549 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.0)])
550 OVS_VSWITCHD_START
551 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
552 ])
553 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl -F openflow10 add-flows br0 -])
554 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 in_port=1,actions=2])
555 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 table=1,in_port=4,actions=3])
556 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
557  in_port=1 actions=output:2
558  in_port=2 actions=output:1
559  table=1, in_port=4 actions=output:3
560 OFPST_FLOW reply:
561 ])
562 AT_CHECK([ovs-ofctl -F openflow10 dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
563 OFPST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
564 ])
565 AT_CHECK([ovs-ofctl -F openflow10 del-flows br0])
566 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
567 ])
568 OVS_VSWITCHD_STOP
569 AT_CLEANUP
570
571 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.1)])
572 OVS_VSWITCHD_START
573 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.1):
574 ])
575 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl -O OpenFlow11 add-flows br0 -])
576 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 in_port=1,actions=2])
577 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 table=1,in_port=4,actions=3])
578 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
579  in_port=1 actions=output:2
580  in_port=2 actions=output:1
581  table=1, in_port=4 actions=output:3
582 OFPST_FLOW reply (OF1.1):
583 ])
584 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
585 OFPST_AGGREGATE reply (OF1.1): packet_count=0 byte_count=0 flow_count=2
586 ])
587 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0])
588 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.1):
589  table=1, in_port=4 actions=output:3
590 ])
591 OVS_VSWITCHD_STOP
592 AT_CLEANUP
593
594 AT_SETUP([ofproto - flow_mod negative test (OpenFlow 1.1)])
595 OVS_VSWITCHD_START(
596   [set bridge br0 protocols=OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13])
597 AT_CHECK([ovs-ofctl add-flow -O OpenFlow11 br0 table=1,action=goto_table:2])
598
599 # The error message here actually comes from ovs-ofctl, not from ovs-vswitchd,
600 # but at least it's the same code in ofpacts_check() that issues the error.
601 AT_CHECK([ovs-ofctl add-flow -O OpenFlow11 br0 table=1,action=goto_table:1],
602   [1], [],
603   [ovs-ofctl: actions are invalid with specified match (OFPBIC_BAD_TABLE_ID)
604 ])
605 OVS_VSWITCHD_STOP
606 AT_CLEANUP
607
608 AT_SETUP([ofproto - set-field flow_mod commands (NXM)])
609 OVS_VSWITCHD_START
610 AT_CHECK([ovs-ofctl add-flow br0 ipv6,table=1,in_port=3,actions=drop])
611 AT_CHECK([ovs-ofctl add-flow br0 ipv6,table=1,in_port=3,actions=set_field:fe80:0123:4567:890a:a6ba:dbff:fefe:59fa-\>ipv6_src])
612 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
613  table=1, ipv6,in_port=3 actions=load:0xa6badbfffefe59fa->NXM_NX_IPV6_SRC[[0..63]],load:0xfe8001234567890a->NXM_NX_IPV6_SRC[[64..127]]
614 NXST_FLOW reply:
615 ])
616 OVS_VSWITCHD_STOP
617 AT_CLEANUP
618
619 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.2)])
620 OVS_VSWITCHD_START
621 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.2):
622 ])
623 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl -O OpenFlow12 add-flows br0 -])
624 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=1,actions=2])
625 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 table=1,in_port=4,actions=3])
626 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
627  in_port=1 actions=output:2
628  in_port=2 actions=output:1
629  table=1, in_port=4 actions=output:3
630 OFPST_FLOW reply (OF1.2):
631 ])
632 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0])
633 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.2):
634 ])
635 OVS_VSWITCHD_STOP
636 AT_CLEANUP
637
638 AT_SETUP([ofproto - dump flows with cookie])
639 OVS_VSWITCHD_START
640 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
641 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
642 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
643 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
644  cookie=0x1, in_port=1 actions=output:1
645  cookie=0x2, in_port=2 actions=output:1
646  cookie=0x3, in_port=3 actions=output:1
647 NXST_FLOW reply:
648 ])
649 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
650 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=3
651 ])
652 AT_CHECK([ovs-ofctl dump-flows br0 cookie=0x3/-1 | ofctl_strip | sort], [0], [dnl
653  cookie=0x3, in_port=3 actions=output:1
654 NXST_FLOW reply:
655 ])
656 AT_CHECK([ovs-ofctl dump-aggregate br0 cookie=0x3/-1 | STRIP_XIDS], [0], [dnl
657 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=1
658 ])
659 OVS_VSWITCHD_STOP
660 AT_CLEANUP
661
662 AT_SETUP([ofproto - mod flow with cookie change (OpenFlow 1.0)])
663 OVS_VSWITCHD_START
664 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 cookie=0x1,in_port=1,actions=1])
665 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
666  cookie=0x1, in_port=1 actions=output:1
667 OFPST_FLOW reply:
668 ])
669
670 AT_CHECK([ovs-ofctl -F openflow10 mod-flows br0 cookie=0x2,in_port=1,actions=1])
671 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
672  cookie=0x2, in_port=1 actions=output:1
673 OFPST_FLOW reply:
674 ])
675 OVS_VSWITCHD_STOP
676 AT_CLEANUP
677
678 AT_SETUP([ofproto - mod flow with cookie change (NXM)])
679 OVS_VSWITCHD_START
680 AT_CHECK([ovs-ofctl -F nxm add-flow br0 cookie=0x1,in_port=1,actions=1])
681 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
682  cookie=0x1, in_port=1 actions=output:1
683 NXST_FLOW reply:
684 ])
685
686 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x2,in_port=1,actions=1])
687 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
688  cookie=0x2, in_port=1 actions=output:1
689 NXST_FLOW reply:
690 ])
691 OVS_VSWITCHD_STOP
692 AT_CLEANUP
693
694 AT_SETUP([ofproto - no mod flow with cookie change (OpenFlow 1.1)])
695 OVS_VSWITCHD_START
696 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
697 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
698  cookie=0x1, in_port=1 actions=output:1
699 OFPST_FLOW reply (OF1.1):
700 ])
701 AT_CHECK([ovs-ofctl -O OpenFlow11 mod-flows br0 cookie=0x2,in_port=1,actions=1])
702 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
703  cookie=0x1, in_port=1 actions=output:1
704 OFPST_FLOW reply (OF1.1):
705 ])
706 OVS_VSWITCHD_STOP
707 AT_CLEANUP
708
709 dnl The OpenFlow 1.2 spec states that the cookie may not be modified
710 AT_SETUP([ofproto - no mod flow with cookie change (OpenFlow 1.2)])
711 OVS_VSWITCHD_START
712 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
713 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
714  cookie=0x1, in_port=1 actions=output:1
715 OFPST_FLOW reply (OF1.2):
716 ])
717
718 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 cookie=0x2,in_port=1,actions=1])
719 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
720  cookie=0x1, in_port=1 actions=output:1
721 OFPST_FLOW reply (OF1.2):
722 ])
723 OVS_VSWITCHD_STOP
724 AT_CLEANUP
725
726 AT_SETUP([ofproto - mod flows based on cookie mask (OpenFlow 1.0)])
727 OVS_VSWITCHD_START
728 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
729 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=1])
730 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=1])
731 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
732  cookie=0x1, in_port=1 actions=output:1
733  cookie=0x1, in_port=2 actions=output:1
734  cookie=0x2, in_port=3 actions=output:1
735 NXST_FLOW reply:
736 ])
737
738 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x1/0xff,actions=4])
739 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
740  cookie=0x1, in_port=1 actions=output:4
741  cookie=0x1, in_port=2 actions=output:4
742  cookie=0x2, in_port=3 actions=output:1
743 NXST_FLOW reply:
744 ])
745 OVS_VSWITCHD_STOP
746 AT_CLEANUP
747
748 AT_SETUP([ofproto - mod flows based on cookie mask (OpenFlow 1.1)])
749 OVS_VSWITCHD_START
750 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
751 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=2,actions=1])
752 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x2,in_port=3,actions=1])
753 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
754  cookie=0x1, in_port=1 actions=output:1
755  cookie=0x1, in_port=2 actions=output:1
756  cookie=0x2, in_port=3 actions=output:1
757 OFPST_FLOW reply (OF1.1):
758 ])
759
760 AT_CHECK([ovs-ofctl -O OpenFlow11 mod-flows br0 cookie=0x1/0xff,actions=4])
761 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
762  cookie=0x1, in_port=1 actions=output:4
763  cookie=0x1, in_port=2 actions=output:4
764  cookie=0x2, in_port=3 actions=output:1
765 OFPST_FLOW reply (OF1.1):
766 ])
767 OVS_VSWITCHD_STOP
768 AT_CLEANUP
769
770 AT_SETUP([ofproto - mod flows based on cookie mask (OpenFlow 1.2)])
771 OVS_VSWITCHD_START
772 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
773 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=2,actions=1])
774 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x2,in_port=3,actions=1])
775 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
776  cookie=0x1, in_port=1 actions=output:1
777  cookie=0x1, in_port=2 actions=output:1
778  cookie=0x2, in_port=3 actions=output:1
779 OFPST_FLOW reply (OF1.2):
780 ])
781
782 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 cookie=0x1/0xff,actions=4])
783 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
784  cookie=0x1, in_port=1 actions=output:4
785  cookie=0x1, in_port=2 actions=output:4
786  cookie=0x2, in_port=3 actions=output:1
787 OFPST_FLOW reply (OF1.2):
788 ])
789 OVS_VSWITCHD_STOP
790 AT_CLEANUP
791
792 dnl The OpenFlow 1.2 spec states that the cookie may not be modified
793 AT_SETUP([ofproto - mod flows based on cookie mask with cookie change])
794 OVS_VSWITCHD_START
795 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
796 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=1])
797 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=1])
798 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
799  cookie=0x1, in_port=1 actions=output:1
800  cookie=0x1, in_port=2 actions=output:1
801  cookie=0x2, in_port=3 actions=output:1
802 NXST_FLOW reply:
803 ])
804
805 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/-1,cookie=4,actions=4])
806 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
807  cookie=0x2, in_port=3 actions=output:1
808  cookie=0x4, in_port=1 actions=output:4
809  cookie=0x4, in_port=2 actions=output:4
810 NXST_FLOW reply:
811 ])
812 OVS_VSWITCHD_STOP
813 AT_CLEANUP
814
815 AT_SETUP([ofproto - mod flow with cookie miss (mask==0) - NXM])
816 OVS_VSWITCHD_START
817 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 in_port=1,actions=1])
818 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
819  in_port=1 actions=output:1
820 NXST_FLOW reply:
821 ])
822 OVS_VSWITCHD_STOP
823 AT_CLEANUP
824
825 AT_SETUP([ofproto - mod flow with cookie miss (mask==0) - OF1.1])
826 OVS_VSWITCHD_START
827 AT_CHECK([ovs-ofctl -O openflow11 mod-flows br0 in_port=1,actions=1])
828 AT_CHECK([ovs-ofctl -O openflow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
829  in_port=1 actions=output:1
830 OFPST_FLOW reply (OF1.1):
831 ])
832 OVS_VSWITCHD_STOP
833 AT_CLEANUP
834
835 AT_SETUP([ofproto - mod flow with cookie miss (mask==0) - OF1.2])
836 OVS_VSWITCHD_START
837 AT_CHECK([ovs-ofctl -O openflow12 mod-flows br0 in_port=1,actions=1])
838 AT_CHECK([ovs-ofctl -O openflow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
839 OFPST_FLOW reply (OF1.2):
840 ])
841 OVS_VSWITCHD_STOP
842 AT_CLEANUP
843
844 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0) - NXM])
845 OVS_VSWITCHD_START
846 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/1,in_port=1,actions=1])
847 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
848 NXST_FLOW reply:
849 ])
850 OVS_VSWITCHD_STOP
851 AT_CLEANUP
852
853 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0) - OF1.1])
854 OVS_VSWITCHD_START
855 AT_CHECK([ovs-ofctl -O openflow11 mod-flows br0 cookie=1/1,in_port=1,actions=1])
856 AT_CHECK([ovs-ofctl -O openflow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
857 OFPST_FLOW reply (OF1.1):
858 ])
859 OVS_VSWITCHD_STOP
860 AT_CLEANUP
861
862 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0) - OF1.2])
863 OVS_VSWITCHD_START
864 AT_CHECK([ovs-ofctl -O openflow12 mod-flows br0 cookie=1/1,in_port=1,actions=1])
865 AT_CHECK([ovs-ofctl -O openflow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
866 OFPST_FLOW reply (OF1.2):
867 ])
868 OVS_VSWITCHD_STOP
869 AT_CLEANUP
870
871 AT_SETUP([ofproto - del flows with cookies])
872 OVS_VSWITCHD_START
873 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
874 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
875 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
876 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
877  cookie=0x1, in_port=1 actions=output:1
878  cookie=0x2, in_port=2 actions=output:1
879  cookie=0x3, in_port=3 actions=output:1
880 NXST_FLOW reply:
881 ])
882
883 AT_CHECK([ovs-ofctl del-flows br0])
884 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
885 NXST_FLOW reply:
886 ])
887 OVS_VSWITCHD_STOP
888 AT_CLEANUP
889
890 AT_SETUP([ofproto - del flows based on cookie])
891 OVS_VSWITCHD_START
892 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
893 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
894 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
895 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
896  cookie=0x1, in_port=1 actions=output:1
897  cookie=0x2, in_port=2 actions=output:1
898  cookie=0x3, in_port=3 actions=output:1
899 NXST_FLOW reply:
900 ])
901
902 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/-1])
903 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
904  cookie=0x1, in_port=1 actions=output:1
905  cookie=0x2, in_port=2 actions=output:1
906 NXST_FLOW reply:
907 ])
908 OVS_VSWITCHD_STOP
909 AT_CLEANUP
910
911 AT_SETUP([ofproto - del flows based on cookie mask])
912 OVS_VSWITCHD_START
913 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
914 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
915 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
916 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
917  cookie=0x1, in_port=1 actions=output:1
918  cookie=0x2, in_port=2 actions=output:1
919  cookie=0x3, in_port=3 actions=output:1
920 NXST_FLOW reply:
921 ])
922 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/0x1])
923 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
924  cookie=0x2, in_port=2 actions=output:1
925 NXST_FLOW reply:
926 ])
927 OVS_VSWITCHD_STOP
928 AT_CLEANUP
929
930 AT_SETUP([ofproto - del flows based on table id (NXM)])
931 OVS_VSWITCHD_START
932 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
933 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
934 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
935  cookie=0x1, in_port=1 actions=output:1
936  cookie=0x2, table=1, in_port=2 actions=output:1
937 NXST_FLOW reply:
938 ])
939 AT_CHECK([ovs-ofctl del-flows br0 table=0])
940 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
941  cookie=0x2, table=1, in_port=2 actions=output:1
942 NXST_FLOW reply:
943 ])
944 AT_CHECK([ovs-ofctl del-flows br0 table=1])
945 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
946 NXST_FLOW reply:
947 ])
948 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
949 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
950 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
951  cookie=0x1, in_port=1 actions=output:1
952  cookie=0x2, table=1, in_port=2 actions=output:1
953 NXST_FLOW reply:
954 ])
955 AT_CHECK([ovs-ofctl del-flows br0])
956 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
957 NXST_FLOW reply:
958 ])
959 OVS_VSWITCHD_STOP
960 AT_CLEANUP
961
962 AT_SETUP([ofproto - del flows based on table id (OpenFlow 1.1)])
963 OVS_VSWITCHD_START
964 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
965 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
966 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
967  cookie=0x1, in_port=1 actions=output:1
968  cookie=0x2, table=1, in_port=2 actions=output:1
969 OFPST_FLOW reply (OF1.1):
970 ])
971 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0 table=0])
972 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
973  cookie=0x2, table=1, in_port=2 actions=output:1
974 OFPST_FLOW reply (OF1.1):
975 ])
976 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0 table=1])
977 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
978 OFPST_FLOW reply (OF1.1):
979 ])
980 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
981 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
982 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
983  cookie=0x1, in_port=1 actions=output:1
984  cookie=0x2, table=1, in_port=2 actions=output:1
985 OFPST_FLOW reply (OF1.1):
986 ])
987 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0])
988 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [dnl
989 OFPST_FLOW reply (OF1.1):
990  cookie=0x2, table=1, in_port=2 actions=output:1
991 ])
992 OVS_VSWITCHD_STOP
993 AT_CLEANUP
994
995 AT_SETUP([ofproto - del flows based on table id (OpenFlow 1.2)])
996 OVS_VSWITCHD_START
997 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
998 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
999 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1000  cookie=0x1, in_port=1 actions=output:1
1001  cookie=0x2, table=1, in_port=2 actions=output:1
1002 OFPST_FLOW reply (OF1.2):
1003 ])
1004 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0 table=0])
1005 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1006  cookie=0x2, table=1, in_port=2 actions=output:1
1007 OFPST_FLOW reply (OF1.2):
1008 ])
1009 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0 table=1])
1010 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1011 OFPST_FLOW reply (OF1.2):
1012 ])
1013 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
1014 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
1015 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1016  cookie=0x1, in_port=1 actions=output:1
1017  cookie=0x2, table=1, in_port=2 actions=output:1
1018 OFPST_FLOW reply (OF1.2):
1019 ])
1020 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0])
1021 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1022 OFPST_FLOW reply (OF1.2):
1023 ])
1024 OVS_VSWITCHD_STOP
1025 AT_CLEANUP
1026
1027 AT_SETUP([ofproto - flow table configuration (OpenFlow 1.0)])
1028 OVS_VSWITCHD_START
1029 # Check the default configuration.
1030 (echo "OFPST_TABLE reply (xid=0x2): 254 tables
1031   0: classifier: wild=0x3fffff, max=1000000, active=0
1032                lookup=0, matched=0"
1033  x=1
1034  while test $x -lt 254; do
1035    printf "  %d: %-8s: wild=0x3fffff, max=1000000, active=0
1036                lookup=0, matched=0
1037 " $x table$x
1038    x=`expr $x + 1`
1039  done) > expout
1040 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
1041 # Change the configuration.
1042 AT_CHECK(
1043   [ovs-vsctl \
1044      -- --id=@t0 create Flow_Table name=main \
1045      -- --id=@t1 create Flow_Table flow-limit=1024 \
1046      -- set bridge br0 'flow_tables={1=@t1,0=@t0}' \
1047    | ${PERL} $srcdir/uuidfilt.pl],
1048   [0], [<0>
1049 <1>
1050 ])
1051 # Check that the configuration was updated.
1052 mv expout orig-expout
1053 (echo "OFPST_TABLE reply (xid=0x2): 254 tables
1054   0: main    : wild=0x3fffff, max=1000000, active=0
1055                lookup=0, matched=0
1056   1: table1  : wild=0x3fffff, max=  1024, active=0
1057                lookup=0, matched=0"
1058  tail -n +6 orig-expout) > expout
1059 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
1060 OVS_VSWITCHD_STOP
1061 AT_CLEANUP
1062
1063 AT_SETUP([ofproto - flow table configuration (OpenFlow 1.2)])
1064 OVS_VSWITCHD_START
1065 # Check the default configuration.
1066 (mid="wild=0xfffffffff, max=1000000,"
1067  tail="
1068                lookup=0, matched=0
1069                match=0xfffffffff, instructions=0x00000007, config=0x00000003
1070                write_actions=0x00000000, apply_actions=0x00000000
1071                write_setfields=0x0000000fffffffff
1072                apply_setfields=0x0000000fffffffff
1073                metadata_match=0xffffffffffffffff
1074                metadata_write=0xffffffffffffffff"
1075  echo "OFPST_TABLE reply (OF1.2) (xid=0x2): 254 tables
1076   0: classifier: $mid active=0$tail"
1077  x=1
1078  while test $x -lt 254; do
1079    printf "  %d: %-8s: $mid active=0$tail
1080 " $x table$x
1081    x=`expr $x + 1`
1082  done) > expout
1083 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-tables br0], [0], [expout])
1084 # Change the configuration.
1085 AT_CHECK(
1086   [ovs-vsctl \
1087      -- --id=@t0 create Flow_Table name=main \
1088      -- --id=@t1 create Flow_Table flow-limit=1024 \
1089      -- set bridge br0 'flow_tables={1=@t1,0=@t0}' \
1090    | ${PERL} $srcdir/uuidfilt.pl],
1091   [0], [<0>
1092 <1>
1093 ])
1094 # Check that the configuration was updated.
1095 mv expout orig-expout
1096 (echo "OFPST_TABLE reply (OF1.2) (xid=0x2): 254 tables
1097   0: main    : wild=0xfffffffff, max=1000000, active=0"
1098  tail -n +3 orig-expout | head -7
1099  echo "  1: table1  : wild=0xfffffffff, max=  1024, active=0"
1100  tail -n +11 orig-expout) > expout
1101 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-tables br0], [0], [expout])
1102 OVS_VSWITCHD_STOP
1103 AT_CLEANUP
1104
1105 AT_SETUP([ofproto - hard limits on flow table size (OpenFlow 1.0)])
1106 OVS_VSWITCHD_START
1107 # Configure a maximum of 4 flows.
1108 AT_CHECK(
1109   [ovs-vsctl \
1110      -- --id=@t0 create Flow_Table flow-limit=4 \
1111      -- set bridge br0 flow_tables:0=@t0 \
1112    | ${PERL} $srcdir/uuidfilt.pl],
1113   [0], [<0>
1114 ])
1115 # Add 4 flows.
1116 for in_port in 1 2 3 4; do
1117     ovs-ofctl add-flow br0 in_port=$in_port,actions=drop
1118 done
1119 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1120  in_port=1 actions=drop
1121  in_port=2 actions=drop
1122  in_port=3 actions=drop
1123  in_port=4 actions=drop
1124 NXST_FLOW reply:
1125 ])
1126 # Adding another flow will be refused.
1127 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop], [1], [], [stderr])
1128 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
1129   [OFPT_ERROR: OFPFMFC_TABLE_FULL
1130 ])
1131 # Also a mod-flow that would add a flow will be refused.
1132 AT_CHECK([ovs-ofctl mod-flows br0 in_port=5,actions=drop], [1], [], [stderr])
1133 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
1134   [OFPT_ERROR: OFPFMFC_TABLE_FULL
1135 ])
1136 # Replacing or modifying an existing flow is allowed.
1137 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
1138 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
1139 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1140  in_port=1 actions=drop
1141  in_port=2 actions=drop
1142  in_port=3 actions=output:1
1143  in_port=4 actions=NORMAL
1144 NXST_FLOW reply:
1145 ])
1146 OVS_VSWITCHD_STOP
1147 AT_CLEANUP
1148
1149 AT_SETUP([ofproto - hard limits on flow table size (OpenFlow 1.2)])
1150 OVS_VSWITCHD_START
1151 # Configure a maximum of 4 flows.
1152 AT_CHECK(
1153   [ovs-vsctl \
1154      -- --id=@t0 create Flow_Table flow-limit=4 \
1155      -- set bridge br0 flow_tables:0=@t0 \
1156    | ${PERL} $srcdir/uuidfilt.pl],
1157   [0], [<0>
1158 ])
1159 # Add 4 flows.
1160 for in_port in 1 2 3 4; do
1161     ovs-ofctl -O OpenFlow12 add-flow br0 in_port=$in_port,actions=drop
1162 done
1163 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1164  in_port=1 actions=drop
1165  in_port=2 actions=drop
1166  in_port=3 actions=drop
1167  in_port=4 actions=drop
1168 OFPST_FLOW reply (OF1.2):
1169 ])
1170 # Adding another flow will be refused.
1171 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=5,actions=drop], [1], [], [stderr])
1172 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
1173   [OFPT_ERROR (OF1.2): OFPFMFC_TABLE_FULL
1174 ])
1175 # Replacing or modifying an existing flow is allowed.
1176 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=4,actions=normal])
1177 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 in_port=3,actions=output:1])
1178 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1179  in_port=1 actions=drop
1180  in_port=2 actions=drop
1181  in_port=3 actions=output:1
1182  in_port=4 actions=NORMAL
1183 OFPST_FLOW reply (OF1.2):
1184 ])
1185 OVS_VSWITCHD_STOP
1186 AT_CLEANUP
1187
1188 AT_SETUP([ofproto - eviction upon table overflow (OpenFlow 1.0)])
1189 OVS_VSWITCHD_START
1190 # Configure a maximum of 4 flows.
1191 AT_CHECK(
1192   [ovs-vsctl \
1193      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
1194      -- set bridge br0 flow_tables:0=@t0 \
1195    | ${PERL} $srcdir/uuidfilt.pl],
1196   [0], [<0>
1197 ])
1198 # Add 4 flows.
1199 for in_port in 4 3 2 1; do
1200     ovs-ofctl add-flow br0 idle_timeout=${in_port}0,in_port=$in_port,actions=drop
1201 done
1202 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1203  idle_timeout=10, in_port=1 actions=drop
1204  idle_timeout=20, in_port=2 actions=drop
1205  idle_timeout=30, in_port=3 actions=drop
1206  idle_timeout=40, in_port=4 actions=drop
1207 NXST_FLOW reply:
1208 ])
1209 # Adding another flow will cause the one that expires soonest to be evicted.
1210 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop])
1211 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1212  idle_timeout=20, in_port=2 actions=drop
1213  idle_timeout=30, in_port=3 actions=drop
1214  idle_timeout=40, in_port=4 actions=drop
1215  in_port=5 actions=drop
1216 NXST_FLOW reply:
1217 ])
1218 # A mod-flow that adds a flow also causes eviction, but replacing or
1219 # modifying an existing flow doesn't.
1220 AT_CHECK([ovs-ofctl mod-flows br0 in_port=6,actions=drop])
1221 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
1222 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
1223 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1224  idle_timeout=30, in_port=3 actions=output:1
1225  in_port=4 actions=NORMAL
1226  in_port=5 actions=drop
1227  in_port=6 actions=drop
1228 NXST_FLOW reply:
1229 ])
1230 # Flows with no timeouts at all cannot be evicted.
1231 AT_CHECK([ovs-ofctl add-flow br0 in_port=7,actions=normal])
1232 AT_CHECK([ovs-ofctl add-flow br0 in_port=8,actions=drop], [1], [], [stderr])
1233 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
1234   [OFPT_ERROR: OFPFMFC_TABLE_FULL
1235 ])
1236 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1237  in_port=4 actions=NORMAL
1238  in_port=5 actions=drop
1239  in_port=6 actions=drop
1240  in_port=7 actions=NORMAL
1241 NXST_FLOW reply:
1242 ])
1243 OVS_VSWITCHD_STOP
1244 AT_CLEANUP
1245
1246 AT_SETUP([ofproto - eviction upon table overflow (OpenFlow 1.2)])
1247 OVS_VSWITCHD_START
1248 # Configure a maximum of 4 flows.
1249 AT_CHECK(
1250   [ovs-vsctl \
1251      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
1252      -- set bridge br0 flow_tables:0=@t0 \
1253    | ${PERL} $srcdir/uuidfilt.pl],
1254   [0], [<0>
1255 ])
1256 # Add 4 flows.
1257 for in_port in 4 3 2 1; do
1258     ovs-ofctl -O OpenFlow12 add-flow br0 idle_timeout=${in_port}0,in_port=$in_port,actions=drop
1259 done
1260 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1261  idle_timeout=10, in_port=1 actions=drop
1262  idle_timeout=20, in_port=2 actions=drop
1263  idle_timeout=30, in_port=3 actions=drop
1264  idle_timeout=40, in_port=4 actions=drop
1265 OFPST_FLOW reply (OF1.2):
1266 ])
1267 # Adding another flow will cause the one that expires soonest to be evicted.
1268 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=5,actions=drop])
1269 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1270  idle_timeout=20, in_port=2 actions=drop
1271  idle_timeout=30, in_port=3 actions=drop
1272  idle_timeout=40, in_port=4 actions=drop
1273  in_port=5 actions=drop
1274 OFPST_FLOW reply (OF1.2):
1275 ])
1276 # In Open Flow 1.2 a mod-flow does not ever add a flow and thus
1277 # has no effect on eviction
1278 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 in_port=6,actions=drop])
1279 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=4,actions=normal])
1280 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 in_port=3,actions=output:1])
1281 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1282  idle_timeout=20, in_port=2 actions=drop
1283  idle_timeout=30, in_port=3 actions=output:1
1284  in_port=4 actions=NORMAL
1285  in_port=5 actions=drop
1286 OFPST_FLOW reply (OF1.2):
1287 ])
1288 # Flows with no timeouts at all cannot be evicted.
1289 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=6,actions=drop])
1290 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=7,actions=normal])
1291 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=8,actions=drop], [1], [], [stderr])
1292 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
1293   [OFPT_ERROR (OF1.2): OFPFMFC_TABLE_FULL
1294 ])
1295 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1296  in_port=4 actions=NORMAL
1297  in_port=5 actions=drop
1298  in_port=6 actions=drop
1299  in_port=7 actions=NORMAL
1300 OFPST_FLOW reply (OF1.2):
1301 ])
1302 OVS_VSWITCHD_STOP
1303 AT_CLEANUP
1304
1305 AT_SETUP([ofproto - eviction upon table overflow, with fairness (OpenFlow 1.0)])
1306 OVS_VSWITCHD_START
1307 # Configure a maximum of 4 flows.
1308 AT_CHECK(
1309   [ovs-vsctl \
1310      -- --id=@t0 create Flow_Table name=evict flow-limit=4 \
1311                                    overflow-policy=evict \
1312                                    groups='"NXM_OF_IN_PORT[[]]"' \
1313      -- set bridge br0 flow_tables:0=@t0 \
1314    | ${PERL} $srcdir/uuidfilt.pl],
1315   [0], [<0>
1316 ])
1317 # Add 4 flows.
1318 ovs-ofctl add-flows br0 - <<EOF
1319 idle_timeout=10 in_port=2 dl_src=00:44:55:66:77:88 actions=drop
1320 idle_timeout=20 in_port=1 dl_src=00:11:22:33:44:55 actions=drop
1321 idle_timeout=30 in_port=1 dl_src=00:22:33:44:55:66 actions=drop
1322 idle_timeout=40 in_port=1 dl_src=00:33:44:55:66:77 actions=drop
1323 EOF
1324 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1325  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1326  idle_timeout=20, in_port=1,dl_src=00:11:22:33:44:55 actions=drop
1327  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1328  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1329 NXST_FLOW reply:
1330 ])
1331 # Adding another flow will cause the one that expires soonest within
1332 # the largest group (those with in_port=1) to be evicted.  In this
1333 # case this is not the same as the one that expires soonest overall
1334 # (which is what makes the test interesting):
1335 AT_CHECK([ovs-ofctl add-flow br0 in_port=2,dl_src=00:55:66:77:88:99,actions=drop])
1336 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1337  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1338  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1339  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1340  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1341 NXST_FLOW reply:
1342 ])
1343 # Enlarge the flow limit, change the eviction policy back to strictly
1344 # based on expiration, and and add some flows.
1345 AT_CHECK([ovs-vsctl set Flow_Table evict groups='[[]]' flow-limit=7])
1346 ovs-ofctl add-flows br0 - <<EOF
1347 idle_timeout=50 in_port=2 dl_src=00:66:77:88:99:aa actions=drop
1348 idle_timeout=60 in_port=2 dl_src=00:77:88:99:aa:bb actions=drop
1349 idle_timeout=70 in_port=2 dl_src=00:88:99:aa:bb:cc actions=drop
1350 EOF
1351 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1352  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1353  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1354  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1355  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1356  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1357  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1358  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1359 NXST_FLOW reply:
1360 ])
1361 # Adding another flow will cause the one that expires soonest overall
1362 # to be evicted.
1363 AT_CHECK([ovs-ofctl add-flow br0 'idle_timeout=80 in_port=2 dl_src=00:99:aa:bb:cc:dd actions=drop'])
1364 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1365  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1366  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1367  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1368  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1369  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1370  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1371  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1372 NXST_FLOW reply:
1373 ])
1374 # Reducing the flow limit also causes the flows that expire soonest
1375 # overall to be evicted.
1376 AT_CHECK([ovs-vsctl set Flow_Table evict flow-limit=4])
1377 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1378  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1379  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1380  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1381  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1382 NXST_FLOW reply:
1383 ])
1384 OVS_VSWITCHD_STOP
1385 AT_CLEANUP
1386
1387 AT_SETUP([ofproto - eviction upon table overflow, with fairness (OpenFlow 1.2)])
1388 OVS_VSWITCHD_START
1389 # Configure a maximum of 4 flows.
1390 AT_CHECK(
1391   [ovs-vsctl \
1392      -- --id=@t0 create Flow_Table name=evict flow-limit=4 \
1393                                    overflow-policy=evict \
1394                                    groups='"NXM_OF_IN_PORT[[]]"' \
1395      -- set bridge br0 flow_tables:0=@t0 \
1396    | ${PERL} $srcdir/uuidfilt.pl],
1397   [0], [<0>
1398 ])
1399 # Add 4 flows.
1400 ovs-ofctl -O OpenFlow12 add-flows br0 - <<EOF
1401 idle_timeout=10 in_port=2 dl_src=00:44:55:66:77:88 actions=drop
1402 idle_timeout=20 in_port=1 dl_src=00:11:22:33:44:55 actions=drop
1403 idle_timeout=30 in_port=1 dl_src=00:22:33:44:55:66 actions=drop
1404 idle_timeout=40 in_port=1 dl_src=00:33:44:55:66:77 actions=drop
1405 EOF
1406 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1407  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1408  idle_timeout=20, in_port=1,dl_src=00:11:22:33:44:55 actions=drop
1409  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1410  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1411 OFPST_FLOW reply (OF1.2):
1412 ])
1413 # Adding another flow will cause the one that expires soonest within
1414 # the largest group (those with in_port=1) to be evicted.  In this
1415 # case this is not the same as the one that expires soonest overall
1416 # (which is what makes the test interesting):
1417 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=2,dl_src=00:55:66:77:88:99,actions=drop])
1418 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1419  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1420  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1421  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1422  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1423 OFPST_FLOW reply (OF1.2):
1424 ])
1425 # Enlarge the flow limit, change the eviction policy back to strictly
1426 # based on expiration, and and add some flows.
1427 AT_CHECK([ovs-vsctl set Flow_Table evict groups='[[]]' flow-limit=7])
1428 ovs-ofctl -O OpenFlow12 add-flows br0 - <<EOF
1429 idle_timeout=50 in_port=2 dl_src=00:66:77:88:99:aa actions=drop
1430 idle_timeout=60 in_port=2 dl_src=00:77:88:99:aa:bb actions=drop
1431 idle_timeout=70 in_port=2 dl_src=00:88:99:aa:bb:cc actions=drop
1432 EOF
1433 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1434  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1435  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1436  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1437  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1438  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1439  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1440  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1441 OFPST_FLOW reply (OF1.2):
1442 ])
1443 # Adding another flow will cause the one that expires soonest overall
1444 # to be evicted.
1445 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 'idle_timeout=80 in_port=2 dl_src=00:99:aa:bb:cc:dd actions=drop'])
1446 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1447  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1448  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1449  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1450  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1451  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1452  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1453  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1454 OFPST_FLOW reply (OF1.2):
1455 ])
1456 # Reducing the flow limit also causes the flows that expire soonest
1457 # overall to be evicted.
1458 AT_CHECK([ovs-vsctl set Flow_Table evict flow-limit=4])
1459 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1460  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1461  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1462  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1463  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1464 OFPST_FLOW reply (OF1.2):
1465 ])
1466 OVS_VSWITCHD_STOP
1467 AT_CLEANUP
1468
1469 AT_SETUP([ofproto - eviction upon table overflow, with modified hard timeout])
1470 OVS_VSWITCHD_START
1471 # Configure a maximum of 4 flows.
1472 AT_CHECK(
1473   [ovs-vsctl \
1474      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
1475      -- set bridge br0 flow_tables:0=@t0 \
1476    | ${PERL} $srcdir/uuidfilt.pl],
1477   [0], [<0>
1478 ])
1479 ovs-appctl time/stop
1480 # Add 4 flows.
1481 for in_port in 4 3 2 1; do
1482     ovs-ofctl add-flow br0 hard_timeout=$((10 + in_port * 3)),in_port=$in_port,actions=drop
1483 done
1484 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1485  hard_timeout=13, in_port=1 actions=drop
1486  hard_timeout=16, in_port=2 actions=drop
1487  hard_timeout=19, in_port=3 actions=drop
1488  hard_timeout=22, in_port=4 actions=drop
1489 NXST_FLOW reply:
1490 ])
1491 # Sleep and modify the one that expires soonest
1492 ovs-appctl time/warp 5000
1493 AT_CHECK([ovs-ofctl mod-flows br0 in_port=1,actions=drop])
1494 # At this point the table would looks like:
1495 #  in_port   seconds to expire
1496 #     1            13
1497 #     2            11
1498 #     3            14
1499 #     4            17
1500 ovs-appctl time/warp 2000
1501 # Adding another flow will cause the one that expires soonest to be evicted.
1502 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop])
1503 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1504  hard_timeout=13, in_port=1 actions=drop
1505  hard_timeout=19, in_port=3 actions=drop
1506  hard_timeout=22, in_port=4 actions=drop
1507  in_port=5 actions=drop
1508 NXST_FLOW reply:
1509 ])
1510 OVS_VSWITCHD_STOP
1511 AT_CLEANUP
1512
1513 AT_SETUP([ofproto - eviction upon table overflow, with modified idle timeout])
1514 OVS_VSWITCHD_START([add-port br0 p1 -- set interface p1 type=dummy ofport_request=1])
1515 # Configure a maximum of 4 flows.
1516 AT_CHECK(
1517   [ovs-vsctl \
1518      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
1519      -- set bridge br0 flow_tables:0=@t0 \
1520    | ${PERL} $srcdir/uuidfilt.pl],
1521   [0], [<0>
1522 ])
1523 # Add 4 flows.
1524 for in_port in 4 3 2 1; do
1525     ovs-ofctl add-flow br0 idle_timeout=$((10 + in_port * 3)),in_port=$in_port,actions=drop
1526 done
1527 ovs-appctl time/stop
1528 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1529  idle_timeout=13, in_port=1 actions=drop
1530  idle_timeout=16, in_port=2 actions=drop
1531  idle_timeout=19, in_port=3 actions=drop
1532  idle_timeout=22, in_port=4 actions=drop
1533 NXST_FLOW reply:
1534 ])
1535 # Sleep and receive on the flow that expires soonest
1536 ovs-appctl time/warp 5000
1537 AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1)'])
1538 # At this point the table would looks like:
1539 #  in_port   seconds to expire
1540 #     1            13
1541 #     2            11
1542 #     3            14
1543 #     4            17
1544 ovs-appctl time/warp 2000
1545 # Adding another flow will cause the one that expires soonest to be evicted.
1546 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop])
1547 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1548  idle_timeout=19, in_port=3 actions=drop
1549  idle_timeout=22, in_port=4 actions=drop
1550  in_port=5 actions=drop
1551  n_packets=1, n_bytes=60, idle_timeout=13, in_port=1 actions=drop
1552 NXST_FLOW reply:
1553 ])
1554 OVS_VSWITCHD_STOP
1555 AT_CLEANUP
1556
1557 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.0)])
1558 OVS_VSWITCHD_START
1559 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
1560 check_async () {
1561     printf '\n\n--- check_async %d ---\n\n\n' $1
1562     shift
1563
1564     ovs-appctl -t ovs-ofctl ofctl/barrier
1565     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1566     : > expout
1567
1568     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
1569     ovs-ofctl -v packet-out br0 controller controller '0001020304050010203040501234'
1570     if test X"$1" = X"OFPR_ACTION"; then shift;
1571         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
1572 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
1573     fi
1574
1575     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
1576     ovs-ofctl -v packet-out br0 controller 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
1577     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
1578         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via no_match) data_len=14 (unbuffered)
1579 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
1580     fi
1581
1582     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
1583     ovs-ofctl packet-out br0 controller dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
1584     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
1585         echo >>expout "OFPT_PACKET_IN: total_len=76 in_port=CONTROLLER (via invalid_ttl) data_len=76 (unbuffered)
1586 udp,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:26:b9:8c:b0:f9,dl_dst=00:25:83:df:b4:00,nw_src=172.17.55.13,nw_dst=172.16.0.2,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=55155,tp_dst=53 udp_csum:8f6d"
1587     fi
1588
1589     # OFPT_PORT_STATUS, OFPPR_ADD
1590     ovs-vsctl add-port br0 test -- set Interface test type=dummy ofport_request=1
1591     if test X"$1" = X"OFPPR_ADD"; then shift;
1592         echo >>expout "OFPT_PORT_STATUS: ADD: 1(test): addr:aa:55:aa:55:00:0x
1593      config:     PORT_DOWN
1594      state:      LINK_DOWN
1595      speed: 0 Mbps now, 0 Mbps max"
1596     fi
1597
1598     # OFPT_PORT_STATUS, OFPPR_DELETE
1599     ovs-vsctl del-port br0 test
1600     if test X"$1" = X"OFPPR_DELETE"; then shift;
1601         echo >>expout "OFPT_PORT_STATUS: DEL: 1(test): addr:aa:55:aa:55:00:0x
1602      config:     PORT_DOWN
1603      state:      LINK_DOWN
1604      speed: 0 Mbps now, 0 Mbps max"
1605     fi
1606
1607     # OFPT_FLOW_REMOVED, OFPRR_DELETE
1608     ovs-ofctl add-flow br0 send_flow_rem,actions=drop
1609     ovs-ofctl --strict del-flows br0 ''
1610     if test X"$1" = X"OFPRR_DELETE"; then shift;
1611         echo >>expout "OFPT_FLOW_REMOVED:  reason=delete"
1612     fi
1613     AT_FAIL_IF([test X"$1" != X])
1614
1615     ovs-appctl -t ovs-ofctl ofctl/barrier
1616     echo >>expout "OFPT_BARRIER_REPLY:"
1617
1618     AT_CHECK(
1619       [[sed '
1620 s/ (xid=0x[0-9a-fA-F]*)//
1621 s/ *duration.*//
1622 s/00:0.$/00:0x/' < monitor.log]],
1623       [0], [expout])
1624 }
1625
1626 # It's a service connection so initially there should be no async messages.
1627 check_async 1
1628
1629 # Set miss_send_len to 128, turning on packet-ins for our service connection.
1630 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
1631 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1632
1633 # Set miss_send_len to 128 and enable invalid_ttl.
1634 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700040080
1635 check_async 3 OFPR_ACTION OFPR_INVALID_TTL OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1636
1637 # Become slave, which should disable everything except port status.
1638 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000002
1639 check_async 4 OFPPR_ADD OFPPR_DELETE
1640
1641 # Use NXT_SET_ASYNC_CONFIG to enable a patchwork of asynchronous messages.
1642 ovs-appctl -t ovs-ofctl ofctl/send 01040028000000020000232000000013000000020000000500000005000000020000000200000005
1643 check_async 5 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
1644
1645 # Set controller ID 123.
1646 ovs-appctl -t ovs-ofctl ofctl/send 01040018000000030000232000000014000000000000007b
1647 check_async 6 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
1648
1649 # Restore controller ID 0.
1650 ovs-appctl -t ovs-ofctl ofctl/send 010400180000000300002320000000140000000000000000
1651
1652 # Become master.
1653 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000001
1654 check_async 7 OFPR_ACTION OFPPR_ADD
1655
1656 ovs-appctl -t ovs-ofctl exit
1657 OVS_VSWITCHD_STOP
1658 AT_CLEANUP
1659
1660 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.2)])
1661 OVS_VSWITCHD_START
1662 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
1663 check_async () {
1664     printf '\n\n--- check_async %d ---\n\n\n' $1
1665     INDEX=$1
1666     shift
1667
1668     ovs-appctl -t ovs-ofctl ofctl/barrier
1669     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1670     : > expout
1671
1672     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
1673     ovs-ofctl -O OpenFlow12 -v packet-out br0 none controller '0001020304050010203040501234'
1674     if test X"$1" = X"OFPR_ACTION"; then shift;
1675         echo >>expout "OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
1676 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
1677     fi
1678
1679     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
1680     ovs-ofctl -O OpenFlow12 -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
1681     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
1682         echo >>expout "OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY (via no_match) data_len=14 (unbuffered)
1683 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
1684     fi
1685
1686     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
1687     ovs-ofctl -O OpenFlow12 packet-out br0 none dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
1688     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
1689         echo >>expout "OFPT_PACKET_IN (OF1.2): total_len=76 in_port=ANY (via invalid_ttl) data_len=76 (unbuffered)
1690 udp,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:26:b9:8c:b0:f9,dl_dst=00:25:83:df:b4:00,nw_src=172.17.55.13,nw_dst=172.16.0.2,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=55155,tp_dst=53 udp_csum:8f6d"
1691     fi
1692
1693     # OFPT_PORT_STATUS, OFPPR_ADD
1694     ovs-vsctl add-port br0 test -- set Interface test type=dummy
1695     if test X"$1" = X"OFPPR_ADD"; then shift;
1696         echo >>expout "OFPT_PORT_STATUS (OF1.2): ADD: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1697      config:     PORT_DOWN
1698      state:      LINK_DOWN
1699      speed: 0 Mbps now, 0 Mbps max"
1700     fi
1701
1702     # OFPT_PORT_STATUS, OFPPR_DELETE
1703     ovs-vsctl del-port br0 test
1704     if test X"$1" = X"OFPPR_DELETE"; then shift;
1705         echo >>expout "OFPT_PORT_STATUS (OF1.2): DEL: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1706      config:     PORT_DOWN
1707      state:      LINK_DOWN
1708      speed: 0 Mbps now, 0 Mbps max"
1709     fi
1710
1711     # OFPT_FLOW_REMOVED, OFPRR_DELETE
1712     ovs-ofctl -O OpenFlow12 add-flow br0 send_flow_rem,actions=drop
1713     ovs-ofctl -O OpenFlow12 --strict del-flows br0 ''
1714     if test X"$1" = X"OFPRR_DELETE"; then shift;
1715         echo >>expout "OFPT_FLOW_REMOVED (OF1.2):  reason=delete table_id=0"
1716     fi
1717     AT_FAIL_IF([test X"$1" != X])
1718
1719     ovs-appctl -t ovs-ofctl ofctl/barrier
1720     echo >>expout "OFPT_BARRIER_REPLY (OF1.2):"
1721
1722     AT_CHECK(
1723       [[sed '
1724 s/ (xid=0x[0-9a-fA-F]*)//
1725 s/ *duration.*//
1726 s/00:0.$/00:0x/' < monitor.log]],
1727       [0], [expout])
1728 }
1729
1730 # It's a service connection so initially there should be no async messages.
1731 check_async 1
1732
1733 # Set miss_send_len to 128, turning on packet-ins for our service connection.
1734 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
1735 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1736
1737 # Set miss_send_len to 128 and enable invalid_ttl.
1738 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700040080
1739 check_async 3 OFPR_ACTION OFPR_INVALID_TTL OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1740
1741 # Become slave (OF 1.2), which should disable everything except port status.
1742 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000200000003000000000000000000000001
1743 check_async 4 OFPPR_ADD OFPPR_DELETE
1744
1745 # Use NXT_SET_ASYNC_CONFIG to enable a patchwork of asynchronous messages.
1746 ovs-appctl -t ovs-ofctl ofctl/send 03040028000000020000232000000013000000020000000500000005000000020000000200000005
1747 check_async 5 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
1748
1749 # Set controller ID 123.
1750 ovs-appctl -t ovs-ofctl ofctl/send 03040018000000030000232000000014000000000000007b
1751 check_async 6 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
1752
1753 # Restore controller ID 0.
1754 ovs-appctl -t ovs-ofctl ofctl/send 030400180000000300002320000000140000000000000000
1755
1756 # Become master (OF 1.2).
1757 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000400000002000000000000000000000002
1758 check_async 7 OFPR_ACTION OFPPR_ADD
1759
1760 ovs-appctl -t ovs-ofctl exit
1761 OVS_VSWITCHD_STOP
1762 AT_CLEANUP
1763
1764 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.3)])
1765 OVS_VSWITCHD_START
1766 AT_CHECK([ovs-ofctl -O OpenFlow13 monitor br0 --detach --no-chdir --pidfile])
1767 check_async () {
1768     printf '\n\n--- check_async %d ---\n\n\n' $1
1769     INDEX=$1
1770     shift
1771
1772     ovs-appctl -t ovs-ofctl ofctl/barrier
1773     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1774     : > expout
1775
1776     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
1777     ovs-ofctl -O OpenFlow13 -v packet-out br0 none controller '0001020304050010203040501234'
1778     if test X"$1" = X"OFPR_ACTION"; then shift;
1779         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
1780 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
1781     fi
1782
1783     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
1784     ovs-ofctl -O OpenFlow13 -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
1785     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
1786         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=14 in_port=ANY (via no_match) data_len=14 (unbuffered)
1787 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
1788     fi
1789
1790     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
1791     ovs-ofctl -O OpenFlow13 packet-out br0 none dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
1792     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
1793         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=76 in_port=ANY (via invalid_ttl) data_len=76 (unbuffered)
1794 udp,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:26:b9:8c:b0:f9,dl_dst=00:25:83:df:b4:00,nw_src=172.17.55.13,nw_dst=172.16.0.2,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=55155,tp_dst=53 udp_csum:8f6d"
1795     fi
1796
1797     # OFPT_PORT_STATUS, OFPPR_ADD
1798     ovs-vsctl add-port br0 test -- set Interface test type=dummy
1799     if test X"$1" = X"OFPPR_ADD"; then shift;
1800         echo >>expout "OFPT_PORT_STATUS (OF1.3): ADD: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1801      config:     PORT_DOWN
1802      state:      LINK_DOWN
1803      speed: 0 Mbps now, 0 Mbps max"
1804     fi
1805
1806     # OFPT_PORT_STATUS, OFPPR_DELETE
1807     ovs-vsctl del-port br0 test
1808     if test X"$1" = X"OFPPR_DELETE"; then shift;
1809         echo >>expout "OFPT_PORT_STATUS (OF1.3): DEL: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1810      config:     PORT_DOWN
1811      state:      LINK_DOWN
1812      speed: 0 Mbps now, 0 Mbps max"
1813     fi
1814
1815     # OFPT_FLOW_REMOVED, OFPRR_DELETE
1816     ovs-ofctl -O OpenFlow13 add-flow br0 send_flow_rem,actions=drop
1817     ovs-ofctl -O OpenFlow13 --strict del-flows br0 ''
1818     if test X"$1" = X"OFPRR_DELETE"; then shift;
1819         echo >>expout "OFPT_FLOW_REMOVED (OF1.3):  reason=delete table_id=0"
1820     fi
1821     AT_FAIL_IF([test X"$1" != X])
1822
1823     ovs-appctl -t ovs-ofctl ofctl/barrier
1824     echo >>expout "OFPT_BARRIER_REPLY (OF1.3):"
1825
1826     AT_CHECK(
1827       [[sed '
1828 s/ (xid=0x[0-9a-fA-F]*)//
1829 s/ *duration.*//
1830 s/00:0.$/00:0x/' < monitor.log]],
1831       [0], [expout])
1832 }
1833
1834 # It's a service connection so initially there should be no async messages.
1835 check_async 1
1836
1837 # Set miss_send_len to 128, turning on packet-ins for our service connection.
1838 ovs-appctl -t ovs-ofctl ofctl/send 0409000c0123456700000080
1839 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1840
1841 # Become slave (OF 1.3), which should disable everything except port status.
1842 ovs-appctl -t ovs-ofctl ofctl/send 041800180000000200000003000000000000000000000001
1843 check_async 3 OFPPR_ADD OFPPR_DELETE
1844
1845 # Use OF 1.3 OFPT_SET_ASYNC to enable a patchwork of asynchronous messages.
1846 ovs-appctl -t ovs-ofctl ofctl/send 041c002000000002000000020000000500000005000000020000000200000005
1847 check_async 4 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
1848
1849 # Set controller ID 123.
1850 ovs-appctl -t ovs-ofctl ofctl/send 04040018000000030000232000000014000000000000007b
1851 check_async 5 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
1852
1853 # Restore controller ID 0.
1854 ovs-appctl -t ovs-ofctl ofctl/send 040400180000000300002320000000140000000000000000
1855
1856 # Become master (OF 1.3).
1857 ovs-appctl -t ovs-ofctl ofctl/send 041800180000000400000002000000000000000000000002
1858 check_async 6 OFPR_ACTION OFPPR_ADD
1859
1860 ovs-appctl -t ovs-ofctl exit
1861 OVS_VSWITCHD_STOP
1862 AT_CLEANUP
1863
1864 dnl This test checks that the role request/response messaging works
1865 dnl and that generation_id is handled properly.
1866 AT_SETUP([ofproto - controller role (OpenFlow 1.2)])
1867 OVS_VSWITCHD_START
1868 ON_EXIT([kill `cat c1.pid c2.pid`])
1869
1870 # Start two ovs-ofctl controller processes.
1871 AT_CAPTURE_FILE([monitor1.log])
1872 AT_CAPTURE_FILE([expout1])
1873 AT_CAPTURE_FILE([experr1])
1874 AT_CAPTURE_FILE([monitor2.log])
1875 AT_CAPTURE_FILE([expout2])
1876 AT_CAPTURE_FILE([experr2])
1877 for i in 1 2; do
1878      AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile=`pwd`/c$i.pid --unixctl=`pwd`/c$i])
1879     ovs-appctl -t `pwd`/c$i ofctl/barrier
1880     ovs-appctl -t `pwd`/c$i ofctl/set-output-file monitor$i.log
1881     : > expout$i
1882     : > experr$i
1883
1884     # find out current role
1885     ovs-appctl -t `pwd`/c$i ofctl/send 031800180000000200000000000000000000000000000000
1886     echo >>experr$i "send: OFPT_ROLE_REQUEST (OF1.2): role=nochange"
1887     echo >>expout$i "OFPT_ROLE_REPLY (OF1.2): role=equal"
1888 done
1889
1890 # controller 1: Become slave (generation_id is initially undefined, so
1891 # 2^63+2 should not be stale)
1892 ovs-appctl -t `pwd`/c1 ofctl/send 031800180000000300000003000000008000000000000002
1893 echo >>experr1 "send: OFPT_ROLE_REQUEST (OF1.2): role=slave generation_id=9223372036854775810"
1894 echo >>expout1 "OFPT_ROLE_REPLY (OF1.2): role=slave generation_id=9223372036854775810"
1895
1896 # controller 2: Become master.
1897 ovs-appctl -t `pwd`/c2 ofctl/send 031800180000000300000002000000008000000000000003
1898 echo >>experr2 "send: OFPT_ROLE_REQUEST (OF1.2): role=master generation_id=9223372036854775811"
1899 echo >>expout2 "OFPT_ROLE_REPLY (OF1.2): role=master generation_id=9223372036854775811"
1900
1901 # controller 1: Try to become the master using a stale generation ID
1902 ovs-appctl -t `pwd`/c1 ofctl/send 031800180000000400000002000000000000000000000003
1903 echo >>experr1 "send: OFPT_ROLE_REQUEST (OF1.2): role=master generation_id=3"
1904 echo >>expout1 "OFPT_ERROR (OF1.2): OFPRRFC_STALE"
1905 echo >>expout1 "OFPT_ROLE_REQUEST (OF1.2): role=master generation_id=3"
1906
1907 # controller 1: Become master using a valid generation ID
1908 ovs-appctl -t `pwd`/c1 ofctl/send 031800180000000500000002000000000000000000000001
1909 echo >>experr1 "send: OFPT_ROLE_REQUEST (OF1.2): role=master generation_id=1"
1910 echo >>expout1 "OFPT_ROLE_REPLY (OF1.2): role=master generation_id=1"
1911
1912 for i in 1 2; do
1913     ovs-appctl -t `pwd`/c$i ofctl/barrier
1914     echo >>expout$i "OFPT_BARRIER_REPLY (OF1.2):"
1915 done
1916
1917 # Check output.
1918 for i in 1 2; do
1919     cp expout$i expout
1920     AT_CHECK([grep -v '^send:' monitor$i.log | STRIP_XIDS], [0], [expout])
1921     cp experr$i expout
1922     AT_CHECK([grep '^send:' monitor$i.log | STRIP_XIDS], [0], [expout])
1923 done
1924 OVS_VSWITCHD_STOP
1925 AT_CLEANUP
1926
1927 dnl This test checks that the role request/response messaging works,
1928 dnl that generation_id is handled properly, and that role status update
1929 dnl messages are sent when a controller's role gets changed from master
1930 dnl to slave.
1931 AT_SETUP([ofproto - controller role (OpenFlow 1.4)])
1932 OVS_VSWITCHD_START
1933 ON_EXIT([kill `cat c1.pid c2.pid`])
1934
1935 # Start two ovs-ofctl controller processes.
1936 AT_CAPTURE_FILE([monitor1.log])
1937 AT_CAPTURE_FILE([expout1])
1938 AT_CAPTURE_FILE([experr1])
1939 AT_CAPTURE_FILE([monitor2.log])
1940 AT_CAPTURE_FILE([expout2])
1941 AT_CAPTURE_FILE([experr2])
1942 for i in 1 2; do
1943      AT_CHECK([ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile=`pwd`/c$i.pid --unixctl=`pwd`/c$i])
1944     ovs-appctl -t `pwd`/c$i ofctl/barrier
1945     ovs-appctl -t `pwd`/c$i ofctl/set-output-file monitor$i.log
1946     : > expout$i
1947     : > experr$i
1948
1949     # find out current role
1950     ovs-appctl -t `pwd`/c$i ofctl/send 051800180000000200000000000000000000000000000000
1951     echo >>experr$i "send: OFPT_ROLE_REQUEST (OF1.4): role=nochange"
1952     echo >>expout$i "OFPT_ROLE_REPLY (OF1.4): role=equal"
1953 done
1954
1955 # controller 1: Become slave (generation_id is initially undefined, so
1956 # 2^63+2 should not be stale)
1957 ovs-appctl -t `pwd`/c1 ofctl/send 051800180000000300000003000000008000000000000002
1958 echo >>experr1 "send: OFPT_ROLE_REQUEST (OF1.4): role=slave generation_id=9223372036854775810"
1959 echo >>expout1 "OFPT_ROLE_REPLY (OF1.4): role=slave generation_id=9223372036854775810"
1960
1961 # controller 2: Become master.
1962 ovs-appctl -t `pwd`/c2 ofctl/send 051800180000000300000002000000008000000000000003
1963 echo >>experr2 "send: OFPT_ROLE_REQUEST (OF1.4): role=master generation_id=9223372036854775811"
1964 echo >>expout2 "OFPT_ROLE_REPLY (OF1.4): role=master generation_id=9223372036854775811"
1965
1966 # controller 1: Try to become the master using a stale generation ID
1967 ovs-appctl -t `pwd`/c1 ofctl/send 051800180000000400000002000000000000000000000003
1968 echo >>experr1 "send: OFPT_ROLE_REQUEST (OF1.4): role=master generation_id=3"
1969 echo >>expout1 "OFPT_ERROR (OF1.4): OFPRRFC_STALE"
1970 echo >>expout1 "OFPT_ROLE_REQUEST (OF1.4): role=master generation_id=3"
1971
1972 # controller 1: Become master using a valid generation ID
1973 ovs-appctl -t `pwd`/c1 ofctl/send 051800180000000500000002000000000000000000000001
1974 echo >>experr1 "send: OFPT_ROLE_REQUEST (OF1.4): role=master generation_id=1"
1975 echo >>expout1 "OFPT_ROLE_REPLY (OF1.4): role=master generation_id=1"
1976 echo >>expout2 "OFPT_ROLE_STATUS (OF1.4): role=slave generation_id=1 reason=master_request"
1977
1978 for i in 1 2; do
1979     ovs-appctl -t `pwd`/c$i ofctl/barrier
1980     echo >>expout$i "OFPT_BARRIER_REPLY (OF1.4):"
1981 done
1982
1983 # Check output.
1984 for i in 1 2; do
1985     cp expout$i expout
1986     AT_CHECK([grep -v '^send:' monitor$i.log | STRIP_XIDS], [0], [expout])
1987     cp experr$i expout
1988     AT_CHECK([grep '^send:' monitor$i.log | STRIP_XIDS], [0], [expout])
1989 done
1990 OVS_VSWITCHD_STOP
1991 AT_CLEANUP
1992
1993 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
1994 dnl specified by OpenFlow 1.0) and OFPP_CONTROLLER (used by some
1995 dnl controllers despite the spec) as meaning a packet that was generated
1996 dnl by the controller.
1997 AT_SETUP([ofproto - packet-out from controller (OpenFlow 1.0)])
1998 OVS_VSWITCHD_START
1999 ADD_OF_PORTS([br0], [1])
2000
2001 # Start a monitor listening for packet-ins.
2002 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
2003 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
2004 ovs-appctl -t ovs-ofctl ofctl/barrier
2005 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2006 AT_CAPTURE_FILE([monitor.log])
2007
2008 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
2009 AT_CHECK([ovs-ofctl packet-out br0 none controller,1 '0001020304050010203040501234'])
2010 AT_CHECK([ovs-ofctl packet-out br0 controller controller,1 '0001020304050010203040505678'])
2011
2012 # Stop the monitor and check its output.
2013 ovs-appctl -t ovs-ofctl ofctl/barrier
2014 ovs-appctl -t ovs-ofctl exit
2015
2016 ovs-ofctl dump-ports br0
2017
2018 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
2019 OFPT_PACKET_IN: total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
2020 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
2021 OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
2022 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x5678
2023 OFPT_BARRIER_REPLY:
2024 ])
2025
2026 OVS_VSWITCHD_STOP
2027 AT_CLEANUP
2028
2029 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
2030 dnl specified by OpenFlow 1.2) and OFPP_CONTROLLER (used by some
2031 dnl controllers despite the spec) as meaning a packet that was generated
2032 dnl by the controller.
2033 AT_SETUP([ofproto - packet-out from controller (OpenFlow 1.2)])
2034 OVS_VSWITCHD_START
2035
2036 # Start a monitor listening for packet-ins.
2037 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
2038 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
2039 ovs-appctl -t ovs-ofctl ofctl/barrier
2040 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2041 AT_CAPTURE_FILE([monitor.log])
2042
2043 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
2044 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 none controller '0001020304050010203040501234'])
2045 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 4294967293 controller '0001020304050010203040505678'])
2046
2047 # Stop the monitor and check its output.
2048 ovs-appctl -t ovs-ofctl ofctl/barrier
2049 ovs-appctl -t ovs-ofctl exit
2050
2051 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
2052 OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
2053 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
2054 OFPT_PACKET_IN (OF1.2): total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
2055 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x5678
2056 OFPT_BARRIER_REPLY (OF1.2):
2057 ])
2058
2059 OVS_VSWITCHD_STOP
2060 AT_CLEANUP
2061
2062 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
2063 dnl specified by OpenFlow 1.1) and OFPP_CONTROLLER (used by some
2064 dnl controllers despite the spec) as meaning a packet that was generated
2065 dnl by the controller.
2066 AT_SETUP([ofproto - packet-out from controller (OpenFlow 1.1)])
2067 OVS_VSWITCHD_START
2068
2069 # Start a monitor listening for packet-ins.
2070 AT_CHECK([ovs-ofctl -O OpenFlow11 monitor br0 --detach --no-chdir --pidfile])
2071 ovs-appctl -t ovs-ofctl ofctl/send 0209000c0123456700000080
2072 ovs-appctl -t ovs-ofctl ofctl/barrier
2073 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2074 AT_CAPTURE_FILE([monitor.log])
2075
2076 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
2077 AT_CHECK([ovs-ofctl -O OpenFlow11 packet-out br0 none controller '0001020304050010203040501234'])
2078 AT_CHECK([ovs-ofctl -O OpenFlow11 packet-out br0 4294967293 controller '0001020304050010203040505678'])
2079
2080 # Stop the monitor and check its output.
2081 ovs-appctl -t ovs-ofctl ofctl/barrier
2082 ovs-appctl -t ovs-ofctl exit
2083
2084 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
2085 OFPT_PACKET_IN (OF1.1): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
2086 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
2087 OFPT_PACKET_IN (OF1.1): total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
2088 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x5678
2089 OFPT_BARRIER_REPLY (OF1.1):
2090 ])
2091
2092 OVS_VSWITCHD_STOP
2093 AT_CLEANUP
2094
2095 dnl This test checks that metadata is encoded in packet_in structures,
2096 dnl supported by NXAST.
2097 AT_SETUP([ofproto - packet-out with metadata (NXM)])
2098 OVS_VSWITCHD_START
2099
2100 # Start a monitor listening for packet-ins.
2101 AT_CHECK([ovs-ofctl -P nxm monitor br0 --detach --no-chdir --pidfile])
2102 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
2103 ovs-appctl -t ovs-ofctl ofctl/barrier
2104 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2105 AT_CAPTURE_FILE([monitor.log])
2106
2107 # Send a packet-out with a load action to set some metadata, and forward to controller
2108 AT_CHECK([ovs-ofctl packet-out br0 controller 'load(0xfafafafa5a5a5a5a->OXM_OF_METADATA[[0..63]]), load(0xaa->NXM_NX_PKT_MARK[[]]), controller' '0001020304050010203040501234'])
2109
2110 # Stop the monitor and check its output.
2111 ovs-appctl -t ovs-ofctl ofctl/barrier
2112 ovs-appctl -t ovs-ofctl exit
2113
2114 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
2115 NXT_PACKET_IN: total_len=14 in_port=CONTROLLER metadata=0xfafafafa5a5a5a5a pkt_mark=0xaa (via action) data_len=14 (unbuffered)
2116 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
2117 OFPT_BARRIER_REPLY:
2118 ])
2119
2120 OVS_VSWITCHD_STOP
2121 AT_CLEANUP
2122
2123 dnl This test checks that metadata is encoded in packet_in structures,
2124 dnl supported by NXAST.
2125 AT_SETUP([ofproto - packet-out with metadata (OpenFlow 1.2)])
2126 OVS_VSWITCHD_START
2127
2128 # Start a monitor listening for packet-ins.
2129 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
2130 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
2131 ovs-appctl -t ovs-ofctl ofctl/barrier
2132 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2133 AT_CAPTURE_FILE([monitor.log])
2134
2135 # Send a packet-out with a load action to set some metadata, and forward to controller
2136 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 none 'load(0xfafafafa5a5a5a5a->OXM_OF_METADATA[[0..63]]), controller' '0001020304050010203040501234'])
2137
2138 # Stop the monitor and check its output.
2139 ovs-appctl -t ovs-ofctl ofctl/barrier
2140 ovs-appctl -t ovs-ofctl exit
2141
2142 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
2143 OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY metadata=0xfafafafa5a5a5a5a (via action) data_len=14 (unbuffered)
2144 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
2145 OFPT_BARRIER_REPLY (OF1.2):
2146 ])
2147
2148 OVS_VSWITCHD_STOP
2149 AT_CLEANUP
2150
2151 dnl This test checks that tunnel metadata is encoded in packet_in structures.
2152 AT_SETUP([ofproto - packet-out with tunnel metadata (OpenFlow 1.2)])
2153 OVS_VSWITCHD_START
2154
2155 # Start a monitor listening for packet-ins.
2156 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
2157 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
2158 ovs-appctl -t ovs-ofctl ofctl/barrier
2159 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2160 AT_CAPTURE_FILE([monitor.log])
2161
2162 # Send a packet-out with set field actions to set some tunnel metadata, and forward to controller
2163 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 none 'set_field:127.0.0.1->tun_src,set_field:0x01020304->tun_id,set_field:192.168.0.1->tun_dst, controller' '0001020304050010203040501234'])
2164
2165 # Stop the monitor and check its output.
2166 ovs-appctl -t ovs-ofctl ofctl/barrier
2167 ovs-appctl -t ovs-ofctl exit
2168
2169 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
2170 OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY tun_id=0x1020304 tun_src=127.0.0.1 tun_dst=192.168.0.1 (via action) data_len=14 (unbuffered)
2171 metadata=0,in_port=0,vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
2172 OFPT_BARRIER_REPLY (OF1.2):
2173 ])
2174
2175 OVS_VSWITCHD_STOP
2176 AT_CLEANUP
2177
2178 AT_SETUP([ofproto - flow monitoring])
2179 AT_KEYWORDS([monitor])
2180 OVS_VSWITCHD_START
2181
2182 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:1
2183
2184 # Start a monitor watching the flow table and check the initial reply.
2185 ovs-ofctl monitor br0 watch: --detach --no-chdir --pidfile >monitor.log 2>&1
2186 AT_CAPTURE_FILE([monitor.log])
2187 ovs-appctl -t ovs-ofctl ofctl/barrier
2188 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log], [0],
2189   [NXST_FLOW_MONITOR reply:
2190  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:1
2191 OFPT_BARRIER_REPLY:
2192 ])
2193
2194 # Add, delete, and modify some flows and check the updates.
2195 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2196 ovs-ofctl add-flow br0 in_port=0,dl_vlan=124,actions=output:2
2197 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:5
2198 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,dl_vlan_pcp=0,actions=output:6
2199 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,dl_vlan_pcp=1,actions=output:7
2200 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:8
2201 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,dl_vlan_pcp=0,actions=output:9
2202 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,dl_vlan_pcp=1,actions=output:10
2203 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,actions=output:11
2204 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,dl_vlan_pcp=0,actions=output:12
2205 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,dl_vlan_pcp=1,actions=output:13
2206 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,actions=output:14
2207 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=0,actions=output:15
2208 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=1,actions=output:16
2209 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,actions=output:17
2210 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=0,actions=output:18
2211 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=1,actions=output:19
2212 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,actions=output:20
2213 ovs-ofctl add-flow br0 in_port=0,dl_vlan_pcp=0,actions=output:21
2214 ovs-ofctl add-flow br0 in_port=0,dl_vlan_pcp=1,actions=output:22
2215 ovs-ofctl add-flow br0 in_port=0,actions=output:23
2216 ovs-ofctl mod-flows br0 dl_vlan=123,actions=output:3
2217 ovs-ofctl mod-flows br0 cookie=5,dl_vlan=123,actions=output:3
2218 ovs-ofctl del-flows br0 dl_vlan=123
2219 ovs-ofctl del-flows br0
2220 ovs-appctl -t ovs-ofctl ofctl/barrier
2221 sort='
2222     # Sorts groups of lines that start with a space, without moving them
2223     # past the nearest line that does not start with a space.
2224     use warnings;
2225     use strict;
2226     my @buffer = ();
2227     while (<STDIN>) {
2228         if (/^ /) {
2229             push(@buffer, $_);
2230         } else {
2231             print $_ foreach sort(@buffer);
2232             print $_;
2233             @buffer = ();
2234         }
2235     }
2236     print $_ foreach sort(@buffer);
2237 '
2238 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log | ${PERL} -e "$sort"], [0],
2239 [NXST_FLOW_MONITOR reply (xid=0x0):
2240  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
2241 NXST_FLOW_MONITOR reply (xid=0x0):
2242  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:5
2243 NXST_FLOW_MONITOR reply (xid=0x0):
2244  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:6
2245 NXST_FLOW_MONITOR reply (xid=0x0):
2246  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:7
2247 NXST_FLOW_MONITOR reply (xid=0x0):
2248  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:8
2249 NXST_FLOW_MONITOR reply (xid=0x0):
2250  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:9
2251 NXST_FLOW_MONITOR reply (xid=0x0):
2252  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:10
2253 NXST_FLOW_MONITOR reply (xid=0x0):
2254  event=ADDED table=0 cookie=0 in_port=0,vlan_tci=0x0000 actions=output:11
2255 NXST_FLOW_MONITOR reply (xid=0x0):
2256  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=0 actions=output:12
2257 NXST_FLOW_MONITOR reply (xid=0x0):
2258  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=1 actions=output:13
2259 NXST_FLOW_MONITOR reply (xid=0x0):
2260  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095 actions=output:14
2261 NXST_FLOW_MONITOR reply (xid=0x0):
2262  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:15
2263 NXST_FLOW_MONITOR reply (xid=0x0):
2264  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:16
2265 NXST_FLOW_MONITOR reply (xid=0x0):
2266  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:17
2267 NXST_FLOW_MONITOR reply (xid=0x0):
2268  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:18
2269 NXST_FLOW_MONITOR reply (xid=0x0):
2270  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:19
2271 NXST_FLOW_MONITOR reply (xid=0x0):
2272  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:20
2273 NXST_FLOW_MONITOR reply (xid=0x0):
2274  event=ADDED table=0 cookie=0 in_port=0,dl_vlan_pcp=0 actions=output:21
2275 NXST_FLOW_MONITOR reply (xid=0x0):
2276  event=ADDED table=0 cookie=0 in_port=0,dl_vlan_pcp=1 actions=output:22
2277 NXST_FLOW_MONITOR reply (xid=0x0):
2278  event=ADDED table=0 cookie=0 in_port=0 actions=output:23
2279 NXST_FLOW_MONITOR reply (xid=0x0):
2280  event=MODIFIED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:3
2281  event=MODIFIED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
2282  event=MODIFIED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
2283 NXST_FLOW_MONITOR reply (xid=0x0):
2284  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123 actions=output:3
2285  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
2286  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
2287 NXST_FLOW_MONITOR reply (xid=0x0):
2288  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123 actions=output:3
2289  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
2290  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
2291 NXST_FLOW_MONITOR reply (xid=0x0):
2292  event=DELETED reason=delete table=0 cookie=0 in_port=0 actions=output:23
2293  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:20
2294  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:18
2295  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:19
2296  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
2297  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095 actions=output:14
2298  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=0 actions=output:12
2299  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=1 actions=output:13
2300  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan_pcp=0 actions=output:21
2301  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan_pcp=1 actions=output:22
2302  event=DELETED reason=delete table=0 cookie=0 in_port=0,vlan_tci=0x0000 actions=output:11
2303 OFPT_BARRIER_REPLY:
2304 ])
2305
2306 # Check that our own changes are reported as abbreviations.
2307 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
2308 ovs-ofctl add-flow br0 in_port=1,actions=output:2
2309 ovs-ofctl add-flow br0 in_port=2,actions=output:1
2310 ovs-appctl -t ovs-ofctl ofctl/barrier
2311 ovs-appctl -t ovs-ofctl ofctl/send 010e004812345678003fffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000ffffffffffff0000
2312 ovs-appctl -t ovs-ofctl ofctl/barrier
2313 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
2314 ])
2315 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log], [0],
2316 [NXST_FLOW_MONITOR reply (xid=0x0):
2317  event=ADDED table=0 cookie=0 in_port=1 actions=output:2
2318 NXST_FLOW_MONITOR reply (xid=0x0):
2319  event=ADDED table=0 cookie=0 in_port=2 actions=output:1
2320 OFPT_BARRIER_REPLY:
2321 send: OFPT_FLOW_MOD: DEL priority=0 actions=drop
2322 NXST_FLOW_MONITOR reply (xid=0x0):
2323  event=ABBREV xid=0x12345678
2324 OFPT_BARRIER_REPLY:
2325 ])
2326
2327 ovs-appctl -t ovs-ofctl exit
2328 OVS_VSWITCHD_STOP
2329 AT_CLEANUP
2330
2331 AT_SETUP([ofproto - flow monitoring pause and resume])
2332 AT_KEYWORDS([monitor])
2333
2334 # The maximum socket receive buffer size is important for this test, which
2335 # tests behavior when the receive buffer overflows.
2336 if test -e /proc/sys/net/core/rmem_max; then
2337     # Linux
2338     rmem_max=`cat /proc/sys/net/core/rmem_max`
2339 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
2340     : # FreeBSD, NetBSD
2341 else
2342     # Don't know how to get maximum socket receive buffer on this OS
2343     AT_SKIP_IF([:])
2344 fi
2345 # Calculate the total amount of queuing: rmem_max in the kernel, 128 kB
2346 # in ofproto sending userspace (see ofmonitor_flush() in connmgr.c).
2347 queue_size=`expr $rmem_max + 128 \* 1024`
2348 echo rmem_max=$rmem_max queue_size=$queue_size
2349
2350 # If there's too much queuing skip the test to avoid timing out.
2351 AT_SKIP_IF([test $rmem_max -gt 1048576])
2352
2353 # Each flow update message takes up at least 48 bytes of space in queues
2354 # and in practice more than that.
2355 n_msgs=`expr $queue_size / 48`
2356 echo n_msgs=$n_msgs
2357
2358 OVS_VSWITCHD_START
2359
2360 # Start a monitor watching the flow table, then make it block.
2361 ON_EXIT([kill `cat ovs-ofctl.pid`])
2362 ovs-ofctl monitor br0 watch: --detach --no-chdir --pidfile >monitor.log 2>&1
2363 AT_CAPTURE_FILE([monitor.log])
2364 ovs-appctl -t ovs-ofctl ofctl/block
2365
2366 # Add $n_msgs flows.
2367 (echo "in_port=2,actions=output:2"
2368 ${PERL} -e '
2369     for ($i = 0; $i < '$n_msgs'; $i++) {
2370         print "cookie=1,reg1=$i,actions=drop\n";
2371     }
2372 ') > flows.txt
2373 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
2374 # Check that multipart flow dumps work properly:
2375 AT_CHECK([ovs-ofctl diff-flows br0 flows.txt])
2376 AT_CHECK([ovs-ofctl add-flow br0 in_port=1,cookie=3,actions=drop])
2377 AT_CHECK([ovs-ofctl mod-flows br0 in_port=2,cookie=2,actions=output:2])
2378 AT_CHECK([ovs-ofctl del-flows br0 cookie=1/-1])
2379
2380 ovs-appctl -t ovs-ofctl ofctl/unblock
2381
2382 # Wait for the connection resumed.
2383 # A barrier doesn't work for this purpose.
2384 #    https://www.mail-archive.com/dev@openvswitch.org/msg27013.html
2385 #    https://www.mail-archive.com/dev@openvswitch.org/msg27675.html
2386 OVS_WAIT_UNTIL([grep NXT_FLOW_MONITOR_RESUMED monitor.log])
2387
2388 ovs-appctl -t ovs-ofctl exit
2389
2390 # Check that the flow monitor reported the same number of flows
2391 # added and deleted, but fewer than we actually added and deleted.
2392 adds=`grep -c 'ADDED.*reg1=' monitor.log`
2393 deletes=`grep -c 'DELETED.*reg1=' monitor.log`
2394 echo adds=$adds deletes=$deletes
2395 AT_CHECK([test $adds -gt 100 && test $adds -lt $n_msgs])
2396 AT_CHECK([test $adds = $deletes])
2397
2398 # Check that the flow monitor reported everything in the expected order:
2399 #
2400 #     event=ADDED table=0 cookie=0x1 reg1=0x22
2401 # ...
2402 #    NXT_FLOW_MONITOR_PAUSED:
2403 # ...
2404 #     event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
2405 # ...
2406 #     event=ADDED table=0 cookie=0x3 in_port=1
2407 #     event=MODIFIED table=0 cookie=0x2 in_port=2 actions=output:2
2408 #    NXT_FLOW_MONITOR_RESUMED:
2409 #
2410 # except that, between the PAUSED and RESUMED, the order of the ADDED
2411 # and MODIFIED lines lines depends on hash order, that is, it varies
2412 # as we change the hash function or change architecture.  Therefore,
2413 # we use a couple of tests below to accept both orders.
2414 AT_CHECK([ofctl_strip < monitor.log | sed -n -e '
2415 /reg1=0x22$/p
2416 /cookie=0x[[23]]/p
2417 /NXT_FLOW_MONITOR_PAUSED:/p
2418 /NXT_FLOW_MONITOR_RESUMED:/p
2419 ' > monitor.log.subset])
2420 AT_CHECK([grep -v MODIFIED monitor.log.subset], [0], [dnl
2421  event=ADDED table=0 cookie=0x1 reg1=0x22
2422 NXT_FLOW_MONITOR_PAUSED:
2423  event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
2424  event=ADDED table=0 cookie=0x3 in_port=1
2425 NXT_FLOW_MONITOR_RESUMED:
2426 ])
2427 AT_CHECK([grep -v ADDED monitor.log.subset], [0], [dnl
2428 NXT_FLOW_MONITOR_PAUSED:
2429  event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
2430  event=MODIFIED table=0 cookie=0x2 in_port=2 actions=output:2
2431 NXT_FLOW_MONITOR_RESUMED:
2432 ])
2433
2434 OVS_VSWITCHD_STOP
2435 AT_CLEANUP
2436
2437 AT_SETUP([ofproto - event filtering (OpenFlow 1.3)])
2438 AT_KEYWORDS([monitor])
2439 OVS_VSWITCHD_START
2440
2441 # Start a monitor, use the required protocol version
2442 ovs-ofctl -O OpenFlow13 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2443 AT_CAPTURE_FILE([monitor.log])
2444
2445 # Send an OpenFlow13 message (04), OFPT_GET_ASYNC_REQUEST (1a), length (8), xid (0a)
2446 ovs-appctl -t ovs-ofctl ofctl/send 041a00080000000a
2447 ovs-appctl -t ovs-ofctl ofctl/barrier
2448
2449 # Check default setting
2450 read -r -d '' expected <<'EOF'
2451 EOF
2452
2453 AT_CHECK([ofctl_strip < monitor.log], [], [dnl
2454 send: OFPT_GET_ASYNC_REQUEST (OF1.3):
2455 OFPT_GET_ASYNC_REPLY (OF1.3):
2456  master:
2457        PACKET_IN: no_match action
2458      PORT_STATUS: add delete modify
2459     FLOW_REMOVED: idle hard delete
2460
2461  slave:
2462        PACKET_IN: (off)
2463      PORT_STATUS: add delete modify
2464     FLOW_REMOVED: (off)
2465 OFPT_BARRIER_REPLY (OF1.3):
2466 ])
2467
2468 OVS_VSWITCHD_STOP
2469 AT_CLEANUP
2470
2471 AT_SETUP([ofproto - ofport_request])
2472 OVS_VSWITCHD_START
2473 ADD_OF_PORTS([br0], [1], [2], [3])
2474
2475 set_and_check_specific_ofports () {
2476     ovs-vsctl set Interface p1 ofport_request="$1" -- \
2477               set Interface p2 ofport_request="$2" -- \
2478               set Interface p3 ofport_request="$3"
2479     ofports=`ovs-vsctl get Interface p1 ofport -- \
2480                        get Interface p2 ofport -- \
2481                        get Interface p3 ofport`
2482     AT_CHECK_UNQUOTED([echo $ofports], [0], [$1 $2 $3
2483 ])
2484 }
2485 for pre in      '1 2 3' '1 3 2' '2 1 3' '2 3 1' '3 1 2' '3 2 1'; do
2486     for post in '1 2 3' '1 3 2' '2 1 3' '2 3 1' '3 1 2' '3 2 1'; do
2487         echo -----------------------------------------------------------
2488         echo "Check changing port numbers from $pre to $post"
2489         set_and_check_ofports $pre
2490         set_and_check_ofports $post
2491     done
2492 done
2493
2494 ovs-vsctl del-port p3
2495
2496 set_and_check_poorly_specified_ofports () {
2497     ovs-vsctl set Interface p1 ofport_request="$1" -- \
2498               set Interface p2 ofport_request="$2"
2499     p1=`ovs-vsctl get Interface p1 ofport`
2500     p2=`ovs-vsctl get Interface p2 ofport`
2501     echo $p1 $p2
2502
2503     AT_CHECK([test "$p1" != "$p2"])
2504     if test "$1" = "$2" && test "$1" != '[[]]'; then
2505         # One port number must be the requested one.
2506         AT_CHECK([test "$p1" = "$1" || test "$p2" = "$1"])
2507         # The other port number must be different (already tested above).
2508     else
2509         AT_CHECK([test "$1" = '[[]]' || test "$p1" == "$1"])
2510         AT_CHECK([test "$2" = '[[]]' || test "$p2" == "$2"])
2511     fi
2512 }
2513 for pre in      '1 2' '[[]] 2' '1 [[]]' '[[]] [[]]' '2 1' '[[]] 1' '2 [[]]' \
2514                 '1 1' '2 2'; do
2515     for post in '1 2' '[[]] 2' '1 [[]]' '[[]] [[]]' '2 1' '[[]] 1' '2 [[]]' \
2516                 '1 1' '2 2'; do
2517         echo -----------------------------------------------------------
2518         echo "Check changing port numbers from $pre to $post"
2519         set_and_check_poorly_specified_ofports $pre
2520         set_and_check_poorly_specified_ofports $post
2521     done
2522 done
2523 OVS_VSWITCHD_STOP
2524 AT_CLEANUP
2525
2526
2527 AT_SETUP([ofproto - bundles, open (OpenFlow 1.4)])
2528 AT_KEYWORDS([monitor])
2529 OVS_VSWITCHD_START
2530
2531 # Start a monitor, use the required protocol version
2532 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2533 AT_CAPTURE_FILE([monitor.log])
2534
2535 # Send an OpenFlow14 message (05), OFPT_BUNDLE_CONTROL (21), length (10), xid (0a)
2536 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 00 00 01"
2537 ovs-appctl -t ovs-ofctl ofctl/barrier
2538 ovs-appctl -t ovs-ofctl exit
2539
2540 AT_CHECK([ofctl_strip < monitor.log], [], [dnl
2541 send: OFPT_BUNDLE_CONTROL (OF1.4):
2542  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2543 OFPT_BUNDLE_CONTROL (OF1.4):
2544  bundle_id=0x1 type=OPEN_REPLY flags=0
2545 OFPT_BARRIER_REPLY (OF1.4):
2546 ])
2547
2548 OVS_VSWITCHD_STOP
2549 AT_CLEANUP
2550
2551 AT_SETUP([ofproto - bundles, double open (OpenFlow 1.4)])
2552 AT_KEYWORDS([monitor])
2553 OVS_VSWITCHD_START
2554
2555 # Start a monitor, use the required protocol version
2556 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2557 AT_CAPTURE_FILE([monitor.log])
2558
2559 # Send twice an OpenFlow14 message (05), OFPT_BUNDLE_CONTROL (21), length (10), xid (0a)
2560 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 00 00 01"
2561 ovs-appctl -t ovs-ofctl ofctl/barrier
2562 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 00 00 01"
2563 ovs-appctl -t ovs-ofctl ofctl/barrier
2564 ovs-appctl -t ovs-ofctl exit
2565
2566 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2567 send: OFPT_BUNDLE_CONTROL (OF1.4):
2568  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2569 OFPT_BUNDLE_CONTROL (OF1.4):
2570  bundle_id=0x1 type=OPEN_REPLY flags=0
2571 OFPT_BARRIER_REPLY (OF1.4):
2572 send: OFPT_BUNDLE_CONTROL (OF1.4):
2573  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2574 OFPT_ERROR (OF1.4): OFPBFC_BAD_ID
2575 OFPT_BUNDLE_CONTROL (OF1.4):
2576  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2577 OFPT_BARRIER_REPLY (OF1.4):
2578 ])
2579
2580 OVS_VSWITCHD_STOP
2581 AT_CLEANUP
2582
2583 AT_SETUP([ofproto - bundle close without open (OpenFlow 1.4)])
2584 AT_KEYWORDS([monitor])
2585 OVS_VSWITCHD_START
2586
2587 # Start a monitor, use the required protocol version
2588 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2589 AT_CAPTURE_FILE([monitor.log])
2590
2591 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 02 00 01"
2592 ovs-appctl -t ovs-ofctl ofctl/barrier
2593 ovs-appctl -t ovs-ofctl exit
2594
2595 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2596 send: OFPT_BUNDLE_CONTROL (OF1.4):
2597  bundle_id=0x1 type=CLOSE_REQUEST flags=atomic
2598 OFPT_ERROR (OF1.4): OFPBFC_BAD_ID
2599 OFPT_BUNDLE_CONTROL (OF1.4):
2600  bundle_id=0x1 type=CLOSE_REQUEST flags=atomic
2601 OFPT_BARRIER_REPLY (OF1.4):
2602 ])
2603
2604 OVS_VSWITCHD_STOP
2605 AT_CLEANUP
2606
2607 AT_SETUP([ofproto - bundle double close (OpenFlow 1.4)])
2608 AT_KEYWORDS([monitor])
2609 OVS_VSWITCHD_START
2610
2611 # Start a monitor, use the required protocol version
2612 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2613 AT_CAPTURE_FILE([monitor.log])
2614
2615 # Open, Close, Close
2616 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 00 00 01"
2617 ovs-appctl -t ovs-ofctl ofctl/barrier
2618 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 02 00 01"
2619 ovs-appctl -t ovs-ofctl ofctl/barrier
2620 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 02 00 01"
2621 ovs-appctl -t ovs-ofctl ofctl/barrier
2622 ovs-appctl -t ovs-ofctl exit
2623
2624 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2625 send: OFPT_BUNDLE_CONTROL (OF1.4):
2626  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2627 OFPT_BUNDLE_CONTROL (OF1.4):
2628  bundle_id=0x1 type=OPEN_REPLY flags=0
2629 OFPT_BARRIER_REPLY (OF1.4):
2630 send: OFPT_BUNDLE_CONTROL (OF1.4):
2631  bundle_id=0x1 type=CLOSE_REQUEST flags=atomic
2632 OFPT_BUNDLE_CONTROL (OF1.4):
2633  bundle_id=0x1 type=CLOSE_REPLY flags=0
2634 OFPT_BARRIER_REPLY (OF1.4):
2635 send: OFPT_BUNDLE_CONTROL (OF1.4):
2636  bundle_id=0x1 type=CLOSE_REQUEST flags=atomic
2637 OFPT_ERROR (OF1.4): OFPBFC_BUNDLE_CLOSED
2638 OFPT_BUNDLE_CONTROL (OF1.4):
2639  bundle_id=0x1 type=CLOSE_REQUEST flags=atomic
2640 OFPT_BARRIER_REPLY (OF1.4):
2641 ])
2642
2643 OVS_VSWITCHD_STOP
2644 AT_CLEANUP
2645
2646 AT_SETUP([ofproto - bundle close, different flags (OpenFlow 1.4)])
2647 AT_KEYWORDS([monitor])
2648 OVS_VSWITCHD_START
2649
2650 # Start a monitor, use the required protocol version
2651 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2652 AT_CAPTURE_FILE([monitor.log])
2653
2654 # Open, Close, Close
2655 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 00 00 01"
2656 ovs-appctl -t ovs-ofctl ofctl/barrier
2657 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 02 00 02"
2658 ovs-appctl -t ovs-ofctl ofctl/barrier
2659 ovs-appctl -t ovs-ofctl exit
2660
2661 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2662 send: OFPT_BUNDLE_CONTROL (OF1.4):
2663  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2664 OFPT_BUNDLE_CONTROL (OF1.4):
2665  bundle_id=0x1 type=OPEN_REPLY flags=0
2666 OFPT_BARRIER_REPLY (OF1.4):
2667 send: OFPT_BUNDLE_CONTROL (OF1.4):
2668  bundle_id=0x1 type=CLOSE_REQUEST flags=ordered
2669 OFPT_ERROR (OF1.4): OFPBFC_BAD_FLAGS
2670 OFPT_BUNDLE_CONTROL (OF1.4):
2671  bundle_id=0x1 type=CLOSE_REQUEST flags=ordered
2672 OFPT_BARRIER_REPLY (OF1.4):
2673 ])
2674
2675 OVS_VSWITCHD_STOP
2676 AT_CLEANUP
2677
2678 AT_SETUP([ofproto - bundle commit without open (OpenFlow 1.4)])
2679 AT_KEYWORDS([monitor])
2680 OVS_VSWITCHD_START
2681
2682 # Start a monitor, use the required protocol version
2683 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2684 AT_CAPTURE_FILE([monitor.log])
2685
2686 # Open, Close, Close
2687 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 04 00 01"
2688 ovs-appctl -t ovs-ofctl ofctl/barrier
2689 ovs-appctl -t ovs-ofctl exit
2690
2691 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2692 send: OFPT_BUNDLE_CONTROL (OF1.4):
2693  bundle_id=0x1 type=COMMIT_REQUEST flags=atomic
2694 OFPT_ERROR (OF1.4): OFPBFC_BAD_ID
2695 OFPT_BUNDLE_CONTROL (OF1.4):
2696  bundle_id=0x1 type=COMMIT_REQUEST flags=atomic
2697 OFPT_BARRIER_REPLY (OF1.4):
2698 ])
2699
2700 OVS_VSWITCHD_STOP
2701 AT_CLEANUP
2702
2703 AT_SETUP([ofproto - bundle commit, different flags (OpenFlow 1.4)])
2704 AT_KEYWORDS([monitor])
2705 OVS_VSWITCHD_START
2706
2707 # Start a monitor, use the required protocol version
2708 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2709 AT_CAPTURE_FILE([monitor.log])
2710
2711 # Open, Close, Close
2712 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 00 00 01"
2713 ovs-appctl -t ovs-ofctl ofctl/barrier
2714 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 04 00 02"
2715 ovs-appctl -t ovs-ofctl ofctl/barrier
2716 ovs-appctl -t ovs-ofctl exit
2717
2718 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2719 send: OFPT_BUNDLE_CONTROL (OF1.4):
2720  bundle_id=0x1 type=OPEN_REQUEST flags=atomic
2721 OFPT_BUNDLE_CONTROL (OF1.4):
2722  bundle_id=0x1 type=OPEN_REPLY flags=0
2723 OFPT_BARRIER_REPLY (OF1.4):
2724 send: OFPT_BUNDLE_CONTROL (OF1.4):
2725  bundle_id=0x1 type=COMMIT_REQUEST flags=ordered
2726 OFPT_ERROR (OF1.4): OFPBFC_BAD_FLAGS
2727 OFPT_BUNDLE_CONTROL (OF1.4):
2728  bundle_id=0x1 type=COMMIT_REQUEST flags=ordered
2729 OFPT_BARRIER_REPLY (OF1.4):
2730 ])
2731
2732 OVS_VSWITCHD_STOP
2733 AT_CLEANUP
2734
2735 AT_SETUP([ofproto - bundle discard without open (OpenFlow 1.4)])
2736 AT_KEYWORDS([monitor])
2737 OVS_VSWITCHD_START
2738
2739 # Start a monitor, use the required protocol version
2740 ovs-ofctl -O OpenFlow14 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
2741 AT_CAPTURE_FILE([monitor.log])
2742
2743 # Open, Close, Close
2744 ovs-appctl -t ovs-ofctl ofctl/send "05 21 00 10 00 00 00 0a 00 00 00 01 00 06 00 01"
2745 ovs-appctl -t ovs-ofctl ofctl/barrier
2746 ovs-appctl -t ovs-ofctl exit
2747
2748 AT_CHECK([ofctl_strip < monitor.log], [0], [dnl
2749 send: OFPT_BUNDLE_CONTROL (OF1.4):
2750  bundle_id=0x1 type=DISCARD_REQUEST flags=atomic
2751 OFPT_ERROR (OF1.4): OFPBFC_BAD_ID
2752 OFPT_BUNDLE_CONTROL (OF1.4):
2753  bundle_id=0x1 type=DISCARD_REQUEST flags=atomic
2754 OFPT_BARRIER_REPLY (OF1.4):
2755 ])
2756
2757 OVS_VSWITCHD_STOP
2758 AT_CLEANUP