2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "ofp-print.h"
22 #include <sys/types.h>
23 #include <netinet/in.h>
30 #include "byte-order.h"
32 #include "dynamic-string.h"
35 #include "multipath.h"
36 #include "meta-flow.h"
39 #include "ofp-actions.h"
41 #include "ofp-errors.h"
44 #include "openflow/openflow.h"
45 #include "openflow/nicira-ext.h"
47 #include "dp-packet.h"
48 #include "type-props.h"
49 #include "unaligned.h"
53 static void ofp_print_queue_name(struct ds *string, uint32_t port);
54 static void ofp_print_error(struct ds *, enum ofperr);
55 static void ofp_print_table_features(struct ds *,
56 const struct ofputil_table_features *,
57 const struct ofputil_table_stats *);
59 /* Returns a string that represents the contents of the Ethernet frame in the
60 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
62 ofp_packet_to_string(const void *data, size_t len)
64 struct ds ds = DS_EMPTY_INITIALIZER;
69 dp_packet_use_const(&buf, data, len);
70 flow_extract(&buf, &flow);
71 flow_format(&ds, &flow);
73 l4_size = dp_packet_l4_size(&buf);
75 if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
76 struct tcp_header *th = dp_packet_l4(&buf);
77 ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum));
78 } else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
79 struct udp_header *uh = dp_packet_l4(&buf);
80 ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum));
81 } else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) {
82 struct sctp_header *sh = dp_packet_l4(&buf);
83 ds_put_format(&ds, " sctp_csum:%"PRIx32,
84 ntohl(get_16aligned_be32(&sh->sctp_csum)));
85 } else if (flow.nw_proto == IPPROTO_ICMP && l4_size >= ICMP_HEADER_LEN) {
86 struct icmp_header *icmph = dp_packet_l4(&buf);
87 ds_put_format(&ds, " icmp_csum:%"PRIx16,
88 ntohs(icmph->icmp_csum));
89 } else if (flow.nw_proto == IPPROTO_ICMPV6 && l4_size >= ICMP6_HEADER_LEN) {
90 struct icmp6_header *icmp6h = dp_packet_l4(&buf);
91 ds_put_format(&ds, " icmp6_csum:%"PRIx16,
92 ntohs(icmp6h->icmp6_cksum));
95 ds_put_char(&ds, '\n');
101 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
104 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
105 struct ofputil_packet_in pin;
108 error = ofputil_decode_packet_in(&pin, oh);
110 ofp_print_error(string, error);
115 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
118 if (pin.cookie != OVS_BE64_MAX) {
119 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
122 ds_put_format(string, " total_len=%"PRIuSIZE" ", pin.total_len);
124 match_format(&pin.flow_metadata, string, OFP_DEFAULT_PRIORITY);
126 ds_put_format(string, " (via %s)",
127 ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
130 ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len);
131 if (pin.buffer_id == UINT32_MAX) {
132 ds_put_format(string, " (unbuffered)");
133 if (pin.total_len != pin.packet_len) {
134 ds_put_format(string, " (***total_len != data_len***)");
137 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
138 if (pin.total_len < pin.packet_len) {
139 ds_put_format(string, " (***total_len < data_len***)");
142 ds_put_char(string, '\n');
145 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
146 ds_put_cstr(string, packet);
150 ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false);
155 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
158 struct ofputil_packet_out po;
159 struct ofpbuf ofpacts;
162 ofpbuf_init(&ofpacts, 64);
163 error = ofputil_decode_packet_out(&po, oh, &ofpacts);
165 ofpbuf_uninit(&ofpacts);
166 ofp_print_error(string, error);
170 ds_put_cstr(string, " in_port=");
171 ofputil_format_port(po.in_port, string);
173 ds_put_cstr(string, " actions=");
174 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
176 if (po.buffer_id == UINT32_MAX) {
177 ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
178 if (verbosity > 0 && po.packet_len > 0) {
179 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
180 ds_put_char(string, '\n');
181 ds_put_cstr(string, packet);
185 ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
188 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
191 ofpbuf_uninit(&ofpacts);
194 /* qsort comparison function. */
196 compare_ports(const void *a_, const void *b_)
198 const struct ofputil_phy_port *a = a_;
199 const struct ofputil_phy_port *b = b_;
200 uint16_t ap = ofp_to_u16(a->port_no);
201 uint16_t bp = ofp_to_u16(b->port_no);
203 return ap < bp ? -1 : ap > bp;
207 ofp_print_bit_names(struct ds *string, uint32_t bits,
208 const char *(*bit_to_name)(uint32_t bit),
215 ds_put_cstr(string, "0");
219 for (i = 0; i < 32; i++) {
220 uint32_t bit = UINT32_C(1) << i;
223 const char *name = bit_to_name(bit);
226 ds_put_char(string, separator);
228 ds_put_cstr(string, name);
236 ds_put_char(string, separator);
238 ds_put_format(string, "0x%"PRIx32, bits);
243 netdev_feature_to_name(uint32_t bit)
245 enum netdev_features f = bit;
248 case NETDEV_F_10MB_HD: return "10MB-HD";
249 case NETDEV_F_10MB_FD: return "10MB-FD";
250 case NETDEV_F_100MB_HD: return "100MB-HD";
251 case NETDEV_F_100MB_FD: return "100MB-FD";
252 case NETDEV_F_1GB_HD: return "1GB-HD";
253 case NETDEV_F_1GB_FD: return "1GB-FD";
254 case NETDEV_F_10GB_FD: return "10GB-FD";
255 case NETDEV_F_40GB_FD: return "40GB-FD";
256 case NETDEV_F_100GB_FD: return "100GB-FD";
257 case NETDEV_F_1TB_FD: return "1TB-FD";
258 case NETDEV_F_OTHER: return "OTHER";
259 case NETDEV_F_COPPER: return "COPPER";
260 case NETDEV_F_FIBER: return "FIBER";
261 case NETDEV_F_AUTONEG: return "AUTO_NEG";
262 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
263 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
270 ofp_print_port_features(struct ds *string, enum netdev_features features)
272 ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
273 ds_put_char(string, '\n');
277 ofputil_port_config_to_name(uint32_t bit)
279 enum ofputil_port_config pc = bit;
282 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
283 case OFPUTIL_PC_NO_STP: return "NO_STP";
284 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
285 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
286 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
287 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
288 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
295 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
297 ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
298 ds_put_char(string, '\n');
302 ofputil_port_state_to_name(uint32_t bit)
304 enum ofputil_port_state ps = bit;
307 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
308 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
309 case OFPUTIL_PS_LIVE: return "LIVE";
311 case OFPUTIL_PS_STP_LISTEN:
312 case OFPUTIL_PS_STP_LEARN:
313 case OFPUTIL_PS_STP_FORWARD:
314 case OFPUTIL_PS_STP_BLOCK:
315 /* Handled elsewhere. */
323 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
325 enum ofputil_port_state stp_state;
327 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
328 * pattern. We have to special case it.
330 * OVS doesn't support STP, so this field will always be 0 if we are
331 * talking to OVS, so we'd always print STP_LISTEN in that case.
332 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
333 * avoid confusing users. */
334 stp_state = state & OFPUTIL_PS_STP_MASK;
337 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
338 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
340 state &= ~OFPUTIL_PS_STP_MASK;
342 ofp_print_bit_names(string, state, ofputil_port_state_to_name,
346 ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
348 ds_put_char(string, '\n');
352 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
354 char name[sizeof port->name];
357 memcpy(name, port->name, sizeof name);
358 for (j = 0; j < sizeof name - 1; j++) {
359 if (!isprint((unsigned char) name[j])) {
365 ds_put_char(string, ' ');
366 ofputil_format_port(port->port_no, string);
367 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
368 name, ETH_ADDR_ARGS(port->hw_addr));
370 ds_put_cstr(string, " config: ");
371 ofp_print_port_config(string, port->config);
373 ds_put_cstr(string, " state: ");
374 ofp_print_port_state(string, port->state);
377 ds_put_format(string, " current: ");
378 ofp_print_port_features(string, port->curr);
380 if (port->advertised) {
381 ds_put_format(string, " advertised: ");
382 ofp_print_port_features(string, port->advertised);
384 if (port->supported) {
385 ds_put_format(string, " supported: ");
386 ofp_print_port_features(string, port->supported);
389 ds_put_format(string, " peer: ");
390 ofp_print_port_features(string, port->peer);
392 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
393 "%"PRIu32" Mbps max\n",
394 port->curr_speed / UINT32_C(1000),
395 port->max_speed / UINT32_C(1000));
398 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
399 * 'ofp_version', writes a detailed description of each port into
402 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
405 struct ofputil_phy_port *ports;
406 size_t allocated_ports, n_ports;
412 for (n_ports = 0; ; n_ports++) {
413 if (n_ports >= allocated_ports) {
414 ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
417 retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
423 qsort(ports, n_ports, sizeof *ports, compare_ports);
424 for (i = 0; i < n_ports; i++) {
425 ofp_print_phy_port(string, &ports[i]);
430 ofp_print_error(string, retval);
435 ofputil_capabilities_to_name(uint32_t bit)
437 enum ofputil_capabilities capabilities = bit;
439 switch (capabilities) {
440 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
441 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
442 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
443 case OFPUTIL_C_IP_REASM: return "IP_REASM";
444 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
445 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
446 case OFPUTIL_C_STP: return "STP";
447 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
448 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
455 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
457 struct ofputil_switch_features features;
461 error = ofputil_decode_switch_features(oh, &features, &b);
463 ofp_print_error(string, error);
467 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
469 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
470 features.n_tables, features.n_buffers);
471 if (features.auxiliary_id) {
472 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
474 ds_put_char(string, '\n');
476 ds_put_cstr(string, "capabilities: ");
477 ofp_print_bit_names(string, features.capabilities,
478 ofputil_capabilities_to_name, ' ');
479 ds_put_char(string, '\n');
481 switch ((enum ofp_version)oh->version) {
483 ds_put_cstr(string, "actions: ");
484 ofpact_bitmap_format(features.ofpacts, string);
485 ds_put_char(string, '\n');
493 return; /* no ports in ofp13_switch_features */
498 ofp_print_phy_ports(string, oh->version, &b);
502 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
504 enum ofp_config_flags flags;
506 flags = ntohs(osc->flags);
508 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
509 flags &= ~OFPC_FRAG_MASK;
511 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
512 ds_put_format(string, " invalid_ttl_to_controller");
513 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
517 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
520 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
523 static void print_wild(struct ds *string, const char *leader, int is_wild,
524 int verbosity, const char *format, ...)
525 OVS_PRINTF_FORMAT(5, 6);
527 static void print_wild(struct ds *string, const char *leader, int is_wild,
528 int verbosity, const char *format, ...)
530 if (is_wild && verbosity < 2) {
533 ds_put_cstr(string, leader);
537 va_start(args, format);
538 ds_put_format_valist(string, format, args);
541 ds_put_char(string, '*');
543 ds_put_char(string, ',');
547 print_wild_port(struct ds *string, const char *leader, int is_wild,
548 int verbosity, ofp_port_t port)
550 if (is_wild && verbosity < 2) {
553 ds_put_cstr(string, leader);
555 ofputil_format_port(port, string);
557 ds_put_char(string, '*');
559 ds_put_char(string, ',');
563 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
564 uint32_t wild_bits, int verbosity)
566 if (wild_bits >= 32 && verbosity < 2) {
569 ds_put_cstr(string, leader);
570 if (wild_bits < 32) {
571 ds_put_format(string, IP_FMT, IP_ARGS(ip));
573 ds_put_format(string, "/%d", 32 - wild_bits);
576 ds_put_char(string, '*');
578 ds_put_char(string, ',');
582 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
584 char *s = ofp10_match_to_string(om, verbosity);
590 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
592 struct ds f = DS_EMPTY_INITIALIZER;
593 uint32_t w = ntohl(om->wildcards);
594 bool skip_type = false;
595 bool skip_proto = false;
597 if (!(w & OFPFW10_DL_TYPE)) {
599 if (om->dl_type == htons(ETH_TYPE_IP)) {
600 if (!(w & OFPFW10_NW_PROTO)) {
602 if (om->nw_proto == IPPROTO_ICMP) {
603 ds_put_cstr(&f, "icmp,");
604 } else if (om->nw_proto == IPPROTO_TCP) {
605 ds_put_cstr(&f, "tcp,");
606 } else if (om->nw_proto == IPPROTO_UDP) {
607 ds_put_cstr(&f, "udp,");
608 } else if (om->nw_proto == IPPROTO_SCTP) {
609 ds_put_cstr(&f, "sctp,");
611 ds_put_cstr(&f, "ip,");
615 ds_put_cstr(&f, "ip,");
617 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
618 ds_put_cstr(&f, "arp,");
619 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
620 ds_put_cstr(&f, "rarp,");
621 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
622 ds_put_cstr(&f, "mpls,");
623 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
624 ds_put_cstr(&f, "mplsm,");
629 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
630 u16_to_ofp(ntohs(om->in_port)));
631 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
632 "%d", ntohs(om->dl_vlan));
633 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
634 "%d", om->dl_vlan_pcp);
635 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
636 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
637 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
638 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
640 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
641 "0x%04x", ntohs(om->dl_type));
643 print_ip_netmask(&f, "nw_src=", om->nw_src,
644 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
646 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
647 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
650 if (om->dl_type == htons(ETH_TYPE_ARP) ||
651 om->dl_type == htons(ETH_TYPE_RARP)) {
652 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
655 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
659 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
661 if (om->nw_proto == IPPROTO_ICMP) {
662 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
663 "%d", ntohs(om->tp_src));
664 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
665 "%d", ntohs(om->tp_dst));
667 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
668 "%d", ntohs(om->tp_src));
669 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
670 "%d", ntohs(om->tp_dst));
677 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
679 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
680 ds_put_cstr(s, "send_flow_rem ");
682 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
683 ds_put_cstr(s, "check_overlap ");
685 if (flags & OFPUTIL_FF_RESET_COUNTS) {
686 ds_put_cstr(s, "reset_counts ");
688 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
689 ds_put_cstr(s, "no_packet_counts ");
691 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
692 ds_put_cstr(s, "no_byte_counts ");
694 if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
695 ds_put_cstr(s, "allow_hidden_fields ");
697 if (flags & OFPUTIL_FF_NO_READONLY) {
698 ds_put_cstr(s, "no_readonly_table ");
703 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
705 struct ofputil_flow_mod fm;
706 struct ofpbuf ofpacts;
710 enum ofputil_protocol protocol;
712 protocol = ofputil_protocol_from_ofp_version(oh->version);
713 protocol = ofputil_protocol_set_tid(protocol, true);
715 ofpbuf_init(&ofpacts, 64);
716 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
719 ofpbuf_uninit(&ofpacts);
720 ofp_print_error(s, error);
725 switch (fm.command) {
727 ds_put_cstr(s, "ADD");
730 ds_put_cstr(s, "MOD");
732 case OFPFC_MODIFY_STRICT:
733 ds_put_cstr(s, "MOD_STRICT");
736 ds_put_cstr(s, "DEL");
738 case OFPFC_DELETE_STRICT:
739 ds_put_cstr(s, "DEL_STRICT");
742 ds_put_format(s, "cmd:%d", fm.command);
744 if (fm.table_id != 0) {
745 ds_put_format(s, " table:%d", fm.table_id);
749 ofpraw_decode(&raw, oh);
750 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
751 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
752 ofp10_match_print(s, &ofm->match, verbosity);
754 /* ofp_print_match() doesn't print priority. */
755 need_priority = true;
756 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
757 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
758 const void *nxm = nfm + 1;
761 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
762 ds_put_cstr(s, nxm_s);
765 /* nx_match_to_string() doesn't print priority. */
766 need_priority = true;
768 match_format(&fm.match, s, fm.priority);
770 /* match_format() does print priority. */
771 need_priority = false;
774 if (ds_last(s) != ' ') {
777 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
778 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
780 if (fm.cookie_mask != htonll(0)) {
781 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
782 ntohll(fm.cookie), ntohll(fm.cookie_mask));
784 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
785 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
787 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
788 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
790 if (fm.importance != 0) {
791 ds_put_format(s, "importance:%"PRIu16" ", fm.importance);
793 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
794 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
796 if (fm.buffer_id != UINT32_MAX) {
797 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
799 if (fm.out_port != OFPP_ANY) {
800 ds_put_format(s, "out_port:");
801 ofputil_format_port(fm.out_port, s);
805 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
806 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
807 * versions don't really have such a flag and printing one is likely to
809 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
811 ofp_print_flow_flags(s, fm.flags);
813 ds_put_cstr(s, "actions=");
814 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
815 ofpbuf_uninit(&ofpacts);
819 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
821 ds_put_format(string, "%u", sec);
823 /* If there are no fractional seconds, don't print any decimals.
825 * If the fractional seconds can be expressed exactly as milliseconds,
826 * print 3 decimals. Open vSwitch provides millisecond precision for most
827 * time measurements, so printing 3 decimals every time makes it easier to
828 * spot real changes in flow dumps that refresh themselves quickly.
830 * If the fractional seconds are more precise than milliseconds, print the
831 * number of decimals needed to express them exactly.
834 unsigned int msec = nsec / 1000000;
835 if (msec * 1000000 == nsec) {
836 ds_put_format(string, ".%03u", msec);
838 ds_put_format(string, ".%09u", nsec);
839 while (string->string[string->length - 1] == '0') {
844 ds_put_char(string, 's');
847 /* Returns a string form of 'reason'. The return value is either a statically
848 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
849 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
850 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
852 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
853 char *reasonbuf, size_t bufsize)
856 case OFPRR_IDLE_TIMEOUT:
858 case OFPRR_HARD_TIMEOUT:
862 case OFPRR_GROUP_DELETE:
863 return "group_delete";
866 case OFPRR_METER_DELETE:
867 return "meter_delete";
870 snprintf(reasonbuf, bufsize, "%d", (int) reason);
876 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
878 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
879 struct ofputil_flow_removed fr;
882 error = ofputil_decode_flow_removed(&fr, oh);
884 ofp_print_error(string, error);
888 ds_put_char(string, ' ');
889 match_format(&fr.match, string, fr.priority);
891 ds_put_format(string, " reason=%s",
892 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
895 if (fr.table_id != 255) {
896 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
899 if (fr.cookie != htonll(0)) {
900 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
902 ds_put_cstr(string, " duration");
903 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
904 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
905 if (fr.hard_timeout) {
906 /* The hard timeout was only added in OF1.2, so only print it if it is
907 * actually in use to avoid gratuitous change to the formatting. */
908 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
910 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
911 fr.packet_count, fr.byte_count);
915 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
917 struct ofputil_port_mod pm;
920 error = ofputil_decode_port_mod(oh, &pm, true);
922 ofp_print_error(string, error);
926 ds_put_cstr(string, "port: ");
927 ofputil_format_port(pm.port_no, string);
928 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
929 ETH_ADDR_ARGS(pm.hw_addr));
931 ds_put_cstr(string, " config: ");
932 ofp_print_port_config(string, pm.config);
934 ds_put_cstr(string, " mask: ");
935 ofp_print_port_config(string, pm.mask);
937 ds_put_cstr(string, " advertise: ");
939 ofp_print_port_features(string, pm.advertise);
941 ds_put_cstr(string, "UNCHANGED\n");
946 ofputil_table_miss_to_string(enum ofputil_table_miss miss)
949 case OFPUTIL_TABLE_MISS_DEFAULT: return "default";
950 case OFPUTIL_TABLE_MISS_CONTROLLER: return "controller";
951 case OFPUTIL_TABLE_MISS_CONTINUE: return "continue";
952 case OFPUTIL_TABLE_MISS_DROP: return "drop";
953 default: return "***error***";
958 ofputil_table_eviction_to_string(enum ofputil_table_eviction eviction)
961 case OFPUTIL_TABLE_EVICTION_DEFAULT: return "default";
962 case OFPUTIL_TABLE_EVICTION_ON: return "on";
963 case OFPUTIL_TABLE_EVICTION_OFF: return "off";
964 default: return "***error***";
970 ofputil_eviction_flag_to_string(uint32_t bit)
972 enum ofp14_table_mod_prop_eviction_flag eviction_flag = bit;
974 switch (eviction_flag) {
975 case OFPTMPEF14_OTHER: return "OTHER";
976 case OFPTMPEF14_IMPORTANCE: return "IMPORTANCE";
977 case OFPTMPEF14_LIFETIME: return "LIFETIME";
983 /* Appends to 'string' a description of the bitmap of OFPTMPEF14_* values in
984 * 'eviction_flags'. */
986 ofputil_put_eviction_flags(struct ds *string, uint32_t eviction_flags)
988 if (eviction_flags != UINT32_MAX) {
989 ofp_print_bit_names(string, eviction_flags,
990 ofputil_eviction_flag_to_string, '|');
992 ds_put_cstr(string, "(default)");
997 ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
999 struct ofputil_table_mod pm;
1002 error = ofputil_decode_table_mod(oh, &pm);
1004 ofp_print_error(string, error);
1008 if (pm.table_id == 0xff) {
1009 ds_put_cstr(string, " table_id: ALL_TABLES");
1011 ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
1014 if (pm.miss != OFPUTIL_TABLE_MISS_DEFAULT) {
1015 ds_put_format(string, ", flow_miss_config=%s",
1016 ofputil_table_miss_to_string(pm.miss));
1018 if (pm.eviction != OFPUTIL_TABLE_EVICTION_DEFAULT) {
1019 ds_put_format(string, ", eviction=%s",
1020 ofputil_table_eviction_to_string(pm.eviction));
1022 if (pm.eviction_flags != UINT32_MAX) {
1023 ds_put_cstr(string, "eviction_flags=");
1024 ofputil_put_eviction_flags(string, pm.eviction_flags);
1028 /* This function will print the Table description properties. */
1030 ofp_print_table_desc(struct ds *string, const struct ofputil_table_desc *td)
1032 ds_put_format(string, "\n table %"PRIu8, td->table_id);
1033 ds_put_cstr(string, ":\n");
1034 ds_put_format(string, " eviction=%s eviction_flags=",
1035 ofputil_table_eviction_to_string(td->eviction));
1036 ofputil_put_eviction_flags(string, td->eviction_flags);
1037 ds_put_char(string, '\n');
1041 ofp_print_queue_get_config_request(struct ds *string,
1042 const struct ofp_header *oh)
1047 error = ofputil_decode_queue_get_config_request(oh, &port);
1049 ofp_print_error(string, error);
1053 ds_put_cstr(string, " port=");
1054 ofputil_format_port(port, string);
1058 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1061 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1062 } else if (rate < UINT16_MAX) {
1063 ds_put_format(string, " %s:(disabled)", name);
1068 ofp_print_queue_get_config_reply(struct ds *string,
1069 const struct ofp_header *oh)
1075 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1076 error = ofputil_decode_queue_get_config_reply(&b, &port);
1078 ofp_print_error(string, error);
1082 ds_put_cstr(string, " port=");
1083 ofputil_format_port(port, string);
1084 ds_put_char(string, '\n');
1087 struct ofputil_queue_config queue;
1090 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1092 if (retval != EOF) {
1093 ofp_print_error(string, retval);
1098 ds_put_format(string, "queue %"PRIu32":", queue.queue_id);
1099 print_queue_rate(string, "min_rate", queue.min_rate);
1100 print_queue_rate(string, "max_rate", queue.max_rate);
1101 ds_put_char(string, '\n');
1106 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1108 if (flags & OFPMF13_KBPS) {
1109 ds_put_cstr(s, "kbps ");
1111 if (flags & OFPMF13_PKTPS) {
1112 ds_put_cstr(s, "pktps ");
1114 if (flags & OFPMF13_BURST) {
1115 ds_put_cstr(s, "burst ");
1117 if (flags & OFPMF13_STATS) {
1118 ds_put_cstr(s, "stats ");
1121 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1123 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1128 ofp_print_meter_band(struct ds *s, uint16_t flags,
1129 const struct ofputil_meter_band *mb)
1131 ds_put_cstr(s, "\ntype=");
1134 ds_put_cstr(s, "drop");
1136 case OFPMBT13_DSCP_REMARK:
1137 ds_put_cstr(s, "dscp_remark");
1140 ds_put_format(s, "%u", mb->type);
1143 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1145 if (flags & OFPMF13_BURST) {
1146 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1148 if (mb->type == OFPMBT13_DSCP_REMARK) {
1149 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1154 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1158 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1159 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1160 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1161 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1162 ds_put_cstr(s, "duration:");
1163 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1164 ds_put_char(s, ' ');
1166 ds_put_cstr(s, "bands:\n");
1167 for (i = 0; i < ms->n_bands; ++i) {
1168 ds_put_format(s, "%d: ", i);
1169 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1170 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1175 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1179 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1181 ofp_print_meter_flags(s, mc->flags);
1183 ds_put_cstr(s, "bands=");
1184 for (i = 0; i < mc->n_bands; ++i) {
1185 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1187 ds_put_char(s, '\n');
1191 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1193 struct ofputil_meter_mod mm;
1194 struct ofpbuf bands;
1197 ofpbuf_init(&bands, 64);
1198 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1200 ofpbuf_uninit(&bands);
1201 ofp_print_error(s, error);
1205 switch (mm.command) {
1207 ds_put_cstr(s, " ADD ");
1209 case OFPMC13_MODIFY:
1210 ds_put_cstr(s, " MOD ");
1212 case OFPMC13_DELETE:
1213 ds_put_cstr(s, " DEL ");
1216 ds_put_format(s, " cmd:%d ", mm.command);
1219 ofp_print_meter_config(s, &mm.meter);
1220 ofpbuf_uninit(&bands);
1224 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1228 ofputil_decode_meter_request(oh, &meter_id);
1230 ds_put_format(s, " meter=%"PRIu32, meter_id);
1234 ofputil_meter_capabilities_to_name(uint32_t bit)
1236 enum ofp13_meter_flags flag = bit;
1239 case OFPMF13_KBPS: return "kbps";
1240 case OFPMF13_PKTPS: return "pktps";
1241 case OFPMF13_BURST: return "burst";
1242 case OFPMF13_STATS: return "stats";
1249 ofputil_meter_band_types_to_name(uint32_t bit)
1252 case 1 << OFPMBT13_DROP: return "drop";
1253 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1260 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1262 struct ofputil_meter_features mf;
1264 ofputil_decode_meter_features(oh, &mf);
1266 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1267 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1268 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1270 ds_put_cstr(s, "band_types: ");
1271 ofp_print_bit_names(s, mf.band_types,
1272 ofputil_meter_band_types_to_name, ' ');
1273 ds_put_char(s, '\n');
1275 ds_put_cstr(s, "capabilities: ");
1276 ofp_print_bit_names(s, mf.capabilities,
1277 ofputil_meter_capabilities_to_name, ' ');
1278 ds_put_char(s, '\n');
1282 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1284 struct ofpbuf bands;
1287 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1288 ofpbuf_init(&bands, 64);
1290 struct ofputil_meter_config mc;
1293 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1295 if (retval != EOF) {
1296 ofp_print_error(s, retval);
1300 ds_put_char(s, '\n');
1301 ofp_print_meter_config(s, &mc);
1303 ofpbuf_uninit(&bands);
1307 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1309 struct ofpbuf bands;
1312 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1313 ofpbuf_init(&bands, 64);
1315 struct ofputil_meter_stats ms;
1318 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1320 if (retval != EOF) {
1321 ofp_print_error(s, retval);
1325 ds_put_char(s, '\n');
1326 ofp_print_meter_stats(s, &ms);
1328 ofpbuf_uninit(&bands);
1332 ofp_print_error(struct ds *string, enum ofperr error)
1334 if (string->length) {
1335 ds_put_char(string, ' ');
1337 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1341 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1343 uint32_t allowed_versions;
1346 ok = ofputil_decode_hello(oh, &allowed_versions);
1348 ds_put_cstr(string, "\n version bitmap: ");
1349 ofputil_format_version_bitmap(string, allowed_versions);
1352 ds_put_cstr(string, "\n unknown data in hello:\n");
1353 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1358 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1360 size_t len = ntohs(oh->length);
1361 struct ofpbuf payload;
1365 error = ofperr_decode_msg(oh, &payload);
1367 ds_put_cstr(string, "***decode error***");
1368 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1372 ds_put_format(string, " %s\n", ofperr_get_name(error));
1374 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1375 ds_put_printable(string, payload.data, payload.size);
1377 s = ofp_to_string(payload.data, payload.size, 1);
1378 ds_put_cstr(string, s);
1381 ofpbuf_uninit(&payload);
1385 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1387 struct ofputil_port_status ps;
1390 error = ofputil_decode_port_status(oh, &ps);
1392 ofp_print_error(string, error);
1396 if (ps.reason == OFPPR_ADD) {
1397 ds_put_format(string, " ADD:");
1398 } else if (ps.reason == OFPPR_DELETE) {
1399 ds_put_format(string, " DEL:");
1400 } else if (ps.reason == OFPPR_MODIFY) {
1401 ds_put_format(string, " MOD:");
1404 ofp_print_phy_port(string, &ps.desc);
1408 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1410 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1412 ds_put_char(string, '\n');
1413 ds_put_format(string, "Manufacturer: %.*s\n",
1414 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1415 ds_put_format(string, "Hardware: %.*s\n",
1416 (int) sizeof ods->hw_desc, ods->hw_desc);
1417 ds_put_format(string, "Software: %.*s\n",
1418 (int) sizeof ods->sw_desc, ods->sw_desc);
1419 ds_put_format(string, "Serial Num: %.*s\n",
1420 (int) sizeof ods->serial_num, ods->serial_num);
1421 ds_put_format(string, "DP Description: %.*s\n",
1422 (int) sizeof ods->dp_desc, ods->dp_desc);
1426 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1428 struct ofputil_flow_stats_request fsr;
1431 error = ofputil_decode_flow_stats_request(&fsr, oh);
1433 ofp_print_error(string, error);
1437 if (fsr.table_id != 0xff) {
1438 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1441 if (fsr.out_port != OFPP_ANY) {
1442 ds_put_cstr(string, " out_port=");
1443 ofputil_format_port(fsr.out_port, string);
1446 ds_put_char(string, ' ');
1447 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1451 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1453 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1454 ntohll(fs->cookie));
1456 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1457 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1458 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1459 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1460 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1461 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1463 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1464 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1467 ofp_print_flow_flags(string, fs->flags);
1469 if (fs->importance != 0) {
1470 ds_put_format(string, "importance=%"PRIu16", ", fs->importance);
1472 if (fs->idle_age >= 0) {
1473 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1475 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1476 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1479 match_format(&fs->match, string, fs->priority);
1480 if (string->string[string->length - 1] != ' ') {
1481 ds_put_char(string, ' ');
1484 ds_put_cstr(string, "actions=");
1485 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1489 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1491 struct ofpbuf ofpacts;
1494 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1495 ofpbuf_init(&ofpacts, 64);
1497 struct ofputil_flow_stats fs;
1500 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1502 if (retval != EOF) {
1503 ds_put_cstr(string, " ***parse error***");
1507 ds_put_char(string, '\n');
1508 ofp_print_flow_stats(string, &fs);
1510 ofpbuf_uninit(&ofpacts);
1514 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1516 struct ofputil_aggregate_stats as;
1519 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1521 ofp_print_error(string, error);
1525 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1526 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1527 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1531 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1533 ds_put_cstr(string, leader);
1534 if (stat != UINT64_MAX) {
1535 ds_put_format(string, "%"PRIu64, stat);
1537 ds_put_char(string, '?');
1540 ds_put_cstr(string, ", ");
1542 ds_put_cstr(string, "\n");
1547 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1549 ofp_port_t ofp10_port;
1552 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1554 ofp_print_error(string, error);
1558 ds_put_cstr(string, " port_no=");
1559 ofputil_format_port(ofp10_port, string);
1563 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1568 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1569 if (verbosity < 1) {
1573 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1575 struct ofputil_port_stats ps;
1578 retval = ofputil_decode_port_stats(&ps, &b);
1580 if (retval != EOF) {
1581 ds_put_cstr(string, " ***parse error***");
1586 ds_put_cstr(string, " port ");
1587 if (ofp_to_u16(ps.port_no) < 10) {
1588 ds_put_char(string, ' ');
1590 ofputil_format_port(ps.port_no, string);
1592 ds_put_cstr(string, ": rx ");
1593 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1594 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1595 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1596 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1597 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1598 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1599 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1601 ds_put_cstr(string, " tx ");
1602 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1603 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1604 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1605 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1606 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1608 if (ps.duration_sec != UINT32_MAX) {
1609 ds_put_cstr(string, " duration=");
1610 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1611 ds_put_char(string, '\n');
1617 ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh)
1621 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1622 ofpraw_pull_assert(&b);
1625 struct ofputil_table_features features;
1626 struct ofputil_table_stats stats;
1629 retval = ofputil_decode_table_stats_reply(&b, &stats, &features);
1631 if (retval != EOF) {
1632 ofp_print_error(string, retval);
1637 ofp_print_table_features(string, &features, &stats);
1642 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1644 if (queue_id == OFPQ_ALL) {
1645 ds_put_cstr(string, "ALL");
1647 ds_put_format(string, "%"PRIu32, queue_id);
1652 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1654 struct ofputil_queue_stats_request oqsr;
1657 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1659 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1663 ds_put_cstr(string, "port=");
1664 ofputil_format_port(oqsr.port_no, string);
1666 ds_put_cstr(string, " queue=");
1667 ofp_print_queue_name(string, oqsr.queue_id);
1671 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1676 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1677 if (verbosity < 1) {
1681 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1683 struct ofputil_queue_stats qs;
1686 retval = ofputil_decode_queue_stats(&qs, &b);
1688 if (retval != EOF) {
1689 ds_put_cstr(string, " ***parse error***");
1694 ds_put_cstr(string, " port ");
1695 ofputil_format_port(qs.port_no, string);
1696 ds_put_cstr(string, " queue ");
1697 ofp_print_queue_name(string, qs.queue_id);
1698 ds_put_cstr(string, ": ");
1700 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1701 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1702 print_port_stat(string, "errors=", qs.tx_errors, 1);
1704 ds_put_cstr(string, "duration=");
1705 if (qs.duration_sec != UINT32_MAX) {
1706 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1708 ds_put_char(string, '?');
1710 ds_put_char(string, '\n');
1715 ofp_print_ofpst_port_desc_request(struct ds *string,
1716 const struct ofp_header *oh)
1721 error = ofputil_decode_port_desc_stats_request(oh, &port);
1723 ofp_print_error(string, error);
1727 ds_put_cstr(string, " port=");
1728 ofputil_format_port(port, string);
1732 ofp_print_ofpst_port_desc_reply(struct ds *string,
1733 const struct ofp_header *oh)
1737 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1738 ofpraw_pull_assert(&b);
1739 ds_put_char(string, '\n');
1740 ofp_print_phy_ports(string, oh->version, &b);
1744 ofp_print_stats(struct ds *string, const struct ofp_header *oh)
1746 uint16_t flags = ofpmp_flags(oh);
1749 ds_put_cstr(string, " flags=");
1750 if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION)
1751 && (flags & OFPSF_REPLY_MORE)) {
1752 ds_put_cstr(string, "[more]");
1753 flags &= ~OFPSF_REPLY_MORE;
1756 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1763 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1765 size_t len = ntohs(oh->length);
1767 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1768 if (verbosity > 1) {
1769 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1774 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1775 uint64_t generation_id)
1777 ds_put_cstr(string, " role=");
1780 case OFPCR12_ROLE_NOCHANGE:
1781 ds_put_cstr(string, "nochange");
1783 case OFPCR12_ROLE_EQUAL:
1784 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1786 case OFPCR12_ROLE_MASTER:
1787 ds_put_cstr(string, "master");
1789 case OFPCR12_ROLE_SLAVE:
1790 ds_put_cstr(string, "slave");
1796 if (generation_id != UINT64_MAX) {
1797 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1802 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1804 struct ofputil_role_request rr;
1807 error = ofputil_decode_role_message(oh, &rr);
1809 ofp_print_error(string, error);
1813 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1817 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1819 struct ofputil_role_status rs;
1822 error = ofputil_decode_role_status(oh, &rs);
1824 ofp_print_error(string, error);
1828 ofp_print_role_generic(string, rs.role, rs.generation_id);
1830 ds_put_cstr(string, " reason=");
1832 switch (rs.reason) {
1833 case OFPCRR_MASTER_REQUEST:
1834 ds_put_cstr(string, "master_request");
1837 ds_put_cstr(string, "configuration_changed");
1839 case OFPCRR_EXPERIMENTER:
1840 ds_put_cstr(string, "experimenter_data_changed");
1848 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1849 const struct nx_flow_mod_table_id *nfmti)
1851 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1855 ofp_print_nxt_set_flow_format(struct ds *string,
1856 const struct nx_set_flow_format *nsff)
1858 uint32_t format = ntohl(nsff->format);
1860 ds_put_cstr(string, " format=");
1861 if (ofputil_nx_flow_format_is_valid(format)) {
1862 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
1864 ds_put_format(string, "%"PRIu32, format);
1869 ofp_print_nxt_set_packet_in_format(struct ds *string,
1870 const struct nx_set_packet_in_format *nspf)
1872 uint32_t format = ntohl(nspf->format);
1874 ds_put_cstr(string, " format=");
1875 if (ofputil_packet_in_format_is_valid(format)) {
1876 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1878 ds_put_format(string, "%"PRIu32, format);
1882 /* Returns a string form of 'reason'. The return value is either a statically
1883 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1884 * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
1885 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
1887 ofp_port_reason_to_string(enum ofp_port_reason reason,
1888 char *reasonbuf, size_t bufsize)
1901 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1906 /* Returns a string form of 'reason'. The return value is either a statically
1907 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1908 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
1910 ofp_role_reason_to_string(enum ofp14_controller_role_reason reason,
1911 char *reasonbuf, size_t bufsize)
1914 case OFPCRR_MASTER_REQUEST:
1915 return "master_request";
1918 return "configuration_changed";
1920 case OFPCRR_EXPERIMENTER:
1921 return "experimenter_data_changed";
1924 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1929 /* Returns a string form of 'reason'. The return value is either a statically
1930 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1931 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
1933 ofp_table_reason_to_string(enum ofp14_table_reason reason,
1934 char *reasonbuf, size_t bufsize)
1937 case OFPTR_VACANCY_DOWN:
1938 return "vacancy_down";
1940 case OFPTR_VACANCY_UP:
1941 return "vacancy_up";
1944 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1949 /* Returns a string form of 'reason'. The return value is either a statically
1950 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1951 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
1953 ofp_requestforward_reason_to_string(enum ofp14_requestforward_reason reason,
1954 char *reasonbuf, size_t bufsize)
1957 case OFPRFR_GROUP_MOD:
1958 return "group_mod_request";
1960 case OFPRFR_METER_MOD:
1961 return "meter_mod_request";
1964 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1970 ofp_async_config_reason_to_string(uint32_t reason,
1971 enum ofputil_async_msg_type type,
1972 char *reasonbuf, size_t bufsize)
1976 return ofputil_packet_in_reason_to_string(reason, reasonbuf, bufsize);
1978 case OAM_PORT_STATUS:
1979 return ofp_port_reason_to_string(reason, reasonbuf, bufsize);
1981 case OAM_FLOW_REMOVED:
1982 return ofp_flow_removed_reason_to_string(reason, reasonbuf, bufsize);
1984 case OAM_ROLE_STATUS:
1985 return ofp_role_reason_to_string(reason, reasonbuf, bufsize);
1987 case OAM_TABLE_STATUS:
1988 return ofp_table_reason_to_string(reason, reasonbuf, bufsize);
1990 case OAM_REQUESTFORWARD:
1991 return ofp_requestforward_reason_to_string(reason, reasonbuf, bufsize);
1995 return "Unknown asynchronous configuration message type";
2000 #define OFP_ASYNC_CONFIG_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2002 ofp_print_nxt_set_async_config(struct ds *string,
2003 const struct ofp_header *oh)
2008 ofpraw_decode(&raw, oh);
2010 if (raw == OFPRAW_OFPT13_SET_ASYNC ||
2011 raw == OFPRAW_NXT_SET_ASYNC_CONFIG ||
2012 raw == OFPRAW_OFPT13_GET_ASYNC_REPLY) {
2013 const struct nx_async_config *nac = ofpmsg_body(oh);
2015 for (i = 0; i < 2; i++) {
2017 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2019 ds_put_cstr(string, " PACKET_IN:");
2020 for (j = 0; j < 32; j++) {
2021 if (nac->packet_in_mask[i] & htonl(1u << j)) {
2022 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2025 reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
2027 ds_put_format(string, " %s", reason);
2030 if (!nac->packet_in_mask[i]) {
2031 ds_put_cstr(string, " (off)");
2033 ds_put_char(string, '\n');
2035 ds_put_cstr(string, " PORT_STATUS:");
2036 for (j = 0; j < 32; j++) {
2037 if (nac->port_status_mask[i] & htonl(1u << j)) {
2038 char reasonbuf[OFP_PORT_REASON_BUFSIZE];
2041 reason = ofp_port_reason_to_string(j, reasonbuf,
2043 ds_put_format(string, " %s", reason);
2046 if (!nac->port_status_mask[i]) {
2047 ds_put_cstr(string, " (off)");
2049 ds_put_char(string, '\n');
2051 ds_put_cstr(string, " FLOW_REMOVED:");
2052 for (j = 0; j < 32; j++) {
2053 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
2054 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2057 reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
2059 ds_put_format(string, " %s", reason);
2062 if (!nac->flow_removed_mask[i]) {
2063 ds_put_cstr(string, " (off)");
2065 ds_put_char(string, '\n');
2067 } else if (raw == OFPRAW_OFPT14_SET_ASYNC ||
2068 raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) {
2069 uint32_t role[2][OAM_N_TYPES] = {{0}};
2072 ofputil_decode_set_async_config(oh, role[0], role[1], true);
2073 for (i = 0; i < 2; i++) {
2075 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2076 for (type = 0; type < OAM_N_TYPES; type++) {
2079 ds_put_cstr(string, " PACKET_IN:");
2082 case OAM_PORT_STATUS:
2083 ds_put_cstr(string, " PORT_STATUS:");
2086 case OAM_FLOW_REMOVED:
2087 ds_put_cstr(string, " FLOW_REMOVED:");
2090 case OAM_ROLE_STATUS:
2091 ds_put_cstr(string, " ROLE_STATUS:");
2094 case OAM_TABLE_STATUS:
2095 ds_put_cstr(string, " TABLE_STATUS:");
2098 case OAM_REQUESTFORWARD:
2099 ds_put_cstr(string, " REQUESTFORWARD:");
2103 for (j = 0; j < 32; j++) {
2104 if (role[i][type] & (1u << j)) {
2105 char reasonbuf[OFP_ASYNC_CONFIG_REASON_BUFSIZE];
2108 reason = ofp_async_config_reason_to_string(j, type,
2111 ds_put_format(string, " %s", reason);
2114 if (!role[i][type]) {
2115 ds_put_cstr(string, " (off)");
2117 ds_put_char(string, '\n');
2124 ofp_print_nxt_set_controller_id(struct ds *string,
2125 const struct nx_controller_id *nci)
2127 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
2131 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
2132 const struct ofp_header *oh)
2134 ds_put_format(string, " id=%"PRIu32,
2135 ofputil_decode_flow_monitor_cancel(oh));
2139 nx_flow_monitor_flags_to_name(uint32_t bit)
2141 enum nx_flow_monitor_flags fmf = bit;
2144 case NXFMF_INITIAL: return "initial";
2145 case NXFMF_ADD: return "add";
2146 case NXFMF_DELETE: return "delete";
2147 case NXFMF_MODIFY: return "modify";
2148 case NXFMF_ACTIONS: return "actions";
2149 case NXFMF_OWN: return "own";
2156 ofp_print_nxst_flow_monitor_request(struct ds *string,
2157 const struct ofp_header *oh)
2161 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2163 struct ofputil_flow_monitor_request request;
2166 retval = ofputil_decode_flow_monitor_request(&request, &b);
2168 if (retval != EOF) {
2169 ofp_print_error(string, retval);
2174 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
2175 ofp_print_bit_names(string, request.flags,
2176 nx_flow_monitor_flags_to_name, ',');
2178 if (request.out_port != OFPP_NONE) {
2179 ds_put_cstr(string, " out_port=");
2180 ofputil_format_port(request.out_port, string);
2183 if (request.table_id != 0xff) {
2184 ds_put_format(string, " table=%"PRIu8, request.table_id);
2187 ds_put_char(string, ' ');
2188 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
2189 ds_chomp(string, ' ');
2194 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2195 const struct ofp_header *oh)
2197 uint64_t ofpacts_stub[1024 / 8];
2198 struct ofpbuf ofpacts;
2201 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2202 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2204 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2205 struct ofputil_flow_update update;
2209 update.match = &match;
2210 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2212 if (retval != EOF) {
2213 ofp_print_error(string, retval);
2215 ofpbuf_uninit(&ofpacts);
2219 ds_put_cstr(string, "\n event=");
2220 switch (update.event) {
2222 ds_put_cstr(string, "ADDED");
2226 ds_put_format(string, "DELETED reason=%s",
2227 ofp_flow_removed_reason_to_string(update.reason,
2232 case NXFME_MODIFIED:
2233 ds_put_cstr(string, "MODIFIED");
2237 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2241 ds_put_format(string, " table=%"PRIu8, update.table_id);
2242 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2243 ds_put_format(string, " idle_timeout=%"PRIu16,
2244 update.idle_timeout);
2246 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2247 ds_put_format(string, " hard_timeout=%"PRIu16,
2248 update.hard_timeout);
2250 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2252 ds_put_char(string, ' ');
2253 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2255 if (update.ofpacts_len) {
2256 if (string->string[string->length - 1] != ' ') {
2257 ds_put_char(string, ' ');
2259 ds_put_cstr(string, "actions=");
2260 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2266 ofp_print_version(const struct ofp_header *oh,
2269 switch (oh->version) {
2273 ds_put_cstr(string, " (OF1.1)");
2276 ds_put_cstr(string, " (OF1.2)");
2279 ds_put_cstr(string, " (OF1.3)");
2282 ds_put_cstr(string, " (OF1.4)");
2285 ds_put_cstr(string, " (OF1.5)");
2288 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2291 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2295 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2298 ds_put_cstr(string, ofpraw_get_name(raw));
2299 ofp_print_version(oh, string);
2303 ofp_print_bucket_id(struct ds *s, const char *label, uint32_t bucket_id,
2304 enum ofp_version ofp_version)
2306 if (ofp_version < OFP15_VERSION) {
2310 ds_put_cstr(s, label);
2312 switch (bucket_id) {
2313 case OFPG15_BUCKET_FIRST:
2314 ds_put_cstr(s, "first");
2316 case OFPG15_BUCKET_LAST:
2317 ds_put_cstr(s, "last");
2319 case OFPG15_BUCKET_ALL:
2320 ds_put_cstr(s, "all");
2323 ds_put_format(s, "%"PRIu32, bucket_id);
2327 ds_put_char(s, ',');
2331 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2332 struct ovs_list *p_buckets, struct ofputil_group_props *props,
2333 enum ofp_version ofp_version, bool suppress_type)
2335 struct ofputil_bucket *bucket;
2337 ds_put_format(s, "group_id=%"PRIu32, group_id);
2339 if (!suppress_type) {
2340 static const char *type_str[] = { "all", "select", "indirect",
2342 ds_put_format(s, ",type=%s", type_str[type > 4 ? 4 : type]);
2345 if (props->selection_method[0]) {
2348 ds_put_format(s, ",selection_method=%s,", props->selection_method);
2349 if (props->selection_method_param) {
2350 ds_put_format(s, "selection_method_param=%"PRIu64",",
2351 props->selection_method_param);
2354 /* Allow rewinding to immediately before the trailing ',' */
2355 mark = s->length - 1;
2357 ds_put_cstr(s, "fields=");
2359 oxm_format_field_array(s, &props->fields);
2360 if (s->length == start) {
2361 ds_truncate(s, mark);
2369 ds_put_char(s, ',');
2371 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2372 ds_put_cstr(s, "bucket=");
2374 ofp_print_bucket_id(s, "bucket_id:", bucket->bucket_id, ofp_version);
2375 if (bucket->weight != 1) {
2376 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2378 if (bucket->watch_port != OFPP_NONE) {
2379 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2381 if (bucket->watch_group != OFPG11_ANY) {
2382 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2385 ds_put_cstr(s, "actions=");
2386 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2387 ds_put_char(s, ',');
2394 ofp_print_ofpst_group_desc_request(struct ds *string,
2395 const struct ofp_header *oh)
2397 uint32_t group_id = ofputil_decode_group_desc_request(oh);
2398 ds_put_cstr(string, " group_id=");
2399 ofputil_format_group(group_id, string);
2403 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2407 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2409 struct ofputil_group_desc gd;
2412 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2414 if (retval != EOF) {
2415 ds_put_cstr(s, " ***parse error***");
2420 ds_put_char(s, '\n');
2421 ds_put_char(s, ' ');
2422 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, &gd.props,
2423 oh->version, false);
2424 ofputil_bucket_list_destroy(&gd.buckets);
2429 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2434 error = ofputil_decode_group_stats_request(oh, &group_id);
2436 ofp_print_error(string, error);
2440 ds_put_cstr(string, " group_id=");
2441 ofputil_format_group(group_id, string);
2445 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2450 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2453 struct ofputil_group_stats gs;
2456 retval = ofputil_decode_group_stats_reply(&b, &gs);
2458 if (retval != EOF) {
2459 ds_put_cstr(s, " ***parse error***");
2464 ds_put_char(s, '\n');
2466 ds_put_char(s, ' ');
2467 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2469 if (gs.duration_sec != UINT32_MAX) {
2470 ds_put_cstr(s, "duration=");
2471 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2472 ds_put_char(s, ',');
2474 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2475 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2476 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2478 for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2479 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2480 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2481 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2482 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2486 free(gs.bucket_stats);
2491 group_type_to_string(enum ofp11_group_type type)
2494 case OFPGT11_ALL: return "all";
2495 case OFPGT11_SELECT: return "select";
2496 case OFPGT11_INDIRECT: return "indirect";
2497 case OFPGT11_FF: return "fast failover";
2498 default: OVS_NOT_REACHED();
2503 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2505 struct ofputil_group_features features;
2508 ofputil_decode_group_features_reply(oh, &features);
2510 ds_put_format(string, "\n Group table:\n");
2511 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2512 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2513 features.capabilities);
2515 for (i = 0; i < OFPGT12_N_TYPES; i++) {
2516 if (features.types & (1u << i)) {
2517 ds_put_format(string, " %s group:\n", group_type_to_string(i));
2518 ds_put_format(string, " max_groups=%#"PRIx32"\n",
2519 features.max_groups[i]);
2520 ds_put_format(string, " actions: ");
2521 ofpact_bitmap_format(features.ofpacts[i], string);
2522 ds_put_char(string, '\n');
2528 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2530 struct ofputil_group_mod gm;
2532 bool bucket_command = false;
2534 error = ofputil_decode_group_mod(oh, &gm);
2536 ofp_print_error(s, error);
2540 ds_put_char(s, '\n');
2542 ds_put_char(s, ' ');
2543 switch (gm.command) {
2545 ds_put_cstr(s, "ADD");
2548 case OFPGC11_MODIFY:
2549 ds_put_cstr(s, "MOD");
2552 case OFPGC11_DELETE:
2553 ds_put_cstr(s, "DEL");
2556 case OFPGC15_INSERT_BUCKET:
2557 ds_put_cstr(s, "INSERT_BUCKET");
2558 bucket_command = true;
2561 case OFPGC15_REMOVE_BUCKET:
2562 ds_put_cstr(s, "REMOVE_BUCKET");
2563 bucket_command = true;
2567 ds_put_format(s, "cmd:%"PRIu16"", gm.command);
2569 ds_put_char(s, ' ');
2571 if (bucket_command) {
2572 ofp_print_bucket_id(s, "command_bucket_id:",
2573 gm.command_bucket_id, oh->version);
2576 ofp_print_group(s, gm.group_id, gm.type, &gm.buckets, &gm.props,
2577 oh->version, bucket_command);
2578 ofputil_bucket_list_destroy(&gm.buckets);
2582 print_table_action_features(struct ds *s,
2583 const struct ofputil_table_action_features *taf)
2586 ds_put_cstr(s, " actions: ");
2587 ofpact_bitmap_format(taf->ofpacts, s);
2588 ds_put_char(s, '\n');
2591 if (!bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS)) {
2594 ds_put_cstr(s, " supported on Set-Field:");
2595 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, taf->set_fields.bm) {
2596 ds_put_format(s, " %s", mf_from_id(i)->name);
2598 ds_put_char(s, '\n');
2603 table_action_features_equal(const struct ofputil_table_action_features *a,
2604 const struct ofputil_table_action_features *b)
2606 return (a->ofpacts == b->ofpacts
2607 && bitmap_equal(a->set_fields.bm, b->set_fields.bm, MFF_N_IDS));
2611 table_action_features_empty(const struct ofputil_table_action_features *taf)
2613 return !taf->ofpacts && bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS);
2617 print_table_instruction_features(
2618 struct ds *s, const struct ofputil_table_instruction_features *tif)
2622 if (!bitmap_is_all_zeros(tif->next, 255)) {
2623 ds_put_cstr(s, " next tables: ");
2624 for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
2625 start = bitmap_scan(tif->next, 1, end, 255)) {
2626 end = bitmap_scan(tif->next, 0, start + 1, 255);
2627 if (end == start + 1) {
2628 ds_put_format(s, "%d,", start);
2630 ds_put_format(s, "%d-%d,", start, end - 1);
2634 if (ds_last(s) == ' ') {
2635 ds_put_cstr(s, "none");
2637 ds_put_char(s, '\n');
2640 if (tif->instructions) {
2641 ds_put_cstr(s, " instructions: ");
2644 for (i = 0; i < 32; i++) {
2645 if (tif->instructions & (1u << i)) {
2646 ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
2650 ds_put_char(s, '\n');
2653 if (!table_action_features_equal(&tif->write, &tif->apply)) {
2654 ds_put_cstr(s, " Write-Actions features:\n");
2655 print_table_action_features(s, &tif->write);
2656 ds_put_cstr(s, " Apply-Actions features:\n");
2657 print_table_action_features(s, &tif->apply);
2658 } else if (tif->write.ofpacts
2659 || !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
2660 ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
2661 print_table_action_features(s, &tif->write);
2666 table_instruction_features_equal(
2667 const struct ofputil_table_instruction_features *a,
2668 const struct ofputil_table_instruction_features *b)
2670 return (bitmap_equal(a->next, b->next, 255)
2671 && a->instructions == b->instructions
2672 && table_action_features_equal(&a->write, &b->write)
2673 && table_action_features_equal(&a->apply, &b->apply));
2677 table_instruction_features_empty(
2678 const struct ofputil_table_instruction_features *tif)
2680 return (bitmap_is_all_zeros(tif->next, 255)
2681 && !tif->instructions
2682 && table_action_features_empty(&tif->write)
2683 && table_action_features_empty(&tif->apply));
2687 ofp_print_table_features(struct ds *s,
2688 const struct ofputil_table_features *features,
2689 const struct ofputil_table_stats *stats)
2693 ds_put_format(s, "\n table %"PRIu8, features->table_id);
2694 if (features->name[0]) {
2695 ds_put_format(s, " (\"%s\")", features->name);
2697 ds_put_cstr(s, ":\n");
2699 ds_put_format(s, " active=%"PRIu32", ", stats->active_count);
2700 ds_put_format(s, "lookup=%"PRIu64", ", stats->lookup_count);
2701 ds_put_format(s, "matched=%"PRIu64"\n", stats->matched_count);
2703 if (features->metadata_match || features->metadata_match) {
2704 ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
2705 ntohll(features->metadata_match),
2706 ntohll(features->metadata_write));
2709 if (features->miss_config != OFPUTIL_TABLE_MISS_DEFAULT) {
2710 ds_put_format(s, " config=%s\n",
2711 ofputil_table_miss_to_string(features->miss_config));
2714 if (features->supports_eviction >= 0) {
2715 ds_put_format(s, " eviction: %ssupported\n",
2716 features->supports_eviction ? "" : "not ");
2719 if (features->supports_vacancy_events >= 0) {
2720 ds_put_format(s, " vacancy events: %ssupported\n",
2721 features->supports_vacancy_events ? "" : "not ");
2725 if (features->max_entries) {
2726 ds_put_format(s, " max_entries=%"PRIu32"\n", features->max_entries);
2729 if (!table_instruction_features_equal(&features->nonmiss,
2731 ds_put_cstr(s, " instructions (other than table miss):\n");
2732 print_table_instruction_features(s, &features->nonmiss);
2733 ds_put_cstr(s, " instructions (table miss):\n");
2734 print_table_instruction_features(s, &features->miss);
2735 } else if (!table_instruction_features_empty(&features->nonmiss)) {
2736 ds_put_cstr(s, " instructions (table miss and others):\n");
2737 print_table_instruction_features(s, &features->nonmiss);
2740 if (!bitmap_is_all_zeros(features->match.bm, MFF_N_IDS)){
2741 ds_put_cstr(s, " matching:\n");
2742 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) {
2743 const struct mf_field *f = mf_from_id(i);
2744 bool mask = bitmap_is_set(features->mask.bm, i);
2745 bool wildcard = bitmap_is_set(features->wildcard.bm, i);
2747 ds_put_format(s, " %s: %s\n",
2749 (mask ? "arbitrary mask"
2750 : wildcard ? "exact match or wildcard"
2751 : "must exact match"));
2757 ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh)
2761 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2764 struct ofputil_table_features tf;
2767 retval = ofputil_decode_table_features(&b, &tf, true);
2769 if (retval != EOF) {
2770 ofp_print_error(s, retval);
2774 ofp_print_table_features(s, &tf, NULL);
2779 ofp_print_table_desc_reply(struct ds *s, const struct ofp_header *oh)
2783 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2786 struct ofputil_table_desc td;
2789 retval = ofputil_decode_table_desc(&b, &td, oh->version);
2791 if (retval != EOF) {
2792 ofp_print_error(s, retval);
2796 ofp_print_table_desc(s, &td);
2801 bundle_flags_to_name(uint32_t bit)
2814 ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh)
2817 struct ofputil_bundle_ctrl_msg bctrl;
2819 error = ofputil_decode_bundle_ctrl(oh, &bctrl);
2821 ofp_print_error(s, error);
2825 ds_put_char(s, '\n');
2827 ds_put_format(s, " bundle_id=%#"PRIx32" type=", bctrl.bundle_id);
2828 switch (bctrl.type) {
2829 case OFPBCT_OPEN_REQUEST:
2830 ds_put_cstr(s, "OPEN_REQUEST");
2832 case OFPBCT_OPEN_REPLY:
2833 ds_put_cstr(s, "OPEN_REPLY");
2835 case OFPBCT_CLOSE_REQUEST:
2836 ds_put_cstr(s, "CLOSE_REQUEST");
2838 case OFPBCT_CLOSE_REPLY:
2839 ds_put_cstr(s, "CLOSE_REPLY");
2841 case OFPBCT_COMMIT_REQUEST:
2842 ds_put_cstr(s, "COMMIT_REQUEST");
2844 case OFPBCT_COMMIT_REPLY:
2845 ds_put_cstr(s, "COMMIT_REPLY");
2847 case OFPBCT_DISCARD_REQUEST:
2848 ds_put_cstr(s, "DISCARD_REQUEST");
2850 case OFPBCT_DISCARD_REPLY:
2851 ds_put_cstr(s, "DISCARD_REPLY");
2855 ds_put_cstr(s, " flags=");
2856 ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' ');
2860 ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
2863 struct ofputil_bundle_add_msg badd;
2866 error = ofputil_decode_bundle_add(oh, &badd, NULL);
2868 ofp_print_error(s, error);
2872 ds_put_char(s, '\n');
2873 ds_put_format(s, " bundle_id=%#"PRIx32, badd.bundle_id);
2874 ds_put_cstr(s, " flags=");
2875 ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
2877 ds_put_char(s, '\n');
2878 msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
2880 ds_put_cstr(s, msg);
2885 print_geneve_table(struct ds *s, struct ovs_list *mappings)
2887 struct ofputil_geneve_map *map;
2889 ds_put_cstr(s, " mapping table:\n");
2890 ds_put_cstr(s, " class\ttype\tlength\tmatch field\n");
2891 ds_put_cstr(s, " -----\t----\t------\t-----------");
2893 LIST_FOR_EACH (map, list_node, mappings) {
2894 ds_put_char(s, '\n');
2895 ds_put_format(s, " 0x%"PRIx16"\t0x%"PRIx8"\t%"PRIu8"\ttun_metadata%"PRIu16,
2896 map->option_class, map->option_type, map->option_len,
2902 ofp_print_geneve_table_mod(struct ds *s, const struct ofp_header *oh)
2905 struct ofputil_geneve_table_mod gtm;
2907 error = ofputil_decode_geneve_table_mod(oh, >m);
2909 ofp_print_error(s, error);
2913 ds_put_cstr(s, "\n ");
2915 switch (gtm.command) {
2917 ds_put_cstr(s, "ADD");
2920 ds_put_cstr(s, "DEL");
2923 ds_put_cstr(s, "CLEAR");
2927 if (gtm.command != NXGTMC_CLEAR) {
2928 print_geneve_table(s, >m.mappings);
2931 ofputil_uninit_geneve_table(>m.mappings);
2935 ofp_print_geneve_table_reply(struct ds *s, const struct ofp_header *oh)
2938 struct ofputil_geneve_table_reply gtr;
2939 struct ofputil_geneve_map *map;
2940 int allocated_space = 0;
2942 error = ofputil_decode_geneve_table_reply(oh, >r);
2944 ofp_print_error(s, error);
2948 ds_put_char(s, '\n');
2950 LIST_FOR_EACH (map, list_node, >r.mappings) {
2951 allocated_space += map->option_len;
2954 ds_put_format(s, " max option space=%"PRIu32" max fields=%"PRIu16"\n",
2955 gtr.max_option_space, gtr.max_fields);
2956 ds_put_format(s, " allocated option space=%d\n", allocated_space);
2957 ds_put_char(s, '\n');
2958 print_geneve_table(s, >r.mappings);
2960 ofputil_uninit_geneve_table(>r.mappings);
2964 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2965 struct ds *string, int verbosity)
2967 const void *msg = oh;
2969 ofp_header_to_string__(oh, raw, string);
2970 switch (ofptype_from_ofpraw(raw)) {
2972 case OFPTYPE_GROUP_STATS_REQUEST:
2973 ofp_print_stats(string, oh);
2974 ofp_print_ofpst_group_request(string, oh);
2977 case OFPTYPE_GROUP_STATS_REPLY:
2978 ofp_print_group_stats(string, oh);
2981 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
2982 ofp_print_stats(string, oh);
2983 ofp_print_ofpst_group_desc_request(string, oh);
2986 case OFPTYPE_GROUP_DESC_STATS_REPLY:
2987 ofp_print_group_desc(string, oh);
2990 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
2991 ofp_print_stats(string, oh);
2994 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
2995 ofp_print_group_features(string, oh);
2998 case OFPTYPE_GROUP_MOD:
2999 ofp_print_group_mod(string, oh);
3002 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
3003 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
3004 ofp_print_table_features_reply(string, oh);
3007 case OFPTYPE_TABLE_DESC_REQUEST:
3008 case OFPTYPE_TABLE_DESC_REPLY:
3009 ofp_print_table_desc_reply(string, oh);
3013 ofp_print_hello(string, oh);
3017 ofp_print_error_msg(string, oh);
3020 case OFPTYPE_ECHO_REQUEST:
3021 case OFPTYPE_ECHO_REPLY:
3022 ofp_print_echo(string, oh, verbosity);
3025 case OFPTYPE_FEATURES_REQUEST:
3028 case OFPTYPE_FEATURES_REPLY:
3029 ofp_print_switch_features(string, oh);
3032 case OFPTYPE_GET_CONFIG_REQUEST:
3035 case OFPTYPE_GET_CONFIG_REPLY:
3036 case OFPTYPE_SET_CONFIG:
3037 ofp_print_switch_config(string, ofpmsg_body(oh));
3040 case OFPTYPE_PACKET_IN:
3041 ofp_print_packet_in(string, oh, verbosity);
3044 case OFPTYPE_FLOW_REMOVED:
3045 ofp_print_flow_removed(string, oh);
3048 case OFPTYPE_PORT_STATUS:
3049 ofp_print_port_status(string, oh);
3052 case OFPTYPE_PACKET_OUT:
3053 ofp_print_packet_out(string, oh, verbosity);
3056 case OFPTYPE_FLOW_MOD:
3057 ofp_print_flow_mod(string, oh, verbosity);
3060 case OFPTYPE_PORT_MOD:
3061 ofp_print_port_mod(string, oh);
3064 case OFPTYPE_TABLE_MOD:
3065 ofp_print_table_mod(string, oh);
3068 case OFPTYPE_METER_MOD:
3069 ofp_print_meter_mod(string, oh);
3072 case OFPTYPE_BARRIER_REQUEST:
3073 case OFPTYPE_BARRIER_REPLY:
3076 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
3077 ofp_print_queue_get_config_request(string, oh);
3080 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
3081 ofp_print_queue_get_config_reply(string, oh);
3084 case OFPTYPE_ROLE_REQUEST:
3085 case OFPTYPE_ROLE_REPLY:
3086 ofp_print_role_message(string, oh);
3088 case OFPTYPE_ROLE_STATUS:
3089 ofp_print_role_status_message(string, oh);
3092 case OFPTYPE_METER_STATS_REQUEST:
3093 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
3094 ofp_print_stats(string, oh);
3095 ofp_print_meter_stats_request(string, oh);
3098 case OFPTYPE_METER_STATS_REPLY:
3099 ofp_print_stats(string, oh);
3100 ofp_print_meter_stats_reply(string, oh);
3103 case OFPTYPE_METER_CONFIG_STATS_REPLY:
3104 ofp_print_stats(string, oh);
3105 ofp_print_meter_config_reply(string, oh);
3108 case OFPTYPE_METER_FEATURES_STATS_REPLY:
3109 ofp_print_stats(string, oh);
3110 ofp_print_meter_features_reply(string, oh);
3113 case OFPTYPE_DESC_STATS_REQUEST:
3114 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
3115 ofp_print_stats(string, oh);
3118 case OFPTYPE_FLOW_STATS_REQUEST:
3119 case OFPTYPE_AGGREGATE_STATS_REQUEST:
3120 ofp_print_stats(string, oh);
3121 ofp_print_flow_stats_request(string, oh);
3124 case OFPTYPE_TABLE_STATS_REQUEST:
3125 ofp_print_stats(string, oh);
3128 case OFPTYPE_PORT_STATS_REQUEST:
3129 ofp_print_stats(string, oh);
3130 ofp_print_ofpst_port_request(string, oh);
3133 case OFPTYPE_QUEUE_STATS_REQUEST:
3134 ofp_print_stats(string, oh);
3135 ofp_print_ofpst_queue_request(string, oh);
3138 case OFPTYPE_DESC_STATS_REPLY:
3139 ofp_print_stats(string, oh);
3140 ofp_print_ofpst_desc_reply(string, oh);
3143 case OFPTYPE_FLOW_STATS_REPLY:
3144 ofp_print_stats(string, oh);
3145 ofp_print_flow_stats_reply(string, oh);
3148 case OFPTYPE_QUEUE_STATS_REPLY:
3149 ofp_print_stats(string, oh);
3150 ofp_print_ofpst_queue_reply(string, oh, verbosity);
3153 case OFPTYPE_PORT_STATS_REPLY:
3154 ofp_print_stats(string, oh);
3155 ofp_print_ofpst_port_reply(string, oh, verbosity);
3158 case OFPTYPE_TABLE_STATS_REPLY:
3159 ofp_print_stats(string, oh);
3160 ofp_print_table_stats_reply(string, oh);
3163 case OFPTYPE_AGGREGATE_STATS_REPLY:
3164 ofp_print_stats(string, oh);
3165 ofp_print_aggregate_stats_reply(string, oh);
3168 case OFPTYPE_PORT_DESC_STATS_REQUEST:
3169 ofp_print_stats(string, oh);
3170 ofp_print_ofpst_port_desc_request(string, oh);
3173 case OFPTYPE_PORT_DESC_STATS_REPLY:
3174 ofp_print_stats(string, oh);
3175 ofp_print_ofpst_port_desc_reply(string, oh);
3178 case OFPTYPE_FLOW_MOD_TABLE_ID:
3179 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
3182 case OFPTYPE_SET_FLOW_FORMAT:
3183 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
3186 case OFPTYPE_SET_PACKET_IN_FORMAT:
3187 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
3190 case OFPTYPE_FLOW_AGE:
3193 case OFPTYPE_SET_CONTROLLER_ID:
3194 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
3197 case OFPTYPE_GET_ASYNC_REPLY:
3198 case OFPTYPE_SET_ASYNC_CONFIG:
3199 ofp_print_nxt_set_async_config(string, oh);
3201 case OFPTYPE_GET_ASYNC_REQUEST:
3203 case OFPTYPE_FLOW_MONITOR_CANCEL:
3204 ofp_print_nxt_flow_monitor_cancel(string, msg);
3207 case OFPTYPE_FLOW_MONITOR_PAUSED:
3208 case OFPTYPE_FLOW_MONITOR_RESUMED:
3211 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
3212 ofp_print_nxst_flow_monitor_request(string, msg);
3215 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
3216 ofp_print_nxst_flow_monitor_reply(string, msg);
3219 case OFPTYPE_BUNDLE_CONTROL:
3220 ofp_print_bundle_ctrl(string, msg);
3223 case OFPTYPE_BUNDLE_ADD_MESSAGE:
3224 ofp_print_bundle_add(string, msg, verbosity);
3227 case OFPTYPE_NXT_GENEVE_TABLE_MOD:
3228 ofp_print_geneve_table_mod(string, msg);
3231 case OFPTYPE_NXT_GENEVE_TABLE_REQUEST:
3234 case OFPTYPE_NXT_GENEVE_TABLE_REPLY:
3235 ofp_print_geneve_table_reply(string, msg);
3241 /* Composes and returns a string representing the OpenFlow packet of 'len'
3242 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
3243 * verbosity and higher numbers increase verbosity. The caller is responsible
3244 * for freeing the string. */
3246 ofp_to_string(const void *oh_, size_t len, int verbosity)
3248 struct ds string = DS_EMPTY_INITIALIZER;
3249 const struct ofp_header *oh = oh_;
3252 ds_put_cstr(&string, "OpenFlow message is empty\n");
3253 } else if (len < sizeof(struct ofp_header)) {
3254 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
3256 } else if (ntohs(oh->length) > len) {
3260 error = ofpraw_decode_partial(&raw, oh, len);
3262 ofp_header_to_string__(oh, raw, &string);
3263 ds_put_char(&string, '\n');
3266 ds_put_format(&string,
3267 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
3268 len, ntohs(oh->length));
3269 } else if (ntohs(oh->length) < len) {
3270 ds_put_format(&string,
3271 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
3272 ntohs(oh->length), len);
3277 error = ofpraw_decode(&raw, oh);
3279 ofp_to_string__(oh, raw, &string, verbosity);
3280 if (verbosity >= 5) {
3281 if (ds_last(&string) != '\n') {
3282 ds_put_char(&string, '\n');
3284 ds_put_hex_dump(&string, oh, len, 0, true);
3286 if (ds_last(&string) != '\n') {
3287 ds_put_char(&string, '\n');
3289 return ds_steal_cstr(&string);
3292 ofp_print_error(&string, error);
3294 ds_put_hex_dump(&string, oh, len, 0, true);
3295 return ds_steal_cstr(&string);
3299 print_and_free(FILE *stream, char *string)
3301 fputs(string, stream);
3305 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
3306 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
3307 * numbers increase verbosity. */
3309 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
3311 print_and_free(stream, ofp_to_string(oh, len, verbosity));
3314 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
3315 * 'data' to 'stream'. */
3317 ofp_print_packet(FILE *stream, const void *data, size_t len)
3319 print_and_free(stream, ofp_packet_to_string(data, len));