668246770c72354ea5dfd7837a19e39b127a5def
[sliver-openvswitch.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 - feature request, config request])
10 OVS_VSWITCHD_START
11 AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
12 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
13 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
14 n_tables:254, n_buffers:256
15 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
16 actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DST SET_NW_SRC SET_NW_DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE
17  LOCAL(br0): addr:aa:55:aa:55:00:00
18      config:     0
19      state:      0
20      speed: 0 Mbps now, 0 Mbps max
21 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
22 ])
23 OVS_VSWITCHD_STOP
24 AT_CLEANUP
25
26 AT_SETUP([ofproto - set OpenFlow port number])
27 OVS_VSWITCHD_START(
28        [add-port br0 p1 -- set Interface p1 type=dummy --\
29         add-port br0 p2 -- set Interface p2 type=dummy ofport_request=99])
30 AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
31 AT_CHECK([[sed '
32 s/ (xid=0x[0-9a-fA-F]*)//
33 s/00:0.$/00:0x/' < stdout]],
34       [0], [dnl
35 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
36 n_tables:254, n_buffers:256
37 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
38 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
39  1(p1): addr:aa:55:aa:55:00:0x
40      config:     PORT_DOWN
41      state:      LINK_DOWN
42      speed: 0 Mbps now, 0 Mbps max
43  99(p2): addr:aa:55:aa:55:00:0x
44      config:     PORT_DOWN
45      state:      LINK_DOWN
46      speed: 0 Mbps now, 0 Mbps max
47  LOCAL(br0): addr:aa:55:aa:55:00:0x
48      config:     0
49      state:      0
50      speed: 0 Mbps now, 0 Mbps max
51 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
52 ])
53
54 OVS_VSWITCHD_STOP
55 AT_CLEANUP
56
57 dnl This is really bare-bones.
58 dnl It at least checks request and reply serialization and deserialization.
59 AT_SETUP([ofproto - port stats - (OpenFlow 1.0)])
60 OVS_VSWITCHD_START
61 AT_CHECK([ovs-ofctl -vwarn dump-ports br0], [0], [stdout])
62 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
63 OFPST_PORT reply: 1 ports
64   port LOCAL: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
65            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
66 ])
67 OVS_VSWITCHD_STOP
68 AT_CLEANUP
69
70 AT_SETUP([ofproto - port stats - (OpenFlow 1.2)])
71 OVS_VSWITCHD_START
72 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn dump-ports br0], [0], [stdout])
73 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
74 OFPST_PORT reply (OF1.2): 1 ports
75   port LOCAL: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
76            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
77 ])
78 OVS_VSWITCHD_STOP
79 AT_CLEANUP
80
81 dnl This is really bare-bones.
82 dnl It at least checks request and reply serialization and deserialization.
83 AT_SETUP([ofproto - port-desc stats (OpenFlow 1.0)])
84 OVS_VSWITCHD_START
85 AT_CHECK([ovs-ofctl -vwarn dump-ports-desc br0], [0], [stdout])
86 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
87 OFPST_PORT_DESC reply:
88  LOCAL(br0): addr:aa:55:aa:55:00:00
89      config:     0
90      state:      0
91      speed: 0 Mbps now, 0 Mbps max
92 ])
93 OVS_VSWITCHD_STOP
94 AT_CLEANUP
95
96 dnl This is really bare-bones.
97 dnl It at least checks request and reply serialization and deserialization.
98 AT_SETUP([ofproto - port-desc stats (OpenFlow 1.2)])
99 OVS_VSWITCHD_START
100 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn dump-ports-desc br0], [0], [stdout])
101 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
102 OFPST_PORT_DESC reply (OF1.2):
103  LOCAL(br0): addr:aa:55:aa:55:00:00
104      config:     0
105      state:      0
106      speed: 0 Mbps now, 0 Mbps max
107 ])
108 OVS_VSWITCHD_STOP
109 AT_CLEANUP
110
111 dnl This is really bare-bones.
112 dnl It at least checks request and reply serialization and deserialization.
113 AT_SETUP([ofproto - queue stats - (OpenFlow 1.0)])
114 OVS_VSWITCHD_START
115 AT_CHECK([ovs-ofctl -vwarn queue-stats br0], [0], [stdout])
116 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
117 OFPST_QUEUE reply: 0 queues
118 ])
119 AT_CHECK([ovs-ofctl -vwarn queue-stats br0 ANY 5], [0],
120   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_QUEUE
121 OFPST_QUEUE request (xid=0x2):port=ANY queue=5
122 ])
123 AT_CHECK([ovs-ofctl -vwarn queue-stats br0 10], [0],
124   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_PORT
125 OFPST_QUEUE request (xid=0x2):port=10 queue=ALL
126 ])
127 OVS_VSWITCHD_STOP
128 AT_CLEANUP
129
130 AT_SETUP([ofproto - queue stats - (OpenFlow 1.2)])
131 OVS_VSWITCHD_START
132 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn queue-stats br0], [0], [stdout])
133 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
134 OFPST_QUEUE reply (OF1.2): 0 queues
135 ])
136 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn queue-stats br0 ALL 5], [0],
137   [OFPT_ERROR (OF1.2) (xid=0x2): OFPQOFC_BAD_QUEUE
138 OFPST_QUEUE request (OF1.2) (xid=0x2):port=ANY queue=5
139 ])
140 AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn queue-stats br0 10], [0],
141   [OFPT_ERROR (OF1.2) (xid=0x2): OFPQOFC_BAD_PORT
142 OFPST_QUEUE request (OF1.2) (xid=0x2):port=10 queue=ALL
143 ])
144 OVS_VSWITCHD_STOP
145 AT_CLEANUP
146
147 AT_SETUP([ofproto - mod-port (OpenFlow 1.0)])
148 OVS_VSWITCHD_START
149 for command_config_state in \
150     'up 0 0' \
151     'noflood NO_FLOOD 0' \
152     'down PORT_DOWN,NO_FLOOD LINK_DOWN' \
153     'flood PORT_DOWN LINK_DOWN' \
154     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
155     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
156     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
157     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
158     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
159     'up NO_RECV 0' \
160     'receive 0 0'
161 do
162     set $command_config_state
163     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
164     AT_CHECK([ovs-ofctl -vwarn mod-port br0 br0 $command])
165     AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
166     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
167 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
168 n_tables:254, n_buffers:256
169 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
170 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
171  LOCAL(br0): addr:aa:55:aa:55:00:00
172      config:     $config
173      state:      $state
174      speed: 0 Mbps now, 0 Mbps max
175 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
176 ])
177 done
178 OVS_VSWITCHD_STOP
179 AT_CLEANUP
180
181 AT_SETUP([ofproto - mod-port (OpenFlow 1.2)])
182 OVS_VSWITCHD_START
183 for command_config_state in \
184     'up 0 0' \
185     'down PORT_DOWN LINK_DOWN' \
186     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
187     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
188     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
189     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
190     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
191     'up NO_RECV 0' \
192     'receive 0 0'
193 do
194     set $command_config_state
195     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
196     AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn mod-port br0 br0 $command])
197     AT_CHECK([ovs-ofctl -O OpenFlow12 -vwarn show br0], [0], [stdout])
198     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
199 OFPT_FEATURES_REPLY (OF1.2): dpid:fedcba9876543210
200 n_tables:254, n_buffers:256
201 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS
202  LOCAL(br0): addr:aa:55:aa:55:00:00
203      config:     $config
204      state:      $state
205      speed: 0 Mbps now, 0 Mbps max
206 OFPT_GET_CONFIG_REPLY (OF1.2): frags=normal miss_send_len=0
207 ])
208 done
209 OVS_VSWITCHD_STOP
210 AT_CLEANUP
211
212 AT_SETUP([ofproto - basic flow_mod commands (NXM)])
213 OVS_VSWITCHD_START
214 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
215 ])
216 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl add-flows br0 -])
217 AT_CHECK([ovs-ofctl add-flow br0 in_port=1,actions=2])
218 AT_CHECK([ovs-ofctl -F nxm add-flow br0 table=1,in_port=4,actions=3])
219 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
220  in_port=1 actions=output:2
221  in_port=2 actions=output:1
222  table=1, in_port=4 actions=output:3
223 NXST_FLOW reply:
224 ])
225 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
226 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
227 ])
228 AT_CHECK([ovs-ofctl del-flows br0])
229 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
230 ])
231 OVS_VSWITCHD_STOP
232 AT_CLEANUP
233
234 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.0)])
235 OVS_VSWITCHD_START
236 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
237 ])
238 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl -F openflow10 add-flows br0 -])
239 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 in_port=1,actions=2])
240 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 table=1,in_port=4,actions=3])
241 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
242  in_port=1 actions=output:2
243  in_port=2 actions=output:1
244  table=1, in_port=4 actions=output:3
245 OFPST_FLOW reply:
246 ])
247 AT_CHECK([ovs-ofctl -F openflow10 dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
248 OFPST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
249 ])
250 AT_CHECK([ovs-ofctl -F openflow10 del-flows br0])
251 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
252 ])
253 OVS_VSWITCHD_STOP
254 AT_CLEANUP
255
256 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.1)])
257 OVS_VSWITCHD_START
258 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.1):
259 ])
260 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl -O OpenFlow11 add-flows br0 -])
261 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 in_port=1,actions=2])
262 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 table=1,in_port=4,actions=3])
263 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
264  in_port=1 actions=output:2
265  in_port=2 actions=output:1
266  table=1, in_port=4 actions=output:3
267 OFPST_FLOW reply (OF1.1):
268 ])
269 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
270 OFPST_AGGREGATE reply (OF1.1): packet_count=0 byte_count=0 flow_count=2
271 ])
272 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0])
273 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.1):
274 ])
275 OVS_VSWITCHD_STOP
276 AT_CLEANUP
277
278 AT_SETUP([ofproto - flow_mod negative test (OpenFlow 1.1)])
279 OVS_VSWITCHD_START(
280   [set bridge br0 protocols=OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13])
281 AT_CHECK([ovs-ofctl add-flow -O OpenFlow11 br0 table=1,action=goto_table:2])
282 AT_CHECK([ovs-ofctl add-flow -O OpenFlow11 br0 table=1,action=goto_table:1],
283   [1], [], [stderr])
284
285 # The output should look like this:
286 #
287 # OFPT_ERROR (OF1.1) (xid=0x2): OFPBRC_BAD_TABLE_ID
288 # OFPT_FLOW_MOD (OF1.1) (xid=0x2):
289 # (***truncated to 64 bytes from 160***)
290 # 00000000  02 0e 00 a0 00 00 00 02-00 00 00 00 00 00 00 00 |................|
291 # 00000010  00 00 00 00 00 00 00 00-01 00 00 00 00 00 80 00 |................|
292 # 00000020  ff ff ff ff ff ff ff ff-ff ff ff ff 00 00 00 00 |................|
293 # 00000030  00 00 00 58 00 00 00 00-00 00 03 ff 00 00 00 00 |...X............|
294 #
295 # This 'sed' command captures the error message but drops details.
296 AT_CHECK([sed '/truncated/d
297 /^000000.0/d' stderr | STRIP_XIDS], [0],
298   [OFPT_ERROR (OF1.1): OFPBRC_BAD_TABLE_ID
299 OFPT_FLOW_MOD (OF1.1):
300 ])
301 OVS_VSWITCHD_STOP
302 AT_CLEANUP
303
304 AT_SETUP([ofproto - set-field flow_mod commands (NXM)])
305 OVS_VSWITCHD_START
306 AT_CHECK([ovs-ofctl add-flow br0 ipv6,table=1,in_port=3,actions=drop])
307 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])
308 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
309  table=1, ipv6,in_port=3 actions=load:0xa6badbfffefe59fa->NXM_NX_IPV6_SRC[[0..63]],load:0xfe8001234567890a->NXM_NX_IPV6_SRC[[64..127]]
310 NXST_FLOW reply:
311 ])
312 OVS_VSWITCHD_STOP
313 AT_CLEANUP
314
315 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.2)])
316 OVS_VSWITCHD_START
317 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.2):
318 ])
319 AT_CHECK([echo 'in_port=2,actions=1' | ovs-ofctl -O OpenFlow12 add-flows br0 -])
320 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=1,actions=2])
321 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 table=1,in_port=4,actions=3])
322 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
323  in_port=1 actions=output:2
324  in_port=2 actions=output:1
325  table=1, in_port=4 actions=output:3
326 OFPST_FLOW reply (OF1.2):
327 ])
328 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0])
329 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply (OF1.2):
330 ])
331 OVS_VSWITCHD_STOP
332 AT_CLEANUP
333
334 AT_SETUP([ofproto - dump flows with cookie])
335 OVS_VSWITCHD_START
336 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
337 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
338 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
339 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
340  cookie=0x1, in_port=1 actions=output:1
341  cookie=0x2, in_port=2 actions=output:1
342  cookie=0x3, in_port=3 actions=output:1
343 NXST_FLOW reply:
344 ])
345 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
346 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=3
347 ])
348 AT_CHECK([ovs-ofctl dump-flows br0 cookie=0x3/-1 | ofctl_strip | sort], [0], [dnl
349  cookie=0x3, in_port=3 actions=output:1
350 NXST_FLOW reply:
351 ])
352 AT_CHECK([ovs-ofctl dump-aggregate br0 cookie=0x3/-1 | STRIP_XIDS], [0], [dnl
353 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=1
354 ])
355 OVS_VSWITCHD_STOP
356 AT_CLEANUP
357
358 AT_SETUP([ofproto - mod flow with cookie change (OpenFlow 1.0)])
359 OVS_VSWITCHD_START
360 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 cookie=0x1,in_port=1,actions=1])
361 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
362  cookie=0x1, in_port=1 actions=output:1
363 OFPST_FLOW reply:
364 ])
365
366 AT_CHECK([ovs-ofctl -F openflow10 mod-flows br0 cookie=0x2,in_port=1,actions=1])
367 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
368  cookie=0x2, in_port=1 actions=output:1
369 OFPST_FLOW reply:
370 ])
371 OVS_VSWITCHD_STOP
372 AT_CLEANUP
373
374 AT_SETUP([ofproto - mod flow with cookie change (NXM)])
375 OVS_VSWITCHD_START
376 AT_CHECK([ovs-ofctl -F nxm add-flow br0 cookie=0x1,in_port=1,actions=1])
377 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
378  cookie=0x1, in_port=1 actions=output:1
379 NXST_FLOW reply:
380 ])
381
382 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x2,in_port=1,actions=1])
383 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
384  cookie=0x2, in_port=1 actions=output:1
385 NXST_FLOW reply:
386 ])
387 OVS_VSWITCHD_STOP
388 AT_CLEANUP
389
390 AT_SETUP([ofproto - no mod flow with cookie change (OpenFlow 1.1)])
391 OVS_VSWITCHD_START
392 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
393 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
394  cookie=0x1, in_port=1 actions=output:1
395 OFPST_FLOW reply (OF1.1):
396 ])
397 AT_CHECK([ovs-ofctl -O OpenFlow11 mod-flows br0 cookie=0x2,in_port=1,actions=1])
398 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
399  cookie=0x1, in_port=1 actions=output:1
400 OFPST_FLOW reply (OF1.1):
401 ])
402 OVS_VSWITCHD_STOP
403 AT_CLEANUP
404
405 dnl The OpenFlow 1.2 spec states that the cookie may not be modified
406 AT_SETUP([ofproto - no mod flow with cookie change (OpenFlow 1.2)])
407 OVS_VSWITCHD_START
408 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
409 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
410  cookie=0x1, in_port=1 actions=output:1
411 OFPST_FLOW reply (OF1.2):
412 ])
413
414 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 cookie=0x2,in_port=1,actions=1])
415 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
416  cookie=0x1, in_port=1 actions=output:1
417 OFPST_FLOW reply (OF1.2):
418 ])
419 OVS_VSWITCHD_STOP
420 AT_CLEANUP
421
422 AT_SETUP([ofproto - mod flows based on cookie mask (OpenFlow 1.0)])
423 OVS_VSWITCHD_START
424 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
425 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=1])
426 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=1])
427 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
428  cookie=0x1, in_port=1 actions=output:1
429  cookie=0x1, in_port=2 actions=output:1
430  cookie=0x2, in_port=3 actions=output:1
431 NXST_FLOW reply:
432 ])
433
434 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x1/0xff,actions=4])
435 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
436  cookie=0x1, in_port=1 actions=output:4
437  cookie=0x1, in_port=2 actions=output:4
438  cookie=0x2, in_port=3 actions=output:1
439 NXST_FLOW reply:
440 ])
441 OVS_VSWITCHD_STOP
442 AT_CLEANUP
443
444 AT_SETUP([ofproto - mod flows based on cookie mask (OpenFlow 1.1)])
445 OVS_VSWITCHD_START
446 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
447 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=2,actions=1])
448 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x2,in_port=3,actions=1])
449 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
450  cookie=0x1, in_port=1 actions=output:1
451  cookie=0x1, in_port=2 actions=output:1
452  cookie=0x2, in_port=3 actions=output:1
453 OFPST_FLOW reply (OF1.1):
454 ])
455
456 AT_CHECK([ovs-ofctl -O OpenFlow11 mod-flows br0 cookie=0x1/0xff,actions=4])
457 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
458  cookie=0x1, in_port=1 actions=output:4
459  cookie=0x1, in_port=2 actions=output:4
460  cookie=0x2, in_port=3 actions=output:1
461 OFPST_FLOW reply (OF1.1):
462 ])
463 OVS_VSWITCHD_STOP
464 AT_CLEANUP
465
466 AT_SETUP([ofproto - mod flows based on cookie mask (OpenFlow 1.2)])
467 OVS_VSWITCHD_START
468 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
469 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=2,actions=1])
470 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x2,in_port=3,actions=1])
471 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
472  cookie=0x1, in_port=1 actions=output:1
473  cookie=0x1, in_port=2 actions=output:1
474  cookie=0x2, in_port=3 actions=output:1
475 OFPST_FLOW reply (OF1.2):
476 ])
477
478 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 cookie=0x1/0xff,actions=4])
479 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
480  cookie=0x1, in_port=1 actions=output:4
481  cookie=0x1, in_port=2 actions=output:4
482  cookie=0x2, in_port=3 actions=output:1
483 OFPST_FLOW reply (OF1.2):
484 ])
485 OVS_VSWITCHD_STOP
486 AT_CLEANUP
487
488 dnl The OpenFlow 1.2 spec states that the cookie may not be modified
489 AT_SETUP([ofproto - mod flows based on cookie mask with cookie change])
490 OVS_VSWITCHD_START
491 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
492 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=1])
493 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=1])
494 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
495  cookie=0x1, in_port=1 actions=output:1
496  cookie=0x1, in_port=2 actions=output:1
497  cookie=0x2, in_port=3 actions=output:1
498 NXST_FLOW reply:
499 ])
500
501 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/-1,cookie=4,actions=4])
502 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
503  cookie=0x2, in_port=3 actions=output:1
504  cookie=0x4, in_port=1 actions=output:4
505  cookie=0x4, in_port=2 actions=output:4
506 NXST_FLOW reply:
507 ])
508 OVS_VSWITCHD_STOP
509 AT_CLEANUP
510
511 AT_SETUP([ofproto - mod flow with cookie miss (mask==0) - NXM])
512 OVS_VSWITCHD_START
513 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 in_port=1,actions=1])
514 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
515  in_port=1 actions=output:1
516 NXST_FLOW reply:
517 ])
518 OVS_VSWITCHD_STOP
519 AT_CLEANUP
520
521 AT_SETUP([ofproto - mod flow with cookie miss (mask==0) - OF1.1])
522 OVS_VSWITCHD_START
523 AT_CHECK([ovs-ofctl -O openflow11 mod-flows br0 in_port=1,actions=1])
524 AT_CHECK([ovs-ofctl -O openflow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
525  in_port=1 actions=output:1
526 OFPST_FLOW reply (OF1.1):
527 ])
528 OVS_VSWITCHD_STOP
529 AT_CLEANUP
530
531 AT_SETUP([ofproto - mod flow with cookie miss (mask==0) - OF1.2])
532 OVS_VSWITCHD_START
533 AT_CHECK([ovs-ofctl -O openflow12 mod-flows br0 in_port=1,actions=1])
534 AT_CHECK([ovs-ofctl -O openflow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
535 OFPST_FLOW reply (OF1.2):
536 ])
537 OVS_VSWITCHD_STOP
538 AT_CLEANUP
539
540 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0) - NXM])
541 OVS_VSWITCHD_START
542 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/1,in_port=1,actions=1])
543 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
544 NXST_FLOW reply:
545 ])
546 OVS_VSWITCHD_STOP
547 AT_CLEANUP
548
549 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0) - OF1.1])
550 OVS_VSWITCHD_START
551 AT_CHECK([ovs-ofctl -O openflow11 mod-flows br0 cookie=1/1,in_port=1,actions=1])
552 AT_CHECK([ovs-ofctl -O openflow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
553 OFPST_FLOW reply (OF1.1):
554 ])
555 OVS_VSWITCHD_STOP
556 AT_CLEANUP
557
558 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0) - OF1.2])
559 OVS_VSWITCHD_START
560 AT_CHECK([ovs-ofctl -O openflow12 mod-flows br0 cookie=1/1,in_port=1,actions=1])
561 AT_CHECK([ovs-ofctl -O openflow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
562 OFPST_FLOW reply (OF1.2):
563 ])
564 OVS_VSWITCHD_STOP
565 AT_CLEANUP
566
567 AT_SETUP([ofproto - del flows with cookies])
568 OVS_VSWITCHD_START
569 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
570 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
571 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
572 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
573  cookie=0x1, in_port=1 actions=output:1
574  cookie=0x2, in_port=2 actions=output:1
575  cookie=0x3, in_port=3 actions=output:1
576 NXST_FLOW reply:
577 ])
578
579 AT_CHECK([ovs-ofctl del-flows br0])
580 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
581 NXST_FLOW reply:
582 ])
583 OVS_VSWITCHD_STOP
584 AT_CLEANUP
585
586 AT_SETUP([ofproto - del flows based on cookie])
587 OVS_VSWITCHD_START
588 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
589 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
590 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
591 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
592  cookie=0x1, in_port=1 actions=output:1
593  cookie=0x2, in_port=2 actions=output:1
594  cookie=0x3, in_port=3 actions=output:1
595 NXST_FLOW reply:
596 ])
597
598 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/-1])
599 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
600  cookie=0x1, in_port=1 actions=output:1
601  cookie=0x2, in_port=2 actions=output:1
602 NXST_FLOW reply:
603 ])
604 OVS_VSWITCHD_STOP
605 AT_CLEANUP
606
607 AT_SETUP([ofproto - del flows based on cookie mask])
608 OVS_VSWITCHD_START
609 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
610 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=1])
611 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=1])
612 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
613  cookie=0x1, in_port=1 actions=output:1
614  cookie=0x2, in_port=2 actions=output:1
615  cookie=0x3, in_port=3 actions=output:1
616 NXST_FLOW reply:
617 ])
618 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/0x1])
619 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
620  cookie=0x2, in_port=2 actions=output:1
621 NXST_FLOW reply:
622 ])
623 OVS_VSWITCHD_STOP
624 AT_CLEANUP
625
626 AT_SETUP([ofproto - del flows based on table id (NXM)])
627 OVS_VSWITCHD_START
628 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
629 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
630 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
631  cookie=0x1, in_port=1 actions=output:1
632  cookie=0x2, table=1, in_port=2 actions=output:1
633 NXST_FLOW reply:
634 ])
635 AT_CHECK([ovs-ofctl del-flows br0 table=0])
636 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
637  cookie=0x2, table=1, in_port=2 actions=output:1
638 NXST_FLOW reply:
639 ])
640 AT_CHECK([ovs-ofctl del-flows br0 table=1])
641 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
642 NXST_FLOW reply:
643 ])
644 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=1])
645 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
646 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
647  cookie=0x1, in_port=1 actions=output:1
648  cookie=0x2, table=1, in_port=2 actions=output:1
649 NXST_FLOW reply:
650 ])
651 AT_CHECK([ovs-ofctl del-flows br0])
652 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
653 NXST_FLOW reply:
654 ])
655 OVS_VSWITCHD_STOP
656 AT_CLEANUP
657
658 AT_SETUP([ofproto - del flows based on table id (OpenFlow 1.1)])
659 OVS_VSWITCHD_START
660 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
661 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
662 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
663  cookie=0x1, in_port=1 actions=output:1
664  cookie=0x2, table=1, in_port=2 actions=output:1
665 OFPST_FLOW reply (OF1.1):
666 ])
667 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0 table=0])
668 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
669  cookie=0x2, table=1, in_port=2 actions=output:1
670 OFPST_FLOW reply (OF1.1):
671 ])
672 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0 table=1])
673 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
674 OFPST_FLOW reply (OF1.1):
675 ])
676 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x1,in_port=1,actions=1])
677 AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
678 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
679  cookie=0x1, in_port=1 actions=output:1
680  cookie=0x2, table=1, in_port=2 actions=output:1
681 OFPST_FLOW reply (OF1.1):
682 ])
683 AT_CHECK([ovs-ofctl -O OpenFlow11 del-flows br0])
684 AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dnl
685 OFPST_FLOW reply (OF1.1):
686 ])
687 OVS_VSWITCHD_STOP
688 AT_CLEANUP
689
690 AT_SETUP([ofproto - del flows based on table id (OpenFlow 1.2)])
691 OVS_VSWITCHD_START
692 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
693 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
694 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
695  cookie=0x1, in_port=1 actions=output:1
696  cookie=0x2, table=1, in_port=2 actions=output:1
697 OFPST_FLOW reply (OF1.2):
698 ])
699 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0 table=0])
700 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
701  cookie=0x2, table=1, in_port=2 actions=output:1
702 OFPST_FLOW reply (OF1.2):
703 ])
704 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0 table=1])
705 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
706 OFPST_FLOW reply (OF1.2):
707 ])
708 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x1,in_port=1,actions=1])
709 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 cookie=0x2,in_port=2,table=1,actions=1])
710 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
711  cookie=0x1, in_port=1 actions=output:1
712  cookie=0x2, table=1, in_port=2 actions=output:1
713 OFPST_FLOW reply (OF1.2):
714 ])
715 AT_CHECK([ovs-ofctl -O OpenFlow12 del-flows br0])
716 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
717 OFPST_FLOW reply (OF1.2):
718 ])
719 OVS_VSWITCHD_STOP
720 AT_CLEANUP
721
722 AT_SETUP([ofproto - flow table configuration (OpenFlow 1.0)])
723 OVS_VSWITCHD_START
724 # Check the default configuration.
725 (echo "OFPST_TABLE reply (xid=0x2): 254 tables
726   0: classifier: wild=0x3fffff, max=1000000, active=0
727                lookup=0, matched=0"
728  x=1
729  while test $x -lt 254; do
730    printf "  %d: %-8s: wild=0x3fffff, max=1000000, active=0
731                lookup=0, matched=0
732 " $x table$x
733    x=`expr $x + 1`
734  done) > expout
735 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
736 # Change the configuration.
737 AT_CHECK(
738   [ovs-vsctl \
739      -- --id=@t0 create Flow_Table name=main \
740      -- --id=@t1 create Flow_Table flow-limit=1024 \
741      -- set bridge br0 'flow_tables={1=@t1,0=@t0}' \
742    | ${PERL} $srcdir/uuidfilt.pl],
743   [0], [<0>
744 <1>
745 ])
746 # Check that the configuration was updated.
747 mv expout orig-expout
748 (echo "OFPST_TABLE reply (xid=0x2): 254 tables
749   0: main    : wild=0x3fffff, max=1000000, active=0
750                lookup=0, matched=0
751   1: table1  : wild=0x3fffff, max=  1024, active=0
752                lookup=0, matched=0"
753  tail -n +6 orig-expout) > expout
754 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
755 OVS_VSWITCHD_STOP
756 AT_CLEANUP
757
758 AT_SETUP([ofproto - flow table configuration (OpenFlow 1.2)])
759 OVS_VSWITCHD_START
760 # Check the default configuration.
761 (mid="wild=0xfffffffff, max=1000000,"
762  tail="
763                lookup=0, matched=0
764                match=0xfffffffff, instructions=0x00000007, config=0x00000003
765                write_actions=0x00000000, apply_actions=0x00000000
766                write_setfields=0x0000000fffffffff
767                apply_setfields=0x0000000fffffffff
768                metadata_match=0xffffffffffffffff
769                metadata_write=0xffffffffffffffff"
770  echo "OFPST_TABLE reply (OF1.2) (xid=0x2): 254 tables
771   0: classifier: $mid active=0$tail"
772  x=1
773  while test $x -lt 254; do
774    printf "  %d: %-8s: $mid active=0$tail
775 " $x table$x
776    x=`expr $x + 1`
777  done) > expout
778 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-tables br0], [0], [expout])
779 # Change the configuration.
780 AT_CHECK(
781   [ovs-vsctl \
782      -- --id=@t0 create Flow_Table name=main \
783      -- --id=@t1 create Flow_Table flow-limit=1024 \
784      -- set bridge br0 'flow_tables={1=@t1,0=@t0}' \
785    | ${PERL} $srcdir/uuidfilt.pl],
786   [0], [<0>
787 <1>
788 ])
789 # Check that the configuration was updated.
790 mv expout orig-expout
791 (echo "OFPST_TABLE reply (OF1.2) (xid=0x2): 254 tables
792   0: main    : wild=0xfffffffff, max=1000000, active=0"
793  tail -n +3 orig-expout | head -7
794  echo "  1: table1  : wild=0xfffffffff, max=  1024, active=0"
795  tail -n +11 orig-expout) > expout
796 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-tables br0], [0], [expout])
797 OVS_VSWITCHD_STOP
798 AT_CLEANUP
799
800 AT_SETUP([ofproto - hard limits on flow table size (OpenFLow 1.0)])
801 OVS_VSWITCHD_START
802 # Configure a maximum of 4 flows.
803 AT_CHECK(
804   [ovs-vsctl \
805      -- --id=@t0 create Flow_Table flow-limit=4 \
806      -- set bridge br0 flow_tables:0=@t0 \
807    | ${PERL} $srcdir/uuidfilt.pl],
808   [0], [<0>
809 ])
810 # Add 4 flows.
811 for in_port in 1 2 3 4; do
812     ovs-ofctl add-flow br0 in_port=$in_port,actions=drop
813 done
814 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
815  in_port=1 actions=drop
816  in_port=2 actions=drop
817  in_port=3 actions=drop
818  in_port=4 actions=drop
819 NXST_FLOW reply:
820 ])
821 # Adding another flow will be refused.
822 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop], [1], [], [stderr])
823 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
824   [OFPT_ERROR: OFPFMFC_TABLE_FULL
825 ])
826 # Also a mod-flow that would add a flow will be refused.
827 AT_CHECK([ovs-ofctl mod-flows br0 in_port=5,actions=drop], [1], [], [stderr])
828 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
829   [OFPT_ERROR: OFPFMFC_TABLE_FULL
830 ])
831 # Replacing or modifying an existing flow is allowed.
832 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
833 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
834 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
835  in_port=1 actions=drop
836  in_port=2 actions=drop
837  in_port=3 actions=output:1
838  in_port=4 actions=NORMAL
839 NXST_FLOW reply:
840 ])
841 OVS_VSWITCHD_STOP
842 AT_CLEANUP
843
844 AT_SETUP([ofproto - hard limits on flow table size (OpenFLow 1.2)])
845 OVS_VSWITCHD_START
846 # Configure a maximum of 4 flows.
847 AT_CHECK(
848   [ovs-vsctl \
849      -- --id=@t0 create Flow_Table flow-limit=4 \
850      -- set bridge br0 flow_tables:0=@t0 \
851    | ${PERL} $srcdir/uuidfilt.pl],
852   [0], [<0>
853 ])
854 # Add 4 flows.
855 for in_port in 1 2 3 4; do
856     ovs-ofctl -O OpenFlow12 add-flow br0 in_port=$in_port,actions=drop
857 done
858 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
859  in_port=1 actions=drop
860  in_port=2 actions=drop
861  in_port=3 actions=drop
862  in_port=4 actions=drop
863 OFPST_FLOW reply (OF1.2):
864 ])
865 # Adding another flow will be refused.
866 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=5,actions=drop], [1], [], [stderr])
867 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
868   [OFPT_ERROR (OF1.2): OFPFMFC_TABLE_FULL
869 ])
870 # Replacing or modifying an existing flow is allowed.
871 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=4,actions=normal])
872 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 in_port=3,actions=output:1])
873 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
874  in_port=1 actions=drop
875  in_port=2 actions=drop
876  in_port=3 actions=output:1
877  in_port=4 actions=NORMAL
878 OFPST_FLOW reply (OF1.2):
879 ])
880 OVS_VSWITCHD_STOP
881 AT_CLEANUP
882
883 AT_SETUP([ofproto - eviction upon table overflow (OpenFlow 1.0)])
884 OVS_VSWITCHD_START
885 # Configure a maximum of 4 flows.
886 AT_CHECK(
887   [ovs-vsctl \
888      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
889      -- set bridge br0 flow_tables:0=@t0 \
890    | ${PERL} $srcdir/uuidfilt.pl],
891   [0], [<0>
892 ])
893 # Add 4 flows.
894 for in_port in 4 3 2 1; do
895     ovs-ofctl add-flow br0 idle_timeout=${in_port}0,in_port=$in_port,actions=drop
896 done
897 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
898  idle_timeout=10, in_port=1 actions=drop
899  idle_timeout=20, in_port=2 actions=drop
900  idle_timeout=30, in_port=3 actions=drop
901  idle_timeout=40, in_port=4 actions=drop
902 NXST_FLOW reply:
903 ])
904 # Adding another flow will cause the one that expires soonest to be evicted.
905 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop])
906 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
907  idle_timeout=20, in_port=2 actions=drop
908  idle_timeout=30, in_port=3 actions=drop
909  idle_timeout=40, in_port=4 actions=drop
910  in_port=5 actions=drop
911 NXST_FLOW reply:
912 ])
913 # A mod-flow that adds a flow also causes eviction, but replacing or
914 # modifying an existing flow doesn't.
915 AT_CHECK([ovs-ofctl mod-flows br0 in_port=6,actions=drop])
916 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
917 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
918 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
919  idle_timeout=30, in_port=3 actions=output:1
920  in_port=4 actions=NORMAL
921  in_port=5 actions=drop
922  in_port=6 actions=drop
923 NXST_FLOW reply:
924 ])
925 # Flows with no timeouts at all cannot be evicted.
926 AT_CHECK([ovs-ofctl add-flow br0 in_port=7,actions=normal])
927 AT_CHECK([ovs-ofctl add-flow br0 in_port=8,actions=drop], [1], [], [stderr])
928 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
929   [OFPT_ERROR: OFPFMFC_TABLE_FULL
930 ])
931 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
932  in_port=4 actions=NORMAL
933  in_port=5 actions=drop
934  in_port=6 actions=drop
935  in_port=7 actions=NORMAL
936 NXST_FLOW reply:
937 ])
938 OVS_VSWITCHD_STOP
939 AT_CLEANUP
940
941 AT_SETUP([ofproto - eviction upon table overflow (OpenFlow 1.2)])
942 OVS_VSWITCHD_START
943 # Configure a maximum of 4 flows.
944 AT_CHECK(
945   [ovs-vsctl \
946      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
947      -- set bridge br0 flow_tables:0=@t0 \
948    | ${PERL} $srcdir/uuidfilt.pl],
949   [0], [<0>
950 ])
951 # Add 4 flows.
952 for in_port in 4 3 2 1; do
953     ovs-ofctl -O OpenFlow12 add-flow br0 idle_timeout=${in_port}0,in_port=$in_port,actions=drop
954 done
955 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
956  idle_timeout=10, in_port=1 actions=drop
957  idle_timeout=20, in_port=2 actions=drop
958  idle_timeout=30, in_port=3 actions=drop
959  idle_timeout=40, in_port=4 actions=drop
960 OFPST_FLOW reply (OF1.2):
961 ])
962 # Adding another flow will cause the one that expires soonest to be evicted.
963 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=5,actions=drop])
964 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
965  idle_timeout=20, in_port=2 actions=drop
966  idle_timeout=30, in_port=3 actions=drop
967  idle_timeout=40, in_port=4 actions=drop
968  in_port=5 actions=drop
969 OFPST_FLOW reply (OF1.2):
970 ])
971 # In Open Flow 1.2 a mod-flow does not ever add a flow and thus
972 # has no effect on eviction
973 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 in_port=6,actions=drop])
974 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=4,actions=normal])
975 AT_CHECK([ovs-ofctl -O OpenFlow12 mod-flows br0 in_port=3,actions=output:1])
976 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
977  idle_timeout=20, in_port=2 actions=drop
978  idle_timeout=30, in_port=3 actions=output:1
979  in_port=4 actions=NORMAL
980  in_port=5 actions=drop
981 OFPST_FLOW reply (OF1.2):
982 ])
983 # Flows with no timeouts at all cannot be evicted.
984 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=6,actions=drop])
985 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=7,actions=normal])
986 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=8,actions=drop], [1], [], [stderr])
987 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
988   [OFPT_ERROR (OF1.2): OFPFMFC_TABLE_FULL
989 ])
990 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
991  in_port=4 actions=NORMAL
992  in_port=5 actions=drop
993  in_port=6 actions=drop
994  in_port=7 actions=NORMAL
995 OFPST_FLOW reply (OF1.2):
996 ])
997 OVS_VSWITCHD_STOP
998 AT_CLEANUP
999
1000 AT_SETUP([ofproto - eviction upon table overflow, with fairness (OpenFlow 1.0)])
1001 OVS_VSWITCHD_START
1002 # Configure a maximum of 4 flows.
1003 AT_CHECK(
1004   [ovs-vsctl \
1005      -- --id=@t0 create Flow_Table name=evict flow-limit=4 \
1006                                    overflow-policy=evict \
1007                                    groups='"NXM_OF_IN_PORT[[]]"' \
1008      -- set bridge br0 flow_tables:0=@t0 \
1009    | ${PERL} $srcdir/uuidfilt.pl],
1010   [0], [<0>
1011 ])
1012 # Add 4 flows.
1013 ovs-ofctl add-flows br0 - <<EOF
1014 idle_timeout=10 in_port=2 dl_src=00:44:55:66:77:88 actions=drop
1015 idle_timeout=20 in_port=1 dl_src=00:11:22:33:44:55 actions=drop
1016 idle_timeout=30 in_port=1 dl_src=00:22:33:44:55:66 actions=drop
1017 idle_timeout=40 in_port=1 dl_src=00:33:44:55:66:77 actions=drop
1018 EOF
1019 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1020  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1021  idle_timeout=20, in_port=1,dl_src=00:11:22:33:44:55 actions=drop
1022  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1023  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1024 NXST_FLOW reply:
1025 ])
1026 # Adding another flow will cause the one that expires soonest within
1027 # the largest group (those with in_port=1) to be evicted.  In this
1028 # case this is not the same as the one that expires soonest overall
1029 # (which is what makes the test interesting):
1030 AT_CHECK([ovs-ofctl add-flow br0 in_port=2,dl_src=00:55:66:77:88:99,actions=drop])
1031 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1032  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1033  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1034  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1035  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1036 NXST_FLOW reply:
1037 ])
1038 # Enlarge the flow limit, change the eviction policy back to strictly
1039 # based on expiration, and and add some flows.
1040 AT_CHECK([ovs-vsctl set Flow_Table evict groups='[[]]' flow-limit=7])
1041 ovs-ofctl add-flows br0 - <<EOF
1042 idle_timeout=50 in_port=2 dl_src=00:66:77:88:99:aa actions=drop
1043 idle_timeout=60 in_port=2 dl_src=00:77:88:99:aa:bb actions=drop
1044 idle_timeout=70 in_port=2 dl_src=00:88:99:aa:bb:cc actions=drop
1045 EOF
1046 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1047  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1048  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1049  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1050  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1051  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1052  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1053  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1054 NXST_FLOW reply:
1055 ])
1056 # Adding another flow will cause the one that expires soonest overall
1057 # to be evicted.
1058 AT_CHECK([ovs-ofctl add-flow br0 'idle_timeout=80 in_port=2 dl_src=00:99:aa:bb:cc:dd actions=drop'])
1059 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1060  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1061  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1062  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1063  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1064  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1065  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1066  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1067 NXST_FLOW reply:
1068 ])
1069 # Reducing the flow limit also causes the flows that expire soonest
1070 # overall to be evicted.
1071 AT_CHECK([ovs-vsctl set Flow_Table evict flow-limit=4])
1072 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
1073  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1074  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1075  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1076  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1077 NXST_FLOW reply:
1078 ])
1079 OVS_VSWITCHD_STOP
1080 AT_CLEANUP
1081
1082 AT_SETUP([ofproto - eviction upon table overflow, with fairness (OpenFlow 1.2)])
1083 OVS_VSWITCHD_START
1084 # Configure a maximum of 4 flows.
1085 AT_CHECK(
1086   [ovs-vsctl \
1087      -- --id=@t0 create Flow_Table name=evict flow-limit=4 \
1088                                    overflow-policy=evict \
1089                                    groups='"NXM_OF_IN_PORT[[]]"' \
1090      -- set bridge br0 flow_tables:0=@t0 \
1091    | ${PERL} $srcdir/uuidfilt.pl],
1092   [0], [<0>
1093 ])
1094 # Add 4 flows.
1095 ovs-ofctl -O OpenFlow12 add-flows br0 - <<EOF
1096 idle_timeout=10 in_port=2 dl_src=00:44:55:66:77:88 actions=drop
1097 idle_timeout=20 in_port=1 dl_src=00:11:22:33:44:55 actions=drop
1098 idle_timeout=30 in_port=1 dl_src=00:22:33:44:55:66 actions=drop
1099 idle_timeout=40 in_port=1 dl_src=00:33:44:55:66:77 actions=drop
1100 EOF
1101 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1102  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1103  idle_timeout=20, in_port=1,dl_src=00:11:22:33:44:55 actions=drop
1104  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1105  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1106 OFPST_FLOW reply (OF1.2):
1107 ])
1108 # Adding another flow will cause the one that expires soonest within
1109 # the largest group (those with in_port=1) to be evicted.  In this
1110 # case this is not the same as the one that expires soonest overall
1111 # (which is what makes the test interesting):
1112 AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 in_port=2,dl_src=00:55:66:77:88:99,actions=drop])
1113 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1114  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1115  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1116  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1117  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1118 OFPST_FLOW reply (OF1.2):
1119 ])
1120 # Enlarge the flow limit, change the eviction policy back to strictly
1121 # based on expiration, and and add some flows.
1122 AT_CHECK([ovs-vsctl set Flow_Table evict groups='[[]]' flow-limit=7])
1123 ovs-ofctl -O OpenFlow12 add-flows br0 - <<EOF
1124 idle_timeout=50 in_port=2 dl_src=00:66:77:88:99:aa actions=drop
1125 idle_timeout=60 in_port=2 dl_src=00:77:88:99:aa:bb actions=drop
1126 idle_timeout=70 in_port=2 dl_src=00:88:99:aa:bb:cc actions=drop
1127 EOF
1128 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1129  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
1130  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1131  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1132  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1133  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1134  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1135  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1136 OFPST_FLOW reply (OF1.2):
1137 ])
1138 # Adding another flow will cause the one that expires soonest overall
1139 # to be evicted.
1140 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'])
1141 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1142  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
1143  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
1144  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
1145  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1146  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1147  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1148  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1149 OFPST_FLOW reply (OF1.2):
1150 ])
1151 # Reducing the flow limit also causes the flows that expire soonest
1152 # overall to be evicted.
1153 AT_CHECK([ovs-vsctl set Flow_Table evict flow-limit=4])
1154 AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip | sort], [0], [dnl
1155  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
1156  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
1157  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
1158  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
1159 OFPST_FLOW reply (OF1.2):
1160 ])
1161 OVS_VSWITCHD_STOP
1162 AT_CLEANUP
1163
1164 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.0)])
1165 OVS_VSWITCHD_START
1166 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
1167 check_async () {
1168     printf '\n\n--- check_async %d ---\n\n\n' $1
1169     shift
1170
1171     ovs-appctl -t ovs-ofctl ofctl/barrier
1172     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1173     : > expout
1174
1175     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
1176     ovs-ofctl -v packet-out br0 controller controller '0001020304050010203040501234'
1177     if test X"$1" = X"OFPR_ACTION"; then shift;
1178         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
1179 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"
1180     fi
1181
1182     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
1183     ovs-ofctl -v packet-out br0 controller 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
1184     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
1185         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via no_match) data_len=14 (unbuffered)
1186 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"
1187     fi
1188
1189     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
1190     ovs-ofctl packet-out br0 controller dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
1191     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
1192         echo >>expout "OFPT_PACKET_IN: total_len=76 in_port=CONTROLLER (via invalid_ttl) data_len=76 (unbuffered)
1193 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"
1194     fi
1195
1196     # OFPT_PORT_STATUS, OFPPR_ADD
1197     ovs-vsctl add-port br0 test -- set Interface test type=dummy ofport_request=1
1198     if test X"$1" = X"OFPPR_ADD"; then shift;
1199         echo >>expout "OFPT_PORT_STATUS: ADD: 1(test): addr:aa:55:aa:55:00:0x
1200      config:     PORT_DOWN
1201      state:      LINK_DOWN
1202      speed: 0 Mbps now, 0 Mbps max"
1203     fi
1204
1205     # OFPT_PORT_STATUS, OFPPR_DELETE
1206     ovs-vsctl del-port br0 test
1207     if test X"$1" = X"OFPPR_DELETE"; then shift;
1208         echo >>expout "OFPT_PORT_STATUS: DEL: 1(test): addr:aa:55:aa:55:00:0x
1209      config:     PORT_DOWN
1210      state:      LINK_DOWN
1211      speed: 0 Mbps now, 0 Mbps max"
1212     fi
1213
1214     # OFPT_FLOW_REMOVED, OFPRR_DELETE
1215     ovs-ofctl add-flow br0 send_flow_rem,actions=drop
1216     ovs-ofctl --strict del-flows br0 ''
1217     if test X"$1" = X"OFPRR_DELETE"; then shift;
1218         echo >>expout "OFPT_FLOW_REMOVED:  reason=delete"
1219     fi
1220     AT_FAIL_IF([test X"$1" != X])
1221
1222     ovs-appctl -t ovs-ofctl ofctl/barrier
1223     echo >>expout "OFPT_BARRIER_REPLY:"
1224
1225     AT_CHECK(
1226       [[sed '
1227 s/ (xid=0x[0-9a-fA-F]*)//
1228 s/ *duration.*//
1229 s/00:0.$/00:0x/' < monitor.log]],
1230       [0], [expout])
1231 }
1232
1233 # It's a service connection so initially there should be no async messages.
1234 check_async 1
1235
1236 # Set miss_send_len to 128, turning on packet-ins for our service connection.
1237 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
1238 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1239
1240 # Set miss_send_len to 128 and enable invalid_ttl.
1241 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700040080
1242 check_async 3 OFPR_ACTION OFPR_INVALID_TTL OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1243
1244 # Become slave, which should disable everything except port status.
1245 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000002
1246 check_async 4 OFPPR_ADD OFPPR_DELETE
1247
1248 # Use NXT_SET_ASYNC_CONFIG to enable a patchwork of asynchronous messages.
1249 ovs-appctl -t ovs-ofctl ofctl/send 01040028000000020000232000000013000000020000000500000005000000020000000200000005
1250 check_async 5 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
1251
1252 # Set controller ID 123.
1253 ovs-appctl -t ovs-ofctl ofctl/send 01040018000000030000232000000014000000000000007b
1254 check_async 6 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
1255
1256 # Restore controller ID 0.
1257 ovs-appctl -t ovs-ofctl ofctl/send 010400180000000300002320000000140000000000000000
1258
1259 # Become master.
1260 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000001
1261 check_async 7 OFPR_ACTION OFPPR_ADD
1262
1263 ovs-appctl -t ovs-ofctl exit
1264 OVS_VSWITCHD_STOP
1265 AT_CLEANUP
1266
1267 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.2)])
1268 OVS_VSWITCHD_START
1269 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
1270 check_async () {
1271     printf '\n\n--- check_async %d ---\n\n\n' $1
1272     INDEX=$1
1273     shift
1274
1275     ovs-appctl -t ovs-ofctl ofctl/barrier
1276     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1277     : > expout
1278
1279     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
1280     ovs-ofctl -O OpenFlow12 -v packet-out br0 none controller '0001020304050010203040501234'
1281     if test X"$1" = X"OFPR_ACTION"; then shift;
1282         echo >>expout "OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
1283 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"
1284     fi
1285
1286     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
1287     ovs-ofctl -O OpenFlow12 -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
1288     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
1289         echo >>expout "OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY (via no_match) data_len=14 (unbuffered)
1290 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"
1291     fi
1292
1293     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
1294     ovs-ofctl -O OpenFlow12 packet-out br0 none dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
1295     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
1296         echo >>expout "OFPT_PACKET_IN (OF1.2): total_len=76 in_port=ANY (via invalid_ttl) data_len=76 (unbuffered)
1297 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"
1298     fi
1299
1300     # OFPT_PORT_STATUS, OFPPR_ADD
1301     ovs-vsctl add-port br0 test -- set Interface test type=dummy
1302     if test X"$1" = X"OFPPR_ADD"; then shift;
1303         echo >>expout "OFPT_PORT_STATUS (OF1.2): ADD: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1304      config:     PORT_DOWN
1305      state:      LINK_DOWN
1306      speed: 0 Mbps now, 0 Mbps max"
1307     fi
1308
1309     # OFPT_PORT_STATUS, OFPPR_DELETE
1310     ovs-vsctl del-port br0 test
1311     if test X"$1" = X"OFPPR_DELETE"; then shift;
1312         echo >>expout "OFPT_PORT_STATUS (OF1.2): DEL: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1313      config:     PORT_DOWN
1314      state:      LINK_DOWN
1315      speed: 0 Mbps now, 0 Mbps max"
1316     fi
1317
1318     # OFPT_FLOW_REMOVED, OFPRR_DELETE
1319     ovs-ofctl -O OpenFlow12 add-flow br0 send_flow_rem,actions=drop
1320     ovs-ofctl -O OpenFlow12 --strict del-flows br0 ''
1321     if test X"$1" = X"OFPRR_DELETE"; then shift;
1322         echo >>expout "OFPT_FLOW_REMOVED (OF1.2):  reason=delete table_id=0"
1323     fi
1324     AT_FAIL_IF([test X"$1" != X])
1325
1326     ovs-appctl -t ovs-ofctl ofctl/barrier
1327     echo >>expout "OFPT_BARRIER_REPLY (OF1.2):"
1328
1329     AT_CHECK(
1330       [[sed '
1331 s/ (xid=0x[0-9a-fA-F]*)//
1332 s/ *duration.*//
1333 s/00:0.$/00:0x/' < monitor.log]],
1334       [0], [expout])
1335 }
1336
1337 # It's a service connection so initially there should be no async messages.
1338 check_async 1
1339
1340 # Set miss_send_len to 128, turning on packet-ins for our service connection.
1341 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
1342 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1343
1344 # Set miss_send_len to 128 and enable invalid_ttl.
1345 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700040080
1346 check_async 3 OFPR_ACTION OFPR_INVALID_TTL OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1347
1348 # Become slave (OF 1.2), which should disable everything except port status.
1349 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000200000003000000000000000000000001
1350 check_async 4 OFPPR_ADD OFPPR_DELETE
1351
1352 # Use NXT_SET_ASYNC_CONFIG to enable a patchwork of asynchronous messages.
1353 ovs-appctl -t ovs-ofctl ofctl/send 03040028000000020000232000000013000000020000000500000005000000020000000200000005
1354 check_async 5 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
1355
1356 # Set controller ID 123.
1357 ovs-appctl -t ovs-ofctl ofctl/send 03040018000000030000232000000014000000000000007b
1358 check_async 6 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
1359
1360 # Restore controller ID 0.
1361 ovs-appctl -t ovs-ofctl ofctl/send 030400180000000300002320000000140000000000000000
1362
1363 # Become master (OF 1.2).
1364 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000400000002000000000000000000000002
1365 check_async 7 OFPR_ACTION OFPPR_ADD
1366
1367 ovs-appctl -t ovs-ofctl exit
1368 OVS_VSWITCHD_STOP
1369 AT_CLEANUP
1370
1371 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.3)])
1372 OVS_VSWITCHD_START
1373 AT_CHECK([ovs-ofctl -O OpenFlow13 monitor br0 --detach --no-chdir --pidfile])
1374 check_async () {
1375     printf '\n\n--- check_async %d ---\n\n\n' $1
1376     INDEX=$1
1377     shift
1378
1379     ovs-appctl -t ovs-ofctl ofctl/barrier
1380     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1381     : > expout
1382
1383     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
1384     ovs-ofctl -O OpenFlow13 -v packet-out br0 none controller '0001020304050010203040501234'
1385     if test X"$1" = X"OFPR_ACTION"; then shift;
1386         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
1387 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"
1388     fi
1389
1390     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
1391     ovs-ofctl -O OpenFlow13 -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
1392     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
1393         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=14 in_port=ANY (via no_match) data_len=14 (unbuffered)
1394 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"
1395     fi
1396
1397     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
1398     ovs-ofctl -O OpenFlow13 packet-out br0 none dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
1399     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
1400         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=76 in_port=ANY (via invalid_ttl) data_len=76 (unbuffered)
1401 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"
1402     fi
1403
1404     # OFPT_PORT_STATUS, OFPPR_ADD
1405     ovs-vsctl add-port br0 test -- set Interface test type=dummy
1406     if test X"$1" = X"OFPPR_ADD"; then shift;
1407         echo >>expout "OFPT_PORT_STATUS (OF1.3): ADD: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1408      config:     PORT_DOWN
1409      state:      LINK_DOWN
1410      speed: 0 Mbps now, 0 Mbps max"
1411     fi
1412
1413     # OFPT_PORT_STATUS, OFPPR_DELETE
1414     ovs-vsctl del-port br0 test
1415     if test X"$1" = X"OFPPR_DELETE"; then shift;
1416         echo >>expout "OFPT_PORT_STATUS (OF1.3): DEL: ${INDEX}(test): addr:aa:55:aa:55:00:0x
1417      config:     PORT_DOWN
1418      state:      LINK_DOWN
1419      speed: 0 Mbps now, 0 Mbps max"
1420     fi
1421
1422     # OFPT_FLOW_REMOVED, OFPRR_DELETE
1423     ovs-ofctl -O OpenFlow13 add-flow br0 send_flow_rem,actions=drop
1424     ovs-ofctl -O OpenFlow13 --strict del-flows br0 ''
1425     if test X"$1" = X"OFPRR_DELETE"; then shift;
1426         echo >>expout "OFPT_FLOW_REMOVED (OF1.3):  reason=delete table_id=0"
1427     fi
1428     AT_FAIL_IF([test X"$1" != X])
1429
1430     ovs-appctl -t ovs-ofctl ofctl/barrier
1431     echo >>expout "OFPT_BARRIER_REPLY (OF1.3):"
1432
1433     AT_CHECK(
1434       [[sed '
1435 s/ (xid=0x[0-9a-fA-F]*)//
1436 s/ *duration.*//
1437 s/00:0.$/00:0x/' < monitor.log]],
1438       [0], [expout])
1439 }
1440
1441 # It's a service connection so initially there should be no async messages.
1442 check_async 1
1443
1444 # Set miss_send_len to 128, turning on packet-ins for our service connection.
1445 ovs-appctl -t ovs-ofctl ofctl/send 0409000c0123456700000080
1446 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
1447
1448 # Become slave (OF 1.3), which should disable everything except port status.
1449 ovs-appctl -t ovs-ofctl ofctl/send 041800180000000200000003000000000000000000000001
1450 check_async 3 OFPPR_ADD OFPPR_DELETE
1451
1452 # Use OF 1.3 OFPT_SET_ASYNC to enable a patchwork of asynchronous messages.
1453 ovs-appctl -t ovs-ofctl ofctl/send 041c002000000002000000020000000500000005000000020000000200000005
1454 check_async 4 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
1455
1456 # Set controller ID 123.
1457 ovs-appctl -t ovs-ofctl ofctl/send 04040018000000030000232000000014000000000000007b
1458 check_async 5 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
1459
1460 # Restore controller ID 0.
1461 ovs-appctl -t ovs-ofctl ofctl/send 040400180000000300002320000000140000000000000000
1462
1463 # Become master (OF 1.3).
1464 ovs-appctl -t ovs-ofctl ofctl/send 041800180000000400000002000000000000000000000002
1465 check_async 6 OFPR_ACTION OFPPR_ADD
1466
1467 ovs-appctl -t ovs-ofctl exit
1468 OVS_VSWITCHD_STOP
1469 AT_CLEANUP
1470
1471 dnl This test checks that the role request/response messaging works
1472 dnl and that generation_id is handled properly.
1473 AT_SETUP([ofproto - controller role (OpenFlow 1.2)])
1474 OVS_VSWITCHD_START
1475 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
1476
1477 ovs-appctl -t ovs-ofctl ofctl/barrier
1478 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1479 : > expout
1480
1481 # find out current role
1482 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000200000000000000000000000000000000
1483 echo >>expout "send: OFPT_ROLE_REQUEST (OF1.2) (xid=0x2): role=nochange"
1484 echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x2): role=equal"
1485
1486 # Become slave (generation_id is initially undefined, so 2^63+2 should not be stale)
1487 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000300000003000000008000000000000002
1488 echo >>expout "send: OFPT_ROLE_REQUEST (OF1.2) (xid=0x3): role=slave generation_id=9223372036854775810"
1489 echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x3): role=slave generation_id=9223372036854775810"
1490
1491 # Try to become the master using a stale generation ID
1492 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000400000002000000000000000000000002
1493 echo >>expout "send: OFPT_ROLE_REQUEST (OF1.2) (xid=0x4): role=master generation_id=2"
1494 echo >>expout "OFPT_ERROR (OF1.2) (xid=0x4): OFPRRFC_STALE"
1495 echo >>expout "OFPT_ROLE_REQUEST (OF1.2) (xid=0x4): role=master generation_id=2"
1496
1497 # Become master using a valid generation ID
1498 ovs-appctl -t ovs-ofctl ofctl/send 031800180000000500000002000000000000000000000001
1499 echo >>expout "send: OFPT_ROLE_REQUEST (OF1.2) (xid=0x5): role=master generation_id=1"
1500 echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x5): role=master generation_id=1"
1501 ovs-appctl -t ovs-ofctl ofctl/barrier
1502 echo >>expout "OFPT_BARRIER_REPLY (OF1.2) (xid=0x3):"
1503
1504 AT_CHECK([cat monitor.log], [0], [expout])
1505
1506 ovs-appctl -t ovs-ofctl exit
1507 OVS_VSWITCHD_STOP
1508 AT_CLEANUP
1509
1510 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
1511 dnl specified by OpenFlow 1.0) and OFPP_CONTROLLER (used by some
1512 dnl controllers despite the spec) as meaning a packet that was generated
1513 dnl by the controller.
1514 AT_SETUP([ofproto - packet-out from controller (OpenFlow 1.0)])
1515 OVS_VSWITCHD_START
1516 ADD_OF_PORTS([br0], [1])
1517
1518 # Start a monitor listening for packet-ins.
1519 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
1520 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
1521 ovs-appctl -t ovs-ofctl ofctl/barrier
1522 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1523 AT_CAPTURE_FILE([monitor.log])
1524
1525 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
1526 AT_CHECK([ovs-ofctl packet-out br0 none controller,1 '0001020304050010203040501234'])
1527 AT_CHECK([ovs-ofctl packet-out br0 controller controller,1 '0001020304050010203040505678'])
1528
1529 # Stop the monitor and check its output.
1530 ovs-appctl -t ovs-ofctl ofctl/barrier
1531 ovs-appctl -t ovs-ofctl exit
1532
1533 ovs-ofctl dump-ports br0
1534
1535 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
1536 OFPT_PACKET_IN: total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
1537 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
1538 OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
1539 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
1540 OFPT_BARRIER_REPLY:
1541 ])
1542
1543 OVS_VSWITCHD_STOP
1544 AT_CLEANUP
1545
1546 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
1547 dnl specified by OpenFlow 1.2) and OFPP_CONTROLLER (used by some
1548 dnl controllers despite the spec) as meaning a packet that was generated
1549 dnl by the controller.
1550 AT_SETUP([ofproto - packet-out from controller (OpenFlow 1.2)])
1551 OVS_VSWITCHD_START
1552
1553 # Start a monitor listening for packet-ins.
1554 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
1555 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
1556 ovs-appctl -t ovs-ofctl ofctl/barrier
1557 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1558 AT_CAPTURE_FILE([monitor.log])
1559
1560 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
1561 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 none controller '0001020304050010203040501234'])
1562 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 4294967293 controller '0001020304050010203040505678'])
1563
1564 # Stop the monitor and check its output.
1565 ovs-appctl -t ovs-ofctl ofctl/barrier
1566 ovs-appctl -t ovs-ofctl exit
1567
1568 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
1569 OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY (via action) data_len=14 (unbuffered)
1570 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
1571 OFPT_PACKET_IN (OF1.2): 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=0x5678
1573 OFPT_BARRIER_REPLY (OF1.2):
1574 ])
1575
1576 OVS_VSWITCHD_STOP
1577 AT_CLEANUP
1578
1579 dnl This test checks that metadata is encoded in packet_in structures,
1580 dnl supported by NXAST.
1581 AT_SETUP([ofproto - packet-out with metadata (NXM)])
1582 OVS_VSWITCHD_START
1583
1584 # Start a monitor listening for packet-ins.
1585 AT_CHECK([ovs-ofctl -P nxm monitor br0 --detach --no-chdir --pidfile])
1586 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
1587 ovs-appctl -t ovs-ofctl ofctl/barrier
1588 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1589 AT_CAPTURE_FILE([monitor.log])
1590
1591 # Send a packet-out with a load action to set some metadata, and forward to controller
1592 AT_CHECK([ovs-ofctl packet-out br0 controller 'load(0xfafafafa5a5a5a5a->OXM_OF_METADATA[[0..63]]), load(0xaa->NXM_NX_PKT_MARK[[]]), controller' '0001020304050010203040501234'])
1593
1594 # Stop the monitor and check its output.
1595 ovs-appctl -t ovs-ofctl ofctl/barrier
1596 ovs-appctl -t ovs-ofctl exit
1597
1598 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
1599 NXT_PACKET_IN: total_len=14 in_port=CONTROLLER metadata=0xfafafafa5a5a5a5a pkt_mark=0xaa (via action) data_len=14 (unbuffered)
1600 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
1601 OFPT_BARRIER_REPLY:
1602 ])
1603
1604 OVS_VSWITCHD_STOP
1605 AT_CLEANUP
1606
1607 dnl This test checks that metadata is encoded in packet_in structures,
1608 dnl supported by NXAST.
1609 AT_SETUP([ofproto - packet-out with metadata (OpenFlow 1.2)])
1610 OVS_VSWITCHD_START
1611
1612 # Start a monitor listening for packet-ins.
1613 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
1614 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
1615 ovs-appctl -t ovs-ofctl ofctl/barrier
1616 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1617 AT_CAPTURE_FILE([monitor.log])
1618
1619 # Send a packet-out with a load action to set some metadata, and forward to controller
1620 AT_CHECK([ovs-ofctl -O OpenFlow12 packet-out br0 none 'load(0xfafafafa5a5a5a5a->OXM_OF_METADATA[[0..63]]), controller' '0001020304050010203040501234'])
1621
1622 # Stop the monitor and check its output.
1623 ovs-appctl -t ovs-ofctl ofctl/barrier
1624 ovs-appctl -t ovs-ofctl exit
1625
1626 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
1627 OFPT_PACKET_IN (OF1.2): total_len=14 in_port=ANY metadata=0xfafafafa5a5a5a5a (via action) data_len=14 (unbuffered)
1628 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
1629 OFPT_BARRIER_REPLY (OF1.2):
1630 ])
1631
1632 OVS_VSWITCHD_STOP
1633 AT_CLEANUP
1634
1635 dnl This test checks that tunnel metadata is encoded in packet_in structures.
1636 AT_SETUP([ofproto - packet-out with tunnel metadata (OpenFlow 1.2)])
1637 OVS_VSWITCHD_START
1638
1639 # Start a monitor listening for packet-ins.
1640 AT_CHECK([ovs-ofctl -O OpenFlow12 monitor br0 --detach --no-chdir --pidfile])
1641 ovs-appctl -t ovs-ofctl ofctl/send 0309000c0123456700000080
1642 ovs-appctl -t ovs-ofctl ofctl/barrier
1643 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1644 AT_CAPTURE_FILE([monitor.log])
1645
1646 # Send a packet-out with set field actions to set some tunnel metadata, and forward to controller
1647 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'])
1648
1649 # Stop the monitor and check its output.
1650 ovs-appctl -t ovs-ofctl ofctl/barrier
1651 ovs-appctl -t ovs-ofctl exit
1652
1653 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
1654 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)
1655 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
1656 OFPT_BARRIER_REPLY (OF1.2):
1657 ])
1658
1659 OVS_VSWITCHD_STOP
1660 AT_CLEANUP
1661
1662 AT_SETUP([ofproto - flow monitoring])
1663 AT_KEYWORDS([monitor])
1664 OVS_VSWITCHD_START
1665
1666 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:1
1667
1668 # Start a monitor watching the flow table and check the initial reply.
1669 ovs-ofctl monitor br0 watch: --detach --no-chdir --pidfile >monitor.log 2>&1
1670 AT_CAPTURE_FILE([monitor.log])
1671 ovs-appctl -t ovs-ofctl ofctl/barrier
1672 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log], [0],
1673   [NXST_FLOW_MONITOR reply:
1674  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:1
1675 OFPT_BARRIER_REPLY:
1676 ])
1677
1678 # Add, delete, and modify some flows and check the updates.
1679 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1680 ovs-ofctl add-flow br0 in_port=0,dl_vlan=124,actions=output:2
1681 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:5
1682 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,dl_vlan_pcp=0,actions=output:6
1683 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,dl_vlan_pcp=1,actions=output:7
1684 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:8
1685 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,dl_vlan_pcp=0,actions=output:9
1686 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,dl_vlan_pcp=1,actions=output:10
1687 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,actions=output:11
1688 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,dl_vlan_pcp=0,actions=output:12
1689 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,dl_vlan_pcp=1,actions=output:13
1690 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,actions=output:14
1691 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=0,actions=output:15
1692 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=1,actions=output:16
1693 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,actions=output:17
1694 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=0,actions=output:18
1695 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=1,actions=output:19
1696 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,actions=output:20
1697 ovs-ofctl add-flow br0 in_port=0,dl_vlan_pcp=0,actions=output:21
1698 ovs-ofctl add-flow br0 in_port=0,dl_vlan_pcp=1,actions=output:22
1699 ovs-ofctl add-flow br0 in_port=0,actions=output:23
1700 ovs-ofctl mod-flows br0 cookie=5,dl_vlan=123,actions=output:3
1701 ovs-ofctl del-flows br0 dl_vlan=123
1702 ovs-ofctl del-flows br0
1703 ovs-appctl -t ovs-ofctl ofctl/barrier
1704 sort='
1705     # Sorts groups of lines that start with a space, without moving them
1706     # past the nearest line that does not start with a space.
1707     use warnings;
1708     use strict;
1709     my @buffer = ();
1710     while (<STDIN>) {
1711         if (/^ /) {
1712             push(@buffer, $_);
1713         } else {
1714             print $_ foreach sort(@buffer);
1715             print $_;
1716             @buffer = ();
1717         }
1718     }
1719     print $_ foreach sort(@buffer);
1720 '
1721 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log | ${PERL} -e "$sort"], [0],
1722 [NXST_FLOW_MONITOR reply (xid=0x0):
1723  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
1724 NXST_FLOW_MONITOR reply (xid=0x0):
1725  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:5
1726 NXST_FLOW_MONITOR reply (xid=0x0):
1727  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:6
1728 NXST_FLOW_MONITOR reply (xid=0x0):
1729  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:7
1730 NXST_FLOW_MONITOR reply (xid=0x0):
1731  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:8
1732 NXST_FLOW_MONITOR reply (xid=0x0):
1733  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:9
1734 NXST_FLOW_MONITOR reply (xid=0x0):
1735  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:10
1736 NXST_FLOW_MONITOR reply (xid=0x0):
1737  event=ADDED table=0 cookie=0 in_port=0,vlan_tci=0x0000 actions=output:11
1738 NXST_FLOW_MONITOR reply (xid=0x0):
1739  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=0 actions=output:12
1740 NXST_FLOW_MONITOR reply (xid=0x0):
1741  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=1 actions=output:13
1742 NXST_FLOW_MONITOR reply (xid=0x0):
1743  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095 actions=output:14
1744 NXST_FLOW_MONITOR reply (xid=0x0):
1745  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:15
1746 NXST_FLOW_MONITOR reply (xid=0x0):
1747  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:16
1748 NXST_FLOW_MONITOR reply (xid=0x0):
1749  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:17
1750 NXST_FLOW_MONITOR reply (xid=0x0):
1751  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:18
1752 NXST_FLOW_MONITOR reply (xid=0x0):
1753  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:19
1754 NXST_FLOW_MONITOR reply (xid=0x0):
1755  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:20
1756 NXST_FLOW_MONITOR reply (xid=0x0):
1757  event=ADDED table=0 cookie=0 in_port=0,dl_vlan_pcp=0 actions=output:21
1758 NXST_FLOW_MONITOR reply (xid=0x0):
1759  event=ADDED table=0 cookie=0 in_port=0,dl_vlan_pcp=1 actions=output:22
1760 NXST_FLOW_MONITOR reply (xid=0x0):
1761  event=ADDED table=0 cookie=0 in_port=0 actions=output:23
1762 NXST_FLOW_MONITOR reply (xid=0x0):
1763  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123 actions=output:3
1764  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
1765  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
1766 NXST_FLOW_MONITOR reply (xid=0x0):
1767  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123 actions=output:3
1768  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
1769  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
1770 NXST_FLOW_MONITOR reply (xid=0x0):
1771  event=DELETED reason=delete table=0 cookie=0 in_port=0 actions=output:23
1772  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:20
1773  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:18
1774  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:19
1775  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
1776  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095 actions=output:14
1777  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=0 actions=output:12
1778  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=1 actions=output:13
1779  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan_pcp=0 actions=output:21
1780  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan_pcp=1 actions=output:22
1781  event=DELETED reason=delete table=0 cookie=0 in_port=0,vlan_tci=0x0000 actions=output:11
1782 OFPT_BARRIER_REPLY:
1783 ])
1784
1785 # Check that our own changes are reported as abbreviations.
1786 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
1787 ovs-ofctl add-flow br0 in_port=1,actions=output:2
1788 ovs-ofctl add-flow br0 in_port=2,actions=output:1
1789 ovs-appctl -t ovs-ofctl ofctl/barrier
1790 ovs-appctl -t ovs-ofctl ofctl/send 010e004812345678003fffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000ffffffffffff0000
1791 ovs-appctl -t ovs-ofctl ofctl/barrier
1792 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
1793 ])
1794 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log], [0],
1795 [NXST_FLOW_MONITOR reply (xid=0x0):
1796  event=ADDED table=0 cookie=0 in_port=1 actions=output:2
1797 NXST_FLOW_MONITOR reply (xid=0x0):
1798  event=ADDED table=0 cookie=0 in_port=2 actions=output:1
1799 OFPT_BARRIER_REPLY:
1800 send: OFPT_FLOW_MOD: DEL priority=0 actions=drop
1801 NXST_FLOW_MONITOR reply (xid=0x0):
1802  event=ABBREV xid=0x12345678
1803 OFPT_BARRIER_REPLY:
1804 ])
1805
1806 ovs-appctl -t ovs-ofctl exit
1807 OVS_VSWITCHD_STOP
1808 AT_CLEANUP
1809
1810 AT_SETUP([ofproto - flow monitoring pause and resume])
1811 AT_KEYWORDS([monitor])
1812
1813 # The maximum socket receive buffer size is important for this test, which
1814 # tests behavior when the receive buffer overflows.
1815 if test -e /proc/sys/net/core/rmem_max; then
1816     # Linux
1817     rmem_max=`cat /proc/sys/net/core/rmem_max`
1818 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
1819     : # FreeBSD, NetBSD
1820 else
1821     # Don't know how to get maximum socket receive buffer on this OS
1822     AT_SKIP_IF([:])
1823 fi
1824 # Calculate the total amount of queuing: rmem_max in the kernel, 128 kB
1825 # in ofproto sending userspace (see ofmonitor_flush() in connmgr.c).
1826 queue_size=`expr $rmem_max + 128 \* 1024`
1827 echo rmem_max=$rmem_max queue_size=$queue_size
1828
1829 # Each flow update message takes up at least 48 bytes of space in queues
1830 # and in practice more than that.
1831 n_msgs=`expr $queue_size / 48`
1832 echo n_msgs=$n_msgs
1833
1834 OVS_VSWITCHD_START
1835
1836 # Start a monitor watching the flow table, then make it block.
1837 ON_EXIT([kill `cat ovs-ofctl.pid`])
1838 ovs-ofctl monitor br0 watch: --detach --no-chdir --pidfile >monitor.log 2>&1
1839 AT_CAPTURE_FILE([monitor.log])
1840 ovs-appctl -t ovs-ofctl ofctl/block
1841
1842 # Add $n_msgs flows.
1843 (echo "in_port=2,actions=output:2"
1844 ${PERL} -e '
1845     for ($i = 0; $i < '$n_msgs'; $i++) {
1846         print "cookie=1,reg1=$i,actions=drop\n";
1847     }
1848 ') > flows.txt
1849 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
1850 # Check that multipart flow dumps work properly:
1851 AT_CHECK([ovs-ofctl diff-flows br0 flows.txt])
1852 AT_CHECK([ovs-ofctl add-flow br0 in_port=1,cookie=3,actions=drop])
1853 AT_CHECK([ovs-ofctl mod-flows br0 in_port=2,cookie=2,actions=output:2])
1854 AT_CHECK([ovs-ofctl del-flows br0 cookie=1/-1])
1855
1856 ovs-appctl -t ovs-ofctl ofctl/unblock
1857 ovs-appctl -t ovs-ofctl ofctl/barrier
1858
1859 ovs-appctl -t ovs-ofctl exit
1860
1861 # Check that the flow monitor reported the same number of flows
1862 # added and deleted, but fewer than we actually added and deleted.
1863 adds=`grep -c 'ADDED.*reg1=' monitor.log`
1864 deletes=`grep -c 'DELETED.*reg1=' monitor.log`
1865 echo adds=$adds deletes=$deletes
1866 AT_CHECK([test $adds -gt 100 && test $adds -lt $n_msgs])
1867 AT_CHECK([test $adds = $deletes])
1868
1869 # Check that the flow monitor reported everything in the expected order:
1870 #
1871 #     event=ADDED table=0 cookie=0x1 reg1=0x22
1872 # ...
1873 #    NXT_FLOW_MONITOR_PAUSED:
1874 # ...
1875 #     event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
1876 # ...
1877 #     event=ADDED table=0 cookie=0x3 in_port=1
1878 #     event=MODIFIED table=0 cookie=0x2 in_port=2 actions=output:2
1879 #    NXT_FLOW_MONITOR_RESUMED:
1880 #
1881 # except that, between the PAUSED and RESUMED, the order of the ADDED
1882 # and MODIFIED lines lines depends on hash order, that is, it varies
1883 # as we change the hash function or change architecture.  Therefore,
1884 # we use a couple of tests below to accept both orders.
1885 AT_CHECK([ofctl_strip < monitor.log | sed -n -e '
1886 /reg1=0x22$/p
1887 /cookie=0x[[23]]/p
1888 /NXT_FLOW_MONITOR_PAUSED:/p
1889 /NXT_FLOW_MONITOR_RESUMED:/p
1890 ' > monitor.log.subset])
1891 AT_CHECK([grep -v MODIFIED monitor.log.subset], [0], [dnl
1892  event=ADDED table=0 cookie=0x1 reg1=0x22
1893 NXT_FLOW_MONITOR_PAUSED:
1894  event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
1895  event=ADDED table=0 cookie=0x3 in_port=1
1896 NXT_FLOW_MONITOR_RESUMED:
1897 ])
1898 AT_CHECK([grep -v ADDED monitor.log.subset], [0], [dnl
1899 NXT_FLOW_MONITOR_PAUSED:
1900  event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
1901  event=MODIFIED table=0 cookie=0x2 in_port=2 actions=output:2
1902 NXT_FLOW_MONITOR_RESUMED:
1903 ])
1904
1905 OVS_VSWITCHD_STOP
1906 AT_CLEANUP
1907
1908 AT_SETUP([ofproto - event filtering (OpenFlow 1.3)])
1909 AT_KEYWORDS([monitor])
1910 OVS_VSWITCHD_START
1911
1912 # Start a monitor, use the required protocol version
1913 ovs-ofctl -O OpenFlow13 monitor br0 --detach --no-chdir --pidfile >monitor.log 2>&1
1914 AT_CAPTURE_FILE([monitor.log])
1915
1916 # Send an OpenFlow13 message (04), OFPT_GET_ASYNC_REQUEST (1a), length (8), xid (0a)
1917 ovs-appctl -t ovs-ofctl ofctl/send 041a00080000000a
1918 ovs-appctl -t ovs-ofctl ofctl/barrier
1919
1920 # Check default setting
1921 read -r -d '' expected <<'EOF'
1922 EOF
1923
1924 AT_CHECK([ofctl_strip < monitor.log], [], [dnl
1925 send: OFPT_GET_ASYNC_REQUEST (OF1.3):
1926 OFPT_GET_ASYNC_REPLY (OF1.3):
1927  master:
1928        PACKET_IN: no_match action
1929      PORT_STATUS: add delete modify
1930     FLOW_REMOVED: idle hard delete
1931
1932  slave:
1933        PACKET_IN: (off)
1934      PORT_STATUS: add delete modify
1935     FLOW_REMOVED: (off)
1936 OFPT_BARRIER_REPLY (OF1.3):
1937 ])
1938
1939 OVS_VSWITCHD_STOP
1940 AT_CLEANUP