a0558510557dbf1cdef92418369121a50bd02b02
[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:255, n_buffers:256
15 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
16 actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DST SET_NW_SRC SET_NW_DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE
17  LOCAL(br0): addr:aa:55:aa:55:00:00
18      config:     PORT_DOWN
19      state:      LINK_DOWN
20      speed: 100 Mbps now, 100 Mbps max
21 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
22 ])
23 OVS_VSWITCHD_STOP
24 AT_CLEANUP
25
26 dnl This is really bare-bones.
27 dnl It at least checks request and reply serialization and deserialization.
28 AT_SETUP([ofproto - port stats])
29 OVS_VSWITCHD_START
30 AT_CHECK([ovs-ofctl -vwarn dump-ports br0], [0], [stdout])
31 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
32 OFPST_PORT reply: 1 ports
33   port 65534: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
34            tx pkts=0, bytes=0, drop=0, errs=0, coll=0
35 ])
36 OVS_VSWITCHD_STOP
37 AT_CLEANUP
38
39 dnl This is really bare-bones.
40 dnl It at least checks request and reply serialization and deserialization.
41 AT_SETUP([ofproto - port-desc stats])
42 OVS_VSWITCHD_START
43 AT_CHECK([ovs-ofctl -vwarn dump-ports-desc br0], [0], [stdout])
44 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
45 OFPST_PORT_DESC reply:
46  LOCAL(br0): addr:aa:55:aa:55:00:00
47      config:     PORT_DOWN
48      state:      LINK_DOWN
49      speed: 100 Mbps now, 100 Mbps max
50 ])
51 OVS_VSWITCHD_STOP
52 AT_CLEANUP
53
54 dnl This is really bare-bones.
55 dnl It at least checks request and reply serialization and deserialization.
56 AT_SETUP([ofproto - queue stats])
57 OVS_VSWITCHD_START
58 AT_CHECK([ovs-ofctl -vwarn queue-stats br0], [0], [stdout])
59 AT_CHECK([STRIP_XIDS stdout], [0], [dnl
60 OFPST_QUEUE reply: 0 queues
61 ])
62 AT_CHECK([ovs-ofctl -vwarn queue-stats br0 ALL 5], [0],
63   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_QUEUE
64 OFPST_QUEUE request (xid=0x2):port=ALL queue=5
65 ])
66 AT_CHECK([ovs-ofctl -vwarn queue-stats br0 10], [0],
67   [OFPT_ERROR (xid=0x2): OFPQOFC_BAD_PORT
68 OFPST_QUEUE request (xid=0x2):port=10 queue=ALL
69 ])
70 OVS_VSWITCHD_STOP
71 AT_CLEANUP
72
73 AT_SETUP([ofproto - mod-port])
74 OVS_VSWITCHD_START
75 for command_config_state in \
76     'up 0 0' \
77     'noflood NO_FLOOD 0' \
78     'down PORT_DOWN,NO_FLOOD LINK_DOWN' \
79     'flood PORT_DOWN LINK_DOWN' \
80     'no-receive PORT_DOWN,NO_RECV LINK_DOWN' \
81     'no-forward PORT_DOWN,NO_RECV,NO_FWD LINK_DOWN' \
82     'no-packet-in PORT_DOWN,NO_RECV,NO_FWD,NO_PACKET_IN LINK_DOWN' \
83     'forward PORT_DOWN,NO_RECV,NO_PACKET_IN LINK_DOWN' \
84     'packet-in PORT_DOWN,NO_RECV LINK_DOWN' \
85     'up NO_RECV 0' \
86     'receive 0 0'
87 do
88     set $command_config_state
89     command=$[1] config=`echo $[2] | sed 's/,/ /g'` state=$[3]
90     AT_CHECK([ovs-ofctl -vwarn mod-port br0 br0 $command])
91     AT_CHECK([ovs-ofctl -vwarn show br0], [0], [stdout])
92     AT_CHECK_UNQUOTED([STRIP_XIDS stdout], [0], [dnl
93 OFPT_FEATURES_REPLY: dpid:fedcba9876543210
94 n_tables:255, n_buffers:256
95 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
96 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
97  LOCAL(br0): addr:aa:55:aa:55:00:00
98      config:     $config
99      state:      $state
100      speed: 100 Mbps now, 100 Mbps max
101 OFPT_GET_CONFIG_REPLY: frags=normal miss_send_len=0
102 ])
103 done
104 OVS_VSWITCHD_STOP
105 AT_CLEANUP
106
107 AT_SETUP([ofproto - basic flow_mod commands (NXM)])
108 OVS_VSWITCHD_START
109 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
110 ])
111 AT_CHECK([echo 'in_port=1,actions=0' | ovs-ofctl add-flows br0 -])
112 AT_CHECK([ovs-ofctl add-flow br0 in_port=0,actions=1])
113 AT_CHECK([ovs-ofctl -F nxm add-flow br0 table=1,in_port=3,actions=2])
114 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
115  in_port=0 actions=output:1
116  in_port=1 actions=output:0
117  table=1, in_port=3 actions=output:2
118 NXST_FLOW reply:
119 ])
120 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
121 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
122 ])
123 AT_CHECK([ovs-ofctl del-flows br0])
124 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
125 ])
126 OVS_VSWITCHD_STOP
127 AT_CLEANUP
128
129 AT_SETUP([ofproto - basic flow_mod commands (OpenFlow 1.0)])
130 OVS_VSWITCHD_START
131 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
132 ])
133 AT_CHECK([echo 'in_port=1,actions=0' | ovs-ofctl -F openflow10 add-flows br0 -])
134 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 in_port=0,actions=1])
135 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 table=1,in_port=3,actions=2])
136 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
137  in_port=0 actions=output:1
138  in_port=1 actions=output:0
139  table=1, in_port=3 actions=output:2
140 OFPST_FLOW reply:
141 ])
142 AT_CHECK([ovs-ofctl -F openflow10 dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
143 OFPST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
144 ])
145 AT_CHECK([ovs-ofctl -F openflow10 del-flows br0])
146 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip], [0], [OFPST_FLOW reply:
147 ])
148 OVS_VSWITCHD_STOP
149 AT_CLEANUP
150
151 AT_SETUP([ofproto - dump flows with cookie])
152 OVS_VSWITCHD_START
153 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
154 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
155 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
156 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
157  cookie=0x1, in_port=1 actions=output:0
158  cookie=0x2, in_port=2 actions=output:0
159  cookie=0x3, in_port=3 actions=output:0
160 NXST_FLOW reply:
161 ])
162 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
163 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=3
164 ])
165 AT_CHECK([ovs-ofctl dump-flows br0 cookie=0x3/-1 | ofctl_strip | sort], [0], [dnl
166  cookie=0x3, in_port=3 actions=output:0
167 NXST_FLOW reply:
168 ])
169 AT_CHECK([ovs-ofctl dump-aggregate br0 cookie=0x3/-1 | STRIP_XIDS], [0], [dnl
170 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=1
171 ])
172 OVS_VSWITCHD_STOP
173 AT_CLEANUP
174
175 AT_SETUP([ofproto - dump flows with cookie mask])
176 OVS_VSWITCHD_START
177 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
178 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
179 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
180 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
181  cookie=0x1, in_port=1 actions=output:0
182  cookie=0x2, in_port=2 actions=output:0
183  cookie=0x3, in_port=3 actions=output:0
184 NXST_FLOW reply:
185 ])
186 AT_CHECK([ovs-ofctl dump-aggregate br0 table=0 | STRIP_XIDS], [0], [dnl
187 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=3
188 ])
189 AT_CHECK([ovs-ofctl dump-flows br0 cookie=0x3/0x1 | ofctl_strip | sort], [0], [dnl
190  cookie=0x1, in_port=1 actions=output:0
191  cookie=0x3, in_port=3 actions=output:0
192 NXST_FLOW reply:
193 ])
194 AT_CHECK([ovs-ofctl dump-aggregate br0 cookie=0x3/0x1 | STRIP_XIDS], [0], [dnl
195 NXST_AGGREGATE reply: packet_count=0 byte_count=0 flow_count=2
196 ])
197 OVS_VSWITCHD_STOP
198 AT_CLEANUP
199
200 AT_SETUP([ofproto - mod flow with cookie change (OpenFlow 1.0)])
201 OVS_VSWITCHD_START
202 AT_CHECK([ovs-ofctl -F openflow10 add-flow br0 cookie=0x1,in_port=1,actions=0])
203 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
204  cookie=0x1, in_port=1 actions=output:0
205 OFPST_FLOW reply:
206 ])
207
208 AT_CHECK([ovs-ofctl -F openflow10 mod-flows br0 cookie=0x2,in_port=1,actions=0])
209 AT_CHECK([ovs-ofctl -F openflow10 dump-flows br0 | ofctl_strip | sort], [0], [dnl
210  cookie=0x2, in_port=1 actions=output:0
211 OFPST_FLOW reply:
212 ])
213 OVS_VSWITCHD_STOP
214 AT_CLEANUP
215
216 AT_SETUP([ofproto - mod flow with cookie change (NXM)])
217 OVS_VSWITCHD_START
218 AT_CHECK([ovs-ofctl -F nxm add-flow br0 cookie=0x1,in_port=1,actions=0])
219 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
220  cookie=0x1, in_port=1 actions=output:0
221 NXST_FLOW reply:
222 ])
223
224 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x2,in_port=1,actions=0])
225 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
226  cookie=0x2, in_port=1 actions=output:0
227 NXST_FLOW reply:
228 ])
229 OVS_VSWITCHD_STOP
230 AT_CLEANUP
231
232 AT_SETUP([ofproto - mod flows based on cookie mask])
233 OVS_VSWITCHD_START
234 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
235 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=0])
236 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=0])
237 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
238  cookie=0x1, in_port=1 actions=output:0
239  cookie=0x1, in_port=2 actions=output:0
240  cookie=0x2, in_port=3 actions=output:0
241 NXST_FLOW reply:
242 ])
243
244 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=0x1/0xff,actions=4])
245 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
246  cookie=0x1, in_port=1 actions=output:4
247  cookie=0x1, in_port=2 actions=output:4
248  cookie=0x2, in_port=3 actions=output:0
249 NXST_FLOW reply:
250 ])
251 OVS_VSWITCHD_STOP
252 AT_CLEANUP
253
254 AT_SETUP([ofproto - mod flows based on cookie mask with cookie change])
255 OVS_VSWITCHD_START
256 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
257 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=2,actions=0])
258 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=3,actions=0])
259 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
260  cookie=0x1, in_port=1 actions=output:0
261  cookie=0x1, in_port=2 actions=output:0
262  cookie=0x2, in_port=3 actions=output:0
263 NXST_FLOW reply:
264 ])
265
266 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/-1,cookie=4,actions=4])
267 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
268  cookie=0x2, in_port=3 actions=output:0
269  cookie=0x4, in_port=1 actions=output:4
270  cookie=0x4, in_port=2 actions=output:4
271 NXST_FLOW reply:
272 ])
273 OVS_VSWITCHD_STOP
274 AT_CLEANUP
275
276 AT_SETUP([ofproto - mod flow with cookie miss (mask==0)])
277 OVS_VSWITCHD_START
278 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 in_port=1,actions=0])
279 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
280  in_port=1 actions=output:0
281 NXST_FLOW reply:
282 ])
283 OVS_VSWITCHD_STOP
284 AT_CLEANUP
285
286 AT_SETUP([ofproto - mod flow with cookie miss (mask!=0)])
287 OVS_VSWITCHD_START
288 AT_CHECK([ovs-ofctl -F nxm mod-flows br0 cookie=1/1,in_port=1,actions=0])
289 AT_CHECK([ovs-ofctl -F nxm dump-flows br0 | ofctl_strip | sort], [0], [dnl
290 NXST_FLOW reply:
291 ])
292 OVS_VSWITCHD_STOP
293 AT_CLEANUP
294
295 AT_SETUP([ofproto - del flows with cookies])
296 OVS_VSWITCHD_START
297 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
298 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
299 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
300 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
301  cookie=0x1, in_port=1 actions=output:0
302  cookie=0x2, in_port=2 actions=output:0
303  cookie=0x3, in_port=3 actions=output:0
304 NXST_FLOW reply:
305 ])
306
307 AT_CHECK([ovs-ofctl del-flows br0])
308 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
309 NXST_FLOW reply:
310 ])
311 OVS_VSWITCHD_STOP
312 AT_CLEANUP
313
314 AT_SETUP([ofproto - del flows based on cookie])
315 OVS_VSWITCHD_START
316 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
317 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
318 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
319 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
320  cookie=0x1, in_port=1 actions=output:0
321  cookie=0x2, in_port=2 actions=output:0
322  cookie=0x3, in_port=3 actions=output:0
323 NXST_FLOW reply:
324 ])
325
326 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/-1])
327 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
328  cookie=0x1, in_port=1 actions=output:0
329  cookie=0x2, in_port=2 actions=output:0
330 NXST_FLOW reply:
331 ])
332 OVS_VSWITCHD_STOP
333 AT_CLEANUP
334
335 AT_SETUP([ofproto - del flows based on cookie mask])
336 OVS_VSWITCHD_START
337 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x1,in_port=1,actions=0])
338 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x2,in_port=2,actions=0])
339 AT_CHECK([ovs-ofctl add-flow br0 cookie=0x3,in_port=3,actions=0])
340 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
341  cookie=0x1, in_port=1 actions=output:0
342  cookie=0x2, in_port=2 actions=output:0
343  cookie=0x3, in_port=3 actions=output:0
344 NXST_FLOW reply:
345 ])
346 AT_CHECK([ovs-ofctl del-flows br0 cookie=0x3/0x1])
347 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
348  cookie=0x2, in_port=2 actions=output:0
349 NXST_FLOW reply:
350 ])
351 OVS_VSWITCHD_STOP
352 AT_CLEANUP
353
354 AT_SETUP([ofproto - flow table configuration])
355 OVS_VSWITCHD_START
356 # Check the default configuration.
357 (echo "OFPST_TABLE reply (xid=0x2): 255 tables
358   0: classifier: wild=0x3fffff, max=1000000, active=0
359                lookup=0, matched=0"
360  x=1
361  while test $x -lt 254; do
362    printf "  %d: %-8s: wild=0x3fffff, max=1000000, active=0
363                lookup=0, matched=0
364 " $x table$x
365    x=`expr $x + 1`
366  done
367  echo "  254: table254: wild=0x3fffff, max=1000000, active=2
368                lookup=0, matched=0") > expout
369 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
370 # Change the configuration.
371 AT_CHECK(
372   [ovs-vsctl \
373      -- --id=@t0 create Flow_Table name=main \
374      -- --id=@t1 create Flow_Table flow-limit=1024 \
375      -- set bridge br0 'flow_tables={1=@t1,0=@t0}' \
376    | perl $srcdir/uuidfilt.pl],
377   [0], [<0>
378 <1>
379 ])
380 # Check that the configuration was updated.
381 mv expout orig-expout
382 (echo "OFPST_TABLE reply (xid=0x2): 255 tables
383   0: main    : wild=0x3fffff, max=1000000, active=0
384                lookup=0, matched=0
385   1: table1  : wild=0x3fffff, max=  1024, active=0
386                lookup=0, matched=0"
387  tail -n +6 orig-expout) > expout
388 AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
389 OVS_VSWITCHD_STOP
390 AT_CLEANUP
391
392 AT_SETUP([ofproto - hard limits on flow table size])
393 OVS_VSWITCHD_START
394 # Configure a maximum of 4 flows.
395 AT_CHECK(
396   [ovs-vsctl \
397      -- --id=@t0 create Flow_Table flow-limit=4 \
398      -- set bridge br0 flow_tables:0=@t0 \
399    | perl $srcdir/uuidfilt.pl],
400   [0], [<0>
401 ])
402 # Add 4 flows.
403 for in_port in 1 2 3 4; do
404     ovs-ofctl add-flow br0 in_port=$in_port,actions=drop
405 done
406 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
407  in_port=1 actions=drop
408  in_port=2 actions=drop
409  in_port=3 actions=drop
410  in_port=4 actions=drop
411 NXST_FLOW reply:
412 ])
413 # Adding another flow will be refused.
414 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop], [1], [], [stderr])
415 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
416   [OFPT_ERROR: OFPFMFC_ALL_TABLES_FULL
417 ])
418 # Also a mod-flow that would add a flow will be refused.
419 AT_CHECK([ovs-ofctl mod-flows br0 in_port=5,actions=drop], [1], [], [stderr])
420 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
421   [OFPT_ERROR: OFPFMFC_ALL_TABLES_FULL
422 ])
423 # Replacing or modifying an existing flow is allowed.
424 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
425 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
426 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
427  in_port=1 actions=drop
428  in_port=2 actions=drop
429  in_port=3 actions=output:1
430  in_port=4 actions=NORMAL
431 NXST_FLOW reply:
432 ])
433 OVS_VSWITCHD_STOP
434 AT_CLEANUP
435
436 AT_SETUP([ofproto - eviction upon table overflow])
437 OVS_VSWITCHD_START
438 # Configure a maximum of 4 flows.
439 AT_CHECK(
440   [ovs-vsctl \
441      -- --id=@t0 create Flow_Table flow-limit=4 overflow-policy=evict \
442      -- set bridge br0 flow_tables:0=@t0 \
443    | perl $srcdir/uuidfilt.pl],
444   [0], [<0>
445 ])
446 # Add 4 flows.
447 for in_port in 4 3 2 1; do
448     ovs-ofctl add-flow br0 idle_timeout=${in_port}0,in_port=$in_port,actions=drop
449 done
450 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
451  idle_timeout=10, in_port=1 actions=drop
452  idle_timeout=20, in_port=2 actions=drop
453  idle_timeout=30, in_port=3 actions=drop
454  idle_timeout=40, in_port=4 actions=drop
455 NXST_FLOW reply:
456 ])
457 # Adding another flow will cause the one that expires soonest to be evicted.
458 AT_CHECK([ovs-ofctl add-flow br0 in_port=5,actions=drop])
459 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
460  idle_timeout=20, in_port=2 actions=drop
461  idle_timeout=30, in_port=3 actions=drop
462  idle_timeout=40, in_port=4 actions=drop
463  in_port=5 actions=drop
464 NXST_FLOW reply:
465 ])
466 # A mod-flow that adds a flow also causes eviction, but replacing or
467 # modifying an existing flow doesn't.
468 AT_CHECK([ovs-ofctl mod-flows br0 in_port=6,actions=drop])
469 AT_CHECK([ovs-ofctl add-flow br0 in_port=4,actions=normal])
470 AT_CHECK([ovs-ofctl mod-flows br0 in_port=3,actions=output:1])
471 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
472  idle_timeout=30, in_port=3 actions=output:1
473  in_port=4 actions=NORMAL
474  in_port=5 actions=drop
475  in_port=6 actions=drop
476 NXST_FLOW reply:
477 ])
478 # Flows with no timeouts at all cannot be evicted.
479 AT_CHECK([ovs-ofctl add-flow br0 in_port=7,actions=normal])
480 AT_CHECK([ovs-ofctl add-flow br0 in_port=8,actions=drop], [1], [], [stderr])
481 AT_CHECK([head -n 1 stderr | ofctl_strip], [0],
482   [OFPT_ERROR: OFPFMFC_ALL_TABLES_FULL
483 ])
484 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
485  in_port=4 actions=NORMAL
486  in_port=5 actions=drop
487  in_port=6 actions=drop
488  in_port=7 actions=NORMAL
489 NXST_FLOW reply:
490 ])
491 OVS_VSWITCHD_STOP
492 AT_CLEANUP
493
494 AT_SETUP([ofproto - eviction upon table overflow, with fairness])
495 OVS_VSWITCHD_START
496 # Configure a maximum of 4 flows.
497 AT_CHECK(
498   [ovs-vsctl \
499      -- --id=@t0 create Flow_Table name=evict flow-limit=4 \
500                                    overflow-policy=evict \
501                                    groups='"NXM_OF_IN_PORT[[]]"' \
502      -- set bridge br0 flow_tables:0=@t0 \
503    | perl $srcdir/uuidfilt.pl],
504   [0], [<0>
505 ])
506 # Add 4 flows.
507 ovs-ofctl add-flows br0 - <<EOF
508 idle_timeout=10 in_port=2 dl_src=00:44:55:66:77:88 actions=drop
509 idle_timeout=20 in_port=1 dl_src=00:11:22:33:44:55 actions=drop
510 idle_timeout=30 in_port=1 dl_src=00:22:33:44:55:66 actions=drop
511 idle_timeout=40 in_port=1 dl_src=00:33:44:55:66:77 actions=drop
512 EOF
513 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
514  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
515  idle_timeout=20, in_port=1,dl_src=00:11:22:33:44:55 actions=drop
516  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
517  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
518 NXST_FLOW reply:
519 ])
520 # Adding another flow will cause the one that expires soonest within
521 # the largest group (those with in_port=1) to be evicted.  In this
522 # case this is not the same as the one that expires soonest overall
523 # (which is what makes the test interesting):
524 AT_CHECK([ovs-ofctl add-flow br0 in_port=2,dl_src=00:55:66:77:88:99,actions=drop])
525 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
526  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
527  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
528  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
529  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
530 NXST_FLOW reply:
531 ])
532 # Enlarge the flow limit, change the eviction policy back to strictly
533 # based on expiration, and and add some flows.
534 AT_CHECK([ovs-vsctl set Flow_Table evict groups='[[]]' flow-limit=7])
535 ovs-ofctl add-flows br0 - <<EOF
536 idle_timeout=50 in_port=2 dl_src=00:66:77:88:99:aa actions=drop
537 idle_timeout=60 in_port=2 dl_src=00:77:88:99:aa:bb actions=drop
538 idle_timeout=70 in_port=2 dl_src=00:88:99:aa:bb:cc actions=drop
539 EOF
540 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
541  idle_timeout=10, in_port=2,dl_src=00:44:55:66:77:88 actions=drop
542  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
543  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
544  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
545  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
546  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
547  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
548 NXST_FLOW reply:
549 ])
550 # Adding another flow will cause the one that expires soonest overall
551 # to be evicted.
552 AT_CHECK([ovs-ofctl add-flow br0 'idle_timeout=80 in_port=2 dl_src=00:99:aa:bb:cc:dd actions=drop'])
553 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
554  idle_timeout=30, in_port=1,dl_src=00:22:33:44:55:66 actions=drop
555  idle_timeout=40, in_port=1,dl_src=00:33:44:55:66:77 actions=drop
556  idle_timeout=50, in_port=2,dl_src=00:66:77:88:99:aa actions=drop
557  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
558  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
559  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
560  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
561 NXST_FLOW reply:
562 ])
563 # Reducing the flow limit also causes the flows that expire soonest
564 # overall to be evicted.
565 AT_CHECK([ovs-vsctl set Flow_Table evict flow-limit=4])
566 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
567  idle_timeout=60, in_port=2,dl_src=00:77:88:99:aa:bb actions=drop
568  idle_timeout=70, in_port=2,dl_src=00:88:99:aa:bb:cc actions=drop
569  idle_timeout=80, in_port=2,dl_src=00:99:aa:bb:cc:dd actions=drop
570  in_port=2,dl_src=00:55:66:77:88:99 actions=drop
571 NXST_FLOW reply:
572 ])
573 OVS_VSWITCHD_STOP
574 AT_CLEANUP
575
576 AT_SETUP([ofproto - asynchronous message control])
577 OVS_VSWITCHD_START
578 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
579 check_async () {
580     printf '\n\n--- check_async %d ---\n\n\n' $1
581     shift
582
583     ovs-appctl -t ovs-ofctl ofctl/barrier
584     ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
585     : > expout
586
587     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
588     ovs-ofctl -v packet-out br0 none controller '0001020304050010203040501234'
589     if test X"$1" = X"OFPR_ACTION"; then shift;
590         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=NONE (via action) data_len=14 (unbuffered)
591 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)"
592     fi
593
594     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
595     ovs-ofctl -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
596     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
597         echo >>expout "OFPT_PACKET_IN: total_len=14 in_port=NONE (via no_match) data_len=14 (unbuffered)
598 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)"
599     fi
600
601     # OFPT_PACKET_IN, OFPR_INVALID_TTL (controller_id=0)
602     ovs-ofctl packet-out br0 none dec_ttl '002583dfb4000026b98cb0f908004500003fb7e200000011339bac11370dac100002d7730035002b8f6d86fb0100000100000000000006626c702d7873066e696369726103636f6d00000f00'
603     if test X"$1" = X"OFPR_INVALID_TTL"; then shift;
604         echo >>expout "OFPT_PACKET_IN: total_len=76 in_port=NONE (via invalid_ttl) data_len=76 (unbuffered)
605 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:26:b9:8c:b0:f9->00:25:83:df:b4:00) type:0800 proto:17 tos:0 ttl:0 ip(172.17.55.13->172.16.0.2) port(55155->53) udp_csum:8f6d"
606     fi
607
608     # OFPT_PORT_STATUS, OFPPR_ADD
609     ovs-vsctl add-port br0 test -- set Interface test type=dummy
610     if test X"$1" = X"OFPPR_ADD"; then shift;
611         echo >>expout "OFPT_PORT_STATUS: ADD: 1(test): addr:aa:55:aa:55:00:0x
612      config:     PORT_DOWN
613      state:      LINK_DOWN
614      speed: 100 Mbps now, 100 Mbps max"
615     fi
616
617     # OFPT_PORT_STATUS, OFPPR_DELETE
618     ovs-vsctl del-port br0 test
619     if test X"$1" = X"OFPPR_DELETE"; then shift;
620         echo >>expout "OFPT_PORT_STATUS: DEL: 1(test): addr:aa:55:aa:55:00:0x
621      config:     PORT_DOWN
622      state:      LINK_DOWN
623      speed: 100 Mbps now, 100 Mbps max"
624     fi
625
626     # OFPT_FLOW_REMOVED, OFPRR_DELETE
627     ovs-ofctl add-flow br0 send_flow_rem,actions=drop
628     ovs-ofctl --strict del-flows br0 ''
629     if test X"$1" = X"OFPRR_DELETE"; then shift;
630         echo >>expout "OFPT_FLOW_REMOVED:  reason=delete"
631     fi
632     AT_FAIL_IF([test X"$1" != X])
633
634     ovs-appctl -t ovs-ofctl ofctl/barrier
635     echo >>expout "OFPT_BARRIER_REPLY:"
636
637     AT_CHECK(
638       [[sed '
639 s/ (xid=0x[0-9a-fA-F]*)//
640 s/ *duration.*//
641 s/00:0.$/00:0x/' < monitor.log]],
642       [0], [expout])
643 }
644
645 # It's a service connection so initially there should be no async messages.
646 check_async 1
647
648 # Set miss_send_len to 128, turning on packet-ins for our service connection.
649 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
650 check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
651
652 # Set miss_send_len to 128 and enable invalid_ttl.
653 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700040080
654 check_async 3 OFPR_ACTION OFPR_INVALID_TTL OFPPR_ADD OFPPR_DELETE OFPRR_DELETE
655
656 # Become slave, which should disable everything except port status.
657 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000002
658 check_async 4 OFPPR_ADD OFPPR_DELETE
659
660 # Use NXT_SET_ASYNC_CONFIG to enable a patchwork of asynchronous messages.
661 ovs-appctl -t ovs-ofctl ofctl/send 01040028000000020000232000000013000000020000000500000005000000020000000200000005
662 check_async 5 OFPR_INVALID_TTL OFPPR_DELETE OFPRR_DELETE
663
664 # Set controller ID 123.
665 ovs-appctl -t ovs-ofctl ofctl/send 01040018000000030000232000000014000000000000007b
666 check_async 6 OFPR_NO_MATCH OFPPR_DELETE OFPRR_DELETE
667
668 # Restore controller ID 0.
669 ovs-appctl -t ovs-ofctl ofctl/send 010400180000000300002320000000140000000000000000
670
671 # Become master.
672 ovs-appctl -t ovs-ofctl ofctl/send 0104001400000002000023200000000a00000001
673 check_async 7 OFPR_ACTION OFPPR_ADD
674
675 ovs-appctl -t ovs-ofctl exit
676 OVS_VSWITCHD_STOP
677 AT_CLEANUP
678
679 dnl This test checks that OFPT_PACKET_OUT accepts both OFPP_NONE (as
680 dnl specified by OpenFlow 1.0) and OFPP_CONTROLLER (used by some
681 dnl controllers despite the spec) as meaning a packet that was generated
682 dnl by the controller.
683 AT_SETUP([ofproto - packet-out from controller])
684 OVS_VSWITCHD_START
685
686 # Start a monitor listening for packet-ins.
687 AT_CHECK([ovs-ofctl -P openflow10 monitor br0 --detach --no-chdir --pidfile])
688 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
689 ovs-appctl -t ovs-ofctl ofctl/barrier
690 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
691 AT_CAPTURE_FILE([monitor.log])
692
693 # Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
694 AT_CHECK([ovs-ofctl packet-out br0 none controller '0001020304050010203040501234'])
695 AT_CHECK([ovs-ofctl packet-out br0 65533 controller '0001020304050010203040505678'])
696
697 # Stop the monitor and check its output.
698 ovs-appctl -t ovs-ofctl ofctl/barrier
699 ovs-appctl -t ovs-ofctl exit
700
701 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
702 OFPT_PACKET_IN: total_len=14 in_port=NONE (via action) data_len=14 (unbuffered)
703 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
704 OFPT_PACKET_IN: total_len=14 in_port=CONTROLLER (via action) data_len=14 (unbuffered)
705 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:5678 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
706 OFPT_BARRIER_REPLY:
707 ])
708
709 OVS_VSWITCHD_STOP
710 AT_CLEANUP
711
712 dnl This test checks that metadata is encoded in packet_in structures,
713 dnl supported by NXAST.
714 AT_SETUP([ofproto - packet-out with metadata (NXM)])
715 OVS_VSWITCHD_START
716
717 # Start a monitor listening for packet-ins.
718 AT_CHECK([ovs-ofctl -P nxm monitor br0 --detach --no-chdir --pidfile])
719 ovs-appctl -t ovs-ofctl ofctl/send 0109000c0123456700000080
720 ovs-appctl -t ovs-ofctl ofctl/barrier
721 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
722 AT_CAPTURE_FILE([monitor.log])
723
724 # Send a packet-out with a load action to set some metadata, and forward to controller
725 AT_CHECK([ovs-ofctl packet-out br0 none 'load(0xfafafafa5a5a5a5a->OXM_OF_METADATA[[0..63]]), controller' '0001020304050010203040501234'])
726
727 # Stop the monitor and check its output.
728 ovs-appctl -t ovs-ofctl ofctl/barrier
729 ovs-appctl -t ovs-ofctl exit
730
731 AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
732 NXT_PACKET_IN: total_len=14 in_port=NONE metadata=0xfafafafa5a5a5a5a (via action) data_len=14 (unbuffered)
733 priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:10:20:30:40:50->00:01:02:03:04:05) type:1234 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
734 OFPT_BARRIER_REPLY:
735 ])
736
737 OVS_VSWITCHD_STOP
738 AT_CLEANUP
739
740 AT_SETUP([ofproto - flow monitoring])
741 AT_KEYWORDS([monitor])
742 OVS_VSWITCHD_START
743
744 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:1
745
746 # Start a monitor watching the flow table and check the initial reply.
747 ovs-ofctl monitor br0 watch: --detach --no-chdir --pidfile >monitor.log 2>&1
748 AT_CAPTURE_FILE([monitor.log])
749 ovs-appctl -t ovs-ofctl ofctl/barrier
750 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log], [0],
751   [NXST_FLOW_MONITOR reply:
752  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:1
753 OFPT_BARRIER_REPLY:
754 ])
755
756 # Add, delete, and modify some flows and check the updates.
757 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
758 ovs-ofctl add-flow br0 in_port=0,dl_vlan=124,actions=output:2
759 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:5
760 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,dl_vlan_pcp=0,actions=output:6
761 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,dl_vlan_pcp=1,actions=output:7
762 ovs-ofctl add-flow br0 in_port=0,dl_vlan=123,actions=output:8
763 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,dl_vlan_pcp=0,actions=output:9
764 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,dl_vlan_pcp=1,actions=output:10
765 ovs-ofctl add-flow br0 in_port=0,dl_vlan=65535,actions=output:11
766 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,dl_vlan_pcp=0,actions=output:12
767 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,dl_vlan_pcp=1,actions=output:13
768 ovs-ofctl add-flow br0 in_port=0,dl_vlan=8191,actions=output:14
769 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=0,actions=output:15
770 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=1,actions=output:16
771 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,actions=output:17
772 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=0,actions=output:18
773 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,dl_vlan_pcp=1,actions=output:19
774 ovs-ofctl add-flow br0 in_port=0,dl_vlan=0,actions=output:20
775 ovs-ofctl add-flow br0 in_port=0,dl_vlan_pcp=0,actions=output:21
776 ovs-ofctl add-flow br0 in_port=0,dl_vlan_pcp=1,actions=output:22
777 ovs-ofctl add-flow br0 in_port=0,actions=output:23
778 ovs-ofctl mod-flows br0 cookie=5,dl_vlan=123,actions=output:3
779 ovs-ofctl del-flows br0 dl_vlan=123
780 ovs-ofctl del-flows br0
781 ovs-appctl -t ovs-ofctl ofctl/barrier
782 sort='
783     # Sorts groups of lines that start with a space, without moving them
784     # past the nearest line that does not start with a space.
785     use warnings;
786     use strict;
787     my @buffer = ();
788     while (<STDIN>) {
789         if (/^ /) {
790             push(@buffer, $_);
791         } else {
792             print $_ foreach sort(@buffer);
793             print $_;
794             @buffer = ();
795         }
796     }
797     print $_ foreach sort(@buffer);
798 '
799 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log | perl -e "$sort"], [0],
800 [NXST_FLOW_MONITOR reply (xid=0x0):
801  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
802 NXST_FLOW_MONITOR reply (xid=0x0):
803  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:5
804 NXST_FLOW_MONITOR reply (xid=0x0):
805  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:6
806 NXST_FLOW_MONITOR reply (xid=0x0):
807  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:7
808 NXST_FLOW_MONITOR reply (xid=0x0):
809  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=123 actions=output:8
810 NXST_FLOW_MONITOR reply (xid=0x0):
811  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:9
812 NXST_FLOW_MONITOR reply (xid=0x0):
813  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:10
814 NXST_FLOW_MONITOR reply (xid=0x0):
815  event=ADDED table=0 cookie=0 in_port=0,vlan_tci=0x0000 actions=output:11
816 NXST_FLOW_MONITOR reply (xid=0x0):
817  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=0 actions=output:12
818 NXST_FLOW_MONITOR reply (xid=0x0):
819  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=1 actions=output:13
820 NXST_FLOW_MONITOR reply (xid=0x0):
821  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=4095 actions=output:14
822 NXST_FLOW_MONITOR reply (xid=0x0):
823  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:15
824 NXST_FLOW_MONITOR reply (xid=0x0):
825  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:16
826 NXST_FLOW_MONITOR reply (xid=0x0):
827  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:17
828 NXST_FLOW_MONITOR reply (xid=0x0):
829  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:18
830 NXST_FLOW_MONITOR reply (xid=0x0):
831  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:19
832 NXST_FLOW_MONITOR reply (xid=0x0):
833  event=ADDED table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:20
834 NXST_FLOW_MONITOR reply (xid=0x0):
835  event=ADDED table=0 cookie=0 in_port=0,dl_vlan_pcp=0 actions=output:21
836 NXST_FLOW_MONITOR reply (xid=0x0):
837  event=ADDED table=0 cookie=0 in_port=0,dl_vlan_pcp=1 actions=output:22
838 NXST_FLOW_MONITOR reply (xid=0x0):
839  event=ADDED table=0 cookie=0 in_port=0 actions=output:23
840 NXST_FLOW_MONITOR reply (xid=0x0):
841  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123 actions=output:3
842  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
843  event=MODIFIED table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
844 NXST_FLOW_MONITOR reply (xid=0x0):
845  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123 actions=output:3
846  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=0 actions=output:3
847  event=DELETED reason=delete table=0 cookie=0x5 in_port=0,dl_vlan=123,dl_vlan_pcp=1 actions=output:3
848 NXST_FLOW_MONITOR reply (xid=0x0):
849  event=DELETED reason=delete table=0 cookie=0 in_port=0 actions=output:23
850  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0 actions=output:20
851  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=0 actions=output:18
852  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=0,dl_vlan_pcp=1 actions=output:19
853  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=124 actions=output:2
854  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095 actions=output:14
855  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=0 actions=output:12
856  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan=4095,dl_vlan_pcp=1 actions=output:13
857  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan_pcp=0 actions=output:21
858  event=DELETED reason=delete table=0 cookie=0 in_port=0,dl_vlan_pcp=1 actions=output:22
859  event=DELETED reason=delete table=0 cookie=0 in_port=0,vlan_tci=0x0000 actions=output:11
860 OFPT_BARRIER_REPLY:
861 ])
862
863 # Check that our own changes are reported as abbreviations.
864 ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
865 ovs-ofctl add-flow br0 in_port=1,actions=output:2
866 ovs-ofctl add-flow br0 in_port=2,actions=output:1
867 ovs-appctl -t ovs-ofctl ofctl/send 010e004812345678003fffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000ffffffffffff0000
868 ovs-appctl -t ovs-ofctl ofctl/barrier
869 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip], [0], [NXST_FLOW reply:
870 ])
871 AT_CHECK([sed 's/ (xid=0x[[1-9a-fA-F]][[0-9a-fA-F]]*)//' monitor.log], [0],
872 [NXST_FLOW_MONITOR reply (xid=0x0):
873  event=ADDED table=0 cookie=0 in_port=1 actions=output:2
874 NXST_FLOW_MONITOR reply (xid=0x0):
875  event=ADDED table=0 cookie=0 in_port=2 actions=output:1
876 send: OFPT_FLOW_MOD: DEL priority=0 actions=drop
877 NXST_FLOW_MONITOR reply (xid=0x0):
878  event=ABBREV xid=0x12345678
879 OFPT_BARRIER_REPLY:
880 ])
881
882 ovs-appctl -t ovs-ofctl exit
883 OVS_VSWITCHD_STOP
884 AT_CLEANUP
885
886 AT_SETUP([ofproto - flow monitoring pause and resume])
887 AT_KEYWORDS([monitor])
888
889 # The maximum socket receive buffer size is important for this test, which
890 # tests behavior when the receive buffer overflows.
891 if test -e /proc/sys/net/core/rmem_max; then
892     # Linux
893     rmem_max=`cat /proc/sys/net/core/rmem_max`
894 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
895     : # FreeBSD
896 else
897     # Don't know how to get maximum socket receive buffer on this OS
898     AT_SKIP_IF([:])
899 fi
900 # Calculate the total amount of queuing: rmem_max in the kernel, 128 kB
901 # in ofproto sending userspace (see ofmonitor_flush() in connmgr.c).
902 queue_size=`expr $rmem_max + 128 \* 1024`
903 echo rmem_max=$rmem_max queue_size=$queue_size
904
905 # Each flow update message takes up at least 48 bytes of space in queues
906 # and in practice more than that.
907 n_msgs=`expr $queue_size / 48`
908 echo n_msgs=$n_msgs
909
910 OVS_VSWITCHD_START
911
912 # Start a monitor watching the flow table, then make it block.
913 ON_EXIT([kill `cat ovs-ofctl.pid`])
914 ovs-ofctl monitor br0 watch: --detach --no-chdir --pidfile >monitor.log 2>&1
915 AT_CAPTURE_FILE([monitor.log])
916 ovs-appctl -t ovs-ofctl ofctl/block
917
918 # Add $n_msgs flows.
919 (echo "in_port=2,actions=output:2"
920 perl -e '
921     for ($i = 0; $i < '$n_msgs'; $i++) {
922         print "cookie=1,reg1=$i,actions=drop\n";
923     }
924 ') > flows.txt
925 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
926 # Check that multipart flow dumps work properly:
927 AT_CHECK([ovs-ofctl diff-flows br0 flows.txt])
928 AT_CHECK([ovs-ofctl add-flow br0 in_port=1,cookie=3,actions=drop])
929 AT_CHECK([ovs-ofctl mod-flows br0 in_port=2,cookie=2,actions=output:2])
930 AT_CHECK([ovs-ofctl del-flows br0 cookie=1/-1])
931
932 ovs-appctl -t ovs-ofctl ofctl/unblock
933 ovs-appctl -t ovs-ofctl ofctl/barrier
934
935 ovs-appctl -t ovs-ofctl exit
936
937 # Check that the flow monitor reported the same number of flows
938 # added and deleted, but fewer than we actually added and deleted.
939 adds=`grep -c 'ADDED.*reg1=' monitor.log`
940 deletes=`grep -c 'DELETED.*reg1=' monitor.log`
941 echo adds=$adds deletes=$deletes
942 AT_CHECK([test $adds -gt 100 && test $adds -lt $n_msgs])
943 AT_CHECK([test $adds = $deletes])
944
945 # Check that the flow monitor reported everything in the expected order:
946 #
947 #     event=ADDED table=0 cookie=0x1 reg1=0x22
948 # ...
949 #    NXT_FLOW_MONITOR_PAUSED:
950 # ...
951 #     event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
952 # ...
953 #     event=ADDED table=0 cookie=0x3 in_port=1
954 #     event=MODIFIED table=0 cookie=0x2 in_port=2 actions=output:2
955 #    NXT_FLOW_MONITOR_RESUMED:
956 #
957 # except that, between the PAUSED and RESUMED, the order of the ADDED
958 # and MODIFIED lines lines depends on hash order, that is, it varies
959 # as we change the hash function or change architecture.  Therefore,
960 # we use a couple of tests below to accept both orders.
961 AT_CHECK([ofctl_strip < monitor.log | sed -n -e '
962 /reg1=0x22$/p
963 /cookie=0x[[23]]/p
964 /NXT_FLOW_MONITOR_PAUSED:/p
965 /NXT_FLOW_MONITOR_RESUMED:/p
966 ' > monitor.log.subset])
967 AT_CHECK([grep -v MODIFIED monitor.log.subset], [0], [dnl
968  event=ADDED table=0 cookie=0x1 reg1=0x22
969 NXT_FLOW_MONITOR_PAUSED:
970  event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
971  event=ADDED table=0 cookie=0x3 in_port=1
972 NXT_FLOW_MONITOR_RESUMED:
973 ])
974 AT_CHECK([grep -v ADDED monitor.log.subset], [0], [dnl
975 NXT_FLOW_MONITOR_PAUSED:
976  event=DELETED reason=delete table=0 cookie=0x1 reg1=0x22
977  event=MODIFIED table=0 cookie=0x2 in_port=2 actions=output:2
978 NXT_FLOW_MONITOR_RESUMED:
979 ])
980
981 OVS_VSWITCHD_STOP
982 AT_CLEANUP