ofp-print: Enable display of Open Flow 1.1 & 1.2 Table Stats Reply Messages
[sliver-openvswitch.git] / lib / ofp-print.c
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
3  *
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:
7  *
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.
15  */
16
17 #include <config.h>
18 #include "ofp-print.h"
19
20 #include <errno.h>
21 #include <inttypes.h>
22 #include <sys/types.h>
23 #include <netinet/in.h>
24 #include <sys/wait.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <ctype.h>
28
29 #include "bundle.h"
30 #include "byte-order.h"
31 #include "compiler.h"
32 #include "dynamic-string.h"
33 #include "flow.h"
34 #include "learn.h"
35 #include "multipath.h"
36 #include "meta-flow.h"
37 #include "netdev.h"
38 #include "nx-match.h"
39 #include "ofp-actions.h"
40 #include "ofp-errors.h"
41 #include "ofp-msgs.h"
42 #include "ofp-util.h"
43 #include "ofpbuf.h"
44 #include "openflow/openflow.h"
45 #include "openflow/nicira-ext.h"
46 #include "packets.h"
47 #include "pcap.h"
48 #include "type-props.h"
49 #include "unaligned.h"
50 #include "util.h"
51
52 static void ofp_print_queue_name(struct ds *string, uint32_t port);
53 static void ofp_print_error(struct ds *, enum ofperr);
54
55
56 /* Returns a string that represents the contents of the Ethernet frame in the
57  * 'len' bytes starting at 'data'.  The caller must free the returned string.*/
58 char *
59 ofp_packet_to_string(const void *data, size_t len)
60 {
61     struct ds ds = DS_EMPTY_INITIALIZER;
62     struct ofpbuf buf;
63     struct flow flow;
64
65     ofpbuf_use_const(&buf, data, len);
66     flow_extract(&buf, 0, 0, 0, &flow);
67     flow_format(&ds, &flow);
68
69     if (buf.l7) {
70         if (flow.nw_proto == IPPROTO_TCP) {
71             struct tcp_header *th = buf.l4;
72             ds_put_format(&ds, " tcp_csum:%"PRIx16,
73                           ntohs(th->tcp_csum));
74         } else if (flow.nw_proto == IPPROTO_UDP) {
75             struct udp_header *uh = buf.l4;
76             ds_put_format(&ds, " udp_csum:%"PRIx16,
77                           ntohs(uh->udp_csum));
78         }
79     }
80
81     ds_put_char(&ds, '\n');
82
83     return ds_cstr(&ds);
84 }
85
86 static void
87 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
88                     int verbosity)
89 {
90     struct ofputil_packet_in pin;
91     int error;
92     int i;
93
94     error = ofputil_decode_packet_in(&pin, oh);
95     if (error) {
96         ofp_print_error(string, error);
97         return;
98     }
99
100     if (pin.table_id) {
101         ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
102     }
103
104     if (pin.cookie) {
105         ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
106     }
107
108     ds_put_format(string, " total_len=%"PRIu16" in_port=", pin.total_len);
109     ofputil_format_port(pin.fmd.in_port, string);
110
111     if (pin.fmd.tun_id_mask) {
112         ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
113         if (pin.fmd.tun_id_mask != htonll(UINT64_MAX)) {
114             ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.tun_id_mask));
115         }
116     }
117
118     if (pin.fmd.metadata_mask) {
119         ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata));
120         if (pin.fmd.metadata_mask != htonll(UINT64_MAX)) {
121             ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.metadata_mask));
122         }
123     }
124
125     for (i = 0; i < FLOW_N_REGS; i++) {
126         if (pin.fmd.reg_masks[i]) {
127             ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
128             if (pin.fmd.reg_masks[i] != UINT32_MAX) {
129                 ds_put_format(string, "/0x%"PRIx32, pin.fmd.reg_masks[i]);
130             }
131         }
132     }
133
134     ds_put_format(string, " (via %s)",
135                   ofputil_packet_in_reason_to_string(pin.reason));
136
137     ds_put_format(string, " data_len=%zu", pin.packet_len);
138     if (pin.buffer_id == UINT32_MAX) {
139         ds_put_format(string, " (unbuffered)");
140         if (pin.total_len != pin.packet_len) {
141             ds_put_format(string, " (***total_len != data_len***)");
142         }
143     } else {
144         ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
145         if (pin.total_len < pin.packet_len) {
146             ds_put_format(string, " (***total_len < data_len***)");
147         }
148     }
149     ds_put_char(string, '\n');
150
151     if (verbosity > 0) {
152         char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
153         ds_put_cstr(string, packet);
154         free(packet);
155     }
156 }
157
158 static void
159 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
160                      int verbosity)
161 {
162     struct ofputil_packet_out po;
163     struct ofpbuf ofpacts;
164     enum ofperr error;
165
166     ofpbuf_init(&ofpacts, 64);
167     error = ofputil_decode_packet_out(&po, oh, &ofpacts);
168     if (error) {
169         ofpbuf_uninit(&ofpacts);
170         ofp_print_error(string, error);
171         return;
172     }
173
174     ds_put_cstr(string, " in_port=");
175     ofputil_format_port(po.in_port, string);
176
177     ds_put_char(string, ' ');
178     ofpacts_format(po.ofpacts, po.ofpacts_len, string);
179
180     if (po.buffer_id == UINT32_MAX) {
181         ds_put_format(string, " data_len=%zu", po.packet_len);
182         if (verbosity > 0 && po.packet_len > 0) {
183             char *packet = ofp_packet_to_string(po.packet, po.packet_len);
184             ds_put_char(string, '\n');
185             ds_put_cstr(string, packet);
186             free(packet);
187         }
188     } else {
189         ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
190     }
191     ds_put_char(string, '\n');
192
193     ofpbuf_uninit(&ofpacts);
194 }
195
196 /* qsort comparison function. */
197 static int
198 compare_ports(const void *a_, const void *b_)
199 {
200     const struct ofputil_phy_port *a = a_;
201     const struct ofputil_phy_port *b = b_;
202     uint16_t ap = a->port_no;
203     uint16_t bp = b->port_no;
204
205     return ap < bp ? -1 : ap > bp;
206 }
207
208 static void
209 ofp_print_bit_names(struct ds *string, uint32_t bits,
210                     const char *(*bit_to_name)(uint32_t bit),
211                     char separator)
212 {
213     int n = 0;
214     int i;
215
216     if (!bits) {
217         ds_put_cstr(string, "0");
218         return;
219     }
220
221     for (i = 0; i < 32; i++) {
222         uint32_t bit = UINT32_C(1) << i;
223
224         if (bits & bit) {
225             const char *name = bit_to_name(bit);
226             if (name) {
227                 if (n++) {
228                     ds_put_char(string, separator);
229                 }
230                 ds_put_cstr(string, name);
231                 bits &= ~bit;
232             }
233         }
234     }
235
236     if (bits) {
237         if (n) {
238             ds_put_char(string, separator);
239         }
240         ds_put_format(string, "0x%"PRIx32, bits);
241     }
242 }
243
244 static const char *
245 netdev_feature_to_name(uint32_t bit)
246 {
247     enum netdev_features f = bit;
248
249     switch (f) {
250     case NETDEV_F_10MB_HD:    return "10MB-HD";
251     case NETDEV_F_10MB_FD:    return "10MB-FD";
252     case NETDEV_F_100MB_HD:   return "100MB-HD";
253     case NETDEV_F_100MB_FD:   return "100MB-FD";
254     case NETDEV_F_1GB_HD:     return "1GB-HD";
255     case NETDEV_F_1GB_FD:     return "1GB-FD";
256     case NETDEV_F_10GB_FD:    return "10GB-FD";
257     case NETDEV_F_40GB_FD:    return "40GB-FD";
258     case NETDEV_F_100GB_FD:   return "100GB-FD";
259     case NETDEV_F_1TB_FD:     return "1TB-FD";
260     case NETDEV_F_OTHER:      return "OTHER";
261     case NETDEV_F_COPPER:     return "COPPER";
262     case NETDEV_F_FIBER:      return "FIBER";
263     case NETDEV_F_AUTONEG:    return "AUTO_NEG";
264     case NETDEV_F_PAUSE:      return "AUTO_PAUSE";
265     case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
266     }
267
268     return NULL;
269 }
270
271 static void
272 ofp_print_port_features(struct ds *string, enum netdev_features features)
273 {
274     ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
275     ds_put_char(string, '\n');
276 }
277
278 static const char *
279 ofputil_port_config_to_name(uint32_t bit)
280 {
281     enum ofputil_port_config pc = bit;
282
283     switch (pc) {
284     case OFPUTIL_PC_PORT_DOWN:    return "PORT_DOWN";
285     case OFPUTIL_PC_NO_STP:       return "NO_STP";
286     case OFPUTIL_PC_NO_RECV:      return "NO_RECV";
287     case OFPUTIL_PC_NO_RECV_STP:  return "NO_RECV_STP";
288     case OFPUTIL_PC_NO_FLOOD:     return "NO_FLOOD";
289     case OFPUTIL_PC_NO_FWD:       return "NO_FWD";
290     case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
291     }
292
293     return NULL;
294 }
295
296 static void
297 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
298 {
299     ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
300     ds_put_char(string, '\n');
301 }
302
303 static const char *
304 ofputil_port_state_to_name(uint32_t bit)
305 {
306     enum ofputil_port_state ps = bit;
307
308     switch (ps) {
309     case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
310     case OFPUTIL_PS_BLOCKED:   return "BLOCKED";
311     case OFPUTIL_PS_LIVE:      return "LIVE";
312
313     case OFPUTIL_PS_STP_LISTEN:
314     case OFPUTIL_PS_STP_LEARN:
315     case OFPUTIL_PS_STP_FORWARD:
316     case OFPUTIL_PS_STP_BLOCK:
317         /* Handled elsewhere. */
318         return NULL;
319     }
320
321     return NULL;
322 }
323
324 static void
325 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
326 {
327     enum ofputil_port_state stp_state;
328
329     /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
330      * pattern.  We have to special case it.
331      *
332      * OVS doesn't support STP, so this field will always be 0 if we are
333      * talking to OVS, so we'd always print STP_LISTEN in that case.
334      * Therefore, we don't print anything at all if the value is STP_LISTEN, to
335      * avoid confusing users. */
336     stp_state = state & OFPUTIL_PS_STP_MASK;
337     if (stp_state) {
338         ds_put_cstr(string,
339                     (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
340                      : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
341                      : "STP_BLOCK"));
342         state &= ~OFPUTIL_PS_STP_MASK;
343         if (state) {
344             ofp_print_bit_names(string, state, ofputil_port_state_to_name,
345                                 ' ');
346         }
347     } else {
348         ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
349     }
350     ds_put_char(string, '\n');
351 }
352
353 static void
354 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
355 {
356     char name[sizeof port->name];
357     int j;
358
359     memcpy(name, port->name, sizeof name);
360     for (j = 0; j < sizeof name - 1; j++) {
361         if (!isprint((unsigned char) name[j])) {
362             break;
363         }
364     }
365     name[j] = '\0';
366
367     ds_put_char(string, ' ');
368     ofputil_format_port(port->port_no, string);
369     ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
370                   name, ETH_ADDR_ARGS(port->hw_addr));
371
372     ds_put_cstr(string, "     config:     ");
373     ofp_print_port_config(string, port->config);
374
375     ds_put_cstr(string, "     state:      ");
376     ofp_print_port_state(string, port->state);
377
378     if (port->curr) {
379         ds_put_format(string, "     current:    ");
380         ofp_print_port_features(string, port->curr);
381     }
382     if (port->advertised) {
383         ds_put_format(string, "     advertised: ");
384         ofp_print_port_features(string, port->advertised);
385     }
386     if (port->supported) {
387         ds_put_format(string, "     supported:  ");
388         ofp_print_port_features(string, port->supported);
389     }
390     if (port->peer) {
391         ds_put_format(string, "     peer:       ");
392         ofp_print_port_features(string, port->peer);
393     }
394     ds_put_format(string, "     speed: %"PRIu32" Mbps now, "
395                   "%"PRIu32" Mbps max\n",
396                   port->curr_speed / UINT32_C(1000),
397                   port->max_speed / UINT32_C(1000));
398 }
399
400 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
401  * 'ofp_version', writes a detailed description of each port into
402  * 'string'. */
403 static void
404 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
405                     struct ofpbuf *b)
406 {
407     size_t n_ports;
408     struct ofputil_phy_port *ports;
409     enum ofperr error;
410     size_t i;
411
412     n_ports = ofputil_count_phy_ports(ofp_version, b);
413
414     ports = xmalloc(n_ports * sizeof *ports);
415     for (i = 0; i < n_ports; i++) {
416         error = ofputil_pull_phy_port(ofp_version, b, &ports[i]);
417         if (error) {
418             ofp_print_error(string, error);
419             goto exit;
420         }
421     }
422     qsort(ports, n_ports, sizeof *ports, compare_ports);
423     for (i = 0; i < n_ports; i++) {
424         ofp_print_phy_port(string, &ports[i]);
425     }
426
427 exit:
428     free(ports);
429 }
430
431 static const char *
432 ofputil_capabilities_to_name(uint32_t bit)
433 {
434     enum ofputil_capabilities capabilities = bit;
435
436     switch (capabilities) {
437     case OFPUTIL_C_FLOW_STATS:   return "FLOW_STATS";
438     case OFPUTIL_C_TABLE_STATS:  return "TABLE_STATS";
439     case OFPUTIL_C_PORT_STATS:   return "PORT_STATS";
440     case OFPUTIL_C_IP_REASM:     return "IP_REASM";
441     case OFPUTIL_C_QUEUE_STATS:  return "QUEUE_STATS";
442     case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
443     case OFPUTIL_C_STP:          return "STP";
444     case OFPUTIL_C_GROUP_STATS:  return "GROUP_STATS";
445     case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
446     }
447
448     return NULL;
449 }
450
451 static const char *
452 ofputil_action_bitmap_to_name(uint32_t bit)
453 {
454     enum ofputil_action_bitmap action = bit;
455
456     switch (action) {
457     case OFPUTIL_A_OUTPUT:         return "OUTPUT";
458     case OFPUTIL_A_SET_VLAN_VID:   return "SET_VLAN_VID";
459     case OFPUTIL_A_SET_VLAN_PCP:   return "SET_VLAN_PCP";
460     case OFPUTIL_A_STRIP_VLAN:     return "STRIP_VLAN";
461     case OFPUTIL_A_SET_DL_SRC:     return "SET_DL_SRC";
462     case OFPUTIL_A_SET_DL_DST:     return "SET_DL_DST";
463     case OFPUTIL_A_SET_NW_SRC:     return "SET_NW_SRC";
464     case OFPUTIL_A_SET_NW_DST:     return "SET_NW_DST";
465     case OFPUTIL_A_SET_NW_ECN:     return "SET_NW_ECN";
466     case OFPUTIL_A_SET_NW_TOS:     return "SET_NW_TOS";
467     case OFPUTIL_A_SET_TP_SRC:     return "SET_TP_SRC";
468     case OFPUTIL_A_SET_TP_DST:     return "SET_TP_DST";
469     case OFPUTIL_A_ENQUEUE:        return "ENQUEUE";
470     case OFPUTIL_A_COPY_TTL_OUT:   return "COPY_TTL_OUT";
471     case OFPUTIL_A_COPY_TTL_IN:    return "COPY_TTL_IN";
472     case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL";
473     case OFPUTIL_A_SET_MPLS_TC:    return "SET_MPLS_TC";
474     case OFPUTIL_A_SET_MPLS_TTL:   return "SET_MPLS_TTL";
475     case OFPUTIL_A_DEC_MPLS_TTL:   return "DEC_MPLS_TTL";
476     case OFPUTIL_A_PUSH_VLAN:      return "PUSH_VLAN";
477     case OFPUTIL_A_POP_VLAN:       return "POP_VLAN";
478     case OFPUTIL_A_PUSH_MPLS:      return "PUSH_MPLS";
479     case OFPUTIL_A_POP_MPLS:       return "POP_MPLS";
480     case OFPUTIL_A_SET_QUEUE:      return "SET_QUEUE";
481     case OFPUTIL_A_GROUP:          return "GROUP";
482     case OFPUTIL_A_SET_NW_TTL:     return "SET_NW_TTL";
483     case OFPUTIL_A_DEC_NW_TTL:     return "DEC_NW_TTL";
484     }
485
486     return NULL;
487 }
488
489 static void
490 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
491 {
492     struct ofputil_switch_features features;
493     enum ofperr error;
494     struct ofpbuf b;
495
496     error = ofputil_decode_switch_features(oh, &features, &b);
497     if (error) {
498         ofp_print_error(string, error);
499         return;
500     }
501
502     ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
503     ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32"\n",
504                   features.n_tables, features.n_buffers);
505
506     ds_put_cstr(string, "capabilities: ");
507     ofp_print_bit_names(string, features.capabilities,
508                         ofputil_capabilities_to_name, ' ');
509     ds_put_char(string, '\n');
510
511     switch ((enum ofp_version)oh->version) {
512     case OFP10_VERSION:
513         ds_put_cstr(string, "actions: ");
514         ofp_print_bit_names(string, features.actions,
515                             ofputil_action_bitmap_to_name, ' ');
516         ds_put_char(string, '\n');
517         break;
518     case OFP11_VERSION:
519     case OFP12_VERSION:
520         break;
521     default:
522         NOT_REACHED();
523     }
524
525     ofp_print_phy_ports(string, oh->version, &b);
526 }
527
528 static void
529 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
530 {
531     enum ofp_config_flags flags;
532
533     flags = ntohs(osc->flags);
534
535     ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
536     flags &= ~OFPC_FRAG_MASK;
537
538     if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
539         ds_put_format(string, " invalid_ttl_to_controller");
540         flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
541     }
542
543     if (flags) {
544         ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
545     }
546
547     ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
548 }
549
550 static void print_wild(struct ds *string, const char *leader, int is_wild,
551             int verbosity, const char *format, ...)
552             __attribute__((format(printf, 5, 6)));
553
554 static void print_wild(struct ds *string, const char *leader, int is_wild,
555                        int verbosity, const char *format, ...)
556 {
557     if (is_wild && verbosity < 2) {
558         return;
559     }
560     ds_put_cstr(string, leader);
561     if (!is_wild) {
562         va_list args;
563
564         va_start(args, format);
565         ds_put_format_valist(string, format, args);
566         va_end(args);
567     } else {
568         ds_put_char(string, '*');
569     }
570     ds_put_char(string, ',');
571 }
572
573 static void
574 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
575                  uint32_t wild_bits, int verbosity)
576 {
577     if (wild_bits >= 32 && verbosity < 2) {
578         return;
579     }
580     ds_put_cstr(string, leader);
581     if (wild_bits < 32) {
582         ds_put_format(string, IP_FMT, IP_ARGS(&ip));
583         if (wild_bits) {
584             ds_put_format(string, "/%d", 32 - wild_bits);
585         }
586     } else {
587         ds_put_char(string, '*');
588     }
589     ds_put_char(string, ',');
590 }
591
592 void
593 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
594 {
595     char *s = ofp10_match_to_string(om, verbosity);
596     ds_put_cstr(f, s);
597     free(s);
598 }
599
600 char *
601 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
602 {
603     struct ds f = DS_EMPTY_INITIALIZER;
604     uint32_t w = ntohl(om->wildcards);
605     bool skip_type = false;
606     bool skip_proto = false;
607
608     if (!(w & OFPFW10_DL_TYPE)) {
609         skip_type = true;
610         if (om->dl_type == htons(ETH_TYPE_IP)) {
611             if (!(w & OFPFW10_NW_PROTO)) {
612                 skip_proto = true;
613                 if (om->nw_proto == IPPROTO_ICMP) {
614                     ds_put_cstr(&f, "icmp,");
615                 } else if (om->nw_proto == IPPROTO_TCP) {
616                     ds_put_cstr(&f, "tcp,");
617                 } else if (om->nw_proto == IPPROTO_UDP) {
618                     ds_put_cstr(&f, "udp,");
619                 } else {
620                     ds_put_cstr(&f, "ip,");
621                     skip_proto = false;
622                 }
623             } else {
624                 ds_put_cstr(&f, "ip,");
625             }
626         } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
627             ds_put_cstr(&f, "arp,");
628         } else {
629             skip_type = false;
630         }
631     }
632     print_wild(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
633                "%d", ntohs(om->in_port));
634     print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
635                "%d", ntohs(om->dl_vlan));
636     print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
637                "%d", om->dl_vlan_pcp);
638     print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
639                ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
640     print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
641                ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
642     if (!skip_type) {
643         print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
644                    "0x%04x", ntohs(om->dl_type));
645     }
646     print_ip_netmask(&f, "nw_src=", om->nw_src,
647                      (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
648                      verbosity);
649     print_ip_netmask(&f, "nw_dst=", om->nw_dst,
650                      (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
651                      verbosity);
652     if (!skip_proto) {
653         if (om->dl_type == htons(ETH_TYPE_ARP)) {
654             print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
655                        "%u", om->nw_proto);
656         } else {
657             print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
658                        "%u", om->nw_proto);
659         }
660     }
661     print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
662                "%u", om->nw_tos);
663     if (om->nw_proto == IPPROTO_ICMP) {
664         print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
665                    "%d", ntohs(om->tp_src));
666         print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
667                    "%d", ntohs(om->tp_dst));
668     } else {
669         print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
670                    "%d", ntohs(om->tp_src));
671         print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
672                    "%d", ntohs(om->tp_dst));
673     }
674     if (ds_last(&f) == ',') {
675         f.length--;
676     }
677     return ds_cstr(&f);
678 }
679
680 static void
681 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
682 {
683     struct ofputil_flow_mod fm;
684     struct ofpbuf ofpacts;
685     bool need_priority;
686     enum ofperr error;
687     enum ofpraw raw;
688     enum ofputil_protocol protocol;
689
690     protocol = ofputil_protocol_from_ofp_version(oh->version);
691     protocol = ofputil_protocol_set_tid(protocol, true);
692
693     ofpbuf_init(&ofpacts, 64);
694     error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts);
695     if (error) {
696         ofpbuf_uninit(&ofpacts);
697         ofp_print_error(s, error);
698         return;
699     }
700
701     ds_put_char(s, ' ');
702     switch (fm.command) {
703     case OFPFC_ADD:
704         ds_put_cstr(s, "ADD");
705         break;
706     case OFPFC_MODIFY:
707         ds_put_cstr(s, "MOD");
708         break;
709     case OFPFC_MODIFY_STRICT:
710         ds_put_cstr(s, "MOD_STRICT");
711         break;
712     case OFPFC_DELETE:
713         ds_put_cstr(s, "DEL");
714         break;
715     case OFPFC_DELETE_STRICT:
716         ds_put_cstr(s, "DEL_STRICT");
717         break;
718     default:
719         ds_put_format(s, "cmd:%d", fm.command);
720     }
721     if (fm.table_id != 0) {
722         ds_put_format(s, " table:%d", fm.table_id);
723     }
724
725     ds_put_char(s, ' ');
726     ofpraw_decode(&raw, oh);
727     if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
728         const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
729         ofp10_match_print(s, &ofm->match, verbosity);
730
731         /* ofp_print_match() doesn't print priority. */
732         need_priority = true;
733     } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
734         const struct nx_flow_mod *nfm = ofpmsg_body(oh);
735         const void *nxm = nfm + 1;
736         char *nxm_s;
737
738         nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
739         ds_put_cstr(s, nxm_s);
740         free(nxm_s);
741
742         /* nx_match_to_string() doesn't print priority. */
743         need_priority = true;
744     } else {
745         cls_rule_format(&fm.cr, s);
746
747         /* cls_rule_format() does print priority. */
748         need_priority = false;
749     }
750
751     if (ds_last(s) != ' ') {
752         ds_put_char(s, ' ');
753     }
754     if (fm.new_cookie != htonll(0)) {
755         ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
756     }
757     if (fm.cookie_mask != htonll(0)) {
758         ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
759                 ntohll(fm.cookie), ntohll(fm.cookie_mask));
760     }
761     if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
762         ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
763     }
764     if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
765         ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
766     }
767     if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
768         ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
769     }
770     if (fm.buffer_id != UINT32_MAX) {
771         ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
772     }
773     if (fm.out_port != OFPP_NONE) {
774         ds_put_format(s, "out_port:");
775         ofputil_format_port(fm.out_port, s);
776         ds_put_char(s, ' ');
777     }
778     if (fm.flags != 0) {
779         uint16_t flags = fm.flags;
780
781         if (flags & OFPFF_SEND_FLOW_REM) {
782             ds_put_cstr(s, "send_flow_rem ");
783         }
784         if (flags & OFPFF_CHECK_OVERLAP) {
785             ds_put_cstr(s, "check_overlap ");
786         }
787         if (flags & OFPFF10_EMERG) {
788             ds_put_cstr(s, "emerg ");
789         }
790
791         flags &= ~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF10_EMERG);
792         if (flags) {
793             ds_put_format(s, "flags:0x%"PRIx16" ", flags);
794         }
795     }
796
797     ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
798     ofpbuf_uninit(&ofpacts);
799 }
800
801 static void
802 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
803 {
804     ds_put_format(string, "%u", sec);
805     if (nsec > 0) {
806         ds_put_format(string, ".%09u", nsec);
807         while (string->string[string->length - 1] == '0') {
808             string->length--;
809         }
810     }
811     ds_put_char(string, 's');
812 }
813
814 static const char *
815 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason)
816 {
817     static char s[32];
818
819     switch (reason) {
820     case OFPRR_IDLE_TIMEOUT:
821         return "idle";
822     case OFPRR_HARD_TIMEOUT:
823         return "hard";
824     case OFPRR_DELETE:
825         return "delete";
826     case OFPRR_GROUP_DELETE:
827         return "group_delete";
828     case OFPRR_EVICTION:
829         return "eviction";
830     default:
831         sprintf(s, "%d", (int) reason);
832         return s;
833     }
834 }
835
836 static void
837 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
838 {
839     struct ofputil_flow_removed fr;
840     enum ofperr error;
841
842     error = ofputil_decode_flow_removed(&fr, oh);
843     if (error) {
844         ofp_print_error(string, error);
845         return;
846     }
847
848     ds_put_char(string, ' ');
849     cls_rule_format(&fr.rule, string);
850
851     ds_put_format(string, " reason=%s",
852                   ofp_flow_removed_reason_to_string(fr.reason));
853
854     if (fr.cookie != htonll(0)) {
855         ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
856     }
857     ds_put_cstr(string, " duration");
858     ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
859     ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
860     if (fr.hard_timeout) {
861         /* The hard timeout was only added in OF1.2, so only print it if it is
862          * actually in use to avoid gratuitous change to the formatting. */
863         ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
864     }
865     ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
866                   fr.packet_count, fr.byte_count);
867 }
868
869 static void
870 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
871 {
872     struct ofputil_port_mod pm;
873     enum ofperr error;
874
875     error = ofputil_decode_port_mod(oh, &pm);
876     if (error) {
877         ofp_print_error(string, error);
878         return;
879     }
880
881     ds_put_format(string, "port: %"PRIu16": addr:"ETH_ADDR_FMT"\n",
882                   pm.port_no, ETH_ADDR_ARGS(pm.hw_addr));
883
884     ds_put_format(string, "     config: ");
885     ofp_print_port_config(string, pm.config);
886
887     ds_put_format(string, "     mask:   ");
888     ofp_print_port_config(string, pm.mask);
889
890     ds_put_format(string, "     advertise: ");
891     if (pm.advertise) {
892         ofp_print_port_features(string, pm.advertise);
893     } else {
894         ds_put_format(string, "UNCHANGED\n");
895     }
896 }
897
898 static void
899 ofp_print_error(struct ds *string, enum ofperr error)
900 {
901     if (string->length) {
902         ds_put_char(string, ' ');
903     }
904     ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
905 }
906
907 static void
908 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
909 {
910     size_t len = ntohs(oh->length);
911     struct ofpbuf payload;
912     enum ofperr error;
913     char *s;
914
915     error = ofperr_decode_msg(oh, &payload);
916     if (!error) {
917         ds_put_cstr(string, "***decode error***");
918         ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
919         return;
920     }
921
922     ds_put_format(string, " %s\n", ofperr_get_name(error));
923
924     if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
925         ds_put_printable(string, payload.data, payload.size);
926     } else {
927         s = ofp_to_string(payload.data, payload.size, 1);
928         ds_put_cstr(string, s);
929         free(s);
930     }
931 }
932
933 static void
934 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
935 {
936     struct ofputil_port_status ps;
937     enum ofperr error;
938
939     error = ofputil_decode_port_status(oh, &ps);
940     if (error) {
941         ofp_print_error(string, error);
942         return;
943     }
944
945     if (ps.reason == OFPPR_ADD) {
946         ds_put_format(string, " ADD:");
947     } else if (ps.reason == OFPPR_DELETE) {
948         ds_put_format(string, " DEL:");
949     } else if (ps.reason == OFPPR_MODIFY) {
950         ds_put_format(string, " MOD:");
951     }
952
953     ofp_print_phy_port(string, &ps.desc);
954 }
955
956 static void
957 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
958 {
959     const struct ofp_desc_stats *ods = ofpmsg_body(oh);
960
961     ds_put_char(string, '\n');
962     ds_put_format(string, "Manufacturer: %.*s\n",
963             (int) sizeof ods->mfr_desc, ods->mfr_desc);
964     ds_put_format(string, "Hardware: %.*s\n",
965             (int) sizeof ods->hw_desc, ods->hw_desc);
966     ds_put_format(string, "Software: %.*s\n",
967             (int) sizeof ods->sw_desc, ods->sw_desc);
968     ds_put_format(string, "Serial Num: %.*s\n",
969             (int) sizeof ods->serial_num, ods->serial_num);
970     ds_put_format(string, "DP Description: %.*s\n",
971             (int) sizeof ods->dp_desc, ods->dp_desc);
972 }
973
974 static void
975 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
976 {
977     struct ofputil_flow_stats_request fsr;
978     enum ofperr error;
979
980     error = ofputil_decode_flow_stats_request(&fsr, oh);
981     if (error) {
982         ofp_print_error(string, error);
983         return;
984     }
985
986     if (fsr.table_id != 0xff) {
987         ds_put_format(string, " table=%"PRIu8, fsr.table_id);
988     }
989
990     if (fsr.out_port != OFPP_NONE) {
991         ds_put_cstr(string, " out_port=");
992         ofputil_format_port(fsr.out_port, string);
993     }
994
995     /* A flow stats request doesn't include a priority, but cls_rule_format()
996      * will print one unless it is OFP_DEFAULT_PRIORITY. */
997     fsr.match.priority = OFP_DEFAULT_PRIORITY;
998
999     ds_put_char(string, ' ');
1000     cls_rule_format(&fsr.match, string);
1001 }
1002
1003 void
1004 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1005 {
1006     ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1007                   ntohll(fs->cookie));
1008
1009     ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1010     ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1011     ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1012     ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1013     if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1014         ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1015     }
1016     if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1017         ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1018     }
1019     if (fs->idle_age >= 0) {
1020         ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1021     }
1022     if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1023         ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1024     }
1025
1026     cls_rule_format(&fs->rule, string);
1027     if (string->string[string->length - 1] != ' ') {
1028         ds_put_char(string, ' ');
1029     }
1030
1031     ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1032 }
1033
1034 static void
1035 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1036 {
1037     struct ofpbuf ofpacts;
1038     struct ofpbuf b;
1039
1040     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1041     ofpbuf_init(&ofpacts, 64);
1042     for (;;) {
1043         struct ofputil_flow_stats fs;
1044         int retval;
1045
1046         retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1047         if (retval) {
1048             if (retval != EOF) {
1049                 ds_put_cstr(string, " ***parse error***");
1050             }
1051             break;
1052         }
1053         ds_put_char(string, '\n');
1054         ofp_print_flow_stats(string, &fs);
1055      }
1056 }
1057
1058 static void
1059 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1060 {
1061     struct ofputil_aggregate_stats as;
1062     enum ofperr error;
1063
1064     error = ofputil_decode_aggregate_stats_reply(&as, oh);
1065     if (error) {
1066         ofp_print_error(string, error);
1067         return;
1068     }
1069
1070     ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1071     ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1072     ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1073 }
1074
1075 static void print_port_stat(struct ds *string, const char *leader,
1076                             const ovs_32aligned_be64 *statp, int more)
1077 {
1078     uint64_t stat = ntohll(get_32aligned_be64(statp));
1079
1080     ds_put_cstr(string, leader);
1081     if (stat != UINT64_MAX) {
1082         ds_put_format(string, "%"PRIu64, stat);
1083     } else {
1084         ds_put_char(string, '?');
1085     }
1086     if (more) {
1087         ds_put_cstr(string, ", ");
1088     } else {
1089         ds_put_cstr(string, "\n");
1090     }
1091 }
1092
1093 static void
1094 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1095 {
1096     const struct ofp10_port_stats_request *psr = ofpmsg_body(oh);
1097     ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
1098 }
1099
1100 static void
1101 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1102                            int verbosity)
1103 {
1104     struct ofp10_port_stats *ps;
1105     struct ofpbuf b;
1106     size_t n;
1107
1108     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1109     ofpraw_pull_assert(&b);
1110
1111     n = b.size / sizeof *ps;
1112     ds_put_format(string, " %zu ports\n", n);
1113     if (verbosity < 1) {
1114         return;
1115     }
1116
1117     for (;;) {
1118         ps = ofpbuf_try_pull(&b, sizeof *ps);
1119         if (!ps) {
1120             return;
1121         }
1122
1123         ds_put_format(string, "  port %2"PRIu16": ", ntohs(ps->port_no));
1124
1125         ds_put_cstr(string, "rx ");
1126         print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1127         print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1128         print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1129         print_port_stat(string, "errs=", &ps->rx_errors, 1);
1130         print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1131         print_port_stat(string, "over=", &ps->rx_over_err, 1);
1132         print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
1133
1134         ds_put_cstr(string, "           tx ");
1135         print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1136         print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1137         print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1138         print_port_stat(string, "errs=", &ps->tx_errors, 1);
1139         print_port_stat(string, "coll=", &ps->collisions, 0);
1140     }
1141 }
1142
1143 static void
1144 ofp_print_one_ofpst_table_reply(struct ds *string, enum ofp_version ofp_version,
1145                                 const char *name, struct ofp12_table_stats *ts)
1146 {
1147     char name_[OFP_MAX_TABLE_NAME_LEN + 1];
1148
1149     ovs_strlcpy(name_, name, sizeof name_);
1150
1151     ds_put_format(string, "  %d: %-8s: ", ts->table_id, name_);
1152     ds_put_format(string, "wild=0x%05"PRIx64", ", ntohll(ts->wildcards));
1153     ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1154     ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1155     ds_put_cstr(string, "               ");
1156     ds_put_format(string, "lookup=%"PRIu64", ", ntohll(ts->lookup_count));
1157     ds_put_format(string, "matched=%"PRIu64"\n", ntohll(ts->matched_count));
1158
1159     if (ofp_version < OFP11_VERSION) {
1160         return;
1161     }
1162
1163     ds_put_cstr(string, "               ");
1164     ds_put_format(string, "match=0x%08"PRIx64", ", ntohll(ts->match));
1165     ds_put_format(string, "instructions=0x%08"PRIx32", ",
1166                   ntohl(ts->instructions));
1167     ds_put_format(string, "config=0x%08"PRIx32"\n", ntohl(ts->config));
1168     ds_put_cstr(string, "               ");
1169     ds_put_format(string, "write_actions=0x%08"PRIx32", ",
1170                   ntohl(ts->write_actions));
1171     ds_put_format(string, "apply_actions=0x%08"PRIx32"\n",
1172                   ntohl(ts->apply_actions));
1173
1174     if (ofp_version < OFP12_VERSION) {
1175         return;
1176     }
1177
1178     ds_put_cstr(string, "               ");
1179     ds_put_format(string, "write_setfields=0x%016"PRIx64"\n",
1180                   ntohll(ts->write_setfields));
1181     ds_put_cstr(string, "               ");
1182     ds_put_format(string, "apply_setfields=0x%016"PRIx64"\n",
1183                   ntohll(ts->apply_setfields));
1184     ds_put_cstr(string, "               ");
1185     ds_put_format(string, "metadata_match=0x%016"PRIx64"\n",
1186                   ntohll(ts->metadata_match));
1187     ds_put_cstr(string, "               ");
1188     ds_put_format(string, "metadata_write=0x%016"PRIx64"\n",
1189                   ntohll(ts->metadata_write));
1190 }
1191
1192 static void
1193 ofp_print_ofpst_table_reply12(struct ds *string, const struct ofp_header *oh,
1194                               int verbosity)
1195 {
1196     struct ofp12_table_stats *ts;
1197     struct ofpbuf b;
1198     size_t n;
1199
1200     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1201     ofpraw_pull_assert(&b);
1202
1203     n = b.size / sizeof *ts;
1204     ds_put_format(string, " %zu tables\n", n);
1205     if (verbosity < 1) {
1206         return;
1207     }
1208
1209     for (;;) {
1210         ts = ofpbuf_try_pull(&b, sizeof *ts);
1211         if (!ts) {
1212             return;
1213         }
1214
1215         ofp_print_one_ofpst_table_reply(string, OFP12_VERSION, ts->name, ts);
1216      }
1217 }
1218
1219 static void
1220 ofp_print_ofpst_table_reply11(struct ds *string, const struct ofp_header *oh,
1221                               int verbosity)
1222 {
1223     struct ofp11_table_stats *ts;
1224     struct ofpbuf b;
1225     size_t n;
1226
1227     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1228     ofpraw_pull_assert(&b);
1229
1230     n = b.size / sizeof *ts;
1231     ds_put_format(string, " %zu tables\n", n);
1232     if (verbosity < 1) {
1233         return;
1234     }
1235
1236     for (;;) {
1237         struct ofp12_table_stats ts12;
1238
1239         ts = ofpbuf_try_pull(&b, sizeof *ts);
1240         if (!ts) {
1241             return;
1242         }
1243
1244         ts12.table_id = ts->table_id;
1245         ts12.wildcards = htonll(ntohl(ts->wildcards));
1246         ts12.max_entries = ts->max_entries;
1247         ts12.active_count = ts->active_count;
1248         ts12.lookup_count = ts->lookup_count;
1249         ts12.matched_count = ts->matched_count;
1250         ts12.match = htonll(ntohl(ts->match));
1251         ts12.instructions = ts->instructions;
1252         ts12.config = ts->config;
1253         ts12.write_actions = ts->write_actions;
1254         ts12.apply_actions = ts->apply_actions;
1255         ofp_print_one_ofpst_table_reply(string, OFP11_VERSION, ts->name, &ts12);
1256      }
1257 }
1258
1259 static void
1260 ofp_print_ofpst_table_reply10(struct ds *string, const struct ofp_header *oh,
1261                               int verbosity)
1262 {
1263     struct ofp10_table_stats *ts;
1264     struct ofpbuf b;
1265     size_t n;
1266
1267     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1268     ofpraw_pull_assert(&b);
1269
1270     n = b.size / sizeof *ts;
1271     ds_put_format(string, " %zu tables\n", n);
1272     if (verbosity < 1) {
1273         return;
1274     }
1275
1276     for (;;) {
1277         struct ofp12_table_stats ts12;
1278
1279         ts = ofpbuf_try_pull(&b, sizeof *ts);
1280         if (!ts) {
1281             return;
1282         }
1283
1284         ts12.table_id = ts->table_id;
1285         ts12.wildcards = htonll(ntohl(ts->wildcards));
1286         ts12.max_entries = ts->max_entries;
1287         ts12.active_count = ts->active_count;
1288         ts12.lookup_count = get_32aligned_be64(&ts->lookup_count);
1289         ts12.matched_count = get_32aligned_be64(&ts->matched_count);
1290         ofp_print_one_ofpst_table_reply(string, OFP10_VERSION, ts->name, &ts12);
1291      }
1292 }
1293
1294 static void
1295 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1296                             int verbosity)
1297 {
1298     switch ((enum ofp_version)oh->version) {
1299     case OFP12_VERSION:
1300         ofp_print_ofpst_table_reply12(string, oh, verbosity);
1301         break;
1302
1303     case OFP11_VERSION:
1304         ofp_print_ofpst_table_reply11(string, oh, verbosity);
1305         break;
1306
1307     case OFP10_VERSION:
1308         ofp_print_ofpst_table_reply10(string, oh, verbosity);
1309         break;
1310
1311     default:
1312         NOT_REACHED();
1313     }
1314 }
1315
1316 static void
1317 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1318 {
1319     if (queue_id == OFPQ_ALL) {
1320         ds_put_cstr(string, "ALL");
1321     } else {
1322         ds_put_format(string, "%"PRIu32, queue_id);
1323     }
1324 }
1325
1326 static void
1327 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1328 {
1329     const struct ofp10_queue_stats_request *qsr = ofpmsg_body(oh);
1330
1331     ds_put_cstr(string, "port=");
1332     ofputil_format_port(ntohs(qsr->port_no), string);
1333
1334     ds_put_cstr(string, " queue=");
1335     ofp_print_queue_name(string, ntohl(qsr->queue_id));
1336 }
1337
1338 static void
1339 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1340                             int verbosity)
1341 {
1342     struct ofp10_queue_stats *qs;
1343     struct ofpbuf b;
1344     size_t n;
1345
1346     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1347     ofpraw_pull_assert(&b);
1348
1349     n = b.size / sizeof *qs;
1350     ds_put_format(string, " %zu queues\n", n);
1351     if (verbosity < 1) {
1352         return;
1353     }
1354
1355     for (;;) {
1356         qs = ofpbuf_try_pull(&b, sizeof *qs);
1357         if (!qs) {
1358             return;
1359         }
1360
1361         ds_put_cstr(string, "  port ");
1362         ofputil_format_port(ntohs(qs->port_no), string);
1363         ds_put_cstr(string, " queue ");
1364         ofp_print_queue_name(string, ntohl(qs->queue_id));
1365         ds_put_cstr(string, ": ");
1366
1367         print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1368         print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1369         print_port_stat(string, "errors=", &qs->tx_errors, 0);
1370     }
1371 }
1372
1373 static void
1374 ofp_print_ofpst_port_desc_reply(struct ds *string,
1375                                 const struct ofp_header *oh)
1376 {
1377     struct ofpbuf b;
1378
1379     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1380     ofpraw_pull_assert(&b);
1381     ds_put_char(string, '\n');
1382     ofp_print_phy_ports(string, oh->version, &b);
1383 }
1384
1385 static void
1386 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1387 {
1388     uint16_t flags = ofpmp_flags(oh);
1389
1390     if (flags) {
1391         ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
1392     }
1393 }
1394
1395 static void
1396 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1397 {
1398     uint16_t flags = ofpmp_flags(oh);
1399
1400     if (flags) {
1401         ds_put_cstr(string, " flags=");
1402         if (flags & OFPSF_REPLY_MORE) {
1403             ds_put_cstr(string, "[more]");
1404             flags &= ~OFPSF_REPLY_MORE;
1405         }
1406         if (flags) {
1407             ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1408                           flags);
1409         }
1410     }
1411 }
1412
1413 static void
1414 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1415 {
1416     size_t len = ntohs(oh->length);
1417
1418     ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1419     if (verbosity > 1) {
1420         ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1421     }
1422 }
1423
1424 static void
1425 ofp_print_nxt_role_message(struct ds *string,
1426                            const struct nx_role_request *nrr)
1427 {
1428     unsigned int role = ntohl(nrr->role);
1429
1430     ds_put_cstr(string, " role=");
1431     if (role == NX_ROLE_OTHER) {
1432         ds_put_cstr(string, "other");
1433     } else if (role == NX_ROLE_MASTER) {
1434         ds_put_cstr(string, "master");
1435     } else if (role == NX_ROLE_SLAVE) {
1436         ds_put_cstr(string, "slave");
1437     } else {
1438         ds_put_format(string, "%u", role);
1439     }
1440 }
1441
1442 static void
1443 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1444                                 const struct nx_flow_mod_table_id *nfmti)
1445 {
1446     ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1447 }
1448
1449 static void
1450 ofp_print_nxt_set_flow_format(struct ds *string,
1451                               const struct nx_set_flow_format *nsff)
1452 {
1453     uint32_t format = ntohl(nsff->format);
1454
1455     ds_put_cstr(string, " format=");
1456     if (ofputil_nx_flow_format_is_valid(format)) {
1457         ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
1458     } else {
1459         ds_put_format(string, "%"PRIu32, format);
1460     }
1461 }
1462
1463 static void
1464 ofp_print_nxt_set_packet_in_format(struct ds *string,
1465                                    const struct nx_set_packet_in_format *nspf)
1466 {
1467     uint32_t format = ntohl(nspf->format);
1468
1469     ds_put_cstr(string, " format=");
1470     if (ofputil_packet_in_format_is_valid(format)) {
1471         ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1472     } else {
1473         ds_put_format(string, "%"PRIu32, format);
1474     }
1475 }
1476
1477 static const char *
1478 ofp_port_reason_to_string(enum ofp_port_reason reason)
1479 {
1480     static char s[32];
1481
1482     switch (reason) {
1483     case OFPPR_ADD:
1484         return "add";
1485
1486     case OFPPR_DELETE:
1487         return "delete";
1488
1489     case OFPPR_MODIFY:
1490         return "modify";
1491
1492     default:
1493         sprintf(s, "%d", (int) reason);
1494         return s;
1495     }
1496 }
1497
1498 static void
1499 ofp_print_nxt_set_async_config(struct ds *string,
1500                                const struct nx_async_config *nac)
1501 {
1502     int i;
1503
1504     for (i = 0; i < 2; i++) {
1505         int j;
1506
1507         ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
1508
1509         ds_put_cstr(string, "       PACKET_IN:");
1510         for (j = 0; j < 32; j++) {
1511             if (nac->packet_in_mask[i] & htonl(1u << j)) {
1512                 ds_put_format(string, " %s",
1513                               ofputil_packet_in_reason_to_string(j));
1514             }
1515         }
1516         if (!nac->packet_in_mask[i]) {
1517             ds_put_cstr(string, " (off)");
1518         }
1519         ds_put_char(string, '\n');
1520
1521         ds_put_cstr(string, "     PORT_STATUS:");
1522         for (j = 0; j < 32; j++) {
1523             if (nac->port_status_mask[i] & htonl(1u << j)) {
1524                 ds_put_format(string, " %s", ofp_port_reason_to_string(j));
1525             }
1526         }
1527         if (!nac->port_status_mask[i]) {
1528             ds_put_cstr(string, " (off)");
1529         }
1530         ds_put_char(string, '\n');
1531
1532         ds_put_cstr(string, "    FLOW_REMOVED:");
1533         for (j = 0; j < 32; j++) {
1534             if (nac->flow_removed_mask[i] & htonl(1u << j)) {
1535                 ds_put_format(string, " %s",
1536                               ofp_flow_removed_reason_to_string(j));
1537             }
1538         }
1539         if (!nac->flow_removed_mask[i]) {
1540             ds_put_cstr(string, " (off)");
1541         }
1542         ds_put_char(string, '\n');
1543     }
1544 }
1545
1546 static void
1547 ofp_print_nxt_set_controller_id(struct ds *string,
1548                                 const struct nx_controller_id *nci)
1549 {
1550     ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
1551 }
1552
1553 static void
1554 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
1555                                   const struct ofp_header *oh)
1556 {
1557     ds_put_format(string, " id=%"PRIu32,
1558                   ofputil_decode_flow_monitor_cancel(oh));
1559 }
1560
1561 static const char *
1562 nx_flow_monitor_flags_to_name(uint32_t bit)
1563 {
1564     enum nx_flow_monitor_flags fmf = bit;
1565
1566     switch (fmf) {
1567     case NXFMF_INITIAL: return "initial";
1568     case NXFMF_ADD: return "add";
1569     case NXFMF_DELETE: return "delete";
1570     case NXFMF_MODIFY: return "modify";
1571     case NXFMF_ACTIONS: return "actions";
1572     case NXFMF_OWN: return "own";
1573     }
1574
1575     return NULL;
1576 }
1577
1578 static void
1579 ofp_print_nxst_flow_monitor_request(struct ds *string,
1580                                     const struct ofp_header *oh)
1581 {
1582     struct ofpbuf b;
1583
1584     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1585     for (;;) {
1586         struct ofputil_flow_monitor_request request;
1587         int retval;
1588
1589         retval = ofputil_decode_flow_monitor_request(&request, &b);
1590         if (retval) {
1591             if (retval != EOF) {
1592                 ofp_print_error(string, retval);
1593             }
1594             return;
1595         }
1596
1597         ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
1598         ofp_print_bit_names(string, request.flags,
1599                             nx_flow_monitor_flags_to_name, ',');
1600
1601         if (request.out_port != OFPP_NONE) {
1602             ds_put_cstr(string, " out_port=");
1603             ofputil_format_port(request.out_port, string);
1604         }
1605
1606         if (request.table_id != 0xff) {
1607             ds_put_format(string, " table=%"PRIu8, request.table_id);
1608         }
1609
1610         ds_put_char(string, ' ');
1611         cls_rule_format(&request.match, string);
1612         ds_chomp(string, ' ');
1613     }
1614 }
1615
1616 static void
1617 ofp_print_nxst_flow_monitor_reply(struct ds *string,
1618                                   const struct ofp_header *oh)
1619 {
1620     uint64_t ofpacts_stub[1024 / 8];
1621     struct ofpbuf ofpacts;
1622     struct ofpbuf b;
1623
1624     ofpbuf_use_const(&b, oh, ntohs(oh->length));
1625     ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
1626     for (;;) {
1627         struct ofputil_flow_update update;
1628         struct cls_rule match;
1629         int retval;
1630
1631         update.match = &match;
1632         retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
1633         if (retval) {
1634             if (retval != EOF) {
1635                 ofp_print_error(string, retval);
1636             }
1637             ofpbuf_uninit(&ofpacts);
1638             return;
1639         }
1640
1641         ds_put_cstr(string, "\n event=");
1642         switch (update.event) {
1643         case NXFME_ADDED:
1644             ds_put_cstr(string, "ADDED");
1645             break;
1646
1647         case NXFME_DELETED:
1648             ds_put_format(string, "DELETED reason=%s",
1649                           ofp_flow_removed_reason_to_string(update.reason));
1650             break;
1651
1652         case NXFME_MODIFIED:
1653             ds_put_cstr(string, "MODIFIED");
1654             break;
1655
1656         case NXFME_ABBREV:
1657             ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
1658             continue;
1659         }
1660
1661         ds_put_format(string, " table=%"PRIu8, update.table_id);
1662         if (update.idle_timeout != OFP_FLOW_PERMANENT) {
1663             ds_put_format(string, " idle_timeout=%"PRIu16,
1664                           update.idle_timeout);
1665         }
1666         if (update.hard_timeout != OFP_FLOW_PERMANENT) {
1667             ds_put_format(string, " hard_timeout=%"PRIu16,
1668                           update.hard_timeout);
1669         }
1670         ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
1671
1672         ds_put_char(string, ' ');
1673         cls_rule_format(update.match, string);
1674
1675         if (update.ofpacts_len) {
1676             if (string->string[string->length - 1] != ' ') {
1677                 ds_put_char(string, ' ');
1678             }
1679             ofpacts_format(update.ofpacts, update.ofpacts_len, string);
1680         }
1681     }
1682 }
1683
1684 void
1685 ofp_print_version(const struct ofp_header *oh,
1686                   struct ds *string)
1687 {
1688     switch (oh->version) {
1689     case OFP10_VERSION:
1690         break;
1691     case OFP11_VERSION:
1692         ds_put_cstr(string, " (OF1.1)");
1693         break;
1694     case OFP12_VERSION:
1695         ds_put_cstr(string, " (OF1.2)");
1696         break;
1697     default:
1698         ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
1699         break;
1700     }
1701     ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
1702 }
1703
1704 static void
1705 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
1706                        struct ds *string)
1707 {
1708     ds_put_cstr(string, ofpraw_get_name(raw));
1709     ofp_print_version(oh, string);
1710 }
1711
1712 static void
1713 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
1714                 struct ds *string, int verbosity)
1715 {
1716     const void *msg = oh;
1717
1718     ofp_header_to_string__(oh, raw, string);
1719     switch (ofptype_from_ofpraw(raw)) {
1720     case OFPTYPE_HELLO:
1721         ds_put_char(string, '\n');
1722         ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1723                         0, true);
1724         break;
1725
1726     case OFPTYPE_ERROR:
1727         ofp_print_error_msg(string, oh);
1728         break;
1729
1730     case OFPTYPE_ECHO_REQUEST:
1731     case OFPTYPE_ECHO_REPLY:
1732         ofp_print_echo(string, oh, verbosity);
1733         break;
1734
1735     case OFPTYPE_FEATURES_REQUEST:
1736         break;
1737
1738     case OFPTYPE_FEATURES_REPLY:
1739         ofp_print_switch_features(string, oh);
1740         break;
1741
1742     case OFPTYPE_GET_CONFIG_REQUEST:
1743         break;
1744
1745     case OFPTYPE_GET_CONFIG_REPLY:
1746     case OFPTYPE_SET_CONFIG:
1747         ofp_print_switch_config(string, ofpmsg_body(oh));
1748         break;
1749
1750     case OFPTYPE_PACKET_IN:
1751         ofp_print_packet_in(string, oh, verbosity);
1752         break;
1753
1754     case OFPTYPE_FLOW_REMOVED:
1755         ofp_print_flow_removed(string, oh);
1756         break;
1757
1758     case OFPTYPE_PORT_STATUS:
1759         ofp_print_port_status(string, oh);
1760         break;
1761
1762     case OFPTYPE_PACKET_OUT:
1763         ofp_print_packet_out(string, oh, verbosity);
1764         break;
1765
1766     case OFPTYPE_FLOW_MOD:
1767         ofp_print_flow_mod(string, oh, verbosity);
1768         break;
1769
1770     case OFPTYPE_PORT_MOD:
1771         ofp_print_port_mod(string, oh);
1772         break;
1773
1774     case OFPTYPE_BARRIER_REQUEST:
1775     case OFPTYPE_BARRIER_REPLY:
1776         break;
1777
1778     case OFPTYPE_DESC_STATS_REQUEST:
1779     case OFPTYPE_PORT_DESC_STATS_REQUEST:
1780         ofp_print_stats_request(string, oh);
1781         break;
1782
1783     case OFPTYPE_FLOW_STATS_REQUEST:
1784     case OFPTYPE_AGGREGATE_STATS_REQUEST:
1785         ofp_print_stats_request(string, oh);
1786         ofp_print_flow_stats_request(string, oh);
1787         break;
1788
1789     case OFPTYPE_TABLE_STATS_REQUEST:
1790         ofp_print_stats_request(string, oh);
1791         break;
1792
1793     case OFPTYPE_PORT_STATS_REQUEST:
1794         ofp_print_stats_request(string, oh);
1795         ofp_print_ofpst_port_request(string, oh);
1796         break;
1797
1798     case OFPTYPE_QUEUE_STATS_REQUEST:
1799         ofp_print_stats_request(string, oh);
1800         ofp_print_ofpst_queue_request(string, oh);
1801         break;
1802
1803     case OFPTYPE_DESC_STATS_REPLY:
1804         ofp_print_stats_reply(string, oh);
1805         ofp_print_ofpst_desc_reply(string, oh);
1806         break;
1807
1808     case OFPTYPE_FLOW_STATS_REPLY:
1809         ofp_print_stats_reply(string, oh);
1810         ofp_print_flow_stats_reply(string, oh);
1811         break;
1812
1813     case OFPTYPE_QUEUE_STATS_REPLY:
1814         ofp_print_stats_reply(string, oh);
1815         ofp_print_ofpst_queue_reply(string, oh, verbosity);
1816         break;
1817
1818     case OFPTYPE_PORT_STATS_REPLY:
1819         ofp_print_stats_reply(string, oh);
1820         ofp_print_ofpst_port_reply(string, oh, verbosity);
1821         break;
1822
1823     case OFPTYPE_TABLE_STATS_REPLY:
1824         ofp_print_stats_reply(string, oh);
1825         ofp_print_ofpst_table_reply(string, oh, verbosity);
1826         break;
1827
1828     case OFPTYPE_AGGREGATE_STATS_REPLY:
1829         ofp_print_stats_reply(string, oh);
1830         ofp_print_aggregate_stats_reply(string, oh);
1831         break;
1832
1833     case OFPTYPE_PORT_DESC_STATS_REPLY:
1834         ofp_print_stats_reply(string, oh);
1835         ofp_print_ofpst_port_desc_reply(string, oh);
1836         break;
1837
1838     case OFPTYPE_ROLE_REQUEST:
1839     case OFPTYPE_ROLE_REPLY:
1840         ofp_print_nxt_role_message(string, ofpmsg_body(oh));
1841         break;
1842
1843     case OFPTYPE_FLOW_MOD_TABLE_ID:
1844         ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
1845         break;
1846
1847     case OFPTYPE_SET_FLOW_FORMAT:
1848         ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
1849         break;
1850
1851     case OFPTYPE_SET_PACKET_IN_FORMAT:
1852         ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
1853         break;
1854
1855     case OFPTYPE_FLOW_AGE:
1856         break;
1857
1858     case OFPTYPE_SET_CONTROLLER_ID:
1859         ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
1860         break;
1861
1862     case OFPTYPE_SET_ASYNC_CONFIG:
1863         ofp_print_nxt_set_async_config(string, ofpmsg_body(oh));
1864         break;
1865
1866     case OFPTYPE_FLOW_MONITOR_CANCEL:
1867         ofp_print_nxt_flow_monitor_cancel(string, msg);
1868         break;
1869
1870     case OFPTYPE_FLOW_MONITOR_PAUSED:
1871     case OFPTYPE_FLOW_MONITOR_RESUMED:
1872         break;
1873
1874     case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
1875         ofp_print_nxst_flow_monitor_request(string, msg);
1876         break;
1877
1878     case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
1879         ofp_print_nxst_flow_monitor_reply(string, msg);
1880         break;
1881     }
1882 }
1883
1884 /* Composes and returns a string representing the OpenFlow packet of 'len'
1885  * bytes at 'oh' at the given 'verbosity' level.  0 is a minimal amount of
1886  * verbosity and higher numbers increase verbosity.  The caller is responsible
1887  * for freeing the string. */
1888 char *
1889 ofp_to_string(const void *oh_, size_t len, int verbosity)
1890 {
1891     struct ds string = DS_EMPTY_INITIALIZER;
1892     const struct ofp_header *oh = oh_;
1893
1894     if (!len) {
1895         ds_put_cstr(&string, "OpenFlow message is empty\n");
1896     } else if (len < sizeof(struct ofp_header)) {
1897         ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1898                       len);
1899     } else if (ntohs(oh->length) > len) {
1900         enum ofperr error;
1901         enum ofpraw raw;
1902
1903         error = ofpraw_decode_partial(&raw, oh, len);
1904         if (!error) {
1905             ofp_header_to_string__(oh, raw, &string);
1906             ds_put_char(&string, '\n');
1907         }
1908
1909         ds_put_format(&string,
1910                       "(***truncated to %zu bytes from %"PRIu16"***)\n",
1911                       len, ntohs(oh->length));
1912     } else if (ntohs(oh->length) < len) {
1913         ds_put_format(&string,
1914                       "(***only uses %"PRIu16" bytes out of %zu***)\n",
1915                       ntohs(oh->length), len);
1916     } else {
1917         enum ofperr error;
1918         enum ofpraw raw;
1919
1920         error = ofpraw_decode(&raw, oh);
1921         if (!error) {
1922             ofp_to_string__(oh, raw, &string, verbosity);
1923             if (verbosity >= 5) {
1924                 if (ds_last(&string) != '\n') {
1925                     ds_put_char(&string, '\n');
1926                 }
1927                 ds_put_hex_dump(&string, oh, len, 0, true);
1928             }
1929             if (ds_last(&string) != '\n') {
1930                 ds_put_char(&string, '\n');
1931             }
1932             return ds_steal_cstr(&string);
1933         }
1934
1935         ofp_print_error(&string, error);
1936     }
1937     ds_put_hex_dump(&string, oh, len, 0, true);
1938     return ds_steal_cstr(&string);
1939 }
1940 \f
1941 static void
1942 print_and_free(FILE *stream, char *string)
1943 {
1944     fputs(string, stream);
1945     free(string);
1946 }
1947
1948 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1949  * given 'verbosity' level.  0 is a minimal amount of verbosity and higher
1950  * numbers increase verbosity. */
1951 void
1952 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1953 {
1954     print_and_free(stream, ofp_to_string(oh, len, verbosity));
1955 }
1956
1957 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1958  * 'data' to 'stream'. */
1959 void
1960 ofp_print_packet(FILE *stream, const void *data, size_t len)
1961 {
1962     print_and_free(stream, ofp_packet_to_string(data, len));
1963 }