2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 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"
43 #include "openflow/openflow.h"
44 #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, 0, &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,
80 ds_put_char(&ds, '\n');
86 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
89 struct ofputil_packet_in pin;
93 error = ofputil_decode_packet_in(&pin, oh);
95 ofp_print_error(string, error);
100 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
104 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
107 ds_put_format(string, " total_len=%"PRIu16" in_port=", pin.total_len);
108 ofputil_format_port(pin.fmd.in_port, string);
110 if (pin.fmd.tun_id_mask) {
111 ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
112 if (pin.fmd.tun_id_mask != htonll(UINT64_MAX)) {
113 ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.tun_id_mask));
117 if (pin.fmd.metadata_mask) {
118 ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata));
119 if (pin.fmd.metadata_mask != htonll(UINT64_MAX)) {
120 ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.metadata_mask));
124 for (i = 0; i < FLOW_N_REGS; i++) {
125 if (pin.fmd.reg_masks[i]) {
126 ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
127 if (pin.fmd.reg_masks[i] != UINT32_MAX) {
128 ds_put_format(string, "/0x%"PRIx32, pin.fmd.reg_masks[i]);
133 ds_put_format(string, " (via %s)",
134 ofputil_packet_in_reason_to_string(pin.reason));
136 ds_put_format(string, " data_len=%zu", pin.packet_len);
137 if (pin.buffer_id == UINT32_MAX) {
138 ds_put_format(string, " (unbuffered)");
139 if (pin.total_len != pin.packet_len) {
140 ds_put_format(string, " (***total_len != data_len***)");
143 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
144 if (pin.total_len < pin.packet_len) {
145 ds_put_format(string, " (***total_len < data_len***)");
148 ds_put_char(string, '\n');
151 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
152 ds_put_cstr(string, packet);
158 ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
161 struct ofputil_packet_out po;
162 struct ofpbuf ofpacts;
165 ofpbuf_init(&ofpacts, 64);
166 error = ofputil_decode_packet_out(&po, opo, &ofpacts);
168 ofpbuf_uninit(&ofpacts);
169 ofp_print_error(string, error);
173 ds_put_cstr(string, " in_port=");
174 ofputil_format_port(po.in_port, string);
176 ds_put_char(string, ' ');
177 ofpacts_format(po.ofpacts, po.ofpacts_len, string);
179 if (po.buffer_id == UINT32_MAX) {
180 ds_put_format(string, " data_len=%zu", po.packet_len);
181 if (verbosity > 0 && po.packet_len > 0) {
182 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
183 ds_put_char(string, '\n');
184 ds_put_cstr(string, packet);
188 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
190 ds_put_char(string, '\n');
192 ofpbuf_uninit(&ofpacts);
195 /* qsort comparison function. */
197 compare_ports(const void *a_, const void *b_)
199 const struct ofputil_phy_port *a = a_;
200 const struct ofputil_phy_port *b = b_;
201 uint16_t ap = a->port_no;
202 uint16_t bp = b->port_no;
204 return ap < bp ? -1 : ap > bp;
208 ofp_print_bit_names(struct ds *string, uint32_t bits,
209 const char *(*bit_to_name)(uint32_t bit))
215 ds_put_cstr(string, "0");
219 for (i = 0; i < 32; i++) {
220 uint32_t bit = UINT32_C(1) << i;
223 const char *name = bit_to_name(bit);
226 ds_put_char(string, ' ');
228 ds_put_cstr(string, name);
236 ds_put_char(string, ' ');
238 ds_put_format(string, "0x%"PRIx32, bits);
243 netdev_feature_to_name(uint32_t bit)
245 enum netdev_features f = bit;
248 case NETDEV_F_10MB_HD: return "10MB-HD";
249 case NETDEV_F_10MB_FD: return "10MB-FD";
250 case NETDEV_F_100MB_HD: return "100MB-HD";
251 case NETDEV_F_100MB_FD: return "100MB-FD";
252 case NETDEV_F_1GB_HD: return "1GB-HD";
253 case NETDEV_F_1GB_FD: return "1GB-FD";
254 case NETDEV_F_10GB_FD: return "10GB-FD";
255 case NETDEV_F_40GB_FD: return "40GB-FD";
256 case NETDEV_F_100GB_FD: return "100GB-FD";
257 case NETDEV_F_1TB_FD: return "1TB-FD";
258 case NETDEV_F_OTHER: return "OTHER";
259 case NETDEV_F_COPPER: return "COPPER";
260 case NETDEV_F_FIBER: return "FIBER";
261 case NETDEV_F_AUTONEG: return "AUTO_NEG";
262 case NETDEV_F_PAUSE: return "AUTO_PAUSE";
263 case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM";
270 ofp_print_port_features(struct ds *string, enum netdev_features features)
272 ofp_print_bit_names(string, features, netdev_feature_to_name);
273 ds_put_char(string, '\n');
277 ofputil_port_config_to_name(uint32_t bit)
279 enum ofputil_port_config pc = bit;
282 case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN";
283 case OFPUTIL_PC_NO_STP: return "NO_STP";
284 case OFPUTIL_PC_NO_RECV: return "NO_RECV";
285 case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP";
286 case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD";
287 case OFPUTIL_PC_NO_FWD: return "NO_FWD";
288 case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN";
295 ofp_print_port_config(struct ds *string, enum ofputil_port_config config)
297 ofp_print_bit_names(string, config, ofputil_port_config_to_name);
298 ds_put_char(string, '\n');
302 ofputil_port_state_to_name(uint32_t bit)
304 enum ofputil_port_state ps = bit;
307 case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN";
308 case OFPUTIL_PS_BLOCKED: return "BLOCKED";
309 case OFPUTIL_PS_LIVE: return "LIVE";
311 case OFPUTIL_PS_STP_LISTEN:
312 case OFPUTIL_PS_STP_LEARN:
313 case OFPUTIL_PS_STP_FORWARD:
314 case OFPUTIL_PS_STP_BLOCK:
315 /* Handled elsewhere. */
323 ofp_print_port_state(struct ds *string, enum ofputil_port_state state)
325 enum ofputil_port_state stp_state;
327 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
328 * pattern. We have to special case it.
330 * OVS doesn't support STP, so this field will always be 0 if we are
331 * talking to OVS, so we'd always print STP_LISTEN in that case.
332 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
333 * avoid confusing users. */
334 stp_state = state & OFPUTIL_PS_STP_MASK;
337 (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN"
338 : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD"
340 state &= ~OFPUTIL_PS_STP_MASK;
342 ofp_print_bit_names(string, state, ofputil_port_state_to_name);
345 ofp_print_bit_names(string, state, ofputil_port_state_to_name);
347 ds_put_char(string, '\n');
351 ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port)
353 char name[sizeof port->name];
356 memcpy(name, port->name, sizeof name);
357 for (j = 0; j < sizeof name - 1; j++) {
358 if (!isprint((unsigned char) name[j])) {
364 ds_put_char(string, ' ');
365 ofputil_format_port(port->port_no, string);
366 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
367 name, ETH_ADDR_ARGS(port->hw_addr));
369 ds_put_cstr(string, " config: ");
370 ofp_print_port_config(string, port->config);
372 ds_put_cstr(string, " state: ");
373 ofp_print_port_state(string, port->state);
376 ds_put_format(string, " current: ");
377 ofp_print_port_features(string, port->curr);
379 if (port->advertised) {
380 ds_put_format(string, " advertised: ");
381 ofp_print_port_features(string, port->advertised);
383 if (port->supported) {
384 ds_put_format(string, " supported: ");
385 ofp_print_port_features(string, port->supported);
388 ds_put_format(string, " peer: ");
389 ofp_print_port_features(string, port->peer);
391 ds_put_format(string, " speed: %"PRIu32" Mbps now, "
392 "%"PRIu32" Mbps max\n",
393 port->curr_speed / UINT32_C(1000),
394 port->max_speed / UINT32_C(1000));
397 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
398 * 'ofp_version', writes a detailed description of each port into
401 ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
405 struct ofputil_phy_port *ports;
409 n_ports = ofputil_count_phy_ports(ofp_version, b);
411 ports = xmalloc(n_ports * sizeof *ports);
412 for (i = 0; i < n_ports; i++) {
413 error = ofputil_pull_phy_port(ofp_version, b, &ports[i]);
415 ofp_print_error(string, error);
419 qsort(ports, n_ports, sizeof *ports, compare_ports);
420 for (i = 0; i < n_ports; i++) {
421 ofp_print_phy_port(string, &ports[i]);
429 ofputil_capabilities_to_name(uint32_t bit)
431 enum ofputil_capabilities capabilities = bit;
433 switch (capabilities) {
434 case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS";
435 case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS";
436 case OFPUTIL_C_PORT_STATS: return "PORT_STATS";
437 case OFPUTIL_C_IP_REASM: return "IP_REASM";
438 case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS";
439 case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP";
440 case OFPUTIL_C_STP: return "STP";
441 case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS";
448 ofputil_action_bitmap_to_name(uint32_t bit)
450 enum ofputil_action_bitmap action = bit;
453 case OFPUTIL_A_OUTPUT: return "OUTPUT";
454 case OFPUTIL_A_SET_VLAN_VID: return "SET_VLAN_VID";
455 case OFPUTIL_A_SET_VLAN_PCP: return "SET_VLAN_PCP";
456 case OFPUTIL_A_STRIP_VLAN: return "STRIP_VLAN";
457 case OFPUTIL_A_SET_DL_SRC: return "SET_DL_SRC";
458 case OFPUTIL_A_SET_DL_DST: return "SET_DL_DST";
459 case OFPUTIL_A_SET_NW_SRC: return "SET_NW_SRC";
460 case OFPUTIL_A_SET_NW_DST: return "SET_NW_DST";
461 case OFPUTIL_A_SET_NW_ECN: return "SET_NW_ECN";
462 case OFPUTIL_A_SET_NW_TOS: return "SET_NW_TOS";
463 case OFPUTIL_A_SET_TP_SRC: return "SET_TP_SRC";
464 case OFPUTIL_A_SET_TP_DST: return "SET_TP_DST";
465 case OFPUTIL_A_ENQUEUE: return "ENQUEUE";
466 case OFPUTIL_A_COPY_TTL_OUT: return "COPY_TTL_OUT";
467 case OFPUTIL_A_COPY_TTL_IN: return "COPY_TTL_IN";
468 case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL";
469 case OFPUTIL_A_SET_MPLS_TC: return "SET_MPLS_TC";
470 case OFPUTIL_A_SET_MPLS_TTL: return "SET_MPLS_TTL";
471 case OFPUTIL_A_DEC_MPLS_TTL: return "DEC_MPLS_TTL";
472 case OFPUTIL_A_PUSH_VLAN: return "PUSH_VLAN";
473 case OFPUTIL_A_POP_VLAN: return "POP_VLAN";
474 case OFPUTIL_A_PUSH_MPLS: return "PUSH_MPLS";
475 case OFPUTIL_A_POP_MPLS: return "POP_MPLS";
476 case OFPUTIL_A_SET_QUEUE: return "SET_QUEUE";
477 case OFPUTIL_A_GROUP: return "GROUP";
478 case OFPUTIL_A_SET_NW_TTL: return "SET_NW_TTL";
479 case OFPUTIL_A_DEC_NW_TTL: return "DEC_NW_TTL";
486 ofp_print_switch_features(struct ds *string,
487 const struct ofp_switch_features *osf)
489 struct ofputil_switch_features features;
493 error = ofputil_decode_switch_features(osf, &features, &b);
495 ofp_print_error(string, error);
499 ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id);
500 ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32"\n",
501 features.n_tables, features.n_buffers);
503 ds_put_cstr(string, "capabilities: ");
504 ofp_print_bit_names(string, features.capabilities,
505 ofputil_capabilities_to_name);
506 ds_put_char(string, '\n');
508 ds_put_cstr(string, "actions: ");
509 ofp_print_bit_names(string, features.actions,
510 ofputil_action_bitmap_to_name);
511 ds_put_char(string, '\n');
513 ofp_print_phy_ports(string, osf->header.version, &b);
517 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
519 enum ofp_config_flags flags;
521 flags = ntohs(osc->flags);
523 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
524 flags &= ~OFPC_FRAG_MASK;
526 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
527 ds_put_format(string, " invalid_ttl_to_controller");
528 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
532 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
535 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
538 static void print_wild(struct ds *string, const char *leader, int is_wild,
539 int verbosity, const char *format, ...)
540 __attribute__((format(printf, 5, 6)));
542 static void print_wild(struct ds *string, const char *leader, int is_wild,
543 int verbosity, const char *format, ...)
545 if (is_wild && verbosity < 2) {
548 ds_put_cstr(string, leader);
552 va_start(args, format);
553 ds_put_format_valist(string, format, args);
556 ds_put_char(string, '*');
558 ds_put_char(string, ',');
562 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
563 uint32_t wild_bits, int verbosity)
565 if (wild_bits >= 32 && verbosity < 2) {
568 ds_put_cstr(string, leader);
569 if (wild_bits < 32) {
570 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
572 ds_put_format(string, "/%d", 32 - wild_bits);
575 ds_put_char(string, '*');
577 ds_put_char(string, ',');
581 ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity)
583 char *s = ofp10_match_to_string(om, verbosity);
589 ofp10_match_to_string(const struct ofp10_match *om, int verbosity)
591 struct ds f = DS_EMPTY_INITIALIZER;
592 uint32_t w = ntohl(om->wildcards);
593 bool skip_type = false;
594 bool skip_proto = false;
596 if (!(w & OFPFW10_DL_TYPE)) {
598 if (om->dl_type == htons(ETH_TYPE_IP)) {
599 if (!(w & OFPFW10_NW_PROTO)) {
601 if (om->nw_proto == IPPROTO_ICMP) {
602 ds_put_cstr(&f, "icmp,");
603 } else if (om->nw_proto == IPPROTO_TCP) {
604 ds_put_cstr(&f, "tcp,");
605 } else if (om->nw_proto == IPPROTO_UDP) {
606 ds_put_cstr(&f, "udp,");
608 ds_put_cstr(&f, "ip,");
612 ds_put_cstr(&f, "ip,");
614 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
615 ds_put_cstr(&f, "arp,");
620 print_wild(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
621 "%d", ntohs(om->in_port));
622 print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
623 "%d", ntohs(om->dl_vlan));
624 print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
625 "%d", om->dl_vlan_pcp);
626 print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity,
627 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
628 print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity,
629 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
631 print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity,
632 "0x%04x", ntohs(om->dl_type));
634 print_ip_netmask(&f, "nw_src=", om->nw_src,
635 (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT,
637 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
638 (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT,
641 if (om->dl_type == htons(ETH_TYPE_ARP)) {
642 print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity,
645 print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity,
649 print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity,
651 if (om->nw_proto == IPPROTO_ICMP) {
652 print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity,
653 "%d", ntohs(om->tp_src));
654 print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity,
655 "%d", ntohs(om->tp_dst));
657 print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity,
658 "%d", ntohs(om->tp_src));
659 print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity,
660 "%d", ntohs(om->tp_dst));
662 if (ds_last(&f) == ',') {
669 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
670 enum ofputil_msg_code code, int verbosity)
672 struct ofputil_flow_mod fm;
673 struct ofpbuf ofpacts;
677 ofpbuf_init(&ofpacts, 64);
678 error = ofputil_decode_flow_mod(&fm, oh, OFPUTIL_P_OF10_TID, &ofpacts);
680 ofpbuf_uninit(&ofpacts);
681 ofp_print_error(s, error);
686 switch (fm.command) {
688 ds_put_cstr(s, "ADD");
691 ds_put_cstr(s, "MOD");
693 case OFPFC_MODIFY_STRICT:
694 ds_put_cstr(s, "MOD_STRICT");
697 ds_put_cstr(s, "DEL");
699 case OFPFC_DELETE_STRICT:
700 ds_put_cstr(s, "DEL_STRICT");
703 ds_put_format(s, "cmd:%d", fm.command);
705 if (fm.table_id != 0) {
706 ds_put_format(s, " table:%d", fm.table_id);
710 if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) {
711 const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh;
712 ofp10_match_print(s, &ofm->match, verbosity);
714 /* ofp_print_match() doesn't print priority. */
715 need_priority = true;
716 } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) {
717 const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh;
718 const void *nxm = nfm + 1;
721 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
722 ds_put_cstr(s, nxm_s);
725 /* nx_match_to_string() doesn't print priority. */
726 need_priority = true;
728 cls_rule_format(&fm.cr, s);
730 /* cls_rule_format() does print priority. */
731 need_priority = false;
734 if (ds_last(s) != ' ') {
737 if (fm.new_cookie != htonll(0)) {
738 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
740 if (fm.cookie_mask != htonll(0)) {
741 ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ",
742 ntohll(fm.cookie), ntohll(fm.cookie_mask));
744 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
745 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
747 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
748 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
750 if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
751 ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
753 if (fm.buffer_id != UINT32_MAX) {
754 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
757 uint16_t flags = fm.flags;
759 if (flags & OFPFF_SEND_FLOW_REM) {
760 ds_put_cstr(s, "send_flow_rem ");
762 if (flags & OFPFF_CHECK_OVERLAP) {
763 ds_put_cstr(s, "check_overlap ");
765 if (flags & OFPFF_EMERG) {
766 ds_put_cstr(s, "emerg ");
769 flags &= ~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG);
771 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
775 ofpacts_format(fm.ofpacts, fm.ofpacts_len, s);
776 ofpbuf_uninit(&ofpacts);
780 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
782 ds_put_format(string, "%u", sec);
784 ds_put_format(string, ".%09u", nsec);
785 while (string->string[string->length - 1] == '0') {
789 ds_put_char(string, 's');
793 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason)
798 case OFPRR_IDLE_TIMEOUT:
800 case OFPRR_HARD_TIMEOUT:
804 case OFPRR_GROUP_DELETE:
805 return "group_delete";
807 sprintf(s, "%d", (int) reason);
813 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
815 struct ofputil_flow_removed fr;
818 error = ofputil_decode_flow_removed(&fr, oh);
820 ofp_print_error(string, error);
824 ds_put_char(string, ' ');
825 cls_rule_format(&fr.rule, string);
827 ds_put_format(string, " reason=%s",
828 ofp_flow_removed_reason_to_string(fr.reason));
830 if (fr.cookie != htonll(0)) {
831 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
833 ds_put_cstr(string, " duration");
834 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
835 ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
836 fr.idle_timeout, fr.packet_count, fr.byte_count);
840 ofp_print_port_mod(struct ds *string, const struct ofp_header *oh)
842 struct ofputil_port_mod pm;
845 error = ofputil_decode_port_mod(oh, &pm);
847 ofp_print_error(string, error);
851 ds_put_format(string, "port: %"PRIu16": addr:"ETH_ADDR_FMT"\n",
852 pm.port_no, ETH_ADDR_ARGS(pm.hw_addr));
854 ds_put_format(string, " config: ");
855 ofp_print_port_config(string, pm.config);
857 ds_put_format(string, " mask: ");
858 ofp_print_port_config(string, pm.mask);
860 ds_put_format(string, " advertise: ");
862 ofp_print_port_features(string, pm.advertise);
864 ds_put_format(string, "UNCHANGED\n");
869 ofp_print_error(struct ds *string, enum ofperr error)
871 if (string->length) {
872 ds_put_char(string, ' ');
874 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
878 ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
880 size_t len = ntohs(oem->header.length);
881 size_t payload_ofs, payload_len;
886 error = ofperr_decode_msg(&oem->header, &payload_ofs);
888 ds_put_cstr(string, "***decode error***");
889 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
893 ds_put_format(string, " %s\n", ofperr_get_name(error));
895 payload = (const uint8_t *) oem + payload_ofs;
896 payload_len = len - payload_ofs;
897 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
898 ds_put_printable(string, payload, payload_len);
900 s = ofp_to_string(payload, payload_len, 1);
901 ds_put_cstr(string, s);
907 ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
909 struct ofputil_port_status ps;
912 error = ofputil_decode_port_status(ops, &ps);
914 ofp_print_error(string, error);
918 if (ps.reason == OFPPR_ADD) {
919 ds_put_format(string, " ADD:");
920 } else if (ps.reason == OFPPR_DELETE) {
921 ds_put_format(string, " DEL:");
922 } else if (ps.reason == OFPPR_MODIFY) {
923 ds_put_format(string, " MOD:");
926 ofp_print_phy_port(string, &ps.desc);
930 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods)
932 ds_put_char(string, '\n');
933 ds_put_format(string, "Manufacturer: %.*s\n",
934 (int) sizeof ods->mfr_desc, ods->mfr_desc);
935 ds_put_format(string, "Hardware: %.*s\n",
936 (int) sizeof ods->hw_desc, ods->hw_desc);
937 ds_put_format(string, "Software: %.*s\n",
938 (int) sizeof ods->sw_desc, ods->sw_desc);
939 ds_put_format(string, "Serial Num: %.*s\n",
940 (int) sizeof ods->serial_num, ods->serial_num);
941 ds_put_format(string, "DP Description: %.*s\n",
942 (int) sizeof ods->dp_desc, ods->dp_desc);
946 ofp_print_flow_stats_request(struct ds *string,
947 const struct ofp_stats_msg *osm)
949 struct ofputil_flow_stats_request fsr;
952 error = ofputil_decode_flow_stats_request(&fsr, &osm->header);
954 ofp_print_error(string, error);
958 if (fsr.table_id != 0xff) {
959 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
962 if (fsr.out_port != OFPP_NONE) {
963 ds_put_cstr(string, " out_port=");
964 ofputil_format_port(fsr.out_port, string);
967 /* A flow stats request doesn't include a priority, but cls_rule_format()
968 * will print one unless it is OFP_DEFAULT_PRIORITY. */
969 fsr.match.priority = OFP_DEFAULT_PRIORITY;
971 ds_put_char(string, ' ');
972 cls_rule_format(&fsr.match, string);
976 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
978 struct ofpbuf ofpacts;
981 ofpbuf_use_const(&b, oh, ntohs(oh->length));
982 ofpbuf_init(&ofpacts, 64);
984 struct ofputil_flow_stats fs;
987 retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
990 ds_put_cstr(string, " ***parse error***");
995 ds_put_char(string, '\n');
997 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
999 ofp_print_duration(string, fs.duration_sec, fs.duration_nsec);
1000 ds_put_format(string, ", table=%"PRIu8", ", fs.table_id);
1001 ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count);
1002 ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count);
1003 if (fs.idle_timeout != OFP_FLOW_PERMANENT) {
1004 ds_put_format(string, "idle_timeout=%"PRIu16", ", fs.idle_timeout);
1006 if (fs.hard_timeout != OFP_FLOW_PERMANENT) {
1007 ds_put_format(string, "hard_timeout=%"PRIu16", ", fs.hard_timeout);
1009 if (fs.idle_age >= 0) {
1010 ds_put_format(string, "idle_age=%d, ", fs.idle_age);
1012 if (fs.hard_age >= 0 && fs.hard_age != fs.duration_sec) {
1013 ds_put_format(string, "hard_age=%d, ", fs.hard_age);
1016 cls_rule_format(&fs.rule, string);
1017 if (string->string[string->length - 1] != ' ') {
1018 ds_put_char(string, ' ');
1020 ofpacts_format(fs.ofpacts, fs.ofpacts_len, string);
1022 ofpbuf_uninit(&ofpacts);
1026 ofp_print_ofpst_aggregate_reply(struct ds *string,
1027 const struct ofp_aggregate_stats_reply *asr)
1029 ds_put_format(string, " packet_count=%"PRIu64,
1030 ntohll(get_32aligned_be64(&asr->packet_count)));
1031 ds_put_format(string, " byte_count=%"PRIu64,
1032 ntohll(get_32aligned_be64(&asr->byte_count)));
1033 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1037 ofp_print_nxst_aggregate_reply(struct ds *string,
1038 const struct nx_aggregate_stats_reply *nasr)
1040 ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count));
1041 ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count));
1042 ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count));
1045 static void print_port_stat(struct ds *string, const char *leader,
1046 const ovs_32aligned_be64 *statp, int more)
1048 uint64_t stat = ntohll(get_32aligned_be64(statp));
1050 ds_put_cstr(string, leader);
1051 if (stat != UINT64_MAX) {
1052 ds_put_format(string, "%"PRIu64, stat);
1054 ds_put_char(string, '?');
1057 ds_put_cstr(string, ", ");
1059 ds_put_cstr(string, "\n");
1064 ofp_print_ofpst_port_request(struct ds *string,
1065 const struct ofp_port_stats_request *psr)
1067 ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
1071 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1074 const struct ofp_port_stats *ps = ofputil_stats_body(oh);
1075 size_t n = ofputil_stats_body_len(oh) / sizeof *ps;
1076 ds_put_format(string, " %zu ports\n", n);
1077 if (verbosity < 1) {
1082 ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no));
1084 ds_put_cstr(string, "rx ");
1085 print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1086 print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1087 print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1088 print_port_stat(string, "errs=", &ps->rx_errors, 1);
1089 print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1090 print_port_stat(string, "over=", &ps->rx_over_err, 1);
1091 print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
1093 ds_put_cstr(string, " tx ");
1094 print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1095 print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1096 print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1097 print_port_stat(string, "errs=", &ps->tx_errors, 1);
1098 print_port_stat(string, "coll=", &ps->collisions, 0);
1103 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1106 const struct ofp_table_stats *ts = ofputil_stats_body(oh);
1107 size_t n = ofputil_stats_body_len(oh) / sizeof *ts;
1108 ds_put_format(string, " %zu tables\n", n);
1109 if (verbosity < 1) {
1114 char name[OFP_MAX_TABLE_NAME_LEN + 1];
1115 ovs_strlcpy(name, ts->name, sizeof name);
1117 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1118 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1119 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1120 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1121 ds_put_cstr(string, " ");
1122 ds_put_format(string, "lookup=%"PRIu64", ",
1123 ntohll(get_32aligned_be64(&ts->lookup_count)));
1124 ds_put_format(string, "matched=%"PRIu64"\n",
1125 ntohll(get_32aligned_be64(&ts->matched_count)));
1130 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1132 if (queue_id == OFPQ_ALL) {
1133 ds_put_cstr(string, "ALL");
1135 ds_put_format(string, "%"PRIu32, queue_id);
1140 ofp_print_ofpst_queue_request(struct ds *string,
1141 const struct ofp_queue_stats_request *qsr)
1143 ds_put_cstr(string, "port=");
1144 ofputil_format_port(ntohs(qsr->port_no), string);
1146 ds_put_cstr(string, " queue=");
1147 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1151 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1154 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1155 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
1156 ds_put_format(string, " %zu queues\n", n);
1157 if (verbosity < 1) {
1162 ds_put_cstr(string, " port ");
1163 ofputil_format_port(ntohs(qs->port_no), string);
1164 ds_put_cstr(string, " queue ");
1165 ofp_print_queue_name(string, ntohl(qs->queue_id));
1166 ds_put_cstr(string, ": ");
1168 print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1169 print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1170 print_port_stat(string, "errors=", &qs->tx_errors, 0);
1175 ofp_print_ofpst_port_desc_reply(struct ds *string,
1176 const struct ofp_header *oh)
1180 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1181 ofpbuf_pull(&b, sizeof(struct ofp_stats_msg));
1182 ds_put_char(string, '\n');
1183 ofp_print_phy_ports(string, oh->version, &b);
1187 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1189 const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh;
1192 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1198 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1200 const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh;
1203 uint16_t flags = ntohs(srp->flags);
1205 ds_put_cstr(string, " flags=");
1206 if (flags & OFPSF_REPLY_MORE) {
1207 ds_put_cstr(string, "[more]");
1208 flags &= ~OFPSF_REPLY_MORE;
1211 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1218 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1220 size_t len = ntohs(oh->length);
1222 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1223 if (verbosity > 1) {
1224 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1229 ofp_print_nxt_role_message(struct ds *string,
1230 const struct nx_role_request *nrr)
1232 unsigned int role = ntohl(nrr->role);
1234 ds_put_cstr(string, " role=");
1235 if (role == NX_ROLE_OTHER) {
1236 ds_put_cstr(string, "other");
1237 } else if (role == NX_ROLE_MASTER) {
1238 ds_put_cstr(string, "master");
1239 } else if (role == NX_ROLE_SLAVE) {
1240 ds_put_cstr(string, "slave");
1242 ds_put_format(string, "%u", role);
1247 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1248 const struct nx_flow_mod_table_id *nfmti)
1250 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1254 ofp_print_nxt_set_flow_format(struct ds *string,
1255 const struct nx_set_flow_format *nsff)
1257 uint32_t format = ntohl(nsff->format);
1259 ds_put_cstr(string, " format=");
1260 if (ofputil_nx_flow_format_is_valid(format)) {
1261 ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
1263 ds_put_format(string, "%"PRIu32, format);
1268 ofp_print_nxt_set_packet_in_format(struct ds *string,
1269 const struct nx_set_packet_in_format *nspf)
1271 uint32_t format = ntohl(nspf->format);
1273 ds_put_cstr(string, " format=");
1274 if (ofputil_packet_in_format_is_valid(format)) {
1275 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1277 ds_put_format(string, "%"PRIu32, format);
1282 ofp_port_reason_to_string(enum ofp_port_reason reason)
1297 sprintf(s, "%d", (int) reason);
1303 ofp_print_nxt_set_async_config(struct ds *string,
1304 const struct nx_async_config *nac)
1308 for (i = 0; i < 2; i++) {
1311 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
1313 ds_put_cstr(string, " PACKET_IN:");
1314 for (j = 0; j < 32; j++) {
1315 if (nac->packet_in_mask[i] & htonl(1u << j)) {
1316 ds_put_format(string, " %s",
1317 ofputil_packet_in_reason_to_string(j));
1320 if (!nac->packet_in_mask[i]) {
1321 ds_put_cstr(string, " (off)");
1323 ds_put_char(string, '\n');
1325 ds_put_cstr(string, " PORT_STATUS:");
1326 for (j = 0; j < 32; j++) {
1327 if (nac->port_status_mask[i] & htonl(1u << j)) {
1328 ds_put_format(string, " %s", ofp_port_reason_to_string(j));
1331 if (!nac->port_status_mask[i]) {
1332 ds_put_cstr(string, " (off)");
1334 ds_put_char(string, '\n');
1336 ds_put_cstr(string, " FLOW_REMOVED:");
1337 for (j = 0; j < 32; j++) {
1338 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
1339 ds_put_format(string, " %s",
1340 ofp_flow_removed_reason_to_string(j));
1343 if (!nac->flow_removed_mask[i]) {
1344 ds_put_cstr(string, " (off)");
1346 ds_put_char(string, '\n');
1351 ofp_print_nxt_set_controller_id(struct ds *string,
1352 const struct nx_controller_id *nci)
1354 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
1358 ofp_to_string__(const struct ofp_header *oh,
1359 const struct ofputil_msg_type *type, struct ds *string,
1362 enum ofputil_msg_code code;
1363 const void *msg = oh;
1365 ds_put_cstr(string, ofputil_msg_type_name(type));
1366 switch (oh->version) {
1370 ds_put_cstr(string, " (OF1.1)");
1373 ds_put_cstr(string, " (OF1.2)");
1376 ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
1379 ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
1381 code = ofputil_msg_type_code(type);
1383 case OFPUTIL_MSG_INVALID:
1386 case OFPUTIL_OFPT_HELLO:
1387 ds_put_char(string, '\n');
1388 ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1392 case OFPUTIL_OFPT_ERROR:
1393 ofp_print_error_msg(string, msg);
1396 case OFPUTIL_OFPT_ECHO_REQUEST:
1397 case OFPUTIL_OFPT_ECHO_REPLY:
1398 ofp_print_echo(string, oh, verbosity);
1401 case OFPUTIL_OFPT_FEATURES_REQUEST:
1404 case OFPUTIL_OFPT_FEATURES_REPLY:
1405 ofp_print_switch_features(string, msg);
1408 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1411 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1412 case OFPUTIL_OFPT_SET_CONFIG:
1413 ofp_print_switch_config(string, msg);
1416 case OFPUTIL_OFPT_PACKET_IN:
1417 case OFPUTIL_NXT_PACKET_IN:
1418 ofp_print_packet_in(string, msg, verbosity);
1421 case OFPUTIL_OFPT_FLOW_REMOVED:
1422 case OFPUTIL_NXT_FLOW_REMOVED:
1423 ofp_print_flow_removed(string, msg);
1426 case OFPUTIL_OFPT_PORT_STATUS:
1427 ofp_print_port_status(string, msg);
1430 case OFPUTIL_OFPT_PACKET_OUT:
1431 ofp_print_packet_out(string, msg, verbosity);
1434 case OFPUTIL_OFPT_FLOW_MOD:
1435 case OFPUTIL_NXT_FLOW_MOD:
1436 ofp_print_flow_mod(string, msg, code, verbosity);
1439 case OFPUTIL_OFPT_PORT_MOD:
1440 ofp_print_port_mod(string, msg);
1443 case OFPUTIL_OFPT_BARRIER_REQUEST:
1444 case OFPUTIL_OFPT_BARRIER_REPLY:
1447 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1448 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1452 case OFPUTIL_OFPST_DESC_REQUEST:
1453 case OFPUTIL_OFPST_PORT_DESC_REQUEST:
1454 ofp_print_stats_request(string, oh);
1457 case OFPUTIL_OFPST_FLOW_REQUEST:
1458 case OFPUTIL_NXST_FLOW_REQUEST:
1459 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
1460 case OFPUTIL_NXST_AGGREGATE_REQUEST:
1461 ofp_print_stats_request(string, oh);
1462 ofp_print_flow_stats_request(string, msg);
1465 case OFPUTIL_OFPST_TABLE_REQUEST:
1466 ofp_print_stats_request(string, oh);
1469 case OFPUTIL_OFPST_PORT_REQUEST:
1470 ofp_print_stats_request(string, oh);
1471 ofp_print_ofpst_port_request(string, msg);
1474 case OFPUTIL_OFPST_QUEUE_REQUEST:
1475 ofp_print_stats_request(string, oh);
1476 ofp_print_ofpst_queue_request(string, msg);
1479 case OFPUTIL_OFPST_DESC_REPLY:
1480 ofp_print_stats_reply(string, oh);
1481 ofp_print_ofpst_desc_reply(string, msg);
1484 case OFPUTIL_OFPST_FLOW_REPLY:
1485 case OFPUTIL_NXST_FLOW_REPLY:
1486 ofp_print_stats_reply(string, oh);
1487 ofp_print_flow_stats_reply(string, oh);
1490 case OFPUTIL_OFPST_QUEUE_REPLY:
1491 ofp_print_stats_reply(string, oh);
1492 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1495 case OFPUTIL_OFPST_PORT_REPLY:
1496 ofp_print_stats_reply(string, oh);
1497 ofp_print_ofpst_port_reply(string, oh, verbosity);
1500 case OFPUTIL_OFPST_TABLE_REPLY:
1501 ofp_print_stats_reply(string, oh);
1502 ofp_print_ofpst_table_reply(string, oh, verbosity);
1505 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1506 ofp_print_stats_reply(string, oh);
1507 ofp_print_ofpst_aggregate_reply(string, msg);
1510 case OFPUTIL_OFPST_PORT_DESC_REPLY:
1511 ofp_print_stats_reply(string, oh);
1512 ofp_print_ofpst_port_desc_reply(string, oh);
1515 case OFPUTIL_NXT_ROLE_REQUEST:
1516 case OFPUTIL_NXT_ROLE_REPLY:
1517 ofp_print_nxt_role_message(string, msg);
1520 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID:
1521 ofp_print_nxt_flow_mod_table_id(string, msg);
1524 case OFPUTIL_NXT_SET_FLOW_FORMAT:
1525 ofp_print_nxt_set_flow_format(string, msg);
1528 case OFPUTIL_NXT_SET_PACKET_IN_FORMAT:
1529 ofp_print_nxt_set_packet_in_format(string, msg);
1532 case OFPUTIL_NXT_FLOW_AGE:
1535 case OFPUTIL_NXT_SET_CONTROLLER_ID:
1536 ofp_print_nxt_set_controller_id(string, msg);
1539 case OFPUTIL_NXT_SET_ASYNC_CONFIG:
1540 ofp_print_nxt_set_async_config(string, msg);
1543 case OFPUTIL_NXST_AGGREGATE_REPLY:
1544 ofp_print_stats_reply(string, oh);
1545 ofp_print_nxst_aggregate_reply(string, msg);
1550 /* Composes and returns a string representing the OpenFlow packet of 'len'
1551 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1552 * verbosity and higher numbers increase verbosity. The caller is responsible
1553 * for freeing the string. */
1555 ofp_to_string(const void *oh_, size_t len, int verbosity)
1557 struct ds string = DS_EMPTY_INITIALIZER;
1558 const struct ofp_header *oh = oh_;
1561 ds_put_cstr(&string, "OpenFlow message is empty\n");
1562 } else if (len < sizeof(struct ofp_header)) {
1563 ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1565 } else if (ntohs(oh->length) > len) {
1566 ds_put_format(&string,
1567 "(***truncated to %zu bytes from %"PRIu16"***)\n",
1568 len, ntohs(oh->length));
1569 } else if (ntohs(oh->length) < len) {
1570 ds_put_format(&string,
1571 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1572 ntohs(oh->length), len);
1574 const struct ofputil_msg_type *type;
1577 error = ofputil_decode_msg_type(oh, &type);
1579 ofp_to_string__(oh, type, &string, verbosity);
1580 if (verbosity >= 5) {
1581 if (ds_last(&string) != '\n') {
1582 ds_put_char(&string, '\n');
1584 ds_put_hex_dump(&string, oh, len, 0, true);
1586 if (ds_last(&string) != '\n') {
1587 ds_put_char(&string, '\n');
1589 return ds_steal_cstr(&string);
1592 ofp_print_error(&string, error);
1594 ds_put_hex_dump(&string, oh, len, 0, true);
1595 return ds_steal_cstr(&string);
1599 print_and_free(FILE *stream, char *string)
1601 fputs(string, stream);
1605 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1606 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1607 * numbers increase verbosity. */
1609 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1611 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1614 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1615 * 'data' to 'stream'. */
1617 ofp_print_packet(FILE *stream, const void *data, size_t len)
1619 print_and_free(stream, ofp_packet_to_string(data, len));