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