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