2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
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"
38 #include "ofp-errors.h"
41 #include "openflow/openflow.h"
42 #include "openflow/nicira-ext.h"
45 #include "type-props.h"
46 #include "unaligned.h"
49 static void ofp_print_queue_name(struct ds *string, uint32_t port);
50 static void ofp_print_error(struct ds *, enum ofperr);
53 /* Returns a string that represents the contents of the Ethernet frame in the
54 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
56 ofp_packet_to_string(const void *data, size_t len)
58 struct ds ds = DS_EMPTY_INITIALIZER;
62 ofpbuf_use_const(&buf, data, len);
63 flow_extract(&buf, 0, 0, 0, &flow);
64 flow_format(&ds, &flow);
67 if (flow.nw_proto == IPPROTO_TCP) {
68 struct tcp_header *th = buf.l4;
69 ds_put_format(&ds, " tcp_csum:%"PRIx16,
71 } else if (flow.nw_proto == IPPROTO_UDP) {
72 struct udp_header *uh = buf.l4;
73 ds_put_format(&ds, " udp_csum:%"PRIx16,
78 ds_put_char(&ds, '\n');
84 ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
87 struct ofputil_packet_in pin;
91 error = ofputil_decode_packet_in(&pin, oh);
93 ofp_print_error(string, error);
98 ds_put_format(string, " table_id=%"PRIu8, pin.table_id);
102 ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
105 ds_put_format(string, " total_len=%"PRIu16" in_port=", pin.total_len);
106 ofputil_format_port(pin.fmd.in_port, string);
108 if (pin.fmd.tun_id_mask) {
109 ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
110 if (pin.fmd.tun_id_mask != htonll(UINT64_MAX)) {
111 ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.tun_id_mask));
115 for (i = 0; i < FLOW_N_REGS; i++) {
116 if (pin.fmd.reg_masks[i]) {
117 ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]);
118 if (pin.fmd.reg_masks[i] != UINT32_MAX) {
119 ds_put_format(string, "/0x%"PRIx32, pin.fmd.reg_masks[i]);
124 ds_put_format(string, " (via %s)",
125 ofputil_packet_in_reason_to_string(pin.reason));
127 ds_put_format(string, " data_len=%zu", pin.packet_len);
128 if (pin.buffer_id == UINT32_MAX) {
129 ds_put_format(string, " (unbuffered)");
130 if (pin.total_len != pin.packet_len) {
131 ds_put_format(string, " (***total_len != data_len***)");
134 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
135 if (pin.total_len < pin.packet_len) {
136 ds_put_format(string, " (***total_len < data_len***)");
139 ds_put_char(string, '\n');
142 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
143 ds_put_cstr(string, packet);
149 print_note(struct ds *string, const struct nx_action_note *nan)
154 ds_put_cstr(string, "note:");
155 len = ntohs(nan->len) - offsetof(struct nx_action_note, note);
156 for (i = 0; i < len; i++) {
158 ds_put_char(string, '.');
160 ds_put_format(string, "%02"PRIx8, nan->note[i]);
165 ofp_print_action(struct ds *s, const union ofp_action *a,
166 enum ofputil_action_code code)
168 const struct ofp_action_enqueue *oae;
169 const struct ofp_action_dl_addr *oada;
170 const struct nx_action_set_tunnel64 *nast64;
171 const struct nx_action_set_tunnel *nast;
172 const struct nx_action_set_queue *nasq;
173 const struct nx_action_resubmit *nar;
174 const struct nx_action_reg_move *move;
175 const struct nx_action_reg_load *load;
176 const struct nx_action_multipath *nam;
177 const struct nx_action_autopath *naa;
178 const struct nx_action_output_reg *naor;
179 const struct nx_action_fin_timeout *naft;
180 const struct nx_action_controller *nac;
181 struct mf_subfield subfield;
185 case OFPUTIL_OFPAT_OUTPUT:
186 port = ntohs(a->output.port);
187 if (port < OFPP_MAX) {
188 ds_put_format(s, "output:%"PRIu16, port);
190 ofputil_format_port(port, s);
191 if (port == OFPP_CONTROLLER) {
192 if (a->output.max_len != htons(0)) {
193 ds_put_format(s, ":%"PRIu16, ntohs(a->output.max_len));
195 ds_put_cstr(s, ":all");
201 case OFPUTIL_OFPAT_ENQUEUE:
202 oae = (const struct ofp_action_enqueue *) a;
203 ds_put_format(s, "enqueue:");
204 ofputil_format_port(ntohs(oae->port), s);
205 ds_put_format(s, "q%"PRIu32, ntohl(oae->queue_id));
208 case OFPUTIL_OFPAT_SET_VLAN_VID:
209 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
210 ntohs(a->vlan_vid.vlan_vid));
213 case OFPUTIL_OFPAT_SET_VLAN_PCP:
214 ds_put_format(s, "mod_vlan_pcp:%"PRIu8, a->vlan_pcp.vlan_pcp);
217 case OFPUTIL_OFPAT_STRIP_VLAN:
218 ds_put_cstr(s, "strip_vlan");
221 case OFPUTIL_OFPAT_SET_DL_SRC:
222 oada = (const struct ofp_action_dl_addr *) a;
223 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
224 ETH_ADDR_ARGS(oada->dl_addr));
227 case OFPUTIL_OFPAT_SET_DL_DST:
228 oada = (const struct ofp_action_dl_addr *) a;
229 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
230 ETH_ADDR_ARGS(oada->dl_addr));
233 case OFPUTIL_OFPAT_SET_NW_SRC:
234 ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
237 case OFPUTIL_OFPAT_SET_NW_DST:
238 ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
241 case OFPUTIL_OFPAT_SET_NW_TOS:
242 ds_put_format(s, "mod_nw_tos:%d", a->nw_tos.nw_tos);
245 case OFPUTIL_OFPAT_SET_TP_SRC:
246 ds_put_format(s, "mod_tp_src:%d", ntohs(a->tp_port.tp_port));
249 case OFPUTIL_OFPAT_SET_TP_DST:
250 ds_put_format(s, "mod_tp_dst:%d", ntohs(a->tp_port.tp_port));
253 case OFPUTIL_NXAST_RESUBMIT:
254 nar = (struct nx_action_resubmit *)a;
255 ds_put_format(s, "resubmit:");
256 ofputil_format_port(ntohs(nar->in_port), s);
259 case OFPUTIL_NXAST_RESUBMIT_TABLE:
260 nar = (struct nx_action_resubmit *)a;
261 ds_put_format(s, "resubmit(");
262 if (nar->in_port != htons(OFPP_IN_PORT)) {
263 ofputil_format_port(ntohs(nar->in_port), s);
266 if (nar->table != 255) {
267 ds_put_format(s, "%"PRIu8, nar->table);
272 case OFPUTIL_NXAST_SET_TUNNEL:
273 nast = (struct nx_action_set_tunnel *)a;
274 ds_put_format(s, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id));
277 case OFPUTIL_NXAST_SET_QUEUE:
278 nasq = (struct nx_action_set_queue *)a;
279 ds_put_format(s, "set_queue:%u", ntohl(nasq->queue_id));
282 case OFPUTIL_NXAST_POP_QUEUE:
283 ds_put_cstr(s, "pop_queue");
286 case OFPUTIL_NXAST_NOTE:
287 print_note(s, (const struct nx_action_note *) a);
290 case OFPUTIL_NXAST_REG_MOVE:
291 move = (const struct nx_action_reg_move *) a;
292 nxm_format_reg_move(move, s);
295 case OFPUTIL_NXAST_REG_LOAD:
296 load = (const struct nx_action_reg_load *) a;
297 nxm_format_reg_load(load, s);
300 case OFPUTIL_NXAST_SET_TUNNEL64:
301 nast64 = (const struct nx_action_set_tunnel64 *) a;
302 ds_put_format(s, "set_tunnel64:%#"PRIx64,
303 ntohll(nast64->tun_id));
306 case OFPUTIL_NXAST_MULTIPATH:
307 nam = (const struct nx_action_multipath *) a;
308 multipath_format(nam, s);
311 case OFPUTIL_NXAST_AUTOPATH:
312 naa = (const struct nx_action_autopath *)a;
313 ds_put_format(s, "autopath(%u,", ntohl(naa->id));
314 nxm_decode(&subfield, naa->dst, naa->ofs_nbits);
315 mf_format_subfield(&subfield, s);
319 case OFPUTIL_NXAST_BUNDLE:
320 case OFPUTIL_NXAST_BUNDLE_LOAD:
321 bundle_format((const struct nx_action_bundle *) a, s);
324 case OFPUTIL_NXAST_OUTPUT_REG:
325 naor = (const struct nx_action_output_reg *) a;
326 ds_put_cstr(s, "output:");
327 nxm_decode(&subfield, naor->src, naor->ofs_nbits);
328 mf_format_subfield(&subfield, s);
331 case OFPUTIL_NXAST_LEARN:
332 learn_format((const struct nx_action_learn *) a, s);
335 case OFPUTIL_NXAST_DEC_TTL:
336 ds_put_cstr(s, "dec_ttl");
339 case OFPUTIL_NXAST_EXIT:
340 ds_put_cstr(s, "exit");
343 case OFPUTIL_NXAST_FIN_TIMEOUT:
344 naft = (const struct nx_action_fin_timeout *) a;
345 ds_put_cstr(s, "fin_timeout(");
346 if (naft->fin_idle_timeout) {
347 ds_put_format(s, "idle_timeout=%"PRIu16",",
348 ntohs(naft->fin_idle_timeout));
350 if (naft->fin_hard_timeout) {
351 ds_put_format(s, "hard_timeout=%"PRIu16",",
352 ntohs(naft->fin_hard_timeout));
358 case OFPUTIL_NXAST_CONTROLLER:
359 nac = (const struct nx_action_controller *) a;
360 ds_put_cstr(s, "controller(");
361 if (nac->reason != OFPR_ACTION) {
362 ds_put_format(s, "reason=%s,",
363 ofputil_packet_in_reason_to_string(nac->reason));
365 if (nac->max_len != htons(UINT16_MAX)) {
366 ds_put_format(s, "max_len=%"PRIu16",", ntohs(nac->max_len));
368 if (nac->controller_id != htons(0)) {
369 ds_put_format(s, "id=%"PRIu16",", ntohs(nac->controller_id));
381 ofp_print_actions(struct ds *string, const union ofp_action *actions,
384 const union ofp_action *a;
387 ds_put_cstr(string, "actions=");
389 ds_put_cstr(string, "drop");
392 OFPUTIL_ACTION_FOR_EACH (a, left, actions, n_actions) {
393 int code = ofputil_decode_action(a);
396 ds_put_cstr(string, ",");
398 ofp_print_action(string, a, code);
400 ofp_print_error(string, -code);
404 ds_put_format(string, " ***%zu leftover bytes following actions",
410 ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
413 struct ofputil_packet_out po;
416 error = ofputil_decode_packet_out(&po, opo);
418 ofp_print_error(string, error);
422 ds_put_cstr(string, " in_port=");
423 ofputil_format_port(po.in_port, string);
425 ds_put_char(string, ' ');
426 ofp_print_actions(string, po.actions, po.n_actions);
428 if (po.buffer_id == UINT32_MAX) {
429 ds_put_format(string, " data_len=%zu", po.packet_len);
430 if (verbosity > 0 && po.packet_len > 0) {
431 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
432 ds_put_char(string, '\n');
433 ds_put_cstr(string, packet);
437 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
439 ds_put_char(string, '\n');
442 /* qsort comparison function. */
444 compare_ports(const void *a_, const void *b_)
446 const struct ofp_phy_port *a = a_;
447 const struct ofp_phy_port *b = b_;
448 uint16_t ap = ntohs(a->port_no);
449 uint16_t bp = ntohs(b->port_no);
451 return ap < bp ? -1 : ap > bp;
460 ofp_print_bit_names(struct ds *string, uint32_t bits,
461 const struct bit_name bit_names[])
466 ds_put_cstr(string, "0");
470 for (; bits && bit_names->name; bit_names++) {
471 if (bits & bit_names->bit) {
473 ds_put_char(string, ' ');
475 ds_put_cstr(string, bit_names->name);
476 bits &= ~bit_names->bit;
482 ds_put_char(string, ' ');
484 ds_put_format(string, "0x%"PRIx32, bits);
489 ofp_print_port_features(struct ds *string, uint32_t features)
491 static const struct bit_name feature_bits[] = {
492 { OFPPF_10MB_HD, "10MB-HD" },
493 { OFPPF_10MB_FD, "10MB-FD" },
494 { OFPPF_100MB_HD, "100MB-HD" },
495 { OFPPF_100MB_FD, "100MB-FD" },
496 { OFPPF_1GB_HD, "1GB-HD" },
497 { OFPPF_1GB_FD, "1GB-FD" },
498 { OFPPF_10GB_FD, "10GB-FD" },
499 { OFPPF_COPPER, "COPPER" },
500 { OFPPF_FIBER, "FIBER" },
501 { OFPPF_AUTONEG, "AUTO_NEG" },
502 { OFPPF_PAUSE, "AUTO_PAUSE" },
503 { OFPPF_PAUSE_ASYM, "AUTO_PAUSE_ASYM" },
507 ofp_print_bit_names(string, features, feature_bits);
508 ds_put_char(string, '\n');
512 ofp_print_port_config(struct ds *string, uint32_t config)
514 static const struct bit_name config_bits[] = {
515 { OFPPC_PORT_DOWN, "PORT_DOWN" },
516 { OFPPC_NO_STP, "NO_STP" },
517 { OFPPC_NO_RECV, "NO_RECV" },
518 { OFPPC_NO_RECV_STP, "NO_RECV_STP" },
519 { OFPPC_NO_FLOOD, "NO_FLOOD" },
520 { OFPPC_NO_FWD, "NO_FWD" },
521 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
525 ofp_print_bit_names(string, config, config_bits);
526 ds_put_char(string, '\n');
530 ofp_print_port_state(struct ds *string, uint32_t state)
532 static const struct bit_name state_bits[] = {
533 { OFPPS_LINK_DOWN, "LINK_DOWN" },
538 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
539 * pattern. We have to special case it.
541 * OVS doesn't support STP, so this field will always be 0 if we are
542 * talking to OVS, so we'd always print STP_LISTEN in that case.
543 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
544 * avoid confusing users. */
545 stp_state = state & OFPPS_STP_MASK;
547 ds_put_cstr(string, (stp_state == OFPPS_STP_LEARN ? "STP_LEARN"
548 : stp_state == OFPPS_STP_FORWARD ? "STP_FORWARD"
550 state &= ~OFPPS_STP_MASK;
552 ofp_print_bit_names(string, state, state_bits);
555 ofp_print_bit_names(string, state, state_bits);
557 ds_put_char(string, '\n');
561 ofp_print_phy_port(struct ds *string, const struct ofp_phy_port *port)
563 char name[OFP_MAX_PORT_NAME_LEN];
566 memcpy(name, port->name, sizeof name);
567 for (j = 0; j < sizeof name - 1; j++) {
568 if (!isprint((unsigned char) name[j])) {
574 ds_put_char(string, ' ');
575 ofputil_format_port(ntohs(port->port_no), string);
576 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
577 name, ETH_ADDR_ARGS(port->hw_addr));
579 ds_put_cstr(string, " config: ");
580 ofp_print_port_config(string, ntohl(port->config));
582 ds_put_cstr(string, " state: ");
583 ofp_print_port_state(string, ntohl(port->state));
586 ds_put_format(string, " current: ");
587 ofp_print_port_features(string, ntohl(port->curr));
589 if (port->advertised) {
590 ds_put_format(string, " advertised: ");
591 ofp_print_port_features(string, ntohl(port->advertised));
593 if (port->supported) {
594 ds_put_format(string, " supported: ");
595 ofp_print_port_features(string, ntohl(port->supported));
598 ds_put_format(string, " peer: ");
599 ofp_print_port_features(string, ntohl(port->peer));
604 ofp_print_switch_features(struct ds *string,
605 const struct ofp_switch_features *osf)
607 size_t len = ntohs(osf->header.length);
608 struct ofp_phy_port *port_list;
612 ds_put_format(string, " ver:0x%x, dpid:%016"PRIx64"\n",
613 osf->header.version, ntohll(osf->datapath_id));
614 ds_put_format(string, "n_tables:%d, n_buffers:%d\n", osf->n_tables,
615 ntohl(osf->n_buffers));
616 ds_put_format(string, "features: capabilities:%#x, actions:%#x\n",
617 ntohl(osf->capabilities), ntohl(osf->actions));
619 n_ports = (len - sizeof *osf) / sizeof *osf->ports;
621 port_list = xmemdup(osf->ports, len - sizeof *osf);
622 qsort(port_list, n_ports, sizeof *port_list, compare_ports);
623 for (i = 0; i < n_ports; i++) {
624 ofp_print_phy_port(string, &port_list[i]);
630 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
632 enum ofp_config_flags flags;
634 flags = ntohs(osc->flags);
636 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
637 flags &= ~OFPC_FRAG_MASK;
639 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
640 ds_put_format(string, " invalid_ttl_to_controller");
641 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
645 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
648 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
651 static void print_wild(struct ds *string, const char *leader, int is_wild,
652 int verbosity, const char *format, ...)
653 __attribute__((format(printf, 5, 6)));
655 static void print_wild(struct ds *string, const char *leader, int is_wild,
656 int verbosity, const char *format, ...)
658 if (is_wild && verbosity < 2) {
661 ds_put_cstr(string, leader);
665 va_start(args, format);
666 ds_put_format_valist(string, format, args);
669 ds_put_char(string, '*');
671 ds_put_char(string, ',');
675 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
676 uint32_t wild_bits, int verbosity)
678 if (wild_bits >= 32 && verbosity < 2) {
681 ds_put_cstr(string, leader);
682 if (wild_bits < 32) {
683 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
685 ds_put_format(string, "/%d", 32 - wild_bits);
688 ds_put_char(string, '*');
690 ds_put_char(string, ',');
694 ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
696 char *s = ofp_match_to_string(om, verbosity);
702 ofp_match_to_string(const struct ofp_match *om, int verbosity)
704 struct ds f = DS_EMPTY_INITIALIZER;
705 uint32_t w = ntohl(om->wildcards);
706 bool skip_type = false;
707 bool skip_proto = false;
709 if (!(w & OFPFW_DL_TYPE)) {
711 if (om->dl_type == htons(ETH_TYPE_IP)) {
712 if (!(w & OFPFW_NW_PROTO)) {
714 if (om->nw_proto == IPPROTO_ICMP) {
715 ds_put_cstr(&f, "icmp,");
716 } else if (om->nw_proto == IPPROTO_TCP) {
717 ds_put_cstr(&f, "tcp,");
718 } else if (om->nw_proto == IPPROTO_UDP) {
719 ds_put_cstr(&f, "udp,");
721 ds_put_cstr(&f, "ip,");
725 ds_put_cstr(&f, "ip,");
727 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
728 ds_put_cstr(&f, "arp,");
733 print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
734 "%d", ntohs(om->in_port));
735 print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
736 "%d", ntohs(om->dl_vlan));
737 print_wild(&f, "dl_vlan_pcp=", w & OFPFW_DL_VLAN_PCP, verbosity,
738 "%d", om->dl_vlan_pcp);
739 print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
740 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
741 print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
742 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
744 print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
745 "0x%04x", ntohs(om->dl_type));
747 print_ip_netmask(&f, "nw_src=", om->nw_src,
748 (w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
749 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
750 (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
752 if (om->dl_type == htons(ETH_TYPE_ARP)) {
753 print_wild(&f, "arp_op=", w & OFPFW_NW_PROTO, verbosity,
756 print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
760 print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
762 if (om->nw_proto == IPPROTO_ICMP) {
763 print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
764 "%d", ntohs(om->tp_src));
765 print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
766 "%d", ntohs(om->tp_dst));
768 print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
769 "%d", ntohs(om->tp_src));
770 print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
771 "%d", ntohs(om->tp_dst));
773 if (ds_last(&f) == ',') {
780 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
781 enum ofputil_msg_code code, int verbosity)
783 struct ofputil_flow_mod fm;
787 error = ofputil_decode_flow_mod(&fm, oh, true);
789 ofp_print_error(s, error);
794 switch (fm.command) {
796 ds_put_cstr(s, "ADD");
799 ds_put_cstr(s, "MOD");
801 case OFPFC_MODIFY_STRICT:
802 ds_put_cstr(s, "MOD_STRICT");
805 ds_put_cstr(s, "DEL");
807 case OFPFC_DELETE_STRICT:
808 ds_put_cstr(s, "DEL_STRICT");
811 ds_put_format(s, "cmd:%d", fm.command);
813 if (fm.table_id != 0) {
814 ds_put_format(s, " table:%d", fm.table_id);
818 if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) {
819 const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh;
820 ofp_print_match(s, &ofm->match, verbosity);
822 /* ofp_print_match() doesn't print priority. */
823 need_priority = true;
824 } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) {
825 const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh;
826 const void *nxm = nfm + 1;
829 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
830 ds_put_cstr(s, nxm_s);
833 /* nx_match_to_string() doesn't print priority. */
834 need_priority = true;
836 cls_rule_format(&fm.cr, s);
838 /* cls_rule_format() does print priority. */
839 need_priority = false;
842 if (ds_last(s) != ' ') {
845 if (fm.cookie != htonll(0)) {
846 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.cookie));
848 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
849 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
851 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
852 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
854 if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
855 ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
857 if (fm.buffer_id != UINT32_MAX) {
858 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
861 uint16_t flags = fm.flags;
863 if (flags & OFPFF_SEND_FLOW_REM) {
864 ds_put_cstr(s, "send_flow_rem ");
866 if (flags & OFPFF_CHECK_OVERLAP) {
867 ds_put_cstr(s, "check_overlap ");
869 if (flags & OFPFF_EMERG) {
870 ds_put_cstr(s, "emerg ");
873 flags &= ~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG);
875 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
879 ofp_print_actions(s, fm.actions, fm.n_actions);
883 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
885 ds_put_format(string, "%u", sec);
887 ds_put_format(string, ".%09u", nsec);
888 while (string->string[string->length - 1] == '0') {
892 ds_put_char(string, 's');
896 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason)
901 case OFPRR_IDLE_TIMEOUT:
903 case OFPRR_HARD_TIMEOUT:
908 sprintf(s, "%d", (int) reason);
914 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
916 struct ofputil_flow_removed fr;
919 error = ofputil_decode_flow_removed(&fr, oh);
921 ofp_print_error(string, error);
925 ds_put_char(string, ' ');
926 cls_rule_format(&fr.rule, string);
928 ds_put_format(string, " reason=%s",
929 ofp_flow_removed_reason_to_string(fr.reason));
931 if (fr.cookie != htonll(0)) {
932 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
934 ds_put_cstr(string, " duration");
935 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
936 ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
937 fr.idle_timeout, fr.packet_count, fr.byte_count);
941 ofp_print_port_mod(struct ds *string, const struct ofp_port_mod *opm)
943 ds_put_format(string, "port: %d: addr:"ETH_ADDR_FMT", config: %#x, mask:%#x\n",
944 ntohs(opm->port_no), ETH_ADDR_ARGS(opm->hw_addr),
945 ntohl(opm->config), ntohl(opm->mask));
946 ds_put_format(string, " advertise: ");
947 if (opm->advertise) {
948 ofp_print_port_features(string, ntohl(opm->advertise));
950 ds_put_format(string, "UNCHANGED\n");
955 ofp_print_error(struct ds *string, enum ofperr error)
957 if (string->length) {
958 ds_put_char(string, ' ');
960 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
964 ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
966 size_t len = ntohs(oem->header.length);
967 size_t payload_ofs, payload_len;
972 error = ofperr_decode_msg(&oem->header, &payload_ofs);
974 ds_put_cstr(string, "***decode error***");
975 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
979 ds_put_format(string, " %s\n", ofperr_get_name(error));
981 payload = (const uint8_t *) oem + payload_ofs;
982 payload_len = len - payload_ofs;
983 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
984 ds_put_printable(string, payload, payload_len);
986 s = ofp_to_string(payload, payload_len, 1);
987 ds_put_cstr(string, s);
993 ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
995 if (ops->reason == OFPPR_ADD) {
996 ds_put_format(string, " ADD:");
997 } else if (ops->reason == OFPPR_DELETE) {
998 ds_put_format(string, " DEL:");
999 } else if (ops->reason == OFPPR_MODIFY) {
1000 ds_put_format(string, " MOD:");
1003 ofp_print_phy_port(string, &ops->desc);
1007 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods)
1009 ds_put_char(string, '\n');
1010 ds_put_format(string, "Manufacturer: %.*s\n",
1011 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1012 ds_put_format(string, "Hardware: %.*s\n",
1013 (int) sizeof ods->hw_desc, ods->hw_desc);
1014 ds_put_format(string, "Software: %.*s\n",
1015 (int) sizeof ods->sw_desc, ods->sw_desc);
1016 ds_put_format(string, "Serial Num: %.*s\n",
1017 (int) sizeof ods->serial_num, ods->serial_num);
1018 ds_put_format(string, "DP Description: %.*s\n",
1019 (int) sizeof ods->dp_desc, ods->dp_desc);
1023 ofp_print_flow_stats_request(struct ds *string,
1024 const struct ofp_stats_msg *osm)
1026 struct ofputil_flow_stats_request fsr;
1029 error = ofputil_decode_flow_stats_request(&fsr, &osm->header);
1031 ofp_print_error(string, error);
1035 if (fsr.table_id != 0xff) {
1036 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1039 if (fsr.out_port != OFPP_NONE) {
1040 ds_put_cstr(string, " out_port=");
1041 ofputil_format_port(fsr.out_port, string);
1044 /* A flow stats request doesn't include a priority, but cls_rule_format()
1045 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1046 fsr.match.priority = OFP_DEFAULT_PRIORITY;
1048 ds_put_char(string, ' ');
1049 cls_rule_format(&fsr.match, string);
1053 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1057 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1059 struct ofputil_flow_stats fs;
1062 retval = ofputil_decode_flow_stats_reply(&fs, &b, true);
1064 if (retval != EOF) {
1065 ds_put_cstr(string, " ***parse error***");
1070 ds_put_char(string, '\n');
1072 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1074 ofp_print_duration(string, fs.duration_sec, fs.duration_nsec);
1075 ds_put_format(string, ", table=%"PRIu8", ", fs.table_id);
1076 ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count);
1077 ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count);
1078 if (fs.idle_timeout != OFP_FLOW_PERMANENT) {
1079 ds_put_format(string, "idle_timeout=%"PRIu16",", fs.idle_timeout);
1081 if (fs.hard_timeout != OFP_FLOW_PERMANENT) {
1082 ds_put_format(string, "hard_timeout=%"PRIu16",", fs.hard_timeout);
1084 if (fs.idle_age >= 0) {
1085 ds_put_format(string, "idle_age=%d,", fs.idle_age);
1087 if (fs.hard_age >= 0 && fs.hard_age != fs.duration_sec) {
1088 ds_put_format(string, "hard_age=%d,", fs.hard_age);
1091 cls_rule_format(&fs.rule, string);
1092 if (string->string[string->length - 1] != ' ') {
1093 ds_put_char(string, ' ');
1095 ofp_print_actions(string, fs.actions, fs.n_actions);
1100 ofp_print_ofpst_aggregate_reply(struct ds *string,
1101 const struct ofp_aggregate_stats_reply *asr)
1103 ds_put_format(string, " packet_count=%"PRIu64,
1104 ntohll(get_32aligned_be64(&asr->packet_count)));
1105 ds_put_format(string, " byte_count=%"PRIu64,
1106 ntohll(get_32aligned_be64(&asr->byte_count)));
1107 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1111 ofp_print_nxst_aggregate_reply(struct ds *string,
1112 const struct nx_aggregate_stats_reply *nasr)
1114 ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count));
1115 ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count));
1116 ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count));
1119 static void print_port_stat(struct ds *string, const char *leader,
1120 const ovs_32aligned_be64 *statp, int more)
1122 uint64_t stat = ntohll(get_32aligned_be64(statp));
1124 ds_put_cstr(string, leader);
1125 if (stat != UINT64_MAX) {
1126 ds_put_format(string, "%"PRIu64, stat);
1128 ds_put_char(string, '?');
1131 ds_put_cstr(string, ", ");
1133 ds_put_cstr(string, "\n");
1138 ofp_print_ofpst_port_request(struct ds *string,
1139 const struct ofp_port_stats_request *psr)
1141 ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
1145 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1148 const struct ofp_port_stats *ps = ofputil_stats_body(oh);
1149 size_t n = ofputil_stats_body_len(oh) / sizeof *ps;
1150 ds_put_format(string, " %zu ports\n", n);
1151 if (verbosity < 1) {
1156 ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no));
1158 ds_put_cstr(string, "rx ");
1159 print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1160 print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1161 print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1162 print_port_stat(string, "errs=", &ps->rx_errors, 1);
1163 print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1164 print_port_stat(string, "over=", &ps->rx_over_err, 1);
1165 print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
1167 ds_put_cstr(string, " tx ");
1168 print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1169 print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1170 print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1171 print_port_stat(string, "errs=", &ps->tx_errors, 1);
1172 print_port_stat(string, "coll=", &ps->collisions, 0);
1177 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1180 const struct ofp_table_stats *ts = ofputil_stats_body(oh);
1181 size_t n = ofputil_stats_body_len(oh) / sizeof *ts;
1182 ds_put_format(string, " %zu tables\n", n);
1183 if (verbosity < 1) {
1188 char name[OFP_MAX_TABLE_NAME_LEN + 1];
1189 ovs_strlcpy(name, ts->name, sizeof name);
1191 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1192 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1193 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1194 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1195 ds_put_cstr(string, " ");
1196 ds_put_format(string, "lookup=%"PRIu64", ",
1197 ntohll(get_32aligned_be64(&ts->lookup_count)));
1198 ds_put_format(string, "matched=%"PRIu64"\n",
1199 ntohll(get_32aligned_be64(&ts->matched_count)));
1204 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1206 if (queue_id == OFPQ_ALL) {
1207 ds_put_cstr(string, "ALL");
1209 ds_put_format(string, "%"PRIu32, queue_id);
1214 ofp_print_ofpst_queue_request(struct ds *string,
1215 const struct ofp_queue_stats_request *qsr)
1217 ds_put_cstr(string, "port=");
1218 ofputil_format_port(ntohs(qsr->port_no), string);
1220 ds_put_cstr(string, " queue=");
1221 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1225 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1228 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1229 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
1230 ds_put_format(string, " %zu queues\n", n);
1231 if (verbosity < 1) {
1236 ds_put_cstr(string, " port ");
1237 ofputil_format_port(ntohs(qs->port_no), string);
1238 ds_put_cstr(string, " queue ");
1239 ofp_print_queue_name(string, ntohl(qs->queue_id));
1240 ds_put_cstr(string, ": ");
1242 print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1243 print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1244 print_port_stat(string, "errors=", &qs->tx_errors, 0);
1249 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1251 const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh;
1254 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1260 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1262 const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh;
1265 uint16_t flags = ntohs(srp->flags);
1267 ds_put_cstr(string, " flags=");
1268 if (flags & OFPSF_REPLY_MORE) {
1269 ds_put_cstr(string, "[more]");
1270 flags &= ~OFPSF_REPLY_MORE;
1273 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1280 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1282 size_t len = ntohs(oh->length);
1284 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1285 if (verbosity > 1) {
1286 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1291 ofp_print_nxt_role_message(struct ds *string,
1292 const struct nx_role_request *nrr)
1294 unsigned int role = ntohl(nrr->role);
1296 ds_put_cstr(string, " role=");
1297 if (role == NX_ROLE_OTHER) {
1298 ds_put_cstr(string, "other");
1299 } else if (role == NX_ROLE_MASTER) {
1300 ds_put_cstr(string, "master");
1301 } else if (role == NX_ROLE_SLAVE) {
1302 ds_put_cstr(string, "slave");
1304 ds_put_format(string, "%u", role);
1309 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1310 const struct nx_flow_mod_table_id *nfmti)
1312 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1316 ofp_print_nxt_set_flow_format(struct ds *string,
1317 const struct nx_set_flow_format *nsff)
1319 uint32_t format = ntohl(nsff->format);
1321 ds_put_cstr(string, " format=");
1322 if (ofputil_flow_format_is_valid(format)) {
1323 ds_put_cstr(string, ofputil_flow_format_to_string(format));
1325 ds_put_format(string, "%"PRIu32, format);
1330 ofp_print_nxt_set_packet_in_format(struct ds *string,
1331 const struct nx_set_packet_in_format *nspf)
1333 uint32_t format = ntohl(nspf->format);
1335 ds_put_cstr(string, " format=");
1336 if (ofputil_packet_in_format_is_valid(format)) {
1337 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1339 ds_put_format(string, "%"PRIu32, format);
1344 ofp_port_reason_to_string(enum ofp_port_reason reason)
1359 sprintf(s, "%d", (int) reason);
1365 ofp_print_nxt_set_async_config(struct ds *string,
1366 const struct nx_async_config *nac)
1370 for (i = 0; i < 2; i++) {
1373 ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
1375 ds_put_cstr(string, " PACKET_IN:");
1376 for (j = 0; j < 32; j++) {
1377 if (nac->packet_in_mask[i] & htonl(1u << j)) {
1378 ds_put_format(string, " %s",
1379 ofputil_packet_in_reason_to_string(j));
1382 if (!nac->packet_in_mask[i]) {
1383 ds_put_cstr(string, " (off)");
1385 ds_put_char(string, '\n');
1387 ds_put_cstr(string, " PORT_STATUS:");
1388 for (j = 0; j < 32; j++) {
1389 if (nac->port_status_mask[i] & htonl(1u << j)) {
1390 ds_put_format(string, " %s", ofp_port_reason_to_string(j));
1393 if (!nac->port_status_mask[i]) {
1394 ds_put_cstr(string, " (off)");
1396 ds_put_char(string, '\n');
1398 ds_put_cstr(string, " FLOW_REMOVED:");
1399 for (j = 0; j < 32; j++) {
1400 if (nac->flow_removed_mask[i] & htonl(1u << j)) {
1401 ds_put_format(string, " %s",
1402 ofp_flow_removed_reason_to_string(j));
1405 if (!nac->flow_removed_mask[i]) {
1406 ds_put_cstr(string, " (off)");
1408 ds_put_char(string, '\n');
1413 ofp_print_nxt_set_controller_id(struct ds *string,
1414 const struct nx_controller_id *nci)
1416 ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
1420 ofp_to_string__(const struct ofp_header *oh,
1421 const struct ofputil_msg_type *type, struct ds *string,
1424 enum ofputil_msg_code code;
1425 const void *msg = oh;
1427 ds_put_format(string, "%s (xid=0x%"PRIx32"):",
1428 ofputil_msg_type_name(type), ntohl(oh->xid));
1430 code = ofputil_msg_type_code(type);
1432 case OFPUTIL_MSG_INVALID:
1435 case OFPUTIL_OFPT_HELLO:
1436 ds_put_char(string, '\n');
1437 ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1441 case OFPUTIL_OFPT_ERROR:
1442 ofp_print_error_msg(string, msg);
1445 case OFPUTIL_OFPT_ECHO_REQUEST:
1446 case OFPUTIL_OFPT_ECHO_REPLY:
1447 ofp_print_echo(string, oh, verbosity);
1450 case OFPUTIL_OFPT_FEATURES_REQUEST:
1453 case OFPUTIL_OFPT_FEATURES_REPLY:
1454 ofp_print_switch_features(string, msg);
1457 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1460 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1461 case OFPUTIL_OFPT_SET_CONFIG:
1462 ofp_print_switch_config(string, msg);
1465 case OFPUTIL_OFPT_PACKET_IN:
1466 case OFPUTIL_NXT_PACKET_IN:
1467 ofp_print_packet_in(string, msg, verbosity);
1470 case OFPUTIL_OFPT_FLOW_REMOVED:
1471 case OFPUTIL_NXT_FLOW_REMOVED:
1472 ofp_print_flow_removed(string, msg);
1475 case OFPUTIL_OFPT_PORT_STATUS:
1476 ofp_print_port_status(string, msg);
1479 case OFPUTIL_OFPT_PACKET_OUT:
1480 ofp_print_packet_out(string, msg, verbosity);
1483 case OFPUTIL_OFPT_FLOW_MOD:
1484 case OFPUTIL_NXT_FLOW_MOD:
1485 ofp_print_flow_mod(string, msg, code, verbosity);
1488 case OFPUTIL_OFPT_PORT_MOD:
1489 ofp_print_port_mod(string, msg);
1492 case OFPUTIL_OFPT_BARRIER_REQUEST:
1493 case OFPUTIL_OFPT_BARRIER_REPLY:
1496 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1497 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1501 case OFPUTIL_OFPST_DESC_REQUEST:
1502 ofp_print_stats_request(string, oh);
1505 case OFPUTIL_OFPST_FLOW_REQUEST:
1506 case OFPUTIL_NXST_FLOW_REQUEST:
1507 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
1508 case OFPUTIL_NXST_AGGREGATE_REQUEST:
1509 ofp_print_stats_request(string, oh);
1510 ofp_print_flow_stats_request(string, msg);
1513 case OFPUTIL_OFPST_TABLE_REQUEST:
1514 ofp_print_stats_request(string, oh);
1517 case OFPUTIL_OFPST_PORT_REQUEST:
1518 ofp_print_stats_request(string, oh);
1519 ofp_print_ofpst_port_request(string, msg);
1522 case OFPUTIL_OFPST_QUEUE_REQUEST:
1523 ofp_print_stats_request(string, oh);
1524 ofp_print_ofpst_queue_request(string, msg);
1527 case OFPUTIL_OFPST_DESC_REPLY:
1528 ofp_print_stats_reply(string, oh);
1529 ofp_print_ofpst_desc_reply(string, msg);
1532 case OFPUTIL_OFPST_FLOW_REPLY:
1533 case OFPUTIL_NXST_FLOW_REPLY:
1534 ofp_print_stats_reply(string, oh);
1535 ofp_print_flow_stats_reply(string, oh);
1538 case OFPUTIL_OFPST_QUEUE_REPLY:
1539 ofp_print_stats_reply(string, oh);
1540 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1543 case OFPUTIL_OFPST_PORT_REPLY:
1544 ofp_print_stats_reply(string, oh);
1545 ofp_print_ofpst_port_reply(string, oh, verbosity);
1548 case OFPUTIL_OFPST_TABLE_REPLY:
1549 ofp_print_stats_reply(string, oh);
1550 ofp_print_ofpst_table_reply(string, oh, verbosity);
1553 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1554 ofp_print_stats_reply(string, oh);
1555 ofp_print_ofpst_aggregate_reply(string, msg);
1558 case OFPUTIL_NXT_ROLE_REQUEST:
1559 case OFPUTIL_NXT_ROLE_REPLY:
1560 ofp_print_nxt_role_message(string, msg);
1563 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID:
1564 ofp_print_nxt_flow_mod_table_id(string, msg);
1567 case OFPUTIL_NXT_SET_FLOW_FORMAT:
1568 ofp_print_nxt_set_flow_format(string, msg);
1571 case OFPUTIL_NXT_SET_PACKET_IN_FORMAT:
1572 ofp_print_nxt_set_packet_in_format(string, msg);
1575 case OFPUTIL_NXT_FLOW_AGE:
1578 case OFPUTIL_NXT_SET_CONTROLLER_ID:
1579 ofp_print_nxt_set_controller_id(string, msg);
1582 case OFPUTIL_NXT_SET_ASYNC_CONFIG:
1583 ofp_print_nxt_set_async_config(string, msg);
1586 case OFPUTIL_NXST_AGGREGATE_REPLY:
1587 ofp_print_stats_reply(string, oh);
1588 ofp_print_nxst_aggregate_reply(string, msg);
1593 /* Composes and returns a string representing the OpenFlow packet of 'len'
1594 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1595 * verbosity and higher numbers increase verbosity. The caller is responsible
1596 * for freeing the string. */
1598 ofp_to_string(const void *oh_, size_t len, int verbosity)
1600 struct ds string = DS_EMPTY_INITIALIZER;
1601 const struct ofp_header *oh = oh_;
1604 ds_put_cstr(&string, "OpenFlow message is empty\n");
1605 } else if (len < sizeof(struct ofp_header)) {
1606 ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1608 } else if (ntohs(oh->length) > len) {
1609 ds_put_format(&string,
1610 "(***truncated to %zu bytes from %"PRIu16"***)\n",
1611 len, ntohs(oh->length));
1612 } else if (ntohs(oh->length) < len) {
1613 ds_put_format(&string,
1614 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1615 ntohs(oh->length), len);
1617 const struct ofputil_msg_type *type;
1620 error = ofputil_decode_msg_type(oh, &type);
1622 ofp_to_string__(oh, type, &string, verbosity);
1623 if (verbosity >= 5) {
1624 if (ds_last(&string) != '\n') {
1625 ds_put_char(&string, '\n');
1627 ds_put_hex_dump(&string, oh, len, 0, true);
1629 if (ds_last(&string) != '\n') {
1630 ds_put_char(&string, '\n');
1632 return ds_steal_cstr(&string);
1635 ofp_print_error(&string, error);
1637 ds_put_hex_dump(&string, oh, len, 0, true);
1638 return ds_steal_cstr(&string);
1641 /* Returns the name for the specified OpenFlow message type as a string,
1642 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1643 * hex number, e.g. "0x55".
1645 * The caller must free the returned string when it is no longer needed. */
1647 ofp_message_type_to_string(uint8_t type)
1658 case OFPT_ECHO_REQUEST:
1659 name = "ECHO_REQUEST";
1661 case OFPT_ECHO_REPLY:
1662 name = "ECHO_REPLY";
1667 case OFPT_FEATURES_REQUEST:
1668 name = "FEATURES_REQUEST";
1670 case OFPT_FEATURES_REPLY:
1671 name = "FEATURES_REPLY";
1673 case OFPT_GET_CONFIG_REQUEST:
1674 name = "GET_CONFIG_REQUEST";
1676 case OFPT_GET_CONFIG_REPLY:
1677 name = "GET_CONFIG_REPLY";
1679 case OFPT_SET_CONFIG:
1680 name = "SET_CONFIG";
1682 case OFPT_PACKET_IN:
1685 case OFPT_FLOW_REMOVED:
1686 name = "FLOW_REMOVED";
1688 case OFPT_PORT_STATUS:
1689 name = "PORT_STATUS";
1691 case OFPT_PACKET_OUT:
1692 name = "PACKET_OUT";
1700 case OFPT_STATS_REQUEST:
1701 name = "STATS_REQUEST";
1703 case OFPT_STATS_REPLY:
1704 name = "STATS_REPLY";
1706 case OFPT_BARRIER_REQUEST:
1707 name = "BARRIER_REQUEST";
1709 case OFPT_BARRIER_REPLY:
1710 name = "BARRIER_REPLY";
1712 case OFPT_QUEUE_GET_CONFIG_REQUEST:
1713 name = "QUEUE_GET_CONFIG_REQUEST";
1715 case OFPT_QUEUE_GET_CONFIG_REPLY:
1716 name = "QUEUE_GET_CONFIG_REPLY";
1723 return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
1727 print_and_free(FILE *stream, char *string)
1729 fputs(string, stream);
1733 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1734 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1735 * numbers increase verbosity. */
1737 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1739 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1742 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1743 * 'data' to 'stream'. */
1745 ofp_print_packet(FILE *stream, const void *data, size_t len)
1747 print_and_free(stream, ofp_packet_to_string(data, len));