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_queue_name(struct ds *string, uint32_t port);
47 static void ofp_print_error(struct ds *, int error);
50 /* Returns a string that represents the contents of the Ethernet frame in the
51 * 'len' bytes starting at 'data' to 'stream' as output by tcpdump.
52 * 'total_len' specifies the full length of the Ethernet frame (of which 'len'
53 * bytes were captured).
55 * The caller must free the returned string.
57 * This starts and kills a tcpdump subprocess so it's quite expensive. */
59 ofp_packet_to_string(const void *data, size_t len, size_t total_len OVS_UNUSED)
61 struct ds ds = DS_EMPTY_INITIALIZER;
70 ofpbuf_use_const(&buf, data, len);
74 ovs_error(errno, "tmpfile");
75 return xstrdup("<error>");
77 pcap_write_header(pcap);
78 pcap_write(pcap, &buf);
81 ovs_error(errno, "error writing temporary file");
85 snprintf(command, sizeof command, "/usr/sbin/tcpdump -t -e -n -r /dev/fd/%d 2>/dev/null",
87 tcpdump = popen(command, "r");
90 ovs_error(errno, "exec(\"%s\")", command);
91 return xstrdup("<error>");
94 while ((c = getc(tcpdump)) != EOF) {
98 status = pclose(tcpdump);
99 if (WIFEXITED(status)) {
100 if (WEXITSTATUS(status))
101 ovs_error(0, "tcpdump exited with status %d", WEXITSTATUS(status));
102 } else if (WIFSIGNALED(status)) {
103 ovs_error(0, "tcpdump exited with signal %d", WTERMSIG(status));
109 ofp_print_packet_in(struct ds *string, const struct ofp_packet_in *op,
112 size_t len = ntohs(op->header.length);
115 ds_put_format(string, " total_len=%"PRIu16" in_port=",
116 ntohs(op->total_len));
117 ofputil_format_port(ntohs(op->in_port), string);
119 if (op->reason == OFPR_ACTION)
120 ds_put_cstr(string, " (via action)");
121 else if (op->reason != OFPR_NO_MATCH)
122 ds_put_format(string, " (***reason %"PRIu8"***)", op->reason);
124 data_len = len - offsetof(struct ofp_packet_in, data);
125 ds_put_format(string, " data_len=%zu", data_len);
126 if (op->buffer_id == htonl(UINT32_MAX)) {
127 ds_put_format(string, " (unbuffered)");
128 if (ntohs(op->total_len) != data_len)
129 ds_put_format(string, " (***total_len != data_len***)");
131 ds_put_format(string, " buffer=0x%08"PRIx32, ntohl(op->buffer_id));
132 if (ntohs(op->total_len) < data_len)
133 ds_put_format(string, " (***total_len < data_len***)");
135 ds_put_char(string, '\n');
139 struct ofpbuf packet;
141 ofpbuf_use_const(&packet, op->data, data_len);
142 flow_extract(&packet, 0, ntohs(op->in_port), &flow);
143 flow_format(string, &flow);
144 ds_put_char(string, '\n');
147 char *packet = ofp_packet_to_string(op->data, data_len,
148 ntohs(op->total_len));
149 ds_put_cstr(string, packet);
155 print_note(struct ds *string, const struct nx_action_note *nan)
160 ds_put_cstr(string, "note:");
161 len = ntohs(nan->len) - offsetof(struct nx_action_note, note);
162 for (i = 0; i < len; i++) {
164 ds_put_char(string, '.');
166 ds_put_format(string, "%02"PRIx8, nan->note[i]);
171 ofp_print_action(struct ds *s, const union ofp_action *a,
172 enum ofputil_action_code code)
174 const struct ofp_action_enqueue *oae;
175 const struct ofp_action_dl_addr *oada;
176 const struct nx_action_set_tunnel64 *nast64;
177 const struct nx_action_set_tunnel *nast;
178 const struct nx_action_set_queue *nasq;
179 const struct nx_action_resubmit *nar;
180 const struct nx_action_reg_move *move;
181 const struct nx_action_reg_load *load;
182 const struct nx_action_multipath *nam;
183 const struct nx_action_autopath *naa;
184 const struct nx_action_output_reg *naor;
188 case OFPUTIL_OFPAT_OUTPUT:
189 port = ntohs(a->output.port);
190 if (port < OFPP_MAX) {
191 ds_put_format(s, "output:%"PRIu16, port);
193 ofputil_format_port(port, s);
194 if (port == OFPP_CONTROLLER) {
195 if (a->output.max_len != htons(0)) {
196 ds_put_format(s, ":%"PRIu16, ntohs(a->output.max_len));
198 ds_put_cstr(s, ":all");
204 case OFPUTIL_OFPAT_ENQUEUE:
205 oae = (const struct ofp_action_enqueue *) a;
206 ds_put_format(s, "enqueue:");
207 ofputil_format_port(ntohs(oae->port), s);
208 ds_put_format(s, "q%"PRIu32, ntohl(oae->queue_id));
211 case OFPUTIL_OFPAT_SET_VLAN_VID:
212 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
213 ntohs(a->vlan_vid.vlan_vid));
216 case OFPUTIL_OFPAT_SET_VLAN_PCP:
217 ds_put_format(s, "mod_vlan_pcp:%"PRIu8, a->vlan_pcp.vlan_pcp);
220 case OFPUTIL_OFPAT_STRIP_VLAN:
221 ds_put_cstr(s, "strip_vlan");
224 case OFPUTIL_OFPAT_SET_DL_SRC:
225 oada = (const struct ofp_action_dl_addr *) a;
226 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
227 ETH_ADDR_ARGS(oada->dl_addr));
230 case OFPUTIL_OFPAT_SET_DL_DST:
231 oada = (const struct ofp_action_dl_addr *) a;
232 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
233 ETH_ADDR_ARGS(oada->dl_addr));
236 case OFPUTIL_OFPAT_SET_NW_SRC:
237 ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
240 case OFPUTIL_OFPAT_SET_NW_DST:
241 ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr));
244 case OFPUTIL_OFPAT_SET_NW_TOS:
245 ds_put_format(s, "mod_nw_tos:%d", a->nw_tos.nw_tos);
248 case OFPUTIL_OFPAT_SET_TP_SRC:
249 ds_put_format(s, "mod_tp_src:%d", ntohs(a->tp_port.tp_port));
252 case OFPUTIL_OFPAT_SET_TP_DST:
253 ds_put_format(s, "mod_tp_dst:%d", ntohs(a->tp_port.tp_port));
256 case OFPUTIL_NXAST_RESUBMIT:
257 nar = (struct nx_action_resubmit *)a;
258 ds_put_format(s, "resubmit:");
259 ofputil_format_port(ntohs(nar->in_port), s);
262 case OFPUTIL_NXAST_RESUBMIT_TABLE:
263 nar = (struct nx_action_resubmit *)a;
264 ds_put_format(s, "resubmit(");
265 if (nar->in_port != htons(OFPP_IN_PORT)) {
266 ofputil_format_port(ntohs(nar->in_port), s);
269 if (nar->table != 255) {
270 ds_put_format(s, "%"PRIu8, nar->table);
275 case OFPUTIL_NXAST_SET_TUNNEL:
276 nast = (struct nx_action_set_tunnel *)a;
277 ds_put_format(s, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id));
280 case OFPUTIL_NXAST_SET_QUEUE:
281 nasq = (struct nx_action_set_queue *)a;
282 ds_put_format(s, "set_queue:%u", ntohl(nasq->queue_id));
285 case OFPUTIL_NXAST_POP_QUEUE:
286 ds_put_cstr(s, "pop_queue");
289 case OFPUTIL_NXAST_NOTE:
290 print_note(s, (const struct nx_action_note *) a);
293 case OFPUTIL_NXAST_REG_MOVE:
294 move = (const struct nx_action_reg_move *) a;
295 nxm_format_reg_move(move, s);
298 case OFPUTIL_NXAST_REG_LOAD:
299 load = (const struct nx_action_reg_load *) a;
300 nxm_format_reg_load(load, s);
303 case OFPUTIL_NXAST_SET_TUNNEL64:
304 nast64 = (const struct nx_action_set_tunnel64 *) a;
305 ds_put_format(s, "set_tunnel64:%#"PRIx64,
306 ntohll(nast64->tun_id));
309 case OFPUTIL_NXAST_MULTIPATH:
310 nam = (const struct nx_action_multipath *) a;
311 multipath_format(nam, s);
314 case OFPUTIL_NXAST_AUTOPATH:
315 naa = (const struct nx_action_autopath *)a;
316 ds_put_format(s, "autopath(%u,", ntohl(naa->id));
317 nxm_format_field_bits(s, ntohl(naa->dst),
318 nxm_decode_ofs(naa->ofs_nbits),
319 nxm_decode_n_bits(naa->ofs_nbits));
323 case OFPUTIL_NXAST_BUNDLE:
324 case OFPUTIL_NXAST_BUNDLE_LOAD:
325 bundle_format((const struct nx_action_bundle *) a, s);
328 case OFPUTIL_NXAST_OUTPUT_REG:
329 naor = (const struct nx_action_output_reg *) a;
330 ds_put_cstr(s, "output:");
331 nxm_format_field_bits(s, ntohl(naor->src),
332 nxm_decode_ofs(naor->ofs_nbits),
333 nxm_decode_n_bits(naor->ofs_nbits));
342 ofp_print_actions(struct ds *string, const union ofp_action *actions,
345 const union ofp_action *a;
348 ds_put_cstr(string, "actions=");
350 ds_put_cstr(string, "drop");
353 OFPUTIL_ACTION_FOR_EACH (a, left, actions, n_actions) {
354 int code = ofputil_decode_action(a);
357 ds_put_cstr(string, ",");
359 ofp_print_action(string, a, code);
361 ofp_print_error(string, -code);
365 ds_put_format(string, " ***%zu leftover bytes following actions",
371 ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
374 size_t len = ntohs(opo->header.length);
375 size_t actions_len = ntohs(opo->actions_len);
377 ds_put_cstr(string, " in_port=");
378 ofputil_format_port(ntohs(opo->in_port), string);
380 ds_put_format(string, " actions_len=%zu ", actions_len);
381 if (actions_len > (ntohs(opo->header.length) - sizeof *opo)) {
382 ds_put_format(string, "***packet too short for action length***\n");
385 if (actions_len % sizeof(union ofp_action)) {
386 ds_put_format(string, "***action length not a multiple of %zu***\n",
387 sizeof(union ofp_action));
389 ofp_print_actions(string, (const union ofp_action *) opo->actions,
390 actions_len / sizeof(union ofp_action));
392 if (ntohl(opo->buffer_id) == UINT32_MAX) {
393 int data_len = len - sizeof *opo - actions_len;
394 ds_put_format(string, " data_len=%d", data_len);
395 if (verbosity > 0 && len > sizeof *opo) {
396 char *packet = ofp_packet_to_string(
397 (uint8_t *)opo->actions + actions_len, data_len, data_len);
398 ds_put_char(string, '\n');
399 ds_put_cstr(string, packet);
403 ds_put_format(string, " buffer=0x%08"PRIx32, ntohl(opo->buffer_id));
405 ds_put_char(string, '\n');
408 /* qsort comparison function. */
410 compare_ports(const void *a_, const void *b_)
412 const struct ofp_phy_port *a = a_;
413 const struct ofp_phy_port *b = b_;
414 uint16_t ap = ntohs(a->port_no);
415 uint16_t bp = ntohs(b->port_no);
417 return ap < bp ? -1 : ap > bp;
426 ofp_print_bit_names(struct ds *string, uint32_t bits,
427 const struct bit_name bit_names[])
432 ds_put_cstr(string, "0");
436 for (; bits && bit_names->name; bit_names++) {
437 if (bits & bit_names->bit) {
439 ds_put_char(string, ' ');
441 ds_put_cstr(string, bit_names->name);
442 bits &= ~bit_names->bit;
448 ds_put_char(string, ' ');
450 ds_put_format(string, "0x%"PRIx32, bits);
455 ofp_print_port_features(struct ds *string, uint32_t features)
457 static const struct bit_name feature_bits[] = {
458 { OFPPF_10MB_HD, "10MB-HD" },
459 { OFPPF_10MB_FD, "10MB-FD" },
460 { OFPPF_100MB_HD, "100MB-HD" },
461 { OFPPF_100MB_FD, "100MB-FD" },
462 { OFPPF_1GB_HD, "1GB-HD" },
463 { OFPPF_1GB_FD, "1GB-FD" },
464 { OFPPF_10GB_FD, "10GB-FD" },
465 { OFPPF_COPPER, "COPPER" },
466 { OFPPF_FIBER, "FIBER" },
467 { OFPPF_AUTONEG, "AUTO_NEG" },
468 { OFPPF_PAUSE, "AUTO_PAUSE" },
469 { OFPPF_PAUSE_ASYM, "AUTO_PAUSE_ASYM" },
473 ofp_print_bit_names(string, features, feature_bits);
474 ds_put_char(string, '\n');
478 ofp_print_port_config(struct ds *string, uint32_t config)
480 static const struct bit_name config_bits[] = {
481 { OFPPC_PORT_DOWN, "PORT_DOWN" },
482 { OFPPC_NO_STP, "NO_STP" },
483 { OFPPC_NO_RECV, "NO_RECV" },
484 { OFPPC_NO_RECV_STP, "NO_RECV_STP" },
485 { OFPPC_NO_FLOOD, "NO_FLOOD" },
486 { OFPPC_NO_FWD, "NO_FWD" },
487 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
491 ofp_print_bit_names(string, config, config_bits);
492 ds_put_char(string, '\n');
496 ofp_print_port_state(struct ds *string, uint32_t state)
498 static const struct bit_name state_bits[] = {
499 { OFPPS_LINK_DOWN, "LINK_DOWN" },
504 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
505 * pattern. We have to special case it.
507 * OVS doesn't support STP, so this field will always be 0 if we are
508 * talking to OVS, so we'd always print STP_LISTEN in that case.
509 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
510 * avoid confusing users. */
511 stp_state = state & OFPPS_STP_MASK;
513 ds_put_cstr(string, (stp_state == OFPPS_STP_LEARN ? "STP_LEARN"
514 : stp_state == OFPPS_STP_FORWARD ? "STP_FORWARD"
516 state &= ~OFPPS_STP_MASK;
518 ofp_print_bit_names(string, state, state_bits);
521 ofp_print_bit_names(string, state, state_bits);
523 ds_put_char(string, '\n');
527 ofp_print_phy_port(struct ds *string, const struct ofp_phy_port *port)
529 char name[OFP_MAX_PORT_NAME_LEN];
532 memcpy(name, port->name, sizeof name);
533 for (j = 0; j < sizeof name - 1; j++) {
534 if (!isprint((unsigned char) name[j])) {
540 ds_put_char(string, ' ');
541 ofputil_format_port(ntohs(port->port_no), string);
542 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n",
543 name, ETH_ADDR_ARGS(port->hw_addr));
545 ds_put_cstr(string, " config: ");
546 ofp_print_port_config(string, ntohl(port->config));
548 ds_put_cstr(string, " state: ");
549 ofp_print_port_state(string, ntohl(port->state));
552 ds_put_format(string, " current: ");
553 ofp_print_port_features(string, ntohl(port->curr));
555 if (port->advertised) {
556 ds_put_format(string, " advertised: ");
557 ofp_print_port_features(string, ntohl(port->advertised));
559 if (port->supported) {
560 ds_put_format(string, " supported: ");
561 ofp_print_port_features(string, ntohl(port->supported));
564 ds_put_format(string, " peer: ");
565 ofp_print_port_features(string, ntohl(port->peer));
570 ofp_print_switch_features(struct ds *string,
571 const struct ofp_switch_features *osf)
573 size_t len = ntohs(osf->header.length);
574 struct ofp_phy_port *port_list;
578 ds_put_format(string, " ver:0x%x, dpid:%016"PRIx64"\n",
579 osf->header.version, ntohll(osf->datapath_id));
580 ds_put_format(string, "n_tables:%d, n_buffers:%d\n", osf->n_tables,
581 ntohl(osf->n_buffers));
582 ds_put_format(string, "features: capabilities:%#x, actions:%#x\n",
583 ntohl(osf->capabilities), ntohl(osf->actions));
585 n_ports = (len - sizeof *osf) / sizeof *osf->ports;
587 port_list = xmemdup(osf->ports, len - sizeof *osf);
588 qsort(port_list, n_ports, sizeof *port_list, compare_ports);
589 for (i = 0; i < n_ports; i++) {
590 ofp_print_phy_port(string, &port_list[i]);
596 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
600 flags = ntohs(osc->flags);
602 ds_put_cstr(string, " frags=");
603 switch (flags & OFPC_FRAG_MASK) {
604 case OFPC_FRAG_NORMAL:
605 ds_put_cstr(string, "normal");
606 flags &= ~OFPC_FRAG_MASK;
609 ds_put_cstr(string, "drop");
610 flags &= ~OFPC_FRAG_MASK;
612 case OFPC_FRAG_REASM:
613 ds_put_cstr(string, "reassemble");
614 flags &= ~OFPC_FRAG_MASK;
618 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
621 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
624 static void print_wild(struct ds *string, const char *leader, int is_wild,
625 int verbosity, const char *format, ...)
626 __attribute__((format(printf, 5, 6)));
628 static void print_wild(struct ds *string, const char *leader, int is_wild,
629 int verbosity, const char *format, ...)
631 if (is_wild && verbosity < 2) {
634 ds_put_cstr(string, leader);
638 va_start(args, format);
639 ds_put_format_valist(string, format, args);
642 ds_put_char(string, '*');
644 ds_put_char(string, ',');
648 print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip,
649 uint32_t wild_bits, int verbosity)
651 if (wild_bits >= 32 && verbosity < 2) {
654 ds_put_cstr(string, leader);
655 if (wild_bits < 32) {
656 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
658 ds_put_format(string, "/%d", 32 - wild_bits);
661 ds_put_char(string, '*');
663 ds_put_char(string, ',');
667 ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
669 char *s = ofp_match_to_string(om, verbosity);
675 ofp_match_to_string(const struct ofp_match *om, int verbosity)
677 struct ds f = DS_EMPTY_INITIALIZER;
678 uint32_t w = ntohl(om->wildcards);
679 bool skip_type = false;
680 bool skip_proto = false;
682 if (!(w & OFPFW_DL_TYPE)) {
684 if (om->dl_type == htons(ETH_TYPE_IP)) {
685 if (!(w & OFPFW_NW_PROTO)) {
687 if (om->nw_proto == IPPROTO_ICMP) {
688 ds_put_cstr(&f, "icmp,");
689 } else if (om->nw_proto == IPPROTO_TCP) {
690 ds_put_cstr(&f, "tcp,");
691 } else if (om->nw_proto == IPPROTO_UDP) {
692 ds_put_cstr(&f, "udp,");
694 ds_put_cstr(&f, "ip,");
698 ds_put_cstr(&f, "ip,");
700 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
701 ds_put_cstr(&f, "arp,");
706 print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
707 "%d", ntohs(om->in_port));
708 print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
709 "%d", ntohs(om->dl_vlan));
710 print_wild(&f, "dl_vlan_pcp=", w & OFPFW_DL_VLAN_PCP, verbosity,
711 "%d", om->dl_vlan_pcp);
712 print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
713 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
714 print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
715 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
717 print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
718 "0x%04x", ntohs(om->dl_type));
720 print_ip_netmask(&f, "nw_src=", om->nw_src,
721 (w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
722 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
723 (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
725 if (om->dl_type == htons(ETH_TYPE_ARP)) {
726 print_wild(&f, "arp_op=", w & OFPFW_NW_PROTO, verbosity,
729 print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
733 print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
735 if (om->nw_proto == IPPROTO_ICMP) {
736 print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
737 "%d", ntohs(om->icmp_type));
738 print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
739 "%d", ntohs(om->icmp_code));
741 print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
742 "%d", ntohs(om->tp_src));
743 print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
744 "%d", ntohs(om->tp_dst));
746 if (ds_last(&f) == ',') {
753 ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
754 enum ofputil_msg_code code, int verbosity)
756 struct ofputil_flow_mod fm;
760 error = ofputil_decode_flow_mod(&fm, oh, true);
762 ofp_print_error(s, error);
767 switch (fm.command) {
769 ds_put_cstr(s, "ADD");
772 ds_put_cstr(s, "MOD");
774 case OFPFC_MODIFY_STRICT:
775 ds_put_cstr(s, "MOD_STRICT");
778 ds_put_cstr(s, "DEL");
780 case OFPFC_DELETE_STRICT:
781 ds_put_cstr(s, "DEL_STRICT");
784 ds_put_format(s, "cmd:%d", fm.command);
786 if (fm.table_id != 0) {
787 ds_put_format(s, " table:%d", fm.table_id);
791 if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) {
792 const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh;
793 ofp_print_match(s, &ofm->match, verbosity);
795 /* ofp_print_match() doesn't print priority. */
796 need_priority = true;
797 } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) {
798 const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh;
799 const void *nxm = nfm + 1;
802 nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len));
803 ds_put_cstr(s, nxm_s);
806 /* nx_match_to_string() doesn't print priority. */
807 need_priority = true;
809 cls_rule_format(&fm.cr, s);
811 /* cls_rule_format() does print priority. */
812 need_priority = false;
815 if (ds_last(s) != ' ') {
818 if (fm.cookie != htonll(0)) {
819 ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.cookie));
821 if (fm.idle_timeout != OFP_FLOW_PERMANENT) {
822 ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout);
824 if (fm.hard_timeout != OFP_FLOW_PERMANENT) {
825 ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout);
827 if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) {
828 ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority);
830 if (fm.buffer_id != UINT32_MAX) {
831 ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id);
834 ds_put_format(s, "flags:0x%"PRIx16" ", fm.flags);
837 ofp_print_actions(s, fm.actions, fm.n_actions);
841 ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
843 ds_put_format(string, "%u", sec);
845 ds_put_format(string, ".%09u", nsec);
846 while (string->string[string->length - 1] == '0') {
850 ds_put_char(string, 's');
854 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
856 struct ofputil_flow_removed fr;
859 error = ofputil_decode_flow_removed(&fr, oh);
861 ofp_print_error(string, error);
865 ds_put_char(string, ' ');
866 cls_rule_format(&fr.rule, string);
868 ds_put_cstr(string, " reason=");
870 case OFPRR_IDLE_TIMEOUT:
871 ds_put_cstr(string, "idle");
873 case OFPRR_HARD_TIMEOUT:
874 ds_put_cstr(string, "hard");
877 ds_put_cstr(string, "delete");
880 ds_put_format(string, "**%"PRIu8"**", fr.reason);
884 if (fr.cookie != htonll(0)) {
885 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
887 ds_put_cstr(string, " duration");
888 ofp_print_duration(string, fr.duration_sec, fr.duration_nsec);
889 ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
890 fr.idle_timeout, fr.packet_count, fr.byte_count);
894 ofp_print_port_mod(struct ds *string, const struct ofp_port_mod *opm)
896 ds_put_format(string, "port: %d: addr:"ETH_ADDR_FMT", config: %#x, mask:%#x\n",
897 ntohs(opm->port_no), ETH_ADDR_ARGS(opm->hw_addr),
898 ntohl(opm->config), ntohl(opm->mask));
899 ds_put_format(string, " advertise: ");
900 if (opm->advertise) {
901 ofp_print_port_features(string, ntohl(opm->advertise));
903 ds_put_format(string, "UNCHANGED\n");
908 ofp_print_error(struct ds *string, int error)
910 if (string->length) {
911 ds_put_char(string, ' ');
913 ds_put_cstr(string, "***decode error: ");
914 ofputil_format_error(string, error);
915 ds_put_cstr(string, "***\n");
919 ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
921 size_t len = ntohs(oem->header.length);
922 size_t payload_ofs, payload_len;
927 error = ofputil_decode_error_msg(&oem->header, &payload_ofs);
928 if (!is_ofp_error(error)) {
929 ofp_print_error(string, error);
930 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
934 ds_put_char(string, ' ');
935 ofputil_format_error(string, error);
936 ds_put_char(string, '\n');
938 payload = (const uint8_t *) oem + payload_ofs;
939 payload_len = len - payload_ofs;
940 switch (get_ofp_err_type(error)) {
941 case OFPET_HELLO_FAILED:
942 ds_put_printable(string, payload, payload_len);
945 case OFPET_BAD_REQUEST:
946 s = ofp_to_string(payload, payload_len, 1);
947 ds_put_cstr(string, s);
952 ds_put_hex_dump(string, payload, payload_len, 0, true);
958 ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
960 if (ops->reason == OFPPR_ADD) {
961 ds_put_format(string, " ADD:");
962 } else if (ops->reason == OFPPR_DELETE) {
963 ds_put_format(string, " DEL:");
964 } else if (ops->reason == OFPPR_MODIFY) {
965 ds_put_format(string, " MOD:");
968 ofp_print_phy_port(string, &ops->desc);
972 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods)
974 ds_put_char(string, '\n');
975 ds_put_format(string, "Manufacturer: %.*s\n",
976 (int) sizeof ods->mfr_desc, ods->mfr_desc);
977 ds_put_format(string, "Hardware: %.*s\n",
978 (int) sizeof ods->hw_desc, ods->hw_desc);
979 ds_put_format(string, "Software: %.*s\n",
980 (int) sizeof ods->sw_desc, ods->sw_desc);
981 ds_put_format(string, "Serial Num: %.*s\n",
982 (int) sizeof ods->serial_num, ods->serial_num);
983 ds_put_format(string, "DP Description: %.*s\n",
984 (int) sizeof ods->dp_desc, ods->dp_desc);
988 ofp_print_flow_stats_request(struct ds *string,
989 const struct ofp_stats_msg *osm)
991 struct ofputil_flow_stats_request fsr;
994 error = ofputil_decode_flow_stats_request(&fsr, &osm->header);
996 ofp_print_error(string, error);
1000 if (fsr.table_id != 0xff) {
1001 ds_put_format(string, " table=%"PRIu8, fsr.table_id);
1004 if (fsr.out_port != OFPP_NONE) {
1005 ds_put_cstr(string, " out_port=");
1006 ofputil_format_port(fsr.out_port, string);
1009 /* A flow stats request doesn't include a priority, but cls_rule_format()
1010 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1011 fsr.match.priority = OFP_DEFAULT_PRIORITY;
1013 ds_put_char(string, ' ');
1014 cls_rule_format(&fsr.match, string);
1018 ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
1022 ofpbuf_use_const(&b, oh, ntohs(oh->length));
1024 struct ofputil_flow_stats fs;
1027 retval = ofputil_decode_flow_stats_reply(&fs, &b);
1029 if (retval != EOF) {
1030 ds_put_cstr(string, " ***parse error***");
1035 ds_put_char(string, '\n');
1037 ds_put_format(string, " cookie=0x%"PRIx64", duration=",
1039 ofp_print_duration(string, fs.duration_sec, fs.duration_nsec);
1040 ds_put_format(string, ", table=%"PRIu8", ", fs.table_id);
1041 ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count);
1042 ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count);
1043 if (fs.idle_timeout != OFP_FLOW_PERMANENT) {
1044 ds_put_format(string, "idle_timeout=%"PRIu16",", fs.idle_timeout);
1046 if (fs.hard_timeout != OFP_FLOW_PERMANENT) {
1047 ds_put_format(string, "hard_timeout=%"PRIu16",", fs.hard_timeout);
1050 cls_rule_format(&fs.rule, string);
1051 ds_put_char(string, ' ');
1052 ofp_print_actions(string, fs.actions, fs.n_actions);
1057 ofp_print_ofpst_aggregate_reply(struct ds *string,
1058 const struct ofp_aggregate_stats_reply *asr)
1060 ds_put_format(string, " packet_count=%"PRIu64,
1061 ntohll(get_32aligned_be64(&asr->packet_count)));
1062 ds_put_format(string, " byte_count=%"PRIu64,
1063 ntohll(get_32aligned_be64(&asr->byte_count)));
1064 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1068 ofp_print_nxst_aggregate_reply(struct ds *string,
1069 const struct nx_aggregate_stats_reply *nasr)
1071 ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count));
1072 ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count));
1073 ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count));
1076 static void print_port_stat(struct ds *string, const char *leader,
1077 const ovs_32aligned_be64 *statp, int more)
1079 uint64_t stat = ntohll(get_32aligned_be64(statp));
1081 ds_put_cstr(string, leader);
1082 if (stat != UINT64_MAX) {
1083 ds_put_format(string, "%"PRIu64, stat);
1085 ds_put_char(string, '?');
1088 ds_put_cstr(string, ", ");
1090 ds_put_cstr(string, "\n");
1095 ofp_print_ofpst_port_request(struct ds *string,
1096 const struct ofp_port_stats_request *psr)
1098 ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no));
1102 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
1105 const struct ofp_port_stats *ps = ofputil_stats_body(oh);
1106 size_t n = ofputil_stats_body_len(oh) / sizeof *ps;
1107 ds_put_format(string, " %zu ports\n", n);
1108 if (verbosity < 1) {
1113 ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no));
1115 ds_put_cstr(string, "rx ");
1116 print_port_stat(string, "pkts=", &ps->rx_packets, 1);
1117 print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
1118 print_port_stat(string, "drop=", &ps->rx_dropped, 1);
1119 print_port_stat(string, "errs=", &ps->rx_errors, 1);
1120 print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
1121 print_port_stat(string, "over=", &ps->rx_over_err, 1);
1122 print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
1124 ds_put_cstr(string, " tx ");
1125 print_port_stat(string, "pkts=", &ps->tx_packets, 1);
1126 print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
1127 print_port_stat(string, "drop=", &ps->tx_dropped, 1);
1128 print_port_stat(string, "errs=", &ps->tx_errors, 1);
1129 print_port_stat(string, "coll=", &ps->collisions, 0);
1134 ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
1137 const struct ofp_table_stats *ts = ofputil_stats_body(oh);
1138 size_t n = ofputil_stats_body_len(oh) / sizeof *ts;
1139 ds_put_format(string, " %zu tables\n", n);
1140 if (verbosity < 1) {
1145 char name[OFP_MAX_TABLE_NAME_LEN + 1];
1146 ovs_strlcpy(name, ts->name, sizeof name);
1148 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1149 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1150 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1151 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1152 ds_put_cstr(string, " ");
1153 ds_put_format(string, "lookup=%"PRIu64", ",
1154 ntohll(get_32aligned_be64(&ts->lookup_count)));
1155 ds_put_format(string, "matched=%"PRIu64"\n",
1156 ntohll(get_32aligned_be64(&ts->matched_count)));
1161 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1163 if (queue_id == OFPQ_ALL) {
1164 ds_put_cstr(string, "ALL");
1166 ds_put_format(string, "%"PRIu32, queue_id);
1171 ofp_print_ofpst_queue_request(struct ds *string,
1172 const struct ofp_queue_stats_request *qsr)
1174 ds_put_cstr(string, "port=");
1175 ofputil_format_port(ntohs(qsr->port_no), string);
1177 ds_put_cstr(string, " queue=");
1178 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1182 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1185 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1186 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
1187 ds_put_format(string, " %zu queues\n", n);
1188 if (verbosity < 1) {
1193 ds_put_cstr(string, " port ");
1194 ofputil_format_port(ntohs(qs->port_no), string);
1195 ds_put_cstr(string, " queue ");
1196 ofp_print_queue_name(string, ntohl(qs->queue_id));
1197 ds_put_cstr(string, ": ");
1199 print_port_stat(string, "bytes=", &qs->tx_bytes, 1);
1200 print_port_stat(string, "pkts=", &qs->tx_packets, 1);
1201 print_port_stat(string, "errors=", &qs->tx_errors, 0);
1206 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1208 const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh;
1211 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1217 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1219 const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh;
1222 uint16_t flags = ntohs(srp->flags);
1224 ds_put_cstr(string, " flags=");
1225 if (flags & OFPSF_REPLY_MORE) {
1226 ds_put_cstr(string, "[more]");
1227 flags &= ~OFPSF_REPLY_MORE;
1230 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1237 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1239 size_t len = ntohs(oh->length);
1241 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1242 if (verbosity > 1) {
1243 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1248 ofp_print_nxt_role_message(struct ds *string,
1249 const struct nx_role_request *nrr)
1251 unsigned int role = ntohl(nrr->role);
1253 ds_put_cstr(string, " role=");
1254 if (role == NX_ROLE_OTHER) {
1255 ds_put_cstr(string, "other");
1256 } else if (role == NX_ROLE_MASTER) {
1257 ds_put_cstr(string, "master");
1258 } else if (role == NX_ROLE_SLAVE) {
1259 ds_put_cstr(string, "slave");
1261 ds_put_format(string, "%u", role);
1266 ofp_print_nxt_flow_mod_table_id(struct ds *string,
1267 const struct nxt_flow_mod_table_id *nfmti)
1269 ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
1273 ofp_print_nxt_set_flow_format(struct ds *string,
1274 const struct nxt_set_flow_format *nsff)
1276 uint32_t format = ntohl(nsff->format);
1278 ds_put_cstr(string, " format=");
1279 if (ofputil_flow_format_is_valid(format)) {
1280 ds_put_cstr(string, ofputil_flow_format_to_string(format));
1282 ds_put_format(string, "%"PRIu32, format);
1287 ofp_to_string__(const struct ofp_header *oh,
1288 const struct ofputil_msg_type *type, struct ds *string,
1291 enum ofputil_msg_code code;
1292 const void *msg = oh;
1294 ds_put_format(string, "%s (xid=0x%"PRIx32"):",
1295 ofputil_msg_type_name(type), ntohl(oh->xid));
1297 code = ofputil_msg_type_code(type);
1299 case OFPUTIL_MSG_INVALID:
1302 case OFPUTIL_OFPT_HELLO:
1303 ds_put_char(string, '\n');
1304 ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh,
1308 case OFPUTIL_OFPT_ERROR:
1309 ofp_print_error_msg(string, msg);
1312 case OFPUTIL_OFPT_ECHO_REQUEST:
1313 case OFPUTIL_OFPT_ECHO_REPLY:
1314 ofp_print_echo(string, oh, verbosity);
1317 case OFPUTIL_OFPT_FEATURES_REQUEST:
1320 case OFPUTIL_OFPT_FEATURES_REPLY:
1321 ofp_print_switch_features(string, msg);
1324 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1327 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1328 case OFPUTIL_OFPT_SET_CONFIG:
1329 ofp_print_switch_config(string, msg);
1332 case OFPUTIL_OFPT_PACKET_IN:
1333 ofp_print_packet_in(string, msg, verbosity);
1336 case OFPUTIL_OFPT_FLOW_REMOVED:
1337 case OFPUTIL_NXT_FLOW_REMOVED:
1338 ofp_print_flow_removed(string, msg);
1341 case OFPUTIL_OFPT_PORT_STATUS:
1342 ofp_print_port_status(string, msg);
1345 case OFPUTIL_OFPT_PACKET_OUT:
1346 ofp_print_packet_out(string, msg, verbosity);
1349 case OFPUTIL_OFPT_FLOW_MOD:
1350 ofp_print_flow_mod(string, msg, code, verbosity);
1353 case OFPUTIL_OFPT_PORT_MOD:
1354 ofp_print_port_mod(string, msg);
1357 case OFPUTIL_OFPT_BARRIER_REQUEST:
1358 case OFPUTIL_OFPT_BARRIER_REPLY:
1361 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1362 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1366 case OFPUTIL_OFPST_DESC_REQUEST:
1367 ofp_print_stats_request(string, oh);
1370 case OFPUTIL_OFPST_FLOW_REQUEST:
1371 case OFPUTIL_NXST_FLOW_REQUEST:
1372 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
1373 case OFPUTIL_NXST_AGGREGATE_REQUEST:
1374 ofp_print_stats_request(string, oh);
1375 ofp_print_flow_stats_request(string, msg);
1378 case OFPUTIL_OFPST_TABLE_REQUEST:
1379 ofp_print_stats_request(string, oh);
1382 case OFPUTIL_OFPST_PORT_REQUEST:
1383 ofp_print_stats_request(string, oh);
1384 ofp_print_ofpst_port_request(string, msg);
1387 case OFPUTIL_OFPST_QUEUE_REQUEST:
1388 ofp_print_stats_request(string, oh);
1389 ofp_print_ofpst_queue_request(string, msg);
1392 case OFPUTIL_OFPST_DESC_REPLY:
1393 ofp_print_stats_reply(string, oh);
1394 ofp_print_ofpst_desc_reply(string, msg);
1397 case OFPUTIL_OFPST_FLOW_REPLY:
1398 case OFPUTIL_NXST_FLOW_REPLY:
1399 ofp_print_stats_reply(string, oh);
1400 ofp_print_flow_stats_reply(string, oh);
1403 case OFPUTIL_OFPST_QUEUE_REPLY:
1404 ofp_print_stats_reply(string, oh);
1405 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1408 case OFPUTIL_OFPST_PORT_REPLY:
1409 ofp_print_stats_reply(string, oh);
1410 ofp_print_ofpst_port_reply(string, oh, verbosity);
1413 case OFPUTIL_OFPST_TABLE_REPLY:
1414 ofp_print_stats_reply(string, oh);
1415 ofp_print_ofpst_table_reply(string, oh, verbosity);
1418 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1419 ofp_print_stats_reply(string, oh);
1420 ofp_print_ofpst_aggregate_reply(string, msg);
1423 case OFPUTIL_NXT_ROLE_REQUEST:
1424 case OFPUTIL_NXT_ROLE_REPLY:
1425 ofp_print_nxt_role_message(string, msg);
1428 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID:
1429 ofp_print_nxt_flow_mod_table_id(string, msg);
1432 case OFPUTIL_NXT_SET_FLOW_FORMAT:
1433 ofp_print_nxt_set_flow_format(string, msg);
1436 case OFPUTIL_NXT_FLOW_MOD:
1437 ofp_print_flow_mod(string, msg, code, verbosity);
1440 case OFPUTIL_NXST_AGGREGATE_REPLY:
1441 ofp_print_stats_reply(string, oh);
1442 ofp_print_nxst_aggregate_reply(string, msg);
1447 /* Composes and returns a string representing the OpenFlow packet of 'len'
1448 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1449 * verbosity and higher numbers increase verbosity. The caller is responsible
1450 * for freeing the string. */
1452 ofp_to_string(const void *oh_, size_t len, int verbosity)
1454 struct ds string = DS_EMPTY_INITIALIZER;
1455 const struct ofp_header *oh = oh_;
1458 ds_put_cstr(&string, "OpenFlow message is empty\n");
1459 } else if (len < sizeof(struct ofp_header)) {
1460 ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
1462 } else if (oh->version != OFP_VERSION) {
1463 ds_put_format(&string, "Bad OpenFlow version %"PRIu8":\n",
1465 } else if (ntohs(oh->length) > len) {
1466 ds_put_format(&string,
1467 "(***truncated to %zu bytes from %"PRIu16"***)\n",
1468 len, ntohs(oh->length));
1469 } else if (ntohs(oh->length) < len) {
1470 ds_put_format(&string,
1471 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1472 ntohs(oh->length), len);
1474 const struct ofputil_msg_type *type;
1477 error = ofputil_decode_msg_type(oh, &type);
1479 ofp_to_string__(oh, type, &string, verbosity);
1480 if (verbosity >= 5) {
1481 if (ds_last(&string) != '\n') {
1482 ds_put_char(&string, '\n');
1484 ds_put_hex_dump(&string, oh, len, 0, true);
1486 if (ds_last(&string) != '\n') {
1487 ds_put_char(&string, '\n');
1489 return ds_steal_cstr(&string);
1492 ofp_print_error(&string, error);
1494 ds_put_hex_dump(&string, oh, len, 0, true);
1495 return ds_steal_cstr(&string);
1498 /* Returns the name for the specified OpenFlow message type as a string,
1499 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1500 * hex number, e.g. "0x55".
1502 * The caller must free the returned string when it is no longer needed. */
1504 ofp_message_type_to_string(uint8_t type)
1515 case OFPT_ECHO_REQUEST:
1516 name = "ECHO_REQUEST";
1518 case OFPT_ECHO_REPLY:
1519 name = "ECHO_REPLY";
1524 case OFPT_FEATURES_REQUEST:
1525 name = "FEATURES_REQUEST";
1527 case OFPT_FEATURES_REPLY:
1528 name = "FEATURES_REPLY";
1530 case OFPT_GET_CONFIG_REQUEST:
1531 name = "GET_CONFIG_REQUEST";
1533 case OFPT_GET_CONFIG_REPLY:
1534 name = "GET_CONFIG_REPLY";
1536 case OFPT_SET_CONFIG:
1537 name = "SET_CONFIG";
1539 case OFPT_PACKET_IN:
1542 case OFPT_FLOW_REMOVED:
1543 name = "FLOW_REMOVED";
1545 case OFPT_PORT_STATUS:
1546 name = "PORT_STATUS";
1548 case OFPT_PACKET_OUT:
1549 name = "PACKET_OUT";
1557 case OFPT_STATS_REQUEST:
1558 name = "STATS_REQUEST";
1560 case OFPT_STATS_REPLY:
1561 name = "STATS_REPLY";
1563 case OFPT_BARRIER_REQUEST:
1564 name = "BARRIER_REQUEST";
1566 case OFPT_BARRIER_REPLY:
1567 name = "BARRIER_REPLY";
1569 case OFPT_QUEUE_GET_CONFIG_REQUEST:
1570 name = "QUEUE_GET_CONFIG_REQUEST";
1572 case OFPT_QUEUE_GET_CONFIG_REPLY:
1573 name = "QUEUE_GET_CONFIG_REPLY";
1580 return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
1584 print_and_free(FILE *stream, char *string)
1586 fputs(string, stream);
1590 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1591 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1592 * numbers increase verbosity. */
1594 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1596 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1599 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1600 * 'data' to 'stream' using tcpdump. 'total_len' specifies the full length of
1601 * the Ethernet frame (of which 'len' bytes were captured).
1603 * This starts and kills a tcpdump subprocess so it's quite expensive. */
1605 ofp_print_packet(FILE *stream, const void *data, size_t len, size_t total_len)
1607 print_and_free(stream, ofp_packet_to_string(data, len, total_len));