2 * Copyright (c) 2008, 2009, 2010, 2011 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"
34 #include "multipath.h"
38 #include "openflow/openflow.h"
39 #include "openflow/nicira-ext.h"
42 #include "type-props.h"
43 #include "unaligned.h"
46 static void ofp_print_port_name(struct ds *string, uint16_t port);
47 static void ofp_print_queue_name(struct ds *string, uint32_t port);
48 static void ofp_print_error(struct ds *, int error);
51 /* Returns a string that represents the contents of the Ethernet frame in the
52 * 'len' bytes starting at 'data' to 'stream' as output by tcpdump.
53 * 'total_len' specifies the full length of the Ethernet frame (of which 'len'
54 * bytes were captured).
56 * The caller must free the returned string.
58 * This starts and kills a tcpdump subprocess so it's quite expensive. */
60 ofp_packet_to_string(const void *data, size_t len, size_t total_len OVS_UNUSED)
62 struct ds ds = DS_EMPTY_INITIALIZER;
71 ofpbuf_use_const(&buf, data, len);
75 ovs_error(errno, "tmpfile");
76 return xstrdup("<error>");
78 pcap_write_header(pcap);
79 pcap_write(pcap, &buf);
82 ovs_error(errno, "error writing temporary file");
86 snprintf(command, sizeof command, "/usr/sbin/tcpdump -t -e -n -r /dev/fd/%d 2>/dev/null",
88 tcpdump = popen(command, "r");
91 ovs_error(errno, "exec(\"%s\")", command);
92 return xstrdup("<error>");
95 while ((c = getc(tcpdump)) != EOF) {
99 status = pclose(tcpdump);
100 if (WIFEXITED(status)) {
101 if (WEXITSTATUS(status))
102 ovs_error(0, "tcpdump exited with status %d", WEXITSTATUS(status));
103 } else if (WIFSIGNALED(status)) {
104 ovs_error(0, "tcpdump exited with signal %d", WTERMSIG(status));
110 ofp_print_packet_in(struct ds *string, const struct ofp_packet_in *op,
113 size_t len = ntohs(op->header.length);
116 ds_put_format(string, " total_len=%"PRIu16" in_port=",
117 ntohs(op->total_len));
118 ofp_print_port_name(string, ntohs(op->in_port));
120 if (op->reason == OFPR_ACTION)
121 ds_put_cstr(string, " (via action)");
122 else if (op->reason != OFPR_NO_MATCH)
123 ds_put_format(string, " (***reason %"PRIu8"***)", op->reason);
125 data_len = len - offsetof(struct ofp_packet_in, data);
126 ds_put_format(string, " data_len=%zu", data_len);
127 if (op->buffer_id == htonl(UINT32_MAX)) {
128 ds_put_format(string, " (unbuffered)");
129 if (ntohs(op->total_len) != data_len)
130 ds_put_format(string, " (***total_len != data_len***)");
132 ds_put_format(string, " buffer=0x%08"PRIx32, ntohl(op->buffer_id));
133 if (ntohs(op->total_len) < data_len)
134 ds_put_format(string, " (***total_len < data_len***)");
136 ds_put_char(string, '\n');
140 struct ofpbuf packet;
142 ofpbuf_use_const(&packet, op->data, data_len);
143 flow_extract(&packet, 0, ntohs(op->in_port), &flow);
144 flow_format(string, &flow);
145 ds_put_char(string, '\n');
148 char *packet = ofp_packet_to_string(op->data, data_len,
149 ntohs(op->total_len));
150 ds_put_cstr(string, packet);
155 static void ofp_print_port_name(struct ds *string, uint16_t port)
174 case OFPP_CONTROLLER:
184 ds_put_format(string, "%"PRIu16, port);
187 ds_put_cstr(string, name);
192 print_note(struct ds *string, const struct nx_action_note *nan)
197 ds_put_cstr(string, "note:");
198 len = ntohs(nan->len) - offsetof(struct nx_action_note, note);
199 for (i = 0; i < len; i++) {
201 ds_put_char(string, '.');
203 ds_put_format(string, "%02"PRIx8, nan->note[i]);
208 ofp_print_action(struct ds *s, const union ofp_action *a,
209 enum ofputil_action_code code)
211 const struct ofp_action_enqueue *oae;
212 const struct ofp_action_dl_addr *oada;
213 const struct nx_action_set_tunnel64 *nast64;
214 const struct nx_action_set_tunnel *nast;
215 const struct nx_action_set_queue *nasq;
216 const struct nx_action_resubmit *nar;
217 const struct nx_action_reg_move *move;
218 const struct nx_action_reg_load *load;
219 const struct nx_action_multipath *nam;
220 const struct nx_action_autopath *naa;
221 const struct nx_action_output_reg *naor;
225 case OFPUTIL_OFPAT_OUTPUT:
226 port = ntohs(a->output.port);
227 if (port < OFPP_MAX) {
228 ds_put_format(s, "output:%"PRIu16, port);
230 ofp_print_port_name(s, port);
231 if (port == OFPP_CONTROLLER) {
232 if (a->output.max_len != htons(0)) {
233 ds_put_format(s, ":%"PRIu16, ntohs(a->output.max_len));
235 ds_put_cstr(s, ":all");
241 case OFPUTIL_OFPAT_ENQUEUE:
242 oae = (const struct ofp_action_enqueue *) a;
243 ds_put_format(s, "enqueue:");
244 ofp_print_port_name(s, ntohs(oae->port));
245 ds_put_format(s, "q%"PRIu32, ntohl(oae->queue_id));
248 case OFPUTIL_OFPAT_SET_VLAN_VID:
249 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
250 ntohs(a->vlan_vid.vlan_vid));
253 case OFPUTIL_OFPAT_SET_VLAN_PCP:
254 ds_put_format(s, "mod_vlan_pcp:%"PRIu8, a->vlan_pcp.vlan_pcp);
257 case OFPUTIL_OFPAT_STRIP_VLAN:
258 ds_put_cstr(s, "strip_vlan");
261 case OFPUTIL_OFPAT_SET_DL_SRC:
262 oada = (const struct ofp_action_dl_addr *) a;
263 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
264 ETH_ADDR_ARGS(oada->dl_addr));
267 case OFPUTIL_OFPAT_SET_DL_DST:
268 oada = (const struct ofp_action_dl_addr *) a;
269 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
270 ETH_ADDR_ARGS(oada->dl_addr));
273 case OFPUTIL_OFPAT_SET_NW_SRC:
274 ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
277 case OFPUTIL_OFPAT_SET_NW_DST:
278 ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
281 case OFPUTIL_OFPAT_SET_NW_TOS:
282 ds_put_format(s, "mod_nw_tos:%d", a->nw_tos.nw_tos);
285 case OFPUTIL_OFPAT_SET_TP_SRC:
286 ds_put_format(s, "mod_tp_src:%d", ntohs(a->tp_port.tp_port));
289 case OFPUTIL_OFPAT_SET_TP_DST:
290 ds_put_format(s, "mod_tp_dst:%d", ntohs(a->tp_port.tp_port));
293 case OFPUTIL_NXAST_RESUBMIT:
294 nar = (struct nx_action_resubmit *)a;
295 ds_put_format(s, "resubmit:");
296 ofp_print_port_name(s, ntohs(nar->in_port));
299 case OFPUTIL_NXAST_RESUBMIT_TABLE:
300 nar = (struct nx_action_resubmit *)a;
301 ds_put_format(s, "resubmit(");
302 if (nar->in_port != htons(OFPP_IN_PORT)) {
303 ofp_print_port_name(s, ntohs(nar->in_port));
306 if (nar->table != 255) {
307 ds_put_format(s, "%"PRIu8, nar->table);
312 case OFPUTIL_NXAST_SET_TUNNEL:
313 nast = (struct nx_action_set_tunnel *)a;
314 ds_put_format(s, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id));
317 case OFPUTIL_NXAST_SET_QUEUE:
318 nasq = (struct nx_action_set_queue *)a;
319 ds_put_format(s, "set_queue:%u", ntohl(nasq->queue_id));
322 case OFPUTIL_NXAST_POP_QUEUE:
323 ds_put_cstr(s, "pop_queue");
326 case OFPUTIL_NXAST_NOTE:
327 print_note(s, (const struct nx_action_note *) a);
330 case OFPUTIL_NXAST_REG_MOVE:
331 move = (const struct nx_action_reg_move *) a;
332 nxm_format_reg_move(move, s);
335 case OFPUTIL_NXAST_REG_LOAD:
336 load = (const struct nx_action_reg_load *) a;
337 nxm_format_reg_load(load, s);
340 case OFPUTIL_NXAST_SET_TUNNEL64:
341 nast64 = (const struct nx_action_set_tunnel64 *) a;
342 ds_put_format(s, "set_tunnel64:%#"PRIx64,
343 ntohll(nast64->tun_id));
346 case OFPUTIL_NXAST_MULTIPATH:
347 nam = (const struct nx_action_multipath *) a;
348 multipath_format(nam, s);
351 case OFPUTIL_NXAST_AUTOPATH:
352 naa = (const struct nx_action_autopath *)a;
353 ds_put_format(s, "autopath(%u,", ntohl(naa->id));
354 nxm_format_field_bits(s, ntohl(naa->dst),
355 nxm_decode_ofs(naa->ofs_nbits),
356 nxm_decode_n_bits(naa->ofs_nbits));
360 case OFPUTIL_NXAST_BUNDLE:
361 case OFPUTIL_NXAST_BUNDLE_LOAD:
362 bundle_format((const struct nx_action_bundle *) a, s);
365 case OFPUTIL_NXAST_OUTPUT_REG:
366 naor = (const struct nx_action_output_reg *) a;
367 ds_put_cstr(s, "output:");
368 nxm_format_field_bits(s, ntohl(naor->src),
369 nxm_decode_ofs(naor->ofs_nbits),
370 nxm_decode_n_bits(naor->ofs_nbits));
379 ofp_print_actions(struct ds *string, const union ofp_action *actions,
382 const union ofp_action *a;
385 ds_put_cstr(string, "actions=");
387 ds_put_cstr(string, "drop");
390 OFPUTIL_ACTION_FOR_EACH (a, left, actions, n_actions) {
391 int code = ofputil_decode_action(a);
394 ds_put_cstr(string, ",");
396 ofp_print_action(string, a, code);
398 ofp_print_error(string, -code);
402 ds_put_format(string, " ***%zu leftover bytes following actions",
408 ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
411 size_t len = ntohs(opo->header.length);
412 size_t actions_len = ntohs(opo->actions_len);
414 ds_put_cstr(string, " in_port=");
415 ofp_print_port_name(string, ntohs(opo->in_port));
417 ds_put_format(string, " actions_len=%zu ", actions_len);
418 if (actions_len > (ntohs(opo->header.length) - sizeof *opo)) {
419 ds_put_format(string, "***packet too short for action length***\n");
422 if (actions_len % sizeof(union ofp_action)) {
423 ds_put_format(string, "***action length not a multiple of %zu***\n",
424 sizeof(union ofp_action));
426 ofp_print_actions(string, (const union ofp_action *) opo->actions,
427 actions_len / sizeof(union ofp_action));
429 if (ntohl(opo->buffer_id) == UINT32_MAX) {
430 int data_len = len - sizeof *opo - actions_len;
431 ds_put_format(string, " data_len=%d", data_len);
432 if (verbosity > 0 && len > sizeof *opo) {
433 char *packet = ofp_packet_to_string(
434 (uint8_t *)opo->actions + actions_len, data_len, data_len);
435 ds_put_char(string, '\n');
436 ds_put_cstr(string, packet);
440 ds_put_format(string, " buffer=0x%08"PRIx32, ntohl(opo->buffer_id));
442 ds_put_char(string, '\n');
445 /* qsort comparison function. */
447 compare_ports(const void *a_, const void *b_)
449 const struct ofp_phy_port *a = a_;
450 const struct ofp_phy_port *b = b_;
451 uint16_t ap = ntohs(a->port_no);
452 uint16_t bp = ntohs(b->port_no);
454 return ap < bp ? -1 : ap > bp;
463 ofp_print_bit_names(struct ds *string, uint32_t bits,
464 const struct bit_name bit_names[])
469 ds_put_cstr(string, "0");
473 for (; bits && bit_names->name; bit_names++) {
474 if (bits & bit_names->bit) {
476 ds_put_char(string, ' ');
478 ds_put_cstr(string, bit_names->name);
479 bits &= ~bit_names->bit;
485 ds_put_char(string, ' ');
487 ds_put_format(string, "0x%"PRIx32, bits);
492 ofp_print_port_features(struct ds *string, uint32_t features)
494 static const struct bit_name feature_bits[] = {
495 { OFPPF_10MB_HD, "10MB-HD" },
496 { OFPPF_10MB_FD, "10MB-FD" },
497 { OFPPF_100MB_HD, "100MB-HD" },
498 { OFPPF_100MB_FD, "100MB-FD" },
499 { OFPPF_1GB_HD, "1GB-HD" },
500 { OFPPF_1GB_FD, "1GB-FD" },
501 { OFPPF_10GB_FD, "10GB-FD" },
502 { OFPPF_COPPER, "COPPER" },
503 { OFPPF_FIBER, "FIBER" },
504 { OFPPF_AUTONEG, "AUTO_NEG" },
505 { OFPPF_PAUSE, "AUTO_PAUSE" },
506 { OFPPF_PAUSE_ASYM, "AUTO_PAUSE_ASYM" },
510 ofp_print_bit_names(string, features, feature_bits);
511 ds_put_char(string, '\n');
515 ofp_print_port_config(struct ds *string, uint32_t config)
517 static const struct bit_name config_bits[] = {
518 { OFPPC_PORT_DOWN, "PORT_DOWN" },
519 { OFPPC_NO_STP, "NO_STP" },
520 { OFPPC_NO_RECV, "NO_RECV" },
521 { OFPPC_NO_RECV_STP, "NO_RECV_STP" },
522 { OFPPC_NO_FLOOD, "NO_FLOOD" },
523 { OFPPC_NO_FWD, "NO_FWD" },
524 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
528 ofp_print_bit_names(string, config, config_bits);
529 ds_put_char(string, '\n');
533 ofp_print_port_state(struct ds *string, uint32_t state)
535 static const struct bit_name state_bits[] = {
536 { OFPPS_LINK_DOWN, "LINK_DOWN" },
541 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
542 * pattern. We have to special case it.
544 * OVS doesn't support STP, so this field will always be 0 if we are
545 * talking to OVS, so we'd always print STP_LISTEN in that case.
546 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
547 * avoid confusing users. */
548 stp_state = state & OFPPS_STP_MASK;
550 ds_put_cstr(string, (stp_state == OFPPS_STP_LEARN ? "STP_LEARN"
551 : stp_state == OFPPS_STP_FORWARD ? "STP_FORWARD"
553 state &= ~OFPPS_STP_MASK;
555 ofp_print_bit_names(string, state, state_bits);
558 ofp_print_bit_names(string, state, state_bits);
560 ds_put_char(string, '\n');
564 ofp_print_phy_port(struct ds *string, const struct ofp_phy_port *port)
566 char name[OFP_MAX_PORT_NAME_LEN];
569 memcpy(name, port->name, sizeof name);
570 for (j = 0; j < sizeof name - 1; j++) {
571 if (!isprint((unsigned char) name[j])) {
577 ds_put_char(string, ' ');
578 ofp_print_port_name(string, ntohs(port->port_no));
579 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
580 name, ETH_ADDR_ARGS(port->hw_addr));
582 ds_put_cstr(string, " config: ");
583 ofp_print_port_config(string, ntohl(port->config));
585 ds_put_cstr(string, " state: ");
586 ofp_print_port_state(string, ntohl(port->state));
589 ds_put_format(string, " current: ");
590 ofp_print_port_features(string, ntohl(port->curr));
592 if (port->advertised) {
593 ds_put_format(string, " advertised: ");
594 ofp_print_port_features(string, ntohl(port->advertised));
596 if (port->supported) {
597 ds_put_format(string, " supported: ");
598 ofp_print_port_features(string, ntohl(port->supported));
601 ds_put_format(string, " peer: ");
602 ofp_print_port_features(string, ntohl(port->peer));
607 ofp_print_switch_features(struct ds *string,
608 const struct ofp_switch_features *osf)
610 size_t len = ntohs(osf->header.length);
611 struct ofp_phy_port *port_list;
615 ds_put_format(string, " ver:0x%x, dpid:%016"PRIx64"\n",
616 osf->header.version, ntohll(osf->datapath_id));
617 ds_put_format(string, "n_tables:%d, n_buffers:%d\n", osf->n_tables,
618 ntohl(osf->n_buffers));
619 ds_put_format(string, "features: capabilities:%#x, actions:%#x\n",
620 ntohl(osf->capabilities), ntohl(osf->actions));
622 n_ports = (len - sizeof *osf) / sizeof *osf->ports;
624 port_list = xmemdup(osf->ports, len - sizeof *osf);
625 qsort(port_list, n_ports, sizeof *port_list, compare_ports);
626 for (i = 0; i < n_ports; i++) {
627 ofp_print_phy_port(string, &port_list[i]);
633 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
637 flags = ntohs(osc->flags);
639 ds_put_cstr(string, " frags=");
640 switch (flags & OFPC_FRAG_MASK) {
641 case OFPC_FRAG_NORMAL:
642 ds_put_cstr(string, "normal");
643 flags &= ~OFPC_FRAG_MASK;
646 ds_put_cstr(string, "drop");
647 flags &= ~OFPC_FRAG_MASK;
649 case OFPC_FRAG_REASM:
650 ds_put_cstr(string, "reassemble");
651 flags &= ~OFPC_FRAG_MASK;
655 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
658 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
661 static void print_wild(struct ds *string, const char *leader, int is_wild,
662 int verbosity, const char *format, ...)
663 __attribute__((format(printf, 5, 6)));
665 static void print_wild(struct ds *string, const char *leader, int is_wild,
666 int verbosity, const char *format, ...)
668 if (is_wild && verbosity < 2) {
671 ds_put_cstr(string, leader);
675 va_start(args, format);
676 ds_put_format_valist(string, format, args);
679 ds_put_char(string, '*');
681 ds_put_char(string, ',');
685 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
686 uint32_t wild_bits, int verbosity)
688 if (wild_bits >= 32 && verbosity < 2) {
691 ds_put_cstr(string, leader);
692 if (wild_bits < 32) {
693 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
695 ds_put_format(string, "/%d", 32 - wild_bits);
698 ds_put_char(string, '*');
700 ds_put_char(string, ',');
704 ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
706 char *s = ofp_match_to_string(om, verbosity);
712 ofp_match_to_string(const struct ofp_match *om, int verbosity)
714 struct ds f = DS_EMPTY_INITIALIZER;
715 uint32_t w = ntohl(om->wildcards);
716 bool skip_type = false;
717 bool skip_proto = false;
719 if (!(w & OFPFW_DL_TYPE)) {
721 if (om->dl_type == htons(ETH_TYPE_IP)) {
722 if (!(w & OFPFW_NW_PROTO)) {
724 if (om->nw_proto == IPPROTO_ICMP) {
725 ds_put_cstr(&f, "icmp,");
726 } else if (om->nw_proto == IPPROTO_TCP) {
727 ds_put_cstr(&f, "tcp,");
728 } else if (om->nw_proto == IPPROTO_UDP) {
729 ds_put_cstr(&f, "udp,");
731 ds_put_cstr(&f, "ip,");
735 ds_put_cstr(&f, "ip,");
737 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
738 ds_put_cstr(&f, "arp,");
743 print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
744 "%d", ntohs(om->in_port));
745 print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
746 "%d", ntohs(om->dl_vlan));
747 print_wild(&f, "dl_vlan_pcp=", w & OFPFW_DL_VLAN_PCP, verbosity,
748 "%d", om->dl_vlan_pcp);
749 print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
750 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
751 print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
752 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
754 print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
755 "0x%04x", ntohs(om->dl_type));
757 print_ip_netmask(&f, "nw_src=", om->nw_src,
758 (w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
759 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
760 (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
762 if (om->dl_type == htons(ETH_TYPE_ARP)) {
763 print_wild(&f, "arp_op=", w & OFPFW_NW_PROTO, verbosity,
766 print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
770 print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
772 if (om->nw_proto == IPPROTO_ICMP) {
773 print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
774 "%d", ntohs(om->icmp_type));
775 print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
776 "%d", ntohs(om->icmp_code));
778 print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
779 "%d", ntohs(om->tp_src));
780 print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
781 "%d", ntohs(om->tp_dst));
783 if (ds_last(&f) == ',') {
790 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
791 enum ofputil_msg_code code, int verbosity)
793 struct ofputil_flow_mod fm;
797 error = ofputil_decode_flow_mod(&fm, oh, true);
799 ofp_print_error(s, error);
804 switch (fm.command) {
806 ds_put_cstr(s, "ADD");
809 ds_put_cstr(s, "MOD");
811 case OFPFC_MODIFY_STRICT:
812 ds_put_cstr(s, "MOD_STRICT");
815 ds_put_cstr(s, "DEL");
817 case OFPFC_DELETE_STRICT:
818 ds_put_cstr(s, "DEL_STRICT");
821 ds_put_format(s, "cmd:%d", fm.command);
823 if (fm.table_id != 0) {
824 ds_put_format(s, " table:%d", fm.table_id);
828 if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) {
829 const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh;
830 ofp_print_match(s, &ofm->match, verbosity);
832 /* ofp_print_match() doesn't print priority. */
833 need_priority = true;
834 } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) {
835 const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh;
836 const void *nxm = nfm + 1;
839 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
840 ds_put_cstr(s, nxm_s);
843 /* nx_match_to_string() doesn't print priority. */
844 need_priority = true;
846 cls_rule_format(&fm.cr, s);
848 /* cls_rule_format() does print priority. */
849 need_priority = false;
852 if (ds_last(s) != ' ') {
855 if (fm.cookie != htonll(0)) {
856 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.cookie));
858 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
859 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
861 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
862 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
864 if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
865 ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
867 if (fm.buffer_id != UINT32_MAX) {
868 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
871 ds_put_format(s, "flags:0x%"PRIx16" ", fm.flags);
874 ofp_print_actions(s, fm.actions, fm.n_actions);
878 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
880 ds_put_format(string, "%u", sec);
882 ds_put_format(string, ".%09u", nsec);
883 while (string->string[string->length - 1] == '0') {
887 ds_put_char(string, 's');
891 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
893 struct ofputil_flow_removed fr;
896 error = ofputil_decode_flow_removed(&fr, oh);
898 ofp_print_error(string, error);
902 ds_put_char(string, ' ');
903 cls_rule_format(&fr.rule, string);
905 ds_put_cstr(string, " reason=");
907 case OFPRR_IDLE_TIMEOUT:
908 ds_put_cstr(string, "idle");
910 case OFPRR_HARD_TIMEOUT:
911 ds_put_cstr(string, "hard");
914 ds_put_cstr(string, "delete");
917 ds_put_format(string, "**%"PRIu8"**", fr.reason);
921 if (fr.cookie != htonll(0)) {
922 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
924 ds_put_cstr(string, " duration");
925 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
926 ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
927 fr.idle_timeout, fr.packet_count, fr.byte_count);
931 ofp_print_port_mod(struct ds *string, const struct ofp_port_mod *opm)
933 ds_put_format(string, "port: %d: addr:"ETH_ADDR_FMT", config: %#x, mask:%#x\n",
934 ntohs(opm->port_no), ETH_ADDR_ARGS(opm->hw_addr),
935 ntohl(opm->config), ntohl(opm->mask));
936 ds_put_format(string, " advertise: ");
937 if (opm->advertise) {
938 ofp_print_port_features(string, ntohl(opm->advertise));
940 ds_put_format(string, "UNCHANGED\n");
945 ofp_print_error(struct ds *string, int error)
947 if (string->length) {
948 ds_put_char(string, ' ');
950 ds_put_cstr(string, "***decode error: ");
951 ofputil_format_error(string, error);
952 ds_put_cstr(string, "***\n");
956 ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
958 size_t len = ntohs(oem->header.length);
959 size_t payload_ofs, payload_len;
964 error = ofputil_decode_error_msg(&oem->header, &payload_ofs);
965 if (!is_ofp_error(error)) {
966 ofp_print_error(string, error);
967 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
971 ds_put_char(string, ' ');
972 ofputil_format_error(string, error);
973 ds_put_char(string, '\n');
975 payload = (const uint8_t *) oem + payload_ofs;
976 payload_len = len - payload_ofs;
977 switch (get_ofp_err_type(error)) {
978 case OFPET_HELLO_FAILED:
979 ds_put_printable(string, payload, payload_len);
982 case OFPET_BAD_REQUEST:
983 s = ofp_to_string(payload, payload_len, 1);
984 ds_put_cstr(string, s);
989 ds_put_hex_dump(string, payload, payload_len, 0, true);
995 ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
997 if (ops->reason == OFPPR_ADD) {
998 ds_put_format(string, " ADD:");
999 } else if (ops->reason == OFPPR_DELETE) {
1000 ds_put_format(string, " DEL:");
1001 } else if (ops->reason == OFPPR_MODIFY) {
1002 ds_put_format(string, " MOD:");
1005 ofp_print_phy_port(string, &ops->desc);
1009 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods)
1011 ds_put_char(string, '\n');
1012 ds_put_format(string, "Manufacturer: %.*s\n",
1013 (int) sizeof ods->mfr_desc, ods->mfr_desc);
1014 ds_put_format(string, "Hardware: %.*s\n",
1015 (int) sizeof ods->hw_desc, ods->hw_desc);
1016 ds_put_format(string, "Software: %.*s\n",
1017 (int) sizeof ods->sw_desc, ods->sw_desc);
1018 ds_put_format(string, "Serial Num: %.*s\n",
1019 (int) sizeof ods->serial_num, ods->serial_num);
1020 ds_put_format(string, "DP Description: %.*s\n",
1021 (int) sizeof ods->dp_desc, ods->dp_desc);
1025 ofp_print_flow_stats_request(struct ds *string,
1026 const struct ofp_stats_msg *osm)
1028 struct ofputil_flow_stats_request fsr;
1031 error = ofputil_decode_flow_stats_request(&fsr, &osm->header);
1033 ofp_print_error(string, error);
1037 if (fsr.table_id != 0xff) {
1038 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1041 if (fsr.out_port != OFPP_NONE) {
1042 ds_put_cstr(string, " out_port=");
1043 ofp_print_port_name(string, fsr.out_port);
1046 /* A flow stats request doesn't include a priority, but cls_rule_format()
1047 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1048 fsr.match.priority = OFP_DEFAULT_PRIORITY;
1050 ds_put_char(string, ' ');
1051 cls_rule_format(&fsr.match, string);
1055 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1059 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1061 struct ofputil_flow_stats fs;
1064 retval = ofputil_decode_flow_stats_reply(&fs, &b);
1066 if (retval != EOF) {
1067 ds_put_cstr(string, " ***parse error***");
1072 ds_put_char(string, '\n');
1074 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1076 ofp_print_duration(string, fs.duration_sec, fs.duration_nsec);
1077 ds_put_format(string, ", table=%"PRIu8", ", fs.table_id);
1078 ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count);
1079 ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count);
1080 if (fs.idle_timeout != OFP_FLOW_PERMANENT) {
1081 ds_put_format(string, "idle_timeout=%"PRIu16",", fs.idle_timeout);
1083 if (fs.hard_timeout != OFP_FLOW_PERMANENT) {
1084 ds_put_format(string, "hard_timeout=%"PRIu16",", fs.hard_timeout);
1087 cls_rule_format(&fs.rule, string);
1088 ds_put_char(string, ' ');
1089 ofp_print_actions(string, fs.actions, fs.n_actions);
1094 ofp_print_ofpst_aggregate_reply(struct ds *string,
1095 const struct ofp_aggregate_stats_reply *asr)
1097 ds_put_format(string, " packet_count=%"PRIu64,
1098 ntohll(get_32aligned_be64(&asr->packet_count)));
1099 ds_put_format(string, " byte_count=%"PRIu64,
1100 ntohll(get_32aligned_be64(&asr->byte_count)));
1101 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1105 ofp_print_nxst_aggregate_reply(struct ds *string,
1106 const struct nx_aggregate_stats_reply *nasr)
1108 ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count));
1109 ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count));
1110 ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count));
1113 static void print_port_stat(struct ds *string, const char *leader,
1114 const ovs_32aligned_be64 *statp, int more)
1116 uint64_t stat = ntohll(get_32aligned_be64(statp));
1118 ds_put_cstr(string, leader);
1119 if (stat != UINT64_MAX) {
1120 ds_put_format(string, "%"PRIu64, stat);
1122 ds_put_char(string, '?');
1125 ds_put_cstr(string, ", ");
1127 ds_put_cstr(string, "\n");
1132 ofp_print_ofpst_port_request(struct ds *string,
1133 const struct ofp_port_stats_request *psr)
1135 ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
1139 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1142 const struct ofp_port_stats *ps = ofputil_stats_body(oh);
1143 size_t n = ofputil_stats_body_len(oh) / sizeof *ps;
1144 ds_put_format(string, " %zu ports\n", n);
1145 if (verbosity < 1) {
1150 ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no));
1152 ds_put_cstr(string, "rx ");
1153 print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1154 print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1155 print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1156 print_port_stat(string, "errs=", &ps->rx_errors, 1);
1157 print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1158 print_port_stat(string, "over=", &ps->rx_over_err, 1);
1159 print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
1161 ds_put_cstr(string, " tx ");
1162 print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1163 print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1164 print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1165 print_port_stat(string, "errs=", &ps->tx_errors, 1);
1166 print_port_stat(string, "coll=", &ps->collisions, 0);
1171 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1174 const struct ofp_table_stats *ts = ofputil_stats_body(oh);
1175 size_t n = ofputil_stats_body_len(oh) / sizeof *ts;
1176 ds_put_format(string, " %zu tables\n", n);
1177 if (verbosity < 1) {
1182 char name[OFP_MAX_TABLE_NAME_LEN + 1];
1183 ovs_strlcpy(name, ts->name, sizeof name);
1185 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1186 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1187 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1188 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1189 ds_put_cstr(string, " ");
1190 ds_put_format(string, "lookup=%"PRIu64", ",
1191 ntohll(get_32aligned_be64(&ts->lookup_count)));
1192 ds_put_format(string, "matched=%"PRIu64"\n",
1193 ntohll(get_32aligned_be64(&ts->matched_count)));
1198 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1200 if (queue_id == OFPQ_ALL) {
1201 ds_put_cstr(string, "ALL");
1203 ds_put_format(string, "%"PRIu32, queue_id);
1208 ofp_print_ofpst_queue_request(struct ds *string,
1209 const struct ofp_queue_stats_request *qsr)
1211 ds_put_cstr(string, "port=");
1212 ofp_print_port_name(string, ntohs(qsr->port_no));
1214 ds_put_cstr(string, " queue=");
1215 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1219 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1222 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1223 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
1224 ds_put_format(string, " %zu queues\n", n);
1225 if (verbosity < 1) {
1230 ds_put_cstr(string, " port ");
1231 ofp_print_port_name(string, ntohs(qs->port_no));
1232 ds_put_cstr(string, " queue ");
1233 ofp_print_queue_name(string, ntohl(qs->queue_id));
1234 ds_put_cstr(string, ": ");
1236 print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1237 print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1238 print_port_stat(string, "errors=", &qs->tx_errors, 0);
1243 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1245 const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh;
1248 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1254 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1256 const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh;
1259 uint16_t flags = ntohs(srp->flags);
1261 ds_put_cstr(string, " flags=");
1262 if (flags & OFPSF_REPLY_MORE) {
1263 ds_put_cstr(string, "[more]");
1264 flags &= ~OFPSF_REPLY_MORE;
1267 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1274 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1276 size_t len = ntohs(oh->length);
1278 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1279 if (verbosity > 1) {
1280 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1285 ofp_print_nxt_role_message(struct ds *string,
1286 const struct nx_role_request *nrr)
1288 unsigned int role = ntohl(nrr->role);
1290 ds_put_cstr(string, " role=");
1291 if (role == NX_ROLE_OTHER) {
1292 ds_put_cstr(string, "other");
1293 } else if (role == NX_ROLE_MASTER) {
1294 ds_put_cstr(string, "master");
1295 } else if (role == NX_ROLE_SLAVE) {
1296 ds_put_cstr(string, "slave");
1298 ds_put_format(string, "%u", role);
1303 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1304 const struct nxt_flow_mod_table_id *nfmti)
1306 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1310 ofp_print_nxt_set_flow_format(struct ds *string,
1311 const struct nxt_set_flow_format *nsff)
1313 uint32_t format = ntohl(nsff->format);
1315 ds_put_cstr(string, " format=");
1316 if (ofputil_flow_format_is_valid(format)) {
1317 ds_put_cstr(string, ofputil_flow_format_to_string(format));
1319 ds_put_format(string, "%"PRIu32, format);
1324 ofp_to_string__(const struct ofp_header *oh,
1325 const struct ofputil_msg_type *type, struct ds *string,
1328 enum ofputil_msg_code code;
1329 const void *msg = oh;
1331 ds_put_format(string, "%s (xid=0x%"PRIx32"):",
1332 ofputil_msg_type_name(type), ntohl(oh->xid));
1334 code = ofputil_msg_type_code(type);
1336 case OFPUTIL_MSG_INVALID:
1339 case OFPUTIL_OFPT_HELLO:
1340 ds_put_char(string, '\n');
1341 ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1345 case OFPUTIL_OFPT_ERROR:
1346 ofp_print_error_msg(string, msg);
1349 case OFPUTIL_OFPT_ECHO_REQUEST:
1350 case OFPUTIL_OFPT_ECHO_REPLY:
1351 ofp_print_echo(string, oh, verbosity);
1354 case OFPUTIL_OFPT_FEATURES_REQUEST:
1357 case OFPUTIL_OFPT_FEATURES_REPLY:
1358 ofp_print_switch_features(string, msg);
1361 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1364 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1365 case OFPUTIL_OFPT_SET_CONFIG:
1366 ofp_print_switch_config(string, msg);
1369 case OFPUTIL_OFPT_PACKET_IN:
1370 ofp_print_packet_in(string, msg, verbosity);
1373 case OFPUTIL_OFPT_FLOW_REMOVED:
1374 case OFPUTIL_NXT_FLOW_REMOVED:
1375 ofp_print_flow_removed(string, msg);
1378 case OFPUTIL_OFPT_PORT_STATUS:
1379 ofp_print_port_status(string, msg);
1382 case OFPUTIL_OFPT_PACKET_OUT:
1383 ofp_print_packet_out(string, msg, verbosity);
1386 case OFPUTIL_OFPT_FLOW_MOD:
1387 ofp_print_flow_mod(string, msg, code, verbosity);
1390 case OFPUTIL_OFPT_PORT_MOD:
1391 ofp_print_port_mod(string, msg);
1394 case OFPUTIL_OFPT_BARRIER_REQUEST:
1395 case OFPUTIL_OFPT_BARRIER_REPLY:
1398 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1399 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1403 case OFPUTIL_OFPST_DESC_REQUEST:
1404 ofp_print_stats_request(string, oh);
1407 case OFPUTIL_OFPST_FLOW_REQUEST:
1408 case OFPUTIL_NXST_FLOW_REQUEST:
1409 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
1410 case OFPUTIL_NXST_AGGREGATE_REQUEST:
1411 ofp_print_stats_request(string, oh);
1412 ofp_print_flow_stats_request(string, msg);
1415 case OFPUTIL_OFPST_TABLE_REQUEST:
1416 ofp_print_stats_request(string, oh);
1419 case OFPUTIL_OFPST_PORT_REQUEST:
1420 ofp_print_stats_request(string, oh);
1421 ofp_print_ofpst_port_request(string, msg);
1424 case OFPUTIL_OFPST_QUEUE_REQUEST:
1425 ofp_print_stats_request(string, oh);
1426 ofp_print_ofpst_queue_request(string, msg);
1429 case OFPUTIL_OFPST_DESC_REPLY:
1430 ofp_print_stats_reply(string, oh);
1431 ofp_print_ofpst_desc_reply(string, msg);
1434 case OFPUTIL_OFPST_FLOW_REPLY:
1435 case OFPUTIL_NXST_FLOW_REPLY:
1436 ofp_print_stats_reply(string, oh);
1437 ofp_print_flow_stats_reply(string, oh);
1440 case OFPUTIL_OFPST_QUEUE_REPLY:
1441 ofp_print_stats_reply(string, oh);
1442 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1445 case OFPUTIL_OFPST_PORT_REPLY:
1446 ofp_print_stats_reply(string, oh);
1447 ofp_print_ofpst_port_reply(string, oh, verbosity);
1450 case OFPUTIL_OFPST_TABLE_REPLY:
1451 ofp_print_stats_reply(string, oh);
1452 ofp_print_ofpst_table_reply(string, oh, verbosity);
1455 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1456 ofp_print_stats_reply(string, oh);
1457 ofp_print_ofpst_aggregate_reply(string, msg);
1460 case OFPUTIL_NXT_ROLE_REQUEST:
1461 case OFPUTIL_NXT_ROLE_REPLY:
1462 ofp_print_nxt_role_message(string, msg);
1465 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID:
1466 ofp_print_nxt_flow_mod_table_id(string, msg);
1469 case OFPUTIL_NXT_SET_FLOW_FORMAT:
1470 ofp_print_nxt_set_flow_format(string, msg);
1473 case OFPUTIL_NXT_FLOW_MOD:
1474 ofp_print_flow_mod(string, msg, code, verbosity);
1477 case OFPUTIL_NXST_AGGREGATE_REPLY:
1478 ofp_print_stats_reply(string, oh);
1479 ofp_print_nxst_aggregate_reply(string, msg);
1484 /* Composes and returns a string representing the OpenFlow packet of 'len'
1485 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1486 * verbosity and higher numbers increase verbosity. The caller is responsible
1487 * for freeing the string. */
1489 ofp_to_string(const void *oh_, size_t len, int verbosity)
1491 struct ds string = DS_EMPTY_INITIALIZER;
1492 const struct ofp_header *oh = oh_;
1495 ds_put_cstr(&string, "OpenFlow message is empty\n");
1496 } else if (len < sizeof(struct ofp_header)) {
1497 ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1499 } else if (oh->version != OFP_VERSION) {
1500 ds_put_format(&string, "Bad OpenFlow version %"PRIu8":\n",
1502 } else if (ntohs(oh->length) > len) {
1503 ds_put_format(&string,
1504 "(***truncated to %zu bytes from %"PRIu16"***)\n",
1505 len, ntohs(oh->length));
1506 } else if (ntohs(oh->length) < len) {
1507 ds_put_format(&string,
1508 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1509 ntohs(oh->length), len);
1511 const struct ofputil_msg_type *type;
1514 error = ofputil_decode_msg_type(oh, &type);
1516 ofp_to_string__(oh, type, &string, verbosity);
1517 if (verbosity >= 5) {
1518 if (ds_last(&string) != '\n') {
1519 ds_put_char(&string, '\n');
1521 ds_put_hex_dump(&string, oh, len, 0, true);
1523 if (ds_last(&string) != '\n') {
1524 ds_put_char(&string, '\n');
1526 return ds_steal_cstr(&string);
1529 ofp_print_error(&string, error);
1531 ds_put_hex_dump(&string, oh, len, 0, true);
1532 return ds_steal_cstr(&string);
1535 /* Returns the name for the specified OpenFlow message type as a string,
1536 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1537 * hex number, e.g. "0x55".
1539 * The caller must free the returned string when it is no longer needed. */
1541 ofp_message_type_to_string(uint8_t type)
1552 case OFPT_ECHO_REQUEST:
1553 name = "ECHO_REQUEST";
1555 case OFPT_ECHO_REPLY:
1556 name = "ECHO_REPLY";
1561 case OFPT_FEATURES_REQUEST:
1562 name = "FEATURES_REQUEST";
1564 case OFPT_FEATURES_REPLY:
1565 name = "FEATURES_REPLY";
1567 case OFPT_GET_CONFIG_REQUEST:
1568 name = "GET_CONFIG_REQUEST";
1570 case OFPT_GET_CONFIG_REPLY:
1571 name = "GET_CONFIG_REPLY";
1573 case OFPT_SET_CONFIG:
1574 name = "SET_CONFIG";
1576 case OFPT_PACKET_IN:
1579 case OFPT_FLOW_REMOVED:
1580 name = "FLOW_REMOVED";
1582 case OFPT_PORT_STATUS:
1583 name = "PORT_STATUS";
1585 case OFPT_PACKET_OUT:
1586 name = "PACKET_OUT";
1594 case OFPT_STATS_REQUEST:
1595 name = "STATS_REQUEST";
1597 case OFPT_STATS_REPLY:
1598 name = "STATS_REPLY";
1600 case OFPT_BARRIER_REQUEST:
1601 name = "BARRIER_REQUEST";
1603 case OFPT_BARRIER_REPLY:
1604 name = "BARRIER_REPLY";
1606 case OFPT_QUEUE_GET_CONFIG_REQUEST:
1607 name = "QUEUE_GET_CONFIG_REQUEST";
1609 case OFPT_QUEUE_GET_CONFIG_REPLY:
1610 name = "QUEUE_GET_CONFIG_REPLY";
1617 return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
1621 print_and_free(FILE *stream, char *string)
1623 fputs(string, stream);
1627 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1628 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1629 * numbers increase verbosity. */
1631 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1633 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1636 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1637 * 'data' to 'stream' using tcpdump. 'total_len' specifies the full length of
1638 * the Ethernet frame (of which 'len' bytes were captured).
1640 * This starts and kills a tcpdump subprocess so it's quite expensive. */
1642 ofp_print_packet(FILE *stream, const void *data, size_t len, size_t total_len)
1644 print_and_free(stream, ofp_packet_to_string(data, len, total_len));