2 * Copyright (c) 2008, 2009, 2010 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>
29 #include "byte-order.h"
31 #include "dynamic-string.h"
35 #include "openflow/openflow.h"
36 #include "openflow/nicira-ext.h"
41 static void ofp_print_port_name(struct ds *string, uint16_t port);
42 static void ofp_print_queue_name(struct ds *string, uint32_t port);
44 /* Returns a string that represents the contents of the Ethernet frame in the
45 * 'len' bytes starting at 'data' to 'stream' as output by tcpdump.
46 * 'total_len' specifies the full length of the Ethernet frame (of which 'len'
47 * bytes were captured).
49 * The caller must free the returned string.
51 * This starts and kills a tcpdump subprocess so it's quite expensive. */
53 ofp_packet_to_string(const void *data, size_t len, size_t total_len OVS_UNUSED)
55 struct ds ds = DS_EMPTY_INITIALIZER;
64 buf.data = (void *) data;
69 ovs_error(errno, "tmpfile");
70 return xstrdup("<error>");
72 pcap_write_header(pcap);
73 pcap_write(pcap, &buf);
76 ovs_error(errno, "error writing temporary file");
80 snprintf(command, sizeof command, "/usr/sbin/tcpdump -e -n -r /dev/fd/%d 2>/dev/null",
82 tcpdump = popen(command, "r");
85 ovs_error(errno, "exec(\"%s\")", command);
86 return xstrdup("<error>");
89 while ((c = getc(tcpdump)) != EOF) {
93 status = pclose(tcpdump);
94 if (WIFEXITED(status)) {
95 if (WEXITSTATUS(status))
96 ovs_error(0, "tcpdump exited with status %d", WEXITSTATUS(status));
97 } else if (WIFSIGNALED(status)) {
98 ovs_error(0, "tcpdump exited with signal %d", WTERMSIG(status));
104 ofp_print_packet_in(struct ds *string, const struct ofp_packet_in *op,
107 size_t len = ntohs(op->header.length);
110 ds_put_format(string, " total_len=%"PRIu16" in_port=",
111 ntohs(op->total_len));
112 ofp_print_port_name(string, ntohs(op->in_port));
114 if (op->reason == OFPR_ACTION)
115 ds_put_cstr(string, " (via action)");
116 else if (op->reason != OFPR_NO_MATCH)
117 ds_put_format(string, " (***reason %"PRIu8"***)", op->reason);
119 data_len = len - offsetof(struct ofp_packet_in, data);
120 ds_put_format(string, " data_len=%zu", data_len);
121 if (htonl(op->buffer_id) == UINT32_MAX) {
122 ds_put_format(string, " (unbuffered)");
123 if (ntohs(op->total_len) != data_len)
124 ds_put_format(string, " (***total_len != data_len***)");
126 ds_put_format(string, " buffer=0x%08"PRIx32, ntohl(op->buffer_id));
127 if (ntohs(op->total_len) < data_len)
128 ds_put_format(string, " (***total_len < data_len***)");
130 ds_put_char(string, '\n');
134 struct ofpbuf packet;
136 packet.data = (void *) op->data;
137 packet.size = data_len;
138 flow_extract(&packet, 0, ntohs(op->in_port), &flow);
139 flow_format(string, &flow);
140 ds_put_char(string, '\n');
143 char *packet = ofp_packet_to_string(op->data, data_len,
144 ntohs(op->total_len));
145 ds_put_cstr(string, packet);
150 static void ofp_print_port_name(struct ds *string, uint16_t port)
169 case OFPP_CONTROLLER:
179 ds_put_format(string, "%"PRIu16, port);
182 ds_put_cstr(string, name);
186 print_note(struct ds *string, const struct nx_action_note *nan)
191 ds_put_cstr(string, "note:");
192 len = ntohs(nan->len) - offsetof(struct nx_action_note, note);
193 for (i = 0; i < len; i++) {
195 ds_put_char(string, '.');
197 ds_put_format(string, "%02"PRIx8, nan->note[i]);
202 ofp_print_nx_action(struct ds *string, const struct nx_action_header *nah)
204 switch (ntohs(nah->subtype)) {
205 case NXAST_RESUBMIT: {
206 const struct nx_action_resubmit *nar = (struct nx_action_resubmit *)nah;
207 ds_put_format(string, "resubmit:");
208 ofp_print_port_name(string, ntohs(nar->in_port));
212 case NXAST_SET_TUNNEL: {
213 const struct nx_action_set_tunnel *nast =
214 (struct nx_action_set_tunnel *)nah;
215 ds_put_format(string, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id));
219 case NXAST_DROP_SPOOFED_ARP:
220 ds_put_cstr(string, "drop_spoofed_arp");
223 case NXAST_SET_QUEUE: {
224 const struct nx_action_set_queue *nasq =
225 (struct nx_action_set_queue *)nah;
226 ds_put_format(string, "set_queue:%u", ntohl(nasq->queue_id));
230 case NXAST_POP_QUEUE:
231 ds_put_cstr(string, "pop_queue");
235 print_note(string, (const struct nx_action_note *) nah);
239 ds_put_format(string, "***unknown Nicira action:%d***",
240 ntohs(nah->subtype));
245 ofp_print_action(struct ds *string, const struct ofp_action_header *ah,
251 struct openflow_action {
256 const struct openflow_action of_actions[] = {
258 sizeof(struct ofp_action_output),
259 sizeof(struct ofp_action_output),
261 [OFPAT_SET_VLAN_VID] = {
262 sizeof(struct ofp_action_vlan_vid),
263 sizeof(struct ofp_action_vlan_vid),
265 [OFPAT_SET_VLAN_PCP] = {
266 sizeof(struct ofp_action_vlan_pcp),
267 sizeof(struct ofp_action_vlan_pcp),
269 [OFPAT_STRIP_VLAN] = {
270 sizeof(struct ofp_action_header),
271 sizeof(struct ofp_action_header),
273 [OFPAT_SET_DL_SRC] = {
274 sizeof(struct ofp_action_dl_addr),
275 sizeof(struct ofp_action_dl_addr),
277 [OFPAT_SET_DL_DST] = {
278 sizeof(struct ofp_action_dl_addr),
279 sizeof(struct ofp_action_dl_addr),
281 [OFPAT_SET_NW_SRC] = {
282 sizeof(struct ofp_action_nw_addr),
283 sizeof(struct ofp_action_nw_addr),
285 [OFPAT_SET_NW_DST] = {
286 sizeof(struct ofp_action_nw_addr),
287 sizeof(struct ofp_action_nw_addr),
289 [OFPAT_SET_NW_TOS] = {
290 sizeof(struct ofp_action_nw_tos),
291 sizeof(struct ofp_action_nw_tos),
293 [OFPAT_SET_TP_SRC] = {
294 sizeof(struct ofp_action_tp_port),
295 sizeof(struct ofp_action_tp_port),
297 [OFPAT_SET_TP_DST] = {
298 sizeof(struct ofp_action_tp_port),
299 sizeof(struct ofp_action_tp_port),
301 /* OFPAT_VENDOR is not here, since it would blow up the array size. */
304 if (actions_len < sizeof *ah) {
305 ds_put_format(string, "***action array too short for next action***\n");
309 type = ntohs(ah->type);
310 len = ntohs(ah->len);
311 if (actions_len < len) {
312 ds_put_format(string, "***truncated action %"PRIu16"***\n", type);
317 ds_put_format(string, "***zero-length action***\n");
321 if ((len % OFP_ACTION_ALIGN) != 0) {
322 ds_put_format(string,
323 "***action %"PRIu16" length not a multiple of %d***\n",
324 type, OFP_ACTION_ALIGN);
328 if (type < ARRAY_SIZE(of_actions)) {
329 const struct openflow_action *act = &of_actions[type];
330 if ((len < act->min_size) || (len > act->max_size)) {
331 ds_put_format(string,
332 "***action %"PRIu16" wrong length: %zu***\n", type, len);
339 struct ofp_action_output *oa = (struct ofp_action_output *)ah;
340 uint16_t port = ntohs(oa->port);
341 if (port < OFPP_MAX) {
342 ds_put_format(string, "output:%"PRIu16, port);
344 ofp_print_port_name(string, port);
345 if (port == OFPP_CONTROLLER) {
347 ds_put_format(string, ":%"PRIu16, ntohs(oa->max_len));
349 ds_put_cstr(string, ":all");
356 case OFPAT_ENQUEUE: {
357 struct ofp_action_enqueue *ea = (struct ofp_action_enqueue *)ah;
358 unsigned int port = ntohs(ea->port);
359 unsigned int queue_id = ntohl(ea->queue_id);
360 ds_put_format(string, "enqueue:");
361 if (port != OFPP_IN_PORT) {
362 ds_put_format(string, "%u", port);
364 ds_put_cstr(string, "IN_PORT");
366 ds_put_format(string, "q%u", queue_id);
370 case OFPAT_SET_VLAN_VID: {
371 struct ofp_action_vlan_vid *va = (struct ofp_action_vlan_vid *)ah;
372 ds_put_format(string, "mod_vlan_vid:%"PRIu16, ntohs(va->vlan_vid));
376 case OFPAT_SET_VLAN_PCP: {
377 struct ofp_action_vlan_pcp *va = (struct ofp_action_vlan_pcp *)ah;
378 ds_put_format(string, "mod_vlan_pcp:%"PRIu8, va->vlan_pcp);
382 case OFPAT_STRIP_VLAN:
383 ds_put_cstr(string, "strip_vlan");
386 case OFPAT_SET_DL_SRC: {
387 struct ofp_action_dl_addr *da = (struct ofp_action_dl_addr *)ah;
388 ds_put_format(string, "mod_dl_src:"ETH_ADDR_FMT,
389 ETH_ADDR_ARGS(da->dl_addr));
393 case OFPAT_SET_DL_DST: {
394 struct ofp_action_dl_addr *da = (struct ofp_action_dl_addr *)ah;
395 ds_put_format(string, "mod_dl_dst:"ETH_ADDR_FMT,
396 ETH_ADDR_ARGS(da->dl_addr));
400 case OFPAT_SET_NW_SRC: {
401 struct ofp_action_nw_addr *na = (struct ofp_action_nw_addr *)ah;
402 ds_put_format(string, "mod_nw_src:"IP_FMT, IP_ARGS(&na->nw_addr));
406 case OFPAT_SET_NW_DST: {
407 struct ofp_action_nw_addr *na = (struct ofp_action_nw_addr *)ah;
408 ds_put_format(string, "mod_nw_dst:"IP_FMT, IP_ARGS(&na->nw_addr));
412 case OFPAT_SET_NW_TOS: {
413 struct ofp_action_nw_tos *nt = (struct ofp_action_nw_tos *)ah;
414 ds_put_format(string, "mod_nw_tos:%d", nt->nw_tos);
418 case OFPAT_SET_TP_SRC: {
419 struct ofp_action_tp_port *ta = (struct ofp_action_tp_port *)ah;
420 ds_put_format(string, "mod_tp_src:%d", ntohs(ta->tp_port));
424 case OFPAT_SET_TP_DST: {
425 struct ofp_action_tp_port *ta = (struct ofp_action_tp_port *)ah;
426 ds_put_format(string, "mod_tp_dst:%d", ntohs(ta->tp_port));
431 struct ofp_action_vendor_header *avh
432 = (struct ofp_action_vendor_header *)ah;
433 if (len < sizeof *avh) {
434 ds_put_format(string, "***ofpat_vendor truncated***\n");
437 if (avh->vendor == htonl(NX_VENDOR_ID)) {
438 ofp_print_nx_action(string, (struct nx_action_header *)avh);
440 ds_put_format(string, "vendor action:0x%x", ntohl(avh->vendor));
446 ds_put_format(string, "(decoder %"PRIu16" not implemented)", type);
454 ofp_print_actions(struct ds *string, const struct ofp_action_header *action,
457 uint8_t *p = (uint8_t *)action;
460 ds_put_cstr(string, "actions=");
462 ds_put_cstr(string, "drop");
464 while (actions_len > 0) {
466 ds_put_cstr(string, ",");
468 len = ofp_print_action(string, (struct ofp_action_header *)p,
479 ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
482 size_t len = ntohs(opo->header.length);
483 size_t actions_len = ntohs(opo->actions_len);
485 ds_put_cstr(string, " in_port=");
486 ofp_print_port_name(string, ntohs(opo->in_port));
488 ds_put_format(string, " actions_len=%zu ", actions_len);
489 if (actions_len > (ntohs(opo->header.length) - sizeof *opo)) {
490 ds_put_format(string, "***packet too short for action length***\n");
493 ofp_print_actions(string, opo->actions, actions_len);
495 if (ntohl(opo->buffer_id) == UINT32_MAX) {
496 int data_len = len - sizeof *opo - actions_len;
497 ds_put_format(string, " data_len=%d", data_len);
498 if (verbosity > 0 && len > sizeof *opo) {
499 char *packet = ofp_packet_to_string(
500 (uint8_t *)opo->actions + actions_len, data_len, data_len);
501 ds_put_char(string, '\n');
502 ds_put_cstr(string, packet);
506 ds_put_format(string, " buffer=0x%08"PRIx32, ntohl(opo->buffer_id));
508 ds_put_char(string, '\n');
511 /* qsort comparison function. */
513 compare_ports(const void *a_, const void *b_)
515 const struct ofp_phy_port *a = a_;
516 const struct ofp_phy_port *b = b_;
517 uint16_t ap = ntohs(a->port_no);
518 uint16_t bp = ntohs(b->port_no);
520 return ap < bp ? -1 : ap > bp;
523 static void ofp_print_port_features(struct ds *string, uint32_t features)
526 ds_put_cstr(string, "Unsupported\n");
529 if (features & OFPPF_10MB_HD) {
530 ds_put_cstr(string, "10MB-HD ");
532 if (features & OFPPF_10MB_FD) {
533 ds_put_cstr(string, "10MB-FD ");
535 if (features & OFPPF_100MB_HD) {
536 ds_put_cstr(string, "100MB-HD ");
538 if (features & OFPPF_100MB_FD) {
539 ds_put_cstr(string, "100MB-FD ");
541 if (features & OFPPF_1GB_HD) {
542 ds_put_cstr(string, "1GB-HD ");
544 if (features & OFPPF_1GB_FD) {
545 ds_put_cstr(string, "1GB-FD ");
547 if (features & OFPPF_10GB_FD) {
548 ds_put_cstr(string, "10GB-FD ");
550 if (features & OFPPF_COPPER) {
551 ds_put_cstr(string, "COPPER ");
553 if (features & OFPPF_FIBER) {
554 ds_put_cstr(string, "FIBER ");
556 if (features & OFPPF_AUTONEG) {
557 ds_put_cstr(string, "AUTO_NEG ");
559 if (features & OFPPF_PAUSE) {
560 ds_put_cstr(string, "AUTO_PAUSE ");
562 if (features & OFPPF_PAUSE_ASYM) {
563 ds_put_cstr(string, "AUTO_PAUSE_ASYM ");
565 ds_put_char(string, '\n');
569 ofp_print_phy_port(struct ds *string, const struct ofp_phy_port *port)
571 char name[OFP_MAX_PORT_NAME_LEN];
574 memcpy(name, port->name, sizeof name);
575 for (j = 0; j < sizeof name - 1; j++) {
576 if (!isprint(name[j])) {
582 ds_put_char(string, ' ');
583 ofp_print_port_name(string, ntohs(port->port_no));
584 ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT", config: %#x, state:%#x\n",
585 name, ETH_ADDR_ARGS(port->hw_addr), ntohl(port->config),
588 ds_put_format(string, " current: ");
589 ofp_print_port_features(string, ntohl(port->curr));
591 if (port->advertised) {
592 ds_put_format(string, " advertised: ");
593 ofp_print_port_features(string, ntohl(port->advertised));
595 if (port->supported) {
596 ds_put_format(string, " supported: ");
597 ofp_print_port_features(string, ntohl(port->supported));
600 ds_put_format(string, " peer: ");
601 ofp_print_port_features(string, ntohl(port->peer));
606 ofp_print_switch_features(struct ds *string,
607 const struct ofp_switch_features *osf)
609 size_t len = ntohs(osf->header.length);
610 struct ofp_phy_port *port_list;
614 ds_put_format(string, " ver:0x%x, dpid:%016"PRIx64"\n",
615 osf->header.version, ntohll(osf->datapath_id));
616 ds_put_format(string, "n_tables:%d, n_buffers:%d\n", osf->n_tables,
617 ntohl(osf->n_buffers));
618 ds_put_format(string, "features: capabilities:%#x, actions:%#x\n",
619 ntohl(osf->capabilities), ntohl(osf->actions));
621 n_ports = (len - sizeof *osf) / sizeof *osf->ports;
623 port_list = xmemdup(osf->ports, len - sizeof *osf);
624 qsort(port_list, n_ports, sizeof *port_list, compare_ports);
625 for (i = 0; i < n_ports; i++) {
626 ofp_print_phy_port(string, &port_list[i]);
632 ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc)
636 flags = ntohs(osc->flags);
638 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
641 ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len));
644 static void print_wild(struct ds *string, const char *leader, int is_wild,
645 int verbosity, const char *format, ...)
646 __attribute__((format(printf, 5, 6)));
648 static void print_wild(struct ds *string, const char *leader, int is_wild,
649 int verbosity, const char *format, ...)
651 if (is_wild && verbosity < 2) {
654 ds_put_cstr(string, leader);
658 va_start(args, format);
659 ds_put_format_valist(string, format, args);
662 ds_put_char(string, '*');
664 ds_put_char(string, ',');
668 print_ip_netmask(struct ds *string, const char *leader, uint32_t ip,
669 uint32_t wild_bits, int verbosity)
671 if (wild_bits >= 32 && verbosity < 2) {
674 ds_put_cstr(string, leader);
675 if (wild_bits < 32) {
676 ds_put_format(string, IP_FMT, IP_ARGS(&ip));
678 ds_put_format(string, "/%d", 32 - wild_bits);
681 ds_put_char(string, '*');
683 ds_put_char(string, ',');
687 ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
689 char *s = ofp_match_to_string(om, verbosity);
695 ofp_match_to_string(const struct ofp_match *om, int verbosity)
697 struct ds f = DS_EMPTY_INITIALIZER;
698 uint32_t w = ntohl(om->wildcards);
699 bool skip_type = false;
700 bool skip_proto = false;
702 if (!(w & OFPFW_DL_TYPE)) {
704 if (om->dl_type == htons(ETH_TYPE_IP)) {
705 if (!(w & OFPFW_NW_PROTO)) {
707 if (om->nw_proto == IP_TYPE_ICMP) {
708 ds_put_cstr(&f, "icmp,");
709 } else if (om->nw_proto == IP_TYPE_TCP) {
710 ds_put_cstr(&f, "tcp,");
711 } else if (om->nw_proto == IP_TYPE_UDP) {
712 ds_put_cstr(&f, "udp,");
714 ds_put_cstr(&f, "ip,");
718 ds_put_cstr(&f, "ip,");
720 } else if (om->dl_type == htons(ETH_TYPE_ARP)) {
721 ds_put_cstr(&f, "arp,");
726 if (w & NXFW_TUN_ID) {
727 ds_put_cstr(&f, "tun_id_wild,");
729 print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
730 "%d", ntohs(om->in_port));
731 print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
732 "%d", ntohs(om->dl_vlan));
733 print_wild(&f, "dl_vlan_pcp=", w & OFPFW_DL_VLAN_PCP, verbosity,
734 "%d", om->dl_vlan_pcp);
735 print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
736 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
737 print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
738 ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
740 print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
741 "0x%04x", ntohs(om->dl_type));
743 print_ip_netmask(&f, "nw_src=", om->nw_src,
744 (w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
745 print_ip_netmask(&f, "nw_dst=", om->nw_dst,
746 (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
748 if (om->dl_type == htons(ETH_TYPE_ARP)) {
749 print_wild(&f, "opcode=", w & OFPFW_NW_PROTO, verbosity,
752 print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
756 print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
758 if (om->nw_proto == IP_TYPE_ICMP) {
759 print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
760 "%d", ntohs(om->icmp_type));
761 print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
762 "%d", ntohs(om->icmp_code));
764 print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
765 "%d", ntohs(om->tp_src));
766 print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
767 "%d", ntohs(om->tp_dst));
773 ofp_print_flow_mod(struct ds *string, const struct ofp_flow_mod *ofm,
776 size_t len = ntohs(ofm->header.length);
778 ds_put_char(string, ' ');
779 ofp_print_match(string, &ofm->match, verbosity);
780 if (ds_last(string) != ' ') {
781 ds_put_char(string, ' ');
784 switch (ntohs(ofm->command)) {
786 ds_put_cstr(string, "ADD:");
789 ds_put_cstr(string, "MOD:");
791 case OFPFC_MODIFY_STRICT:
792 ds_put_cstr(string, "MOD_STRICT:");
795 ds_put_cstr(string, "DEL:");
797 case OFPFC_DELETE_STRICT:
798 ds_put_cstr(string, "DEL_STRICT:");
801 ds_put_format(string, "cmd:%d", ntohs(ofm->command));
803 if (ofm->cookie != htonll(0)) {
804 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(ofm->cookie));
806 if (ofm->idle_timeout != htons(OFP_FLOW_PERMANENT)) {
807 ds_put_format(string, " idle:%d", ntohs(ofm->idle_timeout));
809 if (ofm->hard_timeout != htons(OFP_FLOW_PERMANENT)) {
810 ds_put_format(string, " hard:%d", ntohs(ofm->hard_timeout));
812 if (ofm->priority != htons(32768)) {
813 ds_put_format(string, " pri:%"PRIu16, ntohs(ofm->priority));
815 if (ofm->buffer_id != htonl(UINT32_MAX)) {
816 ds_put_format(string, " buf:%#"PRIx32, ntohl(ofm->buffer_id));
818 if (ofm->flags != htons(0)) {
819 ds_put_format(string, " flags:%"PRIx16, ntohs(ofm->flags));
821 ds_put_cstr(string, " ");
822 ofp_print_actions(string, ofm->actions,
823 len - offsetof(struct ofp_flow_mod, actions));
824 ds_put_char(string, '\n');
828 ofp_print_flow_removed(struct ds *string, const struct ofp_flow_removed *ofr,
831 ofp_print_match(string, &ofr->match, verbosity);
832 ds_put_cstr(string, " reason=");
833 switch (ofr->reason) {
834 case OFPRR_IDLE_TIMEOUT:
835 ds_put_cstr(string, "idle");
837 case OFPRR_HARD_TIMEOUT:
838 ds_put_cstr(string, "hard");
841 ds_put_cstr(string, "delete");
844 ds_put_format(string, "**%"PRIu8"**", ofr->reason);
848 if (ofr->cookie != htonll(0)) {
849 ds_put_format(string, " cookie:0x%"PRIx64, ntohll(ofr->cookie));
851 if (ofr->priority != htons(32768)) {
852 ds_put_format(string, " pri:%"PRIu16, ntohs(ofr->priority));
854 ds_put_format(string, " secs%"PRIu32" nsecs%"PRIu32
855 " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n",
856 ntohl(ofr->duration_sec), ntohl(ofr->duration_nsec),
857 ntohs(ofr->idle_timeout), ntohll(ofr->packet_count),
858 ntohll(ofr->byte_count));
862 ofp_print_port_mod(struct ds *string, const struct ofp_port_mod *opm)
864 ds_put_format(string, "port: %d: addr:"ETH_ADDR_FMT", config: %#x, mask:%#x\n",
865 ntohs(opm->port_no), ETH_ADDR_ARGS(opm->hw_addr),
866 ntohl(opm->config), ntohl(opm->mask));
867 ds_put_format(string, " advertise: ");
868 if (opm->advertise) {
869 ofp_print_port_features(string, ntohl(opm->advertise));
871 ds_put_format(string, "UNCHANGED\n");
881 static const struct error_type error_types[] = {
882 #define ERROR_TYPE(TYPE) {TYPE, -1, #TYPE}
883 #define ERROR_CODE(TYPE, CODE) {TYPE, CODE, #CODE}
884 ERROR_TYPE(OFPET_HELLO_FAILED),
885 ERROR_CODE(OFPET_HELLO_FAILED, OFPHFC_INCOMPATIBLE),
886 ERROR_CODE(OFPET_HELLO_FAILED, OFPHFC_EPERM),
888 ERROR_TYPE(OFPET_BAD_REQUEST),
889 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BAD_VERSION),
890 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BAD_TYPE),
891 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BAD_STAT),
892 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BAD_VENDOR),
893 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BAD_SUBTYPE),
894 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_EPERM),
895 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN),
896 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BUFFER_EMPTY),
897 ERROR_CODE(OFPET_BAD_REQUEST, OFPBRC_BUFFER_UNKNOWN),
899 ERROR_TYPE(OFPET_BAD_ACTION),
900 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_BAD_TYPE),
901 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_BAD_LEN),
902 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_BAD_VENDOR),
903 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_BAD_VENDOR_TYPE),
904 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_BAD_OUT_PORT),
905 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_BAD_ARGUMENT),
906 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_EPERM),
907 ERROR_CODE(OFPET_BAD_ACTION, OFPBAC_TOO_MANY),
909 ERROR_TYPE(OFPET_FLOW_MOD_FAILED),
910 ERROR_CODE(OFPET_FLOW_MOD_FAILED, OFPFMFC_ALL_TABLES_FULL),
911 ERROR_CODE(OFPET_FLOW_MOD_FAILED, OFPFMFC_OVERLAP),
912 ERROR_CODE(OFPET_FLOW_MOD_FAILED, OFPFMFC_EPERM),
913 ERROR_CODE(OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_EMERG_TIMEOUT),
914 ERROR_CODE(OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_COMMAND),
916 ERROR_TYPE(OFPET_PORT_MOD_FAILED),
917 ERROR_CODE(OFPET_PORT_MOD_FAILED, OFPPMFC_BAD_PORT),
918 ERROR_CODE(OFPET_PORT_MOD_FAILED, OFPPMFC_BAD_HW_ADDR)
920 #define N_ERROR_TYPES ARRAY_SIZE(error_types)
923 lookup_error_type(int type)
925 const struct error_type *t;
927 for (t = error_types; t < &error_types[N_ERROR_TYPES]; t++) {
928 if (t->type == type && t->code == -1) {
936 lookup_error_code(int type, int code)
938 const struct error_type *t;
940 for (t = error_types; t < &error_types[N_ERROR_TYPES]; t++) {
941 if (t->type == type && t->code == code) {
949 ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
951 size_t len = ntohs(oem->header.length);
952 int type = ntohs(oem->type);
953 int code = ntohs(oem->code);
956 ds_put_format(string, " type%d(%s) code%d(%s) payload:\n",
957 type, lookup_error_type(type),
958 code, lookup_error_code(type, code));
961 case OFPET_HELLO_FAILED:
962 ds_put_printable(string, (char *) oem->data, len - sizeof *oem);
965 case OFPET_BAD_REQUEST:
966 s = ofp_to_string(oem->data, len - sizeof *oem, 1);
967 ds_put_cstr(string, s);
972 ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
978 ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops)
980 if (ops->reason == OFPPR_ADD) {
981 ds_put_format(string, " ADD:");
982 } else if (ops->reason == OFPPR_DELETE) {
983 ds_put_format(string, " DEL:");
984 } else if (ops->reason == OFPPR_MODIFY) {
985 ds_put_format(string, " MOD:");
988 ofp_print_phy_port(string, &ops->desc);
992 ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
994 const struct ofp_desc_stats *ods = ofputil_stats_body(oh);
996 ds_put_format(string, "Manufacturer: %.*s\n",
997 (int) sizeof ods->mfr_desc, ods->mfr_desc);
998 ds_put_format(string, "Hardware: %.*s\n",
999 (int) sizeof ods->hw_desc, ods->hw_desc);
1000 ds_put_format(string, "Software: %.*s\n",
1001 (int) sizeof ods->sw_desc, ods->sw_desc);
1002 ds_put_format(string, "Serial Num: %.*s\n",
1003 (int) sizeof ods->serial_num, ods->serial_num);
1004 ds_put_format(string, "DP Description: %.*s\n",
1005 (int) sizeof ods->dp_desc, ods->dp_desc);
1009 ofp_print_ofpst_flow_request(struct ds *string, const struct ofp_header *oh,
1012 const struct ofp_flow_stats_request *fsr = ofputil_stats_body(oh);
1014 if (fsr->table_id == 0xff) {
1015 ds_put_format(string, " table_id=any, ");
1017 ds_put_format(string, " table_id=%"PRIu8", ", fsr->table_id);
1020 ofp_print_match(string, &fsr->match, verbosity);
1024 ofp_print_ofpst_flow_reply(struct ds *string, const struct ofp_header *oh,
1027 size_t len = ofputil_stats_body_len(oh);
1028 const char *body = ofputil_stats_body(oh);
1029 const char *pos = body;
1031 const struct ofp_flow_stats *fs;
1032 ptrdiff_t bytes_left = body + len - pos;
1035 if (bytes_left < sizeof *fs) {
1036 if (bytes_left != 0) {
1037 ds_put_format(string, " ***%td leftover bytes at end***",
1043 fs = (const void *) pos;
1044 length = ntohs(fs->length);
1045 if (length < sizeof *fs) {
1046 ds_put_format(string, " ***length=%zu shorter than minimum %zu***",
1047 length, sizeof *fs);
1049 } else if (length > bytes_left) {
1050 ds_put_format(string,
1051 " ***length=%zu but only %td bytes left***",
1052 length, bytes_left);
1054 } else if ((length - sizeof *fs) % sizeof fs->actions[0]) {
1055 ds_put_format(string,
1056 " ***length=%zu has %zu bytes leftover in "
1059 (length - sizeof *fs) % sizeof fs->actions[0]);
1063 ds_put_format(string, " cookie=0x%"PRIx64", ", ntohll(fs->cookie));
1064 ds_put_format(string, "duration_sec=%"PRIu32"s, ",
1065 ntohl(fs->duration_sec));
1066 ds_put_format(string, "duration_nsec=%"PRIu32"ns, ",
1067 ntohl(fs->duration_nsec));
1068 ds_put_format(string, "table_id=%"PRIu8", ", fs->table_id);
1069 ds_put_format(string, "priority=%"PRIu16", ",
1070 fs->match.wildcards ? ntohs(fs->priority) : (uint16_t)-1);
1071 ds_put_format(string, "n_packets=%"PRIu64", ",
1072 ntohll(fs->packet_count));
1073 ds_put_format(string, "n_bytes=%"PRIu64", ", ntohll(fs->byte_count));
1074 if (fs->idle_timeout != htons(OFP_FLOW_PERMANENT)) {
1075 ds_put_format(string, "idle_timeout=%"PRIu16",",
1076 ntohs(fs->idle_timeout));
1078 if (fs->hard_timeout != htons(OFP_FLOW_PERMANENT)) {
1079 ds_put_format(string, "hard_timeout=%"PRIu16",",
1080 ntohs(fs->hard_timeout));
1082 ofp_print_match(string, &fs->match, verbosity);
1083 ofp_print_actions(string, fs->actions, length - sizeof *fs);
1084 ds_put_char(string, '\n');
1091 ofp_print_ofpst_aggregate_request(struct ds *string,
1092 const struct ofp_header *oh, int verbosity)
1094 const struct ofp_aggregate_stats_request *asr = ofputil_stats_body(oh);
1096 if (asr->table_id == 0xff) {
1097 ds_put_format(string, " table_id=any, ");
1099 ds_put_format(string, " table_id=%"PRIu8", ", asr->table_id);
1102 ofp_print_match(string, &asr->match, verbosity);
1106 ofp_print_ofpst_aggregate_reply(struct ds *string, const struct ofp_header *oh)
1108 const struct ofp_aggregate_stats_reply *asr = ofputil_stats_body(oh);
1110 ds_put_format(string, " packet_count=%"PRIu64, ntohll(asr->packet_count));
1111 ds_put_format(string, " byte_count=%"PRIu64, ntohll(asr->byte_count));
1112 ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count));
1115 static void print_port_stat(struct ds *string, const char *leader,
1116 uint64_t stat, int more)
1118 ds_put_cstr(string, leader);
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, const struct ofp_header *oh)
1134 const struct ofp_port_stats_request *psr = ofputil_stats_body(oh);
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=", ntohll(ps->rx_packets), 1);
1154 print_port_stat(string, "bytes=", ntohll(ps->rx_bytes), 1);
1155 print_port_stat(string, "drop=", ntohll(ps->rx_dropped), 1);
1156 print_port_stat(string, "errs=", ntohll(ps->rx_errors), 1);
1157 print_port_stat(string, "frame=", ntohll(ps->rx_frame_err), 1);
1158 print_port_stat(string, "over=", ntohll(ps->rx_over_err), 1);
1159 print_port_stat(string, "crc=", ntohll(ps->rx_crc_err), 0);
1161 ds_put_cstr(string, " tx ");
1162 print_port_stat(string, "pkts=", ntohll(ps->tx_packets), 1);
1163 print_port_stat(string, "bytes=", ntohll(ps->tx_bytes), 1);
1164 print_port_stat(string, "drop=", ntohll(ps->tx_dropped), 1);
1165 print_port_stat(string, "errs=", ntohll(ps->tx_errors), 1);
1166 print_port_stat(string, "coll=", ntohll(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 strncpy(name, ts->name, sizeof name);
1184 name[OFP_MAX_TABLE_NAME_LEN] = '\0';
1186 ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
1187 ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
1188 ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
1189 ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
1190 ds_put_cstr(string, " ");
1191 ds_put_format(string, "lookup=%"PRIu64", ",
1192 ntohll(ts->lookup_count));
1193 ds_put_format(string, "matched=%"PRIu64"\n",
1194 ntohll(ts->matched_count));
1199 ofp_print_queue_name(struct ds *string, uint32_t queue_id)
1201 if (queue_id == OFPQ_ALL) {
1202 ds_put_cstr(string, "ALL");
1204 ds_put_format(string, "%"PRIu32, queue_id);
1209 ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
1211 const struct ofp_queue_stats_request *qsr = ofputil_stats_body(oh);
1213 ds_put_cstr(string, "port=");
1214 ofp_print_port_name(string, ntohs(qsr->port_no));
1216 ds_put_cstr(string, " queue=");
1217 ofp_print_queue_name(string, ntohl(qsr->queue_id));
1221 ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
1224 const struct ofp_queue_stats *qs = ofputil_stats_body(oh);
1225 size_t n = ofputil_stats_body_len(oh) / sizeof *qs;
1226 ds_put_format(string, " %zu queues\n", n);
1227 if (verbosity < 1) {
1232 ds_put_cstr(string, " port ");
1233 ofp_print_port_name(string, ntohs(qs->port_no));
1234 ds_put_cstr(string, " queue ");
1235 ofp_print_queue_name(string, ntohl(qs->queue_id));
1236 ds_put_cstr(string, ": ");
1238 print_port_stat(string, "bytes=", ntohll(qs->tx_bytes), 1);
1239 print_port_stat(string, "pkts=", ntohll(qs->tx_packets), 1);
1240 print_port_stat(string, "errors=", ntohll(qs->tx_errors), 0);
1245 ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
1247 const struct ofp_stats_request *srq
1248 = (const struct ofp_stats_request *) oh;
1251 ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***",
1257 ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
1259 const struct ofp_stats_reply *srp = (const struct ofp_stats_reply *) oh;
1262 uint16_t flags = ntohs(srp->flags);
1264 ds_put_cstr(string, " flags=");
1265 if (flags & OFPSF_REPLY_MORE) {
1266 ds_put_cstr(string, "[more]");
1267 flags &= ~OFPSF_REPLY_MORE;
1270 ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
1277 ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
1279 size_t len = ntohs(oh->length);
1281 ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
1282 if (verbosity > 1) {
1283 ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
1288 ofp_to_string__(const struct ofp_header *oh,
1289 const struct ofputil_msg_type *type, struct ds *string,
1292 const void *msg = oh;
1294 ds_put_format(string, "%s (xid=0x%"PRIx32"):",
1295 ofputil_msg_type_name(type), ntohl(oh->xid));
1297 switch (ofputil_msg_type_code(type)) {
1298 case OFPUTIL_INVALID:
1301 case OFPUTIL_OFPT_HELLO:
1304 case OFPUTIL_OFPT_ERROR:
1305 ofp_print_error_msg(string, msg);
1308 case OFPUTIL_OFPT_ECHO_REQUEST:
1309 case OFPUTIL_OFPT_ECHO_REPLY:
1310 ofp_print_echo(string, oh, verbosity);
1313 case OFPUTIL_OFPT_FEATURES_REQUEST:
1316 case OFPUTIL_OFPT_FEATURES_REPLY:
1317 ofp_print_switch_features(string, msg);
1320 case OFPUTIL_OFPT_GET_CONFIG_REQUEST:
1323 case OFPUTIL_OFPT_GET_CONFIG_REPLY:
1324 case OFPUTIL_OFPT_SET_CONFIG:
1325 ofp_print_switch_config(string, msg);
1328 case OFPUTIL_OFPT_PACKET_IN:
1329 ofp_print_packet_in(string, msg, verbosity);
1332 case OFPUTIL_OFPT_FLOW_REMOVED:
1333 ofp_print_flow_removed(string, msg, verbosity);
1336 case OFPUTIL_OFPT_PORT_STATUS:
1337 ofp_print_port_status(string, msg);
1340 case OFPUTIL_OFPT_PACKET_OUT:
1341 ofp_print_packet_out(string, msg, verbosity);
1344 case OFPUTIL_OFPT_FLOW_MOD:
1345 ofp_print_flow_mod(string, msg, verbosity);
1348 case OFPUTIL_OFPT_PORT_MOD:
1349 ofp_print_port_mod(string, msg);
1352 case OFPUTIL_OFPT_BARRIER_REQUEST:
1353 case OFPUTIL_OFPT_BARRIER_REPLY:
1356 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST:
1357 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY:
1361 case OFPUTIL_OFPST_DESC_REQUEST:
1362 ofp_print_stats_request(string, oh);
1365 case OFPUTIL_OFPST_FLOW_REQUEST:
1366 ofp_print_stats_request(string, oh);
1367 ofp_print_ofpst_flow_request(string, oh, verbosity);
1370 case OFPUTIL_OFPST_AGGREGATE_REQUEST:
1371 ofp_print_stats_request(string, oh);
1372 ofp_print_ofpst_aggregate_request(string, oh, verbosity);
1375 case OFPUTIL_OFPST_TABLE_REQUEST:
1376 ofp_print_stats_request(string, oh);
1379 case OFPUTIL_OFPST_PORT_REQUEST:
1380 ofp_print_stats_request(string, oh);
1381 ofp_print_ofpst_port_request(string, oh);
1384 case OFPUTIL_OFPST_QUEUE_REQUEST:
1385 ofp_print_stats_request(string, oh);
1386 ofp_print_ofpst_queue_request(string, oh);
1389 case OFPUTIL_OFPST_DESC_REPLY:
1390 ofp_print_stats_reply(string, oh);
1391 ofp_print_ofpst_desc_reply(string, oh);
1394 case OFPUTIL_OFPST_FLOW_REPLY:
1395 ofp_print_stats_reply(string, oh);
1396 ofp_print_ofpst_flow_reply(string, oh, verbosity);
1399 case OFPUTIL_OFPST_QUEUE_REPLY:
1400 ofp_print_stats_reply(string, oh);
1401 ofp_print_ofpst_queue_reply(string, oh, verbosity);
1404 case OFPUTIL_OFPST_PORT_REPLY:
1405 ofp_print_stats_reply(string, oh);
1406 ofp_print_ofpst_port_reply(string, oh, verbosity);
1409 case OFPUTIL_OFPST_TABLE_REPLY:
1410 ofp_print_stats_reply(string, oh);
1411 ofp_print_ofpst_table_reply(string, oh, verbosity);
1414 case OFPUTIL_OFPST_AGGREGATE_REPLY:
1415 ofp_print_stats_reply(string, oh);
1416 ofp_print_ofpst_aggregate_reply(string, oh);
1419 case OFPUTIL_NXT_STATUS_REQUEST:
1420 case OFPUTIL_NXT_STATUS_REPLY:
1421 case OFPUTIL_NXT_TUN_ID_FROM_COOKIE:
1422 case OFPUTIL_NXT_ROLE_REQUEST:
1423 case OFPUTIL_NXT_ROLE_REPLY:
1424 case OFPUTIL_NXT_SET_FLOW_FORMAT:
1425 case OFPUTIL_NXT_FLOW_MOD:
1426 case OFPUTIL_NXT_FLOW_REMOVED:
1427 case OFPUTIL_NXST_FLOW_REQUEST:
1428 case OFPUTIL_NXST_AGGREGATE_REQUEST:
1429 case OFPUTIL_NXST_FLOW_REPLY:
1430 case OFPUTIL_NXST_AGGREGATE_REPLY:
1436 /* Composes and returns a string representing the OpenFlow packet of 'len'
1437 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1438 * verbosity and higher numbers increase verbosity. The caller is responsible
1439 * for freeing the string. */
1441 ofp_to_string(const void *oh_, size_t len, int verbosity)
1443 struct ds string = DS_EMPTY_INITIALIZER;
1444 const struct ofp_header *oh = oh_;
1446 if (len < sizeof(struct ofp_header)) {
1447 ds_put_cstr(&string, "OpenFlow packet too short:\n");
1448 } else if (oh->version != OFP_VERSION) {
1449 ds_put_format(&string, "Bad OpenFlow version %"PRIu8":\n",
1451 } else if (ntohs(oh->length) > len) {
1452 ds_put_format(&string,
1453 "(***truncated to %zu bytes from %"PRIu16"***)",
1454 len, ntohs(oh->length));
1455 } else if (ntohs(oh->length) < len) {
1456 ds_put_format(&string,
1457 "(***only uses %"PRIu16" bytes out of %zu***)\n",
1458 ntohs(oh->length), len);
1460 const struct ofputil_msg_type *type;
1461 int err_type, err_code;
1464 error = ofputil_decode_msg_type(oh, &type);
1466 ofp_to_string__(oh, type, &string, verbosity);
1467 if (verbosity >= 3) {
1468 ds_put_hex_dump(&string, oh, len, 0, true);
1470 if (string.string[string.length - 1] != '\n') {
1471 ds_put_char(&string, '\n');
1473 return ds_steal_cstr(&string);
1476 err_type = get_ofp_err_type(error);
1477 err_code = get_ofp_err_code(error);
1478 ds_put_format(&string, "Bad OpenFlow message (%s, %s)\n",
1479 lookup_error_type(err_type),
1480 lookup_error_code(err_type, err_code));
1482 ds_put_hex_dump(&string, oh, len, 0, true);
1483 return ds_steal_cstr(&string);
1486 /* Returns the name for the specified OpenFlow message type as a string,
1487 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1488 * hex number, e.g. "0x55".
1490 * The caller must free the returned string when it is no longer needed. */
1492 ofp_message_type_to_string(uint8_t type)
1503 case OFPT_ECHO_REQUEST:
1504 name = "ECHO_REQUEST";
1506 case OFPT_ECHO_REPLY:
1507 name = "ECHO_REPLY";
1512 case OFPT_FEATURES_REQUEST:
1513 name = "FEATURES_REQUEST";
1515 case OFPT_FEATURES_REPLY:
1516 name = "FEATURES_REPLY";
1518 case OFPT_GET_CONFIG_REQUEST:
1519 name = "GET_CONFIG_REQUEST";
1521 case OFPT_GET_CONFIG_REPLY:
1522 name = "GET_CONFIG_REPLY";
1524 case OFPT_SET_CONFIG:
1525 name = "SET_CONFIG";
1527 case OFPT_PACKET_IN:
1530 case OFPT_FLOW_REMOVED:
1531 name = "FLOW_REMOVED";
1533 case OFPT_PORT_STATUS:
1534 name = "PORT_STATUS";
1536 case OFPT_PACKET_OUT:
1537 name = "PACKET_OUT";
1545 case OFPT_STATS_REQUEST:
1546 name = "STATS_REQUEST";
1548 case OFPT_STATS_REPLY:
1549 name = "STATS_REPLY";
1551 case OFPT_BARRIER_REQUEST:
1552 name = "BARRIER_REQUEST";
1554 case OFPT_BARRIER_REPLY:
1555 name = "BARRIER_REPLY";
1557 case OFPT_QUEUE_GET_CONFIG_REQUEST:
1558 name = "QUEUE_GET_CONFIG_REQUEST";
1560 case OFPT_QUEUE_GET_CONFIG_REPLY:
1561 name = "QUEUE_GET_CONFIG_REPLY";
1568 return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
1572 print_and_free(FILE *stream, char *string)
1574 fputs(string, stream);
1578 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1579 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1580 * numbers increase verbosity. */
1582 ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
1584 print_and_free(stream, ofp_to_string(oh, len, verbosity));
1587 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1588 * 'data' to 'stream' using tcpdump. 'total_len' specifies the full length of
1589 * the Ethernet frame (of which 'len' bytes were captured).
1591 * This starts and kills a tcpdump subprocess so it's quite expensive. */
1593 ofp_print_packet(FILE *stream, const void *data, size_t len, size_t total_len)
1595 print_and_free(stream, ofp_packet_to_string(data, len, total_len));