]> git.proxmox.com Git - ovs.git/blame - lib/ofp-print.c
ofproto: Implement OpenFlow extension to allow control over async messages.
[ovs.git] / lib / ofp-print.c
CommitLineData
064af421 1/*
73dbf4ab 2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
064af421 3 *
a14bc59f
BP
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
064af421 7 *
a14bc59f
BP
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
064af421
BP
15 */
16
17#include <config.h>
18#include "ofp-print.h"
064af421
BP
19
20#include <errno.h>
21#include <inttypes.h>
7f3adc00 22#include <sys/types.h>
064af421
BP
23#include <netinet/in.h>
24#include <sys/wait.h>
25#include <stdarg.h>
26#include <stdlib.h>
27#include <ctype.h>
28
daff3353 29#include "bundle.h"
10a24935 30#include "byte-order.h"
064af421
BP
31#include "compiler.h"
32#include "dynamic-string.h"
33#include "flow.h"
75a75043 34#include "learn.h"
53ddd40a 35#include "multipath.h"
816fd533 36#include "meta-flow.h"
7fa91113 37#include "nx-match.h"
90bf1e07 38#include "ofp-errors.h"
69b6be19 39#include "ofp-util.h"
064af421
BP
40#include "ofpbuf.h"
41#include "openflow/openflow.h"
42#include "openflow/nicira-ext.h"
43#include "packets.h"
44#include "pcap.h"
e41a9130 45#include "type-props.h"
c4617b3c 46#include "unaligned.h"
064af421
BP
47#include "util.h"
48
d2805da2 49static void ofp_print_queue_name(struct ds *string, uint32_t port);
90bf1e07 50static void ofp_print_error(struct ds *, enum ofperr);
7fa91113 51
064af421
BP
52
53/* Returns a string that represents the contents of the Ethernet frame in the
897a8e07 54 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
064af421 55char *
c499c75d 56ofp_packet_to_string(const void *data, size_t len)
064af421
BP
57{
58 struct ds ds = DS_EMPTY_INITIALIZER;
59 struct ofpbuf buf;
897a8e07 60 struct flow flow;
064af421 61
0bc9407d 62 ofpbuf_use_const(&buf, data, len);
897a8e07
EJ
63 flow_extract(&buf, 0, 0, 0, &flow);
64 flow_format(&ds, &flow);
e50abca5
EJ
65
66 if (buf.l7) {
67 if (flow.nw_proto == IPPROTO_TCP) {
68 struct tcp_header *th = buf.l4;
69 ds_put_format(&ds, " tcp_csum:%"PRIx16,
70 ntohs(th->tcp_csum));
71 } else if (flow.nw_proto == IPPROTO_UDP) {
72 struct udp_header *uh = buf.l4;
73 ds_put_format(&ds, " udp_csum:%"PRIx16,
74 ntohs(uh->udp_csum));
75 }
76 }
77
897a8e07 78 ds_put_char(&ds, '\n');
064af421 79
064af421
BP
80 return ds_cstr(&ds);
81}
82
80d5aefd
BP
83static const char *
84ofp_packet_in_reason_to_string(enum ofp_packet_in_reason reason)
85{
86 static char s[32];
87
88 switch (reason) {
89 case OFPR_NO_MATCH:
90 return "no_match";
91 case OFPR_ACTION:
92 return "action";
93 case OFPR_INVALID_TTL:
94 return "invalid_ttl";
95 default:
96 sprintf(s, "%d", (int) reason);
97 return s;
98 }
99}
100
064af421 101static void
65120a8a 102ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
d1e2cf21 103 int verbosity)
064af421 104{
65120a8a
EJ
105 struct ofputil_packet_in pin;
106 int error;
5d6c3af0 107 int i;
064af421 108
65120a8a
EJ
109 error = ofputil_decode_packet_in(&pin, oh);
110 if (error) {
111 ofp_print_error(string, error);
112 return;
113 }
114
54834960
EJ
115 if (pin.table_id) {
116 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
117 }
118
119 if (pin.cookie) {
120 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
121 }
122
65120a8a 123 ds_put_format(string, " total_len=%"PRIu16" in_port=", pin.total_len);
5d6c3af0
EJ
124 ofputil_format_port(pin.fmd.in_port, string);
125
126 if (pin.fmd.tun_id_mask) {
127 ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
128 if (pin.fmd.tun_id_mask != htonll(UINT64_MAX)) {
129 ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.tun_id_mask));
130 }
131 }
132
133 for (i = 0; i < FLOW_N_REGS; i++) {
134 if (pin.fmd.reg_masks[i]) {
135 ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
136 if (pin.fmd.reg_masks[i] != UINT32_MAX) {
137 ds_put_format(string, "/0x%"PRIx32, pin.fmd.reg_masks[i]);
138 }
139 }
140 }
064af421 141
80d5aefd
BP
142 ds_put_format(string, " (via %s)",
143 ofp_packet_in_reason_to_string(pin.reason));
064af421 144
65120a8a
EJ
145 ds_put_format(string, " data_len=%zu", pin.packet_len);
146 if (pin.buffer_id == UINT32_MAX) {
064af421 147 ds_put_format(string, " (unbuffered)");
65120a8a 148 if (pin.total_len != pin.packet_len) {
064af421 149 ds_put_format(string, " (***total_len != data_len***)");
65120a8a 150 }
064af421 151 } else {
65120a8a
EJ
152 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
153 if (pin.total_len < pin.packet_len) {
064af421 154 ds_put_format(string, " (***total_len < data_len***)");
65120a8a 155 }
064af421
BP
156 }
157 ds_put_char(string, '\n');
158
159 if (verbosity > 0) {
65120a8a 160 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
064af421
BP
161 ds_put_cstr(string, packet);
162 free(packet);
163 }
164}
165
96fc46e8
BP
166static void
167print_note(struct ds *string, const struct nx_action_note *nan)
168{
169 size_t len;
170 size_t i;
171
172 ds_put_cstr(string, "note:");
173 len = ntohs(nan->len) - offsetof(struct nx_action_note, note);
174 for (i = 0; i < len; i++) {
175 if (i) {
176 ds_put_char(string, '.');
177 }
178 ds_put_format(string, "%02"PRIx8, nan->note[i]);
179 }
180}
181
064af421 182static void
38f2e360
BP
183ofp_print_action(struct ds *s, const union ofp_action *a,
184 enum ofputil_action_code code)
064af421 185{
38f2e360
BP
186 const struct ofp_action_enqueue *oae;
187 const struct ofp_action_dl_addr *oada;
188 const struct nx_action_set_tunnel64 *nast64;
189 const struct nx_action_set_tunnel *nast;
190 const struct nx_action_set_queue *nasq;
191 const struct nx_action_resubmit *nar;
192 const struct nx_action_reg_move *move;
193 const struct nx_action_reg_load *load;
194 const struct nx_action_multipath *nam;
195 const struct nx_action_autopath *naa;
f694937d 196 const struct nx_action_output_reg *naor;
816fd533 197 struct mf_subfield subfield;
38f2e360
BP
198 uint16_t port;
199
200 switch (code) {
201 case OFPUTIL_OFPAT_OUTPUT:
202 port = ntohs(a->output.port);
203 if (port < OFPP_MAX) {
204 ds_put_format(s, "output:%"PRIu16, port);
205 } else {
39dc9082 206 ofputil_format_port(port, s);
38f2e360
BP
207 if (port == OFPP_CONTROLLER) {
208 if (a->output.max_len != htons(0)) {
209 ds_put_format(s, ":%"PRIu16, ntohs(a->output.max_len));
210 } else {
211 ds_put_cstr(s, ":all");
212 }
213 }
214 }
215 break;
f393f81e 216
38f2e360
BP
217 case OFPUTIL_OFPAT_ENQUEUE:
218 oae = (const struct ofp_action_enqueue *) a;
219 ds_put_format(s, "enqueue:");
39dc9082 220 ofputil_format_port(ntohs(oae->port), s);
38f2e360
BP
221 ds_put_format(s, "q%"PRIu32, ntohl(oae->queue_id));
222 break;
e41a9130 223
38f2e360
BP
224 case OFPUTIL_OFPAT_SET_VLAN_VID:
225 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
226 ntohs(a->vlan_vid.vlan_vid));
227 break;
eedc0097 228
38f2e360
BP
229 case OFPUTIL_OFPAT_SET_VLAN_PCP:
230 ds_put_format(s, "mod_vlan_pcp:%"PRIu8, a->vlan_pcp.vlan_pcp);
231 break;
96fc46e8 232
38f2e360
BP
233 case OFPUTIL_OFPAT_STRIP_VLAN:
234 ds_put_cstr(s, "strip_vlan");
235 break;
064af421 236
38f2e360
BP
237 case OFPUTIL_OFPAT_SET_DL_SRC:
238 oada = (const struct ofp_action_dl_addr *) a;
239 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
240 ETH_ADDR_ARGS(oada->dl_addr));
241 break;
064af421 242
38f2e360
BP
243 case OFPUTIL_OFPAT_SET_DL_DST:
244 oada = (const struct ofp_action_dl_addr *) a;
245 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
246 ETH_ADDR_ARGS(oada->dl_addr));
247 break;
064af421 248
38f2e360
BP
249 case OFPUTIL_OFPAT_SET_NW_SRC:
250 ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
251 break;
d295e8e9 252
38f2e360
BP
253 case OFPUTIL_OFPAT_SET_NW_DST:
254 ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
064af421 255 break;
064af421 256
38f2e360
BP
257 case OFPUTIL_OFPAT_SET_NW_TOS:
258 ds_put_format(s, "mod_nw_tos:%d", a->nw_tos.nw_tos);
c4d279ab 259 break;
c4d279ab 260
38f2e360
BP
261 case OFPUTIL_OFPAT_SET_TP_SRC:
262 ds_put_format(s, "mod_tp_src:%d", ntohs(a->tp_port.tp_port));
064af421 263 break;
064af421 264
38f2e360
BP
265 case OFPUTIL_OFPAT_SET_TP_DST:
266 ds_put_format(s, "mod_tp_dst:%d", ntohs(a->tp_port.tp_port));
064af421 267 break;
064af421 268
38f2e360
BP
269 case OFPUTIL_NXAST_RESUBMIT:
270 nar = (struct nx_action_resubmit *)a;
271 ds_put_format(s, "resubmit:");
39dc9082 272 ofputil_format_port(ntohs(nar->in_port), s);
064af421
BP
273 break;
274
29901626
BP
275 case OFPUTIL_NXAST_RESUBMIT_TABLE:
276 nar = (struct nx_action_resubmit *)a;
277 ds_put_format(s, "resubmit(");
278 if (nar->in_port != htons(OFPP_IN_PORT)) {
39dc9082 279 ofputil_format_port(ntohs(nar->in_port), s);
29901626
BP
280 }
281 ds_put_char(s, ',');
282 if (nar->table != 255) {
283 ds_put_format(s, "%"PRIu8, nar->table);
284 }
285 ds_put_char(s, ')');
286 break;
287
38f2e360
BP
288 case OFPUTIL_NXAST_SET_TUNNEL:
289 nast = (struct nx_action_set_tunnel *)a;
290 ds_put_format(s, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id));
064af421 291 break;
064af421 292
38f2e360
BP
293 case OFPUTIL_NXAST_SET_QUEUE:
294 nasq = (struct nx_action_set_queue *)a;
295 ds_put_format(s, "set_queue:%u", ntohl(nasq->queue_id));
064af421 296 break;
064af421 297
38f2e360
BP
298 case OFPUTIL_NXAST_POP_QUEUE:
299 ds_put_cstr(s, "pop_queue");
064af421 300 break;
064af421 301
38f2e360
BP
302 case OFPUTIL_NXAST_NOTE:
303 print_note(s, (const struct nx_action_note *) a);
064af421 304 break;
064af421 305
38f2e360
BP
306 case OFPUTIL_NXAST_REG_MOVE:
307 move = (const struct nx_action_reg_move *) a;
308 nxm_format_reg_move(move, s);
959a2ecd 309 break;
959a2ecd 310
38f2e360
BP
311 case OFPUTIL_NXAST_REG_LOAD:
312 load = (const struct nx_action_reg_load *) a;
313 nxm_format_reg_load(load, s);
064af421 314 break;
064af421 315
38f2e360
BP
316 case OFPUTIL_NXAST_SET_TUNNEL64:
317 nast64 = (const struct nx_action_set_tunnel64 *) a;
318 ds_put_format(s, "set_tunnel64:%#"PRIx64,
319 ntohll(nast64->tun_id));
064af421 320 break;
064af421 321
38f2e360
BP
322 case OFPUTIL_NXAST_MULTIPATH:
323 nam = (const struct nx_action_multipath *) a;
324 multipath_format(nam, s);
325 break;
326
327 case OFPUTIL_NXAST_AUTOPATH:
328 naa = (const struct nx_action_autopath *)a;
329 ds_put_format(s, "autopath(%u,", ntohl(naa->id));
816fd533
BP
330 nxm_decode(&subfield, naa->dst, naa->ofs_nbits);
331 mf_format_subfield(&subfield, s);
38f2e360 332 ds_put_char(s, ')');
064af421 333 break;
064af421 334
daff3353 335 case OFPUTIL_NXAST_BUNDLE:
a368bb53 336 case OFPUTIL_NXAST_BUNDLE_LOAD:
daff3353
EJ
337 bundle_format((const struct nx_action_bundle *) a, s);
338 break;
339
f694937d
EJ
340 case OFPUTIL_NXAST_OUTPUT_REG:
341 naor = (const struct nx_action_output_reg *) a;
342 ds_put_cstr(s, "output:");
816fd533
BP
343 nxm_decode(&subfield, naor->src, naor->ofs_nbits);
344 mf_format_subfield(&subfield, s);
0c58c0c4 345 break;
f694937d 346
75a75043
BP
347 case OFPUTIL_NXAST_LEARN:
348 learn_format((const struct nx_action_learn *) a, s);
349 break;
350
f0fd1a17
PS
351 case OFPUTIL_NXAST_DEC_TTL:
352 ds_put_cstr(s, "dec_ttl");
353 break;
354
848e8809
EJ
355 case OFPUTIL_NXAST_EXIT:
356 ds_put_cstr(s, "exit");
357 break;
358
064af421 359 default:
064af421
BP
360 break;
361 }
064af421
BP
362}
363
d295e8e9 364void
b4b8c781
BP
365ofp_print_actions(struct ds *string, const union ofp_action *actions,
366 size_t n_actions)
064af421 367{
b4b8c781
BP
368 const union ofp_action *a;
369 size_t left;
064af421
BP
370
371 ds_put_cstr(string, "actions=");
b4b8c781 372 if (!n_actions) {
064af421
BP
373 ds_put_cstr(string, "drop");
374 }
38f2e360 375
b4b8c781 376 OFPUTIL_ACTION_FOR_EACH (a, left, actions, n_actions) {
38f2e360
BP
377 int code = ofputil_decode_action(a);
378 if (code >= 0) {
379 if (a != actions) {
380 ds_put_cstr(string, ",");
381 }
382 ofp_print_action(string, a, code);
383 } else {
384 ofp_print_error(string, -code);
064af421 385 }
b4b8c781
BP
386 }
387 if (left > 0) {
388 ds_put_format(string, " ***%zu leftover bytes following actions",
389 left * sizeof *a);
064af421
BP
390 }
391}
392
d1e2cf21
BP
393static void
394ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
395 int verbosity)
064af421 396{
c6a93eb7
BP
397 struct ofputil_packet_out po;
398 enum ofperr error;
064af421 399
c6a93eb7
BP
400 error = ofputil_decode_packet_out(&po, opo);
401 if (error) {
402 ofp_print_error(string, error);
064af421
BP
403 return;
404 }
c6a93eb7
BP
405
406 ds_put_cstr(string, " in_port=");
407 ofputil_format_port(po.in_port, string);
408
409 ds_put_char(string, ' ');
410 ofp_print_actions(string, po.actions, po.n_actions);
411
412 if (po.buffer_id == UINT32_MAX) {
413 ds_put_format(string, " data_len=%d", po.packet_len);
414 if (verbosity > 0 && po.packet_len > 0) {
415 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
064af421
BP
416 ds_put_char(string, '\n');
417 ds_put_cstr(string, packet);
418 free(packet);
419 }
420 } else {
c6a93eb7 421 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
064af421
BP
422 }
423 ds_put_char(string, '\n');
424}
425
426/* qsort comparison function. */
427static int
428compare_ports(const void *a_, const void *b_)
429{
430 const struct ofp_phy_port *a = a_;
431 const struct ofp_phy_port *b = b_;
432 uint16_t ap = ntohs(a->port_no);
433 uint16_t bp = ntohs(b->port_no);
434
435 return ap < bp ? -1 : ap > bp;
436}
437
0ab14c8e
BP
438struct bit_name {
439 uint32_t bit;
440 const char *name;
441};
442
443static void
444ofp_print_bit_names(struct ds *string, uint32_t bits,
445 const struct bit_name bit_names[])
064af421 446{
0ab14c8e
BP
447 int n = 0;
448
449 if (!bits) {
450 ds_put_cstr(string, "0");
064af421
BP
451 return;
452 }
0ab14c8e
BP
453
454 for (; bits && bit_names->name; bit_names++) {
455 if (bits & bit_names->bit) {
456 if (n++) {
457 ds_put_char(string, ' ');
458 }
459 ds_put_cstr(string, bit_names->name);
460 bits &= ~bit_names->bit;
461 }
064af421 462 }
0ab14c8e
BP
463
464 if (bits) {
465 if (n++) {
466 ds_put_char(string, ' ');
467 }
468 ds_put_format(string, "0x%"PRIx32, bits);
064af421 469 }
0ab14c8e
BP
470}
471
472static void
473ofp_print_port_features(struct ds *string, uint32_t features)
474{
475 static const struct bit_name feature_bits[] = {
476 { OFPPF_10MB_HD, "10MB-HD" },
477 { OFPPF_10MB_FD, "10MB-FD" },
478 { OFPPF_100MB_HD, "100MB-HD" },
479 { OFPPF_100MB_FD, "100MB-FD" },
480 { OFPPF_1GB_HD, "1GB-HD" },
481 { OFPPF_1GB_FD, "1GB-FD" },
482 { OFPPF_10GB_FD, "10GB-FD" },
483 { OFPPF_COPPER, "COPPER" },
484 { OFPPF_FIBER, "FIBER" },
485 { OFPPF_AUTONEG, "AUTO_NEG" },
486 { OFPPF_PAUSE, "AUTO_PAUSE" },
487 { OFPPF_PAUSE_ASYM, "AUTO_PAUSE_ASYM" },
488 { 0, NULL },
489 };
490
491 ofp_print_bit_names(string, features, feature_bits);
492 ds_put_char(string, '\n');
493}
494
495static void
496ofp_print_port_config(struct ds *string, uint32_t config)
497{
498 static const struct bit_name config_bits[] = {
499 { OFPPC_PORT_DOWN, "PORT_DOWN" },
500 { OFPPC_NO_STP, "NO_STP" },
501 { OFPPC_NO_RECV, "NO_RECV" },
502 { OFPPC_NO_RECV_STP, "NO_RECV_STP" },
503 { OFPPC_NO_FLOOD, "NO_FLOOD" },
504 { OFPPC_NO_FWD, "NO_FWD" },
505 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
506 { 0, NULL },
507 };
508
509 ofp_print_bit_names(string, config, config_bits);
510 ds_put_char(string, '\n');
511}
512
513static void
514ofp_print_port_state(struct ds *string, uint32_t state)
515{
516 static const struct bit_name state_bits[] = {
517 { OFPPS_LINK_DOWN, "LINK_DOWN" },
518 { 0, NULL },
519 };
520 uint32_t stp_state;
521
522 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
523 * pattern. We have to special case it.
524 *
525 * OVS doesn't support STP, so this field will always be 0 if we are
526 * talking to OVS, so we'd always print STP_LISTEN in that case.
527 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
528 * avoid confusing users. */
529 stp_state = state & OFPPS_STP_MASK;
530 if (stp_state) {
531 ds_put_cstr(string, (stp_state == OFPPS_STP_LEARN ? "STP_LEARN"
532 : stp_state == OFPPS_STP_FORWARD ? "STP_FORWARD"
533 : "STP_BLOCK"));
534 state &= ~OFPPS_STP_MASK;
535 if (state) {
536 ofp_print_bit_names(string, state, state_bits);
537 }
538 } else {
539 ofp_print_bit_names(string, state, state_bits);
064af421
BP
540 }
541 ds_put_char(string, '\n');
542}
543
544static void
545ofp_print_phy_port(struct ds *string, const struct ofp_phy_port *port)
546{
0b61210e 547 char name[OFP_MAX_PORT_NAME_LEN];
064af421
BP
548 int j;
549
550 memcpy(name, port->name, sizeof name);
551 for (j = 0; j < sizeof name - 1; j++) {
858f2852 552 if (!isprint((unsigned char) name[j])) {
064af421
BP
553 break;
554 }
555 }
556 name[j] = '\0';
557
558 ds_put_char(string, ' ');
39dc9082 559 ofputil_format_port(ntohs(port->port_no), string);
0ab14c8e
BP
560 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
561 name, ETH_ADDR_ARGS(port->hw_addr));
562
563 ds_put_cstr(string, " config: ");
564 ofp_print_port_config(string, ntohl(port->config));
565
566 ds_put_cstr(string, " state: ");
567 ofp_print_port_state(string, ntohl(port->state));
568
064af421
BP
569 if (port->curr) {
570 ds_put_format(string, " current: ");
571 ofp_print_port_features(string, ntohl(port->curr));
572 }
573 if (port->advertised) {
574 ds_put_format(string, " advertised: ");
575 ofp_print_port_features(string, ntohl(port->advertised));
576 }
577 if (port->supported) {
578 ds_put_format(string, " supported: ");
579 ofp_print_port_features(string, ntohl(port->supported));
580 }
581 if (port->peer) {
582 ds_put_format(string, " peer: ");
583 ofp_print_port_features(string, ntohl(port->peer));
584 }
585}
586
064af421 587static void
d1e2cf21
BP
588ofp_print_switch_features(struct ds *string,
589 const struct ofp_switch_features *osf)
064af421 590{
d1e2cf21 591 size_t len = ntohs(osf->header.length);
064af421
BP
592 struct ofp_phy_port *port_list;
593 int n_ports;
594 int i;
595
d295e8e9 596 ds_put_format(string, " ver:0x%x, dpid:%016"PRIx64"\n",
064af421
BP
597 osf->header.version, ntohll(osf->datapath_id));
598 ds_put_format(string, "n_tables:%d, n_buffers:%d\n", osf->n_tables,
599 ntohl(osf->n_buffers));
600 ds_put_format(string, "features: capabilities:%#x, actions:%#x\n",
601 ntohl(osf->capabilities), ntohl(osf->actions));
602
064af421
BP
603 n_ports = (len - sizeof *osf) / sizeof *osf->ports;
604
d295e8e9 605 port_list = xmemdup(osf->ports, len - sizeof *osf);
064af421
BP
606 qsort(port_list, n_ports, sizeof *port_list, compare_ports);
607 for (i = 0; i < n_ports; i++) {
608 ofp_print_phy_port(string, &port_list[i]);
609 }
610 free(port_list);
611}
612
064af421 613static void
d1e2cf21 614ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
064af421 615{
f0fd1a17 616 enum ofp_config_flags flags;
064af421
BP
617
618 flags = ntohs(osc->flags);
3b62feba 619
7257b535
BP
620 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
621 flags &= ~OFPC_FRAG_MASK;
622
f0fd1a17
PS
623 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
624 ds_put_format(string, " invalid_ttl_to_controller");
625 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
626 }
627
064af421
BP
628 if (flags) {
629 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
630 }
631
632 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
633}
634
635static void print_wild(struct ds *string, const char *leader, int is_wild,
d295e8e9 636 int verbosity, const char *format, ...)
064af421
BP
637 __attribute__((format(printf, 5, 6)));
638
639static void print_wild(struct ds *string, const char *leader, int is_wild,
d295e8e9 640 int verbosity, const char *format, ...)
064af421
BP
641{
642 if (is_wild && verbosity < 2) {
643 return;
644 }
645 ds_put_cstr(string, leader);
646 if (!is_wild) {
647 va_list args;
648
649 va_start(args, format);
650 ds_put_format_valist(string, format, args);
651 va_end(args);
652 } else {
653 ds_put_char(string, '*');
654 }
655 ds_put_char(string, ',');
656}
657
658static void
dbba996b 659print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
064af421
BP
660 uint32_t wild_bits, int verbosity)
661{
662 if (wild_bits >= 32 && verbosity < 2) {
663 return;
664 }
665 ds_put_cstr(string, leader);
666 if (wild_bits < 32) {
667 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
668 if (wild_bits) {
669 ds_put_format(string, "/%d", 32 - wild_bits);
670 }
671 } else {
672 ds_put_char(string, '*');
673 }
674 ds_put_char(string, ',');
675}
676
4f2cad2c 677void
064af421
BP
678ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
679{
680 char *s = ofp_match_to_string(om, verbosity);
681 ds_put_cstr(f, s);
682 free(s);
683}
684
685char *
686ofp_match_to_string(const struct ofp_match *om, int verbosity)
687{
688 struct ds f = DS_EMPTY_INITIALIZER;
689 uint32_t w = ntohl(om->wildcards);
690 bool skip_type = false;
691 bool skip_proto = false;
692
693 if (!(w & OFPFW_DL_TYPE)) {
694 skip_type = true;
695 if (om->dl_type == htons(ETH_TYPE_IP)) {
696 if (!(w & OFPFW_NW_PROTO)) {
697 skip_proto = true;
6767a2cc 698 if (om->nw_proto == IPPROTO_ICMP) {
064af421 699 ds_put_cstr(&f, "icmp,");
6767a2cc 700 } else if (om->nw_proto == IPPROTO_TCP) {
064af421 701 ds_put_cstr(&f, "tcp,");
6767a2cc 702 } else if (om->nw_proto == IPPROTO_UDP) {
064af421
BP
703 ds_put_cstr(&f, "udp,");
704 } else {
705 ds_put_cstr(&f, "ip,");
706 skip_proto = false;
707 }
708 } else {
709 ds_put_cstr(&f, "ip,");
710 }
711 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
712 ds_put_cstr(&f, "arp,");
713 } else {
714 skip_type = false;
715 }
716 }
717 print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
718 "%d", ntohs(om->in_port));
719 print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
6a1f89c8 720 "%d", ntohs(om->dl_vlan));
959a2ecd
JP
721 print_wild(&f, "dl_vlan_pcp=", w & OFPFW_DL_VLAN_PCP, verbosity,
722 "%d", om->dl_vlan_pcp);
064af421
BP
723 print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
724 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
725 print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
726 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
727 if (!skip_type) {
728 print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
729 "0x%04x", ntohs(om->dl_type));
730 }
731 print_ip_netmask(&f, "nw_src=", om->nw_src,
732 (w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
733 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
734 (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
735 if (!skip_proto) {
fb892732 736 if (om->dl_type == htons(ETH_TYPE_ARP)) {
fb115f91 737 print_wild(&f, "arp_op=", w & OFPFW_NW_PROTO, verbosity,
fb892732
JP
738 "%u", om->nw_proto);
739 } else {
740 print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
741 "%u", om->nw_proto);
742 }
064af421 743 }
1a960c80
RL
744 print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
745 "%u", om->nw_tos);
6767a2cc 746 if (om->nw_proto == IPPROTO_ICMP) {
064af421 747 print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
3ee8a9f0 748 "%d", ntohs(om->tp_src));
064af421 749 print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
3ee8a9f0 750 "%d", ntohs(om->tp_dst));
064af421
BP
751 } else {
752 print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
753 "%d", ntohs(om->tp_src));
754 print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
755 "%d", ntohs(om->tp_dst));
756 }
7fa91113
BP
757 if (ds_last(&f) == ',') {
758 f.length--;
759 }
064af421
BP
760 return ds_cstr(&f);
761}
762
064af421 763static void
7fa91113
BP
764ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
765 enum ofputil_msg_code code, int verbosity)
064af421 766{
a9a2da38 767 struct ofputil_flow_mod fm;
f904747b 768 bool need_priority;
90bf1e07 769 enum ofperr error;
064af421 770
00794817 771 error = ofputil_decode_flow_mod(&fm, oh, true);
7fa91113
BP
772 if (error) {
773 ofp_print_error(s, error);
774 return;
3ff4f871
BP
775 }
776
7fa91113
BP
777 ds_put_char(s, ' ');
778 switch (fm.command) {
064af421 779 case OFPFC_ADD:
7fa91113 780 ds_put_cstr(s, "ADD");
064af421
BP
781 break;
782 case OFPFC_MODIFY:
7fa91113 783 ds_put_cstr(s, "MOD");
064af421
BP
784 break;
785 case OFPFC_MODIFY_STRICT:
7fa91113 786 ds_put_cstr(s, "MOD_STRICT");
064af421
BP
787 break;
788 case OFPFC_DELETE:
7fa91113 789 ds_put_cstr(s, "DEL");
064af421
BP
790 break;
791 case OFPFC_DELETE_STRICT:
7fa91113 792 ds_put_cstr(s, "DEL_STRICT");
064af421
BP
793 break;
794 default:
7fa91113
BP
795 ds_put_format(s, "cmd:%d", fm.command);
796 }
6c1491fb 797 if (fm.table_id != 0) {
e896c2d4 798 ds_put_format(s, " table:%d", fm.table_id);
6c1491fb 799 }
7fa91113
BP
800
801 ds_put_char(s, ' ');
802 if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) {
803 const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh;
7fa91113 804 ofp_print_match(s, &ofm->match, verbosity);
f904747b
BP
805
806 /* ofp_print_match() doesn't print priority. */
807 need_priority = true;
7fa91113
BP
808 } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) {
809 const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh;
810 const void *nxm = nfm + 1;
f904747b
BP
811 char *nxm_s;
812
813 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
7fa91113
BP
814 ds_put_cstr(s, nxm_s);
815 free(nxm_s);
f904747b
BP
816
817 /* nx_match_to_string() doesn't print priority. */
818 need_priority = true;
7fa91113
BP
819 } else {
820 cls_rule_format(&fm.cr, s);
f904747b
BP
821
822 /* cls_rule_format() does print priority. */
823 need_priority = false;
3ff4f871 824 }
7fa91113
BP
825
826 if (ds_last(s) != ' ') {
827 ds_put_char(s, ' ');
3ff4f871 828 }
7fa91113
BP
829 if (fm.cookie != htonll(0)) {
830 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.cookie));
3ff4f871 831 }
7fa91113
BP
832 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
833 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
064af421 834 }
7fa91113
BP
835 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
836 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
3ff4f871 837 }
f904747b 838 if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
7fa91113 839 ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
3ff4f871 840 }
7fa91113
BP
841 if (fm.buffer_id != UINT32_MAX) {
842 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
3ff4f871 843 }
7fa91113 844 if (fm.flags != 0) {
a993007b
BP
845 uint16_t flags = fm.flags;
846
847 if (flags & OFPFF_SEND_FLOW_REM) {
848 ds_put_cstr(s, "send_flow_rem ");
849 }
850 if (flags & OFPFF_CHECK_OVERLAP) {
851 ds_put_cstr(s, "check_overlap ");
852 }
853 if (flags & OFPFF_EMERG) {
854 ds_put_cstr(s, "emerg ");
855 }
856
857 flags &= ~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG);
858 if (flags) {
859 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
860 }
7fa91113
BP
861 }
862
b4b8c781 863 ofp_print_actions(s, fm.actions, fm.n_actions);
064af421
BP
864}
865
09862ec6
BP
866static void
867ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
868{
869 ds_put_format(string, "%u", sec);
870 if (nsec > 0) {
871 ds_put_format(string, ".%09u", nsec);
872 while (string->string[string->length - 1] == '0') {
873 string->length--;
874 }
875 }
876 ds_put_char(string, 's');
877}
878
80d5aefd
BP
879static const char *
880ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason)
881{
882 static char s[32];
883
884 switch (reason) {
885 case OFPRR_IDLE_TIMEOUT:
886 return "idle";
887 case OFPRR_HARD_TIMEOUT:
888 return "hard";
889 case OFPRR_DELETE:
890 return "delete";
891 default:
892 sprintf(s, "%d", (int) reason);
893 return s;
894 }
895}
896
064af421 897static void
9b045a0c 898ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
064af421 899{
9b045a0c 900 struct ofputil_flow_removed fr;
90bf1e07 901 enum ofperr error;
9b045a0c 902
b78f6b77 903 error = ofputil_decode_flow_removed(&fr, oh);
9b045a0c
BP
904 if (error) {
905 ofp_print_error(string, error);
906 return;
907 }
908
fbd76b2e 909 ds_put_char(string, ' ');
9b045a0c
BP
910 cls_rule_format(&fr.rule, string);
911
80d5aefd
BP
912 ds_put_format(string, " reason=%s",
913 ofp_flow_removed_reason_to_string(fr.reason));
3ff4f871 914
9b045a0c
BP
915 if (fr.cookie != htonll(0)) {
916 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
3ff4f871 917 }
09862ec6 918 ds_put_cstr(string, " duration");
9b045a0c 919 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
09862ec6 920 ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
9b045a0c 921 fr.idle_timeout, fr.packet_count, fr.byte_count);
064af421
BP
922}
923
924static void
d1e2cf21 925ofp_print_port_mod(struct ds *string, const struct ofp_port_mod *opm)
064af421 926{
064af421 927 ds_put_format(string, "port: %d: addr:"ETH_ADDR_FMT", config: %#x, mask:%#x\n",
d295e8e9 928 ntohs(opm->port_no), ETH_ADDR_ARGS(opm->hw_addr),
064af421
BP
929 ntohl(opm->config), ntohl(opm->mask));
930 ds_put_format(string, " advertise: ");
931 if (opm->advertise) {
932 ofp_print_port_features(string, ntohl(opm->advertise));
933 } else {
934 ds_put_format(string, "UNCHANGED\n");
935 }
936}
937
7fa91113 938static void
90bf1e07 939ofp_print_error(struct ds *string, enum ofperr error)
7fa91113 940{
7fa91113
BP
941 if (string->length) {
942 ds_put_char(string, ' ');
943 }
90bf1e07 944 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
f74be05a
JP
945}
946
064af421 947static void
d1e2cf21 948ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
064af421 949{
d1e2cf21 950 size_t len = ntohs(oem->header.length);
dc4762ed
BP
951 size_t payload_ofs, payload_len;
952 const void *payload;
90bf1e07 953 enum ofperr error;
064af421
BP
954 char *s;
955
90bf1e07
BP
956 error = ofperr_decode_msg(&oem->header, &payload_ofs);
957 if (!error) {
958 ds_put_cstr(string, "***decode error***");
dc4762ed
BP
959 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
960 return;
f74be05a
JP
961 }
962
90bf1e07 963 ds_put_format(string, " %s\n", ofperr_get_name(error));
064af421 964
dc4762ed
BP
965 payload = (const uint8_t *) oem + payload_ofs;
966 payload_len = len - payload_ofs;
90bf1e07 967 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
dc4762ed 968 ds_put_printable(string, payload, payload_len);
90bf1e07 969 } else {
dc4762ed 970 s = ofp_to_string(payload, payload_len, 1);
064af421
BP
971 ds_put_cstr(string, s);
972 free(s);
064af421
BP
973 }
974}
975
064af421 976static void
d1e2cf21 977ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
064af421 978{
064af421
BP
979 if (ops->reason == OFPPR_ADD) {
980 ds_put_format(string, " ADD:");
981 } else if (ops->reason == OFPPR_DELETE) {
982 ds_put_format(string, " DEL:");
983 } else if (ops->reason == OFPPR_MODIFY) {
984 ds_put_format(string, " MOD:");
985 }
986
987 ofp_print_phy_port(string, &ops->desc);
988}
989
990static void
63f2140a 991ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods)
064af421 992{
fbd76b2e 993 ds_put_char(string, '\n');
d295e8e9 994 ds_put_format(string, "Manufacturer: %.*s\n",
dd70b475
JP
995 (int) sizeof ods->mfr_desc, ods->mfr_desc);
996 ds_put_format(string, "Hardware: %.*s\n",
997 (int) sizeof ods->hw_desc, ods->hw_desc);
998 ds_put_format(string, "Software: %.*s\n",
999 (int) sizeof ods->sw_desc, ods->sw_desc);
1000 ds_put_format(string, "Serial Num: %.*s\n",
1001 (int) sizeof ods->serial_num, ods->serial_num);
1002 ds_put_format(string, "DP Description: %.*s\n",
1003 (int) sizeof ods->dp_desc, ods->dp_desc);
064af421
BP
1004}
1005
1006static void
76c93b22
BP
1007ofp_print_flow_stats_request(struct ds *string,
1008 const struct ofp_stats_msg *osm)
064af421 1009{
81d1ea94 1010 struct ofputil_flow_stats_request fsr;
90bf1e07 1011 enum ofperr error;
064af421 1012
76c93b22 1013 error = ofputil_decode_flow_stats_request(&fsr, &osm->header);
2af0c0ef
BP
1014 if (error) {
1015 ofp_print_error(string, error);
1016 return;
1017 }
1018
1019 if (fsr.table_id != 0xff) {
e896c2d4 1020 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
064af421
BP
1021 }
1022
2af0c0ef
BP
1023 if (fsr.out_port != OFPP_NONE) {
1024 ds_put_cstr(string, " out_port=");
39dc9082 1025 ofputil_format_port(fsr.out_port, string);
2af0c0ef
BP
1026 }
1027
54ae6fa8
BP
1028 /* A flow stats request doesn't include a priority, but cls_rule_format()
1029 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1030 fsr.match.priority = OFP_DEFAULT_PRIORITY;
1031
2af0c0ef
BP
1032 ds_put_char(string, ' ');
1033 cls_rule_format(&fsr.match, string);
064af421
BP
1034}
1035
1036static void
4ffd1b43 1037ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
064af421 1038{
4ffd1b43 1039 struct ofpbuf b;
064af421 1040
4ffd1b43
BP
1041 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1042 for (;;) {
1043 struct ofputil_flow_stats fs;
1044 int retval;
fab8fadb 1045
f27f2134 1046 retval = ofputil_decode_flow_stats_reply(&fs, &b, true);
4ffd1b43
BP
1047 if (retval) {
1048 if (retval != EOF) {
1049 ds_put_cstr(string, " ***parse error***");
064af421
BP
1050 }
1051 break;
1052 }
1053
8961de6a
BP
1054 ds_put_char(string, '\n');
1055
09862ec6 1056 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
4ffd1b43
BP
1057 ntohll(fs.cookie));
1058 ofp_print_duration(string, fs.duration_sec, fs.duration_nsec);
e896c2d4 1059 ds_put_format(string, ", table=%"PRIu8", ", fs.table_id);
4ffd1b43
BP
1060 ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count);
1061 ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count);
1062 if (fs.idle_timeout != OFP_FLOW_PERMANENT) {
1063 ds_put_format(string, "idle_timeout=%"PRIu16",", fs.idle_timeout);
c6430da5 1064 }
4ffd1b43
BP
1065 if (fs.hard_timeout != OFP_FLOW_PERMANENT) {
1066 ds_put_format(string, "hard_timeout=%"PRIu16",", fs.hard_timeout);
c6430da5 1067 }
f27f2134
BP
1068 if (fs.idle_age >= 0) {
1069 ds_put_format(string, "idle_age=%d,", fs.idle_age);
1070 }
1071 if (fs.hard_age >= 0 && fs.hard_age != fs.duration_sec) {
1072 ds_put_format(string, "hard_age=%d,", fs.hard_age);
1073 }
c6430da5 1074
4ffd1b43 1075 cls_rule_format(&fs.rule, string);
05b8f1c2
BP
1076 if (string->string[string->length - 1] != ' ') {
1077 ds_put_char(string, ' ');
1078 }
b4b8c781 1079 ofp_print_actions(string, fs.actions, fs.n_actions);
c6430da5
BP
1080 }
1081}
1082
064af421 1083static void
63f2140a
BP
1084ofp_print_ofpst_aggregate_reply(struct ds *string,
1085 const struct ofp_aggregate_stats_reply *asr)
064af421 1086{
c4617b3c
BP
1087 ds_put_format(string, " packet_count=%"PRIu64,
1088 ntohll(get_32aligned_be64(&asr->packet_count)));
1089 ds_put_format(string, " byte_count=%"PRIu64,
1090 ntohll(get_32aligned_be64(&asr->byte_count)));
064af421
BP
1091 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1092}
1093
a2ad9ecd
BP
1094static void
1095ofp_print_nxst_aggregate_reply(struct ds *string,
1096 const struct nx_aggregate_stats_reply *nasr)
1097{
675baf0c
BP
1098 ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count));
1099 ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count));
1100 ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count));
a2ad9ecd
BP
1101}
1102
d295e8e9 1103static void print_port_stat(struct ds *string, const char *leader,
c4617b3c 1104 const ovs_32aligned_be64 *statp, int more)
064af421 1105{
c4617b3c
BP
1106 uint64_t stat = ntohll(get_32aligned_be64(statp));
1107
064af421 1108 ds_put_cstr(string, leader);
c4617b3c 1109 if (stat != UINT64_MAX) {
064af421
BP
1110 ds_put_format(string, "%"PRIu64, stat);
1111 } else {
1112 ds_put_char(string, '?');
1113 }
1114 if (more) {
1115 ds_put_cstr(string, ", ");
1116 } else {
1117 ds_put_cstr(string, "\n");
1118 }
1119}
1120
abaad8cf 1121static void
63f2140a
BP
1122ofp_print_ofpst_port_request(struct ds *string,
1123 const struct ofp_port_stats_request *psr)
abaad8cf 1124{
fbd76b2e 1125 ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
abaad8cf
JP
1126}
1127
064af421 1128static void
d1e2cf21
BP
1129ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1130 int verbosity)
064af421 1131{
d1e2cf21
BP
1132 const struct ofp_port_stats *ps = ofputil_stats_body(oh);
1133 size_t n = ofputil_stats_body_len(oh) / sizeof *ps;
064af421
BP
1134 ds_put_format(string, " %zu ports\n", n);
1135 if (verbosity < 1) {
1136 return;
1137 }
1138
1139 for (; n--; ps++) {
1140 ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no));
1141
1142 ds_put_cstr(string, "rx ");
c4617b3c
BP
1143 print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1144 print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1145 print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1146 print_port_stat(string, "errs=", &ps->rx_errors, 1);
1147 print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1148 print_port_stat(string, "over=", &ps->rx_over_err, 1);
1149 print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
064af421
BP
1150
1151 ds_put_cstr(string, " tx ");
c4617b3c
BP
1152 print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1153 print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1154 print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1155 print_port_stat(string, "errs=", &ps->tx_errors, 1);
1156 print_port_stat(string, "coll=", &ps->collisions, 0);
064af421
BP
1157 }
1158}
1159
1160static void
d1e2cf21
BP
1161ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1162 int verbosity)
064af421 1163{
d1e2cf21
BP
1164 const struct ofp_table_stats *ts = ofputil_stats_body(oh);
1165 size_t n = ofputil_stats_body_len(oh) / sizeof *ts;
064af421
BP
1166 ds_put_format(string, " %zu tables\n", n);
1167 if (verbosity < 1) {
1168 return;
1169 }
1170
1171 for (; n--; ts++) {
1172 char name[OFP_MAX_TABLE_NAME_LEN + 1];
e868fb3d 1173 ovs_strlcpy(name, ts->name, sizeof name);
064af421
BP
1174
1175 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1176 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1177 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1178 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1179 ds_put_cstr(string, " ");
d295e8e9 1180 ds_put_format(string, "lookup=%"PRIu64", ",
c4617b3c 1181 ntohll(get_32aligned_be64(&ts->lookup_count)));
064af421 1182 ds_put_format(string, "matched=%"PRIu64"\n",
c4617b3c 1183 ntohll(get_32aligned_be64(&ts->matched_count)));
064af421
BP
1184 }
1185}
1186
d2805da2
BP
1187static void
1188ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1189{
1190 if (queue_id == OFPQ_ALL) {
1191 ds_put_cstr(string, "ALL");
1192 } else {
1193 ds_put_format(string, "%"PRIu32, queue_id);
1194 }
1195}
1196
1197static void
63f2140a
BP
1198ofp_print_ofpst_queue_request(struct ds *string,
1199 const struct ofp_queue_stats_request *qsr)
d2805da2 1200{
d2805da2 1201 ds_put_cstr(string, "port=");
39dc9082 1202 ofputil_format_port(ntohs(qsr->port_no), string);
d2805da2
BP
1203
1204 ds_put_cstr(string, " queue=");
1205 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1206}
1207
1208static void
d1e2cf21
BP
1209ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1210 int verbosity)
d2805da2 1211{
d1e2cf21
BP
1212 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1213 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
d2805da2
BP
1214 ds_put_format(string, " %zu queues\n", n);
1215 if (verbosity < 1) {
1216 return;
1217 }
1218
1219 for (; n--; qs++) {
1220 ds_put_cstr(string, " port ");
39dc9082 1221 ofputil_format_port(ntohs(qs->port_no), string);
d2805da2
BP
1222 ds_put_cstr(string, " queue ");
1223 ofp_print_queue_name(string, ntohl(qs->queue_id));
1224 ds_put_cstr(string, ": ");
1225
c4617b3c
BP
1226 print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1227 print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1228 print_port_stat(string, "errors=", &qs->tx_errors, 0);
d2805da2
BP
1229 }
1230}
1231
064af421 1232static void
d1e2cf21 1233ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
064af421 1234{
28c8bad1 1235 const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh;
064af421
BP
1236
1237 if (srq->flags) {
1238 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1239 ntohs(srq->flags));
1240 }
064af421
BP
1241}
1242
1243static void
d1e2cf21 1244ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
064af421 1245{
28c8bad1 1246 const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh;
064af421 1247
d1e2cf21 1248 if (srp->flags) {
064af421 1249 uint16_t flags = ntohs(srp->flags);
d1e2cf21
BP
1250
1251 ds_put_cstr(string, " flags=");
064af421
BP
1252 if (flags & OFPSF_REPLY_MORE) {
1253 ds_put_cstr(string, "[more]");
1254 flags &= ~OFPSF_REPLY_MORE;
1255 }
1256 if (flags) {
d1e2cf21
BP
1257 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1258 flags);
064af421
BP
1259 }
1260 }
064af421
BP
1261}
1262
1263static void
d1e2cf21 1264ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
064af421 1265{
d1e2cf21 1266 size_t len = ntohs(oh->length);
064af421 1267
d1e2cf21 1268 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
064af421 1269 if (verbosity > 1) {
d1e2cf21 1270 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
064af421
BP
1271 }
1272}
1273
61fe3a7b
BP
1274static void
1275ofp_print_nxt_role_message(struct ds *string,
1276 const struct nx_role_request *nrr)
1277{
1278 unsigned int role = ntohl(nrr->role);
1279
1280 ds_put_cstr(string, " role=");
1281 if (role == NX_ROLE_OTHER) {
1282 ds_put_cstr(string, "other");
1283 } else if (role == NX_ROLE_MASTER) {
1284 ds_put_cstr(string, "master");
1285 } else if (role == NX_ROLE_SLAVE) {
1286 ds_put_cstr(string, "slave");
1287 } else {
1288 ds_put_format(string, "%u", role);
1289 }
1290}
1291
6c1491fb
BP
1292static void
1293ofp_print_nxt_flow_mod_table_id(struct ds *string,
73dbf4ab 1294 const struct nx_flow_mod_table_id *nfmti)
6c1491fb
BP
1295{
1296 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1297}
1298
7fa91113
BP
1299static void
1300ofp_print_nxt_set_flow_format(struct ds *string,
73dbf4ab 1301 const struct nx_set_flow_format *nsff)
7fa91113
BP
1302{
1303 uint32_t format = ntohl(nsff->format);
1304
1305 ds_put_cstr(string, " format=");
1306 if (ofputil_flow_format_is_valid(format)) {
1307 ds_put_cstr(string, ofputil_flow_format_to_string(format));
1308 } else {
1309 ds_put_format(string, "%"PRIu32, format);
1310 }
1311}
1312
54834960
EJ
1313static void
1314ofp_print_nxt_set_packet_in_format(struct ds *string,
73dbf4ab 1315 const struct nx_set_packet_in_format *nspf)
54834960
EJ
1316{
1317 uint32_t format = ntohl(nspf->format);
1318
1319 ds_put_cstr(string, " format=");
1320 if (ofputil_packet_in_format_is_valid(format)) {
1321 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1322 } else {
1323 ds_put_format(string, "%"PRIu32, format);
1324 }
1325}
1326
80d5aefd
BP
1327static const char *
1328ofp_port_reason_to_string(enum ofp_port_reason reason)
1329{
1330 static char s[32];
1331
1332 switch (reason) {
1333 case OFPPR_ADD:
1334 return "add";
1335
1336 case OFPPR_DELETE:
1337 return "delete";
1338
1339 case OFPPR_MODIFY:
1340 return "modify";
1341
1342 default:
1343 sprintf(s, "%d", (int) reason);
1344 return s;
1345 }
1346}
1347
1348static void
1349ofp_print_nxt_set_async_config(struct ds *string,
1350 const struct nx_async_config *nac)
1351{
1352 int i;
1353
1354 for (i = 0; i < 2; i++) {
1355 int j;
1356
1357 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
1358
1359 ds_put_cstr(string, " PACKET_IN:");
1360 for (j = 0; j < 32; j++) {
1361 if (nac->packet_in_mask[i] & htonl(1u << j)) {
1362 ds_put_format(string, " %s",
1363 ofp_packet_in_reason_to_string(j));
1364 }
1365 }
1366 if (!nac->packet_in_mask[i]) {
1367 ds_put_cstr(string, " (off)");
1368 }
1369 ds_put_char(string, '\n');
1370
1371 ds_put_cstr(string, " PORT_STATUS:");
1372 for (j = 0; j < 32; j++) {
1373 if (nac->port_status_mask[i] & htonl(1u << j)) {
1374 ds_put_format(string, " %s", ofp_port_reason_to_string(j));
1375 }
1376 }
1377 if (!nac->port_status_mask[i]) {
1378 ds_put_cstr(string, " (off)");
1379 }
1380 ds_put_char(string, '\n');
1381
1382 ds_put_cstr(string, " FLOW_REMOVED:");
1383 for (j = 0; j < 32; j++) {
1384 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
1385 ds_put_format(string, " %s",
1386 ofp_flow_removed_reason_to_string(j));
1387 }
1388 }
1389 if (!nac->flow_removed_mask[i]) {
1390 ds_put_cstr(string, " (off)");
1391 }
1392 ds_put_char(string, '\n');
1393 }
1394}
1395
d1e2cf21
BP
1396static void
1397ofp_to_string__(const struct ofp_header *oh,
1398 const struct ofputil_msg_type *type, struct ds *string,
1399 int verbosity)
1400{
7fa91113 1401 enum ofputil_msg_code code;
d1e2cf21
BP
1402 const void *msg = oh;
1403
1404 ds_put_format(string, "%s (xid=0x%"PRIx32"):",
1405 ofputil_msg_type_name(type), ntohl(oh->xid));
1406
7fa91113
BP
1407 code = ofputil_msg_type_code(type);
1408 switch (code) {
8f93e93c 1409 case OFPUTIL_MSG_INVALID:
d1e2cf21
BP
1410 break;
1411
1412 case OFPUTIL_OFPT_HELLO:
dc4762ed
BP
1413 ds_put_char(string, '\n');
1414 ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1415 0, true);
d1e2cf21
BP
1416 break;
1417
1418 case OFPUTIL_OFPT_ERROR:
1419 ofp_print_error_msg(string, msg);
1420 break;
1421
1422 case OFPUTIL_OFPT_ECHO_REQUEST:
1423 case OFPUTIL_OFPT_ECHO_REPLY:
1424 ofp_print_echo(string, oh, verbosity);
1425 break;
1426
1427 case OFPUTIL_OFPT_FEATURES_REQUEST:
1428 break;
1429
1430 case OFPUTIL_OFPT_FEATURES_REPLY:
1431 ofp_print_switch_features(string, msg);
1432 break;
1433
1434 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1435 break;
1436
1437 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1438 case OFPUTIL_OFPT_SET_CONFIG:
1439 ofp_print_switch_config(string, msg);
1440 break;
1441
1442 case OFPUTIL_OFPT_PACKET_IN:
54834960 1443 case OFPUTIL_NXT_PACKET_IN:
d1e2cf21
BP
1444 ofp_print_packet_in(string, msg, verbosity);
1445 break;
1446
1447 case OFPUTIL_OFPT_FLOW_REMOVED:
9b045a0c
BP
1448 case OFPUTIL_NXT_FLOW_REMOVED:
1449 ofp_print_flow_removed(string, msg);
d1e2cf21
BP
1450 break;
1451
1452 case OFPUTIL_OFPT_PORT_STATUS:
1453 ofp_print_port_status(string, msg);
1454 break;
1455
1456 case OFPUTIL_OFPT_PACKET_OUT:
1457 ofp_print_packet_out(string, msg, verbosity);
1458 break;
1459
1460 case OFPUTIL_OFPT_FLOW_MOD:
3370cd3c 1461 case OFPUTIL_NXT_FLOW_MOD:
7fa91113 1462 ofp_print_flow_mod(string, msg, code, verbosity);
d1e2cf21
BP
1463 break;
1464
1465 case OFPUTIL_OFPT_PORT_MOD:
1466 ofp_print_port_mod(string, msg);
1467 break;
1468
1469 case OFPUTIL_OFPT_BARRIER_REQUEST:
1470 case OFPUTIL_OFPT_BARRIER_REPLY:
1471 break;
1472
1473 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1474 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1475 /* XXX */
1476 break;
1477
1478 case OFPUTIL_OFPST_DESC_REQUEST:
1479 ofp_print_stats_request(string, oh);
1480 break;
1481
1482 case OFPUTIL_OFPST_FLOW_REQUEST:
2af0c0ef 1483 case OFPUTIL_NXST_FLOW_REQUEST:
d1e2cf21 1484 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
2af0c0ef 1485 case OFPUTIL_NXST_AGGREGATE_REQUEST:
d1e2cf21 1486 ofp_print_stats_request(string, oh);
76c93b22 1487 ofp_print_flow_stats_request(string, msg);
d1e2cf21
BP
1488 break;
1489
1490 case OFPUTIL_OFPST_TABLE_REQUEST:
1491 ofp_print_stats_request(string, oh);
1492 break;
1493
1494 case OFPUTIL_OFPST_PORT_REQUEST:
1495 ofp_print_stats_request(string, oh);
63f2140a 1496 ofp_print_ofpst_port_request(string, msg);
d1e2cf21
BP
1497 break;
1498
1499 case OFPUTIL_OFPST_QUEUE_REQUEST:
1500 ofp_print_stats_request(string, oh);
63f2140a 1501 ofp_print_ofpst_queue_request(string, msg);
d1e2cf21
BP
1502 break;
1503
1504 case OFPUTIL_OFPST_DESC_REPLY:
1505 ofp_print_stats_reply(string, oh);
63f2140a 1506 ofp_print_ofpst_desc_reply(string, msg);
d1e2cf21
BP
1507 break;
1508
1509 case OFPUTIL_OFPST_FLOW_REPLY:
4ffd1b43 1510 case OFPUTIL_NXST_FLOW_REPLY:
d1e2cf21 1511 ofp_print_stats_reply(string, oh);
4ffd1b43 1512 ofp_print_flow_stats_reply(string, oh);
d1e2cf21
BP
1513 break;
1514
1515 case OFPUTIL_OFPST_QUEUE_REPLY:
1516 ofp_print_stats_reply(string, oh);
1517 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1518 break;
1519
1520 case OFPUTIL_OFPST_PORT_REPLY:
1521 ofp_print_stats_reply(string, oh);
1522 ofp_print_ofpst_port_reply(string, oh, verbosity);
1523 break;
1524
1525 case OFPUTIL_OFPST_TABLE_REPLY:
1526 ofp_print_stats_reply(string, oh);
1527 ofp_print_ofpst_table_reply(string, oh, verbosity);
1528 break;
1529
1530 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1531 ofp_print_stats_reply(string, oh);
63f2140a 1532 ofp_print_ofpst_aggregate_reply(string, msg);
d1e2cf21 1533 break;
064af421 1534
d1e2cf21
BP
1535 case OFPUTIL_NXT_ROLE_REQUEST:
1536 case OFPUTIL_NXT_ROLE_REPLY:
61fe3a7b 1537 ofp_print_nxt_role_message(string, msg);
7fa91113
BP
1538 break;
1539
6c1491fb
BP
1540 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID:
1541 ofp_print_nxt_flow_mod_table_id(string, msg);
1542 break;
1543
d1e2cf21 1544 case OFPUTIL_NXT_SET_FLOW_FORMAT:
7fa91113
BP
1545 ofp_print_nxt_set_flow_format(string, msg);
1546 break;
1547
54834960
EJ
1548 case OFPUTIL_NXT_SET_PACKET_IN_FORMAT:
1549 ofp_print_nxt_set_packet_in_format(string, msg);
1550 break;
1551
f27f2134
BP
1552 case OFPUTIL_NXT_FLOW_AGE:
1553 break;
1554
80d5aefd
BP
1555 case OFPUTIL_NXT_SET_ASYNC_CONFIG:
1556 ofp_print_nxt_set_async_config(string, msg);
1557 break;
1558
d1e2cf21 1559 case OFPUTIL_NXST_AGGREGATE_REPLY:
a2ad9ecd 1560 ofp_print_stats_reply(string, oh);
9b045a0c 1561 ofp_print_nxst_aggregate_reply(string, msg);
d1e2cf21 1562 break;
246e61ea 1563 }
d1e2cf21 1564}
064af421
BP
1565
1566/* Composes and returns a string representing the OpenFlow packet of 'len'
1567 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1568 * verbosity and higher numbers increase verbosity. The caller is responsible
1569 * for freeing the string. */
1570char *
1571ofp_to_string(const void *oh_, size_t len, int verbosity)
1572{
1573 struct ds string = DS_EMPTY_INITIALIZER;
1574 const struct ofp_header *oh = oh_;
064af421 1575
49ad0403
BP
1576 if (!len) {
1577 ds_put_cstr(&string, "OpenFlow message is empty\n");
1578 } else if (len < sizeof(struct ofp_header)) {
1579 ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1580 len);
d1e2cf21
BP
1581 } else if (ntohs(oh->length) > len) {
1582 ds_put_format(&string,
49ad0403 1583 "(***truncated to %zu bytes from %"PRIu16"***)\n",
d1e2cf21
BP
1584 len, ntohs(oh->length));
1585 } else if (ntohs(oh->length) < len) {
1586 ds_put_format(&string,
1587 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1588 ntohs(oh->length), len);
1589 } else {
1590 const struct ofputil_msg_type *type;
90bf1e07 1591 enum ofperr error;
d1e2cf21
BP
1592
1593 error = ofputil_decode_msg_type(oh, &type);
1594 if (!error) {
1595 ofp_to_string__(oh, type, &string, verbosity);
7fa91113
BP
1596 if (verbosity >= 5) {
1597 if (ds_last(&string) != '\n') {
1598 ds_put_char(&string, '\n');
1599 }
d1e2cf21
BP
1600 ds_put_hex_dump(&string, oh, len, 0, true);
1601 }
7fa91113 1602 if (ds_last(&string) != '\n') {
d1e2cf21
BP
1603 ds_put_char(&string, '\n');
1604 }
1605 return ds_steal_cstr(&string);
064af421 1606 }
064af421 1607
7fa91113 1608 ofp_print_error(&string, error);
064af421 1609 }
d1e2cf21
BP
1610 ds_put_hex_dump(&string, oh, len, 0, true);
1611 return ds_steal_cstr(&string);
064af421
BP
1612}
1613
1614/* Returns the name for the specified OpenFlow message type as a string,
1615 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1616 * hex number, e.g. "0x55".
1617 *
1618 * The caller must free the returned string when it is no longer needed. */
1619char *
1620ofp_message_type_to_string(uint8_t type)
1621{
d1e2cf21 1622 const char *name;
064af421 1623
d1e2cf21
BP
1624 switch (type) {
1625 case OFPT_HELLO:
1626 name = "HELLO";
1627 break;
1628 case OFPT_ERROR:
1629 name = "ERROR";
1630 break;
1631 case OFPT_ECHO_REQUEST:
1632 name = "ECHO_REQUEST";
1633 break;
1634 case OFPT_ECHO_REPLY:
1635 name = "ECHO_REPLY";
1636 break;
1637 case OFPT_VENDOR:
1638 name = "VENDOR";
1639 break;
1640 case OFPT_FEATURES_REQUEST:
1641 name = "FEATURES_REQUEST";
1642 break;
1643 case OFPT_FEATURES_REPLY:
1644 name = "FEATURES_REPLY";
1645 break;
1646 case OFPT_GET_CONFIG_REQUEST:
1647 name = "GET_CONFIG_REQUEST";
1648 break;
1649 case OFPT_GET_CONFIG_REPLY:
1650 name = "GET_CONFIG_REPLY";
1651 break;
1652 case OFPT_SET_CONFIG:
1653 name = "SET_CONFIG";
1654 break;
1655 case OFPT_PACKET_IN:
1656 name = "PACKET_IN";
1657 break;
1658 case OFPT_FLOW_REMOVED:
1659 name = "FLOW_REMOVED";
1660 break;
1661 case OFPT_PORT_STATUS:
1662 name = "PORT_STATUS";
1663 break;
1664 case OFPT_PACKET_OUT:
1665 name = "PACKET_OUT";
1666 break;
1667 case OFPT_FLOW_MOD:
1668 name = "FLOW_MOD";
1669 break;
1670 case OFPT_PORT_MOD:
1671 name = "PORT_MOD";
1672 break;
1673 case OFPT_STATS_REQUEST:
1674 name = "STATS_REQUEST";
1675 break;
1676 case OFPT_STATS_REPLY:
1677 name = "STATS_REPLY";
1678 break;
1679 case OFPT_BARRIER_REQUEST:
1680 name = "BARRIER_REQUEST";
1681 break;
1682 case OFPT_BARRIER_REPLY:
1683 name = "BARRIER_REPLY";
1684 break;
1685 case OFPT_QUEUE_GET_CONFIG_REQUEST:
1686 name = "QUEUE_GET_CONFIG_REQUEST";
1687 break;
1688 case OFPT_QUEUE_GET_CONFIG_REPLY:
1689 name = "QUEUE_GET_CONFIG_REPLY";
1690 break;
1691 default:
1692 name = NULL;
1693 break;
064af421 1694 }
d1e2cf21
BP
1695
1696 return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
064af421
BP
1697}
1698\f
1699static void
d295e8e9 1700print_and_free(FILE *stream, char *string)
064af421
BP
1701{
1702 fputs(string, stream);
1703 free(string);
1704}
1705
1706/* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1707 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1708 * numbers increase verbosity. */
1709void
1710ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1711{
1712 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1713}
1714
1715/* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
897a8e07 1716 * 'data' to 'stream'. */
064af421 1717void
c499c75d 1718ofp_print_packet(FILE *stream, const void *data, size_t len)
064af421 1719{
c499c75d 1720 print_and_free(stream, ofp_packet_to_string(data, len));
064af421 1721}