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,
422 struct ofputil_phy_port *ports;
426 n_ports = ofputil_count_phy_ports(ofp_version, b);
428 ports = xmalloc(n_ports * sizeof *ports);
429 for (i = 0; i < n_ports; i++) {
430 error = ofputil_pull_phy_port(ofp_version, b, &ports[i]);
432 ofp_print_error(string, error);
436 qsort(ports, n_ports, sizeof *ports, compare_ports);
437 for (i = 0; i < n_ports; i++) {
438 ofp_print_phy_port(string, &ports[i]);
446 ofputil_capabilities_to_name(uint32_t bit)
448 enum ofputil_capabilities capabilities = bit;
450 switch (capabilities) {
451 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
452 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
453 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
454 case OFPUTIL_C_IP_REASM: return "IP_REASM";
455 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
456 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
457 case OFPUTIL_C_STP: return "STP";
458 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
459 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
466 ofputil_action_bitmap_to_name(uint32_t bit)
468 enum ofputil_action_bitmap action = bit;
471 case OFPUTIL_A_OUTPUT: return "OUTPUT";
472 case OFPUTIL_A_SET_VLAN_VID: return "SET_VLAN_VID";
473 case OFPUTIL_A_SET_VLAN_PCP: return "SET_VLAN_PCP";
474 case OFPUTIL_A_STRIP_VLAN: return "STRIP_VLAN";
475 case OFPUTIL_A_SET_DL_SRC: return "SET_DL_SRC";
476 case OFPUTIL_A_SET_DL_DST: return "SET_DL_DST";
477 case OFPUTIL_A_SET_NW_SRC: return "SET_NW_SRC";
478 case OFPUTIL_A_SET_NW_DST: return "SET_NW_DST";
479 case OFPUTIL_A_SET_NW_ECN: return "SET_NW_ECN";
480 case OFPUTIL_A_SET_NW_TOS: return "SET_NW_TOS";
481 case OFPUTIL_A_SET_TP_SRC: return "SET_TP_SRC";
482 case OFPUTIL_A_SET_TP_DST: return "SET_TP_DST";
483 case OFPUTIL_A_SET_FIELD: return "SET_FIELD";
484 case OFPUTIL_A_ENQUEUE: return "ENQUEUE";
485 case OFPUTIL_A_COPY_TTL_OUT: return "COPY_TTL_OUT";
486 case OFPUTIL_A_COPY_TTL_IN: return "COPY_TTL_IN";
487 case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL";
488 case OFPUTIL_A_SET_MPLS_TC: return "SET_MPLS_TC";
489 case OFPUTIL_A_SET_MPLS_TTL: return "SET_MPLS_TTL";
490 case OFPUTIL_A_DEC_MPLS_TTL: return "DEC_MPLS_TTL";
491 case OFPUTIL_A_PUSH_VLAN: return "PUSH_VLAN";
492 case OFPUTIL_A_POP_VLAN: return "POP_VLAN";
493 case OFPUTIL_A_PUSH_MPLS: return "PUSH_MPLS";
494 case OFPUTIL_A_POP_MPLS: return "POP_MPLS";
495 case OFPUTIL_A_SET_QUEUE: return "SET_QUEUE";
496 case OFPUTIL_A_GROUP: return "GROUP";
497 case OFPUTIL_A_SET_NW_TTL: return "SET_NW_TTL";
498 case OFPUTIL_A_DEC_NW_TTL: return "DEC_NW_TTL";
505 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
507 struct ofputil_switch_features features;
511 error = ofputil_decode_switch_features(oh, &features, &b);
513 ofp_print_error(string, error);
517 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
519 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
520 features.n_tables, features.n_buffers);
521 if (features.auxiliary_id) {
522 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
524 ds_put_char(string, '\n');
526 ds_put_cstr(string, "capabilities: ");
527 ofp_print_bit_names(string, features.capabilities,
528 ofputil_capabilities_to_name, ' ');
529 ds_put_char(string, '\n');
531 switch ((enum ofp_version)oh->version) {
533 ds_put_cstr(string, "actions: ");
534 ofp_print_bit_names(string, features.actions,
535 ofputil_action_bitmap_to_name, ' ');
536 ds_put_char(string, '\n');
543 return; /* no ports in ofp13_switch_features */
548 ofp_print_phy_ports(string, oh->version, &b);
552 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
554 enum ofp_config_flags flags;
556 flags = ntohs(osc->flags);
558 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
559 flags &= ~OFPC_FRAG_MASK;
561 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
562 ds_put_format(string, " invalid_ttl_to_controller");
563 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
567 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
570 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
573 static void print_wild(struct ds *string, const char *leader, int is_wild,
574 int verbosity, const char *format, ...)
577 static void print_wild(struct ds *string, const char *leader, int is_wild,
578 int verbosity, const char *format, ...)
580 if (is_wild && verbosity < 2) {
583 ds_put_cstr(string, leader);
587 va_start(args, format);
588 ds_put_format_valist(string, format, args);
591 ds_put_char(string, '*');
593 ds_put_char(string, ',');
597 print_wild_port(struct ds *string, const char *leader, int is_wild,
598 int verbosity, ofp_port_t port)
600 if (is_wild && verbosity < 2) {
603 ds_put_cstr(string, leader);
605 ofputil_format_port(port, string);
607 ds_put_char(string, '*');
609 ds_put_char(string, ',');
613 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
614 uint32_t wild_bits, int verbosity)
616 if (wild_bits >= 32 && verbosity < 2) {
619 ds_put_cstr(string, leader);
620 if (wild_bits < 32) {
621 ds_put_format(string, IP_FMT, IP_ARGS(ip));
623 ds_put_format(string, "/%d", 32 - wild_bits);
626 ds_put_char(string, '*');
628 ds_put_char(string, ',');
632 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
634 char *s = ofp10_match_to_string(om, verbosity);
640 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
642 struct ds f = DS_EMPTY_INITIALIZER;
643 uint32_t w = ntohl(om->wildcards);
644 bool skip_type = false;
645 bool skip_proto = false;
647 if (!(w & OFPFW10_DL_TYPE)) {
649 if (om->dl_type == htons(ETH_TYPE_IP)) {
650 if (!(w & OFPFW10_NW_PROTO)) {
652 if (om->nw_proto == IPPROTO_ICMP) {
653 ds_put_cstr(&f, "icmp,");
654 } else if (om->nw_proto == IPPROTO_TCP) {
655 ds_put_cstr(&f, "tcp,");
656 } else if (om->nw_proto == IPPROTO_UDP) {
657 ds_put_cstr(&f, "udp,");
658 } else if (om->nw_proto == IPPROTO_SCTP) {
659 ds_put_cstr(&f, "sctp,");
661 ds_put_cstr(&f, "ip,");
665 ds_put_cstr(&f, "ip,");
667 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
668 ds_put_cstr(&f, "arp,");
669 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
670 ds_put_cstr(&f, "rarp,");
671 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
672 ds_put_cstr(&f, "mpls,");
673 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
674 ds_put_cstr(&f, "mplsm,");
679 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
680 u16_to_ofp(ntohs(om->in_port)));
681 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
682 "%d", ntohs(om->dl_vlan));
683 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
684 "%d", om->dl_vlan_pcp);
685 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
686 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
687 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
688 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
690 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
691 "0x%04x", ntohs(om->dl_type));
693 print_ip_netmask(&f, "nw_src=", om->nw_src,
694 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
696 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
697 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
700 if (om->dl_type == htons(ETH_TYPE_ARP) ||
701 om->dl_type == htons(ETH_TYPE_RARP)) {
702 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
705 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
709 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
711 if (om->nw_proto == IPPROTO_ICMP) {
712 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
713 "%d", ntohs(om->tp_src));
714 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
715 "%d", ntohs(om->tp_dst));
717 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
718 "%d", ntohs(om->tp_src));
719 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
720 "%d", ntohs(om->tp_dst));
722 if (ds_last(&f) == ',') {
729 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
731 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
732 ds_put_cstr(s, "send_flow_rem ");
734 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
735 ds_put_cstr(s, "check_overlap ");
737 if (flags & OFPUTIL_FF_RESET_COUNTS) {
738 ds_put_cstr(s, "reset_counts ");
740 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
741 ds_put_cstr(s, "no_packet_counts ");
743 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
744 ds_put_cstr(s, "no_byte_counts ");
746 if (flags & OFPUTIL_FF_HIDDEN_FIELDS) {
747 ds_put_cstr(s, "allow_hidden_fields ");
749 if (flags & OFPUTIL_FF_NO_READONLY) {
750 ds_put_cstr(s, "no_readonly_table ");
755 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
757 struct ofputil_flow_mod fm;
758 struct ofpbuf ofpacts;
762 enum ofputil_protocol protocol;
764 protocol = ofputil_protocol_from_ofp_version(oh->version);
765 protocol = ofputil_protocol_set_tid(protocol, true);
767 ofpbuf_init(&ofpacts, 64);
768 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
771 ofpbuf_uninit(&ofpacts);
772 ofp_print_error(s, error);
777 switch (fm.command) {
779 ds_put_cstr(s, "ADD");
782 ds_put_cstr(s, "MOD");
784 case OFPFC_MODIFY_STRICT:
785 ds_put_cstr(s, "MOD_STRICT");
788 ds_put_cstr(s, "DEL");
790 case OFPFC_DELETE_STRICT:
791 ds_put_cstr(s, "DEL_STRICT");
794 ds_put_format(s, "cmd:%d", fm.command);
796 if (fm.table_id != 0) {
797 ds_put_format(s, " table:%d", fm.table_id);
801 ofpraw_decode(&raw, oh);
802 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
803 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
804 ofp10_match_print(s, &ofm->match, verbosity);
806 /* ofp_print_match() doesn't print priority. */
807 need_priority = true;
808 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
809 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
810 const void *nxm = nfm + 1;
813 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
814 ds_put_cstr(s, nxm_s);
817 /* nx_match_to_string() doesn't print priority. */
818 need_priority = true;
820 match_format(&fm.match, s, fm.priority);
822 /* match_format() does print priority. */
823 need_priority = false;
826 if (ds_last(s) != ' ') {
829 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
830 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
832 if (fm.cookie_mask != htonll(0)) {
833 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
834 ntohll(fm.cookie), ntohll(fm.cookie_mask));
836 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
837 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
839 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
840 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
842 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
843 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
845 if (fm.buffer_id != UINT32_MAX) {
846 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
848 if (fm.out_port != OFPP_ANY) {
849 ds_put_format(s, "out_port:");
850 ofputil_format_port(fm.out_port, s);
854 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
855 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
856 * versions don't really have such a flag and printing one is likely to
858 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
860 ofp_print_flow_flags(s, fm.flags);
862 ds_put_cstr(s, "actions=");
863 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
864 ofpbuf_uninit(&ofpacts);
868 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
870 ds_put_format(string, "%u", sec);
872 /* If there are no fractional seconds, don't print any decimals.
874 * If the fractional seconds can be expressed exactly as milliseconds,
875 * print 3 decimals. Open vSwitch provides millisecond precision for most
876 * time measurements, so printing 3 decimals every time makes it easier to
877 * spot real changes in flow dumps that refresh themselves quickly.
879 * If the fractional seconds are more precise than milliseconds, print the
880 * number of decimals needed to express them exactly.
883 unsigned int msec = nsec / 1000000;
884 if (msec * 1000000 == nsec) {
885 ds_put_format(string, ".%03u", msec);
887 ds_put_format(string, ".%09u", nsec);
888 while (string->string[string->length - 1] == '0') {
893 ds_put_char(string, 's');
896 /* Returns a string form of 'reason'. The return value is either a statically
897 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
898 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
899 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
901 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
902 char *reasonbuf, size_t bufsize)
905 case OFPRR_IDLE_TIMEOUT:
907 case OFPRR_HARD_TIMEOUT:
911 case OFPRR_GROUP_DELETE:
912 return "group_delete";
915 case OFPRR_METER_DELETE:
916 return "meter_delete";
918 snprintf(reasonbuf, bufsize, "%d", (int) reason);
924 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
926 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
927 struct ofputil_flow_removed fr;
930 error = ofputil_decode_flow_removed(&fr, oh);
932 ofp_print_error(string, error);
936 ds_put_char(string, ' ');
937 match_format(&fr.match, string, fr.priority);
939 ds_put_format(string, " reason=%s",
940 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
943 if (fr.table_id != 255) {
944 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
947 if (fr.cookie != htonll(0)) {
948 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
950 ds_put_cstr(string, " duration");
951 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
952 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
953 if (fr.hard_timeout) {
954 /* The hard timeout was only added in OF1.2, so only print it if it is
955 * actually in use to avoid gratuitous change to the formatting. */
956 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
958 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
959 fr.packet_count, fr.byte_count);
963 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
965 struct ofputil_port_mod pm;
968 error = ofputil_decode_port_mod(oh, &pm);
970 ofp_print_error(string, error);
974 ds_put_cstr(string, "port: ");
975 ofputil_format_port(pm.port_no, string);
976 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
977 ETH_ADDR_ARGS(pm.hw_addr));
979 ds_put_cstr(string, " config: ");
980 ofp_print_port_config(string, pm.config);
982 ds_put_cstr(string, " mask: ");
983 ofp_print_port_config(string, pm.mask);
985 ds_put_cstr(string, " advertise: ");
987 ofp_print_port_features(string, pm.advertise);
989 ds_put_cstr(string, "UNCHANGED\n");
994 ofp_print_table_miss_config(struct ds *string, const uint32_t config)
996 uint32_t table_miss_config = config & OFPTC11_TABLE_MISS_MASK;
998 switch (table_miss_config) {
999 case OFPTC11_TABLE_MISS_CONTROLLER:
1000 ds_put_cstr(string, "controller\n");
1002 case OFPTC11_TABLE_MISS_CONTINUE:
1003 ds_put_cstr(string, "continue\n");
1005 case OFPTC11_TABLE_MISS_DROP:
1006 ds_put_cstr(string, "drop\n");
1009 ds_put_cstr(string, "Unknown\n");
1015 ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
1017 struct ofputil_table_mod pm;
1020 error = ofputil_decode_table_mod(oh, &pm);
1022 ofp_print_error(string, error);
1026 if (pm.table_id == 0xff) {
1027 ds_put_cstr(string, " table_id: ALL_TABLES");
1029 ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
1032 ds_put_cstr(string, ", flow_miss_config=");
1033 ofp_print_table_miss_config(string, pm.config);
1037 ofp_print_queue_get_config_request(struct ds *string,
1038 const struct ofp_header *oh)
1043 error = ofputil_decode_queue_get_config_request(oh, &port);
1045 ofp_print_error(string, error);
1049 ds_put_cstr(string, " port=");
1050 ofputil_format_port(port, string);
1054 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1057 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1058 } else if (rate < UINT16_MAX) {
1059 ds_put_format(string, " %s:(disabled)", name);
1064 ofp_print_queue_get_config_reply(struct ds *string,
1065 const struct ofp_header *oh)
1071 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1072 error = ofputil_decode_queue_get_config_reply(&b, &port);
1074 ofp_print_error(string, error);
1078 ds_put_cstr(string, " port=");
1079 ofputil_format_port(port, string);
1080 ds_put_char(string, '\n');
1083 struct ofputil_queue_config queue;
1086 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1088 if (retval != EOF) {
1089 ofp_print_error(string, retval);
1094 ds_put_format(string, "queue %"PRIu32":", queue.queue_id);
1095 print_queue_rate(string, "min_rate", queue.min_rate);
1096 print_queue_rate(string, "max_rate", queue.max_rate);
1097 ds_put_char(string, '\n');
1102 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1104 if (flags & OFPMF13_KBPS) {
1105 ds_put_cstr(s, "kbps ");
1107 if (flags & OFPMF13_PKTPS) {
1108 ds_put_cstr(s, "pktps ");
1110 if (flags & OFPMF13_BURST) {
1111 ds_put_cstr(s, "burst ");
1113 if (flags & OFPMF13_STATS) {
1114 ds_put_cstr(s, "stats ");
1117 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1119 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1124 ofp_print_meter_band(struct ds *s, uint16_t flags,
1125 const struct ofputil_meter_band *mb)
1127 ds_put_cstr(s, "\ntype=");
1130 ds_put_cstr(s, "drop");
1132 case OFPMBT13_DSCP_REMARK:
1133 ds_put_cstr(s, "dscp_remark");
1136 ds_put_format(s, "%u", mb->type);
1139 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1141 if (flags & OFPMF13_BURST) {
1142 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1144 if (mb->type == OFPMBT13_DSCP_REMARK) {
1145 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1150 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1154 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1155 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1156 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1157 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1158 ds_put_cstr(s, "duration:");
1159 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1160 ds_put_char(s, ' ');
1162 ds_put_cstr(s, "bands:\n");
1163 for (i = 0; i < ms->n_bands; ++i) {
1164 ds_put_format(s, "%d: ", i);
1165 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1166 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1171 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1175 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1177 ofp_print_meter_flags(s, mc->flags);
1179 ds_put_cstr(s, "bands=");
1180 for (i = 0; i < mc->n_bands; ++i) {
1181 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1183 ds_put_char(s, '\n');
1187 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1189 struct ofputil_meter_mod mm;
1190 struct ofpbuf bands;
1193 ofpbuf_init(&bands, 64);
1194 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1196 ofpbuf_uninit(&bands);
1197 ofp_print_error(s, error);
1201 switch (mm.command) {
1203 ds_put_cstr(s, " ADD ");
1205 case OFPMC13_MODIFY:
1206 ds_put_cstr(s, " MOD ");
1208 case OFPMC13_DELETE:
1209 ds_put_cstr(s, " DEL ");
1212 ds_put_format(s, " cmd:%d ", mm.command);
1215 ofp_print_meter_config(s, &mm.meter);
1216 ofpbuf_uninit(&bands);
1220 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1224 ofputil_decode_meter_request(oh, &meter_id);
1226 ds_put_format(s, " meter=%"PRIu32, meter_id);
1230 ofputil_meter_capabilities_to_name(uint32_t bit)
1232 enum ofp13_meter_flags flag = bit;
1235 case OFPMF13_KBPS: return "kbps";
1236 case OFPMF13_PKTPS: return "pktps";
1237 case OFPMF13_BURST: return "burst";
1238 case OFPMF13_STATS: return "stats";
1245 ofputil_meter_band_types_to_name(uint32_t bit)
1248 case 1 << OFPMBT13_DROP: return "drop";
1249 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1256 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1258 struct ofputil_meter_features mf;
1260 ofputil_decode_meter_features(oh, &mf);
1262 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1263 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1264 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1266 ds_put_cstr(s, "band_types: ");
1267 ofp_print_bit_names(s, mf.band_types,
1268 ofputil_meter_band_types_to_name, ' ');
1269 ds_put_char(s, '\n');
1271 ds_put_cstr(s, "capabilities: ");
1272 ofp_print_bit_names(s, mf.capabilities,
1273 ofputil_meter_capabilities_to_name, ' ');
1274 ds_put_char(s, '\n');
1278 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1280 struct ofpbuf bands;
1283 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1284 ofpbuf_init(&bands, 64);
1286 struct ofputil_meter_config mc;
1289 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1291 if (retval != EOF) {
1292 ofp_print_error(s, retval);
1296 ds_put_char(s, '\n');
1297 ofp_print_meter_config(s, &mc);
1299 ofpbuf_uninit(&bands);
1303 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1305 struct ofpbuf bands;
1308 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1309 ofpbuf_init(&bands, 64);
1311 struct ofputil_meter_stats ms;
1314 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1316 if (retval != EOF) {
1317 ofp_print_error(s, retval);
1321 ds_put_char(s, '\n');
1322 ofp_print_meter_stats(s, &ms);
1324 ofpbuf_uninit(&bands);
1328 ofp_print_error(struct ds *string, enum ofperr error)
1330 if (string->length) {
1331 ds_put_char(string, ' ');
1333 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1337 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1339 uint32_t allowed_versions;
1342 ok = ofputil_decode_hello(oh, &allowed_versions);
1344 ds_put_cstr(string, "\n version bitmap: ");
1345 ofputil_format_version_bitmap(string, allowed_versions);
1348 ds_put_cstr(string, "\n unknown data in hello:\n");
1349 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1354 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1356 size_t len = ntohs(oh->length);
1357 struct ofpbuf payload;
1361 error = ofperr_decode_msg(oh, &payload);
1363 ds_put_cstr(string, "***decode error***");
1364 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1368 ds_put_format(string, " %s\n", ofperr_get_name(error));
1370 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1371 ds_put_printable(string, ofpbuf_data(&payload), ofpbuf_size(&payload));
1373 s = ofp_to_string(ofpbuf_data(&payload), ofpbuf_size(&payload), 1);
1374 ds_put_cstr(string, s);
1377 ofpbuf_uninit(&payload);
1381 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1383 struct ofputil_port_status ps;
1386 error = ofputil_decode_port_status(oh, &ps);
1388 ofp_print_error(string, error);
1392 if (ps.reason == OFPPR_ADD) {
1393 ds_put_format(string, " ADD:");
1394 } else if (ps.reason == OFPPR_DELETE) {
1395 ds_put_format(string, " DEL:");
1396 } else if (ps.reason == OFPPR_MODIFY) {
1397 ds_put_format(string, " MOD:");
1400 ofp_print_phy_port(string, &ps.desc);
1404 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1406 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1408 ds_put_char(string, '\n');
1409 ds_put_format(string, "Manufacturer: %.*s\n",
1410 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1411 ds_put_format(string, "Hardware: %.*s\n",
1412 (int) sizeof ods->hw_desc, ods->hw_desc);
1413 ds_put_format(string, "Software: %.*s\n",
1414 (int) sizeof ods->sw_desc, ods->sw_desc);
1415 ds_put_format(string, "Serial Num: %.*s\n",
1416 (int) sizeof ods->serial_num, ods->serial_num);
1417 ds_put_format(string, "DP Description: %.*s\n",
1418 (int) sizeof ods->dp_desc, ods->dp_desc);
1422 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1424 struct ofputil_flow_stats_request fsr;
1427 error = ofputil_decode_flow_stats_request(&fsr, oh);
1429 ofp_print_error(string, error);
1433 if (fsr.table_id != 0xff) {
1434 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1437 if (fsr.out_port != OFPP_ANY) {
1438 ds_put_cstr(string, " out_port=");
1439 ofputil_format_port(fsr.out_port, string);
1442 ds_put_char(string, ' ');
1443 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1447 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1449 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1450 ntohll(fs->cookie));
1452 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1453 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1454 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1455 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1456 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1457 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1459 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1460 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1463 ofp_print_flow_flags(string, fs->flags);
1465 if (fs->idle_age >= 0) {
1466 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1468 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1469 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1472 match_format(&fs->match, string, fs->priority);
1473 if (string->string[string->length - 1] != ' ') {
1474 ds_put_char(string, ' ');
1477 ds_put_cstr(string, "actions=");
1478 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1482 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1484 struct ofpbuf ofpacts;
1487 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1488 ofpbuf_init(&ofpacts, 64);
1490 struct ofputil_flow_stats fs;
1493 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1495 if (retval != EOF) {
1496 ds_put_cstr(string, " ***parse error***");
1500 ds_put_char(string, '\n');
1501 ofp_print_flow_stats(string, &fs);
1503 ofpbuf_uninit(&ofpacts);
1507 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1509 struct ofputil_aggregate_stats as;
1512 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1514 ofp_print_error(string, error);
1518 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1519 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1520 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1524 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1526 ds_put_cstr(string, leader);
1527 if (stat != UINT64_MAX) {
1528 ds_put_format(string, "%"PRIu64, stat);
1530 ds_put_char(string, '?');
1533 ds_put_cstr(string, ", ");
1535 ds_put_cstr(string, "\n");
1540 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1542 ofp_port_t ofp10_port;
1545 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1547 ofp_print_error(string, error);
1551 ds_put_cstr(string, " port_no=");
1552 ofputil_format_port(ofp10_port, string);
1556 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1561 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1562 if (verbosity < 1) {
1566 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1568 struct ofputil_port_stats ps;
1571 retval = ofputil_decode_port_stats(&ps, &b);
1573 if (retval != EOF) {
1574 ds_put_cstr(string, " ***parse error***");
1579 ds_put_cstr(string, " port ");
1580 if (ofp_to_u16(ps.port_no) < 10) {
1581 ds_put_char(string, ' ');
1583 ofputil_format_port(ps.port_no, string);
1585 ds_put_cstr(string, ": rx ");
1586 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1587 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1588 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1589 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1590 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1591 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1592 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1594 ds_put_cstr(string, " tx ");
1595 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1596 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1597 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1598 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1599 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1601 if (ps.duration_sec != UINT32_MAX) {
1602 ds_put_cstr(string, " duration=");
1603 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1604 ds_put_char(string, '\n');
1610 ofp_print_one_ofpst_table_reply(struct ds *string, enum ofp_version ofp_version,
1611 const char *name, struct ofp12_table_stats *ts)
1613 char name_[OFP_MAX_TABLE_NAME_LEN + 1];
1615 /* ofp13_table_stats is different */
1616 if (ofp_version > OFP12_VERSION) {
1620 ovs_strlcpy(name_, name, sizeof name_);
1622 ds_put_format(string, " %d: %-8s: ", ts->table_id, name_);
1623 ds_put_format(string, "wild=0x%05"PRIx64", ", ntohll(ts->wildcards));
1624 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1625 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1626 ds_put_cstr(string, " ");
1627 ds_put_format(string, "lookup=%"PRIu64", ", ntohll(ts->lookup_count));
1628 ds_put_format(string, "matched=%"PRIu64"\n", ntohll(ts->matched_count));
1630 if (ofp_version < OFP11_VERSION) {
1634 ds_put_cstr(string, " ");
1635 ds_put_format(string, "match=0x%08"PRIx64", ", ntohll(ts->match));
1636 ds_put_format(string, "instructions=0x%08"PRIx32", ",
1637 ntohl(ts->instructions));
1638 ds_put_format(string, "config=0x%08"PRIx32"\n", ntohl(ts->config));
1639 ds_put_cstr(string, " ");
1640 ds_put_format(string, "write_actions=0x%08"PRIx32", ",
1641 ntohl(ts->write_actions));
1642 ds_put_format(string, "apply_actions=0x%08"PRIx32"\n",
1643 ntohl(ts->apply_actions));
1645 if (ofp_version < OFP12_VERSION) {
1649 ds_put_cstr(string, " ");
1650 ds_put_format(string, "write_setfields=0x%016"PRIx64"\n",
1651 ntohll(ts->write_setfields));
1652 ds_put_cstr(string, " ");
1653 ds_put_format(string, "apply_setfields=0x%016"PRIx64"\n",
1654 ntohll(ts->apply_setfields));
1655 ds_put_cstr(string, " ");
1656 ds_put_format(string, "metadata_match=0x%016"PRIx64"\n",
1657 ntohll(ts->metadata_match));
1658 ds_put_cstr(string, " ");
1659 ds_put_format(string, "metadata_write=0x%016"PRIx64"\n",
1660 ntohll(ts->metadata_write));
1664 ofp_print_ofpst_table_reply13(struct ds *string, const struct ofp_header *oh,
1667 struct ofp13_table_stats *ts;
1671 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1672 ofpraw_pull_assert(&b);
1674 n = ofpbuf_size(&b) / sizeof *ts;
1675 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1676 if (verbosity < 1) {
1681 ts = ofpbuf_try_pull(&b, sizeof *ts);
1685 ds_put_format(string,
1686 " %d: active=%"PRIu32", lookup=%"PRIu64 \
1687 ", matched=%"PRIu64"\n",
1688 ts->table_id, ntohl(ts->active_count),
1689 ntohll(ts->lookup_count), ntohll(ts->matched_count));
1694 ofp_print_ofpst_table_reply12(struct ds *string, const struct ofp_header *oh,
1697 struct ofp12_table_stats *ts;
1701 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1702 ofpraw_pull_assert(&b);
1704 n = ofpbuf_size(&b) / sizeof *ts;
1705 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1706 if (verbosity < 1) {
1711 ts = ofpbuf_try_pull(&b, sizeof *ts);
1716 ofp_print_one_ofpst_table_reply(string, OFP12_VERSION, ts->name, ts);
1721 ofp_print_ofpst_table_reply11(struct ds *string, const struct ofp_header *oh,
1724 struct ofp11_table_stats *ts;
1728 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1729 ofpraw_pull_assert(&b);
1731 n = ofpbuf_size(&b) / sizeof *ts;
1732 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1733 if (verbosity < 1) {
1738 struct ofp12_table_stats ts12;
1740 ts = ofpbuf_try_pull(&b, sizeof *ts);
1745 ts12.table_id = ts->table_id;
1746 ts12.wildcards = htonll(ntohl(ts->wildcards));
1747 ts12.max_entries = ts->max_entries;
1748 ts12.active_count = ts->active_count;
1749 ts12.lookup_count = ts->lookup_count;
1750 ts12.matched_count = ts->matched_count;
1751 ts12.match = htonll(ntohl(ts->match));
1752 ts12.instructions = ts->instructions;
1753 ts12.config = ts->config;
1754 ts12.write_actions = ts->write_actions;
1755 ts12.apply_actions = ts->apply_actions;
1756 ofp_print_one_ofpst_table_reply(string, OFP11_VERSION, ts->name, &ts12);
1761 ofp_print_ofpst_table_reply10(struct ds *string, const struct ofp_header *oh,
1764 struct ofp10_table_stats *ts;
1768 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1769 ofpraw_pull_assert(&b);
1771 n = ofpbuf_size(&b) / sizeof *ts;
1772 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1773 if (verbosity < 1) {
1778 struct ofp12_table_stats ts12;
1780 ts = ofpbuf_try_pull(&b, sizeof *ts);
1785 ts12.table_id = ts->table_id;
1786 ts12.wildcards = htonll(ntohl(ts->wildcards));
1787 ts12.max_entries = ts->max_entries;
1788 ts12.active_count = ts->active_count;
1789 ts12.lookup_count = get_32aligned_be64(&ts->lookup_count);
1790 ts12.matched_count = get_32aligned_be64(&ts->matched_count);
1791 ofp_print_one_ofpst_table_reply(string, OFP10_VERSION, ts->name, &ts12);
1796 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1799 switch ((enum ofp_version)oh->version) {
1802 ofp_print_ofpst_table_reply13(string, oh, verbosity);
1806 ofp_print_ofpst_table_reply12(string, oh, verbosity);
1810 ofp_print_ofpst_table_reply11(string, oh, verbosity);
1814 ofp_print_ofpst_table_reply10(string, oh, verbosity);
1823 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1825 if (queue_id == OFPQ_ALL) {
1826 ds_put_cstr(string, "ALL");
1828 ds_put_format(string, "%"PRIu32, queue_id);
1833 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1835 struct ofputil_queue_stats_request oqsr;
1838 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1840 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1844 ds_put_cstr(string, "port=");
1845 ofputil_format_port(oqsr.port_no, string);
1847 ds_put_cstr(string, " queue=");
1848 ofp_print_queue_name(string, oqsr.queue_id);
1852 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1857 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1858 if (verbosity < 1) {
1862 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1864 struct ofputil_queue_stats qs;
1867 retval = ofputil_decode_queue_stats(&qs, &b);
1869 if (retval != EOF) {
1870 ds_put_cstr(string, " ***parse error***");
1875 ds_put_cstr(string, " port ");
1876 ofputil_format_port(qs.port_no, string);
1877 ds_put_cstr(string, " queue ");
1878 ofp_print_queue_name(string, qs.queue_id);
1879 ds_put_cstr(string, ": ");
1881 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1882 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1883 print_port_stat(string, "errors=", qs.tx_errors, 1);
1885 ds_put_cstr(string, "duration=");
1886 if (qs.duration_sec != UINT32_MAX) {
1887 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1889 ds_put_char(string, '?');
1891 ds_put_char(string, '\n');
1896 ofp_print_ofpst_port_desc_reply(struct ds *string,
1897 const struct ofp_header *oh)
1901 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1902 ofpraw_pull_assert(&b);
1903 ds_put_char(string, '\n');
1904 ofp_print_phy_ports(string, oh->version, &b);
1908 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1910 uint16_t flags = ofpmp_flags(oh);
1913 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
1918 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1920 uint16_t flags = ofpmp_flags(oh);
1923 ds_put_cstr(string, " flags=");
1924 if (flags & OFPSF_REPLY_MORE) {
1925 ds_put_cstr(string, "[more]");
1926 flags &= ~OFPSF_REPLY_MORE;
1929 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1936 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1938 size_t len = ntohs(oh->length);
1940 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1941 if (verbosity > 1) {
1942 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1947 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1948 uint64_t generation_id)
1950 ds_put_cstr(string, " role=");
1953 case OFPCR12_ROLE_NOCHANGE:
1954 ds_put_cstr(string, "nochange");
1956 case OFPCR12_ROLE_EQUAL:
1957 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1959 case OFPCR12_ROLE_MASTER:
1960 ds_put_cstr(string, "master");
1962 case OFPCR12_ROLE_SLAVE:
1963 ds_put_cstr(string, "slave");
1969 if (generation_id != UINT64_MAX) {
1970 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1975 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1977 struct ofputil_role_request rr;
1980 error = ofputil_decode_role_message(oh, &rr);
1982 ofp_print_error(string, error);
1986 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1990 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1992 struct ofputil_role_status rs;
1995 error = ofputil_decode_role_status(oh, &rs);
1997 ofp_print_error(string, error);
2001 ofp_print_role_generic(string, rs.role, rs.generation_id);
2003 ds_put_cstr(string, " reason=");
2005 switch (rs.reason) {
2006 case OFPCRR_MASTER_REQUEST:
2007 ds_put_cstr(string, "master_request");
2010 ds_put_cstr(string, "configuration_changed");
2012 case OFPCRR_EXPERIMENTER:
2013 ds_put_cstr(string, "experimenter_data_changed");
2021 ofp_print_nxt_flow_mod_table_id(struct ds *string,
2022 const struct nx_flow_mod_table_id *nfmti)
2024 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
2028 ofp_print_nxt_set_flow_format(struct ds *string,
2029 const struct nx_set_flow_format *nsff)
2031 uint32_t format = ntohl(nsff->format);
2033 ds_put_cstr(string, " format=");
2034 if (ofputil_nx_flow_format_is_valid(format)) {
2035 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
2037 ds_put_format(string, "%"PRIu32, format);
2042 ofp_print_nxt_set_packet_in_format(struct ds *string,
2043 const struct nx_set_packet_in_format *nspf)
2045 uint32_t format = ntohl(nspf->format);
2047 ds_put_cstr(string, " format=");
2048 if (ofputil_packet_in_format_is_valid(format)) {
2049 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
2051 ds_put_format(string, "%"PRIu32, format);
2055 /* Returns a string form of 'reason'. The return value is either a statically
2056 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2057 * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
2058 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2060 ofp_port_reason_to_string(enum ofp_port_reason reason,
2061 char *reasonbuf, size_t bufsize)
2074 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2080 ofp_print_nxt_set_async_config(struct ds *string,
2081 const struct nx_async_config *nac)
2085 for (i = 0; i < 2; i++) {
2088 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2090 ds_put_cstr(string, " PACKET_IN:");
2091 for (j = 0; j < 32; j++) {
2092 if (nac->packet_in_mask[i] & htonl(1u << j)) {
2093 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2096 reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
2098 ds_put_format(string, " %s", reason);
2101 if (!nac->packet_in_mask[i]) {
2102 ds_put_cstr(string, " (off)");
2104 ds_put_char(string, '\n');
2106 ds_put_cstr(string, " PORT_STATUS:");
2107 for (j = 0; j < 32; j++) {
2108 if (nac->port_status_mask[i] & htonl(1u << j)) {
2109 char reasonbuf[OFP_PORT_REASON_BUFSIZE];
2112 reason = ofp_port_reason_to_string(j, reasonbuf,
2114 ds_put_format(string, " %s", reason);
2117 if (!nac->port_status_mask[i]) {
2118 ds_put_cstr(string, " (off)");
2120 ds_put_char(string, '\n');
2122 ds_put_cstr(string, " FLOW_REMOVED:");
2123 for (j = 0; j < 32; j++) {
2124 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
2125 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2128 reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
2130 ds_put_format(string, " %s", reason);
2133 if (!nac->flow_removed_mask[i]) {
2134 ds_put_cstr(string, " (off)");
2136 ds_put_char(string, '\n');
2141 ofp_print_nxt_set_controller_id(struct ds *string,
2142 const struct nx_controller_id *nci)
2144 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
2148 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
2149 const struct ofp_header *oh)
2151 ds_put_format(string, " id=%"PRIu32,
2152 ofputil_decode_flow_monitor_cancel(oh));
2156 nx_flow_monitor_flags_to_name(uint32_t bit)
2158 enum nx_flow_monitor_flags fmf = bit;
2161 case NXFMF_INITIAL: return "initial";
2162 case NXFMF_ADD: return "add";
2163 case NXFMF_DELETE: return "delete";
2164 case NXFMF_MODIFY: return "modify";
2165 case NXFMF_ACTIONS: return "actions";
2166 case NXFMF_OWN: return "own";
2173 ofp_print_nxst_flow_monitor_request(struct ds *string,
2174 const struct ofp_header *oh)
2178 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2180 struct ofputil_flow_monitor_request request;
2183 retval = ofputil_decode_flow_monitor_request(&request, &b);
2185 if (retval != EOF) {
2186 ofp_print_error(string, retval);
2191 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
2192 ofp_print_bit_names(string, request.flags,
2193 nx_flow_monitor_flags_to_name, ',');
2195 if (request.out_port != OFPP_NONE) {
2196 ds_put_cstr(string, " out_port=");
2197 ofputil_format_port(request.out_port, string);
2200 if (request.table_id != 0xff) {
2201 ds_put_format(string, " table=%"PRIu8, request.table_id);
2204 ds_put_char(string, ' ');
2205 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
2206 ds_chomp(string, ' ');
2211 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2212 const struct ofp_header *oh)
2214 uint64_t ofpacts_stub[1024 / 8];
2215 struct ofpbuf ofpacts;
2218 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2219 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2221 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2222 struct ofputil_flow_update update;
2226 update.match = &match;
2227 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2229 if (retval != EOF) {
2230 ofp_print_error(string, retval);
2232 ofpbuf_uninit(&ofpacts);
2236 ds_put_cstr(string, "\n event=");
2237 switch (update.event) {
2239 ds_put_cstr(string, "ADDED");
2243 ds_put_format(string, "DELETED reason=%s",
2244 ofp_flow_removed_reason_to_string(update.reason,
2249 case NXFME_MODIFIED:
2250 ds_put_cstr(string, "MODIFIED");
2254 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2258 ds_put_format(string, " table=%"PRIu8, update.table_id);
2259 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2260 ds_put_format(string, " idle_timeout=%"PRIu16,
2261 update.idle_timeout);
2263 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2264 ds_put_format(string, " hard_timeout=%"PRIu16,
2265 update.hard_timeout);
2267 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2269 ds_put_char(string, ' ');
2270 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2272 if (update.ofpacts_len) {
2273 if (string->string[string->length - 1] != ' ') {
2274 ds_put_char(string, ' ');
2276 ds_put_cstr(string, "actions=");
2277 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2283 ofp_print_version(const struct ofp_header *oh,
2286 switch (oh->version) {
2290 ds_put_cstr(string, " (OF1.1)");
2293 ds_put_cstr(string, " (OF1.2)");
2296 ds_put_cstr(string, " (OF1.3)");
2299 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2302 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2306 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2309 ds_put_cstr(string, ofpraw_get_name(raw));
2310 ofp_print_version(oh, string);
2314 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2315 struct list *p_buckets)
2317 static const char *type_str[] = { "all", "select", "indirect",
2319 struct ofputil_bucket *bucket;
2321 ds_put_format(s, "group_id=%"PRIu32",type=%s",
2322 group_id, type_str[type > 4 ? 4 : type]);
2327 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2328 ds_put_cstr(s, ",bucket=");
2330 if (bucket->weight != 1) {
2331 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2333 if (bucket->watch_port != OFPP_NONE) {
2334 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2336 if (bucket->watch_group != OFPG11_ANY) {
2337 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2340 ds_put_cstr(s, "actions=");
2341 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2346 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2350 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2352 struct ofputil_group_desc gd;
2355 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2357 if (retval != EOF) {
2358 ds_put_cstr(s, " ***parse error***");
2363 ds_put_char(s, '\n');
2364 ds_put_char(s, ' ');
2365 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets);
2370 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2375 error = ofputil_decode_group_stats_request(oh, &group_id);
2377 ofp_print_error(string, error);
2381 ds_put_cstr(string, " group_id=");
2382 ofputil_format_group(group_id, string);
2386 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2391 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2394 struct ofputil_group_stats gs;
2397 retval = ofputil_decode_group_stats_reply(&b, &gs);
2399 if (retval != EOF) {
2400 ds_put_cstr(s, " ***parse error***");
2405 ds_put_char(s, '\n');
2407 ds_put_char(s, ' ');
2408 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2410 if (gs.duration_sec != UINT32_MAX) {
2411 ds_put_cstr(s, "duration=");
2412 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2413 ds_put_char(s, ',');
2415 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2416 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2417 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2419 for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2420 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2421 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2422 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2423 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2427 free(gs.bucket_stats);
2432 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2434 struct ofputil_group_features features;
2436 ofputil_decode_group_features_reply(oh, &features);
2438 ds_put_format(string, "\n Group table:\n");
2439 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2440 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2441 features.capabilities);
2443 if (features.types & (1u << OFPGT11_ALL)) {
2444 ds_put_format(string, " All group :\n");
2445 ds_put_format(string,
2446 " max_groups = %#"PRIx32" actions=0x%08"PRIx32"\n",
2447 features.max_groups[0], features.actions[0]);
2450 if (features.types & (1u << OFPGT11_SELECT)) {
2451 ds_put_format(string, " Select group :\n");
2452 ds_put_format(string, " max_groups = %#"PRIx32" "
2453 "actions=0x%08"PRIx32"\n",
2454 features.max_groups[1], features.actions[1]);
2457 if (features.types & (1u << OFPGT11_INDIRECT)) {
2458 ds_put_format(string, " Indirect group :\n");
2459 ds_put_format(string, " max_groups = %#"PRIx32" "
2460 "actions=0x%08"PRIx32"\n",
2461 features.max_groups[2], features.actions[2]);
2464 if (features.types & (1u << OFPGT11_FF)) {
2465 ds_put_format(string, " Fast Failover group :\n");
2466 ds_put_format(string, " max_groups = %#"PRIx32" "
2467 "actions=0x%08"PRIx32"\n",
2468 features.max_groups[3], features.actions[3]);
2473 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2475 struct ofputil_group_mod gm;
2478 error = ofputil_decode_group_mod(oh, &gm);
2480 ofp_print_error(s, error);
2484 ds_put_char(s, '\n');
2486 ds_put_char(s, ' ');
2487 switch (gm.command) {
2489 ds_put_cstr(s, "ADD");
2492 case OFPGC11_MODIFY:
2493 ds_put_cstr(s, "MOD");
2496 case OFPGC11_DELETE:
2497 ds_put_cstr(s, "DEL");
2501 ds_put_format(s, "cmd:%"PRIu16"", gm.command);
2503 ds_put_char(s, ' ');
2505 ofp_print_group(s, gm.group_id, gm.type, &gm.buckets);
2509 ofp13_action_to_string(uint32_t bit)
2512 #define OFPAT13_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
2513 case 1u << ENUM: return NAME;
2514 #include "ofp-util.def"
2520 print_table_action_features(struct ds *s,
2521 const struct ofputil_table_action_features *taf)
2523 ds_put_cstr(s, " actions: ");
2524 ofp_print_bit_names(s, taf->actions, ofp13_action_to_string, ',');
2525 ds_put_char(s, '\n');
2527 ds_put_cstr(s, " supported on Set-Field: ");
2528 if (taf->set_fields) {
2531 for (i = 0; i < MFF_N_IDS; i++) {
2532 uint64_t bit = UINT64_C(1) << i;
2534 if (taf->set_fields & bit) {
2535 ds_put_format(s, "%s,", mf_from_id(i)->name);
2540 ds_put_cstr(s, "none");
2542 ds_put_char(s, '\n');
2546 table_action_features_equal(const struct ofputil_table_action_features *a,
2547 const struct ofputil_table_action_features *b)
2549 return a->actions == b->actions && a->set_fields == b->set_fields;
2553 print_table_instruction_features(
2554 struct ds *s, const struct ofputil_table_instruction_features *tif)
2558 ds_put_cstr(s, " next tables: ");
2559 for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
2560 start = bitmap_scan(tif->next, 1, end, 255)) {
2561 end = bitmap_scan(tif->next, 0, start + 1, 255);
2562 if (end == start + 1) {
2563 ds_put_format(s, "%d,", start);
2565 ds_put_format(s, "%d-%d,", start, end - 1);
2569 if (ds_last(s) == ' ') {
2570 ds_put_cstr(s, "none");
2572 ds_put_char(s, '\n');
2574 ds_put_cstr(s, " instructions: ");
2575 if (tif->instructions) {
2578 for (i = 0; i < 32; i++) {
2579 if (tif->instructions & (1u << i)) {
2580 ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
2585 ds_put_cstr(s, "none");
2587 ds_put_char(s, '\n');
2589 if (table_action_features_equal(&tif->write, &tif->apply)) {
2590 ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
2591 print_table_action_features(s, &tif->write);
2593 ds_put_cstr(s, " Write-Actions features:\n");
2594 print_table_action_features(s, &tif->write);
2595 ds_put_cstr(s, " Apply-Actions features:\n");
2596 print_table_action_features(s, &tif->apply);
2601 table_instruction_features_equal(
2602 const struct ofputil_table_instruction_features *a,
2603 const struct ofputil_table_instruction_features *b)
2605 return (bitmap_equal(a->next, b->next, 255)
2606 && a->instructions == b->instructions
2607 && table_action_features_equal(&a->write, &b->write)
2608 && table_action_features_equal(&a->apply, &b->apply));
2612 ofp_print_table_features(struct ds *s, const struct ofp_header *oh)
2616 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2619 struct ofputil_table_features tf;
2623 retval = ofputil_decode_table_features(&b, &tf, true);
2625 if (retval != EOF) {
2626 ofp_print_error(s, retval);
2631 ds_put_format(s, "\n table %"PRIu8":\n", tf.table_id);
2632 ds_put_format(s, " name=\"%s\"\n", tf.name);
2633 ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
2634 ntohll(tf.metadata_match), ntohll(tf.metadata_write));
2636 ds_put_cstr(s, " config=");
2637 ofp_print_table_miss_config(s, tf.config);
2639 ds_put_format(s, " max_entries=%"PRIu32"\n", tf.max_entries);
2641 if (table_instruction_features_equal(&tf.nonmiss, &tf.miss)) {
2642 ds_put_cstr(s, " instructions (table miss and others):\n");
2643 print_table_instruction_features(s, &tf.nonmiss);
2645 ds_put_cstr(s, " instructions (other than table miss):\n");
2646 print_table_instruction_features(s, &tf.nonmiss);
2647 ds_put_cstr(s, " instructions (table miss):\n");
2648 print_table_instruction_features(s, &tf.miss);
2651 ds_put_cstr(s, " matching:\n");
2652 for (i = 0; i < MFF_N_IDS; i++) {
2653 uint64_t bit = UINT64_C(1) << i;
2655 if (tf.match & bit) {
2656 const struct mf_field *f = mf_from_id(i);
2658 ds_put_format(s, " %s: %s\n",
2660 (tf.mask ? "arbitrary mask"
2661 : tf.wildcard ? "exact match or wildcard"
2662 : "must exact match"));
2669 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2670 struct ds *string, int verbosity)
2672 const void *msg = oh;
2674 ofp_header_to_string__(oh, raw, string);
2675 switch (ofptype_from_ofpraw(raw)) {
2677 case OFPTYPE_GROUP_STATS_REQUEST:
2678 ofp_print_stats_request(string, oh);
2679 ofp_print_ofpst_group_request(string, oh);
2682 case OFPTYPE_GROUP_STATS_REPLY:
2683 ofp_print_group_stats(string, oh);
2686 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
2687 ofp_print_stats_request(string, oh);
2690 case OFPTYPE_GROUP_DESC_STATS_REPLY:
2691 ofp_print_group_desc(string, oh);
2694 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
2695 ofp_print_stats_request(string, oh);
2698 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
2699 ofp_print_group_features(string, oh);
2702 case OFPTYPE_GROUP_MOD:
2703 ofp_print_group_mod(string, oh);
2706 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
2707 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
2708 ofp_print_table_features(string, oh);
2712 ofp_print_hello(string, oh);
2716 ofp_print_error_msg(string, oh);
2719 case OFPTYPE_ECHO_REQUEST:
2720 case OFPTYPE_ECHO_REPLY:
2721 ofp_print_echo(string, oh, verbosity);
2724 case OFPTYPE_FEATURES_REQUEST:
2727 case OFPTYPE_FEATURES_REPLY:
2728 ofp_print_switch_features(string, oh);
2731 case OFPTYPE_GET_CONFIG_REQUEST:
2734 case OFPTYPE_GET_CONFIG_REPLY:
2735 case OFPTYPE_SET_CONFIG:
2736 ofp_print_switch_config(string, ofpmsg_body(oh));
2739 case OFPTYPE_PACKET_IN:
2740 ofp_print_packet_in(string, oh, verbosity);
2743 case OFPTYPE_FLOW_REMOVED:
2744 ofp_print_flow_removed(string, oh);
2747 case OFPTYPE_PORT_STATUS:
2748 ofp_print_port_status(string, oh);
2751 case OFPTYPE_PACKET_OUT:
2752 ofp_print_packet_out(string, oh, verbosity);
2755 case OFPTYPE_FLOW_MOD:
2756 ofp_print_flow_mod(string, oh, verbosity);
2759 case OFPTYPE_PORT_MOD:
2760 ofp_print_port_mod(string, oh);
2763 case OFPTYPE_TABLE_MOD:
2764 ofp_print_table_mod(string, oh);
2767 case OFPTYPE_METER_MOD:
2768 ofp_print_meter_mod(string, oh);
2771 case OFPTYPE_BARRIER_REQUEST:
2772 case OFPTYPE_BARRIER_REPLY:
2775 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
2776 ofp_print_queue_get_config_request(string, oh);
2779 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
2780 ofp_print_queue_get_config_reply(string, oh);
2783 case OFPTYPE_ROLE_REQUEST:
2784 case OFPTYPE_ROLE_REPLY:
2785 ofp_print_role_message(string, oh);
2787 case OFPTYPE_ROLE_STATUS:
2788 ofp_print_role_status_message(string, oh);
2791 case OFPTYPE_METER_STATS_REQUEST:
2792 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
2793 ofp_print_stats_request(string, oh);
2794 ofp_print_meter_stats_request(string, oh);
2797 case OFPTYPE_METER_STATS_REPLY:
2798 ofp_print_stats_reply(string, oh);
2799 ofp_print_meter_stats_reply(string, oh);
2802 case OFPTYPE_METER_CONFIG_STATS_REPLY:
2803 ofp_print_stats_reply(string, oh);
2804 ofp_print_meter_config_reply(string, oh);
2807 case OFPTYPE_METER_FEATURES_STATS_REPLY:
2808 ofp_print_stats_reply(string, oh);
2809 ofp_print_meter_features_reply(string, oh);
2812 case OFPTYPE_DESC_STATS_REQUEST:
2813 case OFPTYPE_PORT_DESC_STATS_REQUEST:
2814 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
2815 ofp_print_stats_request(string, oh);
2818 case OFPTYPE_FLOW_STATS_REQUEST:
2819 case OFPTYPE_AGGREGATE_STATS_REQUEST:
2820 ofp_print_stats_request(string, oh);
2821 ofp_print_flow_stats_request(string, oh);
2824 case OFPTYPE_TABLE_STATS_REQUEST:
2825 ofp_print_stats_request(string, oh);
2828 case OFPTYPE_PORT_STATS_REQUEST:
2829 ofp_print_stats_request(string, oh);
2830 ofp_print_ofpst_port_request(string, oh);
2833 case OFPTYPE_QUEUE_STATS_REQUEST:
2834 ofp_print_stats_request(string, oh);
2835 ofp_print_ofpst_queue_request(string, oh);
2838 case OFPTYPE_DESC_STATS_REPLY:
2839 ofp_print_stats_reply(string, oh);
2840 ofp_print_ofpst_desc_reply(string, oh);
2843 case OFPTYPE_FLOW_STATS_REPLY:
2844 ofp_print_stats_reply(string, oh);
2845 ofp_print_flow_stats_reply(string, oh);
2848 case OFPTYPE_QUEUE_STATS_REPLY:
2849 ofp_print_stats_reply(string, oh);
2850 ofp_print_ofpst_queue_reply(string, oh, verbosity);
2853 case OFPTYPE_PORT_STATS_REPLY:
2854 ofp_print_stats_reply(string, oh);
2855 ofp_print_ofpst_port_reply(string, oh, verbosity);
2858 case OFPTYPE_TABLE_STATS_REPLY:
2859 ofp_print_stats_reply(string, oh);
2860 ofp_print_ofpst_table_reply(string, oh, verbosity);
2863 case OFPTYPE_AGGREGATE_STATS_REPLY:
2864 ofp_print_stats_reply(string, oh);
2865 ofp_print_aggregate_stats_reply(string, oh);
2868 case OFPTYPE_PORT_DESC_STATS_REPLY:
2869 ofp_print_stats_reply(string, oh);
2870 ofp_print_ofpst_port_desc_reply(string, oh);
2873 case OFPTYPE_FLOW_MOD_TABLE_ID:
2874 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
2877 case OFPTYPE_SET_FLOW_FORMAT:
2878 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
2881 case OFPTYPE_SET_PACKET_IN_FORMAT:
2882 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
2885 case OFPTYPE_FLOW_AGE:
2888 case OFPTYPE_SET_CONTROLLER_ID:
2889 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
2892 case OFPTYPE_GET_ASYNC_REPLY:
2893 case OFPTYPE_SET_ASYNC_CONFIG:
2894 ofp_print_nxt_set_async_config(string, ofpmsg_body(oh));
2896 case OFPTYPE_GET_ASYNC_REQUEST:
2898 case OFPTYPE_FLOW_MONITOR_CANCEL:
2899 ofp_print_nxt_flow_monitor_cancel(string, msg);
2902 case OFPTYPE_FLOW_MONITOR_PAUSED:
2903 case OFPTYPE_FLOW_MONITOR_RESUMED:
2906 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
2907 ofp_print_nxst_flow_monitor_request(string, msg);
2910 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
2911 ofp_print_nxst_flow_monitor_reply(string, msg);
2916 /* Composes and returns a string representing the OpenFlow packet of 'len'
2917 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
2918 * verbosity and higher numbers increase verbosity. The caller is responsible
2919 * for freeing the string. */
2921 ofp_to_string(const void *oh_, size_t len, int verbosity)
2923 struct ds string = DS_EMPTY_INITIALIZER;
2924 const struct ofp_header *oh = oh_;
2927 ds_put_cstr(&string, "OpenFlow message is empty\n");
2928 } else if (len < sizeof(struct ofp_header)) {
2929 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
2931 } else if (ntohs(oh->length) > len) {
2935 error = ofpraw_decode_partial(&raw, oh, len);
2937 ofp_header_to_string__(oh, raw, &string);
2938 ds_put_char(&string, '\n');
2941 ds_put_format(&string,
2942 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
2943 len, ntohs(oh->length));
2944 } else if (ntohs(oh->length) < len) {
2945 ds_put_format(&string,
2946 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
2947 ntohs(oh->length), len);
2952 error = ofpraw_decode(&raw, oh);
2954 ofp_to_string__(oh, raw, &string, verbosity);
2955 if (verbosity >= 5) {
2956 if (ds_last(&string) != '\n') {
2957 ds_put_char(&string, '\n');
2959 ds_put_hex_dump(&string, oh, len, 0, true);
2961 if (ds_last(&string) != '\n') {
2962 ds_put_char(&string, '\n');
2964 return ds_steal_cstr(&string);
2967 ofp_print_error(&string, error);
2969 ds_put_hex_dump(&string, oh, len, 0, true);
2970 return ds_steal_cstr(&string);
2974 print_and_free(FILE *stream, char *string)
2976 fputs(string, stream);
2980 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
2981 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
2982 * numbers increase verbosity. */
2984 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
2986 print_and_free(stream, ofp_to_string(oh, len, verbosity));
2989 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
2990 * 'data' to 'stream'. */
2992 ofp_print_packet(FILE *stream, const void *data, size_t len)
2994 print_and_free(stream, ofp_packet_to_string(data, len));