2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "ofp-print.h"
22 #include <sys/types.h>
23 #include <netinet/in.h>
30 #include "byte-order.h"
32 #include "dynamic-string.h"
35 #include "multipath.h"
36 #include "meta-flow.h"
39 #include "ofp-actions.h"
40 #include "ofp-errors.h"
44 #include "openflow/openflow.h"
45 #include "openflow/nicira-ext.h"
47 #include "type-props.h"
48 #include "unaligned.h"
52 static void ofp_print_queue_name(struct ds *string, uint32_t port);
53 static void ofp_print_error(struct ds *, enum ofperr);
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;
62 const struct pkt_metadata md = PKT_METADATA_INITIALIZER(0);
67 ofpbuf_use_const(&buf, data, len);
68 flow_extract(&buf, &md, &flow);
69 flow_format(&ds, &flow);
71 l4_size = ofpbuf_l4_size(&buf);
73 if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
74 struct tcp_header *th = ofpbuf_l4(&buf);
75 ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum));
76 } else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
77 struct udp_header *uh = ofpbuf_l4(&buf);
78 ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum));
79 } else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) {
80 struct sctp_header *sh = ofpbuf_l4(&buf);
81 ds_put_format(&ds, " sctp_csum:%"PRIx32,
82 ntohl(get_16aligned_be32(&sh->sctp_csum)));
85 ds_put_char(&ds, '\n');
91 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
94 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
95 struct ofputil_packet_in pin;
99 error = ofputil_decode_packet_in(&pin, oh);
101 ofp_print_error(string, error);
106 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
109 if (pin.cookie != OVS_BE64_MAX) {
110 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
113 ds_put_format(string, " total_len=%"PRIuSIZE" in_port=", pin.total_len);
114 ofputil_format_port(pin.fmd.in_port, string);
116 if (pin.fmd.tun_id != htonll(0)) {
117 ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
120 if (pin.fmd.tun_src != htonl(0)) {
121 ds_put_format(string, " tun_src="IP_FMT, IP_ARGS(pin.fmd.tun_src));
124 if (pin.fmd.tun_dst != htonl(0)) {
125 ds_put_format(string, " tun_dst="IP_FMT, IP_ARGS(pin.fmd.tun_dst));
128 if (pin.fmd.metadata != htonll(0)) {
129 ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata));
132 for (i = 0; i < FLOW_N_REGS; i++) {
133 if (pin.fmd.regs[i]) {
134 ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
138 if (pin.fmd.pkt_mark != 0) {
139 ds_put_format(string, " pkt_mark=0x%"PRIx32, pin.fmd.pkt_mark);
142 ds_put_format(string, " (via %s)",
143 ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
146 ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len);
147 if (pin.buffer_id == UINT32_MAX) {
148 ds_put_format(string, " (unbuffered)");
149 if (pin.total_len != pin.packet_len) {
150 ds_put_format(string, " (***total_len != data_len***)");
153 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
154 if (pin.total_len < pin.packet_len) {
155 ds_put_format(string, " (***total_len < data_len***)");
158 ds_put_char(string, '\n');
161 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
162 ds_put_cstr(string, packet);
166 ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false);
171 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
174 struct ofputil_packet_out po;
175 struct ofpbuf ofpacts;
178 ofpbuf_init(&ofpacts, 64);
179 error = ofputil_decode_packet_out(&po, oh, &ofpacts);
181 ofpbuf_uninit(&ofpacts);
182 ofp_print_error(string, error);
186 ds_put_cstr(string, " in_port=");
187 ofputil_format_port(po.in_port, string);
189 ds_put_cstr(string, " actions=");
190 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
192 if (po.buffer_id == UINT32_MAX) {
193 ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
194 if (verbosity > 0 && po.packet_len > 0) {
195 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
196 ds_put_char(string, '\n');
197 ds_put_cstr(string, packet);
201 ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
204 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
207 ofpbuf_uninit(&ofpacts);
210 /* qsort comparison function. */
212 compare_ports(const void *a_, const void *b_)
214 const struct ofputil_phy_port *a = a_;
215 const struct ofputil_phy_port *b = b_;
216 uint16_t ap = ofp_to_u16(a->port_no);
217 uint16_t bp = ofp_to_u16(b->port_no);
219 return ap < bp ? -1 : ap > bp;
223 ofp_print_bit_names(struct ds *string, uint32_t bits,
224 const char *(*bit_to_name)(uint32_t bit),
231 ds_put_cstr(string, "0");
235 for (i = 0; i < 32; i++) {
236 uint32_t bit = UINT32_C(1) << i;
239 const char *name = bit_to_name(bit);
242 ds_put_char(string, separator);
244 ds_put_cstr(string, name);
252 ds_put_char(string, separator);
254 ds_put_format(string, "0x%"PRIx32, bits);
259 netdev_feature_to_name(uint32_t bit)
261 enum netdev_features f = bit;
264 case NETDEV_F_10MB_HD: return "10MB-HD";
265 case NETDEV_F_10MB_FD: return "10MB-FD";
266 case NETDEV_F_100MB_HD: return "100MB-HD";
267 case NETDEV_F_100MB_FD: return "100MB-FD";
268 case NETDEV_F_1GB_HD: return "1GB-HD";
269 case NETDEV_F_1GB_FD: return "1GB-FD";
270 case NETDEV_F_10GB_FD: return "10GB-FD";
271 case NETDEV_F_40GB_FD: return "40GB-FD";
272 case NETDEV_F_100GB_FD: return "100GB-FD";
273 case NETDEV_F_1TB_FD: return "1TB-FD";
274 case NETDEV_F_OTHER: return "OTHER";
275 case NETDEV_F_COPPER: return "COPPER";
276 case NETDEV_F_FIBER: return "FIBER";
277 case NETDEV_F_AUTONEG: return "AUTO_NEG";
278 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
279 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
286 ofp_print_port_features(struct ds *string, enum netdev_features features)
288 ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
289 ds_put_char(string, '\n');
293 ofputil_port_config_to_name(uint32_t bit)
295 enum ofputil_port_config pc = bit;
298 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
299 case OFPUTIL_PC_NO_STP: return "NO_STP";
300 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
301 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
302 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
303 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
304 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
311 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
313 ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
314 ds_put_char(string, '\n');
318 ofputil_port_state_to_name(uint32_t bit)
320 enum ofputil_port_state ps = bit;
323 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
324 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
325 case OFPUTIL_PS_LIVE: return "LIVE";
327 case OFPUTIL_PS_STP_LISTEN:
328 case OFPUTIL_PS_STP_LEARN:
329 case OFPUTIL_PS_STP_FORWARD:
330 case OFPUTIL_PS_STP_BLOCK:
331 /* Handled elsewhere. */
339 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
341 enum ofputil_port_state stp_state;
343 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
344 * pattern. We have to special case it.
346 * OVS doesn't support STP, so this field will always be 0 if we are
347 * talking to OVS, so we'd always print STP_LISTEN in that case.
348 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
349 * avoid confusing users. */
350 stp_state = state & OFPUTIL_PS_STP_MASK;
353 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
354 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
356 state &= ~OFPUTIL_PS_STP_MASK;
358 ofp_print_bit_names(string, state, ofputil_port_state_to_name,
362 ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
364 ds_put_char(string, '\n');
368 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
370 char name[sizeof port->name];
373 memcpy(name, port->name, sizeof name);
374 for (j = 0; j < sizeof name - 1; j++) {
375 if (!isprint((unsigned char) name[j])) {
381 ds_put_char(string, ' ');
382 ofputil_format_port(port->port_no, string);
383 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
384 name, ETH_ADDR_ARGS(port->hw_addr));
386 ds_put_cstr(string, " config: ");
387 ofp_print_port_config(string, port->config);
389 ds_put_cstr(string, " state: ");
390 ofp_print_port_state(string, port->state);
393 ds_put_format(string, " current: ");
394 ofp_print_port_features(string, port->curr);
396 if (port->advertised) {
397 ds_put_format(string, " advertised: ");
398 ofp_print_port_features(string, port->advertised);
400 if (port->supported) {
401 ds_put_format(string, " supported: ");
402 ofp_print_port_features(string, port->supported);
405 ds_put_format(string, " peer: ");
406 ofp_print_port_features(string, port->peer);
408 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
409 "%"PRIu32" Mbps max\n",
410 port->curr_speed / UINT32_C(1000),
411 port->max_speed / UINT32_C(1000));
414 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
415 * 'ofp_version', writes a detailed description of each port into
418 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
421 struct ofputil_phy_port *ports;
422 size_t allocated_ports, n_ports;
428 for (n_ports = 0; ; n_ports++) {
429 if (n_ports >= allocated_ports) {
430 ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
433 retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
439 qsort(ports, n_ports, sizeof *ports, compare_ports);
440 for (i = 0; i < n_ports; i++) {
441 ofp_print_phy_port(string, &ports[i]);
446 ofp_print_error(string, retval);
451 ofputil_capabilities_to_name(uint32_t bit)
453 enum ofputil_capabilities capabilities = bit;
455 switch (capabilities) {
456 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
457 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
458 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
459 case OFPUTIL_C_IP_REASM: return "IP_REASM";
460 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
461 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
462 case OFPUTIL_C_STP: return "STP";
463 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
464 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
471 ofputil_action_bitmap_to_name(uint32_t bit)
473 enum ofputil_action_bitmap action = bit;
476 case OFPUTIL_A_OUTPUT: return "OUTPUT";
477 case OFPUTIL_A_SET_VLAN_VID: return "SET_VLAN_VID";
478 case OFPUTIL_A_SET_VLAN_PCP: return "SET_VLAN_PCP";
479 case OFPUTIL_A_STRIP_VLAN: return "STRIP_VLAN";
480 case OFPUTIL_A_SET_DL_SRC: return "SET_DL_SRC";
481 case OFPUTIL_A_SET_DL_DST: return "SET_DL_DST";
482 case OFPUTIL_A_SET_NW_SRC: return "SET_NW_SRC";
483 case OFPUTIL_A_SET_NW_DST: return "SET_NW_DST";
484 case OFPUTIL_A_SET_NW_ECN: return "SET_NW_ECN";
485 case OFPUTIL_A_SET_NW_TOS: return "SET_NW_TOS";
486 case OFPUTIL_A_SET_TP_SRC: return "SET_TP_SRC";
487 case OFPUTIL_A_SET_TP_DST: return "SET_TP_DST";
488 case OFPUTIL_A_SET_FIELD: return "SET_FIELD";
489 case OFPUTIL_A_ENQUEUE: return "ENQUEUE";
490 case OFPUTIL_A_COPY_TTL_OUT: return "COPY_TTL_OUT";
491 case OFPUTIL_A_COPY_TTL_IN: return "COPY_TTL_IN";
492 case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL";
493 case OFPUTIL_A_SET_MPLS_TC: return "SET_MPLS_TC";
494 case OFPUTIL_A_SET_MPLS_TTL: return "SET_MPLS_TTL";
495 case OFPUTIL_A_DEC_MPLS_TTL: return "DEC_MPLS_TTL";
496 case OFPUTIL_A_PUSH_VLAN: return "PUSH_VLAN";
497 case OFPUTIL_A_POP_VLAN: return "POP_VLAN";
498 case OFPUTIL_A_PUSH_MPLS: return "PUSH_MPLS";
499 case OFPUTIL_A_POP_MPLS: return "POP_MPLS";
500 case OFPUTIL_A_SET_QUEUE: return "SET_QUEUE";
501 case OFPUTIL_A_GROUP: return "GROUP";
502 case OFPUTIL_A_SET_NW_TTL: return "SET_NW_TTL";
503 case OFPUTIL_A_DEC_NW_TTL: return "DEC_NW_TTL";
510 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
512 struct ofputil_switch_features features;
516 error = ofputil_decode_switch_features(oh, &features, &b);
518 ofp_print_error(string, error);
522 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
524 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
525 features.n_tables, features.n_buffers);
526 if (features.auxiliary_id) {
527 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
529 ds_put_char(string, '\n');
531 ds_put_cstr(string, "capabilities: ");
532 ofp_print_bit_names(string, features.capabilities,
533 ofputil_capabilities_to_name, ' ');
534 ds_put_char(string, '\n');
536 switch ((enum ofp_version)oh->version) {
538 ds_put_cstr(string, "actions: ");
539 ofp_print_bit_names(string, features.actions,
540 ofputil_action_bitmap_to_name, ' ');
541 ds_put_char(string, '\n');
548 return; /* no ports in ofp13_switch_features */
553 ofp_print_phy_ports(string, oh->version, &b);
557 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
559 enum ofp_config_flags flags;
561 flags = ntohs(osc->flags);
563 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
564 flags &= ~OFPC_FRAG_MASK;
566 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
567 ds_put_format(string, " invalid_ttl_to_controller");
568 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
572 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
575 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
578 static void print_wild(struct ds *string, const char *leader, int is_wild,
579 int verbosity, const char *format, ...)
582 static void print_wild(struct ds *string, const char *leader, int is_wild,
583 int verbosity, const char *format, ...)
585 if (is_wild && verbosity < 2) {
588 ds_put_cstr(string, leader);
592 va_start(args, format);
593 ds_put_format_valist(string, format, args);
596 ds_put_char(string, '*');
598 ds_put_char(string, ',');
602 print_wild_port(struct ds *string, const char *leader, int is_wild,
603 int verbosity, ofp_port_t port)
605 if (is_wild && verbosity < 2) {
608 ds_put_cstr(string, leader);
610 ofputil_format_port(port, string);
612 ds_put_char(string, '*');
614 ds_put_char(string, ',');
618 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
619 uint32_t wild_bits, int verbosity)
621 if (wild_bits >= 32 && verbosity < 2) {
624 ds_put_cstr(string, leader);
625 if (wild_bits < 32) {
626 ds_put_format(string, IP_FMT, IP_ARGS(ip));
628 ds_put_format(string, "/%d", 32 - wild_bits);
631 ds_put_char(string, '*');
633 ds_put_char(string, ',');
637 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
639 char *s = ofp10_match_to_string(om, verbosity);
645 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
647 struct ds f = DS_EMPTY_INITIALIZER;
648 uint32_t w = ntohl(om->wildcards);
649 bool skip_type = false;
650 bool skip_proto = false;
652 if (!(w & OFPFW10_DL_TYPE)) {
654 if (om->dl_type == htons(ETH_TYPE_IP)) {
655 if (!(w & OFPFW10_NW_PROTO)) {
657 if (om->nw_proto == IPPROTO_ICMP) {
658 ds_put_cstr(&f, "icmp,");
659 } else if (om->nw_proto == IPPROTO_TCP) {
660 ds_put_cstr(&f, "tcp,");
661 } else if (om->nw_proto == IPPROTO_UDP) {
662 ds_put_cstr(&f, "udp,");
663 } else if (om->nw_proto == IPPROTO_SCTP) {
664 ds_put_cstr(&f, "sctp,");
666 ds_put_cstr(&f, "ip,");
670 ds_put_cstr(&f, "ip,");
672 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
673 ds_put_cstr(&f, "arp,");
674 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
675 ds_put_cstr(&f, "rarp,");
676 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
677 ds_put_cstr(&f, "mpls,");
678 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
679 ds_put_cstr(&f, "mplsm,");
684 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
685 u16_to_ofp(ntohs(om->in_port)));
686 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
687 "%d", ntohs(om->dl_vlan));
688 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
689 "%d", om->dl_vlan_pcp);
690 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
691 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
692 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
693 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
695 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
696 "0x%04x", ntohs(om->dl_type));
698 print_ip_netmask(&f, "nw_src=", om->nw_src,
699 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
701 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
702 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
705 if (om->dl_type == htons(ETH_TYPE_ARP) ||
706 om->dl_type == htons(ETH_TYPE_RARP)) {
707 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
710 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
714 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
716 if (om->nw_proto == IPPROTO_ICMP) {
717 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
718 "%d", ntohs(om->tp_src));
719 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
720 "%d", ntohs(om->tp_dst));
722 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
723 "%d", ntohs(om->tp_src));
724 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
725 "%d", ntohs(om->tp_dst));
727 if (ds_last(&f) == ',') {
734 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
736 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
737 ds_put_cstr(s, "send_flow_rem ");
739 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
740 ds_put_cstr(s, "check_overlap ");
742 if (flags & OFPUTIL_FF_RESET_COUNTS) {
743 ds_put_cstr(s, "reset_counts ");
745 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
746 ds_put_cstr(s, "no_packet_counts ");
748 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
749 ds_put_cstr(s, "no_byte_counts ");
751 if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
752 ds_put_cstr(s, "allow_hidden_fields ");
754 if (flags & OFPUTIL_FF_NO_READONLY) {
755 ds_put_cstr(s, "no_readonly_table ");
760 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
762 struct ofputil_flow_mod fm;
763 struct ofpbuf ofpacts;
767 enum ofputil_protocol protocol;
769 protocol = ofputil_protocol_from_ofp_version(oh->version);
770 protocol = ofputil_protocol_set_tid(protocol, true);
772 ofpbuf_init(&ofpacts, 64);
773 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
776 ofpbuf_uninit(&ofpacts);
777 ofp_print_error(s, error);
782 switch (fm.command) {
784 ds_put_cstr(s, "ADD");
787 ds_put_cstr(s, "MOD");
789 case OFPFC_MODIFY_STRICT:
790 ds_put_cstr(s, "MOD_STRICT");
793 ds_put_cstr(s, "DEL");
795 case OFPFC_DELETE_STRICT:
796 ds_put_cstr(s, "DEL_STRICT");
799 ds_put_format(s, "cmd:%d", fm.command);
801 if (fm.table_id != 0) {
802 ds_put_format(s, " table:%d", fm.table_id);
806 ofpraw_decode(&raw, oh);
807 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
808 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
809 ofp10_match_print(s, &ofm->match, verbosity);
811 /* ofp_print_match() doesn't print priority. */
812 need_priority = true;
813 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
814 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
815 const void *nxm = nfm + 1;
818 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
819 ds_put_cstr(s, nxm_s);
822 /* nx_match_to_string() doesn't print priority. */
823 need_priority = true;
825 match_format(&fm.match, s, fm.priority);
827 /* match_format() does print priority. */
828 need_priority = false;
831 if (ds_last(s) != ' ') {
834 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
835 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
837 if (fm.cookie_mask != htonll(0)) {
838 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
839 ntohll(fm.cookie), ntohll(fm.cookie_mask));
841 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
842 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
844 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
845 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
847 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
848 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
850 if (fm.buffer_id != UINT32_MAX) {
851 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
853 if (fm.out_port != OFPP_ANY) {
854 ds_put_format(s, "out_port:");
855 ofputil_format_port(fm.out_port, s);
859 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
860 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
861 * versions don't really have such a flag and printing one is likely to
863 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
865 ofp_print_flow_flags(s, fm.flags);
867 ds_put_cstr(s, "actions=");
868 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
869 ofpbuf_uninit(&ofpacts);
873 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
875 ds_put_format(string, "%u", sec);
877 /* If there are no fractional seconds, don't print any decimals.
879 * If the fractional seconds can be expressed exactly as milliseconds,
880 * print 3 decimals. Open vSwitch provides millisecond precision for most
881 * time measurements, so printing 3 decimals every time makes it easier to
882 * spot real changes in flow dumps that refresh themselves quickly.
884 * If the fractional seconds are more precise than milliseconds, print the
885 * number of decimals needed to express them exactly.
888 unsigned int msec = nsec / 1000000;
889 if (msec * 1000000 == nsec) {
890 ds_put_format(string, ".%03u", msec);
892 ds_put_format(string, ".%09u", nsec);
893 while (string->string[string->length - 1] == '0') {
898 ds_put_char(string, 's');
901 /* Returns a string form of 'reason'. The return value is either a statically
902 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
903 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
904 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
906 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
907 char *reasonbuf, size_t bufsize)
910 case OFPRR_IDLE_TIMEOUT:
912 case OFPRR_HARD_TIMEOUT:
916 case OFPRR_GROUP_DELETE:
917 return "group_delete";
920 case OFPRR_METER_DELETE:
921 return "meter_delete";
923 snprintf(reasonbuf, bufsize, "%d", (int) reason);
929 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
931 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
932 struct ofputil_flow_removed fr;
935 error = ofputil_decode_flow_removed(&fr, oh);
937 ofp_print_error(string, error);
941 ds_put_char(string, ' ');
942 match_format(&fr.match, string, fr.priority);
944 ds_put_format(string, " reason=%s",
945 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
948 if (fr.table_id != 255) {
949 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
952 if (fr.cookie != htonll(0)) {
953 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
955 ds_put_cstr(string, " duration");
956 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
957 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
958 if (fr.hard_timeout) {
959 /* The hard timeout was only added in OF1.2, so only print it if it is
960 * actually in use to avoid gratuitous change to the formatting. */
961 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
963 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
964 fr.packet_count, fr.byte_count);
968 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
970 struct ofputil_port_mod pm;
973 error = ofputil_decode_port_mod(oh, &pm);
975 ofp_print_error(string, error);
979 ds_put_cstr(string, "port: ");
980 ofputil_format_port(pm.port_no, string);
981 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
982 ETH_ADDR_ARGS(pm.hw_addr));
984 ds_put_cstr(string, " config: ");
985 ofp_print_port_config(string, pm.config);
987 ds_put_cstr(string, " mask: ");
988 ofp_print_port_config(string, pm.mask);
990 ds_put_cstr(string, " advertise: ");
992 ofp_print_port_features(string, pm.advertise);
994 ds_put_cstr(string, "UNCHANGED\n");
999 ofp_print_table_miss_config(struct ds *string, const uint32_t config)
1001 uint32_t table_miss_config = config & OFPTC11_TABLE_MISS_MASK;
1003 switch (table_miss_config) {
1004 case OFPTC11_TABLE_MISS_CONTROLLER:
1005 ds_put_cstr(string, "controller\n");
1007 case OFPTC11_TABLE_MISS_CONTINUE:
1008 ds_put_cstr(string, "continue\n");
1010 case OFPTC11_TABLE_MISS_DROP:
1011 ds_put_cstr(string, "drop\n");
1014 ds_put_cstr(string, "Unknown\n");
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 ds_put_cstr(string, ", flow_miss_config=");
1038 ofp_print_table_miss_config(string, pm.config);
1042 ofp_print_queue_get_config_request(struct ds *string,
1043 const struct ofp_header *oh)
1048 error = ofputil_decode_queue_get_config_request(oh, &port);
1050 ofp_print_error(string, error);
1054 ds_put_cstr(string, " port=");
1055 ofputil_format_port(port, string);
1059 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1062 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1063 } else if (rate < UINT16_MAX) {
1064 ds_put_format(string, " %s:(disabled)", name);
1069 ofp_print_queue_get_config_reply(struct ds *string,
1070 const struct ofp_header *oh)
1076 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1077 error = ofputil_decode_queue_get_config_reply(&b, &port);
1079 ofp_print_error(string, error);
1083 ds_put_cstr(string, " port=");
1084 ofputil_format_port(port, string);
1085 ds_put_char(string, '\n');
1088 struct ofputil_queue_config queue;
1091 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1093 if (retval != EOF) {
1094 ofp_print_error(string, retval);
1099 ds_put_format(string, "queue %"PRIu32":", queue.queue_id);
1100 print_queue_rate(string, "min_rate", queue.min_rate);
1101 print_queue_rate(string, "max_rate", queue.max_rate);
1102 ds_put_char(string, '\n');
1107 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1109 if (flags & OFPMF13_KBPS) {
1110 ds_put_cstr(s, "kbps ");
1112 if (flags & OFPMF13_PKTPS) {
1113 ds_put_cstr(s, "pktps ");
1115 if (flags & OFPMF13_BURST) {
1116 ds_put_cstr(s, "burst ");
1118 if (flags & OFPMF13_STATS) {
1119 ds_put_cstr(s, "stats ");
1122 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1124 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1129 ofp_print_meter_band(struct ds *s, uint16_t flags,
1130 const struct ofputil_meter_band *mb)
1132 ds_put_cstr(s, "\ntype=");
1135 ds_put_cstr(s, "drop");
1137 case OFPMBT13_DSCP_REMARK:
1138 ds_put_cstr(s, "dscp_remark");
1141 ds_put_format(s, "%u", mb->type);
1144 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1146 if (flags & OFPMF13_BURST) {
1147 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1149 if (mb->type == OFPMBT13_DSCP_REMARK) {
1150 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1155 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1159 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1160 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1161 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1162 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1163 ds_put_cstr(s, "duration:");
1164 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1165 ds_put_char(s, ' ');
1167 ds_put_cstr(s, "bands:\n");
1168 for (i = 0; i < ms->n_bands; ++i) {
1169 ds_put_format(s, "%d: ", i);
1170 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1171 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1176 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1180 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1182 ofp_print_meter_flags(s, mc->flags);
1184 ds_put_cstr(s, "bands=");
1185 for (i = 0; i < mc->n_bands; ++i) {
1186 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1188 ds_put_char(s, '\n');
1192 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1194 struct ofputil_meter_mod mm;
1195 struct ofpbuf bands;
1198 ofpbuf_init(&bands, 64);
1199 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1201 ofpbuf_uninit(&bands);
1202 ofp_print_error(s, error);
1206 switch (mm.command) {
1208 ds_put_cstr(s, " ADD ");
1210 case OFPMC13_MODIFY:
1211 ds_put_cstr(s, " MOD ");
1213 case OFPMC13_DELETE:
1214 ds_put_cstr(s, " DEL ");
1217 ds_put_format(s, " cmd:%d ", mm.command);
1220 ofp_print_meter_config(s, &mm.meter);
1221 ofpbuf_uninit(&bands);
1225 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1229 ofputil_decode_meter_request(oh, &meter_id);
1231 ds_put_format(s, " meter=%"PRIu32, meter_id);
1235 ofputil_meter_capabilities_to_name(uint32_t bit)
1237 enum ofp13_meter_flags flag = bit;
1240 case OFPMF13_KBPS: return "kbps";
1241 case OFPMF13_PKTPS: return "pktps";
1242 case OFPMF13_BURST: return "burst";
1243 case OFPMF13_STATS: return "stats";
1250 ofputil_meter_band_types_to_name(uint32_t bit)
1253 case 1 << OFPMBT13_DROP: return "drop";
1254 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1261 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1263 struct ofputil_meter_features mf;
1265 ofputil_decode_meter_features(oh, &mf);
1267 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1268 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1269 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1271 ds_put_cstr(s, "band_types: ");
1272 ofp_print_bit_names(s, mf.band_types,
1273 ofputil_meter_band_types_to_name, ' ');
1274 ds_put_char(s, '\n');
1276 ds_put_cstr(s, "capabilities: ");
1277 ofp_print_bit_names(s, mf.capabilities,
1278 ofputil_meter_capabilities_to_name, ' ');
1279 ds_put_char(s, '\n');
1283 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1285 struct ofpbuf bands;
1288 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1289 ofpbuf_init(&bands, 64);
1291 struct ofputil_meter_config mc;
1294 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1296 if (retval != EOF) {
1297 ofp_print_error(s, retval);
1301 ds_put_char(s, '\n');
1302 ofp_print_meter_config(s, &mc);
1304 ofpbuf_uninit(&bands);
1308 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1310 struct ofpbuf bands;
1313 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1314 ofpbuf_init(&bands, 64);
1316 struct ofputil_meter_stats ms;
1319 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1321 if (retval != EOF) {
1322 ofp_print_error(s, retval);
1326 ds_put_char(s, '\n');
1327 ofp_print_meter_stats(s, &ms);
1329 ofpbuf_uninit(&bands);
1333 ofp_print_error(struct ds *string, enum ofperr error)
1335 if (string->length) {
1336 ds_put_char(string, ' ');
1338 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1342 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1344 uint32_t allowed_versions;
1347 ok = ofputil_decode_hello(oh, &allowed_versions);
1349 ds_put_cstr(string, "\n version bitmap: ");
1350 ofputil_format_version_bitmap(string, allowed_versions);
1353 ds_put_cstr(string, "\n unknown data in hello:\n");
1354 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1359 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1361 size_t len = ntohs(oh->length);
1362 struct ofpbuf payload;
1366 error = ofperr_decode_msg(oh, &payload);
1368 ds_put_cstr(string, "***decode error***");
1369 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1373 ds_put_format(string, " %s\n", ofperr_get_name(error));
1375 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1376 ds_put_printable(string, ofpbuf_data(&payload), ofpbuf_size(&payload));
1378 s = ofp_to_string(ofpbuf_data(&payload), ofpbuf_size(&payload), 1);
1379 ds_put_cstr(string, s);
1382 ofpbuf_uninit(&payload);
1386 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1388 struct ofputil_port_status ps;
1391 error = ofputil_decode_port_status(oh, &ps);
1393 ofp_print_error(string, error);
1397 if (ps.reason == OFPPR_ADD) {
1398 ds_put_format(string, " ADD:");
1399 } else if (ps.reason == OFPPR_DELETE) {
1400 ds_put_format(string, " DEL:");
1401 } else if (ps.reason == OFPPR_MODIFY) {
1402 ds_put_format(string, " MOD:");
1405 ofp_print_phy_port(string, &ps.desc);
1409 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1411 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1413 ds_put_char(string, '\n');
1414 ds_put_format(string, "Manufacturer: %.*s\n",
1415 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1416 ds_put_format(string, "Hardware: %.*s\n",
1417 (int) sizeof ods->hw_desc, ods->hw_desc);
1418 ds_put_format(string, "Software: %.*s\n",
1419 (int) sizeof ods->sw_desc, ods->sw_desc);
1420 ds_put_format(string, "Serial Num: %.*s\n",
1421 (int) sizeof ods->serial_num, ods->serial_num);
1422 ds_put_format(string, "DP Description: %.*s\n",
1423 (int) sizeof ods->dp_desc, ods->dp_desc);
1427 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1429 struct ofputil_flow_stats_request fsr;
1432 error = ofputil_decode_flow_stats_request(&fsr, oh);
1434 ofp_print_error(string, error);
1438 if (fsr.table_id != 0xff) {
1439 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1442 if (fsr.out_port != OFPP_ANY) {
1443 ds_put_cstr(string, " out_port=");
1444 ofputil_format_port(fsr.out_port, string);
1447 ds_put_char(string, ' ');
1448 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1452 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1454 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1455 ntohll(fs->cookie));
1457 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1458 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1459 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1460 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1461 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1462 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1464 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1465 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1468 ofp_print_flow_flags(string, fs->flags);
1470 if (fs->idle_age >= 0) {
1471 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1473 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1474 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1477 match_format(&fs->match, string, fs->priority);
1478 if (string->string[string->length - 1] != ' ') {
1479 ds_put_char(string, ' ');
1482 ds_put_cstr(string, "actions=");
1483 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1487 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1489 struct ofpbuf ofpacts;
1492 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1493 ofpbuf_init(&ofpacts, 64);
1495 struct ofputil_flow_stats fs;
1498 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1500 if (retval != EOF) {
1501 ds_put_cstr(string, " ***parse error***");
1505 ds_put_char(string, '\n');
1506 ofp_print_flow_stats(string, &fs);
1508 ofpbuf_uninit(&ofpacts);
1512 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1514 struct ofputil_aggregate_stats as;
1517 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1519 ofp_print_error(string, error);
1523 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1524 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1525 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1529 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1531 ds_put_cstr(string, leader);
1532 if (stat != UINT64_MAX) {
1533 ds_put_format(string, "%"PRIu64, stat);
1535 ds_put_char(string, '?');
1538 ds_put_cstr(string, ", ");
1540 ds_put_cstr(string, "\n");
1545 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1547 ofp_port_t ofp10_port;
1550 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1552 ofp_print_error(string, error);
1556 ds_put_cstr(string, " port_no=");
1557 ofputil_format_port(ofp10_port, string);
1561 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1566 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1567 if (verbosity < 1) {
1571 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1573 struct ofputil_port_stats ps;
1576 retval = ofputil_decode_port_stats(&ps, &b);
1578 if (retval != EOF) {
1579 ds_put_cstr(string, " ***parse error***");
1584 ds_put_cstr(string, " port ");
1585 if (ofp_to_u16(ps.port_no) < 10) {
1586 ds_put_char(string, ' ');
1588 ofputil_format_port(ps.port_no, string);
1590 ds_put_cstr(string, ": rx ");
1591 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1592 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1593 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1594 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1595 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1596 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1597 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1599 ds_put_cstr(string, " tx ");
1600 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1601 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1602 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1603 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1604 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1606 if (ps.duration_sec != UINT32_MAX) {
1607 ds_put_cstr(string, " duration=");
1608 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1609 ds_put_char(string, '\n');
1615 ofp_print_one_ofpst_table_reply(struct ds *string, enum ofp_version ofp_version,
1616 const char *name, struct ofp12_table_stats *ts)
1618 char name_[OFP_MAX_TABLE_NAME_LEN + 1];
1620 /* ofp13_table_stats is different */
1621 if (ofp_version > OFP12_VERSION) {
1625 ovs_strlcpy(name_, name, sizeof name_);
1627 ds_put_format(string, " %d: %-8s: ", ts->table_id, name_);
1628 ds_put_format(string, "wild=0x%05"PRIx64", ", ntohll(ts->wildcards));
1629 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1630 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1631 ds_put_cstr(string, " ");
1632 ds_put_format(string, "lookup=%"PRIu64", ", ntohll(ts->lookup_count));
1633 ds_put_format(string, "matched=%"PRIu64"\n", ntohll(ts->matched_count));
1635 if (ofp_version < OFP11_VERSION) {
1639 ds_put_cstr(string, " ");
1640 ds_put_format(string, "match=0x%08"PRIx64", ", ntohll(ts->match));
1641 ds_put_format(string, "instructions=0x%08"PRIx32", ",
1642 ntohl(ts->instructions));
1643 ds_put_format(string, "config=0x%08"PRIx32"\n", ntohl(ts->config));
1644 ds_put_cstr(string, " ");
1645 ds_put_format(string, "write_actions=0x%08"PRIx32", ",
1646 ntohl(ts->write_actions));
1647 ds_put_format(string, "apply_actions=0x%08"PRIx32"\n",
1648 ntohl(ts->apply_actions));
1650 if (ofp_version < OFP12_VERSION) {
1654 ds_put_cstr(string, " ");
1655 ds_put_format(string, "write_setfields=0x%016"PRIx64"\n",
1656 ntohll(ts->write_setfields));
1657 ds_put_cstr(string, " ");
1658 ds_put_format(string, "apply_setfields=0x%016"PRIx64"\n",
1659 ntohll(ts->apply_setfields));
1660 ds_put_cstr(string, " ");
1661 ds_put_format(string, "metadata_match=0x%016"PRIx64"\n",
1662 ntohll(ts->metadata_match));
1663 ds_put_cstr(string, " ");
1664 ds_put_format(string, "metadata_write=0x%016"PRIx64"\n",
1665 ntohll(ts->metadata_write));
1669 ofp_print_ofpst_table_reply13(struct ds *string, const struct ofp_header *oh,
1672 struct ofp13_table_stats *ts;
1676 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1677 ofpraw_pull_assert(&b);
1679 n = ofpbuf_size(&b) / sizeof *ts;
1680 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1681 if (verbosity < 1) {
1686 ts = ofpbuf_try_pull(&b, sizeof *ts);
1690 ds_put_format(string,
1691 " %d: active=%"PRIu32", lookup=%"PRIu64 \
1692 ", matched=%"PRIu64"\n",
1693 ts->table_id, ntohl(ts->active_count),
1694 ntohll(ts->lookup_count), ntohll(ts->matched_count));
1699 ofp_print_ofpst_table_reply12(struct ds *string, const struct ofp_header *oh,
1702 struct ofp12_table_stats *ts;
1706 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1707 ofpraw_pull_assert(&b);
1709 n = ofpbuf_size(&b) / sizeof *ts;
1710 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1711 if (verbosity < 1) {
1716 ts = ofpbuf_try_pull(&b, sizeof *ts);
1721 ofp_print_one_ofpst_table_reply(string, OFP12_VERSION, ts->name, ts);
1726 ofp_print_ofpst_table_reply11(struct ds *string, const struct ofp_header *oh,
1729 struct ofp11_table_stats *ts;
1733 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1734 ofpraw_pull_assert(&b);
1736 n = ofpbuf_size(&b) / sizeof *ts;
1737 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1738 if (verbosity < 1) {
1743 struct ofp12_table_stats ts12;
1745 ts = ofpbuf_try_pull(&b, sizeof *ts);
1750 ts12.table_id = ts->table_id;
1751 ts12.wildcards = htonll(ntohl(ts->wildcards));
1752 ts12.max_entries = ts->max_entries;
1753 ts12.active_count = ts->active_count;
1754 ts12.lookup_count = ts->lookup_count;
1755 ts12.matched_count = ts->matched_count;
1756 ts12.match = htonll(ntohl(ts->match));
1757 ts12.instructions = ts->instructions;
1758 ts12.config = ts->config;
1759 ts12.write_actions = ts->write_actions;
1760 ts12.apply_actions = ts->apply_actions;
1761 ofp_print_one_ofpst_table_reply(string, OFP11_VERSION, ts->name, &ts12);
1766 ofp_print_ofpst_table_reply10(struct ds *string, const struct ofp_header *oh,
1769 struct ofp10_table_stats *ts;
1773 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1774 ofpraw_pull_assert(&b);
1776 n = ofpbuf_size(&b) / sizeof *ts;
1777 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1778 if (verbosity < 1) {
1783 struct ofp12_table_stats ts12;
1785 ts = ofpbuf_try_pull(&b, sizeof *ts);
1790 ts12.table_id = ts->table_id;
1791 ts12.wildcards = htonll(ntohl(ts->wildcards));
1792 ts12.max_entries = ts->max_entries;
1793 ts12.active_count = ts->active_count;
1794 ts12.lookup_count = get_32aligned_be64(&ts->lookup_count);
1795 ts12.matched_count = get_32aligned_be64(&ts->matched_count);
1796 ofp_print_one_ofpst_table_reply(string, OFP10_VERSION, ts->name, &ts12);
1801 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1804 switch ((enum ofp_version)oh->version) {
1807 ofp_print_ofpst_table_reply13(string, oh, verbosity);
1811 ofp_print_ofpst_table_reply12(string, oh, verbosity);
1815 ofp_print_ofpst_table_reply11(string, oh, verbosity);
1819 ofp_print_ofpst_table_reply10(string, oh, verbosity);
1828 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1830 if (queue_id == OFPQ_ALL) {
1831 ds_put_cstr(string, "ALL");
1833 ds_put_format(string, "%"PRIu32, queue_id);
1838 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1840 struct ofputil_queue_stats_request oqsr;
1843 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1845 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1849 ds_put_cstr(string, "port=");
1850 ofputil_format_port(oqsr.port_no, string);
1852 ds_put_cstr(string, " queue=");
1853 ofp_print_queue_name(string, oqsr.queue_id);
1857 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1862 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1863 if (verbosity < 1) {
1867 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1869 struct ofputil_queue_stats qs;
1872 retval = ofputil_decode_queue_stats(&qs, &b);
1874 if (retval != EOF) {
1875 ds_put_cstr(string, " ***parse error***");
1880 ds_put_cstr(string, " port ");
1881 ofputil_format_port(qs.port_no, string);
1882 ds_put_cstr(string, " queue ");
1883 ofp_print_queue_name(string, qs.queue_id);
1884 ds_put_cstr(string, ": ");
1886 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1887 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1888 print_port_stat(string, "errors=", qs.tx_errors, 1);
1890 ds_put_cstr(string, "duration=");
1891 if (qs.duration_sec != UINT32_MAX) {
1892 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1894 ds_put_char(string, '?');
1896 ds_put_char(string, '\n');
1901 ofp_print_ofpst_port_desc_reply(struct ds *string,
1902 const struct ofp_header *oh)
1906 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1907 ofpraw_pull_assert(&b);
1908 ds_put_char(string, '\n');
1909 ofp_print_phy_ports(string, oh->version, &b);
1913 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1915 uint16_t flags = ofpmp_flags(oh);
1918 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
1923 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1925 uint16_t flags = ofpmp_flags(oh);
1928 ds_put_cstr(string, " flags=");
1929 if (flags & OFPSF_REPLY_MORE) {
1930 ds_put_cstr(string, "[more]");
1931 flags &= ~OFPSF_REPLY_MORE;
1934 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1941 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1943 size_t len = ntohs(oh->length);
1945 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1946 if (verbosity > 1) {
1947 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1952 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1953 uint64_t generation_id)
1955 ds_put_cstr(string, " role=");
1958 case OFPCR12_ROLE_NOCHANGE:
1959 ds_put_cstr(string, "nochange");
1961 case OFPCR12_ROLE_EQUAL:
1962 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1964 case OFPCR12_ROLE_MASTER:
1965 ds_put_cstr(string, "master");
1967 case OFPCR12_ROLE_SLAVE:
1968 ds_put_cstr(string, "slave");
1974 if (generation_id != UINT64_MAX) {
1975 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1980 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1982 struct ofputil_role_request rr;
1985 error = ofputil_decode_role_message(oh, &rr);
1987 ofp_print_error(string, error);
1991 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1995 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1997 struct ofputil_role_status rs;
2000 error = ofputil_decode_role_status(oh, &rs);
2002 ofp_print_error(string, error);
2006 ofp_print_role_generic(string, rs.role, rs.generation_id);
2008 ds_put_cstr(string, " reason=");
2010 switch (rs.reason) {
2011 case OFPCRR_MASTER_REQUEST:
2012 ds_put_cstr(string, "master_request");
2015 ds_put_cstr(string, "configuration_changed");
2017 case OFPCRR_EXPERIMENTER:
2018 ds_put_cstr(string, "experimenter_data_changed");
2026 ofp_print_nxt_flow_mod_table_id(struct ds *string,
2027 const struct nx_flow_mod_table_id *nfmti)
2029 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
2033 ofp_print_nxt_set_flow_format(struct ds *string,
2034 const struct nx_set_flow_format *nsff)
2036 uint32_t format = ntohl(nsff->format);
2038 ds_put_cstr(string, " format=");
2039 if (ofputil_nx_flow_format_is_valid(format)) {
2040 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
2042 ds_put_format(string, "%"PRIu32, format);
2047 ofp_print_nxt_set_packet_in_format(struct ds *string,
2048 const struct nx_set_packet_in_format *nspf)
2050 uint32_t format = ntohl(nspf->format);
2052 ds_put_cstr(string, " format=");
2053 if (ofputil_packet_in_format_is_valid(format)) {
2054 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
2056 ds_put_format(string, "%"PRIu32, format);
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_PORT_REASON_BUFSIZE. */
2063 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2065 ofp_port_reason_to_string(enum ofp_port_reason reason,
2066 char *reasonbuf, size_t bufsize)
2079 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2085 ofp_print_nxt_set_async_config(struct ds *string,
2086 const struct nx_async_config *nac)
2090 for (i = 0; i < 2; i++) {
2093 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2095 ds_put_cstr(string, " PACKET_IN:");
2096 for (j = 0; j < 32; j++) {
2097 if (nac->packet_in_mask[i] & htonl(1u << j)) {
2098 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2101 reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
2103 ds_put_format(string, " %s", reason);
2106 if (!nac->packet_in_mask[i]) {
2107 ds_put_cstr(string, " (off)");
2109 ds_put_char(string, '\n');
2111 ds_put_cstr(string, " PORT_STATUS:");
2112 for (j = 0; j < 32; j++) {
2113 if (nac->port_status_mask[i] & htonl(1u << j)) {
2114 char reasonbuf[OFP_PORT_REASON_BUFSIZE];
2117 reason = ofp_port_reason_to_string(j, reasonbuf,
2119 ds_put_format(string, " %s", reason);
2122 if (!nac->port_status_mask[i]) {
2123 ds_put_cstr(string, " (off)");
2125 ds_put_char(string, '\n');
2127 ds_put_cstr(string, " FLOW_REMOVED:");
2128 for (j = 0; j < 32; j++) {
2129 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
2130 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2133 reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
2135 ds_put_format(string, " %s", reason);
2138 if (!nac->flow_removed_mask[i]) {
2139 ds_put_cstr(string, " (off)");
2141 ds_put_char(string, '\n');
2146 ofp_print_nxt_set_controller_id(struct ds *string,
2147 const struct nx_controller_id *nci)
2149 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
2153 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
2154 const struct ofp_header *oh)
2156 ds_put_format(string, " id=%"PRIu32,
2157 ofputil_decode_flow_monitor_cancel(oh));
2161 nx_flow_monitor_flags_to_name(uint32_t bit)
2163 enum nx_flow_monitor_flags fmf = bit;
2166 case NXFMF_INITIAL: return "initial";
2167 case NXFMF_ADD: return "add";
2168 case NXFMF_DELETE: return "delete";
2169 case NXFMF_MODIFY: return "modify";
2170 case NXFMF_ACTIONS: return "actions";
2171 case NXFMF_OWN: return "own";
2178 ofp_print_nxst_flow_monitor_request(struct ds *string,
2179 const struct ofp_header *oh)
2183 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2185 struct ofputil_flow_monitor_request request;
2188 retval = ofputil_decode_flow_monitor_request(&request, &b);
2190 if (retval != EOF) {
2191 ofp_print_error(string, retval);
2196 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
2197 ofp_print_bit_names(string, request.flags,
2198 nx_flow_monitor_flags_to_name, ',');
2200 if (request.out_port != OFPP_NONE) {
2201 ds_put_cstr(string, " out_port=");
2202 ofputil_format_port(request.out_port, string);
2205 if (request.table_id != 0xff) {
2206 ds_put_format(string, " table=%"PRIu8, request.table_id);
2209 ds_put_char(string, ' ');
2210 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
2211 ds_chomp(string, ' ');
2216 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2217 const struct ofp_header *oh)
2219 uint64_t ofpacts_stub[1024 / 8];
2220 struct ofpbuf ofpacts;
2223 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2224 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2226 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2227 struct ofputil_flow_update update;
2231 update.match = &match;
2232 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2234 if (retval != EOF) {
2235 ofp_print_error(string, retval);
2237 ofpbuf_uninit(&ofpacts);
2241 ds_put_cstr(string, "\n event=");
2242 switch (update.event) {
2244 ds_put_cstr(string, "ADDED");
2248 ds_put_format(string, "DELETED reason=%s",
2249 ofp_flow_removed_reason_to_string(update.reason,
2254 case NXFME_MODIFIED:
2255 ds_put_cstr(string, "MODIFIED");
2259 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2263 ds_put_format(string, " table=%"PRIu8, update.table_id);
2264 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2265 ds_put_format(string, " idle_timeout=%"PRIu16,
2266 update.idle_timeout);
2268 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2269 ds_put_format(string, " hard_timeout=%"PRIu16,
2270 update.hard_timeout);
2272 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2274 ds_put_char(string, ' ');
2275 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2277 if (update.ofpacts_len) {
2278 if (string->string[string->length - 1] != ' ') {
2279 ds_put_char(string, ' ');
2281 ds_put_cstr(string, "actions=");
2282 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2288 ofp_print_version(const struct ofp_header *oh,
2291 switch (oh->version) {
2295 ds_put_cstr(string, " (OF1.1)");
2298 ds_put_cstr(string, " (OF1.2)");
2301 ds_put_cstr(string, " (OF1.3)");
2304 ds_put_cstr(string, " (OF1.4)");
2307 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2310 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2314 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2317 ds_put_cstr(string, ofpraw_get_name(raw));
2318 ofp_print_version(oh, string);
2322 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2323 struct list *p_buckets)
2325 static const char *type_str[] = { "all", "select", "indirect",
2327 struct ofputil_bucket *bucket;
2329 ds_put_format(s, "group_id=%"PRIu32",type=%s",
2330 group_id, type_str[type > 4 ? 4 : type]);
2335 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2336 ds_put_cstr(s, ",bucket=");
2338 if (bucket->weight != 1) {
2339 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2341 if (bucket->watch_port != OFPP_NONE) {
2342 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2344 if (bucket->watch_group != OFPG11_ANY) {
2345 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2348 ds_put_cstr(s, "actions=");
2349 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2354 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2358 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2360 struct ofputil_group_desc gd;
2363 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2365 if (retval != EOF) {
2366 ds_put_cstr(s, " ***parse error***");
2371 ds_put_char(s, '\n');
2372 ds_put_char(s, ' ');
2373 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets);
2378 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2383 error = ofputil_decode_group_stats_request(oh, &group_id);
2385 ofp_print_error(string, error);
2389 ds_put_cstr(string, " group_id=");
2390 ofputil_format_group(group_id, string);
2394 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2399 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2402 struct ofputil_group_stats gs;
2405 retval = ofputil_decode_group_stats_reply(&b, &gs);
2407 if (retval != EOF) {
2408 ds_put_cstr(s, " ***parse error***");
2413 ds_put_char(s, '\n');
2415 ds_put_char(s, ' ');
2416 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2418 if (gs.duration_sec != UINT32_MAX) {
2419 ds_put_cstr(s, "duration=");
2420 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2421 ds_put_char(s, ',');
2423 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2424 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2425 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2427 for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2428 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2429 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2430 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2431 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2435 free(gs.bucket_stats);
2440 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2442 struct ofputil_group_features features;
2444 ofputil_decode_group_features_reply(oh, &features);
2446 ds_put_format(string, "\n Group table:\n");
2447 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2448 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2449 features.capabilities);
2451 if (features.types & (1u << OFPGT11_ALL)) {
2452 ds_put_format(string, " All group :\n");
2453 ds_put_format(string,
2454 " max_groups = %#"PRIx32" actions=0x%08"PRIx32"\n",
2455 features.max_groups[0], features.actions[0]);
2458 if (features.types & (1u << OFPGT11_SELECT)) {
2459 ds_put_format(string, " Select group :\n");
2460 ds_put_format(string, " max_groups = %#"PRIx32" "
2461 "actions=0x%08"PRIx32"\n",
2462 features.max_groups[1], features.actions[1]);
2465 if (features.types & (1u << OFPGT11_INDIRECT)) {
2466 ds_put_format(string, " Indirect group :\n");
2467 ds_put_format(string, " max_groups = %#"PRIx32" "
2468 "actions=0x%08"PRIx32"\n",
2469 features.max_groups[2], features.actions[2]);
2472 if (features.types & (1u << OFPGT11_FF)) {
2473 ds_put_format(string, " Fast Failover group :\n");
2474 ds_put_format(string, " max_groups = %#"PRIx32" "
2475 "actions=0x%08"PRIx32"\n",
2476 features.max_groups[3], features.actions[3]);
2481 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2483 struct ofputil_group_mod gm;
2486 error = ofputil_decode_group_mod(oh, &gm);
2488 ofp_print_error(s, error);
2492 ds_put_char(s, '\n');
2494 ds_put_char(s, ' ');
2495 switch (gm.command) {
2497 ds_put_cstr(s, "ADD");
2500 case OFPGC11_MODIFY:
2501 ds_put_cstr(s, "MOD");
2504 case OFPGC11_DELETE:
2505 ds_put_cstr(s, "DEL");
2509 ds_put_format(s, "cmd:%"PRIu16"", gm.command);
2511 ds_put_char(s, ' ');
2513 ofp_print_group(s, gm.group_id, gm.type, &gm.buckets);
2517 ofp13_action_to_string(uint32_t bit)
2520 #define OFPAT13_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
2521 case 1u << ENUM: return NAME;
2522 #include "ofp-util.def"
2528 print_table_action_features(struct ds *s,
2529 const struct ofputil_table_action_features *taf)
2531 ds_put_cstr(s, " actions: ");
2532 ofp_print_bit_names(s, taf->actions, ofp13_action_to_string, ',');
2533 ds_put_char(s, '\n');
2535 ds_put_cstr(s, " supported on Set-Field: ");
2536 if (taf->set_fields) {
2539 for (i = 0; i < MFF_N_IDS; i++) {
2540 uint64_t bit = UINT64_C(1) << i;
2542 if (taf->set_fields & bit) {
2543 ds_put_format(s, "%s,", mf_from_id(i)->name);
2548 ds_put_cstr(s, "none");
2550 ds_put_char(s, '\n');
2554 table_action_features_equal(const struct ofputil_table_action_features *a,
2555 const struct ofputil_table_action_features *b)
2557 return a->actions == b->actions && a->set_fields == b->set_fields;
2561 print_table_instruction_features(
2562 struct ds *s, const struct ofputil_table_instruction_features *tif)
2566 ds_put_cstr(s, " next tables: ");
2567 for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
2568 start = bitmap_scan(tif->next, 1, end, 255)) {
2569 end = bitmap_scan(tif->next, 0, start + 1, 255);
2570 if (end == start + 1) {
2571 ds_put_format(s, "%d,", start);
2573 ds_put_format(s, "%d-%d,", start, end - 1);
2577 if (ds_last(s) == ' ') {
2578 ds_put_cstr(s, "none");
2580 ds_put_char(s, '\n');
2582 ds_put_cstr(s, " instructions: ");
2583 if (tif->instructions) {
2586 for (i = 0; i < 32; i++) {
2587 if (tif->instructions & (1u << i)) {
2588 ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
2593 ds_put_cstr(s, "none");
2595 ds_put_char(s, '\n');
2597 if (table_action_features_equal(&tif->write, &tif->apply)) {
2598 ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
2599 print_table_action_features(s, &tif->write);
2601 ds_put_cstr(s, " Write-Actions features:\n");
2602 print_table_action_features(s, &tif->write);
2603 ds_put_cstr(s, " Apply-Actions features:\n");
2604 print_table_action_features(s, &tif->apply);
2609 table_instruction_features_equal(
2610 const struct ofputil_table_instruction_features *a,
2611 const struct ofputil_table_instruction_features *b)
2613 return (bitmap_equal(a->next, b->next, 255)
2614 && a->instructions == b->instructions
2615 && table_action_features_equal(&a->write, &b->write)
2616 && table_action_features_equal(&a->apply, &b->apply));
2620 ofp_print_table_features(struct ds *s, const struct ofp_header *oh)
2624 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2627 struct ofputil_table_features tf;
2631 retval = ofputil_decode_table_features(&b, &tf, true);
2633 if (retval != EOF) {
2634 ofp_print_error(s, retval);
2639 ds_put_format(s, "\n table %"PRIu8":\n", tf.table_id);
2640 ds_put_format(s, " name=\"%s\"\n", tf.name);
2641 ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
2642 ntohll(tf.metadata_match), ntohll(tf.metadata_write));
2644 ds_put_cstr(s, " config=");
2645 ofp_print_table_miss_config(s, tf.config);
2647 ds_put_format(s, " max_entries=%"PRIu32"\n", tf.max_entries);
2649 if (table_instruction_features_equal(&tf.nonmiss, &tf.miss)) {
2650 ds_put_cstr(s, " instructions (table miss and others):\n");
2651 print_table_instruction_features(s, &tf.nonmiss);
2653 ds_put_cstr(s, " instructions (other than table miss):\n");
2654 print_table_instruction_features(s, &tf.nonmiss);
2655 ds_put_cstr(s, " instructions (table miss):\n");
2656 print_table_instruction_features(s, &tf.miss);
2659 ds_put_cstr(s, " matching:\n");
2660 for (i = 0; i < MFF_N_IDS; i++) {
2661 uint64_t bit = UINT64_C(1) << i;
2663 if (tf.match & bit) {
2664 const struct mf_field *f = mf_from_id(i);
2666 ds_put_format(s, " %s: %s\n",
2668 (tf.mask ? "arbitrary mask"
2669 : tf.wildcard ? "exact match or wildcard"
2670 : "must exact match"));
2677 bundle_flags_to_name(uint32_t bit)
2690 ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh)
2693 struct ofputil_bundle_ctrl_msg bctrl;
2695 error = ofputil_decode_bundle_ctrl(oh, &bctrl);
2697 ofp_print_error(s, error);
2701 ds_put_char(s, '\n');
2703 ds_put_format(s, " bundle_id=%#"PRIx32" type=", bctrl.bundle_id);
2704 switch (bctrl.type) {
2705 case OFPBCT_OPEN_REQUEST:
2706 ds_put_cstr(s, "OPEN_REQUEST");
2708 case OFPBCT_OPEN_REPLY:
2709 ds_put_cstr(s, "OPEN_REPLY");
2711 case OFPBCT_CLOSE_REQUEST:
2712 ds_put_cstr(s, "CLOSE_REQUEST");
2714 case OFPBCT_CLOSE_REPLY:
2715 ds_put_cstr(s, "CLOSE_REPLY");
2717 case OFPBCT_COMMIT_REQUEST:
2718 ds_put_cstr(s, "COMMIT_REQUEST");
2720 case OFPBCT_COMMIT_REPLY:
2721 ds_put_cstr(s, "COMMIT_REPLY");
2723 case OFPBCT_DISCARD_REQUEST:
2724 ds_put_cstr(s, "DISCARD_REQUEST");
2726 case OFPBCT_DISCARD_REPLY:
2727 ds_put_cstr(s, "DISCARD_REPLY");
2731 ds_put_cstr(s, " flags=");
2732 ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' ');
2736 ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
2739 struct ofputil_bundle_add_msg badd;
2742 error = ofputil_decode_bundle_add(oh, &badd);
2744 ofp_print_error(s, error);
2748 ds_put_char(s, '\n');
2749 ds_put_format(s, " bundle_id=%#"PRIx32, badd.bundle_id);
2750 ds_put_cstr(s, " flags=");
2751 ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
2753 ds_put_char(s, '\n');
2754 msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
2756 ds_put_cstr(s, msg);
2761 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2762 struct ds *string, int verbosity)
2764 const void *msg = oh;
2766 ofp_header_to_string__(oh, raw, string);
2767 switch (ofptype_from_ofpraw(raw)) {
2769 case OFPTYPE_GROUP_STATS_REQUEST:
2770 ofp_print_stats_request(string, oh);
2771 ofp_print_ofpst_group_request(string, oh);
2774 case OFPTYPE_GROUP_STATS_REPLY:
2775 ofp_print_group_stats(string, oh);
2778 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
2779 ofp_print_stats_request(string, oh);
2782 case OFPTYPE_GROUP_DESC_STATS_REPLY:
2783 ofp_print_group_desc(string, oh);
2786 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
2787 ofp_print_stats_request(string, oh);
2790 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
2791 ofp_print_group_features(string, oh);
2794 case OFPTYPE_GROUP_MOD:
2795 ofp_print_group_mod(string, oh);
2798 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
2799 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
2800 ofp_print_table_features(string, oh);
2804 ofp_print_hello(string, oh);
2808 ofp_print_error_msg(string, oh);
2811 case OFPTYPE_ECHO_REQUEST:
2812 case OFPTYPE_ECHO_REPLY:
2813 ofp_print_echo(string, oh, verbosity);
2816 case OFPTYPE_FEATURES_REQUEST:
2819 case OFPTYPE_FEATURES_REPLY:
2820 ofp_print_switch_features(string, oh);
2823 case OFPTYPE_GET_CONFIG_REQUEST:
2826 case OFPTYPE_GET_CONFIG_REPLY:
2827 case OFPTYPE_SET_CONFIG:
2828 ofp_print_switch_config(string, ofpmsg_body(oh));
2831 case OFPTYPE_PACKET_IN:
2832 ofp_print_packet_in(string, oh, verbosity);
2835 case OFPTYPE_FLOW_REMOVED:
2836 ofp_print_flow_removed(string, oh);
2839 case OFPTYPE_PORT_STATUS:
2840 ofp_print_port_status(string, oh);
2843 case OFPTYPE_PACKET_OUT:
2844 ofp_print_packet_out(string, oh, verbosity);
2847 case OFPTYPE_FLOW_MOD:
2848 ofp_print_flow_mod(string, oh, verbosity);
2851 case OFPTYPE_PORT_MOD:
2852 ofp_print_port_mod(string, oh);
2855 case OFPTYPE_TABLE_MOD:
2856 ofp_print_table_mod(string, oh);
2859 case OFPTYPE_METER_MOD:
2860 ofp_print_meter_mod(string, oh);
2863 case OFPTYPE_BARRIER_REQUEST:
2864 case OFPTYPE_BARRIER_REPLY:
2867 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
2868 ofp_print_queue_get_config_request(string, oh);
2871 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
2872 ofp_print_queue_get_config_reply(string, oh);
2875 case OFPTYPE_ROLE_REQUEST:
2876 case OFPTYPE_ROLE_REPLY:
2877 ofp_print_role_message(string, oh);
2879 case OFPTYPE_ROLE_STATUS:
2880 ofp_print_role_status_message(string, oh);
2883 case OFPTYPE_METER_STATS_REQUEST:
2884 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
2885 ofp_print_stats_request(string, oh);
2886 ofp_print_meter_stats_request(string, oh);
2889 case OFPTYPE_METER_STATS_REPLY:
2890 ofp_print_stats_reply(string, oh);
2891 ofp_print_meter_stats_reply(string, oh);
2894 case OFPTYPE_METER_CONFIG_STATS_REPLY:
2895 ofp_print_stats_reply(string, oh);
2896 ofp_print_meter_config_reply(string, oh);
2899 case OFPTYPE_METER_FEATURES_STATS_REPLY:
2900 ofp_print_stats_reply(string, oh);
2901 ofp_print_meter_features_reply(string, oh);
2904 case OFPTYPE_DESC_STATS_REQUEST:
2905 case OFPTYPE_PORT_DESC_STATS_REQUEST:
2906 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
2907 ofp_print_stats_request(string, oh);
2910 case OFPTYPE_FLOW_STATS_REQUEST:
2911 case OFPTYPE_AGGREGATE_STATS_REQUEST:
2912 ofp_print_stats_request(string, oh);
2913 ofp_print_flow_stats_request(string, oh);
2916 case OFPTYPE_TABLE_STATS_REQUEST:
2917 ofp_print_stats_request(string, oh);
2920 case OFPTYPE_PORT_STATS_REQUEST:
2921 ofp_print_stats_request(string, oh);
2922 ofp_print_ofpst_port_request(string, oh);
2925 case OFPTYPE_QUEUE_STATS_REQUEST:
2926 ofp_print_stats_request(string, oh);
2927 ofp_print_ofpst_queue_request(string, oh);
2930 case OFPTYPE_DESC_STATS_REPLY:
2931 ofp_print_stats_reply(string, oh);
2932 ofp_print_ofpst_desc_reply(string, oh);
2935 case OFPTYPE_FLOW_STATS_REPLY:
2936 ofp_print_stats_reply(string, oh);
2937 ofp_print_flow_stats_reply(string, oh);
2940 case OFPTYPE_QUEUE_STATS_REPLY:
2941 ofp_print_stats_reply(string, oh);
2942 ofp_print_ofpst_queue_reply(string, oh, verbosity);
2945 case OFPTYPE_PORT_STATS_REPLY:
2946 ofp_print_stats_reply(string, oh);
2947 ofp_print_ofpst_port_reply(string, oh, verbosity);
2950 case OFPTYPE_TABLE_STATS_REPLY:
2951 ofp_print_stats_reply(string, oh);
2952 ofp_print_ofpst_table_reply(string, oh, verbosity);
2955 case OFPTYPE_AGGREGATE_STATS_REPLY:
2956 ofp_print_stats_reply(string, oh);
2957 ofp_print_aggregate_stats_reply(string, oh);
2960 case OFPTYPE_PORT_DESC_STATS_REPLY:
2961 ofp_print_stats_reply(string, oh);
2962 ofp_print_ofpst_port_desc_reply(string, oh);
2965 case OFPTYPE_FLOW_MOD_TABLE_ID:
2966 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
2969 case OFPTYPE_SET_FLOW_FORMAT:
2970 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
2973 case OFPTYPE_SET_PACKET_IN_FORMAT:
2974 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
2977 case OFPTYPE_FLOW_AGE:
2980 case OFPTYPE_SET_CONTROLLER_ID:
2981 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
2984 case OFPTYPE_GET_ASYNC_REPLY:
2985 case OFPTYPE_SET_ASYNC_CONFIG:
2986 ofp_print_nxt_set_async_config(string, ofpmsg_body(oh));
2988 case OFPTYPE_GET_ASYNC_REQUEST:
2990 case OFPTYPE_FLOW_MONITOR_CANCEL:
2991 ofp_print_nxt_flow_monitor_cancel(string, msg);
2994 case OFPTYPE_FLOW_MONITOR_PAUSED:
2995 case OFPTYPE_FLOW_MONITOR_RESUMED:
2998 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
2999 ofp_print_nxst_flow_monitor_request(string, msg);
3002 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
3003 ofp_print_nxst_flow_monitor_reply(string, msg);
3006 case OFPTYPE_BUNDLE_CONTROL:
3007 ofp_print_bundle_ctrl(string, msg);
3010 case OFPTYPE_BUNDLE_ADD_MESSAGE:
3011 ofp_print_bundle_add(string, msg, verbosity);
3016 /* Composes and returns a string representing the OpenFlow packet of 'len'
3017 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
3018 * verbosity and higher numbers increase verbosity. The caller is responsible
3019 * for freeing the string. */
3021 ofp_to_string(const void *oh_, size_t len, int verbosity)
3023 struct ds string = DS_EMPTY_INITIALIZER;
3024 const struct ofp_header *oh = oh_;
3027 ds_put_cstr(&string, "OpenFlow message is empty\n");
3028 } else if (len < sizeof(struct ofp_header)) {
3029 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
3031 } else if (ntohs(oh->length) > len) {
3035 error = ofpraw_decode_partial(&raw, oh, len);
3037 ofp_header_to_string__(oh, raw, &string);
3038 ds_put_char(&string, '\n');
3041 ds_put_format(&string,
3042 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
3043 len, ntohs(oh->length));
3044 } else if (ntohs(oh->length) < len) {
3045 ds_put_format(&string,
3046 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
3047 ntohs(oh->length), len);
3052 error = ofpraw_decode(&raw, oh);
3054 ofp_to_string__(oh, raw, &string, verbosity);
3055 if (verbosity >= 5) {
3056 if (ds_last(&string) != '\n') {
3057 ds_put_char(&string, '\n');
3059 ds_put_hex_dump(&string, oh, len, 0, true);
3061 if (ds_last(&string) != '\n') {
3062 ds_put_char(&string, '\n');
3064 return ds_steal_cstr(&string);
3067 ofp_print_error(&string, error);
3069 ds_put_hex_dump(&string, oh, len, 0, true);
3070 return ds_steal_cstr(&string);
3074 print_and_free(FILE *stream, char *string)
3076 fputs(string, stream);
3080 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
3081 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
3082 * numbers increase verbosity. */
3084 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
3086 print_and_free(stream, ofp_to_string(oh, len, verbosity));
3089 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
3090 * 'data' to 'stream'. */
3092 ofp_print_packet(FILE *stream, const void *data, size_t len)
3094 print_and_free(stream, ofp_packet_to_string(data, len));