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 switch (pin.reason) {
126 ds_put_cstr(string, " (via no_match)");
129 ds_put_cstr(string, " (via action)");
131 case OFPR_INVALID_TTL:
132 ds_put_cstr(string, " (via invalid_ttl)");
135 ds_put_format(string, " (***reason %"PRIu8"***)", pin.reason);
139 ds_put_format(string, " data_len=%zu", pin.packet_len);
140 if (pin.buffer_id == UINT32_MAX) {
141 ds_put_format(string, " (unbuffered)");
142 if (pin.total_len != pin.packet_len) {
143 ds_put_format(string, " (***total_len != data_len***)");
146 ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id);
147 if (pin.total_len < pin.packet_len) {
148 ds_put_format(string, " (***total_len < data_len***)");
151 ds_put_char(string, '\n');
154 char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
155 ds_put_cstr(string, packet);
161 print_note(struct ds *string, const struct nx_action_note *nan)
166 ds_put_cstr(string, "note:");
167 len = ntohs(nan->len) - offsetof(struct nx_action_note, note);
168 for (i = 0; i < len; i++) {
170 ds_put_char(string, '.');
172 ds_put_format(string, "%02"PRIx8, nan->note[i]);
177 ofp_print_action(struct ds *s, const union ofp_action *a,
178 enum ofputil_action_code code)
180 const struct ofp_action_enqueue *oae;
181 const struct ofp_action_dl_addr *oada;
182 const struct nx_action_set_tunnel64 *nast64;
183 const struct nx_action_set_tunnel *nast;
184 const struct nx_action_set_queue *nasq;
185 const struct nx_action_resubmit *nar;
186 const struct nx_action_reg_move *move;
187 const struct nx_action_reg_load *load;
188 const struct nx_action_multipath *nam;
189 const struct nx_action_autopath *naa;
190 const struct nx_action_output_reg *naor;
191 struct mf_subfield subfield;
195 case OFPUTIL_OFPAT_OUTPUT:
196 port = ntohs(a->output.port);
197 if (port < OFPP_MAX) {
198 ds_put_format(s, "output:%"PRIu16, port);
200 ofputil_format_port(port, s);
201 if (port == OFPP_CONTROLLER) {
202 if (a->output.max_len != htons(0)) {
203 ds_put_format(s, ":%"PRIu16, ntohs(a->output.max_len));
205 ds_put_cstr(s, ":all");
211 case OFPUTIL_OFPAT_ENQUEUE:
212 oae = (const struct ofp_action_enqueue *) a;
213 ds_put_format(s, "enqueue:");
214 ofputil_format_port(ntohs(oae->port), s);
215 ds_put_format(s, "q%"PRIu32, ntohl(oae->queue_id));
218 case OFPUTIL_OFPAT_SET_VLAN_VID:
219 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
220 ntohs(a->vlan_vid.vlan_vid));
223 case OFPUTIL_OFPAT_SET_VLAN_PCP:
224 ds_put_format(s, "mod_vlan_pcp:%"PRIu8, a->vlan_pcp.vlan_pcp);
227 case OFPUTIL_OFPAT_STRIP_VLAN:
228 ds_put_cstr(s, "strip_vlan");
231 case OFPUTIL_OFPAT_SET_DL_SRC:
232 oada = (const struct ofp_action_dl_addr *) a;
233 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
234 ETH_ADDR_ARGS(oada->dl_addr));
237 case OFPUTIL_OFPAT_SET_DL_DST:
238 oada = (const struct ofp_action_dl_addr *) a;
239 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
240 ETH_ADDR_ARGS(oada->dl_addr));
243 case OFPUTIL_OFPAT_SET_NW_SRC:
244 ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
247 case OFPUTIL_OFPAT_SET_NW_DST:
248 ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
251 case OFPUTIL_OFPAT_SET_NW_TOS:
252 ds_put_format(s, "mod_nw_tos:%d", a->nw_tos.nw_tos);
255 case OFPUTIL_OFPAT_SET_TP_SRC:
256 ds_put_format(s, "mod_tp_src:%d", ntohs(a->tp_port.tp_port));
259 case OFPUTIL_OFPAT_SET_TP_DST:
260 ds_put_format(s, "mod_tp_dst:%d", ntohs(a->tp_port.tp_port));
263 case OFPUTIL_NXAST_RESUBMIT:
264 nar = (struct nx_action_resubmit *)a;
265 ds_put_format(s, "resubmit:");
266 ofputil_format_port(ntohs(nar->in_port), s);
269 case OFPUTIL_NXAST_RESUBMIT_TABLE:
270 nar = (struct nx_action_resubmit *)a;
271 ds_put_format(s, "resubmit(");
272 if (nar->in_port != htons(OFPP_IN_PORT)) {
273 ofputil_format_port(ntohs(nar->in_port), s);
276 if (nar->table != 255) {
277 ds_put_format(s, "%"PRIu8, nar->table);
282 case OFPUTIL_NXAST_SET_TUNNEL:
283 nast = (struct nx_action_set_tunnel *)a;
284 ds_put_format(s, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id));
287 case OFPUTIL_NXAST_SET_QUEUE:
288 nasq = (struct nx_action_set_queue *)a;
289 ds_put_format(s, "set_queue:%u", ntohl(nasq->queue_id));
292 case OFPUTIL_NXAST_POP_QUEUE:
293 ds_put_cstr(s, "pop_queue");
296 case OFPUTIL_NXAST_NOTE:
297 print_note(s, (const struct nx_action_note *) a);
300 case OFPUTIL_NXAST_REG_MOVE:
301 move = (const struct nx_action_reg_move *) a;
302 nxm_format_reg_move(move, s);
305 case OFPUTIL_NXAST_REG_LOAD:
306 load = (const struct nx_action_reg_load *) a;
307 nxm_format_reg_load(load, s);
310 case OFPUTIL_NXAST_SET_TUNNEL64:
311 nast64 = (const struct nx_action_set_tunnel64 *) a;
312 ds_put_format(s, "set_tunnel64:%#"PRIx64,
313 ntohll(nast64->tun_id));
316 case OFPUTIL_NXAST_MULTIPATH:
317 nam = (const struct nx_action_multipath *) a;
318 multipath_format(nam, s);
321 case OFPUTIL_NXAST_AUTOPATH:
322 naa = (const struct nx_action_autopath *)a;
323 ds_put_format(s, "autopath(%u,", ntohl(naa->id));
324 nxm_decode(&subfield, naa->dst, naa->ofs_nbits);
325 mf_format_subfield(&subfield, s);
329 case OFPUTIL_NXAST_BUNDLE:
330 case OFPUTIL_NXAST_BUNDLE_LOAD:
331 bundle_format((const struct nx_action_bundle *) a, s);
334 case OFPUTIL_NXAST_OUTPUT_REG:
335 naor = (const struct nx_action_output_reg *) a;
336 ds_put_cstr(s, "output:");
337 nxm_decode(&subfield, naor->src, naor->ofs_nbits);
338 mf_format_subfield(&subfield, s);
341 case OFPUTIL_NXAST_LEARN:
342 learn_format((const struct nx_action_learn *) a, s);
345 case OFPUTIL_NXAST_DEC_TTL:
346 ds_put_cstr(s, "dec_ttl");
349 case OFPUTIL_NXAST_EXIT:
350 ds_put_cstr(s, "exit");
359 ofp_print_actions(struct ds *string, const union ofp_action *actions,
362 const union ofp_action *a;
365 ds_put_cstr(string, "actions=");
367 ds_put_cstr(string, "drop");
370 OFPUTIL_ACTION_FOR_EACH (a, left, actions, n_actions) {
371 int code = ofputil_decode_action(a);
374 ds_put_cstr(string, ",");
376 ofp_print_action(string, a, code);
378 ofp_print_error(string, -code);
382 ds_put_format(string, " ***%zu leftover bytes following actions",
388 ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
391 struct ofputil_packet_out po;
394 error = ofputil_decode_packet_out(&po, opo);
396 ofp_print_error(string, error);
400 ds_put_cstr(string, " in_port=");
401 ofputil_format_port(po.in_port, string);
403 ds_put_char(string, ' ');
404 ofp_print_actions(string, po.actions, po.n_actions);
406 if (po.buffer_id == UINT32_MAX) {
407 ds_put_format(string, " data_len=%d", po.packet_len);
408 if (verbosity > 0 && po.packet_len > 0) {
409 char *packet = ofp_packet_to_string(po.packet, po.packet_len);
410 ds_put_char(string, '\n');
411 ds_put_cstr(string, packet);
415 ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
417 ds_put_char(string, '\n');
420 /* qsort comparison function. */
422 compare_ports(const void *a_, const void *b_)
424 const struct ofp_phy_port *a = a_;
425 const struct ofp_phy_port *b = b_;
426 uint16_t ap = ntohs(a->port_no);
427 uint16_t bp = ntohs(b->port_no);
429 return ap < bp ? -1 : ap > bp;
438 ofp_print_bit_names(struct ds *string, uint32_t bits,
439 const struct bit_name bit_names[])
444 ds_put_cstr(string, "0");
448 for (; bits && bit_names->name; bit_names++) {
449 if (bits & bit_names->bit) {
451 ds_put_char(string, ' ');
453 ds_put_cstr(string, bit_names->name);
454 bits &= ~bit_names->bit;
460 ds_put_char(string, ' ');
462 ds_put_format(string, "0x%"PRIx32, bits);
467 ofp_print_port_features(struct ds *string, uint32_t features)
469 static const struct bit_name feature_bits[] = {
470 { OFPPF_10MB_HD, "10MB-HD" },
471 { OFPPF_10MB_FD, "10MB-FD" },
472 { OFPPF_100MB_HD, "100MB-HD" },
473 { OFPPF_100MB_FD, "100MB-FD" },
474 { OFPPF_1GB_HD, "1GB-HD" },
475 { OFPPF_1GB_FD, "1GB-FD" },
476 { OFPPF_10GB_FD, "10GB-FD" },
477 { OFPPF_COPPER, "COPPER" },
478 { OFPPF_FIBER, "FIBER" },
479 { OFPPF_AUTONEG, "AUTO_NEG" },
480 { OFPPF_PAUSE, "AUTO_PAUSE" },
481 { OFPPF_PAUSE_ASYM, "AUTO_PAUSE_ASYM" },
485 ofp_print_bit_names(string, features, feature_bits);
486 ds_put_char(string, '\n');
490 ofp_print_port_config(struct ds *string, uint32_t config)
492 static const struct bit_name config_bits[] = {
493 { OFPPC_PORT_DOWN, "PORT_DOWN" },
494 { OFPPC_NO_STP, "NO_STP" },
495 { OFPPC_NO_RECV, "NO_RECV" },
496 { OFPPC_NO_RECV_STP, "NO_RECV_STP" },
497 { OFPPC_NO_FLOOD, "NO_FLOOD" },
498 { OFPPC_NO_FWD, "NO_FWD" },
499 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
503 ofp_print_bit_names(string, config, config_bits);
504 ds_put_char(string, '\n');
508 ofp_print_port_state(struct ds *string, uint32_t state)
510 static const struct bit_name state_bits[] = {
511 { OFPPS_LINK_DOWN, "LINK_DOWN" },
516 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
517 * pattern. We have to special case it.
519 * OVS doesn't support STP, so this field will always be 0 if we are
520 * talking to OVS, so we'd always print STP_LISTEN in that case.
521 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
522 * avoid confusing users. */
523 stp_state = state & OFPPS_STP_MASK;
525 ds_put_cstr(string, (stp_state == OFPPS_STP_LEARN ? "STP_LEARN"
526 : stp_state == OFPPS_STP_FORWARD ? "STP_FORWARD"
528 state &= ~OFPPS_STP_MASK;
530 ofp_print_bit_names(string, state, state_bits);
533 ofp_print_bit_names(string, state, state_bits);
535 ds_put_char(string, '\n');
539 ofp_print_phy_port(struct ds *string, const struct ofp_phy_port *port)
541 char name[OFP_MAX_PORT_NAME_LEN];
544 memcpy(name, port->name, sizeof name);
545 for (j = 0; j < sizeof name - 1; j++) {
546 if (!isprint((unsigned char) name[j])) {
552 ds_put_char(string, ' ');
553 ofputil_format_port(ntohs(port->port_no), string);
554 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
555 name, ETH_ADDR_ARGS(port->hw_addr));
557 ds_put_cstr(string, " config: ");
558 ofp_print_port_config(string, ntohl(port->config));
560 ds_put_cstr(string, " state: ");
561 ofp_print_port_state(string, ntohl(port->state));
564 ds_put_format(string, " current: ");
565 ofp_print_port_features(string, ntohl(port->curr));
567 if (port->advertised) {
568 ds_put_format(string, " advertised: ");
569 ofp_print_port_features(string, ntohl(port->advertised));
571 if (port->supported) {
572 ds_put_format(string, " supported: ");
573 ofp_print_port_features(string, ntohl(port->supported));
576 ds_put_format(string, " peer: ");
577 ofp_print_port_features(string, ntohl(port->peer));
582 ofp_print_switch_features(struct ds *string,
583 const struct ofp_switch_features *osf)
585 size_t len = ntohs(osf->header.length);
586 struct ofp_phy_port *port_list;
590 ds_put_format(string, " ver:0x%x, dpid:%016"PRIx64"\n",
591 osf->header.version, ntohll(osf->datapath_id));
592 ds_put_format(string, "n_tables:%d, n_buffers:%d\n", osf->n_tables,
593 ntohl(osf->n_buffers));
594 ds_put_format(string, "features: capabilities:%#x, actions:%#x\n",
595 ntohl(osf->capabilities), ntohl(osf->actions));
597 n_ports = (len - sizeof *osf) / sizeof *osf->ports;
599 port_list = xmemdup(osf->ports, len - sizeof *osf);
600 qsort(port_list, n_ports, sizeof *port_list, compare_ports);
601 for (i = 0; i < n_ports; i++) {
602 ofp_print_phy_port(string, &port_list[i]);
608 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
610 enum ofp_config_flags flags;
612 flags = ntohs(osc->flags);
614 ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags));
615 flags &= ~OFPC_FRAG_MASK;
617 if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) {
618 ds_put_format(string, " invalid_ttl_to_controller");
619 flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER;
623 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
626 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
629 static void print_wild(struct ds *string, const char *leader, int is_wild,
630 int verbosity, const char *format, ...)
631 __attribute__((format(printf, 5, 6)));
633 static void print_wild(struct ds *string, const char *leader, int is_wild,
634 int verbosity, const char *format, ...)
636 if (is_wild && verbosity < 2) {
639 ds_put_cstr(string, leader);
643 va_start(args, format);
644 ds_put_format_valist(string, format, args);
647 ds_put_char(string, '*');
649 ds_put_char(string, ',');
653 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
654 uint32_t wild_bits, int verbosity)
656 if (wild_bits >= 32 && verbosity < 2) {
659 ds_put_cstr(string, leader);
660 if (wild_bits < 32) {
661 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
663 ds_put_format(string, "/%d", 32 - wild_bits);
666 ds_put_char(string, '*');
668 ds_put_char(string, ',');
672 ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
674 char *s = ofp_match_to_string(om, verbosity);
680 ofp_match_to_string(const struct ofp_match *om, int verbosity)
682 struct ds f = DS_EMPTY_INITIALIZER;
683 uint32_t w = ntohl(om->wildcards);
684 bool skip_type = false;
685 bool skip_proto = false;
687 if (!(w & OFPFW_DL_TYPE)) {
689 if (om->dl_type == htons(ETH_TYPE_IP)) {
690 if (!(w & OFPFW_NW_PROTO)) {
692 if (om->nw_proto == IPPROTO_ICMP) {
693 ds_put_cstr(&f, "icmp,");
694 } else if (om->nw_proto == IPPROTO_TCP) {
695 ds_put_cstr(&f, "tcp,");
696 } else if (om->nw_proto == IPPROTO_UDP) {
697 ds_put_cstr(&f, "udp,");
699 ds_put_cstr(&f, "ip,");
703 ds_put_cstr(&f, "ip,");
705 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
706 ds_put_cstr(&f, "arp,");
711 print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
712 "%d", ntohs(om->in_port));
713 print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
714 "%d", ntohs(om->dl_vlan));
715 print_wild(&f, "dl_vlan_pcp=", w & OFPFW_DL_VLAN_PCP, verbosity,
716 "%d", om->dl_vlan_pcp);
717 print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
718 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
719 print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
720 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
722 print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
723 "0x%04x", ntohs(om->dl_type));
725 print_ip_netmask(&f, "nw_src=", om->nw_src,
726 (w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
727 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
728 (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
730 if (om->dl_type == htons(ETH_TYPE_ARP)) {
731 print_wild(&f, "arp_op=", w & OFPFW_NW_PROTO, verbosity,
734 print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
738 print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
740 if (om->nw_proto == IPPROTO_ICMP) {
741 print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
742 "%d", ntohs(om->tp_src));
743 print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
744 "%d", ntohs(om->tp_dst));
746 print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
747 "%d", ntohs(om->tp_src));
748 print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
749 "%d", ntohs(om->tp_dst));
751 if (ds_last(&f) == ',') {
758 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
759 enum ofputil_msg_code code, int verbosity)
761 struct ofputil_flow_mod fm;
765 error = ofputil_decode_flow_mod(&fm, oh, true);
767 ofp_print_error(s, error);
772 switch (fm.command) {
774 ds_put_cstr(s, "ADD");
777 ds_put_cstr(s, "MOD");
779 case OFPFC_MODIFY_STRICT:
780 ds_put_cstr(s, "MOD_STRICT");
783 ds_put_cstr(s, "DEL");
785 case OFPFC_DELETE_STRICT:
786 ds_put_cstr(s, "DEL_STRICT");
789 ds_put_format(s, "cmd:%d", fm.command);
791 if (fm.table_id != 0) {
792 ds_put_format(s, " table:%d", fm.table_id);
796 if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) {
797 const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh;
798 ofp_print_match(s, &ofm->match, verbosity);
800 /* ofp_print_match() doesn't print priority. */
801 need_priority = true;
802 } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) {
803 const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh;
804 const void *nxm = nfm + 1;
807 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
808 ds_put_cstr(s, nxm_s);
811 /* nx_match_to_string() doesn't print priority. */
812 need_priority = true;
814 cls_rule_format(&fm.cr, s);
816 /* cls_rule_format() does print priority. */
817 need_priority = false;
820 if (ds_last(s) != ' ') {
823 if (fm.cookie != htonll(0)) {
824 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.cookie));
826 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
827 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
829 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
830 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
832 if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
833 ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
835 if (fm.buffer_id != UINT32_MAX) {
836 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
839 uint16_t flags = fm.flags;
841 if (flags & OFPFF_SEND_FLOW_REM) {
842 ds_put_cstr(s, "send_flow_rem ");
844 if (flags & OFPFF_CHECK_OVERLAP) {
845 ds_put_cstr(s, "check_overlap ");
847 if (flags & OFPFF_EMERG) {
848 ds_put_cstr(s, "emerg ");
851 flags &= ~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG);
853 ds_put_format(s, "flags:0x%"PRIx16" ", flags);
857 ofp_print_actions(s, fm.actions, fm.n_actions);
861 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
863 ds_put_format(string, "%u", sec);
865 ds_put_format(string, ".%09u", nsec);
866 while (string->string[string->length - 1] == '0') {
870 ds_put_char(string, 's');
874 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
876 struct ofputil_flow_removed fr;
879 error = ofputil_decode_flow_removed(&fr, oh);
881 ofp_print_error(string, error);
885 ds_put_char(string, ' ');
886 cls_rule_format(&fr.rule, string);
888 ds_put_cstr(string, " reason=");
890 case OFPRR_IDLE_TIMEOUT:
891 ds_put_cstr(string, "idle");
893 case OFPRR_HARD_TIMEOUT:
894 ds_put_cstr(string, "hard");
897 ds_put_cstr(string, "delete");
900 ds_put_format(string, "**%"PRIu8"**", fr.reason);
904 if (fr.cookie != htonll(0)) {
905 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
907 ds_put_cstr(string, " duration");
908 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
909 ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
910 fr.idle_timeout, fr.packet_count, fr.byte_count);
914 ofp_print_port_mod(struct ds *string, const struct ofp_port_mod *opm)
916 ds_put_format(string, "port: %d: addr:"ETH_ADDR_FMT", config: %#x, mask:%#x\n",
917 ntohs(opm->port_no), ETH_ADDR_ARGS(opm->hw_addr),
918 ntohl(opm->config), ntohl(opm->mask));
919 ds_put_format(string, " advertise: ");
920 if (opm->advertise) {
921 ofp_print_port_features(string, ntohl(opm->advertise));
923 ds_put_format(string, "UNCHANGED\n");
928 ofp_print_error(struct ds *string, enum ofperr error)
930 if (string->length) {
931 ds_put_char(string, ' ');
933 ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
937 ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
939 size_t len = ntohs(oem->header.length);
940 size_t payload_ofs, payload_len;
945 error = ofperr_decode_msg(&oem->header, &payload_ofs);
947 ds_put_cstr(string, "***decode error***");
948 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
952 ds_put_format(string, " %s\n", ofperr_get_name(error));
954 payload = (const uint8_t *) oem + payload_ofs;
955 payload_len = len - payload_ofs;
956 if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
957 ds_put_printable(string, payload, payload_len);
959 s = ofp_to_string(payload, payload_len, 1);
960 ds_put_cstr(string, s);
966 ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
968 if (ops->reason == OFPPR_ADD) {
969 ds_put_format(string, " ADD:");
970 } else if (ops->reason == OFPPR_DELETE) {
971 ds_put_format(string, " DEL:");
972 } else if (ops->reason == OFPPR_MODIFY) {
973 ds_put_format(string, " MOD:");
976 ofp_print_phy_port(string, &ops->desc);
980 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods)
982 ds_put_char(string, '\n');
983 ds_put_format(string, "Manufacturer: %.*s\n",
984 (int) sizeof ods->mfr_desc, ods->mfr_desc);
985 ds_put_format(string, "Hardware: %.*s\n",
986 (int) sizeof ods->hw_desc, ods->hw_desc);
987 ds_put_format(string, "Software: %.*s\n",
988 (int) sizeof ods->sw_desc, ods->sw_desc);
989 ds_put_format(string, "Serial Num: %.*s\n",
990 (int) sizeof ods->serial_num, ods->serial_num);
991 ds_put_format(string, "DP Description: %.*s\n",
992 (int) sizeof ods->dp_desc, ods->dp_desc);
996 ofp_print_flow_stats_request(struct ds *string,
997 const struct ofp_stats_msg *osm)
999 struct ofputil_flow_stats_request fsr;
1002 error = ofputil_decode_flow_stats_request(&fsr, &osm->header);
1004 ofp_print_error(string, error);
1008 if (fsr.table_id != 0xff) {
1009 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1012 if (fsr.out_port != OFPP_NONE) {
1013 ds_put_cstr(string, " out_port=");
1014 ofputil_format_port(fsr.out_port, string);
1017 /* A flow stats request doesn't include a priority, but cls_rule_format()
1018 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1019 fsr.match.priority = OFP_DEFAULT_PRIORITY;
1021 ds_put_char(string, ' ');
1022 cls_rule_format(&fsr.match, string);
1026 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1030 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1032 struct ofputil_flow_stats fs;
1035 retval = ofputil_decode_flow_stats_reply(&fs, &b, true);
1037 if (retval != EOF) {
1038 ds_put_cstr(string, " ***parse error***");
1043 ds_put_char(string, '\n');
1045 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1047 ofp_print_duration(string, fs.duration_sec, fs.duration_nsec);
1048 ds_put_format(string, ", table=%"PRIu8", ", fs.table_id);
1049 ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count);
1050 ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count);
1051 if (fs.idle_timeout != OFP_FLOW_PERMANENT) {
1052 ds_put_format(string, "idle_timeout=%"PRIu16",", fs.idle_timeout);
1054 if (fs.hard_timeout != OFP_FLOW_PERMANENT) {
1055 ds_put_format(string, "hard_timeout=%"PRIu16",", fs.hard_timeout);
1057 if (fs.idle_age >= 0) {
1058 ds_put_format(string, "idle_age=%d,", fs.idle_age);
1060 if (fs.hard_age >= 0 && fs.hard_age != fs.duration_sec) {
1061 ds_put_format(string, "hard_age=%d,", fs.hard_age);
1064 cls_rule_format(&fs.rule, string);
1065 if (string->string[string->length - 1] != ' ') {
1066 ds_put_char(string, ' ');
1068 ofp_print_actions(string, fs.actions, fs.n_actions);
1073 ofp_print_ofpst_aggregate_reply(struct ds *string,
1074 const struct ofp_aggregate_stats_reply *asr)
1076 ds_put_format(string, " packet_count=%"PRIu64,
1077 ntohll(get_32aligned_be64(&asr->packet_count)));
1078 ds_put_format(string, " byte_count=%"PRIu64,
1079 ntohll(get_32aligned_be64(&asr->byte_count)));
1080 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1084 ofp_print_nxst_aggregate_reply(struct ds *string,
1085 const struct nx_aggregate_stats_reply *nasr)
1087 ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count));
1088 ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count));
1089 ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count));
1092 static void print_port_stat(struct ds *string, const char *leader,
1093 const ovs_32aligned_be64 *statp, int more)
1095 uint64_t stat = ntohll(get_32aligned_be64(statp));
1097 ds_put_cstr(string, leader);
1098 if (stat != UINT64_MAX) {
1099 ds_put_format(string, "%"PRIu64, stat);
1101 ds_put_char(string, '?');
1104 ds_put_cstr(string, ", ");
1106 ds_put_cstr(string, "\n");
1111 ofp_print_ofpst_port_request(struct ds *string,
1112 const struct ofp_port_stats_request *psr)
1114 ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
1118 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1121 const struct ofp_port_stats *ps = ofputil_stats_body(oh);
1122 size_t n = ofputil_stats_body_len(oh) / sizeof *ps;
1123 ds_put_format(string, " %zu ports\n", n);
1124 if (verbosity < 1) {
1129 ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no));
1131 ds_put_cstr(string, "rx ");
1132 print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1133 print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1134 print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1135 print_port_stat(string, "errs=", &ps->rx_errors, 1);
1136 print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1137 print_port_stat(string, "over=", &ps->rx_over_err, 1);
1138 print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
1140 ds_put_cstr(string, " tx ");
1141 print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1142 print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1143 print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1144 print_port_stat(string, "errs=", &ps->tx_errors, 1);
1145 print_port_stat(string, "coll=", &ps->collisions, 0);
1150 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1153 const struct ofp_table_stats *ts = ofputil_stats_body(oh);
1154 size_t n = ofputil_stats_body_len(oh) / sizeof *ts;
1155 ds_put_format(string, " %zu tables\n", n);
1156 if (verbosity < 1) {
1161 char name[OFP_MAX_TABLE_NAME_LEN + 1];
1162 ovs_strlcpy(name, ts->name, sizeof name);
1164 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1165 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1166 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1167 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1168 ds_put_cstr(string, " ");
1169 ds_put_format(string, "lookup=%"PRIu64", ",
1170 ntohll(get_32aligned_be64(&ts->lookup_count)));
1171 ds_put_format(string, "matched=%"PRIu64"\n",
1172 ntohll(get_32aligned_be64(&ts->matched_count)));
1177 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1179 if (queue_id == OFPQ_ALL) {
1180 ds_put_cstr(string, "ALL");
1182 ds_put_format(string, "%"PRIu32, queue_id);
1187 ofp_print_ofpst_queue_request(struct ds *string,
1188 const struct ofp_queue_stats_request *qsr)
1190 ds_put_cstr(string, "port=");
1191 ofputil_format_port(ntohs(qsr->port_no), string);
1193 ds_put_cstr(string, " queue=");
1194 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1198 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1201 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1202 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
1203 ds_put_format(string, " %zu queues\n", n);
1204 if (verbosity < 1) {
1209 ds_put_cstr(string, " port ");
1210 ofputil_format_port(ntohs(qs->port_no), string);
1211 ds_put_cstr(string, " queue ");
1212 ofp_print_queue_name(string, ntohl(qs->queue_id));
1213 ds_put_cstr(string, ": ");
1215 print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1216 print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1217 print_port_stat(string, "errors=", &qs->tx_errors, 0);
1222 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1224 const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh;
1227 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1233 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1235 const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh;
1238 uint16_t flags = ntohs(srp->flags);
1240 ds_put_cstr(string, " flags=");
1241 if (flags & OFPSF_REPLY_MORE) {
1242 ds_put_cstr(string, "[more]");
1243 flags &= ~OFPSF_REPLY_MORE;
1246 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1253 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1255 size_t len = ntohs(oh->length);
1257 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1258 if (verbosity > 1) {
1259 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1264 ofp_print_nxt_role_message(struct ds *string,
1265 const struct nx_role_request *nrr)
1267 unsigned int role = ntohl(nrr->role);
1269 ds_put_cstr(string, " role=");
1270 if (role == NX_ROLE_OTHER) {
1271 ds_put_cstr(string, "other");
1272 } else if (role == NX_ROLE_MASTER) {
1273 ds_put_cstr(string, "master");
1274 } else if (role == NX_ROLE_SLAVE) {
1275 ds_put_cstr(string, "slave");
1277 ds_put_format(string, "%u", role);
1282 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1283 const struct nx_flow_mod_table_id *nfmti)
1285 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1289 ofp_print_nxt_set_flow_format(struct ds *string,
1290 const struct nx_set_flow_format *nsff)
1292 uint32_t format = ntohl(nsff->format);
1294 ds_put_cstr(string, " format=");
1295 if (ofputil_flow_format_is_valid(format)) {
1296 ds_put_cstr(string, ofputil_flow_format_to_string(format));
1298 ds_put_format(string, "%"PRIu32, format);
1303 ofp_print_nxt_set_packet_in_format(struct ds *string,
1304 const struct nx_set_packet_in_format *nspf)
1306 uint32_t format = ntohl(nspf->format);
1308 ds_put_cstr(string, " format=");
1309 if (ofputil_packet_in_format_is_valid(format)) {
1310 ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
1312 ds_put_format(string, "%"PRIu32, format);
1317 ofp_to_string__(const struct ofp_header *oh,
1318 const struct ofputil_msg_type *type, struct ds *string,
1321 enum ofputil_msg_code code;
1322 const void *msg = oh;
1324 ds_put_format(string, "%s (xid=0x%"PRIx32"):",
1325 ofputil_msg_type_name(type), ntohl(oh->xid));
1327 code = ofputil_msg_type_code(type);
1329 case OFPUTIL_MSG_INVALID:
1332 case OFPUTIL_OFPT_HELLO:
1333 ds_put_char(string, '\n');
1334 ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1338 case OFPUTIL_OFPT_ERROR:
1339 ofp_print_error_msg(string, msg);
1342 case OFPUTIL_OFPT_ECHO_REQUEST:
1343 case OFPUTIL_OFPT_ECHO_REPLY:
1344 ofp_print_echo(string, oh, verbosity);
1347 case OFPUTIL_OFPT_FEATURES_REQUEST:
1350 case OFPUTIL_OFPT_FEATURES_REPLY:
1351 ofp_print_switch_features(string, msg);
1354 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1357 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1358 case OFPUTIL_OFPT_SET_CONFIG:
1359 ofp_print_switch_config(string, msg);
1362 case OFPUTIL_OFPT_PACKET_IN:
1363 case OFPUTIL_NXT_PACKET_IN:
1364 ofp_print_packet_in(string, msg, verbosity);
1367 case OFPUTIL_OFPT_FLOW_REMOVED:
1368 case OFPUTIL_NXT_FLOW_REMOVED:
1369 ofp_print_flow_removed(string, msg);
1372 case OFPUTIL_OFPT_PORT_STATUS:
1373 ofp_print_port_status(string, msg);
1376 case OFPUTIL_OFPT_PACKET_OUT:
1377 ofp_print_packet_out(string, msg, verbosity);
1380 case OFPUTIL_OFPT_FLOW_MOD:
1381 case OFPUTIL_NXT_FLOW_MOD:
1382 ofp_print_flow_mod(string, msg, code, verbosity);
1385 case OFPUTIL_OFPT_PORT_MOD:
1386 ofp_print_port_mod(string, msg);
1389 case OFPUTIL_OFPT_BARRIER_REQUEST:
1390 case OFPUTIL_OFPT_BARRIER_REPLY:
1393 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1394 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1398 case OFPUTIL_OFPST_DESC_REQUEST:
1399 ofp_print_stats_request(string, oh);
1402 case OFPUTIL_OFPST_FLOW_REQUEST:
1403 case OFPUTIL_NXST_FLOW_REQUEST:
1404 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
1405 case OFPUTIL_NXST_AGGREGATE_REQUEST:
1406 ofp_print_stats_request(string, oh);
1407 ofp_print_flow_stats_request(string, msg);
1410 case OFPUTIL_OFPST_TABLE_REQUEST:
1411 ofp_print_stats_request(string, oh);
1414 case OFPUTIL_OFPST_PORT_REQUEST:
1415 ofp_print_stats_request(string, oh);
1416 ofp_print_ofpst_port_request(string, msg);
1419 case OFPUTIL_OFPST_QUEUE_REQUEST:
1420 ofp_print_stats_request(string, oh);
1421 ofp_print_ofpst_queue_request(string, msg);
1424 case OFPUTIL_OFPST_DESC_REPLY:
1425 ofp_print_stats_reply(string, oh);
1426 ofp_print_ofpst_desc_reply(string, msg);
1429 case OFPUTIL_OFPST_FLOW_REPLY:
1430 case OFPUTIL_NXST_FLOW_REPLY:
1431 ofp_print_stats_reply(string, oh);
1432 ofp_print_flow_stats_reply(string, oh);
1435 case OFPUTIL_OFPST_QUEUE_REPLY:
1436 ofp_print_stats_reply(string, oh);
1437 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1440 case OFPUTIL_OFPST_PORT_REPLY:
1441 ofp_print_stats_reply(string, oh);
1442 ofp_print_ofpst_port_reply(string, oh, verbosity);
1445 case OFPUTIL_OFPST_TABLE_REPLY:
1446 ofp_print_stats_reply(string, oh);
1447 ofp_print_ofpst_table_reply(string, oh, verbosity);
1450 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1451 ofp_print_stats_reply(string, oh);
1452 ofp_print_ofpst_aggregate_reply(string, msg);
1455 case OFPUTIL_NXT_ROLE_REQUEST:
1456 case OFPUTIL_NXT_ROLE_REPLY:
1457 ofp_print_nxt_role_message(string, msg);
1460 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID:
1461 ofp_print_nxt_flow_mod_table_id(string, msg);
1464 case OFPUTIL_NXT_SET_FLOW_FORMAT:
1465 ofp_print_nxt_set_flow_format(string, msg);
1468 case OFPUTIL_NXT_SET_PACKET_IN_FORMAT:
1469 ofp_print_nxt_set_packet_in_format(string, msg);
1472 case OFPUTIL_NXT_FLOW_AGE:
1475 case OFPUTIL_NXST_AGGREGATE_REPLY:
1476 ofp_print_stats_reply(string, oh);
1477 ofp_print_nxst_aggregate_reply(string, msg);
1482 /* Composes and returns a string representing the OpenFlow packet of 'len'
1483 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1484 * verbosity and higher numbers increase verbosity. The caller is responsible
1485 * for freeing the string. */
1487 ofp_to_string(const void *oh_, size_t len, int verbosity)
1489 struct ds string = DS_EMPTY_INITIALIZER;
1490 const struct ofp_header *oh = oh_;
1493 ds_put_cstr(&string, "OpenFlow message is empty\n");
1494 } else if (len < sizeof(struct ofp_header)) {
1495 ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1497 } else if (ntohs(oh->length) > len) {
1498 ds_put_format(&string,
1499 "(***truncated to %zu bytes from %"PRIu16"***)\n",
1500 len, ntohs(oh->length));
1501 } else if (ntohs(oh->length) < len) {
1502 ds_put_format(&string,
1503 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1504 ntohs(oh->length), len);
1506 const struct ofputil_msg_type *type;
1509 error = ofputil_decode_msg_type(oh, &type);
1511 ofp_to_string__(oh, type, &string, verbosity);
1512 if (verbosity >= 5) {
1513 if (ds_last(&string) != '\n') {
1514 ds_put_char(&string, '\n');
1516 ds_put_hex_dump(&string, oh, len, 0, true);
1518 if (ds_last(&string) != '\n') {
1519 ds_put_char(&string, '\n');
1521 return ds_steal_cstr(&string);
1524 ofp_print_error(&string, error);
1526 ds_put_hex_dump(&string, oh, len, 0, true);
1527 return ds_steal_cstr(&string);
1530 /* Returns the name for the specified OpenFlow message type as a string,
1531 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1532 * hex number, e.g. "0x55".
1534 * The caller must free the returned string when it is no longer needed. */
1536 ofp_message_type_to_string(uint8_t type)
1547 case OFPT_ECHO_REQUEST:
1548 name = "ECHO_REQUEST";
1550 case OFPT_ECHO_REPLY:
1551 name = "ECHO_REPLY";
1556 case OFPT_FEATURES_REQUEST:
1557 name = "FEATURES_REQUEST";
1559 case OFPT_FEATURES_REPLY:
1560 name = "FEATURES_REPLY";
1562 case OFPT_GET_CONFIG_REQUEST:
1563 name = "GET_CONFIG_REQUEST";
1565 case OFPT_GET_CONFIG_REPLY:
1566 name = "GET_CONFIG_REPLY";
1568 case OFPT_SET_CONFIG:
1569 name = "SET_CONFIG";
1571 case OFPT_PACKET_IN:
1574 case OFPT_FLOW_REMOVED:
1575 name = "FLOW_REMOVED";
1577 case OFPT_PORT_STATUS:
1578 name = "PORT_STATUS";
1580 case OFPT_PACKET_OUT:
1581 name = "PACKET_OUT";
1589 case OFPT_STATS_REQUEST:
1590 name = "STATS_REQUEST";
1592 case OFPT_STATS_REPLY:
1593 name = "STATS_REPLY";
1595 case OFPT_BARRIER_REQUEST:
1596 name = "BARRIER_REQUEST";
1598 case OFPT_BARRIER_REPLY:
1599 name = "BARRIER_REPLY";
1601 case OFPT_QUEUE_GET_CONFIG_REQUEST:
1602 name = "QUEUE_GET_CONFIG_REQUEST";
1604 case OFPT_QUEUE_GET_CONFIG_REPLY:
1605 name = "QUEUE_GET_CONFIG_REPLY";
1612 return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
1616 print_and_free(FILE *stream, char *string)
1618 fputs(string, stream);
1622 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1623 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1624 * numbers increase verbosity. */
1626 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1628 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1631 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1632 * 'data' to 'stream'. */
1634 ofp_print_packet(FILE *stream, const void *data, size_t len)
1636 print_and_free(stream, ofp_packet_to_string(data, len));