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"
35 #include "multipath.h"
39 #include "openflow/openflow.h"
40 #include "openflow/nicira-ext.h"
43 #include "type-props.h"
44 #include "unaligned.h"
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 ofputil_format_port(ntohs(op
->in_port
), string
);
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, 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
);
156 print_note(struct ds
*string
, const struct nx_action_note
*nan
)
161 ds_put_cstr(string
, "note:");
162 len
= ntohs(nan
->len
) - offsetof(struct nx_action_note
, note
);
163 for (i
= 0; i
< len
; i
++) {
165 ds_put_char(string
, '.');
167 ds_put_format(string
, "%02"PRIx8
, nan
->note
[i
]);
172 ofp_print_action(struct ds
*s
, const union ofp_action
*a
,
173 enum ofputil_action_code code
)
175 const struct ofp_action_enqueue
*oae
;
176 const struct ofp_action_dl_addr
*oada
;
177 const struct nx_action_set_tunnel64
*nast64
;
178 const struct nx_action_set_tunnel
*nast
;
179 const struct nx_action_set_queue
*nasq
;
180 const struct nx_action_resubmit
*nar
;
181 const struct nx_action_reg_move
*move
;
182 const struct nx_action_reg_load
*load
;
183 const struct nx_action_multipath
*nam
;
184 const struct nx_action_autopath
*naa
;
185 const struct nx_action_output_reg
*naor
;
189 case OFPUTIL_OFPAT_OUTPUT
:
190 port
= ntohs(a
->output
.port
);
191 if (port
< OFPP_MAX
) {
192 ds_put_format(s
, "output:%"PRIu16
, port
);
194 ofputil_format_port(port
, s
);
195 if (port
== OFPP_CONTROLLER
) {
196 if (a
->output
.max_len
!= htons(0)) {
197 ds_put_format(s
, ":%"PRIu16
, ntohs(a
->output
.max_len
));
199 ds_put_cstr(s
, ":all");
205 case OFPUTIL_OFPAT_ENQUEUE
:
206 oae
= (const struct ofp_action_enqueue
*) a
;
207 ds_put_format(s
, "enqueue:");
208 ofputil_format_port(ntohs(oae
->port
), s
);
209 ds_put_format(s
, "q%"PRIu32
, ntohl(oae
->queue_id
));
212 case OFPUTIL_OFPAT_SET_VLAN_VID
:
213 ds_put_format(s
, "mod_vlan_vid:%"PRIu16
,
214 ntohs(a
->vlan_vid
.vlan_vid
));
217 case OFPUTIL_OFPAT_SET_VLAN_PCP
:
218 ds_put_format(s
, "mod_vlan_pcp:%"PRIu8
, a
->vlan_pcp
.vlan_pcp
);
221 case OFPUTIL_OFPAT_STRIP_VLAN
:
222 ds_put_cstr(s
, "strip_vlan");
225 case OFPUTIL_OFPAT_SET_DL_SRC
:
226 oada
= (const struct ofp_action_dl_addr
*) a
;
227 ds_put_format(s
, "mod_dl_src:"ETH_ADDR_FMT
,
228 ETH_ADDR_ARGS(oada
->dl_addr
));
231 case OFPUTIL_OFPAT_SET_DL_DST
:
232 oada
= (const struct ofp_action_dl_addr
*) a
;
233 ds_put_format(s
, "mod_dl_dst:"ETH_ADDR_FMT
,
234 ETH_ADDR_ARGS(oada
->dl_addr
));
237 case OFPUTIL_OFPAT_SET_NW_SRC
:
238 ds_put_format(s
, "mod_nw_src:"IP_FMT
, IP_ARGS(&a
->nw_addr
.nw_addr
));
241 case OFPUTIL_OFPAT_SET_NW_DST
:
242 ds_put_format(s
, "mod_nw_dst:"IP_FMT
, IP_ARGS(&a
->nw_addr
.nw_addr
));
245 case OFPUTIL_OFPAT_SET_NW_TOS
:
246 ds_put_format(s
, "mod_nw_tos:%d", a
->nw_tos
.nw_tos
);
249 case OFPUTIL_OFPAT_SET_TP_SRC
:
250 ds_put_format(s
, "mod_tp_src:%d", ntohs(a
->tp_port
.tp_port
));
253 case OFPUTIL_OFPAT_SET_TP_DST
:
254 ds_put_format(s
, "mod_tp_dst:%d", ntohs(a
->tp_port
.tp_port
));
257 case OFPUTIL_NXAST_RESUBMIT
:
258 nar
= (struct nx_action_resubmit
*)a
;
259 ds_put_format(s
, "resubmit:");
260 ofputil_format_port(ntohs(nar
->in_port
), s
);
263 case OFPUTIL_NXAST_RESUBMIT_TABLE
:
264 nar
= (struct nx_action_resubmit
*)a
;
265 ds_put_format(s
, "resubmit(");
266 if (nar
->in_port
!= htons(OFPP_IN_PORT
)) {
267 ofputil_format_port(ntohs(nar
->in_port
), s
);
270 if (nar
->table
!= 255) {
271 ds_put_format(s
, "%"PRIu8
, nar
->table
);
276 case OFPUTIL_NXAST_SET_TUNNEL
:
277 nast
= (struct nx_action_set_tunnel
*)a
;
278 ds_put_format(s
, "set_tunnel:%#"PRIx32
, ntohl(nast
->tun_id
));
281 case OFPUTIL_NXAST_SET_QUEUE
:
282 nasq
= (struct nx_action_set_queue
*)a
;
283 ds_put_format(s
, "set_queue:%u", ntohl(nasq
->queue_id
));
286 case OFPUTIL_NXAST_POP_QUEUE
:
287 ds_put_cstr(s
, "pop_queue");
290 case OFPUTIL_NXAST_NOTE
:
291 print_note(s
, (const struct nx_action_note
*) a
);
294 case OFPUTIL_NXAST_REG_MOVE
:
295 move
= (const struct nx_action_reg_move
*) a
;
296 nxm_format_reg_move(move
, s
);
299 case OFPUTIL_NXAST_REG_LOAD
:
300 load
= (const struct nx_action_reg_load
*) a
;
301 nxm_format_reg_load(load
, s
);
304 case OFPUTIL_NXAST_SET_TUNNEL64
:
305 nast64
= (const struct nx_action_set_tunnel64
*) a
;
306 ds_put_format(s
, "set_tunnel64:%#"PRIx64
,
307 ntohll(nast64
->tun_id
));
310 case OFPUTIL_NXAST_MULTIPATH
:
311 nam
= (const struct nx_action_multipath
*) a
;
312 multipath_format(nam
, s
);
315 case OFPUTIL_NXAST_AUTOPATH
:
316 naa
= (const struct nx_action_autopath
*)a
;
317 ds_put_format(s
, "autopath(%u,", ntohl(naa
->id
));
318 nxm_format_field_bits(s
, ntohl(naa
->dst
),
319 nxm_decode_ofs(naa
->ofs_nbits
),
320 nxm_decode_n_bits(naa
->ofs_nbits
));
324 case OFPUTIL_NXAST_BUNDLE
:
325 case OFPUTIL_NXAST_BUNDLE_LOAD
:
326 bundle_format((const struct nx_action_bundle
*) a
, s
);
329 case OFPUTIL_NXAST_OUTPUT_REG
:
330 naor
= (const struct nx_action_output_reg
*) a
;
331 ds_put_cstr(s
, "output:");
332 nxm_format_field_bits(s
, ntohl(naor
->src
),
333 nxm_decode_ofs(naor
->ofs_nbits
),
334 nxm_decode_n_bits(naor
->ofs_nbits
));
337 case OFPUTIL_NXAST_LEARN
:
338 learn_format((const struct nx_action_learn
*) a
, s
);
341 case OFPUTIL_NXAST_EXIT
:
342 ds_put_cstr(s
, "exit");
351 ofp_print_actions(struct ds
*string
, const union ofp_action
*actions
,
354 const union ofp_action
*a
;
357 ds_put_cstr(string
, "actions=");
359 ds_put_cstr(string
, "drop");
362 OFPUTIL_ACTION_FOR_EACH (a
, left
, actions
, n_actions
) {
363 int code
= ofputil_decode_action(a
);
366 ds_put_cstr(string
, ",");
368 ofp_print_action(string
, a
, code
);
370 ofp_print_error(string
, -code
);
374 ds_put_format(string
, " ***%zu leftover bytes following actions",
380 ofp_print_packet_out(struct ds
*string
, const struct ofp_packet_out
*opo
,
383 size_t len
= ntohs(opo
->header
.length
);
384 size_t actions_len
= ntohs(opo
->actions_len
);
386 ds_put_cstr(string
, " in_port=");
387 ofputil_format_port(ntohs(opo
->in_port
), string
);
389 ds_put_format(string
, " actions_len=%zu ", actions_len
);
390 if (actions_len
> (ntohs(opo
->header
.length
) - sizeof *opo
)) {
391 ds_put_format(string
, "***packet too short for action length***\n");
394 if (actions_len
% sizeof(union ofp_action
)) {
395 ds_put_format(string
, "***action length not a multiple of %zu***\n",
396 sizeof(union ofp_action
));
398 ofp_print_actions(string
, (const union ofp_action
*) opo
->actions
,
399 actions_len
/ sizeof(union ofp_action
));
401 if (ntohl(opo
->buffer_id
) == UINT32_MAX
) {
402 int data_len
= len
- sizeof *opo
- actions_len
;
403 ds_put_format(string
, " data_len=%d", data_len
);
404 if (verbosity
> 0 && len
> sizeof *opo
) {
405 char *packet
= ofp_packet_to_string(
406 (uint8_t *)opo
->actions
+ actions_len
, data_len
, data_len
);
407 ds_put_char(string
, '\n');
408 ds_put_cstr(string
, packet
);
412 ds_put_format(string
, " buffer=0x%08"PRIx32
, ntohl(opo
->buffer_id
));
414 ds_put_char(string
, '\n');
417 /* qsort comparison function. */
419 compare_ports(const void *a_
, const void *b_
)
421 const struct ofp_phy_port
*a
= a_
;
422 const struct ofp_phy_port
*b
= b_
;
423 uint16_t ap
= ntohs(a
->port_no
);
424 uint16_t bp
= ntohs(b
->port_no
);
426 return ap
< bp
? -1 : ap
> bp
;
435 ofp_print_bit_names(struct ds
*string
, uint32_t bits
,
436 const struct bit_name bit_names
[])
441 ds_put_cstr(string
, "0");
445 for (; bits
&& bit_names
->name
; bit_names
++) {
446 if (bits
& bit_names
->bit
) {
448 ds_put_char(string
, ' ');
450 ds_put_cstr(string
, bit_names
->name
);
451 bits
&= ~bit_names
->bit
;
457 ds_put_char(string
, ' ');
459 ds_put_format(string
, "0x%"PRIx32
, bits
);
464 ofp_print_port_features(struct ds
*string
, uint32_t features
)
466 static const struct bit_name feature_bits
[] = {
467 { OFPPF_10MB_HD
, "10MB-HD" },
468 { OFPPF_10MB_FD
, "10MB-FD" },
469 { OFPPF_100MB_HD
, "100MB-HD" },
470 { OFPPF_100MB_FD
, "100MB-FD" },
471 { OFPPF_1GB_HD
, "1GB-HD" },
472 { OFPPF_1GB_FD
, "1GB-FD" },
473 { OFPPF_10GB_FD
, "10GB-FD" },
474 { OFPPF_COPPER
, "COPPER" },
475 { OFPPF_FIBER
, "FIBER" },
476 { OFPPF_AUTONEG
, "AUTO_NEG" },
477 { OFPPF_PAUSE
, "AUTO_PAUSE" },
478 { OFPPF_PAUSE_ASYM
, "AUTO_PAUSE_ASYM" },
482 ofp_print_bit_names(string
, features
, feature_bits
);
483 ds_put_char(string
, '\n');
487 ofp_print_port_config(struct ds
*string
, uint32_t config
)
489 static const struct bit_name config_bits
[] = {
490 { OFPPC_PORT_DOWN
, "PORT_DOWN" },
491 { OFPPC_NO_STP
, "NO_STP" },
492 { OFPPC_NO_RECV
, "NO_RECV" },
493 { OFPPC_NO_RECV_STP
, "NO_RECV_STP" },
494 { OFPPC_NO_FLOOD
, "NO_FLOOD" },
495 { OFPPC_NO_FWD
, "NO_FWD" },
496 { OFPPC_NO_PACKET_IN
, "NO_PACKET_IN" },
500 ofp_print_bit_names(string
, config
, config_bits
);
501 ds_put_char(string
, '\n');
505 ofp_print_port_state(struct ds
*string
, uint32_t state
)
507 static const struct bit_name state_bits
[] = {
508 { OFPPS_LINK_DOWN
, "LINK_DOWN" },
513 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
514 * pattern. We have to special case it.
516 * OVS doesn't support STP, so this field will always be 0 if we are
517 * talking to OVS, so we'd always print STP_LISTEN in that case.
518 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
519 * avoid confusing users. */
520 stp_state
= state
& OFPPS_STP_MASK
;
522 ds_put_cstr(string
, (stp_state
== OFPPS_STP_LEARN
? "STP_LEARN"
523 : stp_state
== OFPPS_STP_FORWARD
? "STP_FORWARD"
525 state
&= ~OFPPS_STP_MASK
;
527 ofp_print_bit_names(string
, state
, state_bits
);
530 ofp_print_bit_names(string
, state
, state_bits
);
532 ds_put_char(string
, '\n');
536 ofp_print_phy_port(struct ds
*string
, const struct ofp_phy_port
*port
)
538 char name
[OFP_MAX_PORT_NAME_LEN
];
541 memcpy(name
, port
->name
, sizeof name
);
542 for (j
= 0; j
< sizeof name
- 1; j
++) {
543 if (!isprint((unsigned char) name
[j
])) {
549 ds_put_char(string
, ' ');
550 ofputil_format_port(ntohs(port
->port_no
), string
);
551 ds_put_format(string
, "(%s): addr:"ETH_ADDR_FMT
"\n",
552 name
, ETH_ADDR_ARGS(port
->hw_addr
));
554 ds_put_cstr(string
, " config: ");
555 ofp_print_port_config(string
, ntohl(port
->config
));
557 ds_put_cstr(string
, " state: ");
558 ofp_print_port_state(string
, ntohl(port
->state
));
561 ds_put_format(string
, " current: ");
562 ofp_print_port_features(string
, ntohl(port
->curr
));
564 if (port
->advertised
) {
565 ds_put_format(string
, " advertised: ");
566 ofp_print_port_features(string
, ntohl(port
->advertised
));
568 if (port
->supported
) {
569 ds_put_format(string
, " supported: ");
570 ofp_print_port_features(string
, ntohl(port
->supported
));
573 ds_put_format(string
, " peer: ");
574 ofp_print_port_features(string
, ntohl(port
->peer
));
579 ofp_print_switch_features(struct ds
*string
,
580 const struct ofp_switch_features
*osf
)
582 size_t len
= ntohs(osf
->header
.length
);
583 struct ofp_phy_port
*port_list
;
587 ds_put_format(string
, " ver:0x%x, dpid:%016"PRIx64
"\n",
588 osf
->header
.version
, ntohll(osf
->datapath_id
));
589 ds_put_format(string
, "n_tables:%d, n_buffers:%d\n", osf
->n_tables
,
590 ntohl(osf
->n_buffers
));
591 ds_put_format(string
, "features: capabilities:%#x, actions:%#x\n",
592 ntohl(osf
->capabilities
), ntohl(osf
->actions
));
594 n_ports
= (len
- sizeof *osf
) / sizeof *osf
->ports
;
596 port_list
= xmemdup(osf
->ports
, len
- sizeof *osf
);
597 qsort(port_list
, n_ports
, sizeof *port_list
, compare_ports
);
598 for (i
= 0; i
< n_ports
; i
++) {
599 ofp_print_phy_port(string
, &port_list
[i
]);
605 ofp_print_switch_config(struct ds
*string
, const struct ofp_switch_config
*osc
)
609 flags
= ntohs(osc
->flags
);
611 ds_put_format(string
, " frags=%s", ofputil_frag_handling_to_string(flags
));
612 flags
&= ~OFPC_FRAG_MASK
;
615 ds_put_format(string
, " ***unknown flags 0x%04"PRIx16
"***", flags
);
618 ds_put_format(string
, " miss_send_len=%"PRIu16
"\n", ntohs(osc
->miss_send_len
));
621 static void print_wild(struct ds
*string
, const char *leader
, int is_wild
,
622 int verbosity
, const char *format
, ...)
623 __attribute__((format(printf
, 5, 6)));
625 static void print_wild(struct ds
*string
, const char *leader
, int is_wild
,
626 int verbosity
, const char *format
, ...)
628 if (is_wild
&& verbosity
< 2) {
631 ds_put_cstr(string
, leader
);
635 va_start(args
, format
);
636 ds_put_format_valist(string
, format
, args
);
639 ds_put_char(string
, '*');
641 ds_put_char(string
, ',');
645 print_ip_netmask(struct ds
*string
, const char *leader
, ovs_be32 ip
,
646 uint32_t wild_bits
, int verbosity
)
648 if (wild_bits
>= 32 && verbosity
< 2) {
651 ds_put_cstr(string
, leader
);
652 if (wild_bits
< 32) {
653 ds_put_format(string
, IP_FMT
, IP_ARGS(&ip
));
655 ds_put_format(string
, "/%d", 32 - wild_bits
);
658 ds_put_char(string
, '*');
660 ds_put_char(string
, ',');
664 ofp_print_match(struct ds
*f
, const struct ofp_match
*om
, int verbosity
)
666 char *s
= ofp_match_to_string(om
, verbosity
);
672 ofp_match_to_string(const struct ofp_match
*om
, int verbosity
)
674 struct ds f
= DS_EMPTY_INITIALIZER
;
675 uint32_t w
= ntohl(om
->wildcards
);
676 bool skip_type
= false;
677 bool skip_proto
= false;
679 if (!(w
& OFPFW_DL_TYPE
)) {
681 if (om
->dl_type
== htons(ETH_TYPE_IP
)) {
682 if (!(w
& OFPFW_NW_PROTO
)) {
684 if (om
->nw_proto
== IPPROTO_ICMP
) {
685 ds_put_cstr(&f
, "icmp,");
686 } else if (om
->nw_proto
== IPPROTO_TCP
) {
687 ds_put_cstr(&f
, "tcp,");
688 } else if (om
->nw_proto
== IPPROTO_UDP
) {
689 ds_put_cstr(&f
, "udp,");
691 ds_put_cstr(&f
, "ip,");
695 ds_put_cstr(&f
, "ip,");
697 } else if (om
->dl_type
== htons(ETH_TYPE_ARP
)) {
698 ds_put_cstr(&f
, "arp,");
703 print_wild(&f
, "in_port=", w
& OFPFW_IN_PORT
, verbosity
,
704 "%d", ntohs(om
->in_port
));
705 print_wild(&f
, "dl_vlan=", w
& OFPFW_DL_VLAN
, verbosity
,
706 "%d", ntohs(om
->dl_vlan
));
707 print_wild(&f
, "dl_vlan_pcp=", w
& OFPFW_DL_VLAN_PCP
, verbosity
,
708 "%d", om
->dl_vlan_pcp
);
709 print_wild(&f
, "dl_src=", w
& OFPFW_DL_SRC
, verbosity
,
710 ETH_ADDR_FMT
, ETH_ADDR_ARGS(om
->dl_src
));
711 print_wild(&f
, "dl_dst=", w
& OFPFW_DL_DST
, verbosity
,
712 ETH_ADDR_FMT
, ETH_ADDR_ARGS(om
->dl_dst
));
714 print_wild(&f
, "dl_type=", w
& OFPFW_DL_TYPE
, verbosity
,
715 "0x%04x", ntohs(om
->dl_type
));
717 print_ip_netmask(&f
, "nw_src=", om
->nw_src
,
718 (w
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
, verbosity
);
719 print_ip_netmask(&f
, "nw_dst=", om
->nw_dst
,
720 (w
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
, verbosity
);
722 if (om
->dl_type
== htons(ETH_TYPE_ARP
)) {
723 print_wild(&f
, "arp_op=", w
& OFPFW_NW_PROTO
, verbosity
,
726 print_wild(&f
, "nw_proto=", w
& OFPFW_NW_PROTO
, verbosity
,
730 print_wild(&f
, "nw_tos=", w
& OFPFW_NW_TOS
, verbosity
,
732 if (om
->nw_proto
== IPPROTO_ICMP
) {
733 print_wild(&f
, "icmp_type=", w
& OFPFW_ICMP_TYPE
, verbosity
,
734 "%d", ntohs(om
->tp_src
));
735 print_wild(&f
, "icmp_code=", w
& OFPFW_ICMP_CODE
, verbosity
,
736 "%d", ntohs(om
->tp_dst
));
738 print_wild(&f
, "tp_src=", w
& OFPFW_TP_SRC
, verbosity
,
739 "%d", ntohs(om
->tp_src
));
740 print_wild(&f
, "tp_dst=", w
& OFPFW_TP_DST
, verbosity
,
741 "%d", ntohs(om
->tp_dst
));
743 if (ds_last(&f
) == ',') {
750 ofp_print_flow_mod(struct ds
*s
, const struct ofp_header
*oh
,
751 enum ofputil_msg_code code
, int verbosity
)
753 struct ofputil_flow_mod fm
;
757 error
= ofputil_decode_flow_mod(&fm
, oh
, true);
759 ofp_print_error(s
, error
);
764 switch (fm
.command
) {
766 ds_put_cstr(s
, "ADD");
769 ds_put_cstr(s
, "MOD");
771 case OFPFC_MODIFY_STRICT
:
772 ds_put_cstr(s
, "MOD_STRICT");
775 ds_put_cstr(s
, "DEL");
777 case OFPFC_DELETE_STRICT
:
778 ds_put_cstr(s
, "DEL_STRICT");
781 ds_put_format(s
, "cmd:%d", fm
.command
);
783 if (fm
.table_id
!= 0) {
784 ds_put_format(s
, " table:%d", fm
.table_id
);
788 if (verbosity
>= 3 && code
== OFPUTIL_OFPT_FLOW_MOD
) {
789 const struct ofp_flow_mod
*ofm
= (const struct ofp_flow_mod
*) oh
;
790 ofp_print_match(s
, &ofm
->match
, verbosity
);
792 /* ofp_print_match() doesn't print priority. */
793 need_priority
= true;
794 } else if (verbosity
>= 3 && code
== OFPUTIL_NXT_FLOW_MOD
) {
795 const struct nx_flow_mod
*nfm
= (const struct nx_flow_mod
*) oh
;
796 const void *nxm
= nfm
+ 1;
799 nxm_s
= nx_match_to_string(nxm
, ntohs(nfm
->match_len
));
800 ds_put_cstr(s
, nxm_s
);
803 /* nx_match_to_string() doesn't print priority. */
804 need_priority
= true;
806 cls_rule_format(&fm
.cr
, s
);
808 /* cls_rule_format() does print priority. */
809 need_priority
= false;
812 if (ds_last(s
) != ' ') {
815 if (fm
.cookie
!= htonll(0)) {
816 ds_put_format(s
, "cookie:0x%"PRIx64
" ", ntohll(fm
.cookie
));
818 if (fm
.idle_timeout
!= OFP_FLOW_PERMANENT
) {
819 ds_put_format(s
, "idle:%"PRIu16
" ", fm
.idle_timeout
);
821 if (fm
.hard_timeout
!= OFP_FLOW_PERMANENT
) {
822 ds_put_format(s
, "hard:%"PRIu16
" ", fm
.hard_timeout
);
824 if (fm
.cr
.priority
!= OFP_DEFAULT_PRIORITY
&& need_priority
) {
825 ds_put_format(s
, "pri:%"PRIu16
" ", fm
.cr
.priority
);
827 if (fm
.buffer_id
!= UINT32_MAX
) {
828 ds_put_format(s
, "buf:0x%"PRIx32
" ", fm
.buffer_id
);
831 ds_put_format(s
, "flags:0x%"PRIx16
" ", fm
.flags
);
834 ofp_print_actions(s
, fm
.actions
, fm
.n_actions
);
838 ofp_print_duration(struct ds
*string
, unsigned int sec
, unsigned int nsec
)
840 ds_put_format(string
, "%u", sec
);
842 ds_put_format(string
, ".%09u", nsec
);
843 while (string
->string
[string
->length
- 1] == '0') {
847 ds_put_char(string
, 's');
851 ofp_print_flow_removed(struct ds
*string
, const struct ofp_header
*oh
)
853 struct ofputil_flow_removed fr
;
856 error
= ofputil_decode_flow_removed(&fr
, oh
);
858 ofp_print_error(string
, error
);
862 ds_put_char(string
, ' ');
863 cls_rule_format(&fr
.rule
, string
);
865 ds_put_cstr(string
, " reason=");
867 case OFPRR_IDLE_TIMEOUT
:
868 ds_put_cstr(string
, "idle");
870 case OFPRR_HARD_TIMEOUT
:
871 ds_put_cstr(string
, "hard");
874 ds_put_cstr(string
, "delete");
877 ds_put_format(string
, "**%"PRIu8
"**", fr
.reason
);
881 if (fr
.cookie
!= htonll(0)) {
882 ds_put_format(string
, " cookie:0x%"PRIx64
, ntohll(fr
.cookie
));
884 ds_put_cstr(string
, " duration");
885 ofp_print_duration(string
, fr
.duration_sec
, fr
.duration_nsec
);
886 ds_put_format(string
, " idle%"PRIu16
" pkts%"PRIu64
" bytes%"PRIu64
"\n",
887 fr
.idle_timeout
, fr
.packet_count
, fr
.byte_count
);
891 ofp_print_port_mod(struct ds
*string
, const struct ofp_port_mod
*opm
)
893 ds_put_format(string
, "port: %d: addr:"ETH_ADDR_FMT
", config: %#x, mask:%#x\n",
894 ntohs(opm
->port_no
), ETH_ADDR_ARGS(opm
->hw_addr
),
895 ntohl(opm
->config
), ntohl(opm
->mask
));
896 ds_put_format(string
, " advertise: ");
897 if (opm
->advertise
) {
898 ofp_print_port_features(string
, ntohl(opm
->advertise
));
900 ds_put_format(string
, "UNCHANGED\n");
905 ofp_print_error(struct ds
*string
, int error
)
907 if (string
->length
) {
908 ds_put_char(string
, ' ');
910 ds_put_cstr(string
, "***decode error: ");
911 ofputil_format_error(string
, error
);
912 ds_put_cstr(string
, "***\n");
916 ofp_print_error_msg(struct ds
*string
, const struct ofp_error_msg
*oem
)
918 size_t len
= ntohs(oem
->header
.length
);
919 size_t payload_ofs
, payload_len
;
924 error
= ofputil_decode_error_msg(&oem
->header
, &payload_ofs
);
925 if (!is_ofp_error(error
)) {
926 ofp_print_error(string
, error
);
927 ds_put_hex_dump(string
, oem
->data
, len
- sizeof *oem
, 0, true);
931 ds_put_char(string
, ' ');
932 ofputil_format_error(string
, error
);
933 ds_put_char(string
, '\n');
935 payload
= (const uint8_t *) oem
+ payload_ofs
;
936 payload_len
= len
- payload_ofs
;
937 switch (get_ofp_err_type(error
)) {
938 case OFPET_HELLO_FAILED
:
939 ds_put_printable(string
, payload
, payload_len
);
943 s
= ofp_to_string(payload
, payload_len
, 1);
944 ds_put_cstr(string
, s
);
951 ofp_print_port_status(struct ds
*string
, const struct ofp_port_status
*ops
)
953 if (ops
->reason
== OFPPR_ADD
) {
954 ds_put_format(string
, " ADD:");
955 } else if (ops
->reason
== OFPPR_DELETE
) {
956 ds_put_format(string
, " DEL:");
957 } else if (ops
->reason
== OFPPR_MODIFY
) {
958 ds_put_format(string
, " MOD:");
961 ofp_print_phy_port(string
, &ops
->desc
);
965 ofp_print_ofpst_desc_reply(struct ds
*string
, const struct ofp_desc_stats
*ods
)
967 ds_put_char(string
, '\n');
968 ds_put_format(string
, "Manufacturer: %.*s\n",
969 (int) sizeof ods
->mfr_desc
, ods
->mfr_desc
);
970 ds_put_format(string
, "Hardware: %.*s\n",
971 (int) sizeof ods
->hw_desc
, ods
->hw_desc
);
972 ds_put_format(string
, "Software: %.*s\n",
973 (int) sizeof ods
->sw_desc
, ods
->sw_desc
);
974 ds_put_format(string
, "Serial Num: %.*s\n",
975 (int) sizeof ods
->serial_num
, ods
->serial_num
);
976 ds_put_format(string
, "DP Description: %.*s\n",
977 (int) sizeof ods
->dp_desc
, ods
->dp_desc
);
981 ofp_print_flow_stats_request(struct ds
*string
,
982 const struct ofp_stats_msg
*osm
)
984 struct ofputil_flow_stats_request fsr
;
987 error
= ofputil_decode_flow_stats_request(&fsr
, &osm
->header
);
989 ofp_print_error(string
, error
);
993 if (fsr
.table_id
!= 0xff) {
994 ds_put_format(string
, " table=%"PRIu8
, fsr
.table_id
);
997 if (fsr
.out_port
!= OFPP_NONE
) {
998 ds_put_cstr(string
, " out_port=");
999 ofputil_format_port(fsr
.out_port
, string
);
1002 /* A flow stats request doesn't include a priority, but cls_rule_format()
1003 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1004 fsr
.match
.priority
= OFP_DEFAULT_PRIORITY
;
1006 ds_put_char(string
, ' ');
1007 cls_rule_format(&fsr
.match
, string
);
1011 ofp_print_flow_stats_reply(struct ds
*string
, const struct ofp_header
*oh
)
1015 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1017 struct ofputil_flow_stats fs
;
1020 retval
= ofputil_decode_flow_stats_reply(&fs
, &b
);
1022 if (retval
!= EOF
) {
1023 ds_put_cstr(string
, " ***parse error***");
1028 ds_put_char(string
, '\n');
1030 ds_put_format(string
, " cookie=0x%"PRIx64
", duration=",
1032 ofp_print_duration(string
, fs
.duration_sec
, fs
.duration_nsec
);
1033 ds_put_format(string
, ", table=%"PRIu8
", ", fs
.table_id
);
1034 ds_put_format(string
, "n_packets=%"PRIu64
", ", fs
.packet_count
);
1035 ds_put_format(string
, "n_bytes=%"PRIu64
", ", fs
.byte_count
);
1036 if (fs
.idle_timeout
!= OFP_FLOW_PERMANENT
) {
1037 ds_put_format(string
, "idle_timeout=%"PRIu16
",", fs
.idle_timeout
);
1039 if (fs
.hard_timeout
!= OFP_FLOW_PERMANENT
) {
1040 ds_put_format(string
, "hard_timeout=%"PRIu16
",", fs
.hard_timeout
);
1043 cls_rule_format(&fs
.rule
, string
);
1044 if (string
->string
[string
->length
- 1] != ' ') {
1045 ds_put_char(string
, ' ');
1047 ofp_print_actions(string
, fs
.actions
, fs
.n_actions
);
1052 ofp_print_ofpst_aggregate_reply(struct ds
*string
,
1053 const struct ofp_aggregate_stats_reply
*asr
)
1055 ds_put_format(string
, " packet_count=%"PRIu64
,
1056 ntohll(get_32aligned_be64(&asr
->packet_count
)));
1057 ds_put_format(string
, " byte_count=%"PRIu64
,
1058 ntohll(get_32aligned_be64(&asr
->byte_count
)));
1059 ds_put_format(string
, " flow_count=%"PRIu32
, ntohl(asr
->flow_count
));
1063 ofp_print_nxst_aggregate_reply(struct ds
*string
,
1064 const struct nx_aggregate_stats_reply
*nasr
)
1066 ds_put_format(string
, " packet_count=%"PRIu64
, ntohll(nasr
->packet_count
));
1067 ds_put_format(string
, " byte_count=%"PRIu64
, ntohll(nasr
->byte_count
));
1068 ds_put_format(string
, " flow_count=%"PRIu32
, ntohl(nasr
->flow_count
));
1071 static void print_port_stat(struct ds
*string
, const char *leader
,
1072 const ovs_32aligned_be64
*statp
, int more
)
1074 uint64_t stat
= ntohll(get_32aligned_be64(statp
));
1076 ds_put_cstr(string
, leader
);
1077 if (stat
!= UINT64_MAX
) {
1078 ds_put_format(string
, "%"PRIu64
, stat
);
1080 ds_put_char(string
, '?');
1083 ds_put_cstr(string
, ", ");
1085 ds_put_cstr(string
, "\n");
1090 ofp_print_ofpst_port_request(struct ds
*string
,
1091 const struct ofp_port_stats_request
*psr
)
1093 ds_put_format(string
, " port_no=%"PRIu16
, ntohs(psr
->port_no
));
1097 ofp_print_ofpst_port_reply(struct ds
*string
, const struct ofp_header
*oh
,
1100 const struct ofp_port_stats
*ps
= ofputil_stats_body(oh
);
1101 size_t n
= ofputil_stats_body_len(oh
) / sizeof *ps
;
1102 ds_put_format(string
, " %zu ports\n", n
);
1103 if (verbosity
< 1) {
1108 ds_put_format(string
, " port %2"PRIu16
": ", ntohs(ps
->port_no
));
1110 ds_put_cstr(string
, "rx ");
1111 print_port_stat(string
, "pkts=", &ps
->rx_packets
, 1);
1112 print_port_stat(string
, "bytes=", &ps
->rx_bytes
, 1);
1113 print_port_stat(string
, "drop=", &ps
->rx_dropped
, 1);
1114 print_port_stat(string
, "errs=", &ps
->rx_errors
, 1);
1115 print_port_stat(string
, "frame=", &ps
->rx_frame_err
, 1);
1116 print_port_stat(string
, "over=", &ps
->rx_over_err
, 1);
1117 print_port_stat(string
, "crc=", &ps
->rx_crc_err
, 0);
1119 ds_put_cstr(string
, " tx ");
1120 print_port_stat(string
, "pkts=", &ps
->tx_packets
, 1);
1121 print_port_stat(string
, "bytes=", &ps
->tx_bytes
, 1);
1122 print_port_stat(string
, "drop=", &ps
->tx_dropped
, 1);
1123 print_port_stat(string
, "errs=", &ps
->tx_errors
, 1);
1124 print_port_stat(string
, "coll=", &ps
->collisions
, 0);
1129 ofp_print_ofpst_table_reply(struct ds
*string
, const struct ofp_header
*oh
,
1132 const struct ofp_table_stats
*ts
= ofputil_stats_body(oh
);
1133 size_t n
= ofputil_stats_body_len(oh
) / sizeof *ts
;
1134 ds_put_format(string
, " %zu tables\n", n
);
1135 if (verbosity
< 1) {
1140 char name
[OFP_MAX_TABLE_NAME_LEN
+ 1];
1141 ovs_strlcpy(name
, ts
->name
, sizeof name
);
1143 ds_put_format(string
, " %d: %-8s: ", ts
->table_id
, name
);
1144 ds_put_format(string
, "wild=0x%05"PRIx32
", ", ntohl(ts
->wildcards
));
1145 ds_put_format(string
, "max=%6"PRIu32
", ", ntohl(ts
->max_entries
));
1146 ds_put_format(string
, "active=%"PRIu32
"\n", ntohl(ts
->active_count
));
1147 ds_put_cstr(string
, " ");
1148 ds_put_format(string
, "lookup=%"PRIu64
", ",
1149 ntohll(get_32aligned_be64(&ts
->lookup_count
)));
1150 ds_put_format(string
, "matched=%"PRIu64
"\n",
1151 ntohll(get_32aligned_be64(&ts
->matched_count
)));
1156 ofp_print_queue_name(struct ds
*string
, uint32_t queue_id
)
1158 if (queue_id
== OFPQ_ALL
) {
1159 ds_put_cstr(string
, "ALL");
1161 ds_put_format(string
, "%"PRIu32
, queue_id
);
1166 ofp_print_ofpst_queue_request(struct ds
*string
,
1167 const struct ofp_queue_stats_request
*qsr
)
1169 ds_put_cstr(string
, "port=");
1170 ofputil_format_port(ntohs(qsr
->port_no
), string
);
1172 ds_put_cstr(string
, " queue=");
1173 ofp_print_queue_name(string
, ntohl(qsr
->queue_id
));
1177 ofp_print_ofpst_queue_reply(struct ds
*string
, const struct ofp_header
*oh
,
1180 const struct ofp_queue_stats
*qs
= ofputil_stats_body(oh
);
1181 size_t n
= ofputil_stats_body_len(oh
) / sizeof *qs
;
1182 ds_put_format(string
, " %zu queues\n", n
);
1183 if (verbosity
< 1) {
1188 ds_put_cstr(string
, " port ");
1189 ofputil_format_port(ntohs(qs
->port_no
), string
);
1190 ds_put_cstr(string
, " queue ");
1191 ofp_print_queue_name(string
, ntohl(qs
->queue_id
));
1192 ds_put_cstr(string
, ": ");
1194 print_port_stat(string
, "bytes=", &qs
->tx_bytes
, 1);
1195 print_port_stat(string
, "pkts=", &qs
->tx_packets
, 1);
1196 print_port_stat(string
, "errors=", &qs
->tx_errors
, 0);
1201 ofp_print_stats_request(struct ds
*string
, const struct ofp_header
*oh
)
1203 const struct ofp_stats_msg
*srq
= (const struct ofp_stats_msg
*) oh
;
1206 ds_put_format(string
, " ***unknown flags 0x%04"PRIx16
"***",
1212 ofp_print_stats_reply(struct ds
*string
, const struct ofp_header
*oh
)
1214 const struct ofp_stats_msg
*srp
= (const struct ofp_stats_msg
*) oh
;
1217 uint16_t flags
= ntohs(srp
->flags
);
1219 ds_put_cstr(string
, " flags=");
1220 if (flags
& OFPSF_REPLY_MORE
) {
1221 ds_put_cstr(string
, "[more]");
1222 flags
&= ~OFPSF_REPLY_MORE
;
1225 ds_put_format(string
, "[***unknown flags 0x%04"PRIx16
"***]",
1232 ofp_print_echo(struct ds
*string
, const struct ofp_header
*oh
, int verbosity
)
1234 size_t len
= ntohs(oh
->length
);
1236 ds_put_format(string
, " %zu bytes of payload\n", len
- sizeof *oh
);
1237 if (verbosity
> 1) {
1238 ds_put_hex_dump(string
, oh
+ 1, len
- sizeof *oh
, 0, true);
1243 ofp_print_nxt_role_message(struct ds
*string
,
1244 const struct nx_role_request
*nrr
)
1246 unsigned int role
= ntohl(nrr
->role
);
1248 ds_put_cstr(string
, " role=");
1249 if (role
== NX_ROLE_OTHER
) {
1250 ds_put_cstr(string
, "other");
1251 } else if (role
== NX_ROLE_MASTER
) {
1252 ds_put_cstr(string
, "master");
1253 } else if (role
== NX_ROLE_SLAVE
) {
1254 ds_put_cstr(string
, "slave");
1256 ds_put_format(string
, "%u", role
);
1261 ofp_print_nxt_flow_mod_table_id(struct ds
*string
,
1262 const struct nxt_flow_mod_table_id
*nfmti
)
1264 ds_put_format(string
, " %s", nfmti
->set
? "enable" : "disable");
1268 ofp_print_nxt_set_flow_format(struct ds
*string
,
1269 const struct nxt_set_flow_format
*nsff
)
1271 uint32_t format
= ntohl(nsff
->format
);
1273 ds_put_cstr(string
, " format=");
1274 if (ofputil_flow_format_is_valid(format
)) {
1275 ds_put_cstr(string
, ofputil_flow_format_to_string(format
));
1277 ds_put_format(string
, "%"PRIu32
, format
);
1282 ofp_to_string__(const struct ofp_header
*oh
,
1283 const struct ofputil_msg_type
*type
, struct ds
*string
,
1286 enum ofputil_msg_code code
;
1287 const void *msg
= oh
;
1289 ds_put_format(string
, "%s (xid=0x%"PRIx32
"):",
1290 ofputil_msg_type_name(type
), ntohl(oh
->xid
));
1292 code
= ofputil_msg_type_code(type
);
1294 case OFPUTIL_MSG_INVALID
:
1297 case OFPUTIL_OFPT_HELLO
:
1298 ds_put_char(string
, '\n');
1299 ds_put_hex_dump(string
, oh
+ 1, ntohs(oh
->length
) - sizeof *oh
,
1303 case OFPUTIL_OFPT_ERROR
:
1304 ofp_print_error_msg(string
, msg
);
1307 case OFPUTIL_OFPT_ECHO_REQUEST
:
1308 case OFPUTIL_OFPT_ECHO_REPLY
:
1309 ofp_print_echo(string
, oh
, verbosity
);
1312 case OFPUTIL_OFPT_FEATURES_REQUEST
:
1315 case OFPUTIL_OFPT_FEATURES_REPLY
:
1316 ofp_print_switch_features(string
, msg
);
1319 case OFPUTIL_OFPT_GET_CONFIG_REQUEST
:
1322 case OFPUTIL_OFPT_GET_CONFIG_REPLY
:
1323 case OFPUTIL_OFPT_SET_CONFIG
:
1324 ofp_print_switch_config(string
, msg
);
1327 case OFPUTIL_OFPT_PACKET_IN
:
1328 ofp_print_packet_in(string
, msg
, verbosity
);
1331 case OFPUTIL_OFPT_FLOW_REMOVED
:
1332 case OFPUTIL_NXT_FLOW_REMOVED
:
1333 ofp_print_flow_removed(string
, msg
);
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
, code
, 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 case OFPUTIL_NXST_FLOW_REQUEST
:
1367 case OFPUTIL_OFPST_AGGREGATE_REQUEST
:
1368 case OFPUTIL_NXST_AGGREGATE_REQUEST
:
1369 ofp_print_stats_request(string
, oh
);
1370 ofp_print_flow_stats_request(string
, msg
);
1373 case OFPUTIL_OFPST_TABLE_REQUEST
:
1374 ofp_print_stats_request(string
, oh
);
1377 case OFPUTIL_OFPST_PORT_REQUEST
:
1378 ofp_print_stats_request(string
, oh
);
1379 ofp_print_ofpst_port_request(string
, msg
);
1382 case OFPUTIL_OFPST_QUEUE_REQUEST
:
1383 ofp_print_stats_request(string
, oh
);
1384 ofp_print_ofpst_queue_request(string
, msg
);
1387 case OFPUTIL_OFPST_DESC_REPLY
:
1388 ofp_print_stats_reply(string
, oh
);
1389 ofp_print_ofpst_desc_reply(string
, msg
);
1392 case OFPUTIL_OFPST_FLOW_REPLY
:
1393 case OFPUTIL_NXST_FLOW_REPLY
:
1394 ofp_print_stats_reply(string
, oh
);
1395 ofp_print_flow_stats_reply(string
, oh
);
1398 case OFPUTIL_OFPST_QUEUE_REPLY
:
1399 ofp_print_stats_reply(string
, oh
);
1400 ofp_print_ofpst_queue_reply(string
, oh
, verbosity
);
1403 case OFPUTIL_OFPST_PORT_REPLY
:
1404 ofp_print_stats_reply(string
, oh
);
1405 ofp_print_ofpst_port_reply(string
, oh
, verbosity
);
1408 case OFPUTIL_OFPST_TABLE_REPLY
:
1409 ofp_print_stats_reply(string
, oh
);
1410 ofp_print_ofpst_table_reply(string
, oh
, verbosity
);
1413 case OFPUTIL_OFPST_AGGREGATE_REPLY
:
1414 ofp_print_stats_reply(string
, oh
);
1415 ofp_print_ofpst_aggregate_reply(string
, msg
);
1418 case OFPUTIL_NXT_ROLE_REQUEST
:
1419 case OFPUTIL_NXT_ROLE_REPLY
:
1420 ofp_print_nxt_role_message(string
, msg
);
1423 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID
:
1424 ofp_print_nxt_flow_mod_table_id(string
, msg
);
1427 case OFPUTIL_NXT_SET_FLOW_FORMAT
:
1428 ofp_print_nxt_set_flow_format(string
, msg
);
1431 case OFPUTIL_NXT_FLOW_MOD
:
1432 ofp_print_flow_mod(string
, msg
, code
, verbosity
);
1435 case OFPUTIL_NXST_AGGREGATE_REPLY
:
1436 ofp_print_stats_reply(string
, oh
);
1437 ofp_print_nxst_aggregate_reply(string
, msg
);
1442 /* Composes and returns a string representing the OpenFlow packet of 'len'
1443 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1444 * verbosity and higher numbers increase verbosity. The caller is responsible
1445 * for freeing the string. */
1447 ofp_to_string(const void *oh_
, size_t len
, int verbosity
)
1449 struct ds string
= DS_EMPTY_INITIALIZER
;
1450 const struct ofp_header
*oh
= oh_
;
1453 ds_put_cstr(&string
, "OpenFlow message is empty\n");
1454 } else if (len
< sizeof(struct ofp_header
)) {
1455 ds_put_format(&string
, "OpenFlow packet too short (only %zu bytes):\n",
1457 } else if (oh
->version
!= OFP_VERSION
) {
1458 ds_put_format(&string
, "Bad OpenFlow version %"PRIu8
":\n",
1460 } else if (ntohs(oh
->length
) > len
) {
1461 ds_put_format(&string
,
1462 "(***truncated to %zu bytes from %"PRIu16
"***)\n",
1463 len
, ntohs(oh
->length
));
1464 } else if (ntohs(oh
->length
) < len
) {
1465 ds_put_format(&string
,
1466 "(***only uses %"PRIu16
" bytes out of %zu***)\n",
1467 ntohs(oh
->length
), len
);
1469 const struct ofputil_msg_type
*type
;
1472 error
= ofputil_decode_msg_type(oh
, &type
);
1474 ofp_to_string__(oh
, type
, &string
, verbosity
);
1475 if (verbosity
>= 5) {
1476 if (ds_last(&string
) != '\n') {
1477 ds_put_char(&string
, '\n');
1479 ds_put_hex_dump(&string
, oh
, len
, 0, true);
1481 if (ds_last(&string
) != '\n') {
1482 ds_put_char(&string
, '\n');
1484 return ds_steal_cstr(&string
);
1487 ofp_print_error(&string
, error
);
1489 ds_put_hex_dump(&string
, oh
, len
, 0, true);
1490 return ds_steal_cstr(&string
);
1493 /* Returns the name for the specified OpenFlow message type as a string,
1494 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1495 * hex number, e.g. "0x55".
1497 * The caller must free the returned string when it is no longer needed. */
1499 ofp_message_type_to_string(uint8_t type
)
1510 case OFPT_ECHO_REQUEST
:
1511 name
= "ECHO_REQUEST";
1513 case OFPT_ECHO_REPLY
:
1514 name
= "ECHO_REPLY";
1519 case OFPT_FEATURES_REQUEST
:
1520 name
= "FEATURES_REQUEST";
1522 case OFPT_FEATURES_REPLY
:
1523 name
= "FEATURES_REPLY";
1525 case OFPT_GET_CONFIG_REQUEST
:
1526 name
= "GET_CONFIG_REQUEST";
1528 case OFPT_GET_CONFIG_REPLY
:
1529 name
= "GET_CONFIG_REPLY";
1531 case OFPT_SET_CONFIG
:
1532 name
= "SET_CONFIG";
1534 case OFPT_PACKET_IN
:
1537 case OFPT_FLOW_REMOVED
:
1538 name
= "FLOW_REMOVED";
1540 case OFPT_PORT_STATUS
:
1541 name
= "PORT_STATUS";
1543 case OFPT_PACKET_OUT
:
1544 name
= "PACKET_OUT";
1552 case OFPT_STATS_REQUEST
:
1553 name
= "STATS_REQUEST";
1555 case OFPT_STATS_REPLY
:
1556 name
= "STATS_REPLY";
1558 case OFPT_BARRIER_REQUEST
:
1559 name
= "BARRIER_REQUEST";
1561 case OFPT_BARRIER_REPLY
:
1562 name
= "BARRIER_REPLY";
1564 case OFPT_QUEUE_GET_CONFIG_REQUEST
:
1565 name
= "QUEUE_GET_CONFIG_REQUEST";
1567 case OFPT_QUEUE_GET_CONFIG_REPLY
:
1568 name
= "QUEUE_GET_CONFIG_REPLY";
1575 return name
? xasprintf("OFPT_%s", name
) : xasprintf("0x%02"PRIx8
, type
);
1579 print_and_free(FILE *stream
, char *string
)
1581 fputs(string
, stream
);
1585 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1586 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1587 * numbers increase verbosity. */
1589 ofp_print(FILE *stream
, const void *oh
, size_t len
, int verbosity
)
1591 print_and_free(stream
, ofp_to_string(oh
, len
, verbosity
));
1594 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1595 * 'data' to 'stream' using tcpdump. 'total_len' specifies the full length of
1596 * the Ethernet frame (of which 'len' bytes were captured).
1598 * This starts and kills a tcpdump subprocess so it's quite expensive. */
1600 ofp_print_packet(FILE *stream
, const void *data
, size_t len
, size_t total_len
)
1602 print_and_free(stream
, ofp_packet_to_string(data
, len
, total_len
));