2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 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"
40 #include "ofp-errors.h"
44 #include "openflow/openflow.h"
45 #include "openflow/nicira-ext.h"
47 #include "type-props.h"
48 #include "unaligned.h"
52 static void ofp_print_queue_name(struct ds *string, uint32_t port);
53 static void ofp_print_error(struct ds *, enum ofperr);
54 static void ofp_print_table_features(struct ds *,
55 const struct ofputil_table_features *,
56 const struct ofputil_table_stats *);
58 /* Returns a string that represents the contents of the Ethernet frame in the
59 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
61 ofp_packet_to_string(const void *data, size_t len)
63 struct ds ds = DS_EMPTY_INITIALIZER;
64 const struct pkt_metadata md = PKT_METADATA_INITIALIZER(0);
69 ofpbuf_use_const(&buf, data, len);
70 flow_extract(&buf, &md, &flow);
71 flow_format(&ds, &flow);
73 l4_size = ofpbuf_l4_size(&buf);
75 if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
76 struct tcp_header *th = ofpbuf_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 = ofpbuf_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 = ofpbuf_l4(&buf);
83 ds_put_format(&ds, " sctp_csum:%"PRIx32,
84 ntohl(get_16aligned_be32(&sh->sctp_csum)));
87 ds_put_char(&ds, '\n');
93 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
96 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
97 struct ofputil_packet_in pin;
101 error = ofputil_decode_packet_in(&pin, oh);
103 ofp_print_error(string, error);
108 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
111 if (pin.cookie != OVS_BE64_MAX) {
112 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
115 ds_put_format(string, " total_len=%"PRIuSIZE" in_port=", pin.total_len);
116 ofputil_format_port(pin.fmd.in_port, string);
118 if (pin.fmd.tun_id != htonll(0)) {
119 ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
122 if (pin.fmd.tun_src != htonl(0)) {
123 ds_put_format(string, " tun_src="IP_FMT, IP_ARGS(pin.fmd.tun_src));
126 if (pin.fmd.tun_dst != htonl(0)) {
127 ds_put_format(string, " tun_dst="IP_FMT, IP_ARGS(pin.fmd.tun_dst));
130 if (pin.fmd.metadata != htonll(0)) {
131 ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata));
134 for (i = 0; i < FLOW_N_REGS; i++) {
135 if (pin.fmd.regs[i]) {
136 ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
140 if (pin.fmd.pkt_mark != 0) {
141 ds_put_format(string, " pkt_mark=0x%"PRIx32, pin.fmd.pkt_mark);
144 ds_put_format(string, " (via %s)",
145 ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
148 ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len);
149 if (pin.buffer_id == UINT32_MAX) {
150 ds_put_format(string, " (unbuffered)");
151 if (pin.total_len != pin.packet_len) {
152 ds_put_format(string, " (***total_len != data_len***)");
155 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
156 if (pin.total_len < pin.packet_len) {
157 ds_put_format(string, " (***total_len < data_len***)");
160 ds_put_char(string, '\n');
163 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
164 ds_put_cstr(string, packet);
168 ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false);
173 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
176 struct ofputil_packet_out po;
177 struct ofpbuf ofpacts;
180 ofpbuf_init(&ofpacts, 64);
181 error = ofputil_decode_packet_out(&po, oh, &ofpacts);
183 ofpbuf_uninit(&ofpacts);
184 ofp_print_error(string, error);
188 ds_put_cstr(string, " in_port=");
189 ofputil_format_port(po.in_port, string);
191 ds_put_cstr(string, " actions=");
192 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
194 if (po.buffer_id == UINT32_MAX) {
195 ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
196 if (verbosity > 0 && po.packet_len > 0) {
197 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
198 ds_put_char(string, '\n');
199 ds_put_cstr(string, packet);
203 ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
206 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
209 ofpbuf_uninit(&ofpacts);
212 /* qsort comparison function. */
214 compare_ports(const void *a_, const void *b_)
216 const struct ofputil_phy_port *a = a_;
217 const struct ofputil_phy_port *b = b_;
218 uint16_t ap = ofp_to_u16(a->port_no);
219 uint16_t bp = ofp_to_u16(b->port_no);
221 return ap < bp ? -1 : ap > bp;
225 ofp_print_bit_names(struct ds *string, uint32_t bits,
226 const char *(*bit_to_name)(uint32_t bit),
233 ds_put_cstr(string, "0");
237 for (i = 0; i < 32; i++) {
238 uint32_t bit = UINT32_C(1) << i;
241 const char *name = bit_to_name(bit);
244 ds_put_char(string, separator);
246 ds_put_cstr(string, name);
254 ds_put_char(string, separator);
256 ds_put_format(string, "0x%"PRIx32, bits);
261 netdev_feature_to_name(uint32_t bit)
263 enum netdev_features f = bit;
266 case NETDEV_F_10MB_HD: return "10MB-HD";
267 case NETDEV_F_10MB_FD: return "10MB-FD";
268 case NETDEV_F_100MB_HD: return "100MB-HD";
269 case NETDEV_F_100MB_FD: return "100MB-FD";
270 case NETDEV_F_1GB_HD: return "1GB-HD";
271 case NETDEV_F_1GB_FD: return "1GB-FD";
272 case NETDEV_F_10GB_FD: return "10GB-FD";
273 case NETDEV_F_40GB_FD: return "40GB-FD";
274 case NETDEV_F_100GB_FD: return "100GB-FD";
275 case NETDEV_F_1TB_FD: return "1TB-FD";
276 case NETDEV_F_OTHER: return "OTHER";
277 case NETDEV_F_COPPER: return "COPPER";
278 case NETDEV_F_FIBER: return "FIBER";
279 case NETDEV_F_AUTONEG: return "AUTO_NEG";
280 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
281 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
288 ofp_print_port_features(struct ds *string, enum netdev_features features)
290 ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
291 ds_put_char(string, '\n');
295 ofputil_port_config_to_name(uint32_t bit)
297 enum ofputil_port_config pc = bit;
300 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
301 case OFPUTIL_PC_NO_STP: return "NO_STP";
302 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
303 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
304 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
305 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
306 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
313 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
315 ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
316 ds_put_char(string, '\n');
320 ofputil_port_state_to_name(uint32_t bit)
322 enum ofputil_port_state ps = bit;
325 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
326 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
327 case OFPUTIL_PS_LIVE: return "LIVE";
329 case OFPUTIL_PS_STP_LISTEN:
330 case OFPUTIL_PS_STP_LEARN:
331 case OFPUTIL_PS_STP_FORWARD:
332 case OFPUTIL_PS_STP_BLOCK:
333 /* Handled elsewhere. */
341 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
343 enum ofputil_port_state stp_state;
345 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
346 * pattern. We have to special case it.
348 * OVS doesn't support STP, so this field will always be 0 if we are
349 * talking to OVS, so we'd always print STP_LISTEN in that case.
350 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
351 * avoid confusing users. */
352 stp_state = state & OFPUTIL_PS_STP_MASK;
355 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
356 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
358 state &= ~OFPUTIL_PS_STP_MASK;
360 ofp_print_bit_names(string, state, ofputil_port_state_to_name,
364 ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
366 ds_put_char(string, '\n');
370 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
372 char name[sizeof port->name];
375 memcpy(name, port->name, sizeof name);
376 for (j = 0; j < sizeof name - 1; j++) {
377 if (!isprint((unsigned char) name[j])) {
383 ds_put_char(string, ' ');
384 ofputil_format_port(port->port_no, string);
385 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
386 name, ETH_ADDR_ARGS(port->hw_addr));
388 ds_put_cstr(string, " config: ");
389 ofp_print_port_config(string, port->config);
391 ds_put_cstr(string, " state: ");
392 ofp_print_port_state(string, port->state);
395 ds_put_format(string, " current: ");
396 ofp_print_port_features(string, port->curr);
398 if (port->advertised) {
399 ds_put_format(string, " advertised: ");
400 ofp_print_port_features(string, port->advertised);
402 if (port->supported) {
403 ds_put_format(string, " supported: ");
404 ofp_print_port_features(string, port->supported);
407 ds_put_format(string, " peer: ");
408 ofp_print_port_features(string, port->peer);
410 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
411 "%"PRIu32" Mbps max\n",
412 port->curr_speed / UINT32_C(1000),
413 port->max_speed / UINT32_C(1000));
416 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
417 * 'ofp_version', writes a detailed description of each port into
420 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
423 struct ofputil_phy_port *ports;
424 size_t allocated_ports, n_ports;
430 for (n_ports = 0; ; n_ports++) {
431 if (n_ports >= allocated_ports) {
432 ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
435 retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
441 qsort(ports, n_ports, sizeof *ports, compare_ports);
442 for (i = 0; i < n_ports; i++) {
443 ofp_print_phy_port(string, &ports[i]);
448 ofp_print_error(string, retval);
453 ofputil_capabilities_to_name(uint32_t bit)
455 enum ofputil_capabilities capabilities = bit;
457 switch (capabilities) {
458 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
459 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
460 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
461 case OFPUTIL_C_IP_REASM: return "IP_REASM";
462 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
463 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
464 case OFPUTIL_C_STP: return "STP";
465 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
466 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
473 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
475 struct ofputil_switch_features features;
479 error = ofputil_decode_switch_features(oh, &features, &b);
481 ofp_print_error(string, error);
485 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
487 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
488 features.n_tables, features.n_buffers);
489 if (features.auxiliary_id) {
490 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
492 ds_put_char(string, '\n');
494 ds_put_cstr(string, "capabilities: ");
495 ofp_print_bit_names(string, features.capabilities,
496 ofputil_capabilities_to_name, ' ');
497 ds_put_char(string, '\n');
499 switch ((enum ofp_version)oh->version) {
501 ds_put_cstr(string, "actions: ");
502 ofpact_bitmap_format(features.ofpacts, string);
503 ds_put_char(string, '\n');
511 return; /* no ports in ofp13_switch_features */
516 ofp_print_phy_ports(string, oh->version, &b);
520 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
522 enum ofp_config_flags flags;
524 flags = ntohs(osc->flags);
526 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
527 flags &= ~OFPC_FRAG_MASK;
529 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
530 ds_put_format(string, " invalid_ttl_to_controller");
531 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
535 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
538 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
541 static void print_wild(struct ds *string, const char *leader, int is_wild,
542 int verbosity, const char *format, ...)
545 static void print_wild(struct ds *string, const char *leader, int is_wild,
546 int verbosity, const char *format, ...)
548 if (is_wild && verbosity < 2) {
551 ds_put_cstr(string, leader);
555 va_start(args, format);
556 ds_put_format_valist(string, format, args);
559 ds_put_char(string, '*');
561 ds_put_char(string, ',');
565 print_wild_port(struct ds *string, const char *leader, int is_wild,
566 int verbosity, ofp_port_t port)
568 if (is_wild && verbosity < 2) {
571 ds_put_cstr(string, leader);
573 ofputil_format_port(port, string);
575 ds_put_char(string, '*');
577 ds_put_char(string, ',');
581 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
582 uint32_t wild_bits, int verbosity)
584 if (wild_bits >= 32 && verbosity < 2) {
587 ds_put_cstr(string, leader);
588 if (wild_bits < 32) {
589 ds_put_format(string, IP_FMT, IP_ARGS(ip));
591 ds_put_format(string, "/%d", 32 - wild_bits);
594 ds_put_char(string, '*');
596 ds_put_char(string, ',');
600 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
602 char *s = ofp10_match_to_string(om, verbosity);
608 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
610 struct ds f = DS_EMPTY_INITIALIZER;
611 uint32_t w = ntohl(om->wildcards);
612 bool skip_type = false;
613 bool skip_proto = false;
615 if (!(w & OFPFW10_DL_TYPE)) {
617 if (om->dl_type == htons(ETH_TYPE_IP)) {
618 if (!(w & OFPFW10_NW_PROTO)) {
620 if (om->nw_proto == IPPROTO_ICMP) {
621 ds_put_cstr(&f, "icmp,");
622 } else if (om->nw_proto == IPPROTO_TCP) {
623 ds_put_cstr(&f, "tcp,");
624 } else if (om->nw_proto == IPPROTO_UDP) {
625 ds_put_cstr(&f, "udp,");
626 } else if (om->nw_proto == IPPROTO_SCTP) {
627 ds_put_cstr(&f, "sctp,");
629 ds_put_cstr(&f, "ip,");
633 ds_put_cstr(&f, "ip,");
635 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
636 ds_put_cstr(&f, "arp,");
637 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
638 ds_put_cstr(&f, "rarp,");
639 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
640 ds_put_cstr(&f, "mpls,");
641 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
642 ds_put_cstr(&f, "mplsm,");
647 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
648 u16_to_ofp(ntohs(om->in_port)));
649 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
650 "%d", ntohs(om->dl_vlan));
651 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
652 "%d", om->dl_vlan_pcp);
653 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
654 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
655 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
656 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
658 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
659 "0x%04x", ntohs(om->dl_type));
661 print_ip_netmask(&f, "nw_src=", om->nw_src,
662 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
664 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
665 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
668 if (om->dl_type == htons(ETH_TYPE_ARP) ||
669 om->dl_type == htons(ETH_TYPE_RARP)) {
670 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
673 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
677 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
679 if (om->nw_proto == IPPROTO_ICMP) {
680 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
681 "%d", ntohs(om->tp_src));
682 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
683 "%d", ntohs(om->tp_dst));
685 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
686 "%d", ntohs(om->tp_src));
687 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
688 "%d", ntohs(om->tp_dst));
695 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
697 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
698 ds_put_cstr(s, "send_flow_rem ");
700 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
701 ds_put_cstr(s, "check_overlap ");
703 if (flags & OFPUTIL_FF_RESET_COUNTS) {
704 ds_put_cstr(s, "reset_counts ");
706 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
707 ds_put_cstr(s, "no_packet_counts ");
709 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
710 ds_put_cstr(s, "no_byte_counts ");
712 if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
713 ds_put_cstr(s, "allow_hidden_fields ");
715 if (flags & OFPUTIL_FF_NO_READONLY) {
716 ds_put_cstr(s, "no_readonly_table ");
721 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
723 struct ofputil_flow_mod fm;
724 struct ofpbuf ofpacts;
728 enum ofputil_protocol protocol;
730 protocol = ofputil_protocol_from_ofp_version(oh->version);
731 protocol = ofputil_protocol_set_tid(protocol, true);
733 ofpbuf_init(&ofpacts, 64);
734 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
737 ofpbuf_uninit(&ofpacts);
738 ofp_print_error(s, error);
743 switch (fm.command) {
745 ds_put_cstr(s, "ADD");
748 ds_put_cstr(s, "MOD");
750 case OFPFC_MODIFY_STRICT:
751 ds_put_cstr(s, "MOD_STRICT");
754 ds_put_cstr(s, "DEL");
756 case OFPFC_DELETE_STRICT:
757 ds_put_cstr(s, "DEL_STRICT");
760 ds_put_format(s, "cmd:%d", fm.command);
762 if (fm.table_id != 0) {
763 ds_put_format(s, " table:%d", fm.table_id);
767 ofpraw_decode(&raw, oh);
768 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
769 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
770 ofp10_match_print(s, &ofm->match, verbosity);
772 /* ofp_print_match() doesn't print priority. */
773 need_priority = true;
774 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
775 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
776 const void *nxm = nfm + 1;
779 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
780 ds_put_cstr(s, nxm_s);
783 /* nx_match_to_string() doesn't print priority. */
784 need_priority = true;
786 match_format(&fm.match, s, fm.priority);
788 /* match_format() does print priority. */
789 need_priority = false;
792 if (ds_last(s) != ' ') {
795 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
796 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
798 if (fm.cookie_mask != htonll(0)) {
799 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
800 ntohll(fm.cookie), ntohll(fm.cookie_mask));
802 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
803 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
805 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
806 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
808 if (fm.importance != 0) {
809 ds_put_format(s, "importance:%"PRIu16" ", fm.importance);
811 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
812 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
814 if (fm.buffer_id != UINT32_MAX) {
815 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
817 if (fm.out_port != OFPP_ANY) {
818 ds_put_format(s, "out_port:");
819 ofputil_format_port(fm.out_port, s);
823 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
824 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
825 * versions don't really have such a flag and printing one is likely to
827 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
829 ofp_print_flow_flags(s, fm.flags);
831 ds_put_cstr(s, "actions=");
832 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
833 ofpbuf_uninit(&ofpacts);
837 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
839 ds_put_format(string, "%u", sec);
841 /* If there are no fractional seconds, don't print any decimals.
843 * If the fractional seconds can be expressed exactly as milliseconds,
844 * print 3 decimals. Open vSwitch provides millisecond precision for most
845 * time measurements, so printing 3 decimals every time makes it easier to
846 * spot real changes in flow dumps that refresh themselves quickly.
848 * If the fractional seconds are more precise than milliseconds, print the
849 * number of decimals needed to express them exactly.
852 unsigned int msec = nsec / 1000000;
853 if (msec * 1000000 == nsec) {
854 ds_put_format(string, ".%03u", msec);
856 ds_put_format(string, ".%09u", nsec);
857 while (string->string[string->length - 1] == '0') {
862 ds_put_char(string, 's');
865 /* Returns a string form of 'reason'. The return value is either a statically
866 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
867 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
868 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
870 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
871 char *reasonbuf, size_t bufsize)
874 case OFPRR_IDLE_TIMEOUT:
876 case OFPRR_HARD_TIMEOUT:
880 case OFPRR_GROUP_DELETE:
881 return "group_delete";
884 case OFPRR_METER_DELETE:
885 return "meter_delete";
887 snprintf(reasonbuf, bufsize, "%d", (int) reason);
893 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
895 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
896 struct ofputil_flow_removed fr;
899 error = ofputil_decode_flow_removed(&fr, oh);
901 ofp_print_error(string, error);
905 ds_put_char(string, ' ');
906 match_format(&fr.match, string, fr.priority);
908 ds_put_format(string, " reason=%s",
909 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
912 if (fr.table_id != 255) {
913 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
916 if (fr.cookie != htonll(0)) {
917 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
919 ds_put_cstr(string, " duration");
920 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
921 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
922 if (fr.hard_timeout) {
923 /* The hard timeout was only added in OF1.2, so only print it if it is
924 * actually in use to avoid gratuitous change to the formatting. */
925 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
927 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
928 fr.packet_count, fr.byte_count);
932 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
934 struct ofputil_port_mod pm;
937 error = ofputil_decode_port_mod(oh, &pm, true);
939 ofp_print_error(string, error);
943 ds_put_cstr(string, "port: ");
944 ofputil_format_port(pm.port_no, string);
945 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
946 ETH_ADDR_ARGS(pm.hw_addr));
948 ds_put_cstr(string, " config: ");
949 ofp_print_port_config(string, pm.config);
951 ds_put_cstr(string, " mask: ");
952 ofp_print_port_config(string, pm.mask);
954 ds_put_cstr(string, " advertise: ");
956 ofp_print_port_features(string, pm.advertise);
958 ds_put_cstr(string, "UNCHANGED\n");
963 ofp_print_table_miss_config(struct ds *string, enum ofputil_table_miss miss)
966 case OFPUTIL_TABLE_MISS_CONTROLLER:
967 ds_put_cstr(string, "controller\n");
969 case OFPUTIL_TABLE_MISS_CONTINUE:
970 ds_put_cstr(string, "continue\n");
972 case OFPUTIL_TABLE_MISS_DROP:
973 ds_put_cstr(string, "drop\n");
975 case OFPUTIL_TABLE_MISS_DEFAULT:
977 ds_put_format(string, "Unknown (%d)\n", miss);
983 ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
985 struct ofputil_table_mod pm;
988 error = ofputil_decode_table_mod(oh, &pm);
990 ofp_print_error(string, error);
994 if (pm.table_id == 0xff) {
995 ds_put_cstr(string, " table_id: ALL_TABLES");
997 ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
1000 if (pm.miss_config != OFPUTIL_TABLE_MISS_DEFAULT) {
1001 ds_put_cstr(string, ", flow_miss_config=");
1002 ofp_print_table_miss_config(string, pm.miss_config);
1007 ofp_print_queue_get_config_request(struct ds *string,
1008 const struct ofp_header *oh)
1013 error = ofputil_decode_queue_get_config_request(oh, &port);
1015 ofp_print_error(string, error);
1019 ds_put_cstr(string, " port=");
1020 ofputil_format_port(port, string);
1024 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1027 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1028 } else if (rate < UINT16_MAX) {
1029 ds_put_format(string, " %s:(disabled)", name);
1034 ofp_print_queue_get_config_reply(struct ds *string,
1035 const struct ofp_header *oh)
1041 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1042 error = ofputil_decode_queue_get_config_reply(&b, &port);
1044 ofp_print_error(string, error);
1048 ds_put_cstr(string, " port=");
1049 ofputil_format_port(port, string);
1050 ds_put_char(string, '\n');
1053 struct ofputil_queue_config queue;
1056 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1058 if (retval != EOF) {
1059 ofp_print_error(string, retval);
1064 ds_put_format(string, "queue %"PRIu32":", queue.queue_id);
1065 print_queue_rate(string, "min_rate", queue.min_rate);
1066 print_queue_rate(string, "max_rate", queue.max_rate);
1067 ds_put_char(string, '\n');
1072 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1074 if (flags & OFPMF13_KBPS) {
1075 ds_put_cstr(s, "kbps ");
1077 if (flags & OFPMF13_PKTPS) {
1078 ds_put_cstr(s, "pktps ");
1080 if (flags & OFPMF13_BURST) {
1081 ds_put_cstr(s, "burst ");
1083 if (flags & OFPMF13_STATS) {
1084 ds_put_cstr(s, "stats ");
1087 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1089 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1094 ofp_print_meter_band(struct ds *s, uint16_t flags,
1095 const struct ofputil_meter_band *mb)
1097 ds_put_cstr(s, "\ntype=");
1100 ds_put_cstr(s, "drop");
1102 case OFPMBT13_DSCP_REMARK:
1103 ds_put_cstr(s, "dscp_remark");
1106 ds_put_format(s, "%u", mb->type);
1109 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1111 if (flags & OFPMF13_BURST) {
1112 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1114 if (mb->type == OFPMBT13_DSCP_REMARK) {
1115 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1120 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1124 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1125 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1126 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1127 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1128 ds_put_cstr(s, "duration:");
1129 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1130 ds_put_char(s, ' ');
1132 ds_put_cstr(s, "bands:\n");
1133 for (i = 0; i < ms->n_bands; ++i) {
1134 ds_put_format(s, "%d: ", i);
1135 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1136 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1141 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1145 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1147 ofp_print_meter_flags(s, mc->flags);
1149 ds_put_cstr(s, "bands=");
1150 for (i = 0; i < mc->n_bands; ++i) {
1151 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1153 ds_put_char(s, '\n');
1157 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1159 struct ofputil_meter_mod mm;
1160 struct ofpbuf bands;
1163 ofpbuf_init(&bands, 64);
1164 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1166 ofpbuf_uninit(&bands);
1167 ofp_print_error(s, error);
1171 switch (mm.command) {
1173 ds_put_cstr(s, " ADD ");
1175 case OFPMC13_MODIFY:
1176 ds_put_cstr(s, " MOD ");
1178 case OFPMC13_DELETE:
1179 ds_put_cstr(s, " DEL ");
1182 ds_put_format(s, " cmd:%d ", mm.command);
1185 ofp_print_meter_config(s, &mm.meter);
1186 ofpbuf_uninit(&bands);
1190 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1194 ofputil_decode_meter_request(oh, &meter_id);
1196 ds_put_format(s, " meter=%"PRIu32, meter_id);
1200 ofputil_meter_capabilities_to_name(uint32_t bit)
1202 enum ofp13_meter_flags flag = bit;
1205 case OFPMF13_KBPS: return "kbps";
1206 case OFPMF13_PKTPS: return "pktps";
1207 case OFPMF13_BURST: return "burst";
1208 case OFPMF13_STATS: return "stats";
1215 ofputil_meter_band_types_to_name(uint32_t bit)
1218 case 1 << OFPMBT13_DROP: return "drop";
1219 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1226 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1228 struct ofputil_meter_features mf;
1230 ofputil_decode_meter_features(oh, &mf);
1232 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1233 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1234 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1236 ds_put_cstr(s, "band_types: ");
1237 ofp_print_bit_names(s, mf.band_types,
1238 ofputil_meter_band_types_to_name, ' ');
1239 ds_put_char(s, '\n');
1241 ds_put_cstr(s, "capabilities: ");
1242 ofp_print_bit_names(s, mf.capabilities,
1243 ofputil_meter_capabilities_to_name, ' ');
1244 ds_put_char(s, '\n');
1248 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1250 struct ofpbuf bands;
1253 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1254 ofpbuf_init(&bands, 64);
1256 struct ofputil_meter_config mc;
1259 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1261 if (retval != EOF) {
1262 ofp_print_error(s, retval);
1266 ds_put_char(s, '\n');
1267 ofp_print_meter_config(s, &mc);
1269 ofpbuf_uninit(&bands);
1273 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1275 struct ofpbuf bands;
1278 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1279 ofpbuf_init(&bands, 64);
1281 struct ofputil_meter_stats ms;
1284 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1286 if (retval != EOF) {
1287 ofp_print_error(s, retval);
1291 ds_put_char(s, '\n');
1292 ofp_print_meter_stats(s, &ms);
1294 ofpbuf_uninit(&bands);
1298 ofp_print_error(struct ds *string, enum ofperr error)
1300 if (string->length) {
1301 ds_put_char(string, ' ');
1303 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1307 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1309 uint32_t allowed_versions;
1312 ok = ofputil_decode_hello(oh, &allowed_versions);
1314 ds_put_cstr(string, "\n version bitmap: ");
1315 ofputil_format_version_bitmap(string, allowed_versions);
1318 ds_put_cstr(string, "\n unknown data in hello:\n");
1319 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1324 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1326 size_t len = ntohs(oh->length);
1327 struct ofpbuf payload;
1331 error = ofperr_decode_msg(oh, &payload);
1333 ds_put_cstr(string, "***decode error***");
1334 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1338 ds_put_format(string, " %s\n", ofperr_get_name(error));
1340 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1341 ds_put_printable(string, ofpbuf_data(&payload), ofpbuf_size(&payload));
1343 s = ofp_to_string(ofpbuf_data(&payload), ofpbuf_size(&payload), 1);
1344 ds_put_cstr(string, s);
1347 ofpbuf_uninit(&payload);
1351 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1353 struct ofputil_port_status ps;
1356 error = ofputil_decode_port_status(oh, &ps);
1358 ofp_print_error(string, error);
1362 if (ps.reason == OFPPR_ADD) {
1363 ds_put_format(string, " ADD:");
1364 } else if (ps.reason == OFPPR_DELETE) {
1365 ds_put_format(string, " DEL:");
1366 } else if (ps.reason == OFPPR_MODIFY) {
1367 ds_put_format(string, " MOD:");
1370 ofp_print_phy_port(string, &ps.desc);
1374 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1376 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1378 ds_put_char(string, '\n');
1379 ds_put_format(string, "Manufacturer: %.*s\n",
1380 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1381 ds_put_format(string, "Hardware: %.*s\n",
1382 (int) sizeof ods->hw_desc, ods->hw_desc);
1383 ds_put_format(string, "Software: %.*s\n",
1384 (int) sizeof ods->sw_desc, ods->sw_desc);
1385 ds_put_format(string, "Serial Num: %.*s\n",
1386 (int) sizeof ods->serial_num, ods->serial_num);
1387 ds_put_format(string, "DP Description: %.*s\n",
1388 (int) sizeof ods->dp_desc, ods->dp_desc);
1392 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1394 struct ofputil_flow_stats_request fsr;
1397 error = ofputil_decode_flow_stats_request(&fsr, oh);
1399 ofp_print_error(string, error);
1403 if (fsr.table_id != 0xff) {
1404 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1407 if (fsr.out_port != OFPP_ANY) {
1408 ds_put_cstr(string, " out_port=");
1409 ofputil_format_port(fsr.out_port, string);
1412 ds_put_char(string, ' ');
1413 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1417 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1419 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1420 ntohll(fs->cookie));
1422 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1423 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1424 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1425 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1426 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1427 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1429 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1430 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1433 ofp_print_flow_flags(string, fs->flags);
1435 if (fs->importance != 0) {
1436 ds_put_format(string, "importance=%"PRIu16", ", fs->importance);
1438 if (fs->idle_age >= 0) {
1439 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1441 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1442 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1445 match_format(&fs->match, string, fs->priority);
1446 if (string->string[string->length - 1] != ' ') {
1447 ds_put_char(string, ' ');
1450 ds_put_cstr(string, "actions=");
1451 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1455 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1457 struct ofpbuf ofpacts;
1460 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1461 ofpbuf_init(&ofpacts, 64);
1463 struct ofputil_flow_stats fs;
1466 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1468 if (retval != EOF) {
1469 ds_put_cstr(string, " ***parse error***");
1473 ds_put_char(string, '\n');
1474 ofp_print_flow_stats(string, &fs);
1476 ofpbuf_uninit(&ofpacts);
1480 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1482 struct ofputil_aggregate_stats as;
1485 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1487 ofp_print_error(string, error);
1491 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1492 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1493 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1497 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1499 ds_put_cstr(string, leader);
1500 if (stat != UINT64_MAX) {
1501 ds_put_format(string, "%"PRIu64, stat);
1503 ds_put_char(string, '?');
1506 ds_put_cstr(string, ", ");
1508 ds_put_cstr(string, "\n");
1513 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1515 ofp_port_t ofp10_port;
1518 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1520 ofp_print_error(string, error);
1524 ds_put_cstr(string, " port_no=");
1525 ofputil_format_port(ofp10_port, string);
1529 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1534 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1535 if (verbosity < 1) {
1539 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1541 struct ofputil_port_stats ps;
1544 retval = ofputil_decode_port_stats(&ps, &b);
1546 if (retval != EOF) {
1547 ds_put_cstr(string, " ***parse error***");
1552 ds_put_cstr(string, " port ");
1553 if (ofp_to_u16(ps.port_no) < 10) {
1554 ds_put_char(string, ' ');
1556 ofputil_format_port(ps.port_no, string);
1558 ds_put_cstr(string, ": rx ");
1559 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1560 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1561 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1562 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1563 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1564 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1565 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1567 ds_put_cstr(string, " tx ");
1568 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1569 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1570 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1571 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1572 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1574 if (ps.duration_sec != UINT32_MAX) {
1575 ds_put_cstr(string, " duration=");
1576 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1577 ds_put_char(string, '\n');
1583 ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh)
1587 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1588 ofpraw_pull_assert(&b);
1591 struct ofputil_table_features features;
1592 struct ofputil_table_stats stats;
1595 retval = ofputil_decode_table_stats_reply(&b, &stats, &features);
1597 if (retval != EOF) {
1598 ofp_print_error(string, retval);
1603 ofp_print_table_features(string, &features, &stats);
1608 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1610 if (queue_id == OFPQ_ALL) {
1611 ds_put_cstr(string, "ALL");
1613 ds_put_format(string, "%"PRIu32, queue_id);
1618 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1620 struct ofputil_queue_stats_request oqsr;
1623 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1625 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1629 ds_put_cstr(string, "port=");
1630 ofputil_format_port(oqsr.port_no, string);
1632 ds_put_cstr(string, " queue=");
1633 ofp_print_queue_name(string, oqsr.queue_id);
1637 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1642 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1643 if (verbosity < 1) {
1647 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1649 struct ofputil_queue_stats qs;
1652 retval = ofputil_decode_queue_stats(&qs, &b);
1654 if (retval != EOF) {
1655 ds_put_cstr(string, " ***parse error***");
1660 ds_put_cstr(string, " port ");
1661 ofputil_format_port(qs.port_no, string);
1662 ds_put_cstr(string, " queue ");
1663 ofp_print_queue_name(string, qs.queue_id);
1664 ds_put_cstr(string, ": ");
1666 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1667 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1668 print_port_stat(string, "errors=", qs.tx_errors, 1);
1670 ds_put_cstr(string, "duration=");
1671 if (qs.duration_sec != UINT32_MAX) {
1672 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1674 ds_put_char(string, '?');
1676 ds_put_char(string, '\n');
1681 ofp_print_ofpst_port_desc_request(struct ds *string,
1682 const struct ofp_header *oh)
1687 error = ofputil_decode_port_desc_stats_request(oh, &port);
1689 ofp_print_error(string, error);
1693 ds_put_cstr(string, " port=");
1694 ofputil_format_port(port, string);
1698 ofp_print_ofpst_port_desc_reply(struct ds *string,
1699 const struct ofp_header *oh)
1703 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1704 ofpraw_pull_assert(&b);
1705 ds_put_char(string, '\n');
1706 ofp_print_phy_ports(string, oh->version, &b);
1710 ofp_print_stats(struct ds *string, const struct ofp_header *oh)
1712 uint16_t flags = ofpmp_flags(oh);
1715 ds_put_cstr(string, " flags=");
1716 if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION)
1717 && (flags & OFPSF_REPLY_MORE)) {
1718 ds_put_cstr(string, "[more]");
1719 flags &= ~OFPSF_REPLY_MORE;
1722 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1729 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1731 size_t len = ntohs(oh->length);
1733 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1734 if (verbosity > 1) {
1735 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1740 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1741 uint64_t generation_id)
1743 ds_put_cstr(string, " role=");
1746 case OFPCR12_ROLE_NOCHANGE:
1747 ds_put_cstr(string, "nochange");
1749 case OFPCR12_ROLE_EQUAL:
1750 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1752 case OFPCR12_ROLE_MASTER:
1753 ds_put_cstr(string, "master");
1755 case OFPCR12_ROLE_SLAVE:
1756 ds_put_cstr(string, "slave");
1762 if (generation_id != UINT64_MAX) {
1763 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1768 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1770 struct ofputil_role_request rr;
1773 error = ofputil_decode_role_message(oh, &rr);
1775 ofp_print_error(string, error);
1779 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1783 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1785 struct ofputil_role_status rs;
1788 error = ofputil_decode_role_status(oh, &rs);
1790 ofp_print_error(string, error);
1794 ofp_print_role_generic(string, rs.role, rs.generation_id);
1796 ds_put_cstr(string, " reason=");
1798 switch (rs.reason) {
1799 case OFPCRR_MASTER_REQUEST:
1800 ds_put_cstr(string, "master_request");
1803 ds_put_cstr(string, "configuration_changed");
1805 case OFPCRR_EXPERIMENTER:
1806 ds_put_cstr(string, "experimenter_data_changed");
1814 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1815 const struct nx_flow_mod_table_id *nfmti)
1817 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1821 ofp_print_nxt_set_flow_format(struct ds *string,
1822 const struct nx_set_flow_format *nsff)
1824 uint32_t format = ntohl(nsff->format);
1826 ds_put_cstr(string, " format=");
1827 if (ofputil_nx_flow_format_is_valid(format)) {
1828 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
1830 ds_put_format(string, "%"PRIu32, format);
1835 ofp_print_nxt_set_packet_in_format(struct ds *string,
1836 const struct nx_set_packet_in_format *nspf)
1838 uint32_t format = ntohl(nspf->format);
1840 ds_put_cstr(string, " format=");
1841 if (ofputil_packet_in_format_is_valid(format)) {
1842 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1844 ds_put_format(string, "%"PRIu32, format);
1848 /* Returns a string form of 'reason'. The return value is either a statically
1849 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1850 * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
1851 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
1853 ofp_port_reason_to_string(enum ofp_port_reason reason,
1854 char *reasonbuf, size_t bufsize)
1867 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1873 ofp_print_nxt_set_async_config(struct ds *string,
1874 const struct nx_async_config *nac)
1878 for (i = 0; i < 2; i++) {
1881 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
1883 ds_put_cstr(string, " PACKET_IN:");
1884 for (j = 0; j < 32; j++) {
1885 if (nac->packet_in_mask[i] & htonl(1u << j)) {
1886 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
1889 reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
1891 ds_put_format(string, " %s", reason);
1894 if (!nac->packet_in_mask[i]) {
1895 ds_put_cstr(string, " (off)");
1897 ds_put_char(string, '\n');
1899 ds_put_cstr(string, " PORT_STATUS:");
1900 for (j = 0; j < 32; j++) {
1901 if (nac->port_status_mask[i] & htonl(1u << j)) {
1902 char reasonbuf[OFP_PORT_REASON_BUFSIZE];
1905 reason = ofp_port_reason_to_string(j, reasonbuf,
1907 ds_put_format(string, " %s", reason);
1910 if (!nac->port_status_mask[i]) {
1911 ds_put_cstr(string, " (off)");
1913 ds_put_char(string, '\n');
1915 ds_put_cstr(string, " FLOW_REMOVED:");
1916 for (j = 0; j < 32; j++) {
1917 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
1918 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
1921 reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
1923 ds_put_format(string, " %s", reason);
1926 if (!nac->flow_removed_mask[i]) {
1927 ds_put_cstr(string, " (off)");
1929 ds_put_char(string, '\n');
1934 ofp_print_nxt_set_controller_id(struct ds *string,
1935 const struct nx_controller_id *nci)
1937 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
1941 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
1942 const struct ofp_header *oh)
1944 ds_put_format(string, " id=%"PRIu32,
1945 ofputil_decode_flow_monitor_cancel(oh));
1949 nx_flow_monitor_flags_to_name(uint32_t bit)
1951 enum nx_flow_monitor_flags fmf = bit;
1954 case NXFMF_INITIAL: return "initial";
1955 case NXFMF_ADD: return "add";
1956 case NXFMF_DELETE: return "delete";
1957 case NXFMF_MODIFY: return "modify";
1958 case NXFMF_ACTIONS: return "actions";
1959 case NXFMF_OWN: return "own";
1966 ofp_print_nxst_flow_monitor_request(struct ds *string,
1967 const struct ofp_header *oh)
1971 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1973 struct ofputil_flow_monitor_request request;
1976 retval = ofputil_decode_flow_monitor_request(&request, &b);
1978 if (retval != EOF) {
1979 ofp_print_error(string, retval);
1984 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
1985 ofp_print_bit_names(string, request.flags,
1986 nx_flow_monitor_flags_to_name, ',');
1988 if (request.out_port != OFPP_NONE) {
1989 ds_put_cstr(string, " out_port=");
1990 ofputil_format_port(request.out_port, string);
1993 if (request.table_id != 0xff) {
1994 ds_put_format(string, " table=%"PRIu8, request.table_id);
1997 ds_put_char(string, ' ');
1998 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
1999 ds_chomp(string, ' ');
2004 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2005 const struct ofp_header *oh)
2007 uint64_t ofpacts_stub[1024 / 8];
2008 struct ofpbuf ofpacts;
2011 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2012 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2014 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2015 struct ofputil_flow_update update;
2019 update.match = &match;
2020 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2022 if (retval != EOF) {
2023 ofp_print_error(string, retval);
2025 ofpbuf_uninit(&ofpacts);
2029 ds_put_cstr(string, "\n event=");
2030 switch (update.event) {
2032 ds_put_cstr(string, "ADDED");
2036 ds_put_format(string, "DELETED reason=%s",
2037 ofp_flow_removed_reason_to_string(update.reason,
2042 case NXFME_MODIFIED:
2043 ds_put_cstr(string, "MODIFIED");
2047 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2051 ds_put_format(string, " table=%"PRIu8, update.table_id);
2052 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2053 ds_put_format(string, " idle_timeout=%"PRIu16,
2054 update.idle_timeout);
2056 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2057 ds_put_format(string, " hard_timeout=%"PRIu16,
2058 update.hard_timeout);
2060 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2062 ds_put_char(string, ' ');
2063 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2065 if (update.ofpacts_len) {
2066 if (string->string[string->length - 1] != ' ') {
2067 ds_put_char(string, ' ');
2069 ds_put_cstr(string, "actions=");
2070 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2076 ofp_print_version(const struct ofp_header *oh,
2079 switch (oh->version) {
2083 ds_put_cstr(string, " (OF1.1)");
2086 ds_put_cstr(string, " (OF1.2)");
2089 ds_put_cstr(string, " (OF1.3)");
2092 ds_put_cstr(string, " (OF1.4)");
2095 ds_put_cstr(string, " (OF1.5)");
2098 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2101 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2105 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2108 ds_put_cstr(string, ofpraw_get_name(raw));
2109 ofp_print_version(oh, string);
2113 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2114 struct list *p_buckets)
2116 static const char *type_str[] = { "all", "select", "indirect",
2118 struct ofputil_bucket *bucket;
2120 ds_put_format(s, "group_id=%"PRIu32",type=%s",
2121 group_id, type_str[type > 4 ? 4 : type]);
2126 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2127 ds_put_cstr(s, ",bucket=");
2129 if (bucket->weight != 1) {
2130 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2132 if (bucket->watch_port != OFPP_NONE) {
2133 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2135 if (bucket->watch_group != OFPG11_ANY) {
2136 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2139 ds_put_cstr(s, "actions=");
2140 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2145 ofp_print_ofpst_group_desc_request(struct ds *string,
2146 const struct ofp_header *oh)
2148 uint32_t group_id = ofputil_decode_group_desc_request(oh);
2149 ds_put_cstr(string, " group_id=");
2150 ofputil_format_group(group_id, string);
2154 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2158 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2160 struct ofputil_group_desc gd;
2163 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2165 if (retval != EOF) {
2166 ds_put_cstr(s, " ***parse error***");
2171 ds_put_char(s, '\n');
2172 ds_put_char(s, ' ');
2173 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets);
2174 ofputil_bucket_list_destroy(&gd.buckets);
2179 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2184 error = ofputil_decode_group_stats_request(oh, &group_id);
2186 ofp_print_error(string, error);
2190 ds_put_cstr(string, " group_id=");
2191 ofputil_format_group(group_id, string);
2195 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2200 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2203 struct ofputil_group_stats gs;
2206 retval = ofputil_decode_group_stats_reply(&b, &gs);
2208 if (retval != EOF) {
2209 ds_put_cstr(s, " ***parse error***");
2214 ds_put_char(s, '\n');
2216 ds_put_char(s, ' ');
2217 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2219 if (gs.duration_sec != UINT32_MAX) {
2220 ds_put_cstr(s, "duration=");
2221 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2222 ds_put_char(s, ',');
2224 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2225 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2226 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2228 for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2229 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2230 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2231 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2232 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2236 free(gs.bucket_stats);
2241 group_type_to_string(enum ofp11_group_type type)
2244 case OFPGT11_ALL: return "all";
2245 case OFPGT11_SELECT: return "select";
2246 case OFPGT11_INDIRECT: return "indirect";
2247 case OFPGT11_FF: return "fast failover";
2248 default: OVS_NOT_REACHED();
2253 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2255 struct ofputil_group_features features;
2258 ofputil_decode_group_features_reply(oh, &features);
2260 ds_put_format(string, "\n Group table:\n");
2261 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2262 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2263 features.capabilities);
2265 for (i = 0; i < OFPGT12_N_TYPES; i++) {
2266 if (features.types & (1u << i)) {
2267 ds_put_format(string, " %s group:\n", group_type_to_string(i));
2268 ds_put_format(string, " max_groups=%#"PRIx32"\n",
2269 features.max_groups[i]);
2270 ds_put_format(string, " actions: ");
2271 ofpact_bitmap_format(features.ofpacts[i], string);
2272 ds_put_char(string, '\n');
2278 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2280 struct ofputil_group_mod gm;
2283 error = ofputil_decode_group_mod(oh, &gm);
2285 ofp_print_error(s, error);
2289 ds_put_char(s, '\n');
2291 ds_put_char(s, ' ');
2292 switch (gm.command) {
2294 ds_put_cstr(s, "ADD");
2297 case OFPGC11_MODIFY:
2298 ds_put_cstr(s, "MOD");
2301 case OFPGC11_DELETE:
2302 ds_put_cstr(s, "DEL");
2306 ds_put_format(s, "cmd:%"PRIu16"", gm.command);
2308 ds_put_char(s, ' ');
2310 ofp_print_group(s, gm.group_id, gm.type, &gm.buckets);
2311 ofputil_bucket_list_destroy(&gm.buckets);
2315 print_table_action_features(struct ds *s,
2316 const struct ofputil_table_action_features *taf)
2319 ds_put_cstr(s, " actions: ");
2320 ofpact_bitmap_format(taf->ofpacts, s);
2321 ds_put_char(s, '\n');
2324 if (!bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS)) {
2327 ds_put_cstr(s, " supported on Set-Field:");
2328 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, taf->set_fields.bm) {
2329 ds_put_format(s, " %s", mf_from_id(i)->name);
2331 ds_put_char(s, '\n');
2336 table_action_features_equal(const struct ofputil_table_action_features *a,
2337 const struct ofputil_table_action_features *b)
2339 return (a->ofpacts == b->ofpacts
2340 && bitmap_equal(a->set_fields.bm, b->set_fields.bm, MFF_N_IDS));
2344 table_action_features_empty(const struct ofputil_table_action_features *taf)
2346 return !taf->ofpacts && bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS);
2350 print_table_instruction_features(
2351 struct ds *s, const struct ofputil_table_instruction_features *tif)
2355 if (!bitmap_is_all_zeros(tif->next, 255)) {
2356 ds_put_cstr(s, " next tables: ");
2357 for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
2358 start = bitmap_scan(tif->next, 1, end, 255)) {
2359 end = bitmap_scan(tif->next, 0, start + 1, 255);
2360 if (end == start + 1) {
2361 ds_put_format(s, "%d,", start);
2363 ds_put_format(s, "%d-%d,", start, end - 1);
2367 if (ds_last(s) == ' ') {
2368 ds_put_cstr(s, "none");
2370 ds_put_char(s, '\n');
2373 if (tif->instructions) {
2374 ds_put_cstr(s, " instructions: ");
2377 for (i = 0; i < 32; i++) {
2378 if (tif->instructions & (1u << i)) {
2379 ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
2383 ds_put_char(s, '\n');
2386 if (!table_action_features_equal(&tif->write, &tif->apply)) {
2387 ds_put_cstr(s, " Write-Actions features:\n");
2388 print_table_action_features(s, &tif->write);
2389 ds_put_cstr(s, " Apply-Actions features:\n");
2390 print_table_action_features(s, &tif->apply);
2391 } else if (tif->write.ofpacts
2392 || !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
2393 ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
2394 print_table_action_features(s, &tif->write);
2399 table_instruction_features_equal(
2400 const struct ofputil_table_instruction_features *a,
2401 const struct ofputil_table_instruction_features *b)
2403 return (bitmap_equal(a->next, b->next, 255)
2404 && a->instructions == b->instructions
2405 && table_action_features_equal(&a->write, &b->write)
2406 && table_action_features_equal(&a->apply, &b->apply));
2410 table_instruction_features_empty(
2411 const struct ofputil_table_instruction_features *tif)
2413 return (bitmap_is_all_zeros(tif->next, 255)
2414 && !tif->instructions
2415 && table_action_features_empty(&tif->write)
2416 && table_action_features_empty(&tif->apply));
2420 ofp_print_table_features(struct ds *s,
2421 const struct ofputil_table_features *features,
2422 const struct ofputil_table_stats *stats)
2426 ds_put_format(s, "\n table %"PRIu8, features->table_id);
2427 if (features->name[0]) {
2428 ds_put_format(s, " (\"%s\")", features->name);
2430 ds_put_cstr(s, ":\n");
2432 ds_put_format(s, " active=%"PRIu32", ", stats->active_count);
2433 ds_put_format(s, "lookup=%"PRIu64", ", stats->lookup_count);
2434 ds_put_format(s, "matched=%"PRIu64"\n", stats->matched_count);
2436 if (features->metadata_match || features->metadata_match) {
2437 ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
2438 ntohll(features->metadata_match),
2439 ntohll(features->metadata_write));
2442 if (features->miss_config != OFPUTIL_TABLE_MISS_DEFAULT) {
2443 ds_put_cstr(s, " config=");
2444 ofp_print_table_miss_config(s, features->miss_config);
2447 if (features->max_entries) {
2448 ds_put_format(s, " max_entries=%"PRIu32"\n", features->max_entries);
2451 if (!table_instruction_features_equal(&features->nonmiss,
2453 ds_put_cstr(s, " instructions (other than table miss):\n");
2454 print_table_instruction_features(s, &features->nonmiss);
2455 ds_put_cstr(s, " instructions (table miss):\n");
2456 print_table_instruction_features(s, &features->miss);
2457 } else if (!table_instruction_features_empty(&features->nonmiss)) {
2458 ds_put_cstr(s, " instructions (table miss and others):\n");
2459 print_table_instruction_features(s, &features->nonmiss);
2462 if (!bitmap_is_all_zeros(features->match.bm, MFF_N_IDS)){
2463 ds_put_cstr(s, " matching:\n");
2464 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) {
2465 const struct mf_field *f = mf_from_id(i);
2466 bool mask = bitmap_is_set(features->mask.bm, i);
2467 bool wildcard = bitmap_is_set(features->wildcard.bm, i);
2469 ds_put_format(s, " %s: %s\n",
2471 (mask ? "arbitrary mask"
2472 : wildcard ? "exact match or wildcard"
2473 : "must exact match"));
2479 ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh)
2483 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2486 struct ofputil_table_features tf;
2489 retval = ofputil_decode_table_features(&b, &tf, true);
2491 if (retval != EOF) {
2492 ofp_print_error(s, retval);
2496 ofp_print_table_features(s, &tf, NULL);
2501 bundle_flags_to_name(uint32_t bit)
2514 ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh)
2517 struct ofputil_bundle_ctrl_msg bctrl;
2519 error = ofputil_decode_bundle_ctrl(oh, &bctrl);
2521 ofp_print_error(s, error);
2525 ds_put_char(s, '\n');
2527 ds_put_format(s, " bundle_id=%#"PRIx32" type=", bctrl.bundle_id);
2528 switch (bctrl.type) {
2529 case OFPBCT_OPEN_REQUEST:
2530 ds_put_cstr(s, "OPEN_REQUEST");
2532 case OFPBCT_OPEN_REPLY:
2533 ds_put_cstr(s, "OPEN_REPLY");
2535 case OFPBCT_CLOSE_REQUEST:
2536 ds_put_cstr(s, "CLOSE_REQUEST");
2538 case OFPBCT_CLOSE_REPLY:
2539 ds_put_cstr(s, "CLOSE_REPLY");
2541 case OFPBCT_COMMIT_REQUEST:
2542 ds_put_cstr(s, "COMMIT_REQUEST");
2544 case OFPBCT_COMMIT_REPLY:
2545 ds_put_cstr(s, "COMMIT_REPLY");
2547 case OFPBCT_DISCARD_REQUEST:
2548 ds_put_cstr(s, "DISCARD_REQUEST");
2550 case OFPBCT_DISCARD_REPLY:
2551 ds_put_cstr(s, "DISCARD_REPLY");
2555 ds_put_cstr(s, " flags=");
2556 ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' ');
2560 ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
2563 struct ofputil_bundle_add_msg badd;
2566 error = ofputil_decode_bundle_add(oh, &badd);
2568 ofp_print_error(s, error);
2572 ds_put_char(s, '\n');
2573 ds_put_format(s, " bundle_id=%#"PRIx32, badd.bundle_id);
2574 ds_put_cstr(s, " flags=");
2575 ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
2577 ds_put_char(s, '\n');
2578 msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
2580 ds_put_cstr(s, msg);
2585 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2586 struct ds *string, int verbosity)
2588 const void *msg = oh;
2590 ofp_header_to_string__(oh, raw, string);
2591 switch (ofptype_from_ofpraw(raw)) {
2593 case OFPTYPE_GROUP_STATS_REQUEST:
2594 ofp_print_stats(string, oh);
2595 ofp_print_ofpst_group_request(string, oh);
2598 case OFPTYPE_GROUP_STATS_REPLY:
2599 ofp_print_group_stats(string, oh);
2602 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
2603 ofp_print_stats(string, oh);
2604 ofp_print_ofpst_group_desc_request(string, oh);
2607 case OFPTYPE_GROUP_DESC_STATS_REPLY:
2608 ofp_print_group_desc(string, oh);
2611 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
2612 ofp_print_stats(string, oh);
2615 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
2616 ofp_print_group_features(string, oh);
2619 case OFPTYPE_GROUP_MOD:
2620 ofp_print_group_mod(string, oh);
2623 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
2624 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
2625 ofp_print_table_features_reply(string, oh);
2629 ofp_print_hello(string, oh);
2633 ofp_print_error_msg(string, oh);
2636 case OFPTYPE_ECHO_REQUEST:
2637 case OFPTYPE_ECHO_REPLY:
2638 ofp_print_echo(string, oh, verbosity);
2641 case OFPTYPE_FEATURES_REQUEST:
2644 case OFPTYPE_FEATURES_REPLY:
2645 ofp_print_switch_features(string, oh);
2648 case OFPTYPE_GET_CONFIG_REQUEST:
2651 case OFPTYPE_GET_CONFIG_REPLY:
2652 case OFPTYPE_SET_CONFIG:
2653 ofp_print_switch_config(string, ofpmsg_body(oh));
2656 case OFPTYPE_PACKET_IN:
2657 ofp_print_packet_in(string, oh, verbosity);
2660 case OFPTYPE_FLOW_REMOVED:
2661 ofp_print_flow_removed(string, oh);
2664 case OFPTYPE_PORT_STATUS:
2665 ofp_print_port_status(string, oh);
2668 case OFPTYPE_PACKET_OUT:
2669 ofp_print_packet_out(string, oh, verbosity);
2672 case OFPTYPE_FLOW_MOD:
2673 ofp_print_flow_mod(string, oh, verbosity);
2676 case OFPTYPE_PORT_MOD:
2677 ofp_print_port_mod(string, oh);
2680 case OFPTYPE_TABLE_MOD:
2681 ofp_print_table_mod(string, oh);
2684 case OFPTYPE_METER_MOD:
2685 ofp_print_meter_mod(string, oh);
2688 case OFPTYPE_BARRIER_REQUEST:
2689 case OFPTYPE_BARRIER_REPLY:
2692 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
2693 ofp_print_queue_get_config_request(string, oh);
2696 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
2697 ofp_print_queue_get_config_reply(string, oh);
2700 case OFPTYPE_ROLE_REQUEST:
2701 case OFPTYPE_ROLE_REPLY:
2702 ofp_print_role_message(string, oh);
2704 case OFPTYPE_ROLE_STATUS:
2705 ofp_print_role_status_message(string, oh);
2708 case OFPTYPE_METER_STATS_REQUEST:
2709 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
2710 ofp_print_stats(string, oh);
2711 ofp_print_meter_stats_request(string, oh);
2714 case OFPTYPE_METER_STATS_REPLY:
2715 ofp_print_stats(string, oh);
2716 ofp_print_meter_stats_reply(string, oh);
2719 case OFPTYPE_METER_CONFIG_STATS_REPLY:
2720 ofp_print_stats(string, oh);
2721 ofp_print_meter_config_reply(string, oh);
2724 case OFPTYPE_METER_FEATURES_STATS_REPLY:
2725 ofp_print_stats(string, oh);
2726 ofp_print_meter_features_reply(string, oh);
2729 case OFPTYPE_DESC_STATS_REQUEST:
2730 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
2731 ofp_print_stats(string, oh);
2734 case OFPTYPE_FLOW_STATS_REQUEST:
2735 case OFPTYPE_AGGREGATE_STATS_REQUEST:
2736 ofp_print_stats(string, oh);
2737 ofp_print_flow_stats_request(string, oh);
2740 case OFPTYPE_TABLE_STATS_REQUEST:
2741 ofp_print_stats(string, oh);
2744 case OFPTYPE_PORT_STATS_REQUEST:
2745 ofp_print_stats(string, oh);
2746 ofp_print_ofpst_port_request(string, oh);
2749 case OFPTYPE_QUEUE_STATS_REQUEST:
2750 ofp_print_stats(string, oh);
2751 ofp_print_ofpst_queue_request(string, oh);
2754 case OFPTYPE_DESC_STATS_REPLY:
2755 ofp_print_stats(string, oh);
2756 ofp_print_ofpst_desc_reply(string, oh);
2759 case OFPTYPE_FLOW_STATS_REPLY:
2760 ofp_print_stats(string, oh);
2761 ofp_print_flow_stats_reply(string, oh);
2764 case OFPTYPE_QUEUE_STATS_REPLY:
2765 ofp_print_stats(string, oh);
2766 ofp_print_ofpst_queue_reply(string, oh, verbosity);
2769 case OFPTYPE_PORT_STATS_REPLY:
2770 ofp_print_stats(string, oh);
2771 ofp_print_ofpst_port_reply(string, oh, verbosity);
2774 case OFPTYPE_TABLE_STATS_REPLY:
2775 ofp_print_stats(string, oh);
2776 ofp_print_table_stats_reply(string, oh);
2779 case OFPTYPE_AGGREGATE_STATS_REPLY:
2780 ofp_print_stats(string, oh);
2781 ofp_print_aggregate_stats_reply(string, oh);
2784 case OFPTYPE_PORT_DESC_STATS_REQUEST:
2785 ofp_print_stats(string, oh);
2786 ofp_print_ofpst_port_desc_request(string, oh);
2789 case OFPTYPE_PORT_DESC_STATS_REPLY:
2790 ofp_print_stats(string, oh);
2791 ofp_print_ofpst_port_desc_reply(string, oh);
2794 case OFPTYPE_FLOW_MOD_TABLE_ID:
2795 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
2798 case OFPTYPE_SET_FLOW_FORMAT:
2799 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
2802 case OFPTYPE_SET_PACKET_IN_FORMAT:
2803 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
2806 case OFPTYPE_FLOW_AGE:
2809 case OFPTYPE_SET_CONTROLLER_ID:
2810 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
2813 case OFPTYPE_GET_ASYNC_REPLY:
2814 case OFPTYPE_SET_ASYNC_CONFIG:
2815 ofp_print_nxt_set_async_config(string, ofpmsg_body(oh));
2817 case OFPTYPE_GET_ASYNC_REQUEST:
2819 case OFPTYPE_FLOW_MONITOR_CANCEL:
2820 ofp_print_nxt_flow_monitor_cancel(string, msg);
2823 case OFPTYPE_FLOW_MONITOR_PAUSED:
2824 case OFPTYPE_FLOW_MONITOR_RESUMED:
2827 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
2828 ofp_print_nxst_flow_monitor_request(string, msg);
2831 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
2832 ofp_print_nxst_flow_monitor_reply(string, msg);
2835 case OFPTYPE_BUNDLE_CONTROL:
2836 ofp_print_bundle_ctrl(string, msg);
2839 case OFPTYPE_BUNDLE_ADD_MESSAGE:
2840 ofp_print_bundle_add(string, msg, verbosity);
2845 /* Composes and returns a string representing the OpenFlow packet of 'len'
2846 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
2847 * verbosity and higher numbers increase verbosity. The caller is responsible
2848 * for freeing the string. */
2850 ofp_to_string(const void *oh_, size_t len, int verbosity)
2852 struct ds string = DS_EMPTY_INITIALIZER;
2853 const struct ofp_header *oh = oh_;
2856 ds_put_cstr(&string, "OpenFlow message is empty\n");
2857 } else if (len < sizeof(struct ofp_header)) {
2858 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
2860 } else if (ntohs(oh->length) > len) {
2864 error = ofpraw_decode_partial(&raw, oh, len);
2866 ofp_header_to_string__(oh, raw, &string);
2867 ds_put_char(&string, '\n');
2870 ds_put_format(&string,
2871 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
2872 len, ntohs(oh->length));
2873 } else if (ntohs(oh->length) < len) {
2874 ds_put_format(&string,
2875 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
2876 ntohs(oh->length), len);
2881 error = ofpraw_decode(&raw, oh);
2883 ofp_to_string__(oh, raw, &string, verbosity);
2884 if (verbosity >= 5) {
2885 if (ds_last(&string) != '\n') {
2886 ds_put_char(&string, '\n');
2888 ds_put_hex_dump(&string, oh, len, 0, true);
2890 if (ds_last(&string) != '\n') {
2891 ds_put_char(&string, '\n');
2893 return ds_steal_cstr(&string);
2896 ofp_print_error(&string, error);
2898 ds_put_hex_dump(&string, oh, len, 0, true);
2899 return ds_steal_cstr(&string);
2903 print_and_free(FILE *stream, char *string)
2905 fputs(string, stream);
2909 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
2910 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
2911 * numbers increase verbosity. */
2913 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
2915 print_and_free(stream, ofp_to_string(oh, len, verbosity));
2918 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
2919 * 'data' to 'stream'. */
2921 ofp_print_packet(FILE *stream, const void *data, size_t len)
2923 print_and_free(stream, ofp_packet_to_string(data, len));