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 format_hex_arg(struct ds *s, const uint8_t *data, size_t len)
100 for (size_t i = 0; i < len; i++) {
104 ds_put_format(s, "%02"PRIx8, data[i]);
109 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
112 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
113 struct ofputil_packet_in_private pin;
114 const struct ofputil_packet_in *public = &pin.public;
119 error = ofputil_decode_packet_in_private(oh, true,
120 &pin, &total_len, &buffer_id);
122 ofp_print_error(string, error);
126 if (public->table_id) {
127 ds_put_format(string, " table_id=%"PRIu8, public->table_id);
130 if (public->cookie != OVS_BE64_MAX) {
131 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(public->cookie));
134 ds_put_format(string, " total_len=%"PRIuSIZE" ", total_len);
136 match_format(&public->flow_metadata, string, OFP_DEFAULT_PRIORITY);
138 ds_put_format(string, " (via %s)",
139 ofputil_packet_in_reason_to_string(public->reason,
143 ds_put_format(string, " data_len=%"PRIuSIZE, public->packet_len);
144 if (buffer_id == UINT32_MAX) {
145 ds_put_format(string, " (unbuffered)");
146 if (total_len != public->packet_len) {
147 ds_put_format(string, " (***total_len != data_len***)");
150 ds_put_format(string, " buffer=0x%08"PRIx32, buffer_id);
151 if (total_len < public->packet_len) {
152 ds_put_format(string, " (***total_len < data_len***)");
155 ds_put_char(string, '\n');
157 if (public->userdata_len) {
158 ds_put_cstr(string, " userdata=");
159 format_hex_arg(string, pin.public.userdata, pin.public.userdata_len);
160 ds_put_char(string, '\n');
163 if (!uuid_is_zero(&pin.bridge)) {
164 ds_put_format(string, " continuation.bridge="UUID_FMT"\n",
165 UUID_ARGS(&pin.bridge));
169 ds_put_cstr(string, " continuation.stack=");
170 for (size_t i = 0; i < pin.n_stack; i++) {
172 ds_put_char(string, ' ');
174 mf_subvalue_format(&pin.stack[i], string);
179 ds_put_format(string, " continuation.mirrors=0x%"PRIx32"\n",
183 if (pin.conntracked) {
184 ds_put_cstr(string, " continuation.conntracked=true\n");
187 if (pin.actions_len) {
188 ds_put_cstr(string, " continuation.actions=");
189 ofpacts_format(pin.actions, pin.actions_len, string);
190 ds_put_char(string, '\n');
193 if (pin.action_set_len) {
194 ds_put_cstr(string, " continuation.action_set=");
195 ofpacts_format(pin.action_set, pin.action_set_len, string);
196 ds_put_char(string, '\n');
200 char *packet = ofp_packet_to_string(public->packet,
202 ds_put_cstr(string, packet);
206 ds_put_hex_dump(string, public->packet, public->packet_len, 0, false);
209 ofputil_packet_in_private_destroy(&pin);
213 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
216 struct ofputil_packet_out po;
217 struct ofpbuf ofpacts;
220 ofpbuf_init(&ofpacts, 64);
221 error = ofputil_decode_packet_out(&po, oh, &ofpacts);
223 ofpbuf_uninit(&ofpacts);
224 ofp_print_error(string, error);
228 ds_put_cstr(string, " in_port=");
229 ofputil_format_port(po.in_port, string);
231 ds_put_cstr(string, " actions=");
232 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
234 if (po.buffer_id == UINT32_MAX) {
235 ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
236 if (verbosity > 0 && po.packet_len > 0) {
237 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
238 ds_put_char(string, '\n');
239 ds_put_cstr(string, packet);
243 ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
246 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
249 ofpbuf_uninit(&ofpacts);
252 /* qsort comparison function. */
254 compare_ports(const void *a_, const void *b_)
256 const struct ofputil_phy_port *a = a_;
257 const struct ofputil_phy_port *b = b_;
258 uint16_t ap = ofp_to_u16(a->port_no);
259 uint16_t bp = ofp_to_u16(b->port_no);
261 return ap < bp ? -1 : ap > bp;
265 ofp_print_bit_names(struct ds *string, uint32_t bits,
266 const char *(*bit_to_name)(uint32_t bit),
273 ds_put_cstr(string, "0");
277 for (i = 0; i < 32; i++) {
278 uint32_t bit = UINT32_C(1) << i;
281 const char *name = bit_to_name(bit);
284 ds_put_char(string, separator);
286 ds_put_cstr(string, name);
294 ds_put_char(string, separator);
296 ds_put_format(string, "0x%"PRIx32, bits);
301 netdev_feature_to_name(uint32_t bit)
303 enum netdev_features f = bit;
306 case NETDEV_F_10MB_HD: return "10MB-HD";
307 case NETDEV_F_10MB_FD: return "10MB-FD";
308 case NETDEV_F_100MB_HD: return "100MB-HD";
309 case NETDEV_F_100MB_FD: return "100MB-FD";
310 case NETDEV_F_1GB_HD: return "1GB-HD";
311 case NETDEV_F_1GB_FD: return "1GB-FD";
312 case NETDEV_F_10GB_FD: return "10GB-FD";
313 case NETDEV_F_40GB_FD: return "40GB-FD";
314 case NETDEV_F_100GB_FD: return "100GB-FD";
315 case NETDEV_F_1TB_FD: return "1TB-FD";
316 case NETDEV_F_OTHER: return "OTHER";
317 case NETDEV_F_COPPER: return "COPPER";
318 case NETDEV_F_FIBER: return "FIBER";
319 case NETDEV_F_AUTONEG: return "AUTO_NEG";
320 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
321 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
328 ofp_print_port_features(struct ds *string, enum netdev_features features)
330 ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
331 ds_put_char(string, '\n');
335 ofputil_port_config_to_name(uint32_t bit)
337 enum ofputil_port_config pc = bit;
340 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
341 case OFPUTIL_PC_NO_STP: return "NO_STP";
342 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
343 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
344 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
345 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
346 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
353 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
355 ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
356 ds_put_char(string, '\n');
360 ofputil_port_state_to_name(uint32_t bit)
362 enum ofputil_port_state ps = bit;
365 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
366 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
367 case OFPUTIL_PS_LIVE: return "LIVE";
369 case OFPUTIL_PS_STP_LISTEN:
370 case OFPUTIL_PS_STP_LEARN:
371 case OFPUTIL_PS_STP_FORWARD:
372 case OFPUTIL_PS_STP_BLOCK:
373 /* Handled elsewhere. */
381 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
383 enum ofputil_port_state stp_state;
385 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
386 * pattern. We have to special case it.
388 * OVS doesn't support STP, so this field will always be 0 if we are
389 * talking to OVS, so we'd always print STP_LISTEN in that case.
390 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
391 * avoid confusing users. */
392 stp_state = state & OFPUTIL_PS_STP_MASK;
395 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
396 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
398 state &= ~OFPUTIL_PS_STP_MASK;
400 ofp_print_bit_names(string, state, ofputil_port_state_to_name,
404 ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
406 ds_put_char(string, '\n');
410 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
412 char name[sizeof port->name];
415 memcpy(name, port->name, sizeof name);
416 for (j = 0; j < sizeof name - 1; j++) {
417 if (!isprint((unsigned char) name[j])) {
423 ds_put_char(string, ' ');
424 ofputil_format_port(port->port_no, string);
425 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
426 name, ETH_ADDR_ARGS(port->hw_addr));
428 ds_put_cstr(string, " config: ");
429 ofp_print_port_config(string, port->config);
431 ds_put_cstr(string, " state: ");
432 ofp_print_port_state(string, port->state);
435 ds_put_format(string, " current: ");
436 ofp_print_port_features(string, port->curr);
438 if (port->advertised) {
439 ds_put_format(string, " advertised: ");
440 ofp_print_port_features(string, port->advertised);
442 if (port->supported) {
443 ds_put_format(string, " supported: ");
444 ofp_print_port_features(string, port->supported);
447 ds_put_format(string, " peer: ");
448 ofp_print_port_features(string, port->peer);
450 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
451 "%"PRIu32" Mbps max\n",
452 port->curr_speed / UINT32_C(1000),
453 port->max_speed / UINT32_C(1000));
456 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
457 * 'ofp_version', writes a detailed description of each port into
460 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
463 struct ofputil_phy_port *ports;
464 size_t allocated_ports, n_ports;
470 for (n_ports = 0; ; n_ports++) {
471 if (n_ports >= allocated_ports) {
472 ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
475 retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
481 qsort(ports, n_ports, sizeof *ports, compare_ports);
482 for (i = 0; i < n_ports; i++) {
483 ofp_print_phy_port(string, &ports[i]);
488 ofp_print_error(string, retval);
493 ofputil_capabilities_to_name(uint32_t bit)
495 enum ofputil_capabilities capabilities = bit;
497 switch (capabilities) {
498 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
499 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
500 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
501 case OFPUTIL_C_IP_REASM: return "IP_REASM";
502 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
503 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
504 case OFPUTIL_C_STP: return "STP";
505 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
506 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
513 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
515 struct ofputil_switch_features features;
516 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
517 enum ofperr error = ofputil_pull_switch_features(&b, &features);
519 ofp_print_error(string, error);
523 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
525 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
526 features.n_tables, features.n_buffers);
527 if (features.auxiliary_id) {
528 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
530 ds_put_char(string, '\n');
532 ds_put_cstr(string, "capabilities: ");
533 ofp_print_bit_names(string, features.capabilities,
534 ofputil_capabilities_to_name, ' ');
535 ds_put_char(string, '\n');
537 switch ((enum ofp_version)oh->version) {
539 ds_put_cstr(string, "actions: ");
540 ofpact_bitmap_format(features.ofpacts, string);
541 ds_put_char(string, '\n');
549 return; /* no ports in ofp13_switch_features */
554 ofp_print_phy_ports(string, oh->version, &b);
558 ofp_print_switch_config(struct ds *string,
559 const struct ofputil_switch_config *config)
561 ds_put_format(string, " frags=%s",
562 ofputil_frag_handling_to_string(config->frag));
564 if (config->invalid_ttl_to_controller > 0) {
565 ds_put_format(string, " invalid_ttl_to_controller");
568 ds_put_format(string, " miss_send_len=%"PRIu16"\n", config->miss_send_len);
572 ofp_print_set_config(struct ds *string, const struct ofp_header *oh)
574 struct ofputil_switch_config config;
577 error = ofputil_decode_set_config(oh, &config);
579 ofp_print_error(string, error);
582 ofp_print_switch_config(string, &config);
586 ofp_print_get_config_reply(struct ds *string, const struct ofp_header *oh)
588 struct ofputil_switch_config config;
589 ofputil_decode_get_config_reply(oh, &config);
590 ofp_print_switch_config(string, &config);
593 static void print_wild(struct ds *string, const char *leader, int is_wild,
594 int verbosity, const char *format, ...)
595 OVS_PRINTF_FORMAT(5, 6);
597 static void print_wild(struct ds *string, const char *leader, int is_wild,
598 int verbosity, const char *format, ...)
600 if (is_wild && verbosity < 2) {
603 ds_put_cstr(string, leader);
607 va_start(args, format);
608 ds_put_format_valist(string, format, args);
611 ds_put_char(string, '*');
613 ds_put_char(string, ',');
617 print_wild_port(struct ds *string, const char *leader, int is_wild,
618 int verbosity, ofp_port_t port)
620 if (is_wild && verbosity < 2) {
623 ds_put_cstr(string, leader);
625 ofputil_format_port(port, string);
627 ds_put_char(string, '*');
629 ds_put_char(string, ',');
633 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
634 uint32_t wild_bits, int verbosity)
636 if (wild_bits >= 32 && verbosity < 2) {
639 ds_put_cstr(string, leader);
640 if (wild_bits < 32) {
641 ds_put_format(string, IP_FMT, IP_ARGS(ip));
643 ds_put_format(string, "/%d", 32 - wild_bits);
646 ds_put_char(string, '*');
648 ds_put_char(string, ',');
652 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
654 char *s = ofp10_match_to_string(om, verbosity);
660 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
662 struct ds f = DS_EMPTY_INITIALIZER;
663 uint32_t w = ntohl(om->wildcards);
664 bool skip_type = false;
665 bool skip_proto = false;
667 if (!(w & OFPFW10_DL_TYPE)) {
669 if (om->dl_type == htons(ETH_TYPE_IP)) {
670 if (!(w & OFPFW10_NW_PROTO)) {
672 if (om->nw_proto == IPPROTO_ICMP) {
673 ds_put_cstr(&f, "icmp,");
674 } else if (om->nw_proto == IPPROTO_TCP) {
675 ds_put_cstr(&f, "tcp,");
676 } else if (om->nw_proto == IPPROTO_UDP) {
677 ds_put_cstr(&f, "udp,");
678 } else if (om->nw_proto == IPPROTO_SCTP) {
679 ds_put_cstr(&f, "sctp,");
681 ds_put_cstr(&f, "ip,");
685 ds_put_cstr(&f, "ip,");
687 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
688 ds_put_cstr(&f, "arp,");
689 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
690 ds_put_cstr(&f, "rarp,");
691 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
692 ds_put_cstr(&f, "mpls,");
693 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
694 ds_put_cstr(&f, "mplsm,");
699 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
700 u16_to_ofp(ntohs(om->in_port)));
701 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
702 "%d", ntohs(om->dl_vlan));
703 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
704 "%d", om->dl_vlan_pcp);
705 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
706 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
707 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
708 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
710 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
711 "0x%04x", ntohs(om->dl_type));
713 print_ip_netmask(&f, "nw_src=", om->nw_src,
714 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
716 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
717 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
720 if (om->dl_type == htons(ETH_TYPE_ARP) ||
721 om->dl_type == htons(ETH_TYPE_RARP)) {
722 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
725 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
729 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
731 if (om->nw_proto == IPPROTO_ICMP) {
732 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
733 "%d", ntohs(om->tp_src));
734 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
735 "%d", ntohs(om->tp_dst));
737 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
738 "%d", ntohs(om->tp_src));
739 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
740 "%d", ntohs(om->tp_dst));
747 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
749 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
750 ds_put_cstr(s, "send_flow_rem ");
752 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
753 ds_put_cstr(s, "check_overlap ");
755 if (flags & OFPUTIL_FF_RESET_COUNTS) {
756 ds_put_cstr(s, "reset_counts ");
758 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
759 ds_put_cstr(s, "no_packet_counts ");
761 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
762 ds_put_cstr(s, "no_byte_counts ");
764 if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
765 ds_put_cstr(s, "allow_hidden_fields ");
767 if (flags & OFPUTIL_FF_NO_READONLY) {
768 ds_put_cstr(s, "no_readonly_table ");
773 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
775 struct ofputil_flow_mod fm;
776 struct ofpbuf ofpacts;
780 enum ofputil_protocol protocol;
782 protocol = ofputil_protocol_from_ofp_version(oh->version);
783 protocol = ofputil_protocol_set_tid(protocol, true);
785 ofpbuf_init(&ofpacts, 64);
786 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
789 ofpbuf_uninit(&ofpacts);
790 ofp_print_error(s, error);
795 switch (fm.command) {
797 ds_put_cstr(s, "ADD");
800 ds_put_cstr(s, "MOD");
802 case OFPFC_MODIFY_STRICT:
803 ds_put_cstr(s, "MOD_STRICT");
806 ds_put_cstr(s, "DEL");
808 case OFPFC_DELETE_STRICT:
809 ds_put_cstr(s, "DEL_STRICT");
812 ds_put_format(s, "cmd:%d", fm.command);
814 if (fm.table_id != 0) {
815 ds_put_format(s, " table:%d", fm.table_id);
819 ofpraw_decode(&raw, oh);
820 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
821 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
822 ofp10_match_print(s, &ofm->match, verbosity);
824 /* ofp_print_match() doesn't print priority. */
825 need_priority = true;
826 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
827 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
828 const void *nxm = nfm + 1;
831 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
832 ds_put_cstr(s, nxm_s);
835 /* nx_match_to_string() doesn't print priority. */
836 need_priority = true;
838 match_format(&fm.match, s, fm.priority);
840 /* match_format() does print priority. */
841 need_priority = false;
844 if (ds_last(s) != ' ') {
847 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
848 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
850 if (fm.cookie_mask != htonll(0)) {
851 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
852 ntohll(fm.cookie), ntohll(fm.cookie_mask));
854 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
855 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
857 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
858 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
860 if (fm.importance != 0) {
861 ds_put_format(s, "importance:%"PRIu16" ", fm.importance);
863 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
864 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
866 if (fm.buffer_id != UINT32_MAX) {
867 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
869 if (fm.out_port != OFPP_ANY) {
870 ds_put_format(s, "out_port:");
871 ofputil_format_port(fm.out_port, s);
875 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
876 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
877 * versions don't really have such a flag and printing one is likely to
879 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
881 ofp_print_flow_flags(s, fm.flags);
883 ds_put_cstr(s, "actions=");
884 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
885 ofpbuf_uninit(&ofpacts);
889 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
891 ds_put_format(string, "%u", sec);
893 /* If there are no fractional seconds, don't print any decimals.
895 * If the fractional seconds can be expressed exactly as milliseconds,
896 * print 3 decimals. Open vSwitch provides millisecond precision for most
897 * time measurements, so printing 3 decimals every time makes it easier to
898 * spot real changes in flow dumps that refresh themselves quickly.
900 * If the fractional seconds are more precise than milliseconds, print the
901 * number of decimals needed to express them exactly.
904 unsigned int msec = nsec / 1000000;
905 if (msec * 1000000 == nsec) {
906 ds_put_format(string, ".%03u", msec);
908 ds_put_format(string, ".%09u", nsec);
909 while (string->string[string->length - 1] == '0') {
914 ds_put_char(string, 's');
917 /* Returns a string form of 'reason'. The return value is either a statically
918 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
919 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
920 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
922 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
923 char *reasonbuf, size_t bufsize)
926 case OFPRR_IDLE_TIMEOUT:
928 case OFPRR_HARD_TIMEOUT:
932 case OFPRR_GROUP_DELETE:
933 return "group_delete";
936 case OFPRR_METER_DELETE:
937 return "meter_delete";
940 snprintf(reasonbuf, bufsize, "%d", (int) reason);
946 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
948 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
949 struct ofputil_flow_removed fr;
952 error = ofputil_decode_flow_removed(&fr, oh);
954 ofp_print_error(string, error);
958 ds_put_char(string, ' ');
959 match_format(&fr.match, string, fr.priority);
961 ds_put_format(string, " reason=%s",
962 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
965 if (fr.table_id != 255) {
966 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
969 if (fr.cookie != htonll(0)) {
970 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
972 ds_put_cstr(string, " duration");
973 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
974 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
975 if (fr.hard_timeout) {
976 /* The hard timeout was only added in OF1.2, so only print it if it is
977 * actually in use to avoid gratuitous change to the formatting. */
978 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
980 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
981 fr.packet_count, fr.byte_count);
985 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
987 struct ofputil_port_mod pm;
990 error = ofputil_decode_port_mod(oh, &pm, true);
992 ofp_print_error(string, error);
996 ds_put_cstr(string, " port: ");
997 ofputil_format_port(pm.port_no, string);
998 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
999 ETH_ADDR_ARGS(pm.hw_addr));
1001 ds_put_cstr(string, " config: ");
1002 ofp_print_port_config(string, pm.config);
1004 ds_put_cstr(string, " mask: ");
1005 ofp_print_port_config(string, pm.mask);
1007 ds_put_cstr(string, " advertise: ");
1009 ofp_print_port_features(string, pm.advertise);
1011 ds_put_cstr(string, "UNCHANGED\n");
1016 ofputil_table_miss_to_string(enum ofputil_table_miss miss)
1019 case OFPUTIL_TABLE_MISS_DEFAULT: return "default";
1020 case OFPUTIL_TABLE_MISS_CONTROLLER: return "controller";
1021 case OFPUTIL_TABLE_MISS_CONTINUE: return "continue";
1022 case OFPUTIL_TABLE_MISS_DROP: return "drop";
1023 default: return "***error***";
1028 ofputil_table_eviction_to_string(enum ofputil_table_eviction eviction)
1031 case OFPUTIL_TABLE_EVICTION_DEFAULT: return "default";
1032 case OFPUTIL_TABLE_EVICTION_ON: return "on";
1033 case OFPUTIL_TABLE_EVICTION_OFF: return "off";
1034 default: return "***error***";
1040 ofputil_eviction_flag_to_string(uint32_t bit)
1042 enum ofp14_table_mod_prop_eviction_flag eviction_flag = bit;
1044 switch (eviction_flag) {
1045 case OFPTMPEF14_OTHER: return "OTHER";
1046 case OFPTMPEF14_IMPORTANCE: return "IMPORTANCE";
1047 case OFPTMPEF14_LIFETIME: return "LIFETIME";
1053 /* Appends to 'string' a description of the bitmap of OFPTMPEF14_* values in
1054 * 'eviction_flags'. */
1056 ofputil_put_eviction_flags(struct ds *string, uint32_t eviction_flags)
1058 if (eviction_flags != UINT32_MAX) {
1059 ofp_print_bit_names(string, eviction_flags,
1060 ofputil_eviction_flag_to_string, '|');
1062 ds_put_cstr(string, "(default)");
1067 ofputil_table_vacancy_to_string(enum ofputil_table_vacancy vacancy)
1070 case OFPUTIL_TABLE_VACANCY_DEFAULT: return "default";
1071 case OFPUTIL_TABLE_VACANCY_ON: return "on";
1072 case OFPUTIL_TABLE_VACANCY_OFF: return "off";
1073 default: return "***error***";
1079 ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
1081 struct ofputil_table_mod pm;
1084 error = ofputil_decode_table_mod(oh, &pm);
1086 ofp_print_error(string, error);
1090 if (pm.table_id == 0xff) {
1091 ds_put_cstr(string, " table_id: ALL_TABLES");
1093 ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
1096 if (pm.miss != OFPUTIL_TABLE_MISS_DEFAULT) {
1097 ds_put_format(string, ", flow_miss_config=%s",
1098 ofputil_table_miss_to_string(pm.miss));
1100 if (pm.eviction != OFPUTIL_TABLE_EVICTION_DEFAULT) {
1101 ds_put_format(string, ", eviction=%s",
1102 ofputil_table_eviction_to_string(pm.eviction));
1104 if (pm.eviction_flags != UINT32_MAX) {
1105 ds_put_cstr(string, "eviction_flags=");
1106 ofputil_put_eviction_flags(string, pm.eviction_flags);
1108 if (pm.vacancy != OFPUTIL_TABLE_VACANCY_DEFAULT) {
1109 ds_put_format(string, ", vacancy=%s",
1110 ofputil_table_vacancy_to_string(pm.vacancy));
1111 if (pm.vacancy == OFPUTIL_TABLE_VACANCY_ON) {
1112 ds_put_format(string, " vacancy:%"PRIu8""
1113 ",%"PRIu8"", pm.table_vacancy.vacancy_down,
1114 pm.table_vacancy.vacancy_up);
1119 /* This function will print the Table description properties. */
1121 ofp_print_table_desc(struct ds *string, const struct ofputil_table_desc *td)
1123 ds_put_format(string, "\n table %"PRIu8, td->table_id);
1124 ds_put_cstr(string, ":\n");
1125 ds_put_format(string, " eviction=%s eviction_flags=",
1126 ofputil_table_eviction_to_string(td->eviction));
1127 ofputil_put_eviction_flags(string, td->eviction_flags);
1128 ds_put_char(string, '\n');
1129 ds_put_format(string, " vacancy=%s",
1130 ofputil_table_vacancy_to_string(td->vacancy));
1131 if (td->vacancy == OFPUTIL_TABLE_VACANCY_ON) {
1132 ds_put_format(string, " vacancy_down=%"PRIu8"%%",
1133 td->table_vacancy.vacancy_down);
1134 ds_put_format(string, " vacancy_up=%"PRIu8"%%",
1135 td->table_vacancy.vacancy_up);
1136 ds_put_format(string, " vacancy=%"PRIu8"%%",
1137 td->table_vacancy.vacancy);
1139 ds_put_char(string, '\n');
1143 ofp_print_table_status_message(struct ds *string, const struct ofp_header *oh)
1145 struct ofputil_table_status ts;
1148 error = ofputil_decode_table_status(oh, &ts);
1150 ofp_print_error(string, error);
1154 if (ts.reason == OFPTR_VACANCY_DOWN) {
1155 ds_put_format(string, " reason=VACANCY_DOWN");
1156 } else if (ts.reason == OFPTR_VACANCY_UP) {
1157 ds_put_format(string, " reason=VACANCY_UP");
1160 ds_put_format(string, "\ntable_desc:-");
1161 ofp_print_table_desc(string, &ts.desc);
1165 ofp_print_queue_get_config_request(struct ds *string,
1166 const struct ofp_header *oh)
1172 error = ofputil_decode_queue_get_config_request(oh, &port, &queue);
1174 ofp_print_error(string, error);
1178 ds_put_cstr(string, " port=");
1179 ofputil_format_port(port, string);
1181 if (queue != OFPQ_ALL) {
1182 ds_put_cstr(string, " queue=");
1183 ofp_print_queue_name(string, queue);
1188 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1191 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1192 } else if (rate < UINT16_MAX) {
1193 ds_put_format(string, " %s:(disabled)", name);
1198 ofp_print_queue_get_config_reply(struct ds *string,
1199 const struct ofp_header *oh)
1201 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1202 ofp_port_t port = 0;
1204 ds_put_char(string, ' ');
1206 struct ofputil_queue_config queue;
1209 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1211 if (retval != EOF) {
1212 ofp_print_error(string, retval);
1214 ds_chomp(string, ' ');
1218 if (queue.port != port) {
1221 ds_put_cstr(string, "port=");
1222 ofputil_format_port(port, string);
1223 ds_put_char(string, '\n');
1226 ds_put_format(string, "queue %"PRIu32":", queue.queue);
1227 print_queue_rate(string, "min_rate", queue.min_rate);
1228 print_queue_rate(string, "max_rate", queue.max_rate);
1229 ds_put_char(string, '\n');
1234 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1236 if (flags & OFPMF13_KBPS) {
1237 ds_put_cstr(s, "kbps ");
1239 if (flags & OFPMF13_PKTPS) {
1240 ds_put_cstr(s, "pktps ");
1242 if (flags & OFPMF13_BURST) {
1243 ds_put_cstr(s, "burst ");
1245 if (flags & OFPMF13_STATS) {
1246 ds_put_cstr(s, "stats ");
1249 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1251 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1256 ofp_print_meter_band(struct ds *s, uint16_t flags,
1257 const struct ofputil_meter_band *mb)
1259 ds_put_cstr(s, "\ntype=");
1262 ds_put_cstr(s, "drop");
1264 case OFPMBT13_DSCP_REMARK:
1265 ds_put_cstr(s, "dscp_remark");
1268 ds_put_format(s, "%u", mb->type);
1271 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1273 if (flags & OFPMF13_BURST) {
1274 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1276 if (mb->type == OFPMBT13_DSCP_REMARK) {
1277 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1282 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1286 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1287 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1288 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1289 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1290 ds_put_cstr(s, "duration:");
1291 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1292 ds_put_char(s, ' ');
1294 ds_put_cstr(s, "bands:\n");
1295 for (i = 0; i < ms->n_bands; ++i) {
1296 ds_put_format(s, "%d: ", i);
1297 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1298 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1303 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1307 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1309 ofp_print_meter_flags(s, mc->flags);
1311 ds_put_cstr(s, "bands=");
1312 for (i = 0; i < mc->n_bands; ++i) {
1313 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1315 ds_put_char(s, '\n');
1319 ofp_print_meter_mod__(struct ds *s, const struct ofputil_meter_mod *mm)
1321 switch (mm->command) {
1323 ds_put_cstr(s, " ADD ");
1325 case OFPMC13_MODIFY:
1326 ds_put_cstr(s, " MOD ");
1328 case OFPMC13_DELETE:
1329 ds_put_cstr(s, " DEL ");
1332 ds_put_format(s, " cmd:%d ", mm->command);
1335 ofp_print_meter_config(s, &mm->meter);
1339 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1341 struct ofputil_meter_mod mm;
1342 struct ofpbuf bands;
1345 ofpbuf_init(&bands, 64);
1346 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1348 ofp_print_error(s, error);
1350 ofp_print_meter_mod__(s, &mm);
1352 ofpbuf_uninit(&bands);
1356 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1360 ofputil_decode_meter_request(oh, &meter_id);
1362 ds_put_format(s, " meter=%"PRIu32, meter_id);
1366 ofputil_meter_capabilities_to_name(uint32_t bit)
1368 enum ofp13_meter_flags flag = bit;
1371 case OFPMF13_KBPS: return "kbps";
1372 case OFPMF13_PKTPS: return "pktps";
1373 case OFPMF13_BURST: return "burst";
1374 case OFPMF13_STATS: return "stats";
1381 ofputil_meter_band_types_to_name(uint32_t bit)
1384 case 1 << OFPMBT13_DROP: return "drop";
1385 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1392 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1394 struct ofputil_meter_features mf;
1396 ofputil_decode_meter_features(oh, &mf);
1398 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1399 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1400 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1402 ds_put_cstr(s, "band_types: ");
1403 ofp_print_bit_names(s, mf.band_types,
1404 ofputil_meter_band_types_to_name, ' ');
1405 ds_put_char(s, '\n');
1407 ds_put_cstr(s, "capabilities: ");
1408 ofp_print_bit_names(s, mf.capabilities,
1409 ofputil_meter_capabilities_to_name, ' ');
1410 ds_put_char(s, '\n');
1414 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1416 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1417 struct ofpbuf bands;
1419 ofpbuf_init(&bands, 64);
1421 struct ofputil_meter_config mc;
1424 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1426 if (retval != EOF) {
1427 ofp_print_error(s, retval);
1431 ds_put_char(s, '\n');
1432 ofp_print_meter_config(s, &mc);
1434 ofpbuf_uninit(&bands);
1438 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1440 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1441 struct ofpbuf bands;
1443 ofpbuf_init(&bands, 64);
1445 struct ofputil_meter_stats ms;
1448 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1450 if (retval != EOF) {
1451 ofp_print_error(s, retval);
1455 ds_put_char(s, '\n');
1456 ofp_print_meter_stats(s, &ms);
1458 ofpbuf_uninit(&bands);
1462 ofp_print_error(struct ds *string, enum ofperr error)
1464 if (string->length) {
1465 ds_put_char(string, ' ');
1467 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1471 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1473 uint32_t allowed_versions;
1476 ok = ofputil_decode_hello(oh, &allowed_versions);
1478 ds_put_cstr(string, "\n version bitmap: ");
1479 ofputil_format_version_bitmap(string, allowed_versions);
1482 ds_put_cstr(string, "\n unknown data in hello:\n");
1483 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1488 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1490 size_t len = ntohs(oh->length);
1491 struct ofpbuf payload;
1495 error = ofperr_decode_msg(oh, &payload);
1497 ds_put_cstr(string, "***decode error***");
1498 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1502 ds_put_format(string, " %s\n", ofperr_get_name(error));
1504 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1505 ds_put_printable(string, payload.data, payload.size);
1507 s = ofp_to_string(payload.data, payload.size, 1);
1508 ds_put_cstr(string, s);
1511 ofpbuf_uninit(&payload);
1515 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1517 struct ofputil_port_status ps;
1520 error = ofputil_decode_port_status(oh, &ps);
1522 ofp_print_error(string, error);
1526 if (ps.reason == OFPPR_ADD) {
1527 ds_put_format(string, " ADD:");
1528 } else if (ps.reason == OFPPR_DELETE) {
1529 ds_put_format(string, " DEL:");
1530 } else if (ps.reason == OFPPR_MODIFY) {
1531 ds_put_format(string, " MOD:");
1534 ofp_print_phy_port(string, &ps.desc);
1538 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1540 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1542 ds_put_char(string, '\n');
1543 ds_put_format(string, "Manufacturer: %.*s\n",
1544 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1545 ds_put_format(string, "Hardware: %.*s\n",
1546 (int) sizeof ods->hw_desc, ods->hw_desc);
1547 ds_put_format(string, "Software: %.*s\n",
1548 (int) sizeof ods->sw_desc, ods->sw_desc);
1549 ds_put_format(string, "Serial Num: %.*s\n",
1550 (int) sizeof ods->serial_num, ods->serial_num);
1551 ds_put_format(string, "DP Description: %.*s\n",
1552 (int) sizeof ods->dp_desc, ods->dp_desc);
1556 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1558 struct ofputil_flow_stats_request fsr;
1561 error = ofputil_decode_flow_stats_request(&fsr, oh);
1563 ofp_print_error(string, error);
1567 if (fsr.table_id != 0xff) {
1568 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1571 if (fsr.out_port != OFPP_ANY) {
1572 ds_put_cstr(string, " out_port=");
1573 ofputil_format_port(fsr.out_port, string);
1576 ds_put_char(string, ' ');
1577 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1581 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1583 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1584 ntohll(fs->cookie));
1586 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1587 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1588 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1589 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1590 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1591 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1593 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1594 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1597 ofp_print_flow_flags(string, fs->flags);
1599 if (fs->importance != 0) {
1600 ds_put_format(string, "importance=%"PRIu16", ", fs->importance);
1602 if (fs->idle_age >= 0) {
1603 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1605 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1606 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1609 match_format(&fs->match, string, fs->priority);
1610 if (string->string[string->length - 1] != ' ') {
1611 ds_put_char(string, ' ');
1614 ds_put_cstr(string, "actions=");
1615 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1619 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1621 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1622 struct ofpbuf ofpacts;
1624 ofpbuf_init(&ofpacts, 64);
1626 struct ofputil_flow_stats fs;
1629 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1631 if (retval != EOF) {
1632 ds_put_cstr(string, " ***parse error***");
1636 ds_put_char(string, '\n');
1637 ofp_print_flow_stats(string, &fs);
1639 ofpbuf_uninit(&ofpacts);
1643 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1645 struct ofputil_aggregate_stats as;
1648 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1650 ofp_print_error(string, error);
1654 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1655 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1656 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1660 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1662 ds_put_cstr(string, leader);
1663 if (stat != UINT64_MAX) {
1664 ds_put_format(string, "%"PRIu64, stat);
1666 ds_put_char(string, '?');
1669 ds_put_cstr(string, ", ");
1671 ds_put_cstr(string, "\n");
1676 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1678 ofp_port_t ofp10_port;
1681 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1683 ofp_print_error(string, error);
1687 ds_put_cstr(string, " port_no=");
1688 ofputil_format_port(ofp10_port, string);
1692 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1695 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1696 if (verbosity < 1) {
1700 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1702 struct ofputil_port_stats ps;
1705 retval = ofputil_decode_port_stats(&ps, &b);
1707 if (retval != EOF) {
1708 ds_put_cstr(string, " ***parse error***");
1713 ds_put_cstr(string, " port ");
1714 if (ofp_to_u16(ps.port_no) < 10) {
1715 ds_put_char(string, ' ');
1717 ofputil_format_port(ps.port_no, string);
1719 ds_put_cstr(string, ": rx ");
1720 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1721 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1722 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1723 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1724 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1725 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1726 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1728 ds_put_cstr(string, " tx ");
1729 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1730 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1731 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1732 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1733 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1735 if (ps.duration_sec != UINT32_MAX) {
1736 ds_put_cstr(string, " duration=");
1737 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1738 ds_put_char(string, '\n');
1744 ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh)
1746 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1747 ofpraw_pull_assert(&b);
1749 struct ofputil_table_features prev_features;
1750 struct ofputil_table_stats prev_stats;
1751 for (int i = 0;; i++) {
1752 struct ofputil_table_features features;
1753 struct ofputil_table_stats stats;
1756 retval = ofputil_decode_table_stats_reply(&b, &stats, &features);
1758 if (retval != EOF) {
1759 ofp_print_error(string, retval);
1764 ds_put_char(string, '\n');
1765 ofp_print_table_features(string,
1766 &features, i ? &prev_features : NULL,
1767 &stats, i ? &prev_stats : NULL);
1768 prev_features = features;
1774 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1776 if (queue_id == OFPQ_ALL) {
1777 ds_put_cstr(string, "ALL");
1779 ds_put_format(string, "%"PRIu32, queue_id);
1784 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1786 struct ofputil_queue_stats_request oqsr;
1789 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1791 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1795 ds_put_cstr(string, " port=");
1796 ofputil_format_port(oqsr.port_no, string);
1798 ds_put_cstr(string, " queue=");
1799 ofp_print_queue_name(string, oqsr.queue_id);
1803 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1806 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1807 if (verbosity < 1) {
1811 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1813 struct ofputil_queue_stats qs;
1816 retval = ofputil_decode_queue_stats(&qs, &b);
1818 if (retval != EOF) {
1819 ds_put_cstr(string, " ***parse error***");
1824 ds_put_cstr(string, " port ");
1825 ofputil_format_port(qs.port_no, string);
1826 ds_put_cstr(string, " queue ");
1827 ofp_print_queue_name(string, qs.queue_id);
1828 ds_put_cstr(string, ": ");
1830 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1831 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1832 print_port_stat(string, "errors=", qs.tx_errors, 1);
1834 ds_put_cstr(string, "duration=");
1835 if (qs.duration_sec != UINT32_MAX) {
1836 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1838 ds_put_char(string, '?');
1840 ds_put_char(string, '\n');
1845 ofp_print_ofpst_port_desc_request(struct ds *string,
1846 const struct ofp_header *oh)
1851 error = ofputil_decode_port_desc_stats_request(oh, &port);
1853 ofp_print_error(string, error);
1857 ds_put_cstr(string, " port=");
1858 ofputil_format_port(port, string);
1862 ofp_print_ofpst_port_desc_reply(struct ds *string,
1863 const struct ofp_header *oh)
1865 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
1866 ofpraw_pull_assert(&b);
1867 ds_put_char(string, '\n');
1868 ofp_print_phy_ports(string, oh->version, &b);
1872 ofp_print_stats(struct ds *string, const struct ofp_header *oh)
1874 uint16_t flags = ofpmp_flags(oh);
1877 ds_put_cstr(string, " flags=");
1878 if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION)
1879 && (flags & OFPSF_REPLY_MORE)) {
1880 ds_put_cstr(string, "[more]");
1881 flags &= ~OFPSF_REPLY_MORE;
1884 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1891 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1893 size_t len = ntohs(oh->length);
1895 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1896 if (verbosity > 1) {
1897 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1902 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1903 uint64_t generation_id)
1905 ds_put_cstr(string, " role=");
1908 case OFPCR12_ROLE_NOCHANGE:
1909 ds_put_cstr(string, "nochange");
1911 case OFPCR12_ROLE_EQUAL:
1912 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1914 case OFPCR12_ROLE_MASTER:
1915 ds_put_cstr(string, "master");
1917 case OFPCR12_ROLE_SLAVE:
1918 ds_put_cstr(string, "slave");
1924 if (generation_id != UINT64_MAX) {
1925 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1930 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1932 struct ofputil_role_request rr;
1935 error = ofputil_decode_role_message(oh, &rr);
1937 ofp_print_error(string, error);
1941 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1945 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1947 struct ofputil_role_status rs;
1950 error = ofputil_decode_role_status(oh, &rs);
1952 ofp_print_error(string, error);
1956 ofp_print_role_generic(string, rs.role, rs.generation_id);
1958 ds_put_cstr(string, " reason=");
1960 switch (rs.reason) {
1961 case OFPCRR_MASTER_REQUEST:
1962 ds_put_cstr(string, "master_request");
1965 ds_put_cstr(string, "configuration_changed");
1967 case OFPCRR_EXPERIMENTER:
1968 ds_put_cstr(string, "experimenter_data_changed");
1970 case OFPCRR_N_REASONS:
1977 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1978 const struct nx_flow_mod_table_id *nfmti)
1980 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1984 ofp_print_nxt_set_flow_format(struct ds *string,
1985 const struct nx_set_flow_format *nsff)
1987 uint32_t format = ntohl(nsff->format);
1989 ds_put_cstr(string, " format=");
1990 if (ofputil_nx_flow_format_is_valid(format)) {
1991 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
1993 ds_put_format(string, "%"PRIu32, format);
1998 ofp_print_nxt_set_packet_in_format(struct ds *string,
1999 const struct nx_set_packet_in_format *nspf)
2001 uint32_t format = ntohl(nspf->format);
2003 ds_put_cstr(string, " format=");
2004 if (ofputil_packet_in_format_is_valid(format)) {
2005 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
2007 ds_put_format(string, "%"PRIu32, format);
2011 /* Returns a string form of 'reason'. The return value is either a statically
2012 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2013 * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
2014 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2016 ofp_port_reason_to_string(enum ofp_port_reason reason,
2017 char *reasonbuf, size_t bufsize)
2029 case OFPPR_N_REASONS:
2031 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2036 /* Returns a string form of 'reason'. The return value is either a statically
2037 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2038 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
2040 ofp_role_reason_to_string(enum ofp14_controller_role_reason reason,
2041 char *reasonbuf, size_t bufsize)
2044 case OFPCRR_MASTER_REQUEST:
2045 return "master_request";
2048 return "configuration_changed";
2050 case OFPCRR_EXPERIMENTER:
2051 return "experimenter_data_changed";
2053 case OFPCRR_N_REASONS:
2055 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2060 /* Returns a string form of 'reason'. The return value is either a statically
2061 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2062 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
2064 ofp_table_reason_to_string(enum ofp14_table_reason reason,
2065 char *reasonbuf, size_t bufsize)
2068 case OFPTR_VACANCY_DOWN:
2069 return "vacancy_down";
2071 case OFPTR_VACANCY_UP:
2072 return "vacancy_up";
2075 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2080 /* Returns a string form of 'reason'. The return value is either a statically
2081 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2082 * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */
2084 ofp_requestforward_reason_to_string(enum ofp14_requestforward_reason reason,
2085 char *reasonbuf, size_t bufsize)
2088 case OFPRFR_GROUP_MOD:
2089 return "group_mod_request";
2091 case OFPRFR_METER_MOD:
2092 return "meter_mod_request";
2094 case OFPRFR_N_REASONS:
2096 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2102 ofp_async_config_reason_to_string(uint32_t reason,
2103 enum ofputil_async_msg_type type,
2104 char *reasonbuf, size_t bufsize)
2108 return ofputil_packet_in_reason_to_string(reason, reasonbuf, bufsize);
2110 case OAM_PORT_STATUS:
2111 return ofp_port_reason_to_string(reason, reasonbuf, bufsize);
2113 case OAM_FLOW_REMOVED:
2114 return ofp_flow_removed_reason_to_string(reason, reasonbuf, bufsize);
2116 case OAM_ROLE_STATUS:
2117 return ofp_role_reason_to_string(reason, reasonbuf, bufsize);
2119 case OAM_TABLE_STATUS:
2120 return ofp_table_reason_to_string(reason, reasonbuf, bufsize);
2122 case OAM_REQUESTFORWARD:
2123 return ofp_requestforward_reason_to_string(reason, reasonbuf, bufsize);
2127 return "Unknown asynchronous configuration message type";
2132 #define OFP_ASYNC_CONFIG_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2134 ofp_print_set_async_config(struct ds *string, const struct ofp_header *oh,
2137 struct ofputil_async_cfg basis = OFPUTIL_ASYNC_CFG_INIT;
2138 struct ofputil_async_cfg ac;
2140 bool is_reply = type == OFPTYPE_GET_ASYNC_REPLY;
2141 enum ofperr error = ofputil_decode_set_async_config(oh, is_reply,
2144 ofp_print_error(string, error);
2148 for (int i = 0; i < 2; i++) {
2149 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2150 for (uint32_t type = 0; type < OAM_N_TYPES; type++) {
2151 ds_put_format(string, "%16s:",
2152 ofputil_async_msg_type_to_string(type));
2154 uint32_t role = i == 0 ? ac.master[type] : ac.slave[type];
2155 for (int j = 0; j < 32; j++) {
2156 if (role & (1u << j)) {
2157 char reasonbuf[OFP_ASYNC_CONFIG_REASON_BUFSIZE];
2160 reason = ofp_async_config_reason_to_string(
2161 j, type, reasonbuf, sizeof reasonbuf);
2163 ds_put_format(string, " %s", reason);
2168 ds_put_cstr(string, " (off)");
2170 ds_put_char(string, '\n');
2176 ofp_print_nxt_set_controller_id(struct ds *string,
2177 const struct nx_controller_id *nci)
2179 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
2183 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
2184 const struct ofp_header *oh)
2186 ds_put_format(string, " id=%"PRIu32,
2187 ofputil_decode_flow_monitor_cancel(oh));
2191 nx_flow_monitor_flags_to_name(uint32_t bit)
2193 enum nx_flow_monitor_flags fmf = bit;
2196 case NXFMF_INITIAL: return "initial";
2197 case NXFMF_ADD: return "add";
2198 case NXFMF_DELETE: return "delete";
2199 case NXFMF_MODIFY: return "modify";
2200 case NXFMF_ACTIONS: return "actions";
2201 case NXFMF_OWN: return "own";
2208 ofp_print_nxst_flow_monitor_request(struct ds *string,
2209 const struct ofp_header *oh)
2211 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
2213 struct ofputil_flow_monitor_request request;
2216 retval = ofputil_decode_flow_monitor_request(&request, &b);
2218 if (retval != EOF) {
2219 ofp_print_error(string, retval);
2224 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
2225 ofp_print_bit_names(string, request.flags,
2226 nx_flow_monitor_flags_to_name, ',');
2228 if (request.out_port != OFPP_NONE) {
2229 ds_put_cstr(string, " out_port=");
2230 ofputil_format_port(request.out_port, string);
2233 if (request.table_id != 0xff) {
2234 ds_put_format(string, " table=%"PRIu8, request.table_id);
2237 ds_put_char(string, ' ');
2238 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
2239 ds_chomp(string, ' ');
2244 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2245 const struct ofp_header *oh)
2247 uint64_t ofpacts_stub[1024 / 8];
2248 struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
2249 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
2252 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2253 struct ofputil_flow_update update;
2257 update.match = &match;
2258 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2260 if (retval != EOF) {
2261 ofp_print_error(string, retval);
2263 ofpbuf_uninit(&ofpacts);
2267 ds_put_cstr(string, "\n event=");
2268 switch (update.event) {
2270 ds_put_cstr(string, "ADDED");
2274 ds_put_format(string, "DELETED reason=%s",
2275 ofp_flow_removed_reason_to_string(update.reason,
2280 case NXFME_MODIFIED:
2281 ds_put_cstr(string, "MODIFIED");
2285 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2289 ds_put_format(string, " table=%"PRIu8, update.table_id);
2290 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2291 ds_put_format(string, " idle_timeout=%"PRIu16,
2292 update.idle_timeout);
2294 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2295 ds_put_format(string, " hard_timeout=%"PRIu16,
2296 update.hard_timeout);
2298 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2300 ds_put_char(string, ' ');
2301 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2303 if (update.ofpacts_len) {
2304 if (string->string[string->length - 1] != ' ') {
2305 ds_put_char(string, ' ');
2307 ds_put_cstr(string, "actions=");
2308 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2314 ofp_print_version(const struct ofp_header *oh,
2317 switch (oh->version) {
2321 ds_put_cstr(string, " (OF1.1)");
2324 ds_put_cstr(string, " (OF1.2)");
2327 ds_put_cstr(string, " (OF1.3)");
2330 ds_put_cstr(string, " (OF1.4)");
2333 ds_put_cstr(string, " (OF1.5)");
2336 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2339 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2343 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2346 ds_put_cstr(string, ofpraw_get_name(raw));
2347 ofp_print_version(oh, string);
2351 ofp_print_bucket_id(struct ds *s, const char *label, uint32_t bucket_id,
2352 enum ofp_version ofp_version)
2354 if (ofp_version < OFP15_VERSION) {
2358 ds_put_cstr(s, label);
2360 switch (bucket_id) {
2361 case OFPG15_BUCKET_FIRST:
2362 ds_put_cstr(s, "first");
2364 case OFPG15_BUCKET_LAST:
2365 ds_put_cstr(s, "last");
2367 case OFPG15_BUCKET_ALL:
2368 ds_put_cstr(s, "all");
2371 ds_put_format(s, "%"PRIu32, bucket_id);
2375 ds_put_char(s, ',');
2379 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2380 const struct ovs_list *p_buckets,
2381 const struct ofputil_group_props *props,
2382 enum ofp_version ofp_version, bool suppress_type)
2384 struct ofputil_bucket *bucket;
2386 ds_put_format(s, "group_id=%"PRIu32, group_id);
2388 if (!suppress_type) {
2389 static const char *type_str[] = { "all", "select", "indirect",
2391 ds_put_format(s, ",type=%s", type_str[type > 4 ? 4 : type]);
2394 if (props->selection_method[0]) {
2395 ds_put_format(s, ",selection_method=%s", props->selection_method);
2396 if (props->selection_method_param) {
2397 ds_put_format(s, ",selection_method_param=%"PRIu64,
2398 props->selection_method_param);
2401 size_t n = bitmap_count1(props->fields.used.bm, MFF_N_IDS);
2403 ds_put_cstr(s, ",fields=");
2404 oxm_format_field_array(s, &props->fields);
2406 ds_put_cstr(s, ",fields(");
2407 oxm_format_field_array(s, &props->fields);
2408 ds_put_char(s, ')');
2416 ds_put_char(s, ',');
2418 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2419 ds_put_cstr(s, "bucket=");
2421 ofp_print_bucket_id(s, "bucket_id:", bucket->bucket_id, ofp_version);
2422 if (bucket->weight != (type == OFPGT11_SELECT ? 1 : 0)) {
2423 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2425 if (bucket->watch_port != OFPP_NONE) {
2426 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2428 if (bucket->watch_group != OFPG_ANY) {
2429 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2432 ds_put_cstr(s, "actions=");
2433 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2434 ds_put_char(s, ',');
2441 ofp_print_ofpst_group_desc_request(struct ds *string,
2442 const struct ofp_header *oh)
2444 uint32_t group_id = ofputil_decode_group_desc_request(oh);
2445 ds_put_cstr(string, " group_id=");
2446 ofputil_format_group(group_id, string);
2450 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2452 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
2454 struct ofputil_group_desc gd;
2457 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2459 if (retval != EOF) {
2460 ds_put_cstr(s, " ***parse error***");
2465 ds_put_char(s, '\n');
2466 ds_put_char(s, ' ');
2467 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, &gd.props,
2468 oh->version, false);
2469 ofputil_bucket_list_destroy(&gd.buckets);
2474 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2479 error = ofputil_decode_group_stats_request(oh, &group_id);
2481 ofp_print_error(string, error);
2485 ds_put_cstr(string, " group_id=");
2486 ofputil_format_group(group_id, string);
2490 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2492 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
2494 struct ofputil_group_stats gs;
2497 retval = ofputil_decode_group_stats_reply(&b, &gs);
2499 if (retval != EOF) {
2500 ds_put_cstr(s, " ***parse error***");
2505 ds_put_char(s, '\n');
2507 ds_put_char(s, ' ');
2508 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2510 if (gs.duration_sec != UINT32_MAX) {
2511 ds_put_cstr(s, "duration=");
2512 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2513 ds_put_char(s, ',');
2515 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2516 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2517 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2519 for (uint32_t bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2520 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2521 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2522 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2523 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2527 free(gs.bucket_stats);
2532 group_type_to_string(enum ofp11_group_type type)
2535 case OFPGT11_ALL: return "all";
2536 case OFPGT11_SELECT: return "select";
2537 case OFPGT11_INDIRECT: return "indirect";
2538 case OFPGT11_FF: return "fast failover";
2539 default: OVS_NOT_REACHED();
2544 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2546 struct ofputil_group_features features;
2549 ofputil_decode_group_features_reply(oh, &features);
2551 ds_put_format(string, "\n Group table:\n");
2552 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2553 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2554 features.capabilities);
2556 for (i = 0; i < OFPGT12_N_TYPES; i++) {
2557 if (features.types & (1u << i)) {
2558 ds_put_format(string, " %s group:\n", group_type_to_string(i));
2559 ds_put_format(string, " max_groups=%#"PRIx32"\n",
2560 features.max_groups[i]);
2561 ds_put_format(string, " actions: ");
2562 ofpact_bitmap_format(features.ofpacts[i], string);
2563 ds_put_char(string, '\n');
2569 ofp_print_group_mod__(struct ds *s, enum ofp_version ofp_version,
2570 const struct ofputil_group_mod *gm)
2572 bool bucket_command = false;
2574 ds_put_char(s, '\n');
2576 ds_put_char(s, ' ');
2577 switch (gm->command) {
2579 ds_put_cstr(s, "ADD");
2582 case OFPGC11_MODIFY:
2583 ds_put_cstr(s, "MOD");
2586 case OFPGC11_DELETE:
2587 ds_put_cstr(s, "DEL");
2590 case OFPGC15_INSERT_BUCKET:
2591 ds_put_cstr(s, "INSERT_BUCKET");
2592 bucket_command = true;
2595 case OFPGC15_REMOVE_BUCKET:
2596 ds_put_cstr(s, "REMOVE_BUCKET");
2597 bucket_command = true;
2601 ds_put_format(s, "cmd:%"PRIu16"", gm->command);
2603 ds_put_char(s, ' ');
2605 if (bucket_command) {
2606 ofp_print_bucket_id(s, "command_bucket_id:",
2607 gm->command_bucket_id, ofp_version);
2610 ofp_print_group(s, gm->group_id, gm->type, &gm->buckets, &gm->props,
2611 ofp_version, bucket_command);
2615 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2617 struct ofputil_group_mod gm;
2620 error = ofputil_decode_group_mod(oh, &gm);
2622 ofp_print_error(s, error);
2625 ofp_print_group_mod__(s, oh->version, &gm);
2626 ofputil_bucket_list_destroy(&gm.buckets);
2630 print_table_action_features(struct ds *s,
2631 const struct ofputil_table_action_features *taf)
2634 ds_put_cstr(s, " actions: ");
2635 ofpact_bitmap_format(taf->ofpacts, s);
2636 ds_put_char(s, '\n');
2639 if (!bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS)) {
2642 ds_put_cstr(s, " supported on Set-Field:");
2643 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, taf->set_fields.bm) {
2644 ds_put_format(s, " %s", mf_from_id(i)->name);
2646 ds_put_char(s, '\n');
2651 table_action_features_equal(const struct ofputil_table_action_features *a,
2652 const struct ofputil_table_action_features *b)
2654 return (a->ofpacts == b->ofpacts
2655 && bitmap_equal(a->set_fields.bm, b->set_fields.bm, MFF_N_IDS));
2659 table_action_features_empty(const struct ofputil_table_action_features *taf)
2661 return !taf->ofpacts && bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS);
2665 print_table_instruction_features(
2667 const struct ofputil_table_instruction_features *tif,
2668 const struct ofputil_table_instruction_features *prev_tif)
2672 if (!bitmap_is_all_zeros(tif->next, 255)) {
2673 ds_put_cstr(s, " next tables: ");
2674 for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
2675 start = bitmap_scan(tif->next, 1, end, 255)) {
2676 end = bitmap_scan(tif->next, 0, start + 1, 255);
2677 if (end == start + 1) {
2678 ds_put_format(s, "%d,", start);
2680 ds_put_format(s, "%d-%d,", start, end - 1);
2684 if (ds_last(s) == ' ') {
2685 ds_put_cstr(s, "none");
2687 ds_put_char(s, '\n');
2690 if (tif->instructions) {
2691 if (prev_tif && tif->instructions == prev_tif->instructions) {
2692 ds_put_cstr(s, " (same instructions)\n");
2694 ds_put_cstr(s, " instructions: ");
2697 for (i = 0; i < 32; i++) {
2698 if (tif->instructions & (1u << i)) {
2699 ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
2703 ds_put_char(s, '\n');
2708 && table_action_features_equal(&tif->write, &prev_tif->write)
2709 && table_action_features_equal(&tif->apply, &prev_tif->apply)
2710 && !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
2711 ds_put_cstr(s, " (same actions)\n");
2712 } else if (!table_action_features_equal(&tif->write, &tif->apply)) {
2713 ds_put_cstr(s, " Write-Actions features:\n");
2714 print_table_action_features(s, &tif->write);
2715 ds_put_cstr(s, " Apply-Actions features:\n");
2716 print_table_action_features(s, &tif->apply);
2717 } else if (tif->write.ofpacts
2718 || !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) {
2719 ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
2720 print_table_action_features(s, &tif->write);
2725 table_instruction_features_equal(
2726 const struct ofputil_table_instruction_features *a,
2727 const struct ofputil_table_instruction_features *b)
2729 return (bitmap_equal(a->next, b->next, 255)
2730 && a->instructions == b->instructions
2731 && table_action_features_equal(&a->write, &b->write)
2732 && table_action_features_equal(&a->apply, &b->apply));
2736 table_instruction_features_empty(
2737 const struct ofputil_table_instruction_features *tif)
2739 return (bitmap_is_all_zeros(tif->next, 255)
2740 && !tif->instructions
2741 && table_action_features_empty(&tif->write)
2742 && table_action_features_empty(&tif->apply));
2746 table_features_equal(const struct ofputil_table_features *a,
2747 const struct ofputil_table_features *b)
2749 return (a->metadata_match == b->metadata_match
2750 && a->metadata_write == b->metadata_write
2751 && a->miss_config == b->miss_config
2752 && a->supports_eviction == b->supports_eviction
2753 && a->supports_vacancy_events == b->supports_vacancy_events
2754 && a->max_entries == b->max_entries
2755 && table_instruction_features_equal(&a->nonmiss, &b->nonmiss)
2756 && table_instruction_features_equal(&a->miss, &b->miss)
2757 && bitmap_equal(a->match.bm, b->match.bm, MFF_N_IDS));
2761 table_features_empty(const struct ofputil_table_features *tf)
2763 return (!tf->metadata_match
2764 && !tf->metadata_write
2765 && tf->miss_config == OFPUTIL_TABLE_MISS_DEFAULT
2766 && tf->supports_eviction < 0
2767 && tf->supports_vacancy_events < 0
2769 && table_instruction_features_empty(&tf->nonmiss)
2770 && table_instruction_features_empty(&tf->miss)
2771 && bitmap_is_all_zeros(tf->match.bm, MFF_N_IDS));
2775 table_stats_equal(const struct ofputil_table_stats *a,
2776 const struct ofputil_table_stats *b)
2778 return (a->active_count == b->active_count
2779 && a->lookup_count == b->lookup_count
2780 && a->matched_count == b->matched_count);
2784 ofp_print_table_features(struct ds *s,
2785 const struct ofputil_table_features *features,
2786 const struct ofputil_table_features *prev_features,
2787 const struct ofputil_table_stats *stats,
2788 const struct ofputil_table_stats *prev_stats)
2792 ds_put_format(s, " table %"PRIu8, features->table_id);
2793 if (features->name[0]) {
2794 ds_put_format(s, " (\"%s\")", features->name);
2796 ds_put_char(s, ':');
2798 bool same_stats = prev_stats && table_stats_equal(stats, prev_stats);
2799 bool same_features = prev_features && table_features_equal(features,
2801 if ((!stats || same_stats) && same_features) {
2802 ds_put_cstr(s, " ditto");
2805 ds_put_char(s, '\n');
2807 ds_put_format(s, " active=%"PRIu32", ", stats->active_count);
2808 ds_put_format(s, "lookup=%"PRIu64", ", stats->lookup_count);
2809 ds_put_format(s, "matched=%"PRIu64"\n", stats->matched_count);
2811 if (same_features) {
2812 if (!table_features_empty(features)) {
2813 ds_put_cstr(s, " (same features)\n");
2817 if (features->metadata_match || features->metadata_write) {
2818 ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
2819 ntohll(features->metadata_match),
2820 ntohll(features->metadata_write));
2823 if (features->miss_config != OFPUTIL_TABLE_MISS_DEFAULT) {
2824 ds_put_format(s, " config=%s\n",
2825 ofputil_table_miss_to_string(features->miss_config));
2828 if (features->supports_eviction >= 0) {
2829 ds_put_format(s, " eviction: %ssupported\n",
2830 features->supports_eviction ? "" : "not ");
2833 if (features->supports_vacancy_events >= 0) {
2834 ds_put_format(s, " vacancy events: %ssupported\n",
2835 features->supports_vacancy_events ? "" : "not ");
2839 if (features->max_entries) {
2840 ds_put_format(s, " max_entries=%"PRIu32"\n", features->max_entries);
2843 const struct ofputil_table_instruction_features *prev_nonmiss
2844 = prev_features ? &prev_features->nonmiss : NULL;
2845 const struct ofputil_table_instruction_features *prev_miss
2846 = prev_features ? &prev_features->miss : NULL;
2848 && table_instruction_features_equal(&features->nonmiss, prev_nonmiss)
2849 && table_instruction_features_equal(&features->miss, prev_miss)) {
2850 if (!table_instruction_features_empty(&features->nonmiss)) {
2851 ds_put_cstr(s, " (same instructions)\n");
2853 } else if (!table_instruction_features_equal(&features->nonmiss,
2855 ds_put_cstr(s, " instructions (other than table miss):\n");
2856 print_table_instruction_features(s, &features->nonmiss, prev_nonmiss);
2857 ds_put_cstr(s, " instructions (table miss):\n");
2858 print_table_instruction_features(s, &features->miss, prev_miss);
2859 } else if (!table_instruction_features_empty(&features->nonmiss)) {
2860 ds_put_cstr(s, " instructions (table miss and others):\n");
2861 print_table_instruction_features(s, &features->nonmiss, prev_nonmiss);
2864 if (!bitmap_is_all_zeros(features->match.bm, MFF_N_IDS)) {
2866 && bitmap_equal(features->match.bm, prev_features->match.bm,
2868 ds_put_cstr(s, " (same matching)\n");
2870 ds_put_cstr(s, " matching:\n");
2871 BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) {
2872 const struct mf_field *f = mf_from_id(i);
2873 bool mask = bitmap_is_set(features->mask.bm, i);
2874 bool wildcard = bitmap_is_set(features->wildcard.bm, i);
2876 ds_put_format(s, " %s: %s\n",
2878 (mask ? "arbitrary mask"
2879 : wildcard ? "exact match or wildcard"
2880 : "must exact match"));
2887 ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh)
2889 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
2891 struct ofputil_table_features prev;
2892 for (int i = 0; ; i++) {
2893 struct ofputil_table_features tf;
2896 retval = ofputil_decode_table_features(&b, &tf, true);
2898 if (retval != EOF) {
2899 ofp_print_error(s, retval);
2904 ds_put_char(s, '\n');
2905 ofp_print_table_features(s, &tf, i ? &prev : NULL, NULL, NULL);
2911 ofp_print_table_desc_reply(struct ds *s, const struct ofp_header *oh)
2913 struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
2915 struct ofputil_table_desc td;
2918 retval = ofputil_decode_table_desc(&b, &td, oh->version);
2920 if (retval != EOF) {
2921 ofp_print_error(s, retval);
2925 ofp_print_table_desc(s, &td);
2930 bundle_flags_to_name(uint32_t bit)
2943 ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh)
2946 struct ofputil_bundle_ctrl_msg bctrl;
2948 error = ofputil_decode_bundle_ctrl(oh, &bctrl);
2950 ofp_print_error(s, error);
2954 ds_put_char(s, '\n');
2956 ds_put_format(s, " bundle_id=%#"PRIx32" type=", bctrl.bundle_id);
2957 switch (bctrl.type) {
2958 case OFPBCT_OPEN_REQUEST:
2959 ds_put_cstr(s, "OPEN_REQUEST");
2961 case OFPBCT_OPEN_REPLY:
2962 ds_put_cstr(s, "OPEN_REPLY");
2964 case OFPBCT_CLOSE_REQUEST:
2965 ds_put_cstr(s, "CLOSE_REQUEST");
2967 case OFPBCT_CLOSE_REPLY:
2968 ds_put_cstr(s, "CLOSE_REPLY");
2970 case OFPBCT_COMMIT_REQUEST:
2971 ds_put_cstr(s, "COMMIT_REQUEST");
2973 case OFPBCT_COMMIT_REPLY:
2974 ds_put_cstr(s, "COMMIT_REPLY");
2976 case OFPBCT_DISCARD_REQUEST:
2977 ds_put_cstr(s, "DISCARD_REQUEST");
2979 case OFPBCT_DISCARD_REPLY:
2980 ds_put_cstr(s, "DISCARD_REPLY");
2984 ds_put_cstr(s, " flags=");
2985 ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' ');
2989 ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
2992 struct ofputil_bundle_add_msg badd;
2994 error = ofputil_decode_bundle_add(oh, &badd, NULL);
2996 ofp_print_error(s, error);
3000 ds_put_char(s, '\n');
3001 ds_put_format(s, " bundle_id=%#"PRIx32, badd.bundle_id);
3002 ds_put_cstr(s, " flags=");
3003 ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
3005 ds_put_char(s, '\n');
3006 char *msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
3007 ds_put_and_free_cstr(s, msg);
3011 print_tlv_table(struct ds *s, struct ovs_list *mappings)
3013 struct ofputil_tlv_map *map;
3015 ds_put_cstr(s, " mapping table:\n");
3016 ds_put_cstr(s, " class\ttype\tlength\tmatch field\n");
3017 ds_put_cstr(s, " -----\t----\t------\t-----------");
3019 LIST_FOR_EACH (map, list_node, mappings) {
3020 ds_put_char(s, '\n');
3021 ds_put_format(s, " 0x%"PRIx16"\t0x%"PRIx8"\t%"PRIu8"\ttun_metadata%"PRIu16,
3022 map->option_class, map->option_type, map->option_len,
3028 ofp_print_tlv_table_mod(struct ds *s, const struct ofp_header *oh)
3031 struct ofputil_tlv_table_mod ttm;
3033 error = ofputil_decode_tlv_table_mod(oh, &ttm);
3035 ofp_print_error(s, error);
3039 ds_put_cstr(s, "\n ");
3041 switch (ttm.command) {
3043 ds_put_cstr(s, "ADD");
3046 ds_put_cstr(s, "DEL");
3049 ds_put_cstr(s, "CLEAR");
3053 if (ttm.command != NXTTMC_CLEAR) {
3054 print_tlv_table(s, &ttm.mappings);
3057 ofputil_uninit_tlv_table(&ttm.mappings);
3061 ofp_print_tlv_table_reply(struct ds *s, const struct ofp_header *oh)
3064 struct ofputil_tlv_table_reply ttr;
3065 struct ofputil_tlv_map *map;
3066 int allocated_space = 0;
3068 error = ofputil_decode_tlv_table_reply(oh, &ttr);
3070 ofp_print_error(s, error);
3074 ds_put_char(s, '\n');
3076 LIST_FOR_EACH (map, list_node, &ttr.mappings) {
3077 allocated_space += map->option_len;
3080 ds_put_format(s, " max option space=%"PRIu32" max fields=%"PRIu16"\n",
3081 ttr.max_option_space, ttr.max_fields);
3082 ds_put_format(s, " allocated option space=%d\n", allocated_space);
3083 ds_put_char(s, '\n');
3084 print_tlv_table(s, &ttr.mappings);
3086 ofputil_uninit_tlv_table(&ttr.mappings);
3089 /* This function will print the request forward message. The reason for
3090 * request forward is taken from rf.request.type */
3092 ofp_print_requestforward(struct ds *string, const struct ofp_header *oh)
3094 struct ofputil_requestforward rf;
3097 error = ofputil_decode_requestforward(oh, &rf);
3099 ofp_print_error(string, error);
3103 ds_put_cstr(string, " reason=");
3105 switch (rf.reason) {
3106 case OFPRFR_GROUP_MOD:
3107 ds_put_cstr(string, "group_mod");
3108 ofp_print_group_mod__(string, oh->version, rf.group_mod);
3111 case OFPRFR_METER_MOD:
3112 ds_put_cstr(string, "meter_mod");
3113 ofp_print_meter_mod__(string, rf.meter_mod);
3116 case OFPRFR_N_REASONS:
3119 ofputil_destroy_requestforward(&rf);
3123 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
3124 struct ds *string, int verbosity)
3126 const void *msg = oh;
3128 ofp_header_to_string__(oh, raw, string);
3130 enum ofptype type = ofptype_from_ofpraw(raw);
3132 case OFPTYPE_GROUP_STATS_REQUEST:
3133 ofp_print_stats(string, oh);
3134 ofp_print_ofpst_group_request(string, oh);
3137 case OFPTYPE_GROUP_STATS_REPLY:
3138 ofp_print_group_stats(string, oh);
3141 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
3142 ofp_print_stats(string, oh);
3143 ofp_print_ofpst_group_desc_request(string, oh);
3146 case OFPTYPE_GROUP_DESC_STATS_REPLY:
3147 ofp_print_group_desc(string, oh);
3150 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
3151 ofp_print_stats(string, oh);
3154 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
3155 ofp_print_group_features(string, oh);
3158 case OFPTYPE_GROUP_MOD:
3159 ofp_print_group_mod(string, oh);
3162 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
3163 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
3164 ofp_print_table_features_reply(string, oh);
3167 case OFPTYPE_TABLE_DESC_REQUEST:
3168 case OFPTYPE_TABLE_DESC_REPLY:
3169 ofp_print_table_desc_reply(string, oh);
3173 ofp_print_hello(string, oh);
3177 ofp_print_error_msg(string, oh);
3180 case OFPTYPE_ECHO_REQUEST:
3181 case OFPTYPE_ECHO_REPLY:
3182 ofp_print_echo(string, oh, verbosity);
3185 case OFPTYPE_FEATURES_REQUEST:
3188 case OFPTYPE_FEATURES_REPLY:
3189 ofp_print_switch_features(string, oh);
3192 case OFPTYPE_GET_CONFIG_REQUEST:
3195 case OFPTYPE_GET_CONFIG_REPLY:
3196 ofp_print_get_config_reply(string, oh);
3199 case OFPTYPE_SET_CONFIG:
3200 ofp_print_set_config(string, oh);
3203 case OFPTYPE_PACKET_IN:
3204 ofp_print_packet_in(string, oh, verbosity);
3207 case OFPTYPE_FLOW_REMOVED:
3208 ofp_print_flow_removed(string, oh);
3211 case OFPTYPE_PORT_STATUS:
3212 ofp_print_port_status(string, oh);
3215 case OFPTYPE_PACKET_OUT:
3216 ofp_print_packet_out(string, oh, verbosity);
3219 case OFPTYPE_FLOW_MOD:
3220 ofp_print_flow_mod(string, oh, verbosity);
3223 case OFPTYPE_PORT_MOD:
3224 ofp_print_port_mod(string, oh);
3227 case OFPTYPE_TABLE_MOD:
3228 ofp_print_table_mod(string, oh);
3231 case OFPTYPE_METER_MOD:
3232 ofp_print_meter_mod(string, oh);
3235 case OFPTYPE_BARRIER_REQUEST:
3236 case OFPTYPE_BARRIER_REPLY:
3239 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
3240 ofp_print_queue_get_config_request(string, oh);
3243 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
3244 ofp_print_queue_get_config_reply(string, oh);
3247 case OFPTYPE_ROLE_REQUEST:
3248 case OFPTYPE_ROLE_REPLY:
3249 ofp_print_role_message(string, oh);
3251 case OFPTYPE_ROLE_STATUS:
3252 ofp_print_role_status_message(string, oh);
3255 case OFPTYPE_REQUESTFORWARD:
3256 ofp_print_requestforward(string, oh);
3259 case OFPTYPE_TABLE_STATUS:
3260 ofp_print_table_status_message(string, oh);
3263 case OFPTYPE_METER_STATS_REQUEST:
3264 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
3265 ofp_print_stats(string, oh);
3266 ofp_print_meter_stats_request(string, oh);
3269 case OFPTYPE_METER_STATS_REPLY:
3270 ofp_print_stats(string, oh);
3271 ofp_print_meter_stats_reply(string, oh);
3274 case OFPTYPE_METER_CONFIG_STATS_REPLY:
3275 ofp_print_stats(string, oh);
3276 ofp_print_meter_config_reply(string, oh);
3279 case OFPTYPE_METER_FEATURES_STATS_REPLY:
3280 ofp_print_stats(string, oh);
3281 ofp_print_meter_features_reply(string, oh);
3284 case OFPTYPE_DESC_STATS_REQUEST:
3285 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
3286 ofp_print_stats(string, oh);
3289 case OFPTYPE_FLOW_STATS_REQUEST:
3290 case OFPTYPE_AGGREGATE_STATS_REQUEST:
3291 ofp_print_stats(string, oh);
3292 ofp_print_flow_stats_request(string, oh);
3295 case OFPTYPE_TABLE_STATS_REQUEST:
3296 ofp_print_stats(string, oh);
3299 case OFPTYPE_PORT_STATS_REQUEST:
3300 ofp_print_stats(string, oh);
3301 ofp_print_ofpst_port_request(string, oh);
3304 case OFPTYPE_QUEUE_STATS_REQUEST:
3305 ofp_print_stats(string, oh);
3306 ofp_print_ofpst_queue_request(string, oh);
3309 case OFPTYPE_DESC_STATS_REPLY:
3310 ofp_print_stats(string, oh);
3311 ofp_print_ofpst_desc_reply(string, oh);
3314 case OFPTYPE_FLOW_STATS_REPLY:
3315 ofp_print_stats(string, oh);
3316 ofp_print_flow_stats_reply(string, oh);
3319 case OFPTYPE_QUEUE_STATS_REPLY:
3320 ofp_print_stats(string, oh);
3321 ofp_print_ofpst_queue_reply(string, oh, verbosity);
3324 case OFPTYPE_PORT_STATS_REPLY:
3325 ofp_print_stats(string, oh);
3326 ofp_print_ofpst_port_reply(string, oh, verbosity);
3329 case OFPTYPE_TABLE_STATS_REPLY:
3330 ofp_print_stats(string, oh);
3331 ofp_print_table_stats_reply(string, oh);
3334 case OFPTYPE_AGGREGATE_STATS_REPLY:
3335 ofp_print_stats(string, oh);
3336 ofp_print_aggregate_stats_reply(string, oh);
3339 case OFPTYPE_PORT_DESC_STATS_REQUEST:
3340 ofp_print_stats(string, oh);
3341 ofp_print_ofpst_port_desc_request(string, oh);
3344 case OFPTYPE_PORT_DESC_STATS_REPLY:
3345 ofp_print_stats(string, oh);
3346 ofp_print_ofpst_port_desc_reply(string, oh);
3349 case OFPTYPE_FLOW_MOD_TABLE_ID:
3350 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
3353 case OFPTYPE_SET_FLOW_FORMAT:
3354 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
3357 case OFPTYPE_SET_PACKET_IN_FORMAT:
3358 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
3361 case OFPTYPE_FLOW_AGE:
3364 case OFPTYPE_SET_CONTROLLER_ID:
3365 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
3368 case OFPTYPE_GET_ASYNC_REPLY:
3369 case OFPTYPE_SET_ASYNC_CONFIG:
3370 ofp_print_set_async_config(string, oh, type);
3372 case OFPTYPE_GET_ASYNC_REQUEST:
3374 case OFPTYPE_FLOW_MONITOR_CANCEL:
3375 ofp_print_nxt_flow_monitor_cancel(string, msg);
3378 case OFPTYPE_FLOW_MONITOR_PAUSED:
3379 case OFPTYPE_FLOW_MONITOR_RESUMED:
3382 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
3383 ofp_print_nxst_flow_monitor_request(string, msg);
3386 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
3387 ofp_print_nxst_flow_monitor_reply(string, msg);
3390 case OFPTYPE_BUNDLE_CONTROL:
3391 ofp_print_bundle_ctrl(string, msg);
3394 case OFPTYPE_BUNDLE_ADD_MESSAGE:
3395 ofp_print_bundle_add(string, msg, verbosity);
3398 case OFPTYPE_NXT_TLV_TABLE_MOD:
3399 ofp_print_tlv_table_mod(string, msg);
3402 case OFPTYPE_NXT_TLV_TABLE_REQUEST:
3405 case OFPTYPE_NXT_TLV_TABLE_REPLY:
3406 ofp_print_tlv_table_reply(string, msg);
3409 case OFPTYPE_NXT_RESUME:
3410 ofp_print_packet_in(string, msg, verbosity);
3415 /* Composes and returns a string representing the OpenFlow packet of 'len'
3416 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
3417 * verbosity and higher numbers increase verbosity. The caller is responsible
3418 * for freeing the string. */
3420 ofp_to_string(const void *oh_, size_t len, int verbosity)
3422 struct ds string = DS_EMPTY_INITIALIZER;
3423 const struct ofp_header *oh = oh_;
3426 ds_put_cstr(&string, "OpenFlow message is empty\n");
3427 } else if (len < sizeof(struct ofp_header)) {
3428 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
3430 } else if (ntohs(oh->length) > len) {
3434 error = ofpraw_decode_partial(&raw, oh, len);
3436 ofp_header_to_string__(oh, raw, &string);
3437 ds_put_char(&string, '\n');
3440 ds_put_format(&string,
3441 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
3442 len, ntohs(oh->length));
3443 } else if (ntohs(oh->length) < len) {
3444 ds_put_format(&string,
3445 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
3446 ntohs(oh->length), len);
3451 error = ofpraw_decode(&raw, oh);
3453 ofp_to_string__(oh, raw, &string, verbosity);
3454 if (verbosity >= 5) {
3455 if (ds_last(&string) != '\n') {
3456 ds_put_char(&string, '\n');
3458 ds_put_hex_dump(&string, oh, len, 0, true);
3460 if (ds_last(&string) != '\n') {
3461 ds_put_char(&string, '\n');
3463 return ds_steal_cstr(&string);
3466 ofp_print_error(&string, error);
3468 ds_put_hex_dump(&string, oh, len, 0, true);
3469 return ds_steal_cstr(&string);
3473 print_and_free(FILE *stream, char *string)
3475 fputs(string, stream);
3479 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
3480 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
3481 * numbers increase verbosity. */
3483 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
3485 print_and_free(stream, ofp_to_string(oh, len, verbosity));
3488 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
3489 * 'data' to 'stream'. */
3491 ofp_print_packet(FILE *stream, const void *data, size_t len)
3493 print_and_free(stream, ofp_packet_to_string(data, len));