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"
51 static void ofp_print_queue_name(struct ds *string, uint32_t port);
52 static void ofp_print_error(struct ds *, enum ofperr);
55 /* Returns a string that represents the contents of the Ethernet frame in the
56 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
58 ofp_packet_to_string(const void *data, size_t len)
60 struct ds ds = DS_EMPTY_INITIALIZER;
64 ofpbuf_use_const(&buf, data, len);
65 flow_extract(&buf, 0, 0, NULL, NULL, &flow);
66 flow_format(&ds, &flow);
69 if (flow.nw_proto == IPPROTO_TCP) {
70 struct tcp_header *th = buf.l4;
71 ds_put_format(&ds, " tcp_csum:%"PRIx16,
73 } else if (flow.nw_proto == IPPROTO_UDP) {
74 struct udp_header *uh = buf.l4;
75 ds_put_format(&ds, " udp_csum:%"PRIx16,
77 } else if (flow.nw_proto == IPPROTO_SCTP) {
78 struct sctp_header *sh = buf.l4;
79 ds_put_format(&ds, " sctp_csum:%"PRIx32,
80 ntohl(get_16aligned_be32(&sh->sctp_csum)));
84 ds_put_char(&ds, '\n');
90 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
93 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
94 struct ofputil_packet_in pin;
98 error = ofputil_decode_packet_in(&pin, oh);
100 ofp_print_error(string, error);
105 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
108 if (pin.cookie != OVS_BE64_MAX) {
109 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
112 ds_put_format(string, " total_len=%"PRIuSIZE" in_port=", pin.total_len);
113 ofputil_format_port(pin.fmd.in_port, string);
115 if (pin.fmd.tun_id != htonll(0)) {
116 ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
119 if (pin.fmd.tun_src != htonl(0)) {
120 ds_put_format(string, " tun_src="IP_FMT, IP_ARGS(pin.fmd.tun_src));
123 if (pin.fmd.tun_dst != htonl(0)) {
124 ds_put_format(string, " tun_dst="IP_FMT, IP_ARGS(pin.fmd.tun_dst));
127 if (pin.fmd.metadata != htonll(0)) {
128 ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata));
131 for (i = 0; i < FLOW_N_REGS; i++) {
132 if (pin.fmd.regs[i]) {
133 ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
137 if (pin.fmd.pkt_mark != 0) {
138 ds_put_format(string, " pkt_mark=0x%"PRIx32, pin.fmd.pkt_mark);
141 ds_put_format(string, " (via %s)",
142 ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
145 ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len);
146 if (pin.buffer_id == UINT32_MAX) {
147 ds_put_format(string, " (unbuffered)");
148 if (pin.total_len != pin.packet_len) {
149 ds_put_format(string, " (***total_len != data_len***)");
152 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
153 if (pin.total_len < pin.packet_len) {
154 ds_put_format(string, " (***total_len < data_len***)");
157 ds_put_char(string, '\n');
160 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
161 ds_put_cstr(string, packet);
165 ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false);
170 ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
173 struct ofputil_packet_out po;
174 struct ofpbuf ofpacts;
177 ofpbuf_init(&ofpacts, 64);
178 error = ofputil_decode_packet_out(&po, oh, &ofpacts);
180 ofpbuf_uninit(&ofpacts);
181 ofp_print_error(string, error);
185 ds_put_cstr(string, " in_port=");
186 ofputil_format_port(po.in_port, string);
188 ds_put_cstr(string, " actions=");
189 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
191 if (po.buffer_id == UINT32_MAX) {
192 ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
193 if (verbosity > 0 && po.packet_len > 0) {
194 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
195 ds_put_char(string, '\n');
196 ds_put_cstr(string, packet);
200 ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
203 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
206 ofpbuf_uninit(&ofpacts);
209 /* qsort comparison function. */
211 compare_ports(const void *a_, const void *b_)
213 const struct ofputil_phy_port *a = a_;
214 const struct ofputil_phy_port *b = b_;
215 uint16_t ap = ofp_to_u16(a->port_no);
216 uint16_t bp = ofp_to_u16(b->port_no);
218 return ap < bp ? -1 : ap > bp;
222 ofp_print_bit_names(struct ds *string, uint32_t bits,
223 const char *(*bit_to_name)(uint32_t bit),
230 ds_put_cstr(string, "0");
234 for (i = 0; i < 32; i++) {
235 uint32_t bit = UINT32_C(1) << i;
238 const char *name = bit_to_name(bit);
241 ds_put_char(string, separator);
243 ds_put_cstr(string, name);
251 ds_put_char(string, separator);
253 ds_put_format(string, "0x%"PRIx32, bits);
258 netdev_feature_to_name(uint32_t bit)
260 enum netdev_features f = bit;
263 case NETDEV_F_10MB_HD: return "10MB-HD";
264 case NETDEV_F_10MB_FD: return "10MB-FD";
265 case NETDEV_F_100MB_HD: return "100MB-HD";
266 case NETDEV_F_100MB_FD: return "100MB-FD";
267 case NETDEV_F_1GB_HD: return "1GB-HD";
268 case NETDEV_F_1GB_FD: return "1GB-FD";
269 case NETDEV_F_10GB_FD: return "10GB-FD";
270 case NETDEV_F_40GB_FD: return "40GB-FD";
271 case NETDEV_F_100GB_FD: return "100GB-FD";
272 case NETDEV_F_1TB_FD: return "1TB-FD";
273 case NETDEV_F_OTHER: return "OTHER";
274 case NETDEV_F_COPPER: return "COPPER";
275 case NETDEV_F_FIBER: return "FIBER";
276 case NETDEV_F_AUTONEG: return "AUTO_NEG";
277 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
278 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
285 ofp_print_port_features(struct ds *string, enum netdev_features features)
287 ofp_print_bit_names(string, features, netdev_feature_to_name, ' ');
288 ds_put_char(string, '\n');
292 ofputil_port_config_to_name(uint32_t bit)
294 enum ofputil_port_config pc = bit;
297 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
298 case OFPUTIL_PC_NO_STP: return "NO_STP";
299 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
300 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
301 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
302 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
303 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
310 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
312 ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' ');
313 ds_put_char(string, '\n');
317 ofputil_port_state_to_name(uint32_t bit)
319 enum ofputil_port_state ps = bit;
322 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
323 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
324 case OFPUTIL_PS_LIVE: return "LIVE";
326 case OFPUTIL_PS_STP_LISTEN:
327 case OFPUTIL_PS_STP_LEARN:
328 case OFPUTIL_PS_STP_FORWARD:
329 case OFPUTIL_PS_STP_BLOCK:
330 /* Handled elsewhere. */
338 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
340 enum ofputil_port_state stp_state;
342 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
343 * pattern. We have to special case it.
345 * OVS doesn't support STP, so this field will always be 0 if we are
346 * talking to OVS, so we'd always print STP_LISTEN in that case.
347 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
348 * avoid confusing users. */
349 stp_state = state & OFPUTIL_PS_STP_MASK;
352 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
353 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
355 state &= ~OFPUTIL_PS_STP_MASK;
357 ofp_print_bit_names(string, state, ofputil_port_state_to_name,
361 ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' ');
363 ds_put_char(string, '\n');
367 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
369 char name[sizeof port->name];
372 memcpy(name, port->name, sizeof name);
373 for (j = 0; j < sizeof name - 1; j++) {
374 if (!isprint((unsigned char) name[j])) {
380 ds_put_char(string, ' ');
381 ofputil_format_port(port->port_no, string);
382 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
383 name, ETH_ADDR_ARGS(port->hw_addr));
385 ds_put_cstr(string, " config: ");
386 ofp_print_port_config(string, port->config);
388 ds_put_cstr(string, " state: ");
389 ofp_print_port_state(string, port->state);
392 ds_put_format(string, " current: ");
393 ofp_print_port_features(string, port->curr);
395 if (port->advertised) {
396 ds_put_format(string, " advertised: ");
397 ofp_print_port_features(string, port->advertised);
399 if (port->supported) {
400 ds_put_format(string, " supported: ");
401 ofp_print_port_features(string, port->supported);
404 ds_put_format(string, " peer: ");
405 ofp_print_port_features(string, port->peer);
407 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
408 "%"PRIu32" Mbps max\n",
409 port->curr_speed / UINT32_C(1000),
410 port->max_speed / UINT32_C(1000));
413 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
414 * 'ofp_version', writes a detailed description of each port into
417 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
421 struct ofputil_phy_port *ports;
425 n_ports = ofputil_count_phy_ports(ofp_version, b);
427 ports = xmalloc(n_ports * sizeof *ports);
428 for (i = 0; i < n_ports; i++) {
429 error = ofputil_pull_phy_port(ofp_version, b, &ports[i]);
431 ofp_print_error(string, error);
435 qsort(ports, n_ports, sizeof *ports, compare_ports);
436 for (i = 0; i < n_ports; i++) {
437 ofp_print_phy_port(string, &ports[i]);
445 ofputil_capabilities_to_name(uint32_t bit)
447 enum ofputil_capabilities capabilities = bit;
449 switch (capabilities) {
450 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
451 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
452 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
453 case OFPUTIL_C_IP_REASM: return "IP_REASM";
454 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
455 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
456 case OFPUTIL_C_STP: return "STP";
457 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
458 case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED";
465 ofputil_action_bitmap_to_name(uint32_t bit)
467 enum ofputil_action_bitmap action = bit;
470 case OFPUTIL_A_OUTPUT: return "OUTPUT";
471 case OFPUTIL_A_SET_VLAN_VID: return "SET_VLAN_VID";
472 case OFPUTIL_A_SET_VLAN_PCP: return "SET_VLAN_PCP";
473 case OFPUTIL_A_STRIP_VLAN: return "STRIP_VLAN";
474 case OFPUTIL_A_SET_DL_SRC: return "SET_DL_SRC";
475 case OFPUTIL_A_SET_DL_DST: return "SET_DL_DST";
476 case OFPUTIL_A_SET_NW_SRC: return "SET_NW_SRC";
477 case OFPUTIL_A_SET_NW_DST: return "SET_NW_DST";
478 case OFPUTIL_A_SET_NW_ECN: return "SET_NW_ECN";
479 case OFPUTIL_A_SET_NW_TOS: return "SET_NW_TOS";
480 case OFPUTIL_A_SET_TP_SRC: return "SET_TP_SRC";
481 case OFPUTIL_A_SET_TP_DST: return "SET_TP_DST";
482 case OFPUTIL_A_SET_FIELD: return "SET_FIELD";
483 case OFPUTIL_A_ENQUEUE: return "ENQUEUE";
484 case OFPUTIL_A_COPY_TTL_OUT: return "COPY_TTL_OUT";
485 case OFPUTIL_A_COPY_TTL_IN: return "COPY_TTL_IN";
486 case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL";
487 case OFPUTIL_A_SET_MPLS_TC: return "SET_MPLS_TC";
488 case OFPUTIL_A_SET_MPLS_TTL: return "SET_MPLS_TTL";
489 case OFPUTIL_A_DEC_MPLS_TTL: return "DEC_MPLS_TTL";
490 case OFPUTIL_A_PUSH_VLAN: return "PUSH_VLAN";
491 case OFPUTIL_A_POP_VLAN: return "POP_VLAN";
492 case OFPUTIL_A_PUSH_MPLS: return "PUSH_MPLS";
493 case OFPUTIL_A_POP_MPLS: return "POP_MPLS";
494 case OFPUTIL_A_SET_QUEUE: return "SET_QUEUE";
495 case OFPUTIL_A_GROUP: return "GROUP";
496 case OFPUTIL_A_SET_NW_TTL: return "SET_NW_TTL";
497 case OFPUTIL_A_DEC_NW_TTL: return "DEC_NW_TTL";
504 ofp_print_switch_features(struct ds *string, const struct ofp_header *oh)
506 struct ofputil_switch_features features;
510 error = ofputil_decode_switch_features(oh, &features, &b);
512 ofp_print_error(string, error);
516 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
518 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32,
519 features.n_tables, features.n_buffers);
520 if (features.auxiliary_id) {
521 ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id);
523 ds_put_char(string, '\n');
525 ds_put_cstr(string, "capabilities: ");
526 ofp_print_bit_names(string, features.capabilities,
527 ofputil_capabilities_to_name, ' ');
528 ds_put_char(string, '\n');
530 switch ((enum ofp_version)oh->version) {
532 ds_put_cstr(string, "actions: ");
533 ofp_print_bit_names(string, features.actions,
534 ofputil_action_bitmap_to_name, ' ');
535 ds_put_char(string, '\n');
541 return; /* no ports in ofp13_switch_features */
546 ofp_print_phy_ports(string, oh->version, &b);
550 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
552 enum ofp_config_flags flags;
554 flags = ntohs(osc->flags);
556 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
557 flags &= ~OFPC_FRAG_MASK;
559 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
560 ds_put_format(string, " invalid_ttl_to_controller");
561 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
565 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
568 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
571 static void print_wild(struct ds *string, const char *leader, int is_wild,
572 int verbosity, const char *format, ...)
573 __attribute__((format(printf, 5, 6)));
575 static void print_wild(struct ds *string, const char *leader, int is_wild,
576 int verbosity, const char *format, ...)
578 if (is_wild && verbosity < 2) {
581 ds_put_cstr(string, leader);
585 va_start(args, format);
586 ds_put_format_valist(string, format, args);
589 ds_put_char(string, '*');
591 ds_put_char(string, ',');
595 print_wild_port(struct ds *string, const char *leader, int is_wild,
596 int verbosity, ofp_port_t port)
598 if (is_wild && verbosity < 2) {
601 ds_put_cstr(string, leader);
603 ofputil_format_port(port, string);
605 ds_put_char(string, '*');
607 ds_put_char(string, ',');
611 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
612 uint32_t wild_bits, int verbosity)
614 if (wild_bits >= 32 && verbosity < 2) {
617 ds_put_cstr(string, leader);
618 if (wild_bits < 32) {
619 ds_put_format(string, IP_FMT, IP_ARGS(ip));
621 ds_put_format(string, "/%d", 32 - wild_bits);
624 ds_put_char(string, '*');
626 ds_put_char(string, ',');
630 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
632 char *s = ofp10_match_to_string(om, verbosity);
638 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
640 struct ds f = DS_EMPTY_INITIALIZER;
641 uint32_t w = ntohl(om->wildcards);
642 bool skip_type = false;
643 bool skip_proto = false;
645 if (!(w & OFPFW10_DL_TYPE)) {
647 if (om->dl_type == htons(ETH_TYPE_IP)) {
648 if (!(w & OFPFW10_NW_PROTO)) {
650 if (om->nw_proto == IPPROTO_ICMP) {
651 ds_put_cstr(&f, "icmp,");
652 } else if (om->nw_proto == IPPROTO_TCP) {
653 ds_put_cstr(&f, "tcp,");
654 } else if (om->nw_proto == IPPROTO_UDP) {
655 ds_put_cstr(&f, "udp,");
656 } else if (om->nw_proto == IPPROTO_SCTP) {
657 ds_put_cstr(&f, "sctp,");
659 ds_put_cstr(&f, "ip,");
663 ds_put_cstr(&f, "ip,");
665 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
666 ds_put_cstr(&f, "arp,");
667 } else if (om->dl_type == htons(ETH_TYPE_RARP)){
668 ds_put_cstr(&f, "rarp,");
669 } else if (om->dl_type == htons(ETH_TYPE_MPLS)) {
670 ds_put_cstr(&f, "mpls,");
671 } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
672 ds_put_cstr(&f, "mplsm,");
677 print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
678 u16_to_ofp(ntohs(om->in_port)));
679 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
680 "%d", ntohs(om->dl_vlan));
681 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
682 "%d", om->dl_vlan_pcp);
683 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
684 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
685 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
686 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
688 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
689 "0x%04x", ntohs(om->dl_type));
691 print_ip_netmask(&f, "nw_src=", om->nw_src,
692 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
694 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
695 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
698 if (om->dl_type == htons(ETH_TYPE_ARP) ||
699 om->dl_type == htons(ETH_TYPE_RARP)) {
700 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
703 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
707 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
709 if (om->nw_proto == IPPROTO_ICMP) {
710 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
711 "%d", ntohs(om->tp_src));
712 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
713 "%d", ntohs(om->tp_dst));
715 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
716 "%d", ntohs(om->tp_src));
717 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
718 "%d", ntohs(om->tp_dst));
720 if (ds_last(&f) == ',') {
727 ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags)
729 if (flags & OFPUTIL_FF_SEND_FLOW_REM) {
730 ds_put_cstr(s, "send_flow_rem ");
732 if (flags & OFPUTIL_FF_CHECK_OVERLAP) {
733 ds_put_cstr(s, "check_overlap ");
735 if (flags & OFPUTIL_FF_RESET_COUNTS) {
736 ds_put_cstr(s, "reset_counts ");
738 if (flags & OFPUTIL_FF_NO_PKT_COUNTS) {
739 ds_put_cstr(s, "no_packet_counts ");
741 if (flags & OFPUTIL_FF_NO_BYT_COUNTS) {
742 ds_put_cstr(s, "no_byte_counts ");
747 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
749 struct ofputil_flow_mod fm;
750 struct ofpbuf ofpacts;
754 enum ofputil_protocol protocol;
756 protocol = ofputil_protocol_from_ofp_version(oh->version);
757 protocol = ofputil_protocol_set_tid(protocol, true);
759 ofpbuf_init(&ofpacts, 64);
760 error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts,
763 ofpbuf_uninit(&ofpacts);
764 ofp_print_error(s, error);
769 switch (fm.command) {
771 ds_put_cstr(s, "ADD");
774 ds_put_cstr(s, "MOD");
776 case OFPFC_MODIFY_STRICT:
777 ds_put_cstr(s, "MOD_STRICT");
780 ds_put_cstr(s, "DEL");
782 case OFPFC_DELETE_STRICT:
783 ds_put_cstr(s, "DEL_STRICT");
786 ds_put_format(s, "cmd:%d", fm.command);
788 if (fm.table_id != 0) {
789 ds_put_format(s, " table:%d", fm.table_id);
793 ofpraw_decode(&raw, oh);
794 if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) {
795 const struct ofp10_flow_mod *ofm = ofpmsg_body(oh);
796 ofp10_match_print(s, &ofm->match, verbosity);
798 /* ofp_print_match() doesn't print priority. */
799 need_priority = true;
800 } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) {
801 const struct nx_flow_mod *nfm = ofpmsg_body(oh);
802 const void *nxm = nfm + 1;
805 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
806 ds_put_cstr(s, nxm_s);
809 /* nx_match_to_string() doesn't print priority. */
810 need_priority = true;
812 match_format(&fm.match, s, fm.priority);
814 /* match_format() does print priority. */
815 need_priority = false;
818 if (ds_last(s) != ' ') {
821 if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
822 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
824 if (fm.cookie_mask != htonll(0)) {
825 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
826 ntohll(fm.cookie), ntohll(fm.cookie_mask));
828 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
829 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
831 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
832 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
834 if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) {
835 ds_put_format(s, "pri:%"PRIu16" ", fm.priority);
837 if (fm.buffer_id != UINT32_MAX) {
838 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
840 if (fm.out_port != OFPP_ANY) {
841 ds_put_format(s, "out_port:");
842 ofputil_format_port(fm.out_port, s);
846 if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) {
847 /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those
848 * versions don't really have such a flag and printing one is likely to
850 fm.flags &= ~OFPUTIL_FF_RESET_COUNTS;
852 ofp_print_flow_flags(s, fm.flags);
854 ds_put_cstr(s, "actions=");
855 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
856 ofpbuf_uninit(&ofpacts);
860 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
862 ds_put_format(string, "%u", sec);
864 /* If there are no fractional seconds, don't print any decimals.
866 * If the fractional seconds can be expressed exactly as milliseconds,
867 * print 3 decimals. Open vSwitch provides millisecond precision for most
868 * time measurements, so printing 3 decimals every time makes it easier to
869 * spot real changes in flow dumps that refresh themselves quickly.
871 * If the fractional seconds are more precise than milliseconds, print the
872 * number of decimals needed to express them exactly.
875 unsigned int msec = nsec / 1000000;
876 if (msec * 1000000 == nsec) {
877 ds_put_format(string, ".%03u", msec);
879 ds_put_format(string, ".%09u", nsec);
880 while (string->string[string->length - 1] == '0') {
885 ds_put_char(string, 's');
888 /* Returns a string form of 'reason'. The return value is either a statically
889 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
890 * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
891 #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
893 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
894 char *reasonbuf, size_t bufsize)
897 case OFPRR_IDLE_TIMEOUT:
899 case OFPRR_HARD_TIMEOUT:
903 case OFPRR_GROUP_DELETE:
904 return "group_delete";
907 case OFPRR_METER_DELETE:
908 return "meter_delete";
910 snprintf(reasonbuf, bufsize, "%d", (int) reason);
916 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
918 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
919 struct ofputil_flow_removed fr;
922 error = ofputil_decode_flow_removed(&fr, oh);
924 ofp_print_error(string, error);
928 ds_put_char(string, ' ');
929 match_format(&fr.match, string, fr.priority);
931 ds_put_format(string, " reason=%s",
932 ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
935 if (fr.table_id != 255) {
936 ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
939 if (fr.cookie != htonll(0)) {
940 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
942 ds_put_cstr(string, " duration");
943 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
944 ds_put_format(string, " idle%"PRIu16, fr.idle_timeout);
945 if (fr.hard_timeout) {
946 /* The hard timeout was only added in OF1.2, so only print it if it is
947 * actually in use to avoid gratuitous change to the formatting. */
948 ds_put_format(string, " hard%"PRIu16, fr.hard_timeout);
950 ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n",
951 fr.packet_count, fr.byte_count);
955 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
957 struct ofputil_port_mod pm;
960 error = ofputil_decode_port_mod(oh, &pm);
962 ofp_print_error(string, error);
966 ds_put_cstr(string, "port: ");
967 ofputil_format_port(pm.port_no, string);
968 ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n",
969 ETH_ADDR_ARGS(pm.hw_addr));
971 ds_put_cstr(string, " config: ");
972 ofp_print_port_config(string, pm.config);
974 ds_put_cstr(string, " mask: ");
975 ofp_print_port_config(string, pm.mask);
977 ds_put_cstr(string, " advertise: ");
979 ofp_print_port_features(string, pm.advertise);
981 ds_put_cstr(string, "UNCHANGED\n");
986 ofp_print_table_miss_config(struct ds *string, const uint32_t config)
988 uint32_t table_miss_config = config & OFPTC11_TABLE_MISS_MASK;
990 switch (table_miss_config) {
991 case OFPTC11_TABLE_MISS_CONTROLLER:
992 ds_put_cstr(string, "controller\n");
994 case OFPTC11_TABLE_MISS_CONTINUE:
995 ds_put_cstr(string, "continue\n");
997 case OFPTC11_TABLE_MISS_DROP:
998 ds_put_cstr(string, "drop\n");
1001 ds_put_cstr(string, "Unknown\n");
1007 ofp_print_table_mod(struct ds *string, const struct ofp_header *oh)
1009 struct ofputil_table_mod pm;
1012 error = ofputil_decode_table_mod(oh, &pm);
1014 ofp_print_error(string, error);
1018 if (pm.table_id == 0xff) {
1019 ds_put_cstr(string, " table_id: ALL_TABLES");
1021 ds_put_format(string, " table_id=%"PRIu8, pm.table_id);
1024 ds_put_cstr(string, ", flow_miss_config=");
1025 ofp_print_table_miss_config(string, pm.config);
1029 ofp_print_queue_get_config_request(struct ds *string,
1030 const struct ofp_header *oh)
1035 error = ofputil_decode_queue_get_config_request(oh, &port);
1037 ofp_print_error(string, error);
1041 ds_put_cstr(string, " port=");
1042 ofputil_format_port(port, string);
1046 print_queue_rate(struct ds *string, const char *name, unsigned int rate)
1049 ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10);
1050 } else if (rate < UINT16_MAX) {
1051 ds_put_format(string, " %s:(disabled)", name);
1056 ofp_print_queue_get_config_reply(struct ds *string,
1057 const struct ofp_header *oh)
1063 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1064 error = ofputil_decode_queue_get_config_reply(&b, &port);
1066 ofp_print_error(string, error);
1070 ds_put_cstr(string, " port=");
1071 ofputil_format_port(port, string);
1072 ds_put_char(string, '\n');
1075 struct ofputil_queue_config queue;
1078 retval = ofputil_pull_queue_get_config_reply(&b, &queue);
1080 if (retval != EOF) {
1081 ofp_print_error(string, retval);
1086 ds_put_format(string, "queue %"PRIu32":", queue.queue_id);
1087 print_queue_rate(string, "min_rate", queue.min_rate);
1088 print_queue_rate(string, "max_rate", queue.max_rate);
1089 ds_put_char(string, '\n');
1094 ofp_print_meter_flags(struct ds *s, uint16_t flags)
1096 if (flags & OFPMF13_KBPS) {
1097 ds_put_cstr(s, "kbps ");
1099 if (flags & OFPMF13_PKTPS) {
1100 ds_put_cstr(s, "pktps ");
1102 if (flags & OFPMF13_BURST) {
1103 ds_put_cstr(s, "burst ");
1105 if (flags & OFPMF13_STATS) {
1106 ds_put_cstr(s, "stats ");
1109 flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS);
1111 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
1116 ofp_print_meter_band(struct ds *s, uint16_t flags,
1117 const struct ofputil_meter_band *mb)
1119 ds_put_cstr(s, "\ntype=");
1122 ds_put_cstr(s, "drop");
1124 case OFPMBT13_DSCP_REMARK:
1125 ds_put_cstr(s, "dscp_remark");
1128 ds_put_format(s, "%u", mb->type);
1131 ds_put_format(s, " rate=%"PRIu32, mb->rate);
1133 if (flags & OFPMF13_BURST) {
1134 ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size);
1136 if (mb->type == OFPMBT13_DSCP_REMARK) {
1137 ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level);
1142 ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms)
1146 ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id);
1147 ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count);
1148 ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count);
1149 ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count);
1150 ds_put_cstr(s, "duration:");
1151 ofp_print_duration(s, ms->duration_sec, ms->duration_nsec);
1152 ds_put_char(s, ' ');
1154 ds_put_cstr(s, "bands:\n");
1155 for (i = 0; i < ms->n_bands; ++i) {
1156 ds_put_format(s, "%d: ", i);
1157 ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count);
1158 ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count);
1163 ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc)
1167 ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id);
1169 ofp_print_meter_flags(s, mc->flags);
1171 ds_put_cstr(s, "bands=");
1172 for (i = 0; i < mc->n_bands; ++i) {
1173 ofp_print_meter_band(s, mc->flags, &mc->bands[i]);
1175 ds_put_char(s, '\n');
1179 ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh)
1181 struct ofputil_meter_mod mm;
1182 struct ofpbuf bands;
1185 ofpbuf_init(&bands, 64);
1186 error = ofputil_decode_meter_mod(oh, &mm, &bands);
1188 ofpbuf_uninit(&bands);
1189 ofp_print_error(s, error);
1193 switch (mm.command) {
1195 ds_put_cstr(s, " ADD ");
1197 case OFPMC13_MODIFY:
1198 ds_put_cstr(s, " MOD ");
1200 case OFPMC13_DELETE:
1201 ds_put_cstr(s, " DEL ");
1204 ds_put_format(s, " cmd:%d ", mm.command);
1207 ofp_print_meter_config(s, &mm.meter);
1208 ofpbuf_uninit(&bands);
1212 ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh)
1216 ofputil_decode_meter_request(oh, &meter_id);
1218 ds_put_format(s, " meter=%"PRIu32, meter_id);
1222 ofputil_meter_capabilities_to_name(uint32_t bit)
1224 enum ofp13_meter_flags flag = bit;
1227 case OFPMF13_KBPS: return "kbps";
1228 case OFPMF13_PKTPS: return "pktps";
1229 case OFPMF13_BURST: return "burst";
1230 case OFPMF13_STATS: return "stats";
1237 ofputil_meter_band_types_to_name(uint32_t bit)
1240 case 1 << OFPMBT13_DROP: return "drop";
1241 case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark";
1248 ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh)
1250 struct ofputil_meter_features mf;
1252 ofputil_decode_meter_features(oh, &mf);
1254 ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters);
1255 ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands);
1256 ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color);
1258 ds_put_cstr(s, "band_types: ");
1259 ofp_print_bit_names(s, mf.band_types,
1260 ofputil_meter_band_types_to_name, ' ');
1261 ds_put_char(s, '\n');
1263 ds_put_cstr(s, "capabilities: ");
1264 ofp_print_bit_names(s, mf.capabilities,
1265 ofputil_meter_capabilities_to_name, ' ');
1266 ds_put_char(s, '\n');
1270 ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh)
1272 struct ofpbuf bands;
1275 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1276 ofpbuf_init(&bands, 64);
1278 struct ofputil_meter_config mc;
1281 retval = ofputil_decode_meter_config(&b, &mc, &bands);
1283 if (retval != EOF) {
1284 ofp_print_error(s, retval);
1288 ds_put_char(s, '\n');
1289 ofp_print_meter_config(s, &mc);
1291 ofpbuf_uninit(&bands);
1295 ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
1297 struct ofpbuf bands;
1300 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1301 ofpbuf_init(&bands, 64);
1303 struct ofputil_meter_stats ms;
1306 retval = ofputil_decode_meter_stats(&b, &ms, &bands);
1308 if (retval != EOF) {
1309 ofp_print_error(s, retval);
1313 ds_put_char(s, '\n');
1314 ofp_print_meter_stats(s, &ms);
1316 ofpbuf_uninit(&bands);
1320 ofp_print_error(struct ds *string, enum ofperr error)
1322 if (string->length) {
1323 ds_put_char(string, ' ');
1325 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1329 ofp_print_hello(struct ds *string, const struct ofp_header *oh)
1331 uint32_t allowed_versions;
1334 ok = ofputil_decode_hello(oh, &allowed_versions);
1336 ds_put_cstr(string, "\n version bitmap: ");
1337 ofputil_format_version_bitmap(string, allowed_versions);
1340 ds_put_cstr(string, "\n unknown data in hello:\n");
1341 ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
1346 ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
1348 size_t len = ntohs(oh->length);
1349 struct ofpbuf payload;
1353 error = ofperr_decode_msg(oh, &payload);
1355 ds_put_cstr(string, "***decode error***");
1356 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1360 ds_put_format(string, " %s\n", ofperr_get_name(error));
1362 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
1363 ds_put_printable(string, payload.data, payload.size);
1365 s = ofp_to_string(payload.data, payload.size, 1);
1366 ds_put_cstr(string, s);
1369 ofpbuf_uninit(&payload);
1373 ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
1375 struct ofputil_port_status ps;
1378 error = ofputil_decode_port_status(oh, &ps);
1380 ofp_print_error(string, error);
1384 if (ps.reason == OFPPR_ADD) {
1385 ds_put_format(string, " ADD:");
1386 } else if (ps.reason == OFPPR_DELETE) {
1387 ds_put_format(string, " DEL:");
1388 } else if (ps.reason == OFPPR_MODIFY) {
1389 ds_put_format(string, " MOD:");
1392 ofp_print_phy_port(string, &ps.desc);
1396 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
1398 const struct ofp_desc_stats *ods = ofpmsg_body(oh);
1400 ds_put_char(string, '\n');
1401 ds_put_format(string, "Manufacturer: %.*s\n",
1402 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1403 ds_put_format(string, "Hardware: %.*s\n",
1404 (int) sizeof ods->hw_desc, ods->hw_desc);
1405 ds_put_format(string, "Software: %.*s\n",
1406 (int) sizeof ods->sw_desc, ods->sw_desc);
1407 ds_put_format(string, "Serial Num: %.*s\n",
1408 (int) sizeof ods->serial_num, ods->serial_num);
1409 ds_put_format(string, "DP Description: %.*s\n",
1410 (int) sizeof ods->dp_desc, ods->dp_desc);
1414 ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
1416 struct ofputil_flow_stats_request fsr;
1419 error = ofputil_decode_flow_stats_request(&fsr, oh);
1421 ofp_print_error(string, error);
1425 if (fsr.table_id != 0xff) {
1426 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1429 if (fsr.out_port != OFPP_ANY) {
1430 ds_put_cstr(string, " out_port=");
1431 ofputil_format_port(fsr.out_port, string);
1434 ds_put_char(string, ' ');
1435 match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
1439 ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
1441 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1442 ntohll(fs->cookie));
1444 ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
1445 ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
1446 ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
1447 ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
1448 if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
1449 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
1451 if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
1452 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
1455 ofp_print_flow_flags(string, fs->flags);
1457 if (fs->idle_age >= 0) {
1458 ds_put_format(string, "idle_age=%d, ", fs->idle_age);
1460 if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
1461 ds_put_format(string, "hard_age=%d, ", fs->hard_age);
1464 match_format(&fs->match, string, fs->priority);
1465 if (string->string[string->length - 1] != ' ') {
1466 ds_put_char(string, ' ');
1469 ds_put_cstr(string, "actions=");
1470 ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
1474 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1476 struct ofpbuf ofpacts;
1479 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1480 ofpbuf_init(&ofpacts, 64);
1482 struct ofputil_flow_stats fs;
1485 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
1487 if (retval != EOF) {
1488 ds_put_cstr(string, " ***parse error***");
1492 ds_put_char(string, '\n');
1493 ofp_print_flow_stats(string, &fs);
1495 ofpbuf_uninit(&ofpacts);
1499 ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
1501 struct ofputil_aggregate_stats as;
1504 error = ofputil_decode_aggregate_stats_reply(&as, oh);
1506 ofp_print_error(string, error);
1510 ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
1511 ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
1512 ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
1516 print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
1518 ds_put_cstr(string, leader);
1519 if (stat != UINT64_MAX) {
1520 ds_put_format(string, "%"PRIu64, stat);
1522 ds_put_char(string, '?');
1525 ds_put_cstr(string, ", ");
1527 ds_put_cstr(string, "\n");
1532 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
1534 ofp_port_t ofp10_port;
1537 error = ofputil_decode_port_stats_request(oh, &ofp10_port);
1539 ofp_print_error(string, error);
1543 ds_put_cstr(string, " port_no=");
1544 ofputil_format_port(ofp10_port, string);
1548 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1553 ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
1554 if (verbosity < 1) {
1558 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1560 struct ofputil_port_stats ps;
1563 retval = ofputil_decode_port_stats(&ps, &b);
1565 if (retval != EOF) {
1566 ds_put_cstr(string, " ***parse error***");
1571 ds_put_cstr(string, " port ");
1572 if (ofp_to_u16(ps.port_no) < 10) {
1573 ds_put_char(string, ' ');
1575 ofputil_format_port(ps.port_no, string);
1577 ds_put_cstr(string, ": rx ");
1578 print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
1579 print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
1580 print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
1581 print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
1582 print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
1583 print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
1584 print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
1586 ds_put_cstr(string, " tx ");
1587 print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
1588 print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
1589 print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
1590 print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
1591 print_port_stat(string, "coll=", ps.stats.collisions, 0);
1593 if (ps.duration_sec != UINT32_MAX) {
1594 ds_put_cstr(string, " duration=");
1595 ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
1596 ds_put_char(string, '\n');
1602 ofp_print_one_ofpst_table_reply(struct ds *string, enum ofp_version ofp_version,
1603 const char *name, struct ofp12_table_stats *ts)
1605 char name_[OFP_MAX_TABLE_NAME_LEN + 1];
1607 /* ofp13_table_stats is different */
1608 if (ofp_version > OFP12_VERSION) {
1612 ovs_strlcpy(name_, name, sizeof name_);
1614 ds_put_format(string, " %d: %-8s: ", ts->table_id, name_);
1615 ds_put_format(string, "wild=0x%05"PRIx64", ", ntohll(ts->wildcards));
1616 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1617 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1618 ds_put_cstr(string, " ");
1619 ds_put_format(string, "lookup=%"PRIu64", ", ntohll(ts->lookup_count));
1620 ds_put_format(string, "matched=%"PRIu64"\n", ntohll(ts->matched_count));
1622 if (ofp_version < OFP11_VERSION) {
1626 ds_put_cstr(string, " ");
1627 ds_put_format(string, "match=0x%08"PRIx64", ", ntohll(ts->match));
1628 ds_put_format(string, "instructions=0x%08"PRIx32", ",
1629 ntohl(ts->instructions));
1630 ds_put_format(string, "config=0x%08"PRIx32"\n", ntohl(ts->config));
1631 ds_put_cstr(string, " ");
1632 ds_put_format(string, "write_actions=0x%08"PRIx32", ",
1633 ntohl(ts->write_actions));
1634 ds_put_format(string, "apply_actions=0x%08"PRIx32"\n",
1635 ntohl(ts->apply_actions));
1637 if (ofp_version < OFP12_VERSION) {
1641 ds_put_cstr(string, " ");
1642 ds_put_format(string, "write_setfields=0x%016"PRIx64"\n",
1643 ntohll(ts->write_setfields));
1644 ds_put_cstr(string, " ");
1645 ds_put_format(string, "apply_setfields=0x%016"PRIx64"\n",
1646 ntohll(ts->apply_setfields));
1647 ds_put_cstr(string, " ");
1648 ds_put_format(string, "metadata_match=0x%016"PRIx64"\n",
1649 ntohll(ts->metadata_match));
1650 ds_put_cstr(string, " ");
1651 ds_put_format(string, "metadata_write=0x%016"PRIx64"\n",
1652 ntohll(ts->metadata_write));
1656 ofp_print_ofpst_table_reply13(struct ds *string, const struct ofp_header *oh,
1659 struct ofp13_table_stats *ts;
1663 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1664 ofpraw_pull_assert(&b);
1666 n = b.size / sizeof *ts;
1667 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1668 if (verbosity < 1) {
1673 ts = ofpbuf_try_pull(&b, sizeof *ts);
1677 ds_put_format(string,
1678 " %d: active=%"PRIu32", lookup=%"PRIu64 \
1679 ", matched=%"PRIu64"\n",
1680 ts->table_id, ntohl(ts->active_count),
1681 ntohll(ts->lookup_count), ntohll(ts->matched_count));
1686 ofp_print_ofpst_table_reply12(struct ds *string, const struct ofp_header *oh,
1689 struct ofp12_table_stats *ts;
1693 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1694 ofpraw_pull_assert(&b);
1696 n = b.size / sizeof *ts;
1697 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1698 if (verbosity < 1) {
1703 ts = ofpbuf_try_pull(&b, sizeof *ts);
1708 ofp_print_one_ofpst_table_reply(string, OFP12_VERSION, ts->name, ts);
1713 ofp_print_ofpst_table_reply11(struct ds *string, const struct ofp_header *oh,
1716 struct ofp11_table_stats *ts;
1720 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1721 ofpraw_pull_assert(&b);
1723 n = b.size / sizeof *ts;
1724 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1725 if (verbosity < 1) {
1730 struct ofp12_table_stats ts12;
1732 ts = ofpbuf_try_pull(&b, sizeof *ts);
1737 ts12.table_id = ts->table_id;
1738 ts12.wildcards = htonll(ntohl(ts->wildcards));
1739 ts12.max_entries = ts->max_entries;
1740 ts12.active_count = ts->active_count;
1741 ts12.lookup_count = ts->lookup_count;
1742 ts12.matched_count = ts->matched_count;
1743 ts12.match = htonll(ntohl(ts->match));
1744 ts12.instructions = ts->instructions;
1745 ts12.config = ts->config;
1746 ts12.write_actions = ts->write_actions;
1747 ts12.apply_actions = ts->apply_actions;
1748 ofp_print_one_ofpst_table_reply(string, OFP11_VERSION, ts->name, &ts12);
1753 ofp_print_ofpst_table_reply10(struct ds *string, const struct ofp_header *oh,
1756 struct ofp10_table_stats *ts;
1760 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1761 ofpraw_pull_assert(&b);
1763 n = b.size / sizeof *ts;
1764 ds_put_format(string, " %"PRIuSIZE" tables\n", n);
1765 if (verbosity < 1) {
1770 struct ofp12_table_stats ts12;
1772 ts = ofpbuf_try_pull(&b, sizeof *ts);
1777 ts12.table_id = ts->table_id;
1778 ts12.wildcards = htonll(ntohl(ts->wildcards));
1779 ts12.max_entries = ts->max_entries;
1780 ts12.active_count = ts->active_count;
1781 ts12.lookup_count = get_32aligned_be64(&ts->lookup_count);
1782 ts12.matched_count = get_32aligned_be64(&ts->matched_count);
1783 ofp_print_one_ofpst_table_reply(string, OFP10_VERSION, ts->name, &ts12);
1788 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1791 switch ((enum ofp_version)oh->version) {
1793 ofp_print_ofpst_table_reply13(string, oh, verbosity);
1797 ofp_print_ofpst_table_reply12(string, oh, verbosity);
1801 ofp_print_ofpst_table_reply11(string, oh, verbosity);
1805 ofp_print_ofpst_table_reply10(string, oh, verbosity);
1814 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1816 if (queue_id == OFPQ_ALL) {
1817 ds_put_cstr(string, "ALL");
1819 ds_put_format(string, "%"PRIu32, queue_id);
1824 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1826 struct ofputil_queue_stats_request oqsr;
1829 error = ofputil_decode_queue_stats_request(oh, &oqsr);
1831 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
1835 ds_put_cstr(string, "port=");
1836 ofputil_format_port(oqsr.port_no, string);
1838 ds_put_cstr(string, " queue=");
1839 ofp_print_queue_name(string, oqsr.queue_id);
1843 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1848 ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
1849 if (verbosity < 1) {
1853 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1855 struct ofputil_queue_stats qs;
1858 retval = ofputil_decode_queue_stats(&qs, &b);
1860 if (retval != EOF) {
1861 ds_put_cstr(string, " ***parse error***");
1866 ds_put_cstr(string, " port ");
1867 ofputil_format_port(qs.port_no, string);
1868 ds_put_cstr(string, " queue ");
1869 ofp_print_queue_name(string, qs.queue_id);
1870 ds_put_cstr(string, ": ");
1872 print_port_stat(string, "bytes=", qs.tx_bytes, 1);
1873 print_port_stat(string, "pkts=", qs.tx_packets, 1);
1874 print_port_stat(string, "errors=", qs.tx_errors, 1);
1876 ds_put_cstr(string, "duration=");
1877 if (qs.duration_sec != UINT32_MAX) {
1878 ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
1880 ds_put_char(string, '?');
1882 ds_put_char(string, '\n');
1887 ofp_print_ofpst_port_desc_reply(struct ds *string,
1888 const struct ofp_header *oh)
1892 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1893 ofpraw_pull_assert(&b);
1894 ds_put_char(string, '\n');
1895 ofp_print_phy_ports(string, oh->version, &b);
1899 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1901 uint16_t flags = ofpmp_flags(oh);
1904 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
1909 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1911 uint16_t flags = ofpmp_flags(oh);
1914 ds_put_cstr(string, " flags=");
1915 if (flags & OFPSF_REPLY_MORE) {
1916 ds_put_cstr(string, "[more]");
1917 flags &= ~OFPSF_REPLY_MORE;
1920 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1927 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1929 size_t len = ntohs(oh->length);
1931 ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
1932 if (verbosity > 1) {
1933 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1938 ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
1939 uint64_t generation_id)
1941 ds_put_cstr(string, " role=");
1944 case OFPCR12_ROLE_NOCHANGE:
1945 ds_put_cstr(string, "nochange");
1947 case OFPCR12_ROLE_EQUAL:
1948 ds_put_cstr(string, "equal"); /* OF 1.2 wording */
1950 case OFPCR12_ROLE_MASTER:
1951 ds_put_cstr(string, "master");
1953 case OFPCR12_ROLE_SLAVE:
1954 ds_put_cstr(string, "slave");
1960 if (generation_id != UINT64_MAX) {
1961 ds_put_format(string, " generation_id=%"PRIu64, generation_id);
1966 ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
1968 struct ofputil_role_request rr;
1971 error = ofputil_decode_role_message(oh, &rr);
1973 ofp_print_error(string, error);
1977 ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
1981 ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
1983 struct ofputil_role_status rs;
1986 error = ofputil_decode_role_status(oh, &rs);
1988 ofp_print_error(string, error);
1992 ofp_print_role_generic(string, rs.role, rs.generation_id);
1994 ds_put_cstr(string, " reason=");
1996 switch (rs.reason) {
1997 case OFPCRR_MASTER_REQUEST:
1998 ds_put_cstr(string, "master_request");
2001 ds_put_cstr(string, "configuration_changed");
2003 case OFPCRR_EXPERIMENTER:
2004 ds_put_cstr(string, "experimenter_data_changed");
2012 ofp_print_nxt_flow_mod_table_id(struct ds *string,
2013 const struct nx_flow_mod_table_id *nfmti)
2015 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
2019 ofp_print_nxt_set_flow_format(struct ds *string,
2020 const struct nx_set_flow_format *nsff)
2022 uint32_t format = ntohl(nsff->format);
2024 ds_put_cstr(string, " format=");
2025 if (ofputil_nx_flow_format_is_valid(format)) {
2026 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
2028 ds_put_format(string, "%"PRIu32, format);
2033 ofp_print_nxt_set_packet_in_format(struct ds *string,
2034 const struct nx_set_packet_in_format *nspf)
2036 uint32_t format = ntohl(nspf->format);
2038 ds_put_cstr(string, " format=");
2039 if (ofputil_packet_in_format_is_valid(format)) {
2040 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
2042 ds_put_format(string, "%"PRIu32, format);
2046 /* Returns a string form of 'reason'. The return value is either a statically
2047 * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
2048 * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
2049 #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
2051 ofp_port_reason_to_string(enum ofp_port_reason reason,
2052 char *reasonbuf, size_t bufsize)
2065 snprintf(reasonbuf, bufsize, "%d", (int) reason);
2071 ofp_print_nxt_set_async_config(struct ds *string,
2072 const struct nx_async_config *nac)
2076 for (i = 0; i < 2; i++) {
2079 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
2081 ds_put_cstr(string, " PACKET_IN:");
2082 for (j = 0; j < 32; j++) {
2083 if (nac->packet_in_mask[i] & htonl(1u << j)) {
2084 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2087 reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
2089 ds_put_format(string, " %s", reason);
2092 if (!nac->packet_in_mask[i]) {
2093 ds_put_cstr(string, " (off)");
2095 ds_put_char(string, '\n');
2097 ds_put_cstr(string, " PORT_STATUS:");
2098 for (j = 0; j < 32; j++) {
2099 if (nac->port_status_mask[i] & htonl(1u << j)) {
2100 char reasonbuf[OFP_PORT_REASON_BUFSIZE];
2103 reason = ofp_port_reason_to_string(j, reasonbuf,
2105 ds_put_format(string, " %s", reason);
2108 if (!nac->port_status_mask[i]) {
2109 ds_put_cstr(string, " (off)");
2111 ds_put_char(string, '\n');
2113 ds_put_cstr(string, " FLOW_REMOVED:");
2114 for (j = 0; j < 32; j++) {
2115 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
2116 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2119 reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
2121 ds_put_format(string, " %s", reason);
2124 if (!nac->flow_removed_mask[i]) {
2125 ds_put_cstr(string, " (off)");
2127 ds_put_char(string, '\n');
2132 ofp_print_nxt_set_controller_id(struct ds *string,
2133 const struct nx_controller_id *nci)
2135 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
2139 ofp_print_nxt_flow_monitor_cancel(struct ds *string,
2140 const struct ofp_header *oh)
2142 ds_put_format(string, " id=%"PRIu32,
2143 ofputil_decode_flow_monitor_cancel(oh));
2147 nx_flow_monitor_flags_to_name(uint32_t bit)
2149 enum nx_flow_monitor_flags fmf = bit;
2152 case NXFMF_INITIAL: return "initial";
2153 case NXFMF_ADD: return "add";
2154 case NXFMF_DELETE: return "delete";
2155 case NXFMF_MODIFY: return "modify";
2156 case NXFMF_ACTIONS: return "actions";
2157 case NXFMF_OWN: return "own";
2164 ofp_print_nxst_flow_monitor_request(struct ds *string,
2165 const struct ofp_header *oh)
2169 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2171 struct ofputil_flow_monitor_request request;
2174 retval = ofputil_decode_flow_monitor_request(&request, &b);
2176 if (retval != EOF) {
2177 ofp_print_error(string, retval);
2182 ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
2183 ofp_print_bit_names(string, request.flags,
2184 nx_flow_monitor_flags_to_name, ',');
2186 if (request.out_port != OFPP_NONE) {
2187 ds_put_cstr(string, " out_port=");
2188 ofputil_format_port(request.out_port, string);
2191 if (request.table_id != 0xff) {
2192 ds_put_format(string, " table=%"PRIu8, request.table_id);
2195 ds_put_char(string, ' ');
2196 match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
2197 ds_chomp(string, ' ');
2202 ofp_print_nxst_flow_monitor_reply(struct ds *string,
2203 const struct ofp_header *oh)
2205 uint64_t ofpacts_stub[1024 / 8];
2206 struct ofpbuf ofpacts;
2209 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2210 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2212 char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
2213 struct ofputil_flow_update update;
2217 update.match = &match;
2218 retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
2220 if (retval != EOF) {
2221 ofp_print_error(string, retval);
2223 ofpbuf_uninit(&ofpacts);
2227 ds_put_cstr(string, "\n event=");
2228 switch (update.event) {
2230 ds_put_cstr(string, "ADDED");
2234 ds_put_format(string, "DELETED reason=%s",
2235 ofp_flow_removed_reason_to_string(update.reason,
2240 case NXFME_MODIFIED:
2241 ds_put_cstr(string, "MODIFIED");
2245 ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
2249 ds_put_format(string, " table=%"PRIu8, update.table_id);
2250 if (update.idle_timeout != OFP_FLOW_PERMANENT) {
2251 ds_put_format(string, " idle_timeout=%"PRIu16,
2252 update.idle_timeout);
2254 if (update.hard_timeout != OFP_FLOW_PERMANENT) {
2255 ds_put_format(string, " hard_timeout=%"PRIu16,
2256 update.hard_timeout);
2258 ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
2260 ds_put_char(string, ' ');
2261 match_format(update.match, string, OFP_DEFAULT_PRIORITY);
2263 if (update.ofpacts_len) {
2264 if (string->string[string->length - 1] != ' ') {
2265 ds_put_char(string, ' ');
2267 ds_put_cstr(string, "actions=");
2268 ofpacts_format(update.ofpacts, update.ofpacts_len, string);
2274 ofp_print_version(const struct ofp_header *oh,
2277 switch (oh->version) {
2281 ds_put_cstr(string, " (OF1.1)");
2284 ds_put_cstr(string, " (OF1.2)");
2287 ds_put_cstr(string, " (OF1.3)");
2290 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
2293 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
2297 ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2300 ds_put_cstr(string, ofpraw_get_name(raw));
2301 ofp_print_version(oh, string);
2305 ofp_print_not_implemented(struct ds *string)
2307 ds_put_cstr(string, "NOT IMPLEMENTED YET!\n");
2311 ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
2312 struct list *p_buckets)
2314 static const char *type_str[] = { "all", "select", "indirect",
2316 struct ofputil_bucket *bucket;
2318 ds_put_format(s, "group_id=%"PRIu32",type=%s",
2319 group_id, type_str[type > 4 ? 4 : type]);
2324 LIST_FOR_EACH (bucket, list_node, p_buckets) {
2325 ds_put_cstr(s, ",bucket=");
2327 if (bucket->weight != 1) {
2328 ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
2330 if (bucket->watch_port != OFPP_NONE) {
2331 ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
2333 if (bucket->watch_group != OFPG11_ANY) {
2334 ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
2337 ds_put_cstr(s, "actions=");
2338 ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
2343 ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
2347 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2349 struct ofputil_group_desc gd;
2352 retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
2354 if (retval != EOF) {
2355 ds_put_cstr(s, " ***parse error***");
2360 ds_put_char(s, '\n');
2361 ds_put_char(s, ' ');
2362 ofp_print_group(s, gd.group_id, gd.type, &gd.buckets);
2367 ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
2372 error = ofputil_decode_group_stats_request(oh, &group_id);
2374 ofp_print_error(string, error);
2378 ds_put_cstr(string, " group_id=");
2379 ofputil_format_group(group_id, string);
2383 ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
2388 ofpbuf_use_const(&b, oh, ntohs(oh->length));
2391 struct ofputil_group_stats gs;
2394 retval = ofputil_decode_group_stats_reply(&b, &gs);
2396 if (retval != EOF) {
2397 ds_put_cstr(s, " ***parse error***");
2402 ds_put_char(s, '\n');
2404 ds_put_char(s, ' ');
2405 ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
2407 if (gs.duration_sec != UINT32_MAX) {
2408 ds_put_cstr(s, "duration=");
2409 ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
2410 ds_put_char(s, ',');
2412 ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
2413 ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
2414 ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
2416 for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
2417 if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
2418 ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
2419 ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
2420 ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
2424 free(gs.bucket_stats);
2429 ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
2431 struct ofputil_group_features features;
2433 ofputil_decode_group_features_reply(oh, &features);
2435 ds_put_format(string, "\n Group table:\n");
2436 ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
2437 ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
2438 features.capabilities);
2440 if (features.types & (1u << OFPGT11_ALL)) {
2441 ds_put_format(string, " All group :\n");
2442 ds_put_format(string,
2443 " max_groups = %#"PRIx32" actions=0x%08"PRIx32"\n",
2444 features.max_groups[0], features.actions[0]);
2447 if (features.types & (1u << OFPGT11_SELECT)) {
2448 ds_put_format(string, " Select group :\n");
2449 ds_put_format(string, " max_groups = %#"PRIx32" "
2450 "actions=0x%08"PRIx32"\n",
2451 features.max_groups[1], features.actions[1]);
2454 if (features.types & (1u << OFPGT11_INDIRECT)) {
2455 ds_put_format(string, " Indirect group :\n");
2456 ds_put_format(string, " max_groups = %#"PRIx32" "
2457 "actions=0x%08"PRIx32"\n",
2458 features.max_groups[2], features.actions[2]);
2461 if (features.types & (1u << OFPGT11_FF)) {
2462 ds_put_format(string, " Fast Failover group :\n");
2463 ds_put_format(string, " max_groups = %#"PRIx32" "
2464 "actions=0x%08"PRIx32"\n",
2465 features.max_groups[3], features.actions[3]);
2470 ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
2472 struct ofputil_group_mod gm;
2475 error = ofputil_decode_group_mod(oh, &gm);
2477 ofp_print_error(s, error);
2481 ds_put_char(s, '\n');
2483 ds_put_char(s, ' ');
2484 switch (gm.command) {
2486 ds_put_cstr(s, "ADD");
2489 case OFPGC11_MODIFY:
2490 ds_put_cstr(s, "MOD");
2493 case OFPGC11_DELETE:
2494 ds_put_cstr(s, "DEL");
2498 ds_put_format(s, "cmd:%"PRIu16"", gm.command);
2500 ds_put_char(s, ' ');
2502 ofp_print_group(s, gm.group_id, gm.type, &gm.buckets);
2506 ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
2507 struct ds *string, int verbosity)
2509 const void *msg = oh;
2511 ofp_header_to_string__(oh, raw, string);
2512 switch (ofptype_from_ofpraw(raw)) {
2514 case OFPTYPE_GROUP_STATS_REQUEST:
2515 ofp_print_stats_request(string, oh);
2516 ofp_print_ofpst_group_request(string, oh);
2519 case OFPTYPE_GROUP_STATS_REPLY:
2520 ofp_print_group_stats(string, oh);
2523 case OFPTYPE_GROUP_DESC_STATS_REQUEST:
2524 ofp_print_stats_request(string, oh);
2527 case OFPTYPE_GROUP_DESC_STATS_REPLY:
2528 ofp_print_group_desc(string, oh);
2531 case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
2532 ofp_print_stats_request(string, oh);
2535 case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
2536 ofp_print_group_features(string, oh);
2539 case OFPTYPE_GROUP_MOD:
2540 ofp_print_group_mod(string, oh);
2543 case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
2544 case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
2545 ofp_print_not_implemented(string);
2549 ofp_print_hello(string, oh);
2553 ofp_print_error_msg(string, oh);
2556 case OFPTYPE_ECHO_REQUEST:
2557 case OFPTYPE_ECHO_REPLY:
2558 ofp_print_echo(string, oh, verbosity);
2561 case OFPTYPE_FEATURES_REQUEST:
2564 case OFPTYPE_FEATURES_REPLY:
2565 ofp_print_switch_features(string, oh);
2568 case OFPTYPE_GET_CONFIG_REQUEST:
2571 case OFPTYPE_GET_CONFIG_REPLY:
2572 case OFPTYPE_SET_CONFIG:
2573 ofp_print_switch_config(string, ofpmsg_body(oh));
2576 case OFPTYPE_PACKET_IN:
2577 ofp_print_packet_in(string, oh, verbosity);
2580 case OFPTYPE_FLOW_REMOVED:
2581 ofp_print_flow_removed(string, oh);
2584 case OFPTYPE_PORT_STATUS:
2585 ofp_print_port_status(string, oh);
2588 case OFPTYPE_PACKET_OUT:
2589 ofp_print_packet_out(string, oh, verbosity);
2592 case OFPTYPE_FLOW_MOD:
2593 ofp_print_flow_mod(string, oh, verbosity);
2596 case OFPTYPE_PORT_MOD:
2597 ofp_print_port_mod(string, oh);
2600 case OFPTYPE_TABLE_MOD:
2601 ofp_print_table_mod(string, oh);
2604 case OFPTYPE_METER_MOD:
2605 ofp_print_meter_mod(string, oh);
2608 case OFPTYPE_BARRIER_REQUEST:
2609 case OFPTYPE_BARRIER_REPLY:
2612 case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
2613 ofp_print_queue_get_config_request(string, oh);
2616 case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
2617 ofp_print_queue_get_config_reply(string, oh);
2620 case OFPTYPE_ROLE_REQUEST:
2621 case OFPTYPE_ROLE_REPLY:
2622 ofp_print_role_message(string, oh);
2624 case OFPTYPE_ROLE_STATUS:
2625 ofp_print_role_status_message(string, oh);
2628 case OFPTYPE_METER_STATS_REQUEST:
2629 case OFPTYPE_METER_CONFIG_STATS_REQUEST:
2630 ofp_print_stats_request(string, oh);
2631 ofp_print_meter_stats_request(string, oh);
2634 case OFPTYPE_METER_STATS_REPLY:
2635 ofp_print_stats_reply(string, oh);
2636 ofp_print_meter_stats_reply(string, oh);
2639 case OFPTYPE_METER_CONFIG_STATS_REPLY:
2640 ofp_print_stats_reply(string, oh);
2641 ofp_print_meter_config_reply(string, oh);
2644 case OFPTYPE_METER_FEATURES_STATS_REPLY:
2645 ofp_print_stats_reply(string, oh);
2646 ofp_print_meter_features_reply(string, oh);
2649 case OFPTYPE_DESC_STATS_REQUEST:
2650 case OFPTYPE_PORT_DESC_STATS_REQUEST:
2651 case OFPTYPE_METER_FEATURES_STATS_REQUEST:
2652 ofp_print_stats_request(string, oh);
2655 case OFPTYPE_FLOW_STATS_REQUEST:
2656 case OFPTYPE_AGGREGATE_STATS_REQUEST:
2657 ofp_print_stats_request(string, oh);
2658 ofp_print_flow_stats_request(string, oh);
2661 case OFPTYPE_TABLE_STATS_REQUEST:
2662 ofp_print_stats_request(string, oh);
2665 case OFPTYPE_PORT_STATS_REQUEST:
2666 ofp_print_stats_request(string, oh);
2667 ofp_print_ofpst_port_request(string, oh);
2670 case OFPTYPE_QUEUE_STATS_REQUEST:
2671 ofp_print_stats_request(string, oh);
2672 ofp_print_ofpst_queue_request(string, oh);
2675 case OFPTYPE_DESC_STATS_REPLY:
2676 ofp_print_stats_reply(string, oh);
2677 ofp_print_ofpst_desc_reply(string, oh);
2680 case OFPTYPE_FLOW_STATS_REPLY:
2681 ofp_print_stats_reply(string, oh);
2682 ofp_print_flow_stats_reply(string, oh);
2685 case OFPTYPE_QUEUE_STATS_REPLY:
2686 ofp_print_stats_reply(string, oh);
2687 ofp_print_ofpst_queue_reply(string, oh, verbosity);
2690 case OFPTYPE_PORT_STATS_REPLY:
2691 ofp_print_stats_reply(string, oh);
2692 ofp_print_ofpst_port_reply(string, oh, verbosity);
2695 case OFPTYPE_TABLE_STATS_REPLY:
2696 ofp_print_stats_reply(string, oh);
2697 ofp_print_ofpst_table_reply(string, oh, verbosity);
2700 case OFPTYPE_AGGREGATE_STATS_REPLY:
2701 ofp_print_stats_reply(string, oh);
2702 ofp_print_aggregate_stats_reply(string, oh);
2705 case OFPTYPE_PORT_DESC_STATS_REPLY:
2706 ofp_print_stats_reply(string, oh);
2707 ofp_print_ofpst_port_desc_reply(string, oh);
2710 case OFPTYPE_FLOW_MOD_TABLE_ID:
2711 ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
2714 case OFPTYPE_SET_FLOW_FORMAT:
2715 ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
2718 case OFPTYPE_SET_PACKET_IN_FORMAT:
2719 ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
2722 case OFPTYPE_FLOW_AGE:
2725 case OFPTYPE_SET_CONTROLLER_ID:
2726 ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
2729 case OFPTYPE_GET_ASYNC_REPLY:
2730 case OFPTYPE_SET_ASYNC_CONFIG:
2731 ofp_print_nxt_set_async_config(string, ofpmsg_body(oh));
2733 case OFPTYPE_GET_ASYNC_REQUEST:
2735 case OFPTYPE_FLOW_MONITOR_CANCEL:
2736 ofp_print_nxt_flow_monitor_cancel(string, msg);
2739 case OFPTYPE_FLOW_MONITOR_PAUSED:
2740 case OFPTYPE_FLOW_MONITOR_RESUMED:
2743 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
2744 ofp_print_nxst_flow_monitor_request(string, msg);
2747 case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
2748 ofp_print_nxst_flow_monitor_reply(string, msg);
2753 /* Composes and returns a string representing the OpenFlow packet of 'len'
2754 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
2755 * verbosity and higher numbers increase verbosity. The caller is responsible
2756 * for freeing the string. */
2758 ofp_to_string(const void *oh_, size_t len, int verbosity)
2760 struct ds string = DS_EMPTY_INITIALIZER;
2761 const struct ofp_header *oh = oh_;
2764 ds_put_cstr(&string, "OpenFlow message is empty\n");
2765 } else if (len < sizeof(struct ofp_header)) {
2766 ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
2768 } else if (ntohs(oh->length) > len) {
2772 error = ofpraw_decode_partial(&raw, oh, len);
2774 ofp_header_to_string__(oh, raw, &string);
2775 ds_put_char(&string, '\n');
2778 ds_put_format(&string,
2779 "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
2780 len, ntohs(oh->length));
2781 } else if (ntohs(oh->length) < len) {
2782 ds_put_format(&string,
2783 "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
2784 ntohs(oh->length), len);
2789 error = ofpraw_decode(&raw, oh);
2791 ofp_to_string__(oh, raw, &string, verbosity);
2792 if (verbosity >= 5) {
2793 if (ds_last(&string) != '\n') {
2794 ds_put_char(&string, '\n');
2796 ds_put_hex_dump(&string, oh, len, 0, true);
2798 if (ds_last(&string) != '\n') {
2799 ds_put_char(&string, '\n');
2801 return ds_steal_cstr(&string);
2804 ofp_print_error(&string, error);
2806 ds_put_hex_dump(&string, oh, len, 0, true);
2807 return ds_steal_cstr(&string);
2811 print_and_free(FILE *stream, char *string)
2813 fputs(string, stream);
2817 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
2818 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
2819 * numbers increase verbosity. */
2821 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
2823 print_and_free(stream, ofp_to_string(oh, len, verbosity));
2826 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
2827 * 'data' to 'stream'. */
2829 ofp_print_packet(FILE *stream, const void *data, size_t len)
2831 print_and_free(stream, ofp_packet_to_string(data, len));