2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
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"
36 #include "meta-flow.h"
39 #include "ofp-actions.h"
40 #include "ofp-errors.h"
44 #include "openflow/openflow.h"
45 #include "openflow/nicira-ext.h"
48 #include "type-props.h"
49 #include "unaligned.h"
52 static void ofp_print_queue_name(struct ds
*string
, uint32_t port
);
53 static void ofp_print_error(struct ds
*, enum ofperr
);
56 /* Returns a string that represents the contents of the Ethernet frame in the
57 * 'len' bytes starting at 'data'. The caller must free the returned string.*/
59 ofp_packet_to_string(const void *data
, size_t len
)
61 struct ds ds
= DS_EMPTY_INITIALIZER
;
65 ofpbuf_use_const(&buf
, data
, len
);
66 flow_extract(&buf
, 0, 0, 0, &flow
);
67 flow_format(&ds
, &flow
);
70 if (flow
.nw_proto
== IPPROTO_TCP
) {
71 struct tcp_header
*th
= buf
.l4
;
72 ds_put_format(&ds
, " tcp_csum:%"PRIx16
,
74 } else if (flow
.nw_proto
== IPPROTO_UDP
) {
75 struct udp_header
*uh
= buf
.l4
;
76 ds_put_format(&ds
, " udp_csum:%"PRIx16
,
81 ds_put_char(&ds
, '\n');
87 ofp_print_packet_in(struct ds
*string
, const struct ofp_header
*oh
,
90 struct ofputil_packet_in pin
;
94 error
= ofputil_decode_packet_in(&pin
, oh
);
96 ofp_print_error(string
, error
);
101 ds_put_format(string
, " table_id=%"PRIu8
, pin
.table_id
);
105 ds_put_format(string
, " cookie=0x%"PRIx64
, ntohll(pin
.cookie
));
108 ds_put_format(string
, " total_len=%"PRIu16
" in_port=", pin
.total_len
);
109 ofputil_format_port(pin
.fmd
.in_port
, string
);
111 if (pin
.fmd
.tun_id_mask
) {
112 ds_put_format(string
, " tun_id=0x%"PRIx64
, ntohll(pin
.fmd
.tun_id
));
113 if (pin
.fmd
.tun_id_mask
!= htonll(UINT64_MAX
)) {
114 ds_put_format(string
, "/0x%"PRIx64
, ntohll(pin
.fmd
.tun_id_mask
));
118 if (pin
.fmd
.metadata_mask
) {
119 ds_put_format(string
, " metadata=0x%"PRIx64
, ntohll(pin
.fmd
.metadata
));
120 if (pin
.fmd
.metadata_mask
!= htonll(UINT64_MAX
)) {
121 ds_put_format(string
, "/0x%"PRIx64
, ntohll(pin
.fmd
.metadata_mask
));
125 for (i
= 0; i
< FLOW_N_REGS
; i
++) {
126 if (pin
.fmd
.reg_masks
[i
]) {
127 ds_put_format(string
, " reg%d=0x%"PRIx32
, i
, pin
.fmd
.regs
[i
]);
128 if (pin
.fmd
.reg_masks
[i
] != UINT32_MAX
) {
129 ds_put_format(string
, "/0x%"PRIx32
, pin
.fmd
.reg_masks
[i
]);
134 ds_put_format(string
, " (via %s)",
135 ofputil_packet_in_reason_to_string(pin
.reason
));
137 ds_put_format(string
, " data_len=%zu", pin
.packet_len
);
138 if (pin
.buffer_id
== UINT32_MAX
) {
139 ds_put_format(string
, " (unbuffered)");
140 if (pin
.total_len
!= pin
.packet_len
) {
141 ds_put_format(string
, " (***total_len != data_len***)");
144 ds_put_format(string
, " buffer=0x%08"PRIx32
, pin
.buffer_id
);
145 if (pin
.total_len
< pin
.packet_len
) {
146 ds_put_format(string
, " (***total_len < data_len***)");
149 ds_put_char(string
, '\n');
152 char *packet
= ofp_packet_to_string(pin
.packet
, pin
.packet_len
);
153 ds_put_cstr(string
, packet
);
159 ofp_print_packet_out(struct ds
*string
, const struct ofp_header
*oh
,
162 struct ofputil_packet_out po
;
163 struct ofpbuf ofpacts
;
166 ofpbuf_init(&ofpacts
, 64);
167 error
= ofputil_decode_packet_out(&po
, oh
, &ofpacts
);
169 ofpbuf_uninit(&ofpacts
);
170 ofp_print_error(string
, error
);
174 ds_put_cstr(string
, " in_port=");
175 ofputil_format_port(po
.in_port
, string
);
177 ds_put_char(string
, ' ');
178 ofpacts_format(po
.ofpacts
, po
.ofpacts_len
, string
);
180 if (po
.buffer_id
== UINT32_MAX
) {
181 ds_put_format(string
, " data_len=%zu", po
.packet_len
);
182 if (verbosity
> 0 && po
.packet_len
> 0) {
183 char *packet
= ofp_packet_to_string(po
.packet
, po
.packet_len
);
184 ds_put_char(string
, '\n');
185 ds_put_cstr(string
, packet
);
189 ds_put_format(string
, " buffer=0x%08"PRIx32
, po
.buffer_id
);
191 ds_put_char(string
, '\n');
193 ofpbuf_uninit(&ofpacts
);
196 /* qsort comparison function. */
198 compare_ports(const void *a_
, const void *b_
)
200 const struct ofputil_phy_port
*a
= a_
;
201 const struct ofputil_phy_port
*b
= b_
;
202 uint16_t ap
= a
->port_no
;
203 uint16_t bp
= b
->port_no
;
205 return ap
< bp
? -1 : ap
> bp
;
209 ofp_print_bit_names(struct ds
*string
, uint32_t bits
,
210 const char *(*bit_to_name
)(uint32_t bit
),
217 ds_put_cstr(string
, "0");
221 for (i
= 0; i
< 32; i
++) {
222 uint32_t bit
= UINT32_C(1) << i
;
225 const char *name
= bit_to_name(bit
);
228 ds_put_char(string
, separator
);
230 ds_put_cstr(string
, name
);
238 ds_put_char(string
, separator
);
240 ds_put_format(string
, "0x%"PRIx32
, bits
);
245 netdev_feature_to_name(uint32_t bit
)
247 enum netdev_features f
= bit
;
250 case NETDEV_F_10MB_HD
: return "10MB-HD";
251 case NETDEV_F_10MB_FD
: return "10MB-FD";
252 case NETDEV_F_100MB_HD
: return "100MB-HD";
253 case NETDEV_F_100MB_FD
: return "100MB-FD";
254 case NETDEV_F_1GB_HD
: return "1GB-HD";
255 case NETDEV_F_1GB_FD
: return "1GB-FD";
256 case NETDEV_F_10GB_FD
: return "10GB-FD";
257 case NETDEV_F_40GB_FD
: return "40GB-FD";
258 case NETDEV_F_100GB_FD
: return "100GB-FD";
259 case NETDEV_F_1TB_FD
: return "1TB-FD";
260 case NETDEV_F_OTHER
: return "OTHER";
261 case NETDEV_F_COPPER
: return "COPPER";
262 case NETDEV_F_FIBER
: return "FIBER";
263 case NETDEV_F_AUTONEG
: return "AUTO_NEG";
264 case NETDEV_F_PAUSE
: return "AUTO_PAUSE";
265 case NETDEV_F_PAUSE_ASYM
: return "AUTO_PAUSE_ASYM";
272 ofp_print_port_features(struct ds
*string
, enum netdev_features features
)
274 ofp_print_bit_names(string
, features
, netdev_feature_to_name
, ' ');
275 ds_put_char(string
, '\n');
279 ofputil_port_config_to_name(uint32_t bit
)
281 enum ofputil_port_config pc
= bit
;
284 case OFPUTIL_PC_PORT_DOWN
: return "PORT_DOWN";
285 case OFPUTIL_PC_NO_STP
: return "NO_STP";
286 case OFPUTIL_PC_NO_RECV
: return "NO_RECV";
287 case OFPUTIL_PC_NO_RECV_STP
: return "NO_RECV_STP";
288 case OFPUTIL_PC_NO_FLOOD
: return "NO_FLOOD";
289 case OFPUTIL_PC_NO_FWD
: return "NO_FWD";
290 case OFPUTIL_PC_NO_PACKET_IN
: return "NO_PACKET_IN";
297 ofp_print_port_config(struct ds
*string
, enum ofputil_port_config config
)
299 ofp_print_bit_names(string
, config
, ofputil_port_config_to_name
, ' ');
300 ds_put_char(string
, '\n');
304 ofputil_port_state_to_name(uint32_t bit
)
306 enum ofputil_port_state ps
= bit
;
309 case OFPUTIL_PS_LINK_DOWN
: return "LINK_DOWN";
310 case OFPUTIL_PS_BLOCKED
: return "BLOCKED";
311 case OFPUTIL_PS_LIVE
: return "LIVE";
313 case OFPUTIL_PS_STP_LISTEN
:
314 case OFPUTIL_PS_STP_LEARN
:
315 case OFPUTIL_PS_STP_FORWARD
:
316 case OFPUTIL_PS_STP_BLOCK
:
317 /* Handled elsewhere. */
325 ofp_print_port_state(struct ds
*string
, enum ofputil_port_state state
)
327 enum ofputil_port_state stp_state
;
329 /* The STP state is a 2-bit field so it doesn't fit in with the bitmask
330 * pattern. We have to special case it.
332 * OVS doesn't support STP, so this field will always be 0 if we are
333 * talking to OVS, so we'd always print STP_LISTEN in that case.
334 * Therefore, we don't print anything at all if the value is STP_LISTEN, to
335 * avoid confusing users. */
336 stp_state
= state
& OFPUTIL_PS_STP_MASK
;
339 (stp_state
== OFPUTIL_PS_STP_LEARN
? "STP_LEARN"
340 : stp_state
== OFPUTIL_PS_STP_FORWARD
? "STP_FORWARD"
342 state
&= ~OFPUTIL_PS_STP_MASK
;
344 ofp_print_bit_names(string
, state
, ofputil_port_state_to_name
,
348 ofp_print_bit_names(string
, state
, ofputil_port_state_to_name
, ' ');
350 ds_put_char(string
, '\n');
354 ofp_print_phy_port(struct ds
*string
, const struct ofputil_phy_port
*port
)
356 char name
[sizeof port
->name
];
359 memcpy(name
, port
->name
, sizeof name
);
360 for (j
= 0; j
< sizeof name
- 1; j
++) {
361 if (!isprint((unsigned char) name
[j
])) {
367 ds_put_char(string
, ' ');
368 ofputil_format_port(port
->port_no
, string
);
369 ds_put_format(string
, "(%s): addr:"ETH_ADDR_FMT
"\n",
370 name
, ETH_ADDR_ARGS(port
->hw_addr
));
372 ds_put_cstr(string
, " config: ");
373 ofp_print_port_config(string
, port
->config
);
375 ds_put_cstr(string
, " state: ");
376 ofp_print_port_state(string
, port
->state
);
379 ds_put_format(string
, " current: ");
380 ofp_print_port_features(string
, port
->curr
);
382 if (port
->advertised
) {
383 ds_put_format(string
, " advertised: ");
384 ofp_print_port_features(string
, port
->advertised
);
386 if (port
->supported
) {
387 ds_put_format(string
, " supported: ");
388 ofp_print_port_features(string
, port
->supported
);
391 ds_put_format(string
, " peer: ");
392 ofp_print_port_features(string
, port
->peer
);
394 ds_put_format(string
, " speed: %"PRIu32
" Mbps now, "
395 "%"PRIu32
" Mbps max\n",
396 port
->curr_speed
/ UINT32_C(1000),
397 port
->max_speed
/ UINT32_C(1000));
400 /* Given a buffer 'b' that contains an array of OpenFlow ports of type
401 * 'ofp_version', writes a detailed description of each port into
404 ofp_print_phy_ports(struct ds
*string
, uint8_t ofp_version
,
408 struct ofputil_phy_port
*ports
;
412 n_ports
= ofputil_count_phy_ports(ofp_version
, b
);
414 ports
= xmalloc(n_ports
* sizeof *ports
);
415 for (i
= 0; i
< n_ports
; i
++) {
416 error
= ofputil_pull_phy_port(ofp_version
, b
, &ports
[i
]);
418 ofp_print_error(string
, error
);
422 qsort(ports
, n_ports
, sizeof *ports
, compare_ports
);
423 for (i
= 0; i
< n_ports
; i
++) {
424 ofp_print_phy_port(string
, &ports
[i
]);
432 ofputil_capabilities_to_name(uint32_t bit
)
434 enum ofputil_capabilities capabilities
= bit
;
436 switch (capabilities
) {
437 case OFPUTIL_C_FLOW_STATS
: return "FLOW_STATS";
438 case OFPUTIL_C_TABLE_STATS
: return "TABLE_STATS";
439 case OFPUTIL_C_PORT_STATS
: return "PORT_STATS";
440 case OFPUTIL_C_IP_REASM
: return "IP_REASM";
441 case OFPUTIL_C_QUEUE_STATS
: return "QUEUE_STATS";
442 case OFPUTIL_C_ARP_MATCH_IP
: return "ARP_MATCH_IP";
443 case OFPUTIL_C_STP
: return "STP";
444 case OFPUTIL_C_GROUP_STATS
: return "GROUP_STATS";
445 case OFPUTIL_C_PORT_BLOCKED
: return "PORT_BLOCKED";
452 ofputil_action_bitmap_to_name(uint32_t bit
)
454 enum ofputil_action_bitmap action
= bit
;
457 case OFPUTIL_A_OUTPUT
: return "OUTPUT";
458 case OFPUTIL_A_SET_VLAN_VID
: return "SET_VLAN_VID";
459 case OFPUTIL_A_SET_VLAN_PCP
: return "SET_VLAN_PCP";
460 case OFPUTIL_A_STRIP_VLAN
: return "STRIP_VLAN";
461 case OFPUTIL_A_SET_DL_SRC
: return "SET_DL_SRC";
462 case OFPUTIL_A_SET_DL_DST
: return "SET_DL_DST";
463 case OFPUTIL_A_SET_NW_SRC
: return "SET_NW_SRC";
464 case OFPUTIL_A_SET_NW_DST
: return "SET_NW_DST";
465 case OFPUTIL_A_SET_NW_ECN
: return "SET_NW_ECN";
466 case OFPUTIL_A_SET_NW_TOS
: return "SET_NW_TOS";
467 case OFPUTIL_A_SET_TP_SRC
: return "SET_TP_SRC";
468 case OFPUTIL_A_SET_TP_DST
: return "SET_TP_DST";
469 case OFPUTIL_A_ENQUEUE
: return "ENQUEUE";
470 case OFPUTIL_A_COPY_TTL_OUT
: return "COPY_TTL_OUT";
471 case OFPUTIL_A_COPY_TTL_IN
: return "COPY_TTL_IN";
472 case OFPUTIL_A_SET_MPLS_LABEL
: return "SET_MPLS_LABEL";
473 case OFPUTIL_A_SET_MPLS_TC
: return "SET_MPLS_TC";
474 case OFPUTIL_A_SET_MPLS_TTL
: return "SET_MPLS_TTL";
475 case OFPUTIL_A_DEC_MPLS_TTL
: return "DEC_MPLS_TTL";
476 case OFPUTIL_A_PUSH_VLAN
: return "PUSH_VLAN";
477 case OFPUTIL_A_POP_VLAN
: return "POP_VLAN";
478 case OFPUTIL_A_PUSH_MPLS
: return "PUSH_MPLS";
479 case OFPUTIL_A_POP_MPLS
: return "POP_MPLS";
480 case OFPUTIL_A_SET_QUEUE
: return "SET_QUEUE";
481 case OFPUTIL_A_GROUP
: return "GROUP";
482 case OFPUTIL_A_SET_NW_TTL
: return "SET_NW_TTL";
483 case OFPUTIL_A_DEC_NW_TTL
: return "DEC_NW_TTL";
490 ofp_print_switch_features(struct ds
*string
, const struct ofp_header
*oh
)
492 struct ofputil_switch_features features
;
496 error
= ofputil_decode_switch_features(oh
, &features
, &b
);
498 ofp_print_error(string
, error
);
502 ds_put_format(string
, " dpid:%016"PRIx64
"\n", features
.datapath_id
);
503 ds_put_format(string
, "n_tables:%"PRIu8
", n_buffers:%"PRIu32
"\n",
504 features
.n_tables
, features
.n_buffers
);
506 ds_put_cstr(string
, "capabilities: ");
507 ofp_print_bit_names(string
, features
.capabilities
,
508 ofputil_capabilities_to_name
, ' ');
509 ds_put_char(string
, '\n');
511 switch ((enum ofp_version
)oh
->version
) {
513 ds_put_cstr(string
, "actions: ");
514 ofp_print_bit_names(string
, features
.actions
,
515 ofputil_action_bitmap_to_name
, ' ');
516 ds_put_char(string
, '\n');
525 ofp_print_phy_ports(string
, oh
->version
, &b
);
529 ofp_print_switch_config(struct ds
*string
, const struct ofp_switch_config
*osc
)
531 enum ofp_config_flags flags
;
533 flags
= ntohs(osc
->flags
);
535 ds_put_format(string
, " frags=%s", ofputil_frag_handling_to_string(flags
));
536 flags
&= ~OFPC_FRAG_MASK
;
538 if (flags
& OFPC_INVALID_TTL_TO_CONTROLLER
) {
539 ds_put_format(string
, " invalid_ttl_to_controller");
540 flags
&= ~OFPC_INVALID_TTL_TO_CONTROLLER
;
544 ds_put_format(string
, " ***unknown flags 0x%04"PRIx16
"***", flags
);
547 ds_put_format(string
, " miss_send_len=%"PRIu16
"\n", ntohs(osc
->miss_send_len
));
550 static void print_wild(struct ds
*string
, const char *leader
, int is_wild
,
551 int verbosity
, const char *format
, ...)
552 __attribute__((format(printf
, 5, 6)));
554 static void print_wild(struct ds
*string
, const char *leader
, int is_wild
,
555 int verbosity
, const char *format
, ...)
557 if (is_wild
&& verbosity
< 2) {
560 ds_put_cstr(string
, leader
);
564 va_start(args
, format
);
565 ds_put_format_valist(string
, format
, args
);
568 ds_put_char(string
, '*');
570 ds_put_char(string
, ',');
574 print_ip_netmask(struct ds
*string
, const char *leader
, ovs_be32 ip
,
575 uint32_t wild_bits
, int verbosity
)
577 if (wild_bits
>= 32 && verbosity
< 2) {
580 ds_put_cstr(string
, leader
);
581 if (wild_bits
< 32) {
582 ds_put_format(string
, IP_FMT
, IP_ARGS(&ip
));
584 ds_put_format(string
, "/%d", 32 - wild_bits
);
587 ds_put_char(string
, '*');
589 ds_put_char(string
, ',');
593 ofp10_match_print(struct ds
*f
, const struct ofp10_match
*om
, int verbosity
)
595 char *s
= ofp10_match_to_string(om
, verbosity
);
601 ofp10_match_to_string(const struct ofp10_match
*om
, int verbosity
)
603 struct ds f
= DS_EMPTY_INITIALIZER
;
604 uint32_t w
= ntohl(om
->wildcards
);
605 bool skip_type
= false;
606 bool skip_proto
= false;
608 if (!(w
& OFPFW10_DL_TYPE
)) {
610 if (om
->dl_type
== htons(ETH_TYPE_IP
)) {
611 if (!(w
& OFPFW10_NW_PROTO
)) {
613 if (om
->nw_proto
== IPPROTO_ICMP
) {
614 ds_put_cstr(&f
, "icmp,");
615 } else if (om
->nw_proto
== IPPROTO_TCP
) {
616 ds_put_cstr(&f
, "tcp,");
617 } else if (om
->nw_proto
== IPPROTO_UDP
) {
618 ds_put_cstr(&f
, "udp,");
620 ds_put_cstr(&f
, "ip,");
624 ds_put_cstr(&f
, "ip,");
626 } else if (om
->dl_type
== htons(ETH_TYPE_ARP
)) {
627 ds_put_cstr(&f
, "arp,");
632 print_wild(&f
, "in_port=", w
& OFPFW10_IN_PORT
, verbosity
,
633 "%d", ntohs(om
->in_port
));
634 print_wild(&f
, "dl_vlan=", w
& OFPFW10_DL_VLAN
, verbosity
,
635 "%d", ntohs(om
->dl_vlan
));
636 print_wild(&f
, "dl_vlan_pcp=", w
& OFPFW10_DL_VLAN_PCP
, verbosity
,
637 "%d", om
->dl_vlan_pcp
);
638 print_wild(&f
, "dl_src=", w
& OFPFW10_DL_SRC
, verbosity
,
639 ETH_ADDR_FMT
, ETH_ADDR_ARGS(om
->dl_src
));
640 print_wild(&f
, "dl_dst=", w
& OFPFW10_DL_DST
, verbosity
,
641 ETH_ADDR_FMT
, ETH_ADDR_ARGS(om
->dl_dst
));
643 print_wild(&f
, "dl_type=", w
& OFPFW10_DL_TYPE
, verbosity
,
644 "0x%04x", ntohs(om
->dl_type
));
646 print_ip_netmask(&f
, "nw_src=", om
->nw_src
,
647 (w
& OFPFW10_NW_SRC_MASK
) >> OFPFW10_NW_SRC_SHIFT
,
649 print_ip_netmask(&f
, "nw_dst=", om
->nw_dst
,
650 (w
& OFPFW10_NW_DST_MASK
) >> OFPFW10_NW_DST_SHIFT
,
653 if (om
->dl_type
== htons(ETH_TYPE_ARP
)) {
654 print_wild(&f
, "arp_op=", w
& OFPFW10_NW_PROTO
, verbosity
,
657 print_wild(&f
, "nw_proto=", w
& OFPFW10_NW_PROTO
, verbosity
,
661 print_wild(&f
, "nw_tos=", w
& OFPFW10_NW_TOS
, verbosity
,
663 if (om
->nw_proto
== IPPROTO_ICMP
) {
664 print_wild(&f
, "icmp_type=", w
& OFPFW10_ICMP_TYPE
, verbosity
,
665 "%d", ntohs(om
->tp_src
));
666 print_wild(&f
, "icmp_code=", w
& OFPFW10_ICMP_CODE
, verbosity
,
667 "%d", ntohs(om
->tp_dst
));
669 print_wild(&f
, "tp_src=", w
& OFPFW10_TP_SRC
, verbosity
,
670 "%d", ntohs(om
->tp_src
));
671 print_wild(&f
, "tp_dst=", w
& OFPFW10_TP_DST
, verbosity
,
672 "%d", ntohs(om
->tp_dst
));
674 if (ds_last(&f
) == ',') {
681 ofp_print_flow_mod(struct ds
*s
, const struct ofp_header
*oh
, int verbosity
)
683 struct ofputil_flow_mod fm
;
684 struct ofpbuf ofpacts
;
688 enum ofputil_protocol protocol
;
690 protocol
= ofputil_protocol_from_ofp_version(oh
->version
);
691 protocol
= ofputil_protocol_set_tid(protocol
, true);
693 ofpbuf_init(&ofpacts
, 64);
694 error
= ofputil_decode_flow_mod(&fm
, oh
, protocol
, &ofpacts
);
696 ofpbuf_uninit(&ofpacts
);
697 ofp_print_error(s
, error
);
702 switch (fm
.command
) {
704 ds_put_cstr(s
, "ADD");
707 ds_put_cstr(s
, "MOD");
709 case OFPFC_MODIFY_STRICT
:
710 ds_put_cstr(s
, "MOD_STRICT");
713 ds_put_cstr(s
, "DEL");
715 case OFPFC_DELETE_STRICT
:
716 ds_put_cstr(s
, "DEL_STRICT");
719 ds_put_format(s
, "cmd:%d", fm
.command
);
721 if (fm
.table_id
!= 0) {
722 ds_put_format(s
, " table:%d", fm
.table_id
);
726 ofpraw_decode(&raw
, oh
);
727 if (verbosity
>= 3 && raw
== OFPRAW_OFPT10_FLOW_MOD
) {
728 const struct ofp10_flow_mod
*ofm
= ofpmsg_body(oh
);
729 ofp10_match_print(s
, &ofm
->match
, verbosity
);
731 /* ofp_print_match() doesn't print priority. */
732 need_priority
= true;
733 } else if (verbosity
>= 3 && raw
== OFPRAW_NXT_FLOW_MOD
) {
734 const struct nx_flow_mod
*nfm
= ofpmsg_body(oh
);
735 const void *nxm
= nfm
+ 1;
738 nxm_s
= nx_match_to_string(nxm
, ntohs(nfm
->match_len
));
739 ds_put_cstr(s
, nxm_s
);
742 /* nx_match_to_string() doesn't print priority. */
743 need_priority
= true;
745 cls_rule_format(&fm
.cr
, s
);
747 /* cls_rule_format() does print priority. */
748 need_priority
= false;
751 if (ds_last(s
) != ' ') {
754 if (fm
.new_cookie
!= htonll(0)) {
755 ds_put_format(s
, "cookie:0x%"PRIx64
" ", ntohll(fm
.new_cookie
));
757 if (fm
.cookie_mask
!= htonll(0)) {
758 ds_put_format(s
, "cookie:0x%"PRIx64
"/0x%"PRIx64
" ",
759 ntohll(fm
.cookie
), ntohll(fm
.cookie_mask
));
761 if (fm
.idle_timeout
!= OFP_FLOW_PERMANENT
) {
762 ds_put_format(s
, "idle:%"PRIu16
" ", fm
.idle_timeout
);
764 if (fm
.hard_timeout
!= OFP_FLOW_PERMANENT
) {
765 ds_put_format(s
, "hard:%"PRIu16
" ", fm
.hard_timeout
);
767 if (fm
.cr
.priority
!= OFP_DEFAULT_PRIORITY
&& need_priority
) {
768 ds_put_format(s
, "pri:%"PRIu16
" ", fm
.cr
.priority
);
770 if (fm
.buffer_id
!= UINT32_MAX
) {
771 ds_put_format(s
, "buf:0x%"PRIx32
" ", fm
.buffer_id
);
773 if (fm
.out_port
!= OFPP_NONE
) {
774 ds_put_format(s
, "out_port:");
775 ofputil_format_port(fm
.out_port
, s
);
779 uint16_t flags
= fm
.flags
;
781 if (flags
& OFPFF_SEND_FLOW_REM
) {
782 ds_put_cstr(s
, "send_flow_rem ");
784 if (flags
& OFPFF_CHECK_OVERLAP
) {
785 ds_put_cstr(s
, "check_overlap ");
787 if (flags
& OFPFF10_EMERG
) {
788 ds_put_cstr(s
, "emerg ");
791 flags
&= ~(OFPFF_SEND_FLOW_REM
| OFPFF_CHECK_OVERLAP
| OFPFF10_EMERG
);
793 ds_put_format(s
, "flags:0x%"PRIx16
" ", flags
);
797 ofpacts_format(fm
.ofpacts
, fm
.ofpacts_len
, s
);
798 ofpbuf_uninit(&ofpacts
);
802 ofp_print_duration(struct ds
*string
, unsigned int sec
, unsigned int nsec
)
804 ds_put_format(string
, "%u", sec
);
806 ds_put_format(string
, ".%09u", nsec
);
807 while (string
->string
[string
->length
- 1] == '0') {
811 ds_put_char(string
, 's');
815 ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason
)
820 case OFPRR_IDLE_TIMEOUT
:
822 case OFPRR_HARD_TIMEOUT
:
826 case OFPRR_GROUP_DELETE
:
827 return "group_delete";
831 sprintf(s
, "%d", (int) reason
);
837 ofp_print_flow_removed(struct ds
*string
, const struct ofp_header
*oh
)
839 struct ofputil_flow_removed fr
;
842 error
= ofputil_decode_flow_removed(&fr
, oh
);
844 ofp_print_error(string
, error
);
848 ds_put_char(string
, ' ');
849 cls_rule_format(&fr
.rule
, string
);
851 ds_put_format(string
, " reason=%s",
852 ofp_flow_removed_reason_to_string(fr
.reason
));
854 if (fr
.cookie
!= htonll(0)) {
855 ds_put_format(string
, " cookie:0x%"PRIx64
, ntohll(fr
.cookie
));
857 ds_put_cstr(string
, " duration");
858 ofp_print_duration(string
, fr
.duration_sec
, fr
.duration_nsec
);
859 ds_put_format(string
, " idle%"PRIu16
" pkts%"PRIu64
" bytes%"PRIu64
"\n",
860 fr
.idle_timeout
, fr
.packet_count
, fr
.byte_count
);
864 ofp_print_port_mod(struct ds
*string
, const struct ofp_header
*oh
)
866 struct ofputil_port_mod pm
;
869 error
= ofputil_decode_port_mod(oh
, &pm
);
871 ofp_print_error(string
, error
);
875 ds_put_format(string
, "port: %"PRIu16
": addr:"ETH_ADDR_FMT
"\n",
876 pm
.port_no
, ETH_ADDR_ARGS(pm
.hw_addr
));
878 ds_put_format(string
, " config: ");
879 ofp_print_port_config(string
, pm
.config
);
881 ds_put_format(string
, " mask: ");
882 ofp_print_port_config(string
, pm
.mask
);
884 ds_put_format(string
, " advertise: ");
886 ofp_print_port_features(string
, pm
.advertise
);
888 ds_put_format(string
, "UNCHANGED\n");
893 ofp_print_error(struct ds
*string
, enum ofperr error
)
895 if (string
->length
) {
896 ds_put_char(string
, ' ');
898 ds_put_format(string
, "***decode error: %s***\n", ofperr_get_name(error
));
902 ofp_print_error_msg(struct ds
*string
, const struct ofp_header
*oh
)
904 size_t len
= ntohs(oh
->length
);
905 struct ofpbuf payload
;
909 error
= ofperr_decode_msg(oh
, &payload
);
911 ds_put_cstr(string
, "***decode error***");
912 ds_put_hex_dump(string
, oh
+ 1, len
- sizeof *oh
, 0, true);
916 ds_put_format(string
, " %s\n", ofperr_get_name(error
));
918 if (error
== OFPERR_OFPHFC_INCOMPATIBLE
|| error
== OFPERR_OFPHFC_EPERM
) {
919 ds_put_printable(string
, payload
.data
, payload
.size
);
921 s
= ofp_to_string(payload
.data
, payload
.size
, 1);
922 ds_put_cstr(string
, s
);
928 ofp_print_port_status(struct ds
*string
, const struct ofp_header
*oh
)
930 struct ofputil_port_status ps
;
933 error
= ofputil_decode_port_status(oh
, &ps
);
935 ofp_print_error(string
, error
);
939 if (ps
.reason
== OFPPR_ADD
) {
940 ds_put_format(string
, " ADD:");
941 } else if (ps
.reason
== OFPPR_DELETE
) {
942 ds_put_format(string
, " DEL:");
943 } else if (ps
.reason
== OFPPR_MODIFY
) {
944 ds_put_format(string
, " MOD:");
947 ofp_print_phy_port(string
, &ps
.desc
);
951 ofp_print_ofpst_desc_reply(struct ds
*string
, const struct ofp_header
*oh
)
953 const struct ofp_desc_stats
*ods
= ofpmsg_body(oh
);
955 ds_put_char(string
, '\n');
956 ds_put_format(string
, "Manufacturer: %.*s\n",
957 (int) sizeof ods
->mfr_desc
, ods
->mfr_desc
);
958 ds_put_format(string
, "Hardware: %.*s\n",
959 (int) sizeof ods
->hw_desc
, ods
->hw_desc
);
960 ds_put_format(string
, "Software: %.*s\n",
961 (int) sizeof ods
->sw_desc
, ods
->sw_desc
);
962 ds_put_format(string
, "Serial Num: %.*s\n",
963 (int) sizeof ods
->serial_num
, ods
->serial_num
);
964 ds_put_format(string
, "DP Description: %.*s\n",
965 (int) sizeof ods
->dp_desc
, ods
->dp_desc
);
969 ofp_print_flow_stats_request(struct ds
*string
, const struct ofp_header
*oh
)
971 struct ofputil_flow_stats_request fsr
;
974 error
= ofputil_decode_flow_stats_request(&fsr
, oh
);
976 ofp_print_error(string
, error
);
980 if (fsr
.table_id
!= 0xff) {
981 ds_put_format(string
, " table=%"PRIu8
, fsr
.table_id
);
984 if (fsr
.out_port
!= OFPP_NONE
) {
985 ds_put_cstr(string
, " out_port=");
986 ofputil_format_port(fsr
.out_port
, string
);
989 /* A flow stats request doesn't include a priority, but cls_rule_format()
990 * will print one unless it is OFP_DEFAULT_PRIORITY. */
991 fsr
.match
.priority
= OFP_DEFAULT_PRIORITY
;
993 ds_put_char(string
, ' ');
994 cls_rule_format(&fsr
.match
, string
);
998 ofp_print_flow_stats(struct ds
*string
, struct ofputil_flow_stats
*fs
)
1000 ds_put_format(string
, " cookie=0x%"PRIx64
", duration=",
1001 ntohll(fs
->cookie
));
1003 ofp_print_duration(string
, fs
->duration_sec
, fs
->duration_nsec
);
1004 ds_put_format(string
, ", table=%"PRIu8
", ", fs
->table_id
);
1005 ds_put_format(string
, "n_packets=%"PRIu64
", ", fs
->packet_count
);
1006 ds_put_format(string
, "n_bytes=%"PRIu64
", ", fs
->byte_count
);
1007 if (fs
->idle_timeout
!= OFP_FLOW_PERMANENT
) {
1008 ds_put_format(string
, "idle_timeout=%"PRIu16
", ", fs
->idle_timeout
);
1010 if (fs
->hard_timeout
!= OFP_FLOW_PERMANENT
) {
1011 ds_put_format(string
, "hard_timeout=%"PRIu16
", ", fs
->hard_timeout
);
1013 if (fs
->idle_age
>= 0) {
1014 ds_put_format(string
, "idle_age=%d, ", fs
->idle_age
);
1016 if (fs
->hard_age
>= 0 && fs
->hard_age
!= fs
->duration_sec
) {
1017 ds_put_format(string
, "hard_age=%d, ", fs
->hard_age
);
1020 cls_rule_format(&fs
->rule
, string
);
1021 if (string
->string
[string
->length
- 1] != ' ') {
1022 ds_put_char(string
, ' ');
1025 ofpacts_format(fs
->ofpacts
, fs
->ofpacts_len
, string
);
1029 ofp_print_flow_stats_reply(struct ds
*string
, const struct ofp_header
*oh
)
1031 struct ofpbuf ofpacts
;
1034 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1035 ofpbuf_init(&ofpacts
, 64);
1037 struct ofputil_flow_stats fs
;
1040 retval
= ofputil_decode_flow_stats_reply(&fs
, &b
, true, &ofpacts
);
1042 if (retval
!= EOF
) {
1043 ds_put_cstr(string
, " ***parse error***");
1047 ds_put_char(string
, '\n');
1048 ofp_print_flow_stats(string
, &fs
);
1053 ofp_print_aggregate_stats_reply(struct ds
*string
, const struct ofp_header
*oh
)
1055 struct ofputil_aggregate_stats as
;
1058 error
= ofputil_decode_aggregate_stats_reply(&as
, oh
);
1060 ofp_print_error(string
, error
);
1064 ds_put_format(string
, " packet_count=%"PRIu64
, as
.packet_count
);
1065 ds_put_format(string
, " byte_count=%"PRIu64
, as
.byte_count
);
1066 ds_put_format(string
, " flow_count=%"PRIu32
, as
.flow_count
);
1069 static void print_port_stat(struct ds
*string
, const char *leader
,
1070 const ovs_32aligned_be64
*statp
, int more
)
1072 uint64_t stat
= ntohll(get_32aligned_be64(statp
));
1074 ds_put_cstr(string
, leader
);
1075 if (stat
!= UINT64_MAX
) {
1076 ds_put_format(string
, "%"PRIu64
, stat
);
1078 ds_put_char(string
, '?');
1081 ds_put_cstr(string
, ", ");
1083 ds_put_cstr(string
, "\n");
1088 ofp_print_ofpst_port_request(struct ds
*string
, const struct ofp_header
*oh
)
1090 const struct ofp10_port_stats_request
*psr
= ofpmsg_body(oh
);
1091 ds_put_format(string
, " port_no=%"PRIu16
, ntohs(psr
->port_no
));
1095 ofp_print_ofpst_port_reply(struct ds
*string
, const struct ofp_header
*oh
,
1098 struct ofp10_port_stats
*ps
;
1102 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1103 ofpraw_pull_assert(&b
);
1105 n
= b
.size
/ sizeof *ps
;
1106 ds_put_format(string
, " %zu ports\n", n
);
1107 if (verbosity
< 1) {
1112 ps
= ofpbuf_try_pull(&b
, sizeof *ps
);
1117 ds_put_format(string
, " port %2"PRIu16
": ", ntohs(ps
->port_no
));
1119 ds_put_cstr(string
, "rx ");
1120 print_port_stat(string
, "pkts=", &ps
->rx_packets
, 1);
1121 print_port_stat(string
, "bytes=", &ps
->rx_bytes
, 1);
1122 print_port_stat(string
, "drop=", &ps
->rx_dropped
, 1);
1123 print_port_stat(string
, "errs=", &ps
->rx_errors
, 1);
1124 print_port_stat(string
, "frame=", &ps
->rx_frame_err
, 1);
1125 print_port_stat(string
, "over=", &ps
->rx_over_err
, 1);
1126 print_port_stat(string
, "crc=", &ps
->rx_crc_err
, 0);
1128 ds_put_cstr(string
, " tx ");
1129 print_port_stat(string
, "pkts=", &ps
->tx_packets
, 1);
1130 print_port_stat(string
, "bytes=", &ps
->tx_bytes
, 1);
1131 print_port_stat(string
, "drop=", &ps
->tx_dropped
, 1);
1132 print_port_stat(string
, "errs=", &ps
->tx_errors
, 1);
1133 print_port_stat(string
, "coll=", &ps
->collisions
, 0);
1138 ofp_print_ofpst_table_reply(struct ds
*string
, const struct ofp_header
*oh
,
1141 struct ofp10_table_stats
*ts
;
1145 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1146 ofpraw_pull_assert(&b
);
1148 n
= b
.size
/ sizeof *ts
;
1149 ds_put_format(string
, " %zu tables\n", n
);
1150 if (verbosity
< 1) {
1155 char name
[OFP_MAX_TABLE_NAME_LEN
+ 1];
1157 ts
= ofpbuf_try_pull(&b
, sizeof *ts
);
1162 ovs_strlcpy(name
, ts
->name
, sizeof name
);
1164 ds_put_format(string
, " %d: %-8s: ", ts
->table_id
, name
);
1165 ds_put_format(string
, "wild=0x%05"PRIx32
", ", ntohl(ts
->wildcards
));
1166 ds_put_format(string
, "max=%6"PRIu32
", ", ntohl(ts
->max_entries
));
1167 ds_put_format(string
, "active=%"PRIu32
"\n", ntohl(ts
->active_count
));
1168 ds_put_cstr(string
, " ");
1169 ds_put_format(string
, "lookup=%"PRIu64
", ",
1170 ntohll(get_32aligned_be64(&ts
->lookup_count
)));
1171 ds_put_format(string
, "matched=%"PRIu64
"\n",
1172 ntohll(get_32aligned_be64(&ts
->matched_count
)));
1177 ofp_print_queue_name(struct ds
*string
, uint32_t queue_id
)
1179 if (queue_id
== OFPQ_ALL
) {
1180 ds_put_cstr(string
, "ALL");
1182 ds_put_format(string
, "%"PRIu32
, queue_id
);
1187 ofp_print_ofpst_queue_request(struct ds
*string
, const struct ofp_header
*oh
)
1189 const struct ofp10_queue_stats_request
*qsr
= ofpmsg_body(oh
);
1191 ds_put_cstr(string
, "port=");
1192 ofputil_format_port(ntohs(qsr
->port_no
), string
);
1194 ds_put_cstr(string
, " queue=");
1195 ofp_print_queue_name(string
, ntohl(qsr
->queue_id
));
1199 ofp_print_ofpst_queue_reply(struct ds
*string
, const struct ofp_header
*oh
,
1202 struct ofp10_queue_stats
*qs
;
1206 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1207 ofpraw_pull_assert(&b
);
1209 n
= b
.size
/ sizeof *qs
;
1210 ds_put_format(string
, " %zu queues\n", n
);
1211 if (verbosity
< 1) {
1216 qs
= ofpbuf_try_pull(&b
, sizeof *qs
);
1221 ds_put_cstr(string
, " port ");
1222 ofputil_format_port(ntohs(qs
->port_no
), string
);
1223 ds_put_cstr(string
, " queue ");
1224 ofp_print_queue_name(string
, ntohl(qs
->queue_id
));
1225 ds_put_cstr(string
, ": ");
1227 print_port_stat(string
, "bytes=", &qs
->tx_bytes
, 1);
1228 print_port_stat(string
, "pkts=", &qs
->tx_packets
, 1);
1229 print_port_stat(string
, "errors=", &qs
->tx_errors
, 0);
1234 ofp_print_ofpst_port_desc_reply(struct ds
*string
,
1235 const struct ofp_header
*oh
)
1239 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1240 ofpraw_pull_assert(&b
);
1241 ds_put_char(string
, '\n');
1242 ofp_print_phy_ports(string
, oh
->version
, &b
);
1246 ofp_print_stats_request(struct ds
*string
, const struct ofp_header
*oh
)
1248 uint16_t flags
= ofpmp_flags(oh
);
1251 ds_put_format(string
, " ***unknown flags 0x%04"PRIx16
"***", flags
);
1256 ofp_print_stats_reply(struct ds
*string
, const struct ofp_header
*oh
)
1258 uint16_t flags
= ofpmp_flags(oh
);
1261 ds_put_cstr(string
, " flags=");
1262 if (flags
& OFPSF_REPLY_MORE
) {
1263 ds_put_cstr(string
, "[more]");
1264 flags
&= ~OFPSF_REPLY_MORE
;
1267 ds_put_format(string
, "[***unknown flags 0x%04"PRIx16
"***]",
1274 ofp_print_echo(struct ds
*string
, const struct ofp_header
*oh
, int verbosity
)
1276 size_t len
= ntohs(oh
->length
);
1278 ds_put_format(string
, " %zu bytes of payload\n", len
- sizeof *oh
);
1279 if (verbosity
> 1) {
1280 ds_put_hex_dump(string
, oh
+ 1, len
- sizeof *oh
, 0, true);
1285 ofp_print_nxt_role_message(struct ds
*string
,
1286 const struct nx_role_request
*nrr
)
1288 unsigned int role
= ntohl(nrr
->role
);
1290 ds_put_cstr(string
, " role=");
1291 if (role
== NX_ROLE_OTHER
) {
1292 ds_put_cstr(string
, "other");
1293 } else if (role
== NX_ROLE_MASTER
) {
1294 ds_put_cstr(string
, "master");
1295 } else if (role
== NX_ROLE_SLAVE
) {
1296 ds_put_cstr(string
, "slave");
1298 ds_put_format(string
, "%u", role
);
1303 ofp_print_nxt_flow_mod_table_id(struct ds
*string
,
1304 const struct nx_flow_mod_table_id
*nfmti
)
1306 ds_put_format(string
, " %s", nfmti
->set
? "enable" : "disable");
1310 ofp_print_nxt_set_flow_format(struct ds
*string
,
1311 const struct nx_set_flow_format
*nsff
)
1313 uint32_t format
= ntohl(nsff
->format
);
1315 ds_put_cstr(string
, " format=");
1316 if (ofputil_nx_flow_format_is_valid(format
)) {
1317 ds_put_cstr(string
, ofputil_nx_flow_format_to_string(format
));
1319 ds_put_format(string
, "%"PRIu32
, format
);
1324 ofp_print_nxt_set_packet_in_format(struct ds
*string
,
1325 const struct nx_set_packet_in_format
*nspf
)
1327 uint32_t format
= ntohl(nspf
->format
);
1329 ds_put_cstr(string
, " format=");
1330 if (ofputil_packet_in_format_is_valid(format
)) {
1331 ds_put_cstr(string
, ofputil_packet_in_format_to_string(format
));
1333 ds_put_format(string
, "%"PRIu32
, format
);
1338 ofp_port_reason_to_string(enum ofp_port_reason reason
)
1353 sprintf(s
, "%d", (int) reason
);
1359 ofp_print_nxt_set_async_config(struct ds
*string
,
1360 const struct nx_async_config
*nac
)
1364 for (i
= 0; i
< 2; i
++) {
1367 ds_put_format(string
, "\n %s:\n", i
== 0 ? "master" : "slave");
1369 ds_put_cstr(string
, " PACKET_IN:");
1370 for (j
= 0; j
< 32; j
++) {
1371 if (nac
->packet_in_mask
[i
] & htonl(1u << j
)) {
1372 ds_put_format(string
, " %s",
1373 ofputil_packet_in_reason_to_string(j
));
1376 if (!nac
->packet_in_mask
[i
]) {
1377 ds_put_cstr(string
, " (off)");
1379 ds_put_char(string
, '\n');
1381 ds_put_cstr(string
, " PORT_STATUS:");
1382 for (j
= 0; j
< 32; j
++) {
1383 if (nac
->port_status_mask
[i
] & htonl(1u << j
)) {
1384 ds_put_format(string
, " %s", ofp_port_reason_to_string(j
));
1387 if (!nac
->port_status_mask
[i
]) {
1388 ds_put_cstr(string
, " (off)");
1390 ds_put_char(string
, '\n');
1392 ds_put_cstr(string
, " FLOW_REMOVED:");
1393 for (j
= 0; j
< 32; j
++) {
1394 if (nac
->flow_removed_mask
[i
] & htonl(1u << j
)) {
1395 ds_put_format(string
, " %s",
1396 ofp_flow_removed_reason_to_string(j
));
1399 if (!nac
->flow_removed_mask
[i
]) {
1400 ds_put_cstr(string
, " (off)");
1402 ds_put_char(string
, '\n');
1407 ofp_print_nxt_set_controller_id(struct ds
*string
,
1408 const struct nx_controller_id
*nci
)
1410 ds_put_format(string
, " id=%"PRIu16
, ntohs(nci
->controller_id
));
1414 ofp_print_nxt_flow_monitor_cancel(struct ds
*string
,
1415 const struct ofp_header
*oh
)
1417 ds_put_format(string
, " id=%"PRIu32
,
1418 ofputil_decode_flow_monitor_cancel(oh
));
1422 nx_flow_monitor_flags_to_name(uint32_t bit
)
1424 enum nx_flow_monitor_flags fmf
= bit
;
1427 case NXFMF_INITIAL
: return "initial";
1428 case NXFMF_ADD
: return "add";
1429 case NXFMF_DELETE
: return "delete";
1430 case NXFMF_MODIFY
: return "modify";
1431 case NXFMF_ACTIONS
: return "actions";
1432 case NXFMF_OWN
: return "own";
1439 ofp_print_nxst_flow_monitor_request(struct ds
*string
,
1440 const struct ofp_header
*oh
)
1444 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1446 struct ofputil_flow_monitor_request request
;
1449 retval
= ofputil_decode_flow_monitor_request(&request
, &b
);
1451 if (retval
!= EOF
) {
1452 ofp_print_error(string
, retval
);
1457 ds_put_format(string
, "\n id=%"PRIu32
" flags=", request
.id
);
1458 ofp_print_bit_names(string
, request
.flags
,
1459 nx_flow_monitor_flags_to_name
, ',');
1461 if (request
.out_port
!= OFPP_NONE
) {
1462 ds_put_cstr(string
, " out_port=");
1463 ofputil_format_port(request
.out_port
, string
);
1466 if (request
.table_id
!= 0xff) {
1467 ds_put_format(string
, " table=%"PRIu8
, request
.table_id
);
1470 ds_put_char(string
, ' ');
1471 cls_rule_format(&request
.match
, string
);
1472 ds_chomp(string
, ' ');
1477 ofp_print_nxst_flow_monitor_reply(struct ds
*string
,
1478 const struct ofp_header
*oh
)
1480 uint64_t ofpacts_stub
[1024 / 8];
1481 struct ofpbuf ofpacts
;
1484 ofpbuf_use_const(&b
, oh
, ntohs(oh
->length
));
1485 ofpbuf_use_stub(&ofpacts
, ofpacts_stub
, sizeof ofpacts_stub
);
1487 struct ofputil_flow_update update
;
1488 struct cls_rule match
;
1491 update
.match
= &match
;
1492 retval
= ofputil_decode_flow_update(&update
, &b
, &ofpacts
);
1494 if (retval
!= EOF
) {
1495 ofp_print_error(string
, retval
);
1497 ofpbuf_uninit(&ofpacts
);
1501 ds_put_cstr(string
, "\n event=");
1502 switch (update
.event
) {
1504 ds_put_cstr(string
, "ADDED");
1508 ds_put_format(string
, "DELETED reason=%s",
1509 ofp_flow_removed_reason_to_string(update
.reason
));
1512 case NXFME_MODIFIED
:
1513 ds_put_cstr(string
, "MODIFIED");
1517 ds_put_format(string
, "ABBREV xid=0x%"PRIx32
, ntohl(update
.xid
));
1521 ds_put_format(string
, " table=%"PRIu8
, update
.table_id
);
1522 if (update
.idle_timeout
!= OFP_FLOW_PERMANENT
) {
1523 ds_put_format(string
, " idle_timeout=%"PRIu16
,
1524 update
.idle_timeout
);
1526 if (update
.hard_timeout
!= OFP_FLOW_PERMANENT
) {
1527 ds_put_format(string
, " hard_timeout=%"PRIu16
,
1528 update
.hard_timeout
);
1530 ds_put_format(string
, " cookie=%#"PRIx64
, ntohll(update
.cookie
));
1532 ds_put_char(string
, ' ');
1533 cls_rule_format(update
.match
, string
);
1535 if (update
.ofpacts_len
) {
1536 if (string
->string
[string
->length
- 1] != ' ') {
1537 ds_put_char(string
, ' ');
1539 ofpacts_format(update
.ofpacts
, update
.ofpacts_len
, string
);
1545 ofp_print_version(const struct ofp_header
*oh
,
1548 switch (oh
->version
) {
1552 ds_put_cstr(string
, " (OF1.1)");
1555 ds_put_cstr(string
, " (OF1.2)");
1558 ds_put_format(string
, " (OF 0x%02"PRIx8
")", oh
->version
);
1561 ds_put_format(string
, " (xid=0x%"PRIx32
"):", ntohl(oh
->xid
));
1565 ofp_header_to_string__(const struct ofp_header
*oh
, enum ofpraw raw
,
1568 ds_put_cstr(string
, ofpraw_get_name(raw
));
1569 ofp_print_version(oh
, string
);
1573 ofp_to_string__(const struct ofp_header
*oh
, enum ofpraw raw
,
1574 struct ds
*string
, int verbosity
)
1576 const void *msg
= oh
;
1578 ofp_header_to_string__(oh
, raw
, string
);
1579 switch (ofptype_from_ofpraw(raw
)) {
1581 ds_put_char(string
, '\n');
1582 ds_put_hex_dump(string
, oh
+ 1, ntohs(oh
->length
) - sizeof *oh
,
1587 ofp_print_error_msg(string
, oh
);
1590 case OFPTYPE_ECHO_REQUEST
:
1591 case OFPTYPE_ECHO_REPLY
:
1592 ofp_print_echo(string
, oh
, verbosity
);
1595 case OFPTYPE_FEATURES_REQUEST
:
1598 case OFPTYPE_FEATURES_REPLY
:
1599 ofp_print_switch_features(string
, oh
);
1602 case OFPTYPE_GET_CONFIG_REQUEST
:
1605 case OFPTYPE_GET_CONFIG_REPLY
:
1606 case OFPTYPE_SET_CONFIG
:
1607 ofp_print_switch_config(string
, ofpmsg_body(oh
));
1610 case OFPTYPE_PACKET_IN
:
1611 ofp_print_packet_in(string
, oh
, verbosity
);
1614 case OFPTYPE_FLOW_REMOVED
:
1615 ofp_print_flow_removed(string
, oh
);
1618 case OFPTYPE_PORT_STATUS
:
1619 ofp_print_port_status(string
, oh
);
1622 case OFPTYPE_PACKET_OUT
:
1623 ofp_print_packet_out(string
, oh
, verbosity
);
1626 case OFPTYPE_FLOW_MOD
:
1627 ofp_print_flow_mod(string
, oh
, verbosity
);
1630 case OFPTYPE_PORT_MOD
:
1631 ofp_print_port_mod(string
, oh
);
1634 case OFPTYPE_BARRIER_REQUEST
:
1635 case OFPTYPE_BARRIER_REPLY
:
1638 case OFPTYPE_DESC_STATS_REQUEST
:
1639 case OFPTYPE_PORT_DESC_STATS_REQUEST
:
1640 ofp_print_stats_request(string
, oh
);
1643 case OFPTYPE_FLOW_STATS_REQUEST
:
1644 case OFPTYPE_AGGREGATE_STATS_REQUEST
:
1645 ofp_print_stats_request(string
, oh
);
1646 ofp_print_flow_stats_request(string
, oh
);
1649 case OFPTYPE_TABLE_STATS_REQUEST
:
1650 ofp_print_stats_request(string
, oh
);
1653 case OFPTYPE_PORT_STATS_REQUEST
:
1654 ofp_print_stats_request(string
, oh
);
1655 ofp_print_ofpst_port_request(string
, oh
);
1658 case OFPTYPE_QUEUE_STATS_REQUEST
:
1659 ofp_print_stats_request(string
, oh
);
1660 ofp_print_ofpst_queue_request(string
, oh
);
1663 case OFPTYPE_DESC_STATS_REPLY
:
1664 ofp_print_stats_reply(string
, oh
);
1665 ofp_print_ofpst_desc_reply(string
, oh
);
1668 case OFPTYPE_FLOW_STATS_REPLY
:
1669 ofp_print_stats_reply(string
, oh
);
1670 ofp_print_flow_stats_reply(string
, oh
);
1673 case OFPTYPE_QUEUE_STATS_REPLY
:
1674 ofp_print_stats_reply(string
, oh
);
1675 ofp_print_ofpst_queue_reply(string
, oh
, verbosity
);
1678 case OFPTYPE_PORT_STATS_REPLY
:
1679 ofp_print_stats_reply(string
, oh
);
1680 ofp_print_ofpst_port_reply(string
, oh
, verbosity
);
1683 case OFPTYPE_TABLE_STATS_REPLY
:
1684 ofp_print_stats_reply(string
, oh
);
1685 ofp_print_ofpst_table_reply(string
, oh
, verbosity
);
1688 case OFPTYPE_AGGREGATE_STATS_REPLY
:
1689 ofp_print_stats_reply(string
, oh
);
1690 ofp_print_aggregate_stats_reply(string
, oh
);
1693 case OFPTYPE_PORT_DESC_STATS_REPLY
:
1694 ofp_print_stats_reply(string
, oh
);
1695 ofp_print_ofpst_port_desc_reply(string
, oh
);
1698 case OFPTYPE_ROLE_REQUEST
:
1699 case OFPTYPE_ROLE_REPLY
:
1700 ofp_print_nxt_role_message(string
, ofpmsg_body(oh
));
1703 case OFPTYPE_FLOW_MOD_TABLE_ID
:
1704 ofp_print_nxt_flow_mod_table_id(string
, ofpmsg_body(oh
));
1707 case OFPTYPE_SET_FLOW_FORMAT
:
1708 ofp_print_nxt_set_flow_format(string
, ofpmsg_body(oh
));
1711 case OFPTYPE_SET_PACKET_IN_FORMAT
:
1712 ofp_print_nxt_set_packet_in_format(string
, ofpmsg_body(oh
));
1715 case OFPTYPE_FLOW_AGE
:
1718 case OFPTYPE_SET_CONTROLLER_ID
:
1719 ofp_print_nxt_set_controller_id(string
, ofpmsg_body(oh
));
1722 case OFPTYPE_SET_ASYNC_CONFIG
:
1723 ofp_print_nxt_set_async_config(string
, ofpmsg_body(oh
));
1726 case OFPTYPE_FLOW_MONITOR_CANCEL
:
1727 ofp_print_nxt_flow_monitor_cancel(string
, msg
);
1730 case OFPTYPE_FLOW_MONITOR_PAUSED
:
1731 case OFPTYPE_FLOW_MONITOR_RESUMED
:
1734 case OFPTYPE_FLOW_MONITOR_STATS_REQUEST
:
1735 ofp_print_nxst_flow_monitor_request(string
, msg
);
1738 case OFPTYPE_FLOW_MONITOR_STATS_REPLY
:
1739 ofp_print_nxst_flow_monitor_reply(string
, msg
);
1744 /* Composes and returns a string representing the OpenFlow packet of 'len'
1745 * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
1746 * verbosity and higher numbers increase verbosity. The caller is responsible
1747 * for freeing the string. */
1749 ofp_to_string(const void *oh_
, size_t len
, int verbosity
)
1751 struct ds string
= DS_EMPTY_INITIALIZER
;
1752 const struct ofp_header
*oh
= oh_
;
1755 ds_put_cstr(&string
, "OpenFlow message is empty\n");
1756 } else if (len
< sizeof(struct ofp_header
)) {
1757 ds_put_format(&string
, "OpenFlow packet too short (only %zu bytes):\n",
1759 } else if (ntohs(oh
->length
) > len
) {
1763 error
= ofpraw_decode_partial(&raw
, oh
, len
);
1765 ofp_header_to_string__(oh
, raw
, &string
);
1766 ds_put_char(&string
, '\n');
1769 ds_put_format(&string
,
1770 "(***truncated to %zu bytes from %"PRIu16
"***)\n",
1771 len
, ntohs(oh
->length
));
1772 } else if (ntohs(oh
->length
) < len
) {
1773 ds_put_format(&string
,
1774 "(***only uses %"PRIu16
" bytes out of %zu***)\n",
1775 ntohs(oh
->length
), len
);
1780 error
= ofpraw_decode(&raw
, oh
);
1782 ofp_to_string__(oh
, raw
, &string
, verbosity
);
1783 if (verbosity
>= 5) {
1784 if (ds_last(&string
) != '\n') {
1785 ds_put_char(&string
, '\n');
1787 ds_put_hex_dump(&string
, oh
, len
, 0, true);
1789 if (ds_last(&string
) != '\n') {
1790 ds_put_char(&string
, '\n');
1792 return ds_steal_cstr(&string
);
1795 ofp_print_error(&string
, error
);
1797 ds_put_hex_dump(&string
, oh
, len
, 0, true);
1798 return ds_steal_cstr(&string
);
1802 print_and_free(FILE *stream
, char *string
)
1804 fputs(string
, stream
);
1808 /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
1809 * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
1810 * numbers increase verbosity. */
1812 ofp_print(FILE *stream
, const void *oh
, size_t len
, int verbosity
)
1814 print_and_free(stream
, ofp_to_string(oh
, len
, verbosity
));
1817 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
1818 * 'data' to 'stream'. */
1820 ofp_print_packet(FILE *stream
, const void *data
, size_t len
)
1822 print_and_free(stream
, ofp_packet_to_string(data
, len
));