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