2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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);
56 /* Returns a string that represents the contents of the Ethernet frame in the
57 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
59 ofp_packet_to_string(const void *data, size_t len)
61 struct ds ds = DS_EMPTY_INITIALIZER;
66 dp_packet_use_const(&buf, data, len);
67 flow_extract(&buf, &flow);
68 flow_format(&ds, &flow);
70 l4_size = dp_packet_l4_size(&buf);
72 if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
73 struct tcp_header *th = dp_packet_l4(&buf);
74 ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum));
75 } else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
76 struct udp_header *uh = dp_packet_l4(&buf);
77 ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum));
78 } else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) {
79 struct sctp_header *sh = dp_packet_l4(&buf);
80 ds_put_format(&ds, " sctp_csum:%"PRIx32,
81 ntohl(get_16aligned_be32(&sh->sctp_csum)));
82 } else if (flow.nw_proto == IPPROTO_ICMP && l4_size >= ICMP_HEADER_LEN) {
83 struct icmp_header *icmph = dp_packet_l4(&buf);
84 ds_put_format(&ds, " icmp_csum:%"PRIx16,
85 ntohs(icmph->icmp_csum));
86 } else if (flow.nw_proto == IPPROTO_ICMPV6 && l4_size >= ICMP6_HEADER_LEN) {
87 struct icmp6_header *icmp6h = dp_packet_l4(&buf);
88 ds_put_format(&ds, " icmp6_csum:%"PRIx16,
89 ntohs(icmp6h->icmp6_cksum));
92 ds_put_char(&ds, '\n');
98 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
101 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
102 struct ofputil_packet_in pin;
105 error = ofputil_decode_packet_in(&pin, oh);
107 ofp_print_error(string, error);
112 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
115 if (pin.cookie != OVS_BE64_MAX) {
116 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
119 ds_put_format(string, " total_len=%"PRIuSIZE" ", pin.total_len);
121 match_format(&pin.flow_metadata, string, OFP_DEFAULT_PRIORITY);
123 ds_put_format(string, " (via %s)",
124 ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
127 ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len);
128 if (pin.buffer_id == UINT32_MAX) {
129 ds_put_format(string, " (unbuffered)");
130 if (pin.total_len != pin.packet_len) {
131 ds_put_format(string, " (***total_len != data_len***)");
134 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
135 if (pin.total_len < pin.packet_len) {
136 ds_put_format(string, " (***total_len < data_len***)");
139 ds_put_char(string, '\n');
142 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
143 ds_put_cstr(string, packet);
147 ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false);
152 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
155 struct ofputil_packet_out po;
156 struct ofpbuf ofpacts;
159 ofpbuf_init(&ofpacts, 64);
160 error = ofputil_decode_packet_out(&po, oh, &ofpacts);
162 ofpbuf_uninit(&ofpacts);
163 ofp_print_error(string, error);
167 ds_put_cstr(string, " in_port=");
168 ofputil_format_port(po.in_port, string);
170 ds_put_cstr(string, " actions=");
171 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
173 if (po.buffer_id == UINT32_MAX) {
174 ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
175 if (verbosity > 0 && po.packet_len > 0) {
176 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
177 ds_put_char(string, '\n');
178 ds_put_cstr(string, packet);
182 ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
185 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
188 ofpbuf_uninit(&ofpacts);
191 /* qsort comparison function. */
193 compare_ports(const void *a_, const void *b_)
195 const struct ofputil_phy_port *a = a_;
196 const struct ofputil_phy_port *b = b_;
197 uint16_t ap = ofp_to_u16(a->port_no);
198 uint16_t bp = ofp_to_u16(b->port_no);
200 return ap < bp ? -1 : ap > bp;
204 ofp_print_bit_names(struct ds *string, uint32_t bits,
205 const char *(*bit_to_name)(uint32_t bit),
212 ds_put_cstr(string, "0");
216 for (i = 0; i < 32; i++) {
217 uint32_t bit = UINT32_C(1) << i;
220 const char *name = bit_to_name(bit);
223 ds_put_char(string, separator);
225 ds_put_cstr(string, name);
233 ds_put_char(string, separator);
235 ds_put_format(string, "0x%"PRIx32, bits);
240 netdev_feature_to_name(uint32_t bit)
242 enum netdev_features f = bit;
245 case NETDEV_F_10MB_HD: return "10MB-HD";
246 case NETDEV_F_10MB_FD: return "10MB-FD";
247 case NETDEV_F_100MB_HD: return "100MB-HD";
248 case NETDEV_F_100MB_FD: return "100MB-FD";
249 case NETDEV_F_1GB_HD: return "1GB-HD";
250 case NETDEV_F_1GB_FD: return "1GB-FD";
251 case NETDEV_F_10GB_FD: return "10GB-FD";
252 case NETDEV_F_40GB_FD: return "40GB-FD";
253 case NETDEV_F_100GB_FD: return "100GB-FD";
254 case NETDEV_F_1TB_FD: return "1TB-FD";
255 case NETDEV_F_OTHER: return "OTHER";
256 case NETDEV_F_COPPER: return "COPPER";
257 case NETDEV_F_FIBER: return "FIBER";
258 case NETDEV_F_AUTONEG: return "AUTO_NEG";
259 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
260 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
267 ofp_print_port_features(struct ds *string, enum netdev_features features)
269 ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
270 ds_put_char(string, '\n');
274 ofputil_port_config_to_name(uint32_t bit)
276 enum ofputil_port_config pc = bit;
279 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
280 case OFPUTIL_PC_NO_STP: return "NO_STP";
281 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
282 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
283 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
284 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
285 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
292 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
294 ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
295 ds_put_char(string, '\n');
299 ofputil_port_state_to_name(uint32_t bit)
301 enum ofputil_port_state ps = bit;
304 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
305 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
306 case OFPUTIL_PS_LIVE: return "LIVE";
308 case OFPUTIL_PS_STP_LISTEN:
309 case OFPUTIL_PS_STP_LEARN:
310 case OFPUTIL_PS_STP_FORWARD:
311 case OFPUTIL_PS_STP_BLOCK:
312 /* Handled elsewhere. */
320 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
322 enum ofputil_port_state stp_state;
324 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
325 * pattern. We have to special case it.
327 * OVS doesn't support STP, so this field will always be 0 if we are
328 * talking to OVS, so we'd always print STP_LISTEN in that case.
329 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
330 * avoid confusing users. */
331 stp_state = state & OFPUTIL_PS_STP_MASK;
334 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
335 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
337 state &= ~OFPUTIL_PS_STP_MASK;
339 ofp_print_bit_names(string, state, ofputil_port_state_to_name,
343 ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
345 ds_put_char(string, '\n');
349 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
351 char name[sizeof port->name];
354 memcpy(name, port->name, sizeof name);
355 for (j = 0; j < sizeof name - 1; j++) {
356 if (!isprint((unsigned char) name[j])) {
362 ds_put_char(string, ' ');
363 ofputil_format_port(port->port_no, string);
364 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
365 name, ETH_ADDR_ARGS(port->hw_addr));
367 ds_put_cstr(string, " config: ");
368 ofp_print_port_config(string, port->config);
370 ds_put_cstr(string, " state: ");
371 ofp_print_port_state(string, port->state);
374 ds_put_format(string, " current: ");
375 ofp_print_port_features(string, port->curr);
377 if (port->advertised) {
378 ds_put_format(string, " advertised: ");
379 ofp_print_port_features(string, port->advertised);
381 if (port->supported) {
382 ds_put_format(string, " supported: ");
383 ofp_print_port_features(string, port->supported);
386 ds_put_format(string, " peer: ");
387 ofp_print_port_features(string, port->peer);
389 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
390 "%"PRIu32" Mbps max\n",
391 port->curr_speed / UINT32_C(1000),
392 port->max_speed / UINT32_C(1000));
395 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
396 * 'ofp_version', writes a detailed description of each port into
399 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
402 struct ofputil_phy_port *ports;
403 size_t allocated_ports, n_ports;
409 for (n_ports = 0; ; n_ports++) {
410 if (n_ports >= allocated_ports) {
411 ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
414 retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
420 qsort(ports, n_ports, sizeof *ports, compare_ports);
421 for (i = 0; i < n_ports; i++) {
422 ofp_print_phy_port(string, &ports[i]);
427 ofp_print_error(string, retval);
432 ofputil_capabilities_to_name(uint32_t bit)
434 enum ofputil_capabilities capabilities = bit;
436 switch (capabilities) {
437 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
438 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
439 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
440 case OFPUTIL_C_IP_REASM: return "IP_REASM";
441 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
442 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
443 case OFPUTIL_C_STP: return "STP";
444 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
445 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
452 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
454 struct ofputil_switch_features features;
458 error = ofputil_decode_switch_features(oh, &features, &b);
460 ofp_print_error(string, error);
464 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
466 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
467 features.n_tables, features.n_buffers);
468 if (features.auxiliary_id) {
469 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
471 ds_put_char(string, '\n');
473 ds_put_cstr(string, "capabilities: ");
474 ofp_print_bit_names(string, features.capabilities,
475 ofputil_capabilities_to_name, ' ');
476 ds_put_char(string, '\n');
478 switch ((enum ofp_version)oh->version) {
480 ds_put_cstr(string, "actions: ");
481 ofpact_bitmap_format(features.ofpacts, string);
482 ds_put_char(string, '\n');
490 return; /* no ports in ofp13_switch_features */
495 ofp_print_phy_ports(string, oh->version, &b);
499 ofp_print_switch_config(struct ds *string,
500 const struct ofputil_switch_config *config)
502 ds_put_format(string, " frags=%s",
503 ofputil_frag_handling_to_string(config->frag));
505 if (config->invalid_ttl_to_controller > 0) {
506 ds_put_format(string, " invalid_ttl_to_controller");
509 ds_put_format(string, " miss_send_len=%"PRIu16"\n", config->miss_send_len);
513 ofp_print_set_config(struct ds *string, const struct ofp_header *oh)
515 struct ofputil_switch_config config;
518 error = ofputil_decode_set_config(oh, &config);
520 ofp_print_error(string, error);
523 ofp_print_switch_config(string, &config);
527 ofp_print_get_config_reply(struct ds *string, const struct ofp_header *oh)
529 struct ofputil_switch_config config;
530 ofputil_decode_get_config_reply(oh, &config);
531 ofp_print_switch_config(string, &config);
534 static void print_wild(struct ds *string, const char *leader, int is_wild,
535 int verbosity, const char *format, ...)
536 OVS_PRINTF_FORMAT(5, 6);
538 static void print_wild(struct ds *string, const char *leader, int is_wild,
539 int verbosity, const char *format, ...)
541 if (is_wild && verbosity < 2) {
544 ds_put_cstr(string, leader);
548 va_start(args, format);
549 ds_put_format_valist(string, format, args);
552 ds_put_char(string, '*');
554 ds_put_char(string, ',');
558 print_wild_port(struct ds *string, const char *leader, int is_wild,
559 int verbosity, ofp_port_t port)
561 if (is_wild && verbosity < 2) {
564 ds_put_cstr(string, leader);
566 ofputil_format_port(port, string);
568 ds_put_char(string, '*');
570 ds_put_char(string, ',');
574 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
575 uint32_t wild_bits, int verbosity)
577 if (wild_bits >= 32 && verbosity < 2) {
580 ds_put_cstr(string, leader);
581 if (wild_bits < 32) {
582 ds_put_format(string, IP_FMT, IP_ARGS(ip));
584 ds_put_format(string, "/%d", 32 - wild_bits);
587 ds_put_char(string, '*');
589 ds_put_char(string, ',');
593 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
595 char *s = ofp10_match_to_string(om, verbosity);
601 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
603 struct ds f = DS_EMPTY_INITIALIZER;
604 uint32_t w = ntohl(om->wildcards);
605 bool skip_type = false;
606 bool skip_proto = false;
608 if (!(w & OFPFW10_DL_TYPE)) {
610 if (om->dl_type == htons(ETH_TYPE_IP)) {
611 if (!(w & OFPFW10_NW_PROTO)) {
613 if (om->nw_proto == IPPROTO_ICMP) {
614 ds_put_cstr(&f, "icmp,");
615 } else if (om->nw_proto == IPPROTO_TCP) {
616 ds_put_cstr(&f, "tcp,");
617 } else if (om->nw_proto == IPPROTO_UDP) {
618 ds_put_cstr(&f, "udp,");
619 } else if (om->nw_proto == IPPROTO_SCTP) {
620 ds_put_cstr(&f, "sctp,");
622 ds_put_cstr(&f, "ip,");
626 ds_put_cstr(&f, "ip,");
628 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
629 ds_put_cstr(&f, "arp,");
630 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
631 ds_put_cstr(&f, "rarp,");
632 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
633 ds_put_cstr(&f, "mpls,");
634 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
635 ds_put_cstr(&f, "mplsm,");
640 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
641 u16_to_ofp(ntohs(om->in_port)));
642 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
643 "%d", ntohs(om->dl_vlan));
644 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
645 "%d", om->dl_vlan_pcp);
646 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
647 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
648 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
649 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
651 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
652 "0x%04x", ntohs(om->dl_type));
654 print_ip_netmask(&f, "nw_src=", om->nw_src,
655 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
657 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
658 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
661 if (om->dl_type == htons(ETH_TYPE_ARP) ||
662 om->dl_type == htons(ETH_TYPE_RARP)) {
663 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
666 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
670 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
672 if (om->nw_proto == IPPROTO_ICMP) {
673 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
674 "%d", ntohs(om->tp_src));
675 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
676 "%d", ntohs(om->tp_dst));
678 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
679 "%d", ntohs(om->tp_src));
680 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
681 "%d", ntohs(om->tp_dst));
688 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
690 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
691 ds_put_cstr(s, "send_flow_rem ");
693 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
694 ds_put_cstr(s, "check_overlap ");
696 if (flags & OFPUTIL_FF_RESET_COUNTS) {
697 ds_put_cstr(s, "reset_counts ");
699 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
700 ds_put_cstr(s, "no_packet_counts ");
702 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
703 ds_put_cstr(s, "no_byte_counts ");
705 if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
706 ds_put_cstr(s, "allow_hidden_fields ");
708 if (flags & OFPUTIL_FF_NO_READONLY) {
709 ds_put_cstr(s, "no_readonly_table ");
714 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
716 struct ofputil_flow_mod fm;
717 struct ofpbuf ofpacts;
721 enum ofputil_protocol protocol;
723 protocol = ofputil_protocol_from_ofp_version(oh->version);
724 protocol = ofputil_protocol_set_tid(protocol, true);
726 ofpbuf_init(&ofpacts, 64);
727 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
730 ofpbuf_uninit(&ofpacts);
731 ofp_print_error(s, error);
736 switch (fm.command) {
738 ds_put_cstr(s, "ADD");
741 ds_put_cstr(s, "MOD");
743 case OFPFC_MODIFY_STRICT:
744 ds_put_cstr(s, "MOD_STRICT");
747 ds_put_cstr(s, "DEL");
749 case OFPFC_DELETE_STRICT:
750 ds_put_cstr(s, "DEL_STRICT");
753 ds_put_format(s, "cmd:%d", fm.command);
755 if (fm.table_id != 0) {
756 ds_put_format(s, " table:%d", fm.table_id);
760 ofpraw_decode(&raw, oh);
761 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
762 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
763 ofp10_match_print(s, &ofm->match, verbosity);
765 /* ofp_print_match() doesn't print priority. */
766 need_priority = true;
767 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
768 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
769 const void *nxm = nfm + 1;
772 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
773 ds_put_cstr(s, nxm_s);
776 /* nx_match_to_string() doesn't print priority. */
777 need_priority = true;
779 match_format(&fm.match, s, fm.priority);
781 /* match_format() does print priority. */
782 need_priority = false;
785 if (ds_last(s) != ' ') {
788 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
789 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
791 if (fm.cookie_mask != htonll(0)) {
792 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
793 ntohll(fm.cookie), ntohll(fm.cookie_mask));
795 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
796 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
798 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
799 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
801 if (fm.importance != 0) {
802 ds_put_format(s, "importance:%"PRIu16" ", fm.importance);
804 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
805 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
807 if (fm.buffer_id != UINT32_MAX) {
808 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
810 if (fm.out_port != OFPP_ANY) {
811 ds_put_format(s, "out_port:");
812 ofputil_format_port(fm.out_port, s);
816 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
817 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
818 * versions don't really have such a flag and printing one is likely to
820 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
822 ofp_print_flow_flags(s, fm.flags);
824 ds_put_cstr(s, "actions=");
825 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
826 ofpbuf_uninit(&ofpacts);
830 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
832 ds_put_format(string, "%u", sec);
834 /* If there are no fractional seconds, don't print any decimals.
836 * If the fractional seconds can be expressed exactly as milliseconds,
837 * print 3 decimals. Open vSwitch provides millisecond precision for most
838 * time measurements, so printing 3 decimals every time makes it easier to
839 * spot real changes in flow dumps that refresh themselves quickly.
841 * If the fractional seconds are more precise than milliseconds, print the
842 * number of decimals needed to express them exactly.
845 unsigned int msec = nsec / 1000000;
846 if (msec * 1000000 == nsec) {
847 ds_put_format(string, ".%03u", msec);
849 ds_put_format(string, ".%09u", nsec);
850 while (string->string[string->length - 1] == '0') {
855 ds_put_char(string, 's');
858 /* Returns a string form of 'reason'. The return value is either a statically
859 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
860 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
861 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
863 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
864 char *reasonbuf, size_t bufsize)
867 case OFPRR_IDLE_TIMEOUT:
869 case OFPRR_HARD_TIMEOUT:
873 case OFPRR_GROUP_DELETE:
874 return "group_delete";
877 case OFPRR_METER_DELETE:
878 return "meter_delete";
881 snprintf(reasonbuf, bufsize, "%d", (int) reason);
887 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
889 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
890 struct ofputil_flow_removed fr;
893 error = ofputil_decode_flow_removed(&fr, oh);
895 ofp_print_error(string, error);
899 ds_put_char(string, ' ');
900 match_format(&fr.match, string, fr.priority);
902 ds_put_format(string, " reason=%s",
903 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
906 if (fr.table_id != 255) {
907 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
910 if (fr.cookie != htonll(0)) {
911 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
913 ds_put_cstr(string, " duration");
914 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
915 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
916 if (fr.hard_timeout) {
917 /* The hard timeout was only added in OF1.2, so only print it if it is
918 * actually in use to avoid gratuitous change to the formatting. */
919 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
921 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
922 fr.packet_count, fr.byte_count);
926 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
928 struct ofputil_port_mod pm;
931 error = ofputil_decode_port_mod(oh, &pm, true);
933 ofp_print_error(string, error);
937 ds_put_cstr(string, " port: ");
938 ofputil_format_port(pm.port_no, string);
939 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
940 ETH_ADDR_ARGS(pm.hw_addr));
942 ds_put_cstr(string, " config: ");
943 ofp_print_port_config(string, pm.config);
945 ds_put_cstr(string, " mask: ");
946 ofp_print_port_config(string, pm.mask);
948 ds_put_cstr(string, " advertise: ");
950 ofp_print_port_features(string, pm.advertise);
952 ds_put_cstr(string, "UNCHANGED\n");
957 ofputil_table_miss_to_string(enum ofputil_table_miss miss)
960 case OFPUTIL_TABLE_MISS_DEFAULT: return "default";
961 case OFPUTIL_TABLE_MISS_CONTROLLER: return "controller";
962 case OFPUTIL_TABLE_MISS_CONTINUE: return "continue";
963 case OFPUTIL_TABLE_MISS_DROP: return "drop";
964 default: return "***error***";
969 ofputil_table_eviction_to_string(enum ofputil_table_eviction eviction)
972 case OFPUTIL_TABLE_EVICTION_DEFAULT: return "default";
973 case OFPUTIL_TABLE_EVICTION_ON: return "on";
974 case OFPUTIL_TABLE_EVICTION_OFF: return "off";
975 default: return "***error***";
981 ofputil_eviction_flag_to_string(uint32_t bit)
983 enum ofp14_table_mod_prop_eviction_flag eviction_flag = bit;
985 switch (eviction_flag) {
986 case OFPTMPEF14_OTHER: return "OTHER";
987 case OFPTMPEF14_IMPORTANCE: return "IMPORTANCE";
988 case OFPTMPEF14_LIFETIME: return "LIFETIME";
994 /* Appends to 'string' a description of the bitmap of OFPTMPEF14_* values in
995 * 'eviction_flags'. */
997 ofputil_put_eviction_flags(struct ds *string, uint32_t eviction_flags)
999 if (eviction_flags != UINT32_MAX) {
1000 ofp_print_bit_names(string, eviction_flags,
1001 ofputil_eviction_flag_to_string, '|');
1003 ds_put_cstr(string, "(default)");
1008 ofputil_table_vacancy_to_string(enum ofputil_table_vacancy vacancy)
1011 case OFPUTIL_TABLE_VACANCY_DEFAULT: return "default";
1012 case OFPUTIL_TABLE_VACANCY_ON: return "on";
1013 case OFPUTIL_TABLE_VACANCY_OFF: return "off";
1014 default: return "***error***";
1020 ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
1022 struct ofputil_table_mod pm;
1025 error = ofputil_decode_table_mod(oh, &pm);
1027 ofp_print_error(string, error);
1031 if (pm.table_id == 0xff) {
1032 ds_put_cstr(string, " table_id: ALL_TABLES");
1034 ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
1037 if (pm.miss != OFPUTIL_TABLE_MISS_DEFAULT) {
1038 ds_put_format(string, ", flow_miss_config=%s",
1039 ofputil_table_miss_to_string(pm.miss));
1041 if (pm.eviction != OFPUTIL_TABLE_EVICTION_DEFAULT) {
1042 ds_put_format(string, ", eviction=%s",
1043 ofputil_table_eviction_to_string(pm.eviction));
1045 if (pm.eviction_flags != UINT32_MAX) {
1046 ds_put_cstr(string, "eviction_flags=");
1047 ofputil_put_eviction_flags(string, pm.eviction_flags);
1049 if (pm.vacancy != OFPUTIL_TABLE_VACANCY_DEFAULT) {
1050 ds_put_format(string, ", vacancy=%s",
1051 ofputil_table_vacancy_to_string(pm.vacancy));
1052 if (pm.vacancy == OFPUTIL_TABLE_VACANCY_ON) {
1053 ds_put_format(string, " vacancy:%"PRIu8""
1054 ",%"PRIu8"", pm.table_vacancy.vacancy_down,
1055 pm.table_vacancy.vacancy_up);
1060 /* This function will print the Table description properties. */
1062 ofp_print_table_desc(struct ds *string, const struct ofputil_table_desc *td)
1064 ds_put_format(string, "\n table %"PRIu8, td->table_id);
1065 ds_put_cstr(string, ":\n");
1066 ds_put_format(string, " eviction=%s eviction_flags=",
1067 ofputil_table_eviction_to_string(td->eviction));
1068 ofputil_put_eviction_flags(string, td->eviction_flags);
1069 ds_put_char(string, '\n');
1070 ds_put_format(string, " vacancy=%s",
1071 ofputil_table_vacancy_to_string(td->vacancy));
1072 if (td->vacancy == OFPUTIL_TABLE_VACANCY_ON) {
1073 ds_put_format(string, " vacancy_down=%"PRIu8"%%",
1074 td->table_vacancy.vacancy_down);
1075 ds_put_format(string, " vacancy_up=%"PRIu8"%%",
1076 td->table_vacancy.vacancy_up);
1077 ds_put_format(string, " vacancy=%"PRIu8"%%",
1078 td->table_vacancy.vacancy);
1080 ds_put_char(string, '\n');
1084 ofp_print_queue_get_config_request(struct ds *string,
1085 const struct ofp_header *oh)
1091 error = ofputil_decode_queue_get_config_request(oh, &port, &queue);
1093 ofp_print_error(string, error);
1097 ds_put_cstr(string, " port=");
1098 ofputil_format_port(port, string);
1100 if (queue != OFPQ_ALL) {
1101 ds_put_cstr(string, " queue=");
1102 ofp_print_queue_name(string, queue);
1107 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1110 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1111 } else if (rate < UINT16_MAX) {
1112 ds_put_format(string, " %s:(disabled)", name);
1117 ofp_print_queue_get_config_reply(struct ds *string,
1118 const struct ofp_header *oh)
1121 ofp_port_t port = 0;
1123 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1125 ds_put_char(string, ' ');
1127 struct ofputil_queue_config queue;
1130 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1132 if (retval != EOF) {
1133 ofp_print_error(string, retval);
1135 ds_chomp(string, ' ');
1139 if (queue.port != port) {
1142 ds_put_cstr(string, "port=");
1143 ofputil_format_port(port, string);
1144 ds_put_char(string, '\n');
1147 ds_put_format(string, "queue %"PRIu32":", queue.queue);
1148 print_queue_rate(string, "min_rate", queue.min_rate);
1149 print_queue_rate(string, "max_rate", queue.max_rate);
1150 ds_put_char(string, '\n');
1155 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1157 if (flags & OFPMF13_KBPS) {
1158 ds_put_cstr(s, "kbps ");
1160 if (flags & OFPMF13_PKTPS) {
1161 ds_put_cstr(s, "pktps ");
1163 if (flags & OFPMF13_BURST) {
1164 ds_put_cstr(s, "burst ");
1166 if (flags & OFPMF13_STATS) {
1167 ds_put_cstr(s, "stats ");
1170 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1172 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1177 ofp_print_meter_band(struct ds *s, uint16_t flags,
1178 const struct ofputil_meter_band *mb)
1180 ds_put_cstr(s, "\ntype=");
1183 ds_put_cstr(s, "drop");
1185 case OFPMBT13_DSCP_REMARK:
1186 ds_put_cstr(s, "dscp_remark");
1189 ds_put_format(s, "%u", mb->type);
1192 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1194 if (flags & OFPMF13_BURST) {
1195 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1197 if (mb->type == OFPMBT13_DSCP_REMARK) {
1198 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1203 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1207 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1208 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1209 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1210 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1211 ds_put_cstr(s, "duration:");
1212 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1213 ds_put_char(s, ' ');
1215 ds_put_cstr(s, "bands:\n");
1216 for (i = 0; i < ms->n_bands; ++i) {
1217 ds_put_format(s, "%d: ", i);
1218 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1219 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1224 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1228 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1230 ofp_print_meter_flags(s, mc->flags);
1232 ds_put_cstr(s, "bands=");
1233 for (i = 0; i < mc->n_bands; ++i) {
1234 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1236 ds_put_char(s, '\n');
1240 ofp_print_meter_mod__(struct ds *s, const struct ofputil_meter_mod *mm)
1242 switch (mm->command) {
1244 ds_put_cstr(s, " ADD ");
1246 case OFPMC13_MODIFY:
1247 ds_put_cstr(s, " MOD ");
1249 case OFPMC13_DELETE:
1250 ds_put_cstr(s, " DEL ");
1253 ds_put_format(s, " cmd:%d ", mm->command);
1256 ofp_print_meter_config(s, &mm->meter);
1260 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1262 struct ofputil_meter_mod mm;
1263 struct ofpbuf bands;
1266 ofpbuf_init(&bands, 64);
1267 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1269 ofp_print_error(s, error);
1271 ofp_print_meter_mod__(s, &mm);
1273 ofpbuf_uninit(&bands);
1277 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1281 ofputil_decode_meter_request(oh, &meter_id);
1283 ds_put_format(s, " meter=%"PRIu32, meter_id);
1287 ofputil_meter_capabilities_to_name(uint32_t bit)
1289 enum ofp13_meter_flags flag = bit;
1292 case OFPMF13_KBPS: return "kbps";
1293 case OFPMF13_PKTPS: return "pktps";
1294 case OFPMF13_BURST: return "burst";
1295 case OFPMF13_STATS: return "stats";
1302 ofputil_meter_band_types_to_name(uint32_t bit)
1305 case 1 << OFPMBT13_DROP: return "drop";
1306 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1313 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1315 struct ofputil_meter_features mf;
1317 ofputil_decode_meter_features(oh, &mf);
1319 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1320 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1321 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1323 ds_put_cstr(s, "band_types: ");
1324 ofp_print_bit_names(s, mf.band_types,
1325 ofputil_meter_band_types_to_name, ' ');
1326 ds_put_char(s, '\n');
1328 ds_put_cstr(s, "capabilities: ");
1329 ofp_print_bit_names(s, mf.capabilities,
1330 ofputil_meter_capabilities_to_name, ' ');
1331 ds_put_char(s, '\n');
1335 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1337 struct ofpbuf bands;
1340 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1341 ofpbuf_init(&bands, 64);
1343 struct ofputil_meter_config mc;
1346 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1348 if (retval != EOF) {
1349 ofp_print_error(s, retval);
1353 ds_put_char(s, '\n');
1354 ofp_print_meter_config(s, &mc);
1356 ofpbuf_uninit(&bands);
1360 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1362 struct ofpbuf bands;
1365 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1366 ofpbuf_init(&bands, 64);
1368 struct ofputil_meter_stats ms;
1371 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1373 if (retval != EOF) {
1374 ofp_print_error(s, retval);
1378 ds_put_char(s, '\n');
1379 ofp_print_meter_stats(s, &ms);
1381 ofpbuf_uninit(&bands);
1385 ofp_print_error(struct ds *string, enum ofperr error)
1387 if (string->length) {
1388 ds_put_char(string, ' ');
1390 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1394 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1396 uint32_t allowed_versions;
1399 ok = ofputil_decode_hello(oh, &allowed_versions);
1401 ds_put_cstr(string, "\n version bitmap: ");
1402 ofputil_format_version_bitmap(string, allowed_versions);
1405 ds_put_cstr(string, "\n unknown data in hello:\n");
1406 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1411 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1413 size_t len = ntohs(oh->length);
1414 struct ofpbuf payload;
1418 error = ofperr_decode_msg(oh, &payload);
1420 ds_put_cstr(string, "***decode error***");
1421 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1425 ds_put_format(string, " %s\n", ofperr_get_name(error));
1427 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1428 ds_put_printable(string, payload.data, payload.size);
1430 s = ofp_to_string(payload.data, payload.size, 1);
1431 ds_put_cstr(string, s);
1434 ofpbuf_uninit(&payload);
1438 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1440 struct ofputil_port_status ps;
1443 error = ofputil_decode_port_status(oh, &ps);
1445 ofp_print_error(string, error);
1449 if (ps.reason == OFPPR_ADD) {
1450 ds_put_format(string, " ADD:");
1451 } else if (ps.reason == OFPPR_DELETE) {
1452 ds_put_format(string, " DEL:");
1453 } else if (ps.reason == OFPPR_MODIFY) {
1454 ds_put_format(string, " MOD:");
1457 ofp_print_phy_port(string, &ps.desc);
1461 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1463 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1465 ds_put_char(string, '\n');
1466 ds_put_format(string, "Manufacturer: %.*s\n",
1467 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1468 ds_put_format(string, "Hardware: %.*s\n",
1469 (int) sizeof ods->hw_desc, ods->hw_desc);
1470 ds_put_format(string, "Software: %.*s\n",
1471 (int) sizeof ods->sw_desc, ods->sw_desc);
1472 ds_put_format(string, "Serial Num: %.*s\n",
1473 (int) sizeof ods->serial_num, ods->serial_num);
1474 ds_put_format(string, "DP Description: %.*s\n",
1475 (int) sizeof ods->dp_desc, ods->dp_desc);
1479 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1481 struct ofputil_flow_stats_request fsr;
1484 error = ofputil_decode_flow_stats_request(&fsr, oh);
1486 ofp_print_error(string, error);
1490 if (fsr.table_id != 0xff) {
1491 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1494 if (fsr.out_port != OFPP_ANY) {
1495 ds_put_cstr(string, " out_port=");
1496 ofputil_format_port(fsr.out_port, string);
1499 ds_put_char(string, ' ');
1500 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1504 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1506 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1507 ntohll(fs->cookie));
1509 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1510 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1511 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1512 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1513 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1514 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1516 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1517 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1520 ofp_print_flow_flags(string, fs->flags);
1522 if (fs->importance != 0) {
1523 ds_put_format(string, "importance=%"PRIu16", ", fs->importance);
1525 if (fs->idle_age >= 0) {
1526 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1528 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1529 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1532 match_format(&fs->match, string, fs->priority);
1533 if (string->string[string->length - 1] != ' ') {
1534 ds_put_char(string, ' ');
1537 ds_put_cstr(string, "actions=");
1538 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1542 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1544 struct ofpbuf ofpacts;
1547 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1548 ofpbuf_init(&ofpacts, 64);
1550 struct ofputil_flow_stats fs;
1553 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1555 if (retval != EOF) {
1556 ds_put_cstr(string, " ***parse error***");
1560 ds_put_char(string, '\n');
1561 ofp_print_flow_stats(string, &fs);
1563 ofpbuf_uninit(&ofpacts);
1567 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1569 struct ofputil_aggregate_stats as;
1572 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1574 ofp_print_error(string, error);
1578 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1579 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1580 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1584 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1586 ds_put_cstr(string, leader);
1587 if (stat != UINT64_MAX) {
1588 ds_put_format(string, "%"PRIu64, stat);
1590 ds_put_char(string, '?');
1593 ds_put_cstr(string, ", ");
1595 ds_put_cstr(string, "\n");
1600 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1602 ofp_port_t ofp10_port;
1605 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1607 ofp_print_error(string, error);
1611 ds_put_cstr(string, " port_no=");
1612 ofputil_format_port(ofp10_port, string);
1616 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1621 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1622 if (verbosity < 1) {
1626 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1628 struct ofputil_port_stats ps;
1631 retval = ofputil_decode_port_stats(&ps, &b);
1633 if (retval != EOF) {
1634 ds_put_cstr(string, " ***parse error***");
1639 ds_put_cstr(string, " port ");
1640 if (ofp_to_u16(ps.port_no) < 10) {
1641 ds_put_char(string, ' ');
1643 ofputil_format_port(ps.port_no, string);
1645 ds_put_cstr(string, ": rx ");
1646 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1647 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1648 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1649 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1650 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1651 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1652 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1654 ds_put_cstr(string, " tx ");
1655 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1656 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1657 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1658 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1659 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1661 if (ps.duration_sec != UINT32_MAX) {
1662 ds_put_cstr(string, " duration=");
1663 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1664 ds_put_char(string, '\n');
1670 ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh)
1674 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1675 ofpraw_pull_assert(&b);
1677 struct ofputil_table_features prev_features;
1678 struct ofputil_table_stats prev_stats;
1679 for (int i = 0;; i++) {
1680 struct ofputil_table_features features;
1681 struct ofputil_table_stats stats;
1684 retval = ofputil_decode_table_stats_reply(&b, &stats, &features);
1686 if (retval != EOF) {
1687 ofp_print_error(string, retval);
1692 ds_put_char(string, '\n');
1693 ofp_print_table_features(string,
1694 &features, i ? &prev_features : NULL,
1695 &stats, i ? &prev_stats : NULL);
1696 prev_features = features;
1702 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1704 if (queue_id == OFPQ_ALL) {
1705 ds_put_cstr(string, "ALL");
1707 ds_put_format(string, "%"PRIu32, queue_id);
1712 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1714 struct ofputil_queue_stats_request oqsr;
1717 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1719 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1723 ds_put_cstr(string, " port=");
1724 ofputil_format_port(oqsr.port_no, string);
1726 ds_put_cstr(string, " queue=");
1727 ofp_print_queue_name(string, oqsr.queue_id);
1731 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1736 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1737 if (verbosity < 1) {
1741 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1743 struct ofputil_queue_stats qs;
1746 retval = ofputil_decode_queue_stats(&qs, &b);
1748 if (retval != EOF) {
1749 ds_put_cstr(string, " ***parse error***");
1754 ds_put_cstr(string, " port ");
1755 ofputil_format_port(qs.port_no, string);
1756 ds_put_cstr(string, " queue ");
1757 ofp_print_queue_name(string, qs.queue_id);
1758 ds_put_cstr(string, ": ");
1760 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1761 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1762 print_port_stat(string, "errors=", qs.tx_errors, 1);
1764 ds_put_cstr(string, "duration=");
1765 if (qs.duration_sec != UINT32_MAX) {
1766 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1768 ds_put_char(string, '?');
1770 ds_put_char(string, '\n');
1775 ofp_print_ofpst_port_desc_request(struct ds *string,
1776 const struct ofp_header *oh)
1781 error = ofputil_decode_port_desc_stats_request(oh, &port);
1783 ofp_print_error(string, error);
1787 ds_put_cstr(string, " port=");
1788 ofputil_format_port(port, string);
1792 ofp_print_ofpst_port_desc_reply(struct ds *string,
1793 const struct ofp_header *oh)
1797 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1798 ofpraw_pull_assert(&b);
1799 ds_put_char(string, '\n');
1800 ofp_print_phy_ports(string, oh->version, &b);
1804 ofp_print_stats(struct ds *string, const struct ofp_header *oh)
1806 uint16_t flags = ofpmp_flags(oh);
1809 ds_put_cstr(string, " flags=");
1810 if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION)
1811 && (flags & OFPSF_REPLY_MORE)) {
1812 ds_put_cstr(string, "[more]");
1813 flags &= ~OFPSF_REPLY_MORE;
1816 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1823 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1825 size_t len = ntohs(oh->length);
1827 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1828 if (verbosity > 1) {
1829 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1834 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1835 uint64_t generation_id)
1837 ds_put_cstr(string, " role=");
1840 case OFPCR12_ROLE_NOCHANGE:
1841 ds_put_cstr(string, "nochange");
1843 case OFPCR12_ROLE_EQUAL:
1844 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1846 case OFPCR12_ROLE_MASTER:
1847 ds_put_cstr(string, "master");
1849 case OFPCR12_ROLE_SLAVE:
1850 ds_put_cstr(string, "slave");
1856 if (generation_id != UINT64_MAX) {
1857 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1862 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1864 struct ofputil_role_request rr;
1867 error = ofputil_decode_role_message(oh, &rr);
1869 ofp_print_error(string, error);
1873 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1877 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1879 struct ofputil_role_status rs;
1882 error = ofputil_decode_role_status(oh, &rs);
1884 ofp_print_error(string, error);
1888 ofp_print_role_generic(string, rs.role, rs.generation_id);
1890 ds_put_cstr(string, " reason=");
1892 switch (rs.reason) {
1893 case OFPCRR_MASTER_REQUEST:
1894 ds_put_cstr(string, "master_request");
1897 ds_put_cstr(string, "configuration_changed");
1899 case OFPCRR_EXPERIMENTER:
1900 ds_put_cstr(string, "experimenter_data_changed");
1902 case OFPCRR_N_REASONS:
1909 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1910 const struct nx_flow_mod_table_id *nfmti)
1912 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1916 ofp_print_nxt_set_flow_format(struct ds *string,
1917 const struct nx_set_flow_format *nsff)
1919 uint32_t format = ntohl(nsff->format);
1921 ds_put_cstr(string, " format=");
1922 if (ofputil_nx_flow_format_is_valid(format)) {
1923 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
1925 ds_put_format(string, "%"PRIu32, format);
1930 ofp_print_nxt_set_packet_in_format(struct ds *string,
1931 const struct nx_set_packet_in_format *nspf)
1933 uint32_t format = ntohl(nspf->format);
1935 ds_put_cstr(string, " format=");
1936 if (ofputil_packet_in_format_is_valid(format)) {
1937 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1939 ds_put_format(string, "%"PRIu32, format);
1943 /* Returns a string form of 'reason'. The return value is either a statically
1944 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1945 * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
1946 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
1948 ofp_port_reason_to_string(enum ofp_port_reason reason,
1949 char *reasonbuf, size_t bufsize)
1961 case OFPPR_N_REASONS:
1963 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1968 /* Returns a string form of 'reason'. The return value is either a statically
1969 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1970 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
1972 ofp_role_reason_to_string(enum ofp14_controller_role_reason reason,
1973 char *reasonbuf, size_t bufsize)
1976 case OFPCRR_MASTER_REQUEST:
1977 return "master_request";
1980 return "configuration_changed";
1982 case OFPCRR_EXPERIMENTER:
1983 return "experimenter_data_changed";
1985 case OFPCRR_N_REASONS:
1987 snprintf(reasonbuf, bufsize, "%d", (int) reason);
1992 /* Returns a string form of 'reason'. The return value is either a statically
1993 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
1994 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
1996 ofp_table_reason_to_string(enum ofp14_table_reason reason,
1997 char *reasonbuf, size_t bufsize)
2000 case OFPTR_VACANCY_DOWN:
2001 return "vacancy_down";
2003 case OFPTR_VACANCY_UP:
2004 return "vacancy_up";
2006 case OFPTR_N_REASONS:
2008 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2013 /* Returns a string form of 'reason'. The return value is either a statically
2014 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2015 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
2017 ofp_requestforward_reason_to_string(enum ofp14_requestforward_reason reason,
2018 char *reasonbuf, size_t bufsize)
2021 case OFPRFR_GROUP_MOD:
2022 return "group_mod_request";
2024 case OFPRFR_METER_MOD:
2025 return "meter_mod_request";
2027 case OFPRFR_N_REASONS:
2029 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2035 ofp_async_config_reason_to_string(uint32_t reason,
2036 enum ofputil_async_msg_type type,
2037 char *reasonbuf, size_t bufsize)
2041 return ofputil_packet_in_reason_to_string(reason, reasonbuf, bufsize);
2043 case OAM_PORT_STATUS:
2044 return ofp_port_reason_to_string(reason, reasonbuf, bufsize);
2046 case OAM_FLOW_REMOVED:
2047 return ofp_flow_removed_reason_to_string(reason, reasonbuf, bufsize);
2049 case OAM_ROLE_STATUS:
2050 return ofp_role_reason_to_string(reason, reasonbuf, bufsize);
2052 case OAM_TABLE_STATUS:
2053 return ofp_table_reason_to_string(reason, reasonbuf, bufsize);
2055 case OAM_REQUESTFORWARD:
2056 return ofp_requestforward_reason_to_string(reason, reasonbuf, bufsize);
2060 return "Unknown asynchronous configuration message type";
2065 #define OFP_ASYNC_CONFIG_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2067 ofp_print_nxt_set_async_config(struct ds *string,
2068 const struct ofp_header *oh)
2073 ofpraw_decode(&raw, oh);
2075 if (raw == OFPRAW_OFPT13_SET_ASYNC ||
2076 raw == OFPRAW_NXT_SET_ASYNC_CONFIG ||
2077 raw == OFPRAW_OFPT13_GET_ASYNC_REPLY) {
2078 const struct nx_async_config *nac = ofpmsg_body(oh);
2080 for (i = 0; i < 2; i++) {
2082 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2084 ds_put_cstr(string, " PACKET_IN:");
2085 for (j = 0; j < 32; j++) {
2086 if (nac->packet_in_mask[i] & htonl(1u << j)) {
2087 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2090 reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
2092 ds_put_format(string, " %s", reason);
2095 if (!nac->packet_in_mask[i]) {
2096 ds_put_cstr(string, " (off)");
2098 ds_put_char(string, '\n');
2100 ds_put_cstr(string, " PORT_STATUS:");
2101 for (j = 0; j < 32; j++) {
2102 if (nac->port_status_mask[i] & htonl(1u << j)) {
2103 char reasonbuf[OFP_PORT_REASON_BUFSIZE];
2106 reason = ofp_port_reason_to_string(j, reasonbuf,
2108 ds_put_format(string, " %s", reason);
2111 if (!nac->port_status_mask[i]) {
2112 ds_put_cstr(string, " (off)");
2114 ds_put_char(string, '\n');
2116 ds_put_cstr(string, " FLOW_REMOVED:");
2117 for (j = 0; j < 32; j++) {
2118 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
2119 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2122 reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
2124 ds_put_format(string, " %s", reason);
2127 if (!nac->flow_removed_mask[i]) {
2128 ds_put_cstr(string, " (off)");
2130 ds_put_char(string, '\n');
2132 } else if (raw == OFPRAW_OFPT14_SET_ASYNC ||
2133 raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) {
2134 enum ofperr error = 0;
2135 uint32_t role[2][OAM_N_TYPES] = {{0}};
2138 if (raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) {
2139 error = ofputil_decode_set_async_config(oh, role[0], role[1], true);
2141 else if (raw == OFPRAW_OFPT14_SET_ASYNC) {
2142 error = ofputil_decode_set_async_config(oh, role[0], role[1],
2146 ofp_print_error(string, error);
2150 for (i = 0; i < 2; i++) {
2152 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2153 for (type = 0; type < OAM_N_TYPES; type++) {
2156 ds_put_cstr(string, " PACKET_IN:");
2159 case OAM_PORT_STATUS:
2160 ds_put_cstr(string, " PORT_STATUS:");
2163 case OAM_FLOW_REMOVED:
2164 ds_put_cstr(string, " FLOW_REMOVED:");
2167 case OAM_ROLE_STATUS:
2168 ds_put_cstr(string, " ROLE_STATUS:");
2171 case OAM_TABLE_STATUS:
2172 ds_put_cstr(string, " TABLE_STATUS:");
2175 case OAM_REQUESTFORWARD:
2176 ds_put_cstr(string, " REQUESTFORWARD:");
2180 for (j = 0; j < 32; j++) {
2181 if (role[i][type] & (1u << j)) {
2182 char reasonbuf[OFP_ASYNC_CONFIG_REASON_BUFSIZE];
2185 reason = ofp_async_config_reason_to_string(j, type,
2188 ds_put_format(string, " %s", reason);
2191 if (!role[i][type]) {
2192 ds_put_cstr(string, " (off)");
2194 ds_put_char(string, '\n');
2201 ofp_print_nxt_set_controller_id(struct ds *string,
2202 const struct nx_controller_id *nci)
2204 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
2208 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
2209 const struct ofp_header *oh)
2211 ds_put_format(string, " id=%"PRIu32,
2212 ofputil_decode_flow_monitor_cancel(oh));
2216 nx_flow_monitor_flags_to_name(uint32_t bit)
2218 enum nx_flow_monitor_flags fmf = bit;
2221 case NXFMF_INITIAL: return "initial";
2222 case NXFMF_ADD: return "add";
2223 case NXFMF_DELETE: return "delete";
2224 case NXFMF_MODIFY: return "modify";
2225 case NXFMF_ACTIONS: return "actions";
2226 case NXFMF_OWN: return "own";
2233 ofp_print_nxst_flow_monitor_request(struct ds *string,
2234 const struct ofp_header *oh)
2238 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2240 struct ofputil_flow_monitor_request request;
2243 retval = ofputil_decode_flow_monitor_request(&request, &b);
2245 if (retval != EOF) {
2246 ofp_print_error(string, retval);
2251 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
2252 ofp_print_bit_names(string, request.flags,
2253 nx_flow_monitor_flags_to_name, ',');
2255 if (request.out_port != OFPP_NONE) {
2256 ds_put_cstr(string, " out_port=");
2257 ofputil_format_port(request.out_port, string);
2260 if (request.table_id != 0xff) {
2261 ds_put_format(string, " table=%"PRIu8, request.table_id);
2264 ds_put_char(string, ' ');
2265 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
2266 ds_chomp(string, ' ');
2271 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2272 const struct ofp_header *oh)
2274 uint64_t ofpacts_stub[1024 / 8];
2275 struct ofpbuf ofpacts;
2278 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2279 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2281 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2282 struct ofputil_flow_update update;
2286 update.match = &match;
2287 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2289 if (retval != EOF) {
2290 ofp_print_error(string, retval);
2292 ofpbuf_uninit(&ofpacts);
2296 ds_put_cstr(string, "\n event=");
2297 switch (update.event) {
2299 ds_put_cstr(string, "ADDED");
2303 ds_put_format(string, "DELETED reason=%s",
2304 ofp_flow_removed_reason_to_string(update.reason,
2309 case NXFME_MODIFIED:
2310 ds_put_cstr(string, "MODIFIED");
2314 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2318 ds_put_format(string, " table=%"PRIu8, update.table_id);
2319 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2320 ds_put_format(string, " idle_timeout=%"PRIu16,
2321 update.idle_timeout);
2323 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2324 ds_put_format(string, " hard_timeout=%"PRIu16,
2325 update.hard_timeout);
2327 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2329 ds_put_char(string, ' ');
2330 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2332 if (update.ofpacts_len) {
2333 if (string->string[string->length - 1] != ' ') {
2334 ds_put_char(string, ' ');
2336 ds_put_cstr(string, "actions=");
2337 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2343 ofp_print_version(const struct ofp_header *oh,
2346 switch (oh->version) {
2350 ds_put_cstr(string, " (OF1.1)");
2353 ds_put_cstr(string, " (OF1.2)");
2356 ds_put_cstr(string, " (OF1.3)");
2359 ds_put_cstr(string, " (OF1.4)");
2362 ds_put_cstr(string, " (OF1.5)");
2365 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2368 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2372 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2375 ds_put_cstr(string, ofpraw_get_name(raw));
2376 ofp_print_version(oh, string);
2380 ofp_print_bucket_id(struct ds *s, const char *label, uint32_t bucket_id,
2381 enum ofp_version ofp_version)
2383 if (ofp_version < OFP15_VERSION) {
2387 ds_put_cstr(s, label);
2389 switch (bucket_id) {
2390 case OFPG15_BUCKET_FIRST:
2391 ds_put_cstr(s, "first");
2393 case OFPG15_BUCKET_LAST:
2394 ds_put_cstr(s, "last");
2396 case OFPG15_BUCKET_ALL:
2397 ds_put_cstr(s, "all");
2400 ds_put_format(s, "%"PRIu32, bucket_id);
2404 ds_put_char(s, ',');
2408 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2409 const struct ovs_list *p_buckets,
2410 const struct ofputil_group_props *props,
2411 enum ofp_version ofp_version, bool suppress_type)
2413 struct ofputil_bucket *bucket;
2415 ds_put_format(s, "group_id=%"PRIu32, group_id);
2417 if (!suppress_type) {
2418 static const char *type_str[] = { "all", "select", "indirect",
2420 ds_put_format(s, ",type=%s", type_str[type > 4 ? 4 : type]);
2423 if (props->selection_method[0]) {
2424 ds_put_format(s, ",selection_method=%s", props->selection_method);
2425 if (props->selection_method_param) {
2426 ds_put_format(s, ",selection_method_param=%"PRIu64,
2427 props->selection_method_param);
2430 size_t n = bitmap_count1(props->fields.used.bm, MFF_N_IDS);
2432 ds_put_cstr(s, ",fields=");
2433 oxm_format_field_array(s, &props->fields);
2435 ds_put_cstr(s, ",fields(");
2436 oxm_format_field_array(s, &props->fields);
2437 ds_put_char(s, ')');
2445 ds_put_char(s, ',');
2447 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2448 ds_put_cstr(s, "bucket=");
2450 ofp_print_bucket_id(s, "bucket_id:", bucket->bucket_id, ofp_version);
2451 if (bucket->weight != (type == OFPGT11_SELECT ? 1 : 0)) {
2452 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2454 if (bucket->watch_port != OFPP_NONE) {
2455 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2457 if (bucket->watch_group != OFPG_ANY) {
2458 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2461 ds_put_cstr(s, "actions=");
2462 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2463 ds_put_char(s, ',');
2470 ofp_print_ofpst_group_desc_request(struct ds *string,
2471 const struct ofp_header *oh)
2473 uint32_t group_id = ofputil_decode_group_desc_request(oh);
2474 ds_put_cstr(string, " group_id=");
2475 ofputil_format_group(group_id, string);
2479 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2483 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2485 struct ofputil_group_desc gd;
2488 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2490 if (retval != EOF) {
2491 ds_put_cstr(s, " ***parse error***");
2496 ds_put_char(s, '\n');
2497 ds_put_char(s, ' ');
2498 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, &gd.props,
2499 oh->version, false);
2500 ofputil_bucket_list_destroy(&gd.buckets);
2505 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2510 error = ofputil_decode_group_stats_request(oh, &group_id);
2512 ofp_print_error(string, error);
2516 ds_put_cstr(string, " group_id=");
2517 ofputil_format_group(group_id, string);
2521 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2526 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2529 struct ofputil_group_stats gs;
2532 retval = ofputil_decode_group_stats_reply(&b, &gs);
2534 if (retval != EOF) {
2535 ds_put_cstr(s, " ***parse error***");
2540 ds_put_char(s, '\n');
2542 ds_put_char(s, ' ');
2543 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2545 if (gs.duration_sec != UINT32_MAX) {
2546 ds_put_cstr(s, "duration=");
2547 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2548 ds_put_char(s, ',');
2550 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2551 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2552 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2554 for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2555 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2556 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2557 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2558 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2562 free(gs.bucket_stats);
2567 group_type_to_string(enum ofp11_group_type type)
2570 case OFPGT11_ALL: return "all";
2571 case OFPGT11_SELECT: return "select";
2572 case OFPGT11_INDIRECT: return "indirect";
2573 case OFPGT11_FF: return "fast failover";
2574 default: OVS_NOT_REACHED();
2579 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2581 struct ofputil_group_features features;
2584 ofputil_decode_group_features_reply(oh, &features);
2586 ds_put_format(string, "\n Group table:\n");
2587 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2588 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2589 features.capabilities);
2591 for (i = 0; i < OFPGT12_N_TYPES; i++) {
2592 if (features.types & (1u << i)) {
2593 ds_put_format(string, " %s group:\n", group_type_to_string(i));
2594 ds_put_format(string, " max_groups=%#"PRIx32"\n",
2595 features.max_groups[i]);
2596 ds_put_format(string, " actions: ");
2597 ofpact_bitmap_format(features.ofpacts[i], string);
2598 ds_put_char(string, '\n');
2604 ofp_print_group_mod__(struct ds *s, enum ofp_version ofp_version,
2605 const struct ofputil_group_mod *gm)
2607 bool bucket_command = false;
2609 ds_put_char(s, '\n');
2611 ds_put_char(s, ' ');
2612 switch (gm->command) {
2614 ds_put_cstr(s, "ADD");
2617 case OFPGC11_MODIFY:
2618 ds_put_cstr(s, "MOD");
2621 case OFPGC11_DELETE:
2622 ds_put_cstr(s, "DEL");
2625 case OFPGC15_INSERT_BUCKET:
2626 ds_put_cstr(s, "INSERT_BUCKET");
2627 bucket_command = true;
2630 case OFPGC15_REMOVE_BUCKET:
2631 ds_put_cstr(s, "REMOVE_BUCKET");
2632 bucket_command = true;
2636 ds_put_format(s, "cmd:%"PRIu16"", gm->command);
2638 ds_put_char(s, ' ');
2640 if (bucket_command) {
2641 ofp_print_bucket_id(s, "command_bucket_id:",
2642 gm->command_bucket_id, ofp_version);
2645 ofp_print_group(s, gm->group_id, gm->type, &gm->buckets, &gm->props,
2646 ofp_version, bucket_command);
2650 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2652 struct ofputil_group_mod gm;
2655 error = ofputil_decode_group_mod(oh, &gm);
2657 ofp_print_error(s, error);
2660 ofp_print_group_mod__(s, oh->version, &gm);
2661 ofputil_bucket_list_destroy(&gm.buckets);
2665 print_table_action_features(struct ds *s,
2666 const struct ofputil_table_action_features *taf)
2669 ds_put_cstr(s, " actions: ");
2670 ofpact_bitmap_format(taf->ofpacts, s);
2671 ds_put_char(s, '\n');
2674 if (!bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS)) {
2677 ds_put_cstr(s, " supported on Set-Field:");
2678 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, taf->set_fields.bm) {
2679 ds_put_format(s, " %s", mf_from_id(i)->name);
2681 ds_put_char(s, '\n');
2686 table_action_features_equal(const struct ofputil_table_action_features *a,
2687 const struct ofputil_table_action_features *b)
2689 return (a->ofpacts == b->ofpacts
2690 && bitmap_equal(a->set_fields.bm, b->set_fields.bm, MFF_N_IDS));
2694 table_action_features_empty(const struct ofputil_table_action_features *taf)
2696 return !taf->ofpacts && bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS);
2700 print_table_instruction_features(
2702 const struct ofputil_table_instruction_features *tif,
2703 const struct ofputil_table_instruction_features *prev_tif)
2707 if (!bitmap_is_all_zeros(tif->next, 255)) {
2708 ds_put_cstr(s, " next tables: ");
2709 for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
2710 start = bitmap_scan(tif->next, 1, end, 255)) {
2711 end = bitmap_scan(tif->next, 0, start + 1, 255);
2712 if (end == start + 1) {
2713 ds_put_format(s, "%d,", start);
2715 ds_put_format(s, "%d-%d,", start, end - 1);
2719 if (ds_last(s) == ' ') {
2720 ds_put_cstr(s, "none");
2722 ds_put_char(s, '\n');
2725 if (tif->instructions) {
2726 if (prev_tif && tif->instructions == prev_tif->instructions) {
2727 ds_put_cstr(s, " (same instructions)\n");
2729 ds_put_cstr(s, " instructions: ");
2732 for (i = 0; i < 32; i++) {
2733 if (tif->instructions & (1u << i)) {
2734 ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
2738 ds_put_char(s, '\n');
2743 && table_action_features_equal(&tif->write, &prev_tif->write)
2744 && table_action_features_equal(&tif->apply, &prev_tif->apply)
2745 && !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
2746 ds_put_cstr(s, " (same actions)\n");
2747 } else if (!table_action_features_equal(&tif->write, &tif->apply)) {
2748 ds_put_cstr(s, " Write-Actions features:\n");
2749 print_table_action_features(s, &tif->write);
2750 ds_put_cstr(s, " Apply-Actions features:\n");
2751 print_table_action_features(s, &tif->apply);
2752 } else if (tif->write.ofpacts
2753 || !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
2754 ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
2755 print_table_action_features(s, &tif->write);
2760 table_instruction_features_equal(
2761 const struct ofputil_table_instruction_features *a,
2762 const struct ofputil_table_instruction_features *b)
2764 return (bitmap_equal(a->next, b->next, 255)
2765 && a->instructions == b->instructions
2766 && table_action_features_equal(&a->write, &b->write)
2767 && table_action_features_equal(&a->apply, &b->apply));
2771 table_instruction_features_empty(
2772 const struct ofputil_table_instruction_features *tif)
2774 return (bitmap_is_all_zeros(tif->next, 255)
2775 && !tif->instructions
2776 && table_action_features_empty(&tif->write)
2777 && table_action_features_empty(&tif->apply));
2781 table_features_equal(const struct ofputil_table_features *a,
2782 const struct ofputil_table_features *b)
2784 return (a->metadata_match == b->metadata_match
2785 && a->metadata_write == b->metadata_write
2786 && a->miss_config == b->miss_config
2787 && a->supports_eviction == b->supports_eviction
2788 && a->supports_vacancy_events == b->supports_vacancy_events
2789 && a->max_entries == b->max_entries
2790 && table_instruction_features_equal(&a->nonmiss, &b->nonmiss)
2791 && table_instruction_features_equal(&a->miss, &b->miss)
2792 && bitmap_equal(a->match.bm, b->match.bm, MFF_N_IDS));
2796 table_features_empty(const struct ofputil_table_features *tf)
2798 return (!tf->metadata_match
2799 && !tf->metadata_write
2800 && tf->miss_config == OFPUTIL_TABLE_MISS_DEFAULT
2801 && tf->supports_eviction < 0
2802 && tf->supports_vacancy_events < 0
2804 && table_instruction_features_empty(&tf->nonmiss)
2805 && table_instruction_features_empty(&tf->miss)
2806 && bitmap_is_all_zeros(tf->match.bm, MFF_N_IDS));
2810 table_stats_equal(const struct ofputil_table_stats *a,
2811 const struct ofputil_table_stats *b)
2813 return (a->active_count == b->active_count
2814 && a->lookup_count == b->lookup_count
2815 && a->matched_count == b->matched_count);
2819 ofp_print_table_features(struct ds *s,
2820 const struct ofputil_table_features *features,
2821 const struct ofputil_table_features *prev_features,
2822 const struct ofputil_table_stats *stats,
2823 const struct ofputil_table_stats *prev_stats)
2827 ds_put_format(s, " table %"PRIu8, features->table_id);
2828 if (features->name[0]) {
2829 ds_put_format(s, " (\"%s\")", features->name);
2831 ds_put_char(s, ':');
2833 bool same_stats = prev_stats && table_stats_equal(stats, prev_stats);
2834 bool same_features = prev_features && table_features_equal(features,
2836 if ((!stats || same_stats) && same_features) {
2837 ds_put_cstr(s, " ditto");
2840 ds_put_char(s, '\n');
2842 ds_put_format(s, " active=%"PRIu32", ", stats->active_count);
2843 ds_put_format(s, "lookup=%"PRIu64", ", stats->lookup_count);
2844 ds_put_format(s, "matched=%"PRIu64"\n", stats->matched_count);
2846 if (same_features) {
2847 if (!table_features_empty(features)) {
2848 ds_put_cstr(s, " (same features)\n");
2852 if (features->metadata_match || features->metadata_write) {
2853 ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
2854 ntohll(features->metadata_match),
2855 ntohll(features->metadata_write));
2858 if (features->miss_config != OFPUTIL_TABLE_MISS_DEFAULT) {
2859 ds_put_format(s, " config=%s\n",
2860 ofputil_table_miss_to_string(features->miss_config));
2863 if (features->supports_eviction >= 0) {
2864 ds_put_format(s, " eviction: %ssupported\n",
2865 features->supports_eviction ? "" : "not ");
2868 if (features->supports_vacancy_events >= 0) {
2869 ds_put_format(s, " vacancy events: %ssupported\n",
2870 features->supports_vacancy_events ? "" : "not ");
2874 if (features->max_entries) {
2875 ds_put_format(s, " max_entries=%"PRIu32"\n", features->max_entries);
2878 const struct ofputil_table_instruction_features *prev_nonmiss
2879 = prev_features ? &prev_features->nonmiss : NULL;
2880 const struct ofputil_table_instruction_features *prev_miss
2881 = prev_features ? &prev_features->miss : NULL;
2883 && table_instruction_features_equal(&features->nonmiss, prev_nonmiss)
2884 && table_instruction_features_equal(&features->miss, prev_miss)) {
2885 if (!table_instruction_features_empty(&features->nonmiss)) {
2886 ds_put_cstr(s, " (same instructions)\n");
2888 } else if (!table_instruction_features_equal(&features->nonmiss,
2890 ds_put_cstr(s, " instructions (other than table miss):\n");
2891 print_table_instruction_features(s, &features->nonmiss, prev_nonmiss);
2892 ds_put_cstr(s, " instructions (table miss):\n");
2893 print_table_instruction_features(s, &features->miss, prev_miss);
2894 } else if (!table_instruction_features_empty(&features->nonmiss)) {
2895 ds_put_cstr(s, " instructions (table miss and others):\n");
2896 print_table_instruction_features(s, &features->nonmiss, prev_nonmiss);
2899 if (!bitmap_is_all_zeros(features->match.bm, MFF_N_IDS)) {
2901 && bitmap_equal(features->match.bm, prev_features->match.bm,
2903 ds_put_cstr(s, " (same matching)\n");
2905 ds_put_cstr(s, " matching:\n");
2906 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) {
2907 const struct mf_field *f = mf_from_id(i);
2908 bool mask = bitmap_is_set(features->mask.bm, i);
2909 bool wildcard = bitmap_is_set(features->wildcard.bm, i);
2911 ds_put_format(s, " %s: %s\n",
2913 (mask ? "arbitrary mask"
2914 : wildcard ? "exact match or wildcard"
2915 : "must exact match"));
2922 ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh)
2926 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2928 struct ofputil_table_features prev;
2929 for (int i = 0; ; i++) {
2930 struct ofputil_table_features tf;
2933 retval = ofputil_decode_table_features(&b, &tf, true);
2935 if (retval != EOF) {
2936 ofp_print_error(s, retval);
2941 ds_put_char(s, '\n');
2942 ofp_print_table_features(s, &tf, i ? &prev : NULL, NULL, NULL);
2948 ofp_print_table_desc_reply(struct ds *s, const struct ofp_header *oh)
2952 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2955 struct ofputil_table_desc td;
2958 retval = ofputil_decode_table_desc(&b, &td, oh->version);
2960 if (retval != EOF) {
2961 ofp_print_error(s, retval);
2965 ofp_print_table_desc(s, &td);
2970 bundle_flags_to_name(uint32_t bit)
2983 ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh)
2986 struct ofputil_bundle_ctrl_msg bctrl;
2988 error = ofputil_decode_bundle_ctrl(oh, &bctrl);
2990 ofp_print_error(s, error);
2994 ds_put_char(s, '\n');
2996 ds_put_format(s, " bundle_id=%#"PRIx32" type=", bctrl.bundle_id);
2997 switch (bctrl.type) {
2998 case OFPBCT_OPEN_REQUEST:
2999 ds_put_cstr(s, "OPEN_REQUEST");
3001 case OFPBCT_OPEN_REPLY:
3002 ds_put_cstr(s, "OPEN_REPLY");
3004 case OFPBCT_CLOSE_REQUEST:
3005 ds_put_cstr(s, "CLOSE_REQUEST");
3007 case OFPBCT_CLOSE_REPLY:
3008 ds_put_cstr(s, "CLOSE_REPLY");
3010 case OFPBCT_COMMIT_REQUEST:
3011 ds_put_cstr(s, "COMMIT_REQUEST");
3013 case OFPBCT_COMMIT_REPLY:
3014 ds_put_cstr(s, "COMMIT_REPLY");
3016 case OFPBCT_DISCARD_REQUEST:
3017 ds_put_cstr(s, "DISCARD_REQUEST");
3019 case OFPBCT_DISCARD_REPLY:
3020 ds_put_cstr(s, "DISCARD_REPLY");
3024 ds_put_cstr(s, " flags=");
3025 ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' ');
3029 ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
3032 struct ofputil_bundle_add_msg badd;
3034 error = ofputil_decode_bundle_add(oh, &badd, NULL);
3036 ofp_print_error(s, error);
3040 ds_put_char(s, '\n');
3041 ds_put_format(s, " bundle_id=%#"PRIx32, badd.bundle_id);
3042 ds_put_cstr(s, " flags=");
3043 ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
3045 ds_put_char(s, '\n');
3046 char *msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
3047 ds_put_and_free_cstr(s, msg);
3051 print_tlv_table(struct ds *s, struct ovs_list *mappings)
3053 struct ofputil_tlv_map *map;
3055 ds_put_cstr(s, " mapping table:\n");
3056 ds_put_cstr(s, " class\ttype\tlength\tmatch field\n");
3057 ds_put_cstr(s, " -----\t----\t------\t-----------");
3059 LIST_FOR_EACH (map, list_node, mappings) {
3060 ds_put_char(s, '\n');
3061 ds_put_format(s, " 0x%"PRIx16"\t0x%"PRIx8"\t%"PRIu8"\ttun_metadata%"PRIu16,
3062 map->option_class, map->option_type, map->option_len,
3068 ofp_print_tlv_table_mod(struct ds *s, const struct ofp_header *oh)
3071 struct ofputil_tlv_table_mod ttm;
3073 error = ofputil_decode_tlv_table_mod(oh, &ttm);
3075 ofp_print_error(s, error);
3079 ds_put_cstr(s, "\n ");
3081 switch (ttm.command) {
3083 ds_put_cstr(s, "ADD");
3086 ds_put_cstr(s, "DEL");
3089 ds_put_cstr(s, "CLEAR");
3093 if (ttm.command != NXTTMC_CLEAR) {
3094 print_tlv_table(s, &ttm.mappings);
3097 ofputil_uninit_tlv_table(&ttm.mappings);
3101 ofp_print_tlv_table_reply(struct ds *s, const struct ofp_header *oh)
3104 struct ofputil_tlv_table_reply ttr;
3105 struct ofputil_tlv_map *map;
3106 int allocated_space = 0;
3108 error = ofputil_decode_tlv_table_reply(oh, &ttr);
3110 ofp_print_error(s, error);
3114 ds_put_char(s, '\n');
3116 LIST_FOR_EACH (map, list_node, &ttr.mappings) {
3117 allocated_space += map->option_len;
3120 ds_put_format(s, " max option space=%"PRIu32" max fields=%"PRIu16"\n",
3121 ttr.max_option_space, ttr.max_fields);
3122 ds_put_format(s, " allocated option space=%d\n", allocated_space);
3123 ds_put_char(s, '\n');
3124 print_tlv_table(s, &ttr.mappings);
3126 ofputil_uninit_tlv_table(&ttr.mappings);
3129 /* This function will print the request forward message. The reason for
3130 * request forward is taken from rf.request.type */
3132 ofp_print_requestforward(struct ds *string, const struct ofp_header *oh)
3134 struct ofputil_requestforward rf;
3137 error = ofputil_decode_requestforward(oh, &rf);
3139 ofp_print_error(string, error);
3143 ds_put_cstr(string, " reason=");
3145 switch (rf.reason) {
3146 case OFPRFR_GROUP_MOD:
3147 ds_put_cstr(string, "group_mod");
3148 ofp_print_group_mod__(string, oh->version, rf.group_mod);
3151 case OFPRFR_METER_MOD:
3152 ds_put_cstr(string, "meter_mod");
3153 ofp_print_meter_mod__(string, rf.meter_mod);
3156 case OFPRFR_N_REASONS:
3159 ofputil_destroy_requestforward(&rf);
3163 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
3164 struct ds *string, int verbosity)
3166 const void *msg = oh;
3168 ofp_header_to_string__(oh, raw, string);
3169 switch (ofptype_from_ofpraw(raw)) {
3171 case OFPTYPE_GROUP_STATS_REQUEST:
3172 ofp_print_stats(string, oh);
3173 ofp_print_ofpst_group_request(string, oh);
3176 case OFPTYPE_GROUP_STATS_REPLY:
3177 ofp_print_group_stats(string, oh);
3180 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
3181 ofp_print_stats(string, oh);
3182 ofp_print_ofpst_group_desc_request(string, oh);
3185 case OFPTYPE_GROUP_DESC_STATS_REPLY:
3186 ofp_print_group_desc(string, oh);
3189 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
3190 ofp_print_stats(string, oh);
3193 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
3194 ofp_print_group_features(string, oh);
3197 case OFPTYPE_GROUP_MOD:
3198 ofp_print_group_mod(string, oh);
3201 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
3202 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
3203 ofp_print_table_features_reply(string, oh);
3206 case OFPTYPE_TABLE_DESC_REQUEST:
3207 case OFPTYPE_TABLE_DESC_REPLY:
3208 ofp_print_table_desc_reply(string, oh);
3212 ofp_print_hello(string, oh);
3216 ofp_print_error_msg(string, oh);
3219 case OFPTYPE_ECHO_REQUEST:
3220 case OFPTYPE_ECHO_REPLY:
3221 ofp_print_echo(string, oh, verbosity);
3224 case OFPTYPE_FEATURES_REQUEST:
3227 case OFPTYPE_FEATURES_REPLY:
3228 ofp_print_switch_features(string, oh);
3231 case OFPTYPE_GET_CONFIG_REQUEST:
3234 case OFPTYPE_GET_CONFIG_REPLY:
3235 ofp_print_get_config_reply(string, oh);
3238 case OFPTYPE_SET_CONFIG:
3239 ofp_print_set_config(string, oh);
3242 case OFPTYPE_PACKET_IN:
3243 ofp_print_packet_in(string, oh, verbosity);
3246 case OFPTYPE_FLOW_REMOVED:
3247 ofp_print_flow_removed(string, oh);
3250 case OFPTYPE_PORT_STATUS:
3251 ofp_print_port_status(string, oh);
3254 case OFPTYPE_PACKET_OUT:
3255 ofp_print_packet_out(string, oh, verbosity);
3258 case OFPTYPE_FLOW_MOD:
3259 ofp_print_flow_mod(string, oh, verbosity);
3262 case OFPTYPE_PORT_MOD:
3263 ofp_print_port_mod(string, oh);
3266 case OFPTYPE_TABLE_MOD:
3267 ofp_print_table_mod(string, oh);
3270 case OFPTYPE_METER_MOD:
3271 ofp_print_meter_mod(string, oh);
3274 case OFPTYPE_BARRIER_REQUEST:
3275 case OFPTYPE_BARRIER_REPLY:
3278 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
3279 ofp_print_queue_get_config_request(string, oh);
3282 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
3283 ofp_print_queue_get_config_reply(string, oh);
3286 case OFPTYPE_ROLE_REQUEST:
3287 case OFPTYPE_ROLE_REPLY:
3288 ofp_print_role_message(string, oh);
3290 case OFPTYPE_ROLE_STATUS:
3291 ofp_print_role_status_message(string, oh);
3294 case OFPTYPE_REQUESTFORWARD:
3295 ofp_print_requestforward(string, oh);
3298 case OFPTYPE_METER_STATS_REQUEST:
3299 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
3300 ofp_print_stats(string, oh);
3301 ofp_print_meter_stats_request(string, oh);
3304 case OFPTYPE_METER_STATS_REPLY:
3305 ofp_print_stats(string, oh);
3306 ofp_print_meter_stats_reply(string, oh);
3309 case OFPTYPE_METER_CONFIG_STATS_REPLY:
3310 ofp_print_stats(string, oh);
3311 ofp_print_meter_config_reply(string, oh);
3314 case OFPTYPE_METER_FEATURES_STATS_REPLY:
3315 ofp_print_stats(string, oh);
3316 ofp_print_meter_features_reply(string, oh);
3319 case OFPTYPE_DESC_STATS_REQUEST:
3320 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
3321 ofp_print_stats(string, oh);
3324 case OFPTYPE_FLOW_STATS_REQUEST:
3325 case OFPTYPE_AGGREGATE_STATS_REQUEST:
3326 ofp_print_stats(string, oh);
3327 ofp_print_flow_stats_request(string, oh);
3330 case OFPTYPE_TABLE_STATS_REQUEST:
3331 ofp_print_stats(string, oh);
3334 case OFPTYPE_PORT_STATS_REQUEST:
3335 ofp_print_stats(string, oh);
3336 ofp_print_ofpst_port_request(string, oh);
3339 case OFPTYPE_QUEUE_STATS_REQUEST:
3340 ofp_print_stats(string, oh);
3341 ofp_print_ofpst_queue_request(string, oh);
3344 case OFPTYPE_DESC_STATS_REPLY:
3345 ofp_print_stats(string, oh);
3346 ofp_print_ofpst_desc_reply(string, oh);
3349 case OFPTYPE_FLOW_STATS_REPLY:
3350 ofp_print_stats(string, oh);
3351 ofp_print_flow_stats_reply(string, oh);
3354 case OFPTYPE_QUEUE_STATS_REPLY:
3355 ofp_print_stats(string, oh);
3356 ofp_print_ofpst_queue_reply(string, oh, verbosity);
3359 case OFPTYPE_PORT_STATS_REPLY:
3360 ofp_print_stats(string, oh);
3361 ofp_print_ofpst_port_reply(string, oh, verbosity);
3364 case OFPTYPE_TABLE_STATS_REPLY:
3365 ofp_print_stats(string, oh);
3366 ofp_print_table_stats_reply(string, oh);
3369 case OFPTYPE_AGGREGATE_STATS_REPLY:
3370 ofp_print_stats(string, oh);
3371 ofp_print_aggregate_stats_reply(string, oh);
3374 case OFPTYPE_PORT_DESC_STATS_REQUEST:
3375 ofp_print_stats(string, oh);
3376 ofp_print_ofpst_port_desc_request(string, oh);
3379 case OFPTYPE_PORT_DESC_STATS_REPLY:
3380 ofp_print_stats(string, oh);
3381 ofp_print_ofpst_port_desc_reply(string, oh);
3384 case OFPTYPE_FLOW_MOD_TABLE_ID:
3385 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
3388 case OFPTYPE_SET_FLOW_FORMAT:
3389 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
3392 case OFPTYPE_SET_PACKET_IN_FORMAT:
3393 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
3396 case OFPTYPE_FLOW_AGE:
3399 case OFPTYPE_SET_CONTROLLER_ID:
3400 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
3403 case OFPTYPE_GET_ASYNC_REPLY:
3404 case OFPTYPE_SET_ASYNC_CONFIG:
3405 ofp_print_nxt_set_async_config(string, oh);
3407 case OFPTYPE_GET_ASYNC_REQUEST:
3409 case OFPTYPE_FLOW_MONITOR_CANCEL:
3410 ofp_print_nxt_flow_monitor_cancel(string, msg);
3413 case OFPTYPE_FLOW_MONITOR_PAUSED:
3414 case OFPTYPE_FLOW_MONITOR_RESUMED:
3417 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
3418 ofp_print_nxst_flow_monitor_request(string, msg);
3421 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
3422 ofp_print_nxst_flow_monitor_reply(string, msg);
3425 case OFPTYPE_BUNDLE_CONTROL:
3426 ofp_print_bundle_ctrl(string, msg);
3429 case OFPTYPE_BUNDLE_ADD_MESSAGE:
3430 ofp_print_bundle_add(string, msg, verbosity);
3433 case OFPTYPE_NXT_TLV_TABLE_MOD:
3434 ofp_print_tlv_table_mod(string, msg);
3437 case OFPTYPE_NXT_TLV_TABLE_REQUEST:
3440 case OFPTYPE_NXT_TLV_TABLE_REPLY:
3441 ofp_print_tlv_table_reply(string, msg);
3447 /* Composes and returns a string representing the OpenFlow packet of 'len'
3448 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
3449 * verbosity and higher numbers increase verbosity. The caller is responsible
3450 * for freeing the string. */
3452 ofp_to_string(const void *oh_, size_t len, int verbosity)
3454 struct ds string = DS_EMPTY_INITIALIZER;
3455 const struct ofp_header *oh = oh_;
3458 ds_put_cstr(&string, "OpenFlow message is empty\n");
3459 } else if (len < sizeof(struct ofp_header)) {
3460 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
3462 } else if (ntohs(oh->length) > len) {
3466 error = ofpraw_decode_partial(&raw, oh, len);
3468 ofp_header_to_string__(oh, raw, &string);
3469 ds_put_char(&string, '\n');
3472 ds_put_format(&string,
3473 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
3474 len, ntohs(oh->length));
3475 } else if (ntohs(oh->length) < len) {
3476 ds_put_format(&string,
3477 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
3478 ntohs(oh->length), len);
3483 error = ofpraw_decode(&raw, oh);
3485 ofp_to_string__(oh, raw, &string, verbosity);
3486 if (verbosity >= 5) {
3487 if (ds_last(&string) != '\n') {
3488 ds_put_char(&string, '\n');
3490 ds_put_hex_dump(&string, oh, len, 0, true);
3492 if (ds_last(&string) != '\n') {
3493 ds_put_char(&string, '\n');
3495 return ds_steal_cstr(&string);
3498 ofp_print_error(&string, error);
3500 ds_put_hex_dump(&string, oh, len, 0, true);
3501 return ds_steal_cstr(&string);
3505 print_and_free(FILE *stream, char *string)
3507 fputs(string, stream);
3511 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
3512 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
3513 * numbers increase verbosity. */
3515 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
3517 print_and_free(stream, ofp_to_string(oh, len, verbosity));
3520 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
3521 * 'data' to 'stream'. */
3523 ofp_print_packet(FILE *stream, const void *data, size_t len)
3525 print_and_free(stream, ofp_packet_to_string(data, len));