2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "ofp-print.h"
22 #include <sys/types.h>
23 #include <netinet/in.h>
30 #include "byte-order.h"
32 #include "dynamic-string.h"
35 #include "multipath.h"
37 #include "ofp-errors.h"
40 #include "openflow/openflow.h"
41 #include "openflow/nicira-ext.h"
44 #include "type-props.h"
45 #include "unaligned.h"
48 static void ofp_print_queue_name(struct ds
*string
, uint32_t port
);
49 static void ofp_print_error(struct ds
*, enum ofperr
);
52 /* Returns a string that represents the contents of the Ethernet frame in the
53 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
55 ofp_packet_to_string(const void *data
, size_t len
)
57 struct ds ds
= DS_EMPTY_INITIALIZER
;
61 ofpbuf_use_const(&buf
, data
, len
);
62 flow_extract(&buf
, 0, 0, 0, &flow
);
63 flow_format(&ds
, &flow
);
66 if (flow
.nw_proto
== IPPROTO_TCP
) {
67 struct tcp_header
*th
= buf
.l4
;
68 ds_put_format(&ds
, " tcp_csum:%"PRIx16
,
70 } else if (flow
.nw_proto
== IPPROTO_UDP
) {
71 struct udp_header
*uh
= buf
.l4
;
72 ds_put_format(&ds
, " udp_csum:%"PRIx16
,
77 ds_put_char(&ds
, '\n');
83 ofp_print_packet_in(struct ds
*string
, const struct ofp_header
*oh
,
86 struct ofputil_packet_in pin
;
90 error
= ofputil_decode_packet_in(&pin
, oh
);
92 ofp_print_error(string
, error
);
97 ds_put_format(string
, " table_id=%"PRIu8
, pin
.table_id
);
101 ds_put_format(string
, " cookie=0x%"PRIx64
, ntohll(pin
.cookie
));
104 ds_put_format(string
, " total_len=%"PRIu16
" in_port=", pin
.total_len
);
105 ofputil_format_port(pin
.fmd
.in_port
, string
);
107 if (pin
.fmd
.tun_id_mask
) {
108 ds_put_format(string
, " tun_id=0x%"PRIx64
, ntohll(pin
.fmd
.tun_id
));
109 if (pin
.fmd
.tun_id_mask
!= htonll(UINT64_MAX
)) {
110 ds_put_format(string
, "/0x%"PRIx64
, ntohll(pin
.fmd
.tun_id_mask
));
114 for (i
= 0; i
< FLOW_N_REGS
; i
++) {
115 if (pin
.fmd
.reg_masks
[i
]) {
116 ds_put_format(string
, " reg%d=0x%"PRIx32
, i
, pin
.fmd
.regs
[i
]);
117 if (pin
.fmd
.reg_masks
[i
] != UINT32_MAX
) {
118 ds_put_format(string
, "/0x%"PRIx32
, pin
.fmd
.reg_masks
[i
]);
123 switch (pin
.reason
) {
125 ds_put_cstr(string
, " (via no_match)");
128 ds_put_cstr(string
, " (via action)");
130 case OFPR_INVALID_TTL
:
131 ds_put_cstr(string
, " (via invalid_ttl)");
134 ds_put_format(string
, " (***reason %"PRIu8
"***)", pin
.reason
);
138 ds_put_format(string
, " data_len=%zu", pin
.packet_len
);
139 if (pin
.buffer_id
== UINT32_MAX
) {
140 ds_put_format(string
, " (unbuffered)");
141 if (pin
.total_len
!= pin
.packet_len
) {
142 ds_put_format(string
, " (***total_len != data_len***)");
145 ds_put_format(string
, " buffer=0x%08"PRIx32
, pin
.buffer_id
);
146 if (pin
.total_len
< pin
.packet_len
) {
147 ds_put_format(string
, " (***total_len < data_len***)");
150 ds_put_char(string
, '\n');
153 char *packet
= ofp_packet_to_string(pin
.packet
, pin
.packet_len
);
154 ds_put_cstr(string
, packet
);
160 print_note(struct ds
*string
, const struct nx_action_note
*nan
)
165 ds_put_cstr(string
, "note:");
166 len
= ntohs(nan
->len
) - offsetof(struct nx_action_note
, note
);
167 for (i
= 0; i
< len
; i
++) {
169 ds_put_char(string
, '.');
171 ds_put_format(string
, "%02"PRIx8
, nan
->note
[i
]);
176 ofp_print_action(struct ds
*s
, const union ofp_action
*a
,
177 enum ofputil_action_code code
)
179 const struct ofp_action_enqueue
*oae
;
180 const struct ofp_action_dl_addr
*oada
;
181 const struct nx_action_set_tunnel64
*nast64
;
182 const struct nx_action_set_tunnel
*nast
;
183 const struct nx_action_set_queue
*nasq
;
184 const struct nx_action_resubmit
*nar
;
185 const struct nx_action_reg_move
*move
;
186 const struct nx_action_reg_load
*load
;
187 const struct nx_action_multipath
*nam
;
188 const struct nx_action_autopath
*naa
;
189 const struct nx_action_output_reg
*naor
;
193 case OFPUTIL_OFPAT_OUTPUT
:
194 port
= ntohs(a
->output
.port
);
195 if (port
< OFPP_MAX
) {
196 ds_put_format(s
, "output:%"PRIu16
, port
);
198 ofputil_format_port(port
, s
);
199 if (port
== OFPP_CONTROLLER
) {
200 if (a
->output
.max_len
!= htons(0)) {
201 ds_put_format(s
, ":%"PRIu16
, ntohs(a
->output
.max_len
));
203 ds_put_cstr(s
, ":all");
209 case OFPUTIL_OFPAT_ENQUEUE
:
210 oae
= (const struct ofp_action_enqueue
*) a
;
211 ds_put_format(s
, "enqueue:");
212 ofputil_format_port(ntohs(oae
->port
), s
);
213 ds_put_format(s
, "q%"PRIu32
, ntohl(oae
->queue_id
));
216 case OFPUTIL_OFPAT_SET_VLAN_VID
:
217 ds_put_format(s
, "mod_vlan_vid:%"PRIu16
,
218 ntohs(a
->vlan_vid
.vlan_vid
));
221 case OFPUTIL_OFPAT_SET_VLAN_PCP
:
222 ds_put_format(s
, "mod_vlan_pcp:%"PRIu8
, a
->vlan_pcp
.vlan_pcp
);
225 case OFPUTIL_OFPAT_STRIP_VLAN
:
226 ds_put_cstr(s
, "strip_vlan");
229 case OFPUTIL_OFPAT_SET_DL_SRC
:
230 oada
= (const struct ofp_action_dl_addr
*) a
;
231 ds_put_format(s
, "mod_dl_src:"ETH_ADDR_FMT
,
232 ETH_ADDR_ARGS(oada
->dl_addr
));
235 case OFPUTIL_OFPAT_SET_DL_DST
:
236 oada
= (const struct ofp_action_dl_addr
*) a
;
237 ds_put_format(s
, "mod_dl_dst:"ETH_ADDR_FMT
,
238 ETH_ADDR_ARGS(oada
->dl_addr
));
241 case OFPUTIL_OFPAT_SET_NW_SRC
:
242 ds_put_format(s
, "mod_nw_src:"IP_FMT
, IP_ARGS(&a
->nw_addr
.nw_addr
));
245 case OFPUTIL_OFPAT_SET_NW_DST
:
246 ds_put_format(s
, "mod_nw_dst:"IP_FMT
, IP_ARGS(&a
->nw_addr
.nw_addr
));
249 case OFPUTIL_OFPAT_SET_NW_TOS
:
250 ds_put_format(s
, "mod_nw_tos:%d", a
->nw_tos
.nw_tos
);
253 case OFPUTIL_OFPAT_SET_TP_SRC
:
254 ds_put_format(s
, "mod_tp_src:%d", ntohs(a
->tp_port
.tp_port
));
257 case OFPUTIL_OFPAT_SET_TP_DST
:
258 ds_put_format(s
, "mod_tp_dst:%d", ntohs(a
->tp_port
.tp_port
));
261 case OFPUTIL_NXAST_RESUBMIT
:
262 nar
= (struct nx_action_resubmit
*)a
;
263 ds_put_format(s
, "resubmit:");
264 ofputil_format_port(ntohs(nar
->in_port
), s
);
267 case OFPUTIL_NXAST_RESUBMIT_TABLE
:
268 nar
= (struct nx_action_resubmit
*)a
;
269 ds_put_format(s
, "resubmit(");
270 if (nar
->in_port
!= htons(OFPP_IN_PORT
)) {
271 ofputil_format_port(ntohs(nar
->in_port
), s
);
274 if (nar
->table
!= 255) {
275 ds_put_format(s
, "%"PRIu8
, nar
->table
);
280 case OFPUTIL_NXAST_SET_TUNNEL
:
281 nast
= (struct nx_action_set_tunnel
*)a
;
282 ds_put_format(s
, "set_tunnel:%#"PRIx32
, ntohl(nast
->tun_id
));
285 case OFPUTIL_NXAST_SET_QUEUE
:
286 nasq
= (struct nx_action_set_queue
*)a
;
287 ds_put_format(s
, "set_queue:%u", ntohl(nasq
->queue_id
));
290 case OFPUTIL_NXAST_POP_QUEUE
:
291 ds_put_cstr(s
, "pop_queue");
294 case OFPUTIL_NXAST_NOTE
:
295 print_note(s
, (const struct nx_action_note
*) a
);
298 case OFPUTIL_NXAST_REG_MOVE
:
299 move
= (const struct nx_action_reg_move
*) a
;
300 nxm_format_reg_move(move
, s
);
303 case OFPUTIL_NXAST_REG_LOAD
:
304 load
= (const struct nx_action_reg_load
*) a
;
305 nxm_format_reg_load(load
, s
);
308 case OFPUTIL_NXAST_SET_TUNNEL64
:
309 nast64
= (const struct nx_action_set_tunnel64
*) a
;
310 ds_put_format(s
, "set_tunnel64:%#"PRIx64
,
311 ntohll(nast64
->tun_id
));
314 case OFPUTIL_NXAST_MULTIPATH
:
315 nam
= (const struct nx_action_multipath
*) a
;
316 multipath_format(nam
, s
);
319 case OFPUTIL_NXAST_AUTOPATH
:
320 naa
= (const struct nx_action_autopath
*)a
;
321 ds_put_format(s
, "autopath(%u,", ntohl(naa
->id
));
322 nxm_format_field_bits(s
, ntohl(naa
->dst
),
323 nxm_decode_ofs(naa
->ofs_nbits
),
324 nxm_decode_n_bits(naa
->ofs_nbits
));
328 case OFPUTIL_NXAST_BUNDLE
:
329 case OFPUTIL_NXAST_BUNDLE_LOAD
:
330 bundle_format((const struct nx_action_bundle
*) a
, s
);
333 case OFPUTIL_NXAST_OUTPUT_REG
:
334 naor
= (const struct nx_action_output_reg
*) a
;
335 ds_put_cstr(s
, "output:");
336 nxm_format_field_bits(s
, ntohl(naor
->src
),
337 nxm_decode_ofs(naor
->ofs_nbits
),
338 nxm_decode_n_bits(naor
->ofs_nbits
));
341 case OFPUTIL_NXAST_LEARN
:
342 learn_format((const struct nx_action_learn
*) a
, s
);
345 case OFPUTIL_NXAST_DEC_TTL
:
346 ds_put_cstr(s
, "dec_ttl");
349 case OFPUTIL_NXAST_EXIT
:
350 ds_put_cstr(s
, "exit");
359 ofp_print_actions(struct ds
*string
, const union ofp_action
*actions
,
362 const union ofp_action
*a
;
365 ds_put_cstr(string
, "actions=");
367 ds_put_cstr(string
, "drop");
370 OFPUTIL_ACTION_FOR_EACH (a
, left
, actions
, n_actions
) {
371 int code
= ofputil_decode_action(a
);
374 ds_put_cstr(string
, ",");
376 ofp_print_action(string
, a
, code
);
378 ofp_print_error(string
, -code
);
382 ds_put_format(string
, " ***%zu leftover bytes following actions",
388 ofp_print_packet_out(struct ds
*string
, const struct ofp_packet_out
*opo
,
391 size_t len
= ntohs(opo
->header
.length
);
392 size_t actions_len
= ntohs(opo
->actions_len
);
394 ds_put_cstr(string
, " in_port=");
395 ofputil_format_port(ntohs(opo
->in_port
), string
);
397 ds_put_format(string
, " actions_len=%zu ", actions_len
);
398 if (actions_len
> (ntohs(opo
->header
.length
) - sizeof *opo
)) {
399 ds_put_format(string
, "***packet too short for action length***\n");
402 if (actions_len
% sizeof(union ofp_action
)) {
403 ds_put_format(string
, "***action length not a multiple of %zu***\n",
404 sizeof(union ofp_action
));
406 ofp_print_actions(string
, (const union ofp_action
*) opo
->actions
,
407 actions_len
/ sizeof(union ofp_action
));
409 if (ntohl(opo
->buffer_id
) == UINT32_MAX
) {
410 int data_len
= len
- sizeof *opo
- actions_len
;
411 ds_put_format(string
, " data_len=%d", data_len
);
412 if (verbosity
> 0 && len
> sizeof *opo
) {
413 char *packet
= ofp_packet_to_string(
414 (uint8_t *) opo
->actions
+ actions_len
, data_len
);
415 ds_put_char(string
, '\n');
416 ds_put_cstr(string
, packet
);
420 ds_put_format(string
, " buffer=0x%08"PRIx32
, ntohl(opo
->buffer_id
));
422 ds_put_char(string
, '\n');
425 /* qsort comparison function. */
427 compare_ports(const void *a_
, const void *b_
)
429 const struct ofp_phy_port
*a
= a_
;
430 const struct ofp_phy_port
*b
= b_
;
431 uint16_t ap
= ntohs(a
->port_no
);
432 uint16_t bp
= ntohs(b
->port_no
);
434 return ap
< bp
? -1 : ap
> bp
;
443 ofp_print_bit_names(struct ds
*string
, uint32_t bits
,
444 const struct bit_name bit_names
[])
449 ds_put_cstr(string
, "0");
453 for (; bits
&& bit_names
->name
; bit_names
++) {
454 if (bits
& bit_names
->bit
) {
456 ds_put_char(string
, ' ');
458 ds_put_cstr(string
, bit_names
->name
);
459 bits
&= ~bit_names
->bit
;
465 ds_put_char(string
, ' ');
467 ds_put_format(string
, "0x%"PRIx32
, bits
);
472 ofp_print_port_features(struct ds
*string
, uint32_t features
)
474 static const struct bit_name feature_bits
[] = {
475 { OFPPF_10MB_HD
, "10MB-HD" },
476 { OFPPF_10MB_FD
, "10MB-FD" },
477 { OFPPF_100MB_HD
, "100MB-HD" },
478 { OFPPF_100MB_FD
, "100MB-FD" },
479 { OFPPF_1GB_HD
, "1GB-HD" },
480 { OFPPF_1GB_FD
, "1GB-FD" },
481 { OFPPF_10GB_FD
, "10GB-FD" },
482 { OFPPF_COPPER
, "COPPER" },
483 { OFPPF_FIBER
, "FIBER" },
484 { OFPPF_AUTONEG
, "AUTO_NEG" },
485 { OFPPF_PAUSE
, "AUTO_PAUSE" },
486 { OFPPF_PAUSE_ASYM
, "AUTO_PAUSE_ASYM" },
490 ofp_print_bit_names(string
, features
, feature_bits
);
491 ds_put_char(string
, '\n');
495 ofp_print_port_config(struct ds
*string
, uint32_t config
)
497 static const struct bit_name config_bits
[] = {
498 { OFPPC_PORT_DOWN
, "PORT_DOWN" },
499 { OFPPC_NO_STP
, "NO_STP" },
500 { OFPPC_NO_RECV
, "NO_RECV" },
501 { OFPPC_NO_RECV_STP
, "NO_RECV_STP" },
502 { OFPPC_NO_FLOOD
, "NO_FLOOD" },
503 { OFPPC_NO_FWD
, "NO_FWD" },
504 { OFPPC_NO_PACKET_IN
, "NO_PACKET_IN" },
508 ofp_print_bit_names(string
, config
, config_bits
);
509 ds_put_char(string
, '\n');
513 ofp_print_port_state(struct ds
*string
, uint32_t state
)
515 static const struct bit_name state_bits
[] = {
516 { OFPPS_LINK_DOWN
, "LINK_DOWN" },
521 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
522 * pattern. We have to special case it.
524 * OVS doesn't support STP, so this field will always be 0 if we are
525 * talking to OVS, so we'd always print STP_LISTEN in that case.
526 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
527 * avoid confusing users. */
528 stp_state
= state
& OFPPS_STP_MASK
;
530 ds_put_cstr(string
, (stp_state
== OFPPS_STP_LEARN
? "STP_LEARN"
531 : stp_state
== OFPPS_STP_FORWARD
? "STP_FORWARD"
533 state
&= ~OFPPS_STP_MASK
;
535 ofp_print_bit_names(string
, state
, state_bits
);
538 ofp_print_bit_names(string
, state
, state_bits
);
540 ds_put_char(string
, '\n');
544 ofp_print_phy_port(struct ds
*string
, const struct ofp_phy_port
*port
)
546 char name
[OFP_MAX_PORT_NAME_LEN
];
549 memcpy(name
, port
->name
, sizeof name
);
550 for (j
= 0; j
< sizeof name
- 1; j
++) {
551 if (!isprint((unsigned char) name
[j
])) {
557 ds_put_char(string
, ' ');
558 ofputil_format_port(ntohs(port
->port_no
), string
);
559 ds_put_format(string
, "(%s): addr:"ETH_ADDR_FMT
"\n",
560 name
, ETH_ADDR_ARGS(port
->hw_addr
));
562 ds_put_cstr(string
, " config: ");
563 ofp_print_port_config(string
, ntohl(port
->config
));
565 ds_put_cstr(string
, " state: ");
566 ofp_print_port_state(string
, ntohl(port
->state
));
569 ds_put_format(string
, " current: ");
570 ofp_print_port_features(string
, ntohl(port
->curr
));
572 if (port
->advertised
) {
573 ds_put_format(string
, " advertised: ");
574 ofp_print_port_features(string
, ntohl(port
->advertised
));
576 if (port
->supported
) {
577 ds_put_format(string
, " supported: ");
578 ofp_print_port_features(string
, ntohl(port
->supported
));
581 ds_put_format(string
, " peer: ");
582 ofp_print_port_features(string
, ntohl(port
->peer
));
587 ofp_print_switch_features(struct ds
*string
,
588 const struct ofp_switch_features
*osf
)
590 size_t len
= ntohs(osf
->header
.length
);
591 struct ofp_phy_port
*port_list
;
595 ds_put_format(string
, " ver:0x%x, dpid:%016"PRIx64
"\n",
596 osf
->header
.version
, ntohll(osf
->datapath_id
));
597 ds_put_format(string
, "n_tables:%d, n_buffers:%d\n", osf
->n_tables
,
598 ntohl(osf
->n_buffers
));
599 ds_put_format(string
, "features: capabilities:%#x, actions:%#x\n",
600 ntohl(osf
->capabilities
), ntohl(osf
->actions
));
602 n_ports
= (len
- sizeof *osf
) / sizeof *osf
->ports
;
604 port_list
= xmemdup(osf
->ports
, len
- sizeof *osf
);
605 qsort(port_list
, n_ports
, sizeof *port_list
, compare_ports
);
606 for (i
= 0; i
< n_ports
; i
++) {
607 ofp_print_phy_port(string
, &port_list
[i
]);
613 ofp_print_switch_config(struct ds
*string
, const struct ofp_switch_config
*osc
)
615 enum ofp_config_flags flags
;
617 flags
= ntohs(osc
->flags
);
619 ds_put_format(string
, " frags=%s", ofputil_frag_handling_to_string(flags
));
620 flags
&= ~OFPC_FRAG_MASK
;
622 if (flags
& OFPC_INVALID_TTL_TO_CONTROLLER
) {
623 ds_put_format(string
, " invalid_ttl_to_controller");
624 flags
&= ~OFPC_INVALID_TTL_TO_CONTROLLER
;
628 ds_put_format(string
, " ***unknown flags 0x%04"PRIx16
"***", flags
);
631 ds_put_format(string
, " miss_send_len=%"PRIu16
"\n", ntohs(osc
->miss_send_len
));
634 static void print_wild(struct ds
*string
, const char *leader
, int is_wild
,
635 int verbosity
, const char *format
, ...)
636 __attribute__((format(printf
, 5, 6)));
638 static void print_wild(struct ds
*string
, const char *leader
, int is_wild
,
639 int verbosity
, const char *format
, ...)
641 if (is_wild
&& verbosity
< 2) {
644 ds_put_cstr(string
, leader
);
648 va_start(args
, format
);
649 ds_put_format_valist(string
, format
, args
);
652 ds_put_char(string
, '*');
654 ds_put_char(string
, ',');
658 print_ip_netmask(struct ds
*string
, const char *leader
, ovs_be32 ip
,
659 uint32_t wild_bits
, int verbosity
)
661 if (wild_bits
>= 32 && verbosity
< 2) {
664 ds_put_cstr(string
, leader
);
665 if (wild_bits
< 32) {
666 ds_put_format(string
, IP_FMT
, IP_ARGS(&ip
));
668 ds_put_format(string
, "/%d", 32 - wild_bits
);
671 ds_put_char(string
, '*');
673 ds_put_char(string
, ',');
677 ofp_print_match(struct ds
*f
, const struct ofp_match
*om
, int verbosity
)
679 char *s
= ofp_match_to_string(om
, verbosity
);
685 ofp_match_to_string(const struct ofp_match
*om
, int verbosity
)
687 struct ds f
= DS_EMPTY_INITIALIZER
;
688 uint32_t w
= ntohl(om
->wildcards
);
689 bool skip_type
= false;
690 bool skip_proto
= false;
692 if (!(w
& OFPFW_DL_TYPE
)) {
694 if (om
->dl_type
== htons(ETH_TYPE_IP
)) {
695 if (!(w
& OFPFW_NW_PROTO
)) {
697 if (om
->nw_proto
== IPPROTO_ICMP
) {
698 ds_put_cstr(&f
, "icmp,");
699 } else if (om
->nw_proto
== IPPROTO_TCP
) {
700 ds_put_cstr(&f
, "tcp,");
701 } else if (om
->nw_proto
== IPPROTO_UDP
) {
702 ds_put_cstr(&f
, "udp,");
704 ds_put_cstr(&f
, "ip,");
708 ds_put_cstr(&f
, "ip,");
710 } else if (om
->dl_type
== htons(ETH_TYPE_ARP
)) {
711 ds_put_cstr(&f
, "arp,");
716 print_wild(&f
, "in_port=", w
& OFPFW_IN_PORT
, verbosity
,
717 "%d", ntohs(om
->in_port
));
718 print_wild(&f
, "dl_vlan=", w
& OFPFW_DL_VLAN
, verbosity
,
719 "%d", ntohs(om
->dl_vlan
));
720 print_wild(&f
, "dl_vlan_pcp=", w
& OFPFW_DL_VLAN_PCP
, verbosity
,
721 "%d", om
->dl_vlan_pcp
);
722 print_wild(&f
, "dl_src=", w
& OFPFW_DL_SRC
, verbosity
,
723 ETH_ADDR_FMT
, ETH_ADDR_ARGS(om
->dl_src
));
724 print_wild(&f
, "dl_dst=", w
& OFPFW_DL_DST
, verbosity
,
725 ETH_ADDR_FMT
, ETH_ADDR_ARGS(om
->dl_dst
));
727 print_wild(&f
, "dl_type=", w
& OFPFW_DL_TYPE
, verbosity
,
728 "0x%04x", ntohs(om
->dl_type
));
730 print_ip_netmask(&f
, "nw_src=", om
->nw_src
,
731 (w
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
, verbosity
);
732 print_ip_netmask(&f
, "nw_dst=", om
->nw_dst
,
733 (w
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
, verbosity
);
735 if (om
->dl_type
== htons(ETH_TYPE_ARP
)) {
736 print_wild(&f
, "arp_op=", w
& OFPFW_NW_PROTO
, verbosity
,
739 print_wild(&f
, "nw_proto=", w
& OFPFW_NW_PROTO
, verbosity
,
743 print_wild(&f
, "nw_tos=", w
& OFPFW_NW_TOS
, verbosity
,
745 if (om
->nw_proto
== IPPROTO_ICMP
) {
746 print_wild(&f
, "icmp_type=", w
& OFPFW_ICMP_TYPE
, verbosity
,
747 "%d", ntohs(om
->tp_src
));
748 print_wild(&f
, "icmp_code=", w
& OFPFW_ICMP_CODE
, verbosity
,
749 "%d", ntohs(om
->tp_dst
));
751 print_wild(&f
, "tp_src=", w
& OFPFW_TP_SRC
, verbosity
,
752 "%d", ntohs(om
->tp_src
));
753 print_wild(&f
, "tp_dst=", w
& OFPFW_TP_DST
, verbosity
,
754 "%d", ntohs(om
->tp_dst
));
756 if (ds_last(&f
) == ',') {
763 ofp_print_flow_mod(struct ds
*s
, const struct ofp_header
*oh
,
764 enum ofputil_msg_code code
, int verbosity
)
766 struct ofputil_flow_mod fm
;
770 error
= ofputil_decode_flow_mod(&fm
, oh
, true);
772 ofp_print_error(s
, error
);
777 switch (fm
.command
) {
779 ds_put_cstr(s
, "ADD");
782 ds_put_cstr(s
, "MOD");
784 case OFPFC_MODIFY_STRICT
:
785 ds_put_cstr(s
, "MOD_STRICT");
788 ds_put_cstr(s
, "DEL");
790 case OFPFC_DELETE_STRICT
:
791 ds_put_cstr(s
, "DEL_STRICT");
794 ds_put_format(s
, "cmd:%d", fm
.command
);
796 if (fm
.table_id
!= 0) {
797 ds_put_format(s
, " table:%d", fm
.table_id
);
801 if (verbosity
>= 3 && code
== OFPUTIL_OFPT_FLOW_MOD
) {
802 const struct ofp_flow_mod
*ofm
= (const struct ofp_flow_mod
*) oh
;
803 ofp_print_match(s
, &ofm
->match
, verbosity
);
805 /* ofp_print_match() doesn't print priority. */
806 need_priority
= true;
807 } else if (verbosity
>= 3 && code
== OFPUTIL_NXT_FLOW_MOD
) {
808 const struct nx_flow_mod
*nfm
= (const struct nx_flow_mod
*) oh
;
809 const void *nxm
= nfm
+ 1;
812 nxm_s
= nx_match_to_string(nxm
, ntohs(nfm
->match_len
));
813 ds_put_cstr(s
, nxm_s
);
816 /* nx_match_to_string() doesn't print priority. */
817 need_priority
= true;
819 cls_rule_format(&fm
.cr
, s
);
821 /* cls_rule_format() does print priority. */
822 need_priority
= false;
825 if (ds_last(s
) != ' ') {
828 if (fm
.cookie
!= htonll(0)) {
829 ds_put_format(s
, "cookie:0x%"PRIx64
" ", ntohll(fm
.cookie
));
831 if (fm
.idle_timeout
!= OFP_FLOW_PERMANENT
) {
832 ds_put_format(s
, "idle:%"PRIu16
" ", fm
.idle_timeout
);
834 if (fm
.hard_timeout
!= OFP_FLOW_PERMANENT
) {
835 ds_put_format(s
, "hard:%"PRIu16
" ", fm
.hard_timeout
);
837 if (fm
.cr
.priority
!= OFP_DEFAULT_PRIORITY
&& need_priority
) {
838 ds_put_format(s
, "pri:%"PRIu16
" ", fm
.cr
.priority
);
840 if (fm
.buffer_id
!= UINT32_MAX
) {
841 ds_put_format(s
, "buf:0x%"PRIx32
" ", fm
.buffer_id
);
844 ds_put_format(s
, "flags:0x%"PRIx16
" ", fm
.flags
);
847 ofp_print_actions(s
, fm
.actions
, fm
.n_actions
);
851 ofp_print_duration(struct ds
*string
, unsigned int sec
, unsigned int nsec
)
853 ds_put_format(string
, "%u", sec
);
855 ds_put_format(string
, ".%09u", nsec
);
856 while (string
->string
[string
->length
- 1] == '0') {
860 ds_put_char(string
, 's');
864 ofp_print_flow_removed(struct ds
*string
, const struct ofp_header
*oh
)
866 struct ofputil_flow_removed fr
;
869 error
= ofputil_decode_flow_removed(&fr
, oh
);
871 ofp_print_error(string
, error
);
875 ds_put_char(string
, ' ');
876 cls_rule_format(&fr
.rule
, string
);
878 ds_put_cstr(string
, " reason=");
880 case OFPRR_IDLE_TIMEOUT
:
881 ds_put_cstr(string
, "idle");
883 case OFPRR_HARD_TIMEOUT
:
884 ds_put_cstr(string
, "hard");
887 ds_put_cstr(string
, "delete");
890 ds_put_format(string
, "**%"PRIu8
"**", fr
.reason
);
894 if (fr
.cookie
!= htonll(0)) {
895 ds_put_format(string
, " cookie:0x%"PRIx64
, ntohll(fr
.cookie
));
897 ds_put_cstr(string
, " duration");
898 ofp_print_duration(string
, fr
.duration_sec
, fr
.duration_nsec
);
899 ds_put_format(string
, " idle%"PRIu16
" pkts%"PRIu64
" bytes%"PRIu64
"\n",
900 fr
.idle_timeout
, fr
.packet_count
, fr
.byte_count
);
904 ofp_print_port_mod(struct ds
*string
, const struct ofp_port_mod
*opm
)
906 ds_put_format(string
, "port: %d: addr:"ETH_ADDR_FMT
", config: %#x, mask:%#x\n",
907 ntohs(opm
->port_no
), ETH_ADDR_ARGS(opm
->hw_addr
),
908 ntohl(opm
->config
), ntohl(opm
->mask
));
909 ds_put_format(string
, " advertise: ");
910 if (opm
->advertise
) {
911 ofp_print_port_features(string
, ntohl(opm
->advertise
));
913 ds_put_format(string
, "UNCHANGED\n");
918 ofp_print_error(struct ds
*string
, enum ofperr error
)
920 if (string
->length
) {
921 ds_put_char(string
, ' ');
923 ds_put_format(string
, "***decode error: %s***\n", ofperr_get_name(error
));
927 ofp_print_error_msg(struct ds
*string
, const struct ofp_error_msg
*oem
)
929 size_t len
= ntohs(oem
->header
.length
);
930 size_t payload_ofs
, payload_len
;
935 error
= ofperr_decode_msg(&oem
->header
, &payload_ofs
);
937 ds_put_cstr(string
, "***decode error***");
938 ds_put_hex_dump(string
, oem
->data
, len
- sizeof *oem
, 0, true);
942 ds_put_format(string
, " %s\n", ofperr_get_name(error
));
944 payload
= (const uint8_t *) oem
+ payload_ofs
;
945 payload_len
= len
- payload_ofs
;
946 if (error
== OFPERR_OFPHFC_INCOMPATIBLE
|| error
== OFPERR_OFPHFC_EPERM
) {
947 ds_put_printable(string
, payload
, payload_len
);
949 s
= ofp_to_string(payload
, payload_len
, 1);
950 ds_put_cstr(string
, s
);
956 ofp_print_port_status(struct ds
*string
, const struct ofp_port_status
*ops
)
958 if (ops
->reason
== OFPPR_ADD
) {
959 ds_put_format(string
, " ADD:");
960 } else if (ops
->reason
== OFPPR_DELETE
) {
961 ds_put_format(string
, " DEL:");
962 } else if (ops
->reason
== OFPPR_MODIFY
) {
963 ds_put_format(string
, " MOD:");
966 ofp_print_phy_port(string
, &ops
->desc
);
970 ofp_print_ofpst_desc_reply(struct ds
*string
, const struct ofp_desc_stats
*ods
)
972 ds_put_char(string
, '\n');
973 ds_put_format(string
, "Manufacturer: %.*s\n",
974 (int) sizeof ods
->mfr_desc
, ods
->mfr_desc
);
975 ds_put_format(string
, "Hardware: %.*s\n",
976 (int) sizeof ods
->hw_desc
, ods
->hw_desc
);
977 ds_put_format(string
, "Software: %.*s\n",
978 (int) sizeof ods
->sw_desc
, ods
->sw_desc
);
979 ds_put_format(string
, "Serial Num: %.*s\n",
980 (int) sizeof ods
->serial_num
, ods
->serial_num
);
981 ds_put_format(string
, "DP Description: %.*s\n",
982 (int) sizeof ods
->dp_desc
, ods
->dp_desc
);
986 ofp_print_flow_stats_request(struct ds
*string
,
987 const struct ofp_stats_msg
*osm
)
989 struct ofputil_flow_stats_request fsr
;
992 error
= ofputil_decode_flow_stats_request(&fsr
, &osm
->header
);
994 ofp_print_error(string
, error
);
998 if (fsr
.table_id
!= 0xff) {
999 ds_put_format(string
, " table=%"PRIu8
, fsr
.table_id
);
1002 if (fsr
.out_port
!= OFPP_NONE
) {
1003 ds_put_cstr(string
, " out_port=");
1004 ofputil_format_port(fsr
.out_port
, string
);
1007 /* A flow stats request doesn't include a priority, but cls_rule_format()
1008 * will print one unless it is OFP_DEFAULT_PRIORITY. */
1009 fsr
.match
.priority
= OFP_DEFAULT_PRIORITY
;
1011 ds_put_char(string
, ' ');
1012 cls_rule_format(&fsr
.match
, string
);
1016 ofp_print_flow_stats_reply(struct ds
*string
, const struct ofp_header
*oh
)
1020 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1022 struct ofputil_flow_stats fs
;
1025 retval
= ofputil_decode_flow_stats_reply(&fs
, &b
);
1027 if (retval
!= EOF
) {
1028 ds_put_cstr(string
, " ***parse error***");
1033 ds_put_char(string
, '\n');
1035 ds_put_format(string
, " cookie=0x%"PRIx64
", duration=",
1037 ofp_print_duration(string
, fs
.duration_sec
, fs
.duration_nsec
);
1038 ds_put_format(string
, ", table=%"PRIu8
", ", fs
.table_id
);
1039 ds_put_format(string
, "n_packets=%"PRIu64
", ", fs
.packet_count
);
1040 ds_put_format(string
, "n_bytes=%"PRIu64
", ", fs
.byte_count
);
1041 if (fs
.idle_timeout
!= OFP_FLOW_PERMANENT
) {
1042 ds_put_format(string
, "idle_timeout=%"PRIu16
",", fs
.idle_timeout
);
1044 if (fs
.hard_timeout
!= OFP_FLOW_PERMANENT
) {
1045 ds_put_format(string
, "hard_timeout=%"PRIu16
",", fs
.hard_timeout
);
1048 cls_rule_format(&fs
.rule
, string
);
1049 if (string
->string
[string
->length
- 1] != ' ') {
1050 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 nx_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 nx_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_print_nxt_set_packet_in_format(struct ds
*string
,
1288 const struct nx_set_packet_in_format
*nspf
)
1290 uint32_t format
= ntohl(nspf
->format
);
1292 ds_put_cstr(string
, " format=");
1293 if (ofputil_packet_in_format_is_valid(format
)) {
1294 ds_put_cstr(string
, ofputil_packet_in_format_to_string(format
));
1296 ds_put_format(string
, "%"PRIu32
, format
);
1301 ofp_to_string__(const struct ofp_header
*oh
,
1302 const struct ofputil_msg_type
*type
, struct ds
*string
,
1305 enum ofputil_msg_code code
;
1306 const void *msg
= oh
;
1308 ds_put_format(string
, "%s (xid=0x%"PRIx32
"):",
1309 ofputil_msg_type_name(type
), ntohl(oh
->xid
));
1311 code
= ofputil_msg_type_code(type
);
1313 case OFPUTIL_MSG_INVALID
:
1316 case OFPUTIL_OFPT_HELLO
:
1317 ds_put_char(string
, '\n');
1318 ds_put_hex_dump(string
, oh
+ 1, ntohs(oh
->length
) - sizeof *oh
,
1322 case OFPUTIL_OFPT_ERROR
:
1323 ofp_print_error_msg(string
, msg
);
1326 case OFPUTIL_OFPT_ECHO_REQUEST
:
1327 case OFPUTIL_OFPT_ECHO_REPLY
:
1328 ofp_print_echo(string
, oh
, verbosity
);
1331 case OFPUTIL_OFPT_FEATURES_REQUEST
:
1334 case OFPUTIL_OFPT_FEATURES_REPLY
:
1335 ofp_print_switch_features(string
, msg
);
1338 case OFPUTIL_OFPT_GET_CONFIG_REQUEST
:
1341 case OFPUTIL_OFPT_GET_CONFIG_REPLY
:
1342 case OFPUTIL_OFPT_SET_CONFIG
:
1343 ofp_print_switch_config(string
, msg
);
1346 case OFPUTIL_OFPT_PACKET_IN
:
1347 case OFPUTIL_NXT_PACKET_IN
:
1348 ofp_print_packet_in(string
, msg
, verbosity
);
1351 case OFPUTIL_OFPT_FLOW_REMOVED
:
1352 case OFPUTIL_NXT_FLOW_REMOVED
:
1353 ofp_print_flow_removed(string
, msg
);
1356 case OFPUTIL_OFPT_PORT_STATUS
:
1357 ofp_print_port_status(string
, msg
);
1360 case OFPUTIL_OFPT_PACKET_OUT
:
1361 ofp_print_packet_out(string
, msg
, verbosity
);
1364 case OFPUTIL_OFPT_FLOW_MOD
:
1365 ofp_print_flow_mod(string
, msg
, code
, verbosity
);
1368 case OFPUTIL_OFPT_PORT_MOD
:
1369 ofp_print_port_mod(string
, msg
);
1372 case OFPUTIL_OFPT_BARRIER_REQUEST
:
1373 case OFPUTIL_OFPT_BARRIER_REPLY
:
1376 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST
:
1377 case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY
:
1381 case OFPUTIL_OFPST_DESC_REQUEST
:
1382 ofp_print_stats_request(string
, oh
);
1385 case OFPUTIL_OFPST_FLOW_REQUEST
:
1386 case OFPUTIL_NXST_FLOW_REQUEST
:
1387 case OFPUTIL_OFPST_AGGREGATE_REQUEST
:
1388 case OFPUTIL_NXST_AGGREGATE_REQUEST
:
1389 ofp_print_stats_request(string
, oh
);
1390 ofp_print_flow_stats_request(string
, msg
);
1393 case OFPUTIL_OFPST_TABLE_REQUEST
:
1394 ofp_print_stats_request(string
, oh
);
1397 case OFPUTIL_OFPST_PORT_REQUEST
:
1398 ofp_print_stats_request(string
, oh
);
1399 ofp_print_ofpst_port_request(string
, msg
);
1402 case OFPUTIL_OFPST_QUEUE_REQUEST
:
1403 ofp_print_stats_request(string
, oh
);
1404 ofp_print_ofpst_queue_request(string
, msg
);
1407 case OFPUTIL_OFPST_DESC_REPLY
:
1408 ofp_print_stats_reply(string
, oh
);
1409 ofp_print_ofpst_desc_reply(string
, msg
);
1412 case OFPUTIL_OFPST_FLOW_REPLY
:
1413 case OFPUTIL_NXST_FLOW_REPLY
:
1414 ofp_print_stats_reply(string
, oh
);
1415 ofp_print_flow_stats_reply(string
, oh
);
1418 case OFPUTIL_OFPST_QUEUE_REPLY
:
1419 ofp_print_stats_reply(string
, oh
);
1420 ofp_print_ofpst_queue_reply(string
, oh
, verbosity
);
1423 case OFPUTIL_OFPST_PORT_REPLY
:
1424 ofp_print_stats_reply(string
, oh
);
1425 ofp_print_ofpst_port_reply(string
, oh
, verbosity
);
1428 case OFPUTIL_OFPST_TABLE_REPLY
:
1429 ofp_print_stats_reply(string
, oh
);
1430 ofp_print_ofpst_table_reply(string
, oh
, verbosity
);
1433 case OFPUTIL_OFPST_AGGREGATE_REPLY
:
1434 ofp_print_stats_reply(string
, oh
);
1435 ofp_print_ofpst_aggregate_reply(string
, msg
);
1438 case OFPUTIL_NXT_ROLE_REQUEST
:
1439 case OFPUTIL_NXT_ROLE_REPLY
:
1440 ofp_print_nxt_role_message(string
, msg
);
1443 case OFPUTIL_NXT_FLOW_MOD_TABLE_ID
:
1444 ofp_print_nxt_flow_mod_table_id(string
, msg
);
1447 case OFPUTIL_NXT_SET_FLOW_FORMAT
:
1448 ofp_print_nxt_set_flow_format(string
, msg
);
1451 case OFPUTIL_NXT_SET_PACKET_IN_FORMAT
:
1452 ofp_print_nxt_set_packet_in_format(string
, msg
);
1455 case OFPUTIL_NXT_FLOW_MOD
:
1456 ofp_print_flow_mod(string
, msg
, code
, verbosity
);
1459 case OFPUTIL_NXST_AGGREGATE_REPLY
:
1460 ofp_print_stats_reply(string
, oh
);
1461 ofp_print_nxst_aggregate_reply(string
, msg
);
1466 /* Composes and returns a string representing the OpenFlow packet of 'len'
1467 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1468 * verbosity and higher numbers increase verbosity. The caller is responsible
1469 * for freeing the string. */
1471 ofp_to_string(const void *oh_
, size_t len
, int verbosity
)
1473 struct ds string
= DS_EMPTY_INITIALIZER
;
1474 const struct ofp_header
*oh
= oh_
;
1477 ds_put_cstr(&string
, "OpenFlow message is empty\n");
1478 } else if (len
< sizeof(struct ofp_header
)) {
1479 ds_put_format(&string
, "OpenFlow packet too short (only %zu bytes):\n",
1481 } else if (ntohs(oh
->length
) > len
) {
1482 ds_put_format(&string
,
1483 "(***truncated to %zu bytes from %"PRIu16
"***)\n",
1484 len
, ntohs(oh
->length
));
1485 } else if (ntohs(oh
->length
) < len
) {
1486 ds_put_format(&string
,
1487 "(***only uses %"PRIu16
" bytes out of %zu***)\n",
1488 ntohs(oh
->length
), len
);
1490 const struct ofputil_msg_type
*type
;
1493 error
= ofputil_decode_msg_type(oh
, &type
);
1495 ofp_to_string__(oh
, type
, &string
, verbosity
);
1496 if (verbosity
>= 5) {
1497 if (ds_last(&string
) != '\n') {
1498 ds_put_char(&string
, '\n');
1500 ds_put_hex_dump(&string
, oh
, len
, 0, true);
1502 if (ds_last(&string
) != '\n') {
1503 ds_put_char(&string
, '\n');
1505 return ds_steal_cstr(&string
);
1508 ofp_print_error(&string
, error
);
1510 ds_put_hex_dump(&string
, oh
, len
, 0, true);
1511 return ds_steal_cstr(&string
);
1514 /* Returns the name for the specified OpenFlow message type as a string,
1515 * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
1516 * hex number, e.g. "0x55".
1518 * The caller must free the returned string when it is no longer needed. */
1520 ofp_message_type_to_string(uint8_t type
)
1531 case OFPT_ECHO_REQUEST
:
1532 name
= "ECHO_REQUEST";
1534 case OFPT_ECHO_REPLY
:
1535 name
= "ECHO_REPLY";
1540 case OFPT_FEATURES_REQUEST
:
1541 name
= "FEATURES_REQUEST";
1543 case OFPT_FEATURES_REPLY
:
1544 name
= "FEATURES_REPLY";
1546 case OFPT_GET_CONFIG_REQUEST
:
1547 name
= "GET_CONFIG_REQUEST";
1549 case OFPT_GET_CONFIG_REPLY
:
1550 name
= "GET_CONFIG_REPLY";
1552 case OFPT_SET_CONFIG
:
1553 name
= "SET_CONFIG";
1555 case OFPT_PACKET_IN
:
1558 case OFPT_FLOW_REMOVED
:
1559 name
= "FLOW_REMOVED";
1561 case OFPT_PORT_STATUS
:
1562 name
= "PORT_STATUS";
1564 case OFPT_PACKET_OUT
:
1565 name
= "PACKET_OUT";
1573 case OFPT_STATS_REQUEST
:
1574 name
= "STATS_REQUEST";
1576 case OFPT_STATS_REPLY
:
1577 name
= "STATS_REPLY";
1579 case OFPT_BARRIER_REQUEST
:
1580 name
= "BARRIER_REQUEST";
1582 case OFPT_BARRIER_REPLY
:
1583 name
= "BARRIER_REPLY";
1585 case OFPT_QUEUE_GET_CONFIG_REQUEST
:
1586 name
= "QUEUE_GET_CONFIG_REQUEST";
1588 case OFPT_QUEUE_GET_CONFIG_REPLY
:
1589 name
= "QUEUE_GET_CONFIG_REPLY";
1596 return name
? xasprintf("OFPT_%s", name
) : xasprintf("0x%02"PRIx8
, type
);
1600 print_and_free(FILE *stream
, char *string
)
1602 fputs(string
, stream
);
1606 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1607 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1608 * numbers increase verbosity. */
1610 ofp_print(FILE *stream
, const void *oh
, size_t len
, int verbosity
)
1612 print_and_free(stream
, ofp_to_string(oh
, len
, verbosity
));
1615 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1616 * 'data' to 'stream'. */
1618 ofp_print_packet(FILE *stream
, const void *data
, size_t len
)
1620 print_and_free(stream
, ofp_packet_to_string(data
, len
));