]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
7ac27a04 | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. |
064af421 | 3 | * |
a14bc59f BP |
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: | |
064af421 | 7 | * |
a14bc59f BP |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * | |
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. | |
064af421 BP |
15 | */ |
16 | ||
17 | #include <config.h> | |
18 | #include "ofp-print.h" | |
064af421 BP |
19 | |
20 | #include <errno.h> | |
21 | #include <inttypes.h> | |
7f3adc00 | 22 | #include <sys/types.h> |
064af421 BP |
23 | #include <netinet/in.h> |
24 | #include <sys/wait.h> | |
25 | #include <stdarg.h> | |
26 | #include <stdlib.h> | |
27 | #include <ctype.h> | |
28 | ||
daff3353 | 29 | #include "bundle.h" |
10a24935 | 30 | #include "byte-order.h" |
064af421 BP |
31 | #include "compiler.h" |
32 | #include "dynamic-string.h" | |
33 | #include "flow.h" | |
75a75043 | 34 | #include "learn.h" |
53ddd40a | 35 | #include "multipath.h" |
816fd533 | 36 | #include "meta-flow.h" |
9e1fd49b | 37 | #include "netdev.h" |
7fa91113 | 38 | #include "nx-match.h" |
f25d0cf3 | 39 | #include "ofp-actions.h" |
cf62fa4c | 40 | #include "ofpbuf.h" |
90bf1e07 | 41 | #include "ofp-errors.h" |
982697a4 | 42 | #include "ofp-msgs.h" |
69b6be19 | 43 | #include "ofp-util.h" |
064af421 BP |
44 | #include "openflow/openflow.h" |
45 | #include "openflow/nicira-ext.h" | |
46 | #include "packets.h" | |
cf62fa4c | 47 | #include "dp-packet.h" |
e41a9130 | 48 | #include "type-props.h" |
c4617b3c | 49 | #include "unaligned.h" |
b5e7e61a | 50 | #include "odp-util.h" |
064af421 BP |
51 | #include "util.h" |
52 | ||
d2805da2 | 53 | static void ofp_print_queue_name(struct ds *string, uint32_t port); |
90bf1e07 | 54 | static void ofp_print_error(struct ds *, enum ofperr); |
064af421 BP |
55 | |
56 | /* Returns a string that represents the contents of the Ethernet frame in the | |
897a8e07 | 57 | * 'len' bytes starting at 'data'. The caller must free the returned string.*/ |
064af421 | 58 | char * |
c499c75d | 59 | ofp_packet_to_string(const void *data, size_t len) |
064af421 BP |
60 | { |
61 | struct ds ds = DS_EMPTY_INITIALIZER; | |
cf62fa4c | 62 | struct dp_packet buf; |
897a8e07 | 63 | struct flow flow; |
5a51b2cd | 64 | size_t l4_size; |
064af421 | 65 | |
cf62fa4c PS |
66 | dp_packet_use_const(&buf, data, len); |
67 | flow_extract(&buf, &flow); | |
897a8e07 | 68 | flow_format(&ds, &flow); |
e50abca5 | 69 | |
cf62fa4c | 70 | l4_size = dp_packet_l4_size(&buf); |
5a51b2cd JR |
71 | |
72 | if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) { | |
cf62fa4c | 73 | struct tcp_header *th = dp_packet_l4(&buf); |
5a51b2cd JR |
74 | ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum)); |
75 | } else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) { | |
cf62fa4c | 76 | struct udp_header *uh = dp_packet_l4(&buf); |
5a51b2cd JR |
77 | ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum)); |
78 | } else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) { | |
cf62fa4c | 79 | struct sctp_header *sh = dp_packet_l4(&buf); |
5fa008d4 BP |
80 | ds_put_format(&ds, " sctp_csum:%"PRIx32, |
81 | ntohl(get_16aligned_be32(&sh->sctp_csum))); | |
e60e935b | 82 | } else if (flow.nw_proto == IPPROTO_ICMP && l4_size >= ICMP_HEADER_LEN) { |
cf62fa4c | 83 | struct icmp_header *icmph = dp_packet_l4(&buf); |
e60e935b SRCSA |
84 | ds_put_format(&ds, " icmp_csum:%"PRIx16, |
85 | ntohs(icmph->icmp_csum)); | |
86 | } else if (flow.nw_proto == IPPROTO_ICMPV6 && l4_size >= ICMP6_HEADER_LEN) { | |
cf62fa4c | 87 | struct icmp6_header *icmp6h = dp_packet_l4(&buf); |
e60e935b SRCSA |
88 | ds_put_format(&ds, " icmp6_csum:%"PRIx16, |
89 | ntohs(icmp6h->icmp6_cksum)); | |
e50abca5 EJ |
90 | } |
91 | ||
897a8e07 | 92 | ds_put_char(&ds, '\n'); |
064af421 | 93 | |
064af421 BP |
94 | return ds_cstr(&ds); |
95 | } | |
96 | ||
064af421 | 97 | static void |
65120a8a | 98 | ofp_print_packet_in(struct ds *string, const struct ofp_header *oh, |
d1e2cf21 | 99 | int verbosity) |
064af421 | 100 | { |
5014a89d | 101 | char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE]; |
65120a8a EJ |
102 | struct ofputil_packet_in pin; |
103 | int error; | |
064af421 | 104 | |
65120a8a EJ |
105 | error = ofputil_decode_packet_in(&pin, oh); |
106 | if (error) { | |
107 | ofp_print_error(string, error); | |
108 | return; | |
109 | } | |
110 | ||
54834960 EJ |
111 | if (pin.table_id) { |
112 | ds_put_format(string, " table_id=%"PRIu8, pin.table_id); | |
113 | } | |
114 | ||
d4fa4e79 | 115 | if (pin.cookie != OVS_BE64_MAX) { |
54834960 EJ |
116 | ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie)); |
117 | } | |
118 | ||
50dcbd8e | 119 | ds_put_format(string, " total_len=%"PRIuSIZE" ", pin.total_len); |
5d6c3af0 | 120 | |
50dcbd8e | 121 | match_format(&pin.flow_metadata, string, OFP_DEFAULT_PRIORITY); |
ac923e91 | 122 | |
80d5aefd | 123 | ds_put_format(string, " (via %s)", |
5014a89d BP |
124 | ofputil_packet_in_reason_to_string(pin.reason, reasonbuf, |
125 | sizeof reasonbuf)); | |
064af421 | 126 | |
34582733 | 127 | ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len); |
65120a8a | 128 | if (pin.buffer_id == UINT32_MAX) { |
064af421 | 129 | ds_put_format(string, " (unbuffered)"); |
65120a8a | 130 | if (pin.total_len != pin.packet_len) { |
064af421 | 131 | ds_put_format(string, " (***total_len != data_len***)"); |
65120a8a | 132 | } |
064af421 | 133 | } else { |
65120a8a EJ |
134 | ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id); |
135 | if (pin.total_len < pin.packet_len) { | |
064af421 | 136 | ds_put_format(string, " (***total_len < data_len***)"); |
65120a8a | 137 | } |
064af421 BP |
138 | } |
139 | ds_put_char(string, '\n'); | |
140 | ||
141 | if (verbosity > 0) { | |
65120a8a | 142 | char *packet = ofp_packet_to_string(pin.packet, pin.packet_len); |
064af421 BP |
143 | ds_put_cstr(string, packet); |
144 | free(packet); | |
145 | } | |
b4ccee75 SH |
146 | if (verbosity > 2) { |
147 | ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false); | |
148 | } | |
064af421 BP |
149 | } |
150 | ||
d1e2cf21 | 151 | static void |
982697a4 | 152 | ofp_print_packet_out(struct ds *string, const struct ofp_header *oh, |
d1e2cf21 | 153 | int verbosity) |
064af421 | 154 | { |
c6a93eb7 | 155 | struct ofputil_packet_out po; |
f25d0cf3 | 156 | struct ofpbuf ofpacts; |
c6a93eb7 | 157 | enum ofperr error; |
064af421 | 158 | |
f25d0cf3 | 159 | ofpbuf_init(&ofpacts, 64); |
982697a4 | 160 | error = ofputil_decode_packet_out(&po, oh, &ofpacts); |
c6a93eb7 | 161 | if (error) { |
f25d0cf3 | 162 | ofpbuf_uninit(&ofpacts); |
c6a93eb7 | 163 | ofp_print_error(string, error); |
064af421 BP |
164 | return; |
165 | } | |
c6a93eb7 BP |
166 | |
167 | ds_put_cstr(string, " in_port="); | |
168 | ofputil_format_port(po.in_port, string); | |
169 | ||
455ecd77 | 170 | ds_put_cstr(string, " actions="); |
f25d0cf3 | 171 | ofpacts_format(po.ofpacts, po.ofpacts_len, string); |
c6a93eb7 BP |
172 | |
173 | if (po.buffer_id == UINT32_MAX) { | |
34582733 | 174 | ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len); |
c6a93eb7 BP |
175 | if (verbosity > 0 && po.packet_len > 0) { |
176 | char *packet = ofp_packet_to_string(po.packet, po.packet_len); | |
064af421 BP |
177 | ds_put_char(string, '\n'); |
178 | ds_put_cstr(string, packet); | |
179 | free(packet); | |
180 | } | |
b4ccee75 SH |
181 | if (verbosity > 2) { |
182 | ds_put_hex_dump(string, po.packet, po.packet_len, 0, false); | |
183 | } | |
064af421 | 184 | } else { |
c6a93eb7 | 185 | ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id); |
064af421 | 186 | } |
f25d0cf3 BP |
187 | |
188 | ofpbuf_uninit(&ofpacts); | |
064af421 BP |
189 | } |
190 | ||
191 | /* qsort comparison function. */ | |
192 | static int | |
193 | compare_ports(const void *a_, const void *b_) | |
194 | { | |
9e1fd49b BP |
195 | const struct ofputil_phy_port *a = a_; |
196 | const struct ofputil_phy_port *b = b_; | |
4e022ec0 AW |
197 | uint16_t ap = ofp_to_u16(a->port_no); |
198 | uint16_t bp = ofp_to_u16(b->port_no); | |
064af421 BP |
199 | |
200 | return ap < bp ? -1 : ap > bp; | |
201 | } | |
202 | ||
0ab14c8e BP |
203 | static void |
204 | ofp_print_bit_names(struct ds *string, uint32_t bits, | |
e8fa940e BP |
205 | const char *(*bit_to_name)(uint32_t bit), |
206 | char separator) | |
064af421 | 207 | { |
0ab14c8e | 208 | int n = 0; |
9e1fd49b | 209 | int i; |
0ab14c8e BP |
210 | |
211 | if (!bits) { | |
212 | ds_put_cstr(string, "0"); | |
064af421 BP |
213 | return; |
214 | } | |
0ab14c8e | 215 | |
9e1fd49b BP |
216 | for (i = 0; i < 32; i++) { |
217 | uint32_t bit = UINT32_C(1) << i; | |
218 | ||
219 | if (bits & bit) { | |
220 | const char *name = bit_to_name(bit); | |
221 | if (name) { | |
222 | if (n++) { | |
e8fa940e | 223 | ds_put_char(string, separator); |
9e1fd49b BP |
224 | } |
225 | ds_put_cstr(string, name); | |
226 | bits &= ~bit; | |
0ab14c8e | 227 | } |
0ab14c8e | 228 | } |
064af421 | 229 | } |
0ab14c8e BP |
230 | |
231 | if (bits) { | |
f5cd6874 | 232 | if (n) { |
e8fa940e | 233 | ds_put_char(string, separator); |
0ab14c8e BP |
234 | } |
235 | ds_put_format(string, "0x%"PRIx32, bits); | |
064af421 | 236 | } |
0ab14c8e BP |
237 | } |
238 | ||
9e1fd49b BP |
239 | static const char * |
240 | netdev_feature_to_name(uint32_t bit) | |
241 | { | |
242 | enum netdev_features f = bit; | |
243 | ||
244 | switch (f) { | |
245 | case NETDEV_F_10MB_HD: return "10MB-HD"; | |
246 | case NETDEV_F_10MB_FD: return "10MB-FD"; | |
247 | case NETDEV_F_100MB_HD: return "100MB-HD"; | |
248 | case NETDEV_F_100MB_FD: return "100MB-FD"; | |
249 | case NETDEV_F_1GB_HD: return "1GB-HD"; | |
250 | case NETDEV_F_1GB_FD: return "1GB-FD"; | |
251 | case NETDEV_F_10GB_FD: return "10GB-FD"; | |
252 | case NETDEV_F_40GB_FD: return "40GB-FD"; | |
253 | case NETDEV_F_100GB_FD: return "100GB-FD"; | |
254 | case NETDEV_F_1TB_FD: return "1TB-FD"; | |
255 | case NETDEV_F_OTHER: return "OTHER"; | |
256 | case NETDEV_F_COPPER: return "COPPER"; | |
257 | case NETDEV_F_FIBER: return "FIBER"; | |
258 | case NETDEV_F_AUTONEG: return "AUTO_NEG"; | |
259 | case NETDEV_F_PAUSE: return "AUTO_PAUSE"; | |
260 | case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM"; | |
261 | } | |
262 | ||
263 | return NULL; | |
264 | } | |
265 | ||
0ab14c8e | 266 | static void |
9e1fd49b | 267 | ofp_print_port_features(struct ds *string, enum netdev_features features) |
0ab14c8e | 268 | { |
e8fa940e | 269 | ofp_print_bit_names(string, features, netdev_feature_to_name, ' '); |
0ab14c8e BP |
270 | ds_put_char(string, '\n'); |
271 | } | |
272 | ||
9e1fd49b BP |
273 | static const char * |
274 | ofputil_port_config_to_name(uint32_t bit) | |
275 | { | |
276 | enum ofputil_port_config pc = bit; | |
277 | ||
278 | switch (pc) { | |
279 | case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN"; | |
280 | case OFPUTIL_PC_NO_STP: return "NO_STP"; | |
281 | case OFPUTIL_PC_NO_RECV: return "NO_RECV"; | |
282 | case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP"; | |
283 | case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD"; | |
284 | case OFPUTIL_PC_NO_FWD: return "NO_FWD"; | |
285 | case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN"; | |
286 | } | |
287 | ||
288 | return NULL; | |
289 | } | |
290 | ||
0ab14c8e | 291 | static void |
9e1fd49b | 292 | ofp_print_port_config(struct ds *string, enum ofputil_port_config config) |
0ab14c8e | 293 | { |
e8fa940e | 294 | ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' '); |
0ab14c8e BP |
295 | ds_put_char(string, '\n'); |
296 | } | |
297 | ||
9e1fd49b BP |
298 | static const char * |
299 | ofputil_port_state_to_name(uint32_t bit) | |
300 | { | |
301 | enum ofputil_port_state ps = bit; | |
302 | ||
303 | switch (ps) { | |
304 | case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN"; | |
305 | case OFPUTIL_PS_BLOCKED: return "BLOCKED"; | |
306 | case OFPUTIL_PS_LIVE: return "LIVE"; | |
307 | ||
308 | case OFPUTIL_PS_STP_LISTEN: | |
309 | case OFPUTIL_PS_STP_LEARN: | |
310 | case OFPUTIL_PS_STP_FORWARD: | |
311 | case OFPUTIL_PS_STP_BLOCK: | |
312 | /* Handled elsewhere. */ | |
313 | return NULL; | |
314 | } | |
315 | ||
316 | return NULL; | |
317 | } | |
318 | ||
0ab14c8e | 319 | static void |
9e1fd49b | 320 | ofp_print_port_state(struct ds *string, enum ofputil_port_state state) |
0ab14c8e | 321 | { |
9e1fd49b | 322 | enum ofputil_port_state stp_state; |
0ab14c8e BP |
323 | |
324 | /* The STP state is a 2-bit field so it doesn't fit in with the bitmask | |
325 | * pattern. We have to special case it. | |
326 | * | |
327 | * OVS doesn't support STP, so this field will always be 0 if we are | |
328 | * talking to OVS, so we'd always print STP_LISTEN in that case. | |
329 | * Therefore, we don't print anything at all if the value is STP_LISTEN, to | |
330 | * avoid confusing users. */ | |
9e1fd49b | 331 | stp_state = state & OFPUTIL_PS_STP_MASK; |
0ab14c8e | 332 | if (stp_state) { |
9e1fd49b BP |
333 | ds_put_cstr(string, |
334 | (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN" | |
335 | : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD" | |
336 | : "STP_BLOCK")); | |
337 | state &= ~OFPUTIL_PS_STP_MASK; | |
0ab14c8e | 338 | if (state) { |
e8fa940e BP |
339 | ofp_print_bit_names(string, state, ofputil_port_state_to_name, |
340 | ' '); | |
0ab14c8e BP |
341 | } |
342 | } else { | |
e8fa940e | 343 | ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' '); |
064af421 BP |
344 | } |
345 | ds_put_char(string, '\n'); | |
346 | } | |
347 | ||
348 | static void | |
9e1fd49b | 349 | ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port) |
064af421 | 350 | { |
9e1fd49b | 351 | char name[sizeof port->name]; |
064af421 BP |
352 | int j; |
353 | ||
354 | memcpy(name, port->name, sizeof name); | |
355 | for (j = 0; j < sizeof name - 1; j++) { | |
858f2852 | 356 | if (!isprint((unsigned char) name[j])) { |
064af421 BP |
357 | break; |
358 | } | |
359 | } | |
360 | name[j] = '\0'; | |
361 | ||
362 | ds_put_char(string, ' '); | |
9e1fd49b | 363 | ofputil_format_port(port->port_no, string); |
0ab14c8e BP |
364 | ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n", |
365 | name, ETH_ADDR_ARGS(port->hw_addr)); | |
366 | ||
367 | ds_put_cstr(string, " config: "); | |
9e1fd49b | 368 | ofp_print_port_config(string, port->config); |
0ab14c8e BP |
369 | |
370 | ds_put_cstr(string, " state: "); | |
9e1fd49b | 371 | ofp_print_port_state(string, port->state); |
0ab14c8e | 372 | |
064af421 BP |
373 | if (port->curr) { |
374 | ds_put_format(string, " current: "); | |
9e1fd49b | 375 | ofp_print_port_features(string, port->curr); |
064af421 BP |
376 | } |
377 | if (port->advertised) { | |
378 | ds_put_format(string, " advertised: "); | |
9e1fd49b | 379 | ofp_print_port_features(string, port->advertised); |
064af421 BP |
380 | } |
381 | if (port->supported) { | |
382 | ds_put_format(string, " supported: "); | |
9e1fd49b | 383 | ofp_print_port_features(string, port->supported); |
064af421 BP |
384 | } |
385 | if (port->peer) { | |
386 | ds_put_format(string, " peer: "); | |
9e1fd49b BP |
387 | ofp_print_port_features(string, port->peer); |
388 | } | |
389 | ds_put_format(string, " speed: %"PRIu32" Mbps now, " | |
390 | "%"PRIu32" Mbps max\n", | |
391 | port->curr_speed / UINT32_C(1000), | |
392 | port->max_speed / UINT32_C(1000)); | |
393 | } | |
394 | ||
2be393ed JP |
395 | /* Given a buffer 'b' that contains an array of OpenFlow ports of type |
396 | * 'ofp_version', writes a detailed description of each port into | |
397 | * 'string'. */ | |
398 | static void | |
399 | ofp_print_phy_ports(struct ds *string, uint8_t ofp_version, | |
400 | struct ofpbuf *b) | |
401 | { | |
2be393ed | 402 | struct ofputil_phy_port *ports; |
9b77a336 BP |
403 | size_t allocated_ports, n_ports; |
404 | int retval; | |
2be393ed JP |
405 | size_t i; |
406 | ||
9b77a336 BP |
407 | ports = NULL; |
408 | allocated_ports = 0; | |
409 | for (n_ports = 0; ; n_ports++) { | |
410 | if (n_ports >= allocated_ports) { | |
411 | ports = x2nrealloc(ports, &allocated_ports, sizeof *ports); | |
412 | } | |
2be393ed | 413 | |
9b77a336 BP |
414 | retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]); |
415 | if (retval) { | |
416 | break; | |
2be393ed JP |
417 | } |
418 | } | |
9b77a336 | 419 | |
2be393ed JP |
420 | qsort(ports, n_ports, sizeof *ports, compare_ports); |
421 | for (i = 0; i < n_ports; i++) { | |
422 | ofp_print_phy_port(string, &ports[i]); | |
423 | } | |
2be393ed | 424 | free(ports); |
9b77a336 BP |
425 | |
426 | if (retval != EOF) { | |
427 | ofp_print_error(string, retval); | |
428 | } | |
2be393ed JP |
429 | } |
430 | ||
9e1fd49b BP |
431 | static const char * |
432 | ofputil_capabilities_to_name(uint32_t bit) | |
433 | { | |
434 | enum ofputil_capabilities capabilities = bit; | |
435 | ||
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"; | |
60202987 | 445 | case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED"; |
9e1fd49b BP |
446 | } |
447 | ||
448 | return NULL; | |
449 | } | |
450 | ||
064af421 | 451 | static void |
982697a4 | 452 | ofp_print_switch_features(struct ds *string, const struct ofp_header *oh) |
064af421 | 453 | { |
9e1fd49b | 454 | struct ofputil_switch_features features; |
9e1fd49b BP |
455 | enum ofperr error; |
456 | struct ofpbuf b; | |
064af421 | 457 | |
982697a4 | 458 | error = ofputil_decode_switch_features(oh, &features, &b); |
9e1fd49b BP |
459 | if (error) { |
460 | ofp_print_error(string, error); | |
461 | return; | |
462 | } | |
064af421 | 463 | |
9e1fd49b | 464 | ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id); |
2e1ae200 JR |
465 | |
466 | ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32, | |
9e1fd49b | 467 | features.n_tables, features.n_buffers); |
2e1ae200 JR |
468 | if (features.auxiliary_id) { |
469 | ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id); | |
470 | } | |
471 | ds_put_char(string, '\n'); | |
064af421 | 472 | |
9e1fd49b BP |
473 | ds_put_cstr(string, "capabilities: "); |
474 | ofp_print_bit_names(string, features.capabilities, | |
e8fa940e | 475 | ofputil_capabilities_to_name, ' '); |
9e1fd49b BP |
476 | ds_put_char(string, '\n'); |
477 | ||
210d8d9c SH |
478 | switch ((enum ofp_version)oh->version) { |
479 | case OFP10_VERSION: | |
480 | ds_put_cstr(string, "actions: "); | |
08d1e234 | 481 | ofpact_bitmap_format(features.ofpacts, string); |
210d8d9c SH |
482 | ds_put_char(string, '\n'); |
483 | break; | |
484 | case OFP11_VERSION: | |
485 | case OFP12_VERSION: | |
486 | break; | |
2e1ae200 | 487 | case OFP13_VERSION: |
c37c0382 | 488 | case OFP14_VERSION: |
42dccab5 | 489 | case OFP15_VERSION: |
2e1ae200 | 490 | return; /* no ports in ofp13_switch_features */ |
210d8d9c | 491 | default: |
428b2edd | 492 | OVS_NOT_REACHED(); |
210d8d9c | 493 | } |
9e1fd49b | 494 | |
982697a4 | 495 | ofp_print_phy_ports(string, oh->version, &b); |
064af421 BP |
496 | } |
497 | ||
064af421 | 498 | static void |
d1e2cf21 | 499 | ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc) |
064af421 | 500 | { |
f0fd1a17 | 501 | enum ofp_config_flags flags; |
064af421 BP |
502 | |
503 | flags = ntohs(osc->flags); | |
3b62feba | 504 | |
7257b535 BP |
505 | ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags)); |
506 | flags &= ~OFPC_FRAG_MASK; | |
507 | ||
f0fd1a17 PS |
508 | if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) { |
509 | ds_put_format(string, " invalid_ttl_to_controller"); | |
510 | flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER; | |
511 | } | |
512 | ||
064af421 BP |
513 | if (flags) { |
514 | ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags); | |
515 | } | |
516 | ||
517 | ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len)); | |
518 | } | |
519 | ||
520 | static void print_wild(struct ds *string, const char *leader, int is_wild, | |
d295e8e9 | 521 | int verbosity, const char *format, ...) |
cab50449 | 522 | OVS_PRINTF_FORMAT(5, 6); |
064af421 BP |
523 | |
524 | static void print_wild(struct ds *string, const char *leader, int is_wild, | |
d295e8e9 | 525 | int verbosity, const char *format, ...) |
064af421 BP |
526 | { |
527 | if (is_wild && verbosity < 2) { | |
528 | return; | |
529 | } | |
530 | ds_put_cstr(string, leader); | |
531 | if (!is_wild) { | |
532 | va_list args; | |
533 | ||
534 | va_start(args, format); | |
535 | ds_put_format_valist(string, format, args); | |
536 | va_end(args); | |
537 | } else { | |
538 | ds_put_char(string, '*'); | |
539 | } | |
540 | ds_put_char(string, ','); | |
541 | } | |
542 | ||
e1db42d6 JR |
543 | static void |
544 | print_wild_port(struct ds *string, const char *leader, int is_wild, | |
4e022ec0 | 545 | int verbosity, ofp_port_t port) |
e1db42d6 JR |
546 | { |
547 | if (is_wild && verbosity < 2) { | |
548 | return; | |
549 | } | |
550 | ds_put_cstr(string, leader); | |
551 | if (!is_wild) { | |
552 | ofputil_format_port(port, string); | |
553 | } else { | |
554 | ds_put_char(string, '*'); | |
555 | } | |
556 | ds_put_char(string, ','); | |
557 | } | |
558 | ||
064af421 | 559 | static void |
dbba996b | 560 | print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip, |
064af421 BP |
561 | uint32_t wild_bits, int verbosity) |
562 | { | |
563 | if (wild_bits >= 32 && verbosity < 2) { | |
564 | return; | |
565 | } | |
566 | ds_put_cstr(string, leader); | |
567 | if (wild_bits < 32) { | |
ed36537e | 568 | ds_put_format(string, IP_FMT, IP_ARGS(ip)); |
064af421 BP |
569 | if (wild_bits) { |
570 | ds_put_format(string, "/%d", 32 - wild_bits); | |
571 | } | |
572 | } else { | |
573 | ds_put_char(string, '*'); | |
574 | } | |
575 | ds_put_char(string, ','); | |
576 | } | |
577 | ||
4f2cad2c | 578 | void |
eec25dc1 | 579 | ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity) |
064af421 | 580 | { |
eec25dc1 | 581 | char *s = ofp10_match_to_string(om, verbosity); |
064af421 BP |
582 | ds_put_cstr(f, s); |
583 | free(s); | |
584 | } | |
585 | ||
586 | char * | |
eec25dc1 | 587 | ofp10_match_to_string(const struct ofp10_match *om, int verbosity) |
064af421 BP |
588 | { |
589 | struct ds f = DS_EMPTY_INITIALIZER; | |
590 | uint32_t w = ntohl(om->wildcards); | |
591 | bool skip_type = false; | |
592 | bool skip_proto = false; | |
593 | ||
eec25dc1 | 594 | if (!(w & OFPFW10_DL_TYPE)) { |
064af421 BP |
595 | skip_type = true; |
596 | if (om->dl_type == htons(ETH_TYPE_IP)) { | |
eec25dc1 | 597 | if (!(w & OFPFW10_NW_PROTO)) { |
064af421 | 598 | skip_proto = true; |
6767a2cc | 599 | if (om->nw_proto == IPPROTO_ICMP) { |
064af421 | 600 | ds_put_cstr(&f, "icmp,"); |
6767a2cc | 601 | } else if (om->nw_proto == IPPROTO_TCP) { |
064af421 | 602 | ds_put_cstr(&f, "tcp,"); |
6767a2cc | 603 | } else if (om->nw_proto == IPPROTO_UDP) { |
064af421 | 604 | ds_put_cstr(&f, "udp,"); |
0d56eaf2 JS |
605 | } else if (om->nw_proto == IPPROTO_SCTP) { |
606 | ds_put_cstr(&f, "sctp,"); | |
064af421 BP |
607 | } else { |
608 | ds_put_cstr(&f, "ip,"); | |
609 | skip_proto = false; | |
610 | } | |
611 | } else { | |
612 | ds_put_cstr(&f, "ip,"); | |
613 | } | |
614 | } else if (om->dl_type == htons(ETH_TYPE_ARP)) { | |
615 | ds_put_cstr(&f, "arp,"); | |
8087f5ff MM |
616 | } else if (om->dl_type == htons(ETH_TYPE_RARP)){ |
617 | ds_put_cstr(&f, "rarp,"); | |
b02475c5 SH |
618 | } else if (om->dl_type == htons(ETH_TYPE_MPLS)) { |
619 | ds_put_cstr(&f, "mpls,"); | |
620 | } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) { | |
621 | ds_put_cstr(&f, "mplsm,"); | |
064af421 BP |
622 | } else { |
623 | skip_type = false; | |
624 | } | |
625 | } | |
e1db42d6 | 626 | print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity, |
4e022ec0 | 627 | u16_to_ofp(ntohs(om->in_port))); |
eec25dc1 | 628 | print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity, |
6a1f89c8 | 629 | "%d", ntohs(om->dl_vlan)); |
eec25dc1 | 630 | print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity, |
959a2ecd | 631 | "%d", om->dl_vlan_pcp); |
eec25dc1 | 632 | print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity, |
064af421 | 633 | ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src)); |
eec25dc1 | 634 | print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity, |
064af421 BP |
635 | ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst)); |
636 | if (!skip_type) { | |
eec25dc1 | 637 | print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity, |
064af421 BP |
638 | "0x%04x", ntohs(om->dl_type)); |
639 | } | |
640 | print_ip_netmask(&f, "nw_src=", om->nw_src, | |
eec25dc1 BP |
641 | (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT, |
642 | verbosity); | |
064af421 | 643 | print_ip_netmask(&f, "nw_dst=", om->nw_dst, |
eec25dc1 BP |
644 | (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT, |
645 | verbosity); | |
064af421 | 646 | if (!skip_proto) { |
8087f5ff MM |
647 | if (om->dl_type == htons(ETH_TYPE_ARP) || |
648 | om->dl_type == htons(ETH_TYPE_RARP)) { | |
eec25dc1 | 649 | print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity, |
fb892732 JP |
650 | "%u", om->nw_proto); |
651 | } else { | |
eec25dc1 | 652 | print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity, |
fb892732 JP |
653 | "%u", om->nw_proto); |
654 | } | |
064af421 | 655 | } |
eec25dc1 | 656 | print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity, |
1a960c80 | 657 | "%u", om->nw_tos); |
6767a2cc | 658 | if (om->nw_proto == IPPROTO_ICMP) { |
eec25dc1 | 659 | print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity, |
3ee8a9f0 | 660 | "%d", ntohs(om->tp_src)); |
eec25dc1 | 661 | print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity, |
3ee8a9f0 | 662 | "%d", ntohs(om->tp_dst)); |
064af421 | 663 | } else { |
eec25dc1 | 664 | print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity, |
064af421 | 665 | "%d", ntohs(om->tp_src)); |
eec25dc1 | 666 | print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity, |
064af421 BP |
667 | "%d", ntohs(om->tp_dst)); |
668 | } | |
dbf9e6d9 | 669 | ds_chomp(&f, ','); |
064af421 BP |
670 | return ds_cstr(&f); |
671 | } | |
672 | ||
2e1ae200 | 673 | static void |
0fb88c18 | 674 | ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags) |
2e1ae200 | 675 | { |
0fb88c18 | 676 | if (flags & OFPUTIL_FF_SEND_FLOW_REM) { |
2e1ae200 JR |
677 | ds_put_cstr(s, "send_flow_rem "); |
678 | } | |
0fb88c18 | 679 | if (flags & OFPUTIL_FF_CHECK_OVERLAP) { |
2e1ae200 JR |
680 | ds_put_cstr(s, "check_overlap "); |
681 | } | |
0fb88c18 | 682 | if (flags & OFPUTIL_FF_RESET_COUNTS) { |
2e1ae200 JR |
683 | ds_put_cstr(s, "reset_counts "); |
684 | } | |
0fb88c18 | 685 | if (flags & OFPUTIL_FF_NO_PKT_COUNTS) { |
2e1ae200 JR |
686 | ds_put_cstr(s, "no_packet_counts "); |
687 | } | |
0fb88c18 | 688 | if (flags & OFPUTIL_FF_NO_BYT_COUNTS) { |
2e1ae200 JR |
689 | ds_put_cstr(s, "no_byte_counts "); |
690 | } | |
adcf00ba AZ |
691 | if (flags & OFPUTIL_FF_HIDDEN_FIELDS) { |
692 | ds_put_cstr(s, "allow_hidden_fields "); | |
693 | } | |
694 | if (flags & OFPUTIL_FF_NO_READONLY) { | |
695 | ds_put_cstr(s, "no_readonly_table "); | |
696 | } | |
2e1ae200 JR |
697 | } |
698 | ||
064af421 | 699 | static void |
982697a4 | 700 | ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity) |
064af421 | 701 | { |
a9a2da38 | 702 | struct ofputil_flow_mod fm; |
f25d0cf3 | 703 | struct ofpbuf ofpacts; |
f904747b | 704 | bool need_priority; |
90bf1e07 | 705 | enum ofperr error; |
982697a4 | 706 | enum ofpraw raw; |
981c5fdd SH |
707 | enum ofputil_protocol protocol; |
708 | ||
709 | protocol = ofputil_protocol_from_ofp_version(oh->version); | |
710 | protocol = ofputil_protocol_set_tid(protocol, true); | |
064af421 | 711 | |
f25d0cf3 | 712 | ofpbuf_init(&ofpacts, 64); |
7e9f8266 BP |
713 | error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts, |
714 | OFPP_MAX, 255); | |
7fa91113 | 715 | if (error) { |
f25d0cf3 | 716 | ofpbuf_uninit(&ofpacts); |
7fa91113 BP |
717 | ofp_print_error(s, error); |
718 | return; | |
3ff4f871 BP |
719 | } |
720 | ||
7fa91113 BP |
721 | ds_put_char(s, ' '); |
722 | switch (fm.command) { | |
064af421 | 723 | case OFPFC_ADD: |
7fa91113 | 724 | ds_put_cstr(s, "ADD"); |
064af421 BP |
725 | break; |
726 | case OFPFC_MODIFY: | |
7fa91113 | 727 | ds_put_cstr(s, "MOD"); |
064af421 BP |
728 | break; |
729 | case OFPFC_MODIFY_STRICT: | |
7fa91113 | 730 | ds_put_cstr(s, "MOD_STRICT"); |
064af421 BP |
731 | break; |
732 | case OFPFC_DELETE: | |
7fa91113 | 733 | ds_put_cstr(s, "DEL"); |
064af421 BP |
734 | break; |
735 | case OFPFC_DELETE_STRICT: | |
7fa91113 | 736 | ds_put_cstr(s, "DEL_STRICT"); |
064af421 BP |
737 | break; |
738 | default: | |
7fa91113 BP |
739 | ds_put_format(s, "cmd:%d", fm.command); |
740 | } | |
6c1491fb | 741 | if (fm.table_id != 0) { |
e896c2d4 | 742 | ds_put_format(s, " table:%d", fm.table_id); |
6c1491fb | 743 | } |
7fa91113 BP |
744 | |
745 | ds_put_char(s, ' '); | |
982697a4 BP |
746 | ofpraw_decode(&raw, oh); |
747 | if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) { | |
35805806 | 748 | const struct ofp10_flow_mod *ofm = ofpmsg_body(oh); |
eec25dc1 | 749 | ofp10_match_print(s, &ofm->match, verbosity); |
f904747b BP |
750 | |
751 | /* ofp_print_match() doesn't print priority. */ | |
752 | need_priority = true; | |
982697a4 BP |
753 | } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) { |
754 | const struct nx_flow_mod *nfm = ofpmsg_body(oh); | |
7fa91113 | 755 | const void *nxm = nfm + 1; |
f904747b BP |
756 | char *nxm_s; |
757 | ||
758 | nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len)); | |
7fa91113 BP |
759 | ds_put_cstr(s, nxm_s); |
760 | free(nxm_s); | |
f904747b BP |
761 | |
762 | /* nx_match_to_string() doesn't print priority. */ | |
763 | need_priority = true; | |
7fa91113 | 764 | } else { |
81a76618 | 765 | match_format(&fm.match, s, fm.priority); |
f904747b | 766 | |
81a76618 | 767 | /* match_format() does print priority. */ |
f904747b | 768 | need_priority = false; |
3ff4f871 | 769 | } |
7fa91113 BP |
770 | |
771 | if (ds_last(s) != ' ') { | |
772 | ds_put_char(s, ' '); | |
3ff4f871 | 773 | } |
b8266395 | 774 | if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) { |
623e1caf JP |
775 | ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie)); |
776 | } | |
777 | if (fm.cookie_mask != htonll(0)) { | |
778 | ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ", | |
779 | ntohll(fm.cookie), ntohll(fm.cookie_mask)); | |
3ff4f871 | 780 | } |
7fa91113 BP |
781 | if (fm.idle_timeout != OFP_FLOW_PERMANENT) { |
782 | ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout); | |
064af421 | 783 | } |
7fa91113 BP |
784 | if (fm.hard_timeout != OFP_FLOW_PERMANENT) { |
785 | ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout); | |
3ff4f871 | 786 | } |
ca26eb44 RB |
787 | if (fm.importance != 0) { |
788 | ds_put_format(s, "importance:%"PRIu16" ", fm.importance); | |
789 | } | |
81a76618 BP |
790 | if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) { |
791 | ds_put_format(s, "pri:%"PRIu16" ", fm.priority); | |
3ff4f871 | 792 | } |
7fa91113 BP |
793 | if (fm.buffer_id != UINT32_MAX) { |
794 | ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id); | |
3ff4f871 | 795 | } |
7f05e7ab | 796 | if (fm.out_port != OFPP_ANY) { |
de0f16bc BP |
797 | ds_put_format(s, "out_port:"); |
798 | ofputil_format_port(fm.out_port, s); | |
799 | ds_put_char(s, ' '); | |
800 | } | |
0fb88c18 BP |
801 | |
802 | if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) { | |
803 | /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those | |
804 | * versions don't really have such a flag and printing one is likely to | |
805 | * confuse people. */ | |
806 | fm.flags &= ~OFPUTIL_FF_RESET_COUNTS; | |
7fa91113 | 807 | } |
0fb88c18 | 808 | ofp_print_flow_flags(s, fm.flags); |
7fa91113 | 809 | |
455ecd77 | 810 | ds_put_cstr(s, "actions="); |
f25d0cf3 BP |
811 | ofpacts_format(fm.ofpacts, fm.ofpacts_len, s); |
812 | ofpbuf_uninit(&ofpacts); | |
064af421 BP |
813 | } |
814 | ||
09862ec6 BP |
815 | static void |
816 | ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec) | |
817 | { | |
818 | ds_put_format(string, "%u", sec); | |
b1634591 BP |
819 | |
820 | /* If there are no fractional seconds, don't print any decimals. | |
821 | * | |
822 | * If the fractional seconds can be expressed exactly as milliseconds, | |
823 | * print 3 decimals. Open vSwitch provides millisecond precision for most | |
824 | * time measurements, so printing 3 decimals every time makes it easier to | |
825 | * spot real changes in flow dumps that refresh themselves quickly. | |
826 | * | |
827 | * If the fractional seconds are more precise than milliseconds, print the | |
828 | * number of decimals needed to express them exactly. | |
829 | */ | |
09862ec6 | 830 | if (nsec > 0) { |
b1634591 BP |
831 | unsigned int msec = nsec / 1000000; |
832 | if (msec * 1000000 == nsec) { | |
833 | ds_put_format(string, ".%03u", msec); | |
834 | } else { | |
835 | ds_put_format(string, ".%09u", nsec); | |
836 | while (string->string[string->length - 1] == '0') { | |
837 | string->length--; | |
838 | } | |
09862ec6 BP |
839 | } |
840 | } | |
841 | ds_put_char(string, 's'); | |
842 | } | |
843 | ||
8961699e BP |
844 | /* Returns a string form of 'reason'. The return value is either a statically |
845 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
846 | * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */ | |
847 | #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1) | |
80d5aefd | 848 | static const char * |
8961699e BP |
849 | ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason, |
850 | char *reasonbuf, size_t bufsize) | |
80d5aefd | 851 | { |
80d5aefd BP |
852 | switch (reason) { |
853 | case OFPRR_IDLE_TIMEOUT: | |
854 | return "idle"; | |
855 | case OFPRR_HARD_TIMEOUT: | |
856 | return "hard"; | |
857 | case OFPRR_DELETE: | |
858 | return "delete"; | |
04f68eb2 SH |
859 | case OFPRR_GROUP_DELETE: |
860 | return "group_delete"; | |
1d31ece9 BP |
861 | case OFPRR_EVICTION: |
862 | return "eviction"; | |
638a19b0 JR |
863 | case OFPRR_METER_DELETE: |
864 | return "meter_delete"; | |
f695ebfa | 865 | case OVS_OFPRR_NONE: |
80d5aefd | 866 | default: |
8961699e BP |
867 | snprintf(reasonbuf, bufsize, "%d", (int) reason); |
868 | return reasonbuf; | |
80d5aefd BP |
869 | } |
870 | } | |
871 | ||
064af421 | 872 | static void |
9b045a0c | 873 | ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh) |
064af421 | 874 | { |
8961699e | 875 | char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE]; |
9b045a0c | 876 | struct ofputil_flow_removed fr; |
90bf1e07 | 877 | enum ofperr error; |
9b045a0c | 878 | |
b78f6b77 | 879 | error = ofputil_decode_flow_removed(&fr, oh); |
9b045a0c BP |
880 | if (error) { |
881 | ofp_print_error(string, error); | |
882 | return; | |
883 | } | |
884 | ||
fbd76b2e | 885 | ds_put_char(string, ' '); |
81a76618 | 886 | match_format(&fr.match, string, fr.priority); |
9b045a0c | 887 | |
80d5aefd | 888 | ds_put_format(string, " reason=%s", |
8961699e BP |
889 | ofp_flow_removed_reason_to_string(fr.reason, reasonbuf, |
890 | sizeof reasonbuf)); | |
3ff4f871 | 891 | |
95216219 SH |
892 | if (fr.table_id != 255) { |
893 | ds_put_format(string, " table_id=%"PRIu8, fr.table_id); | |
894 | } | |
895 | ||
9b045a0c BP |
896 | if (fr.cookie != htonll(0)) { |
897 | ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie)); | |
3ff4f871 | 898 | } |
09862ec6 | 899 | ds_put_cstr(string, " duration"); |
9b045a0c | 900 | ofp_print_duration(string, fr.duration_sec, fr.duration_nsec); |
fa2bad0f BP |
901 | ds_put_format(string, " idle%"PRIu16, fr.idle_timeout); |
902 | if (fr.hard_timeout) { | |
903 | /* The hard timeout was only added in OF1.2, so only print it if it is | |
904 | * actually in use to avoid gratuitous change to the formatting. */ | |
905 | ds_put_format(string, " hard%"PRIu16, fr.hard_timeout); | |
906 | } | |
907 | ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n", | |
908 | fr.packet_count, fr.byte_count); | |
064af421 BP |
909 | } |
910 | ||
911 | static void | |
9e1fd49b | 912 | ofp_print_port_mod(struct ds *string, const struct ofp_header *oh) |
064af421 | 913 | { |
9e1fd49b BP |
914 | struct ofputil_port_mod pm; |
915 | enum ofperr error; | |
916 | ||
18cc69d9 | 917 | error = ofputil_decode_port_mod(oh, &pm, true); |
9e1fd49b BP |
918 | if (error) { |
919 | ofp_print_error(string, error); | |
920 | return; | |
921 | } | |
922 | ||
e1db42d6 JR |
923 | ds_put_cstr(string, "port: "); |
924 | ofputil_format_port(pm.port_no, string); | |
925 | ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n", | |
926 | ETH_ADDR_ARGS(pm.hw_addr)); | |
9e1fd49b | 927 | |
e1db42d6 | 928 | ds_put_cstr(string, " config: "); |
9e1fd49b BP |
929 | ofp_print_port_config(string, pm.config); |
930 | ||
e1db42d6 | 931 | ds_put_cstr(string, " mask: "); |
9e1fd49b BP |
932 | ofp_print_port_config(string, pm.mask); |
933 | ||
e1db42d6 | 934 | ds_put_cstr(string, " advertise: "); |
9e1fd49b BP |
935 | if (pm.advertise) { |
936 | ofp_print_port_features(string, pm.advertise); | |
064af421 | 937 | } else { |
e1db42d6 | 938 | ds_put_cstr(string, "UNCHANGED\n"); |
064af421 BP |
939 | } |
940 | } | |
941 | ||
82c22d34 BP |
942 | static const char * |
943 | ofputil_table_miss_to_string(enum ofputil_table_miss miss) | |
918f2b82 | 944 | { |
3c1bb396 | 945 | switch (miss) { |
82c22d34 BP |
946 | case OFPUTIL_TABLE_MISS_DEFAULT: return "default"; |
947 | case OFPUTIL_TABLE_MISS_CONTROLLER: return "controller"; | |
948 | case OFPUTIL_TABLE_MISS_CONTINUE: return "continue"; | |
949 | case OFPUTIL_TABLE_MISS_DROP: return "drop"; | |
950 | default: return "***error***"; | |
951 | } | |
952 | } | |
953 | ||
954 | static const char * | |
955 | ofputil_table_eviction_to_string(enum ofputil_table_eviction eviction) | |
956 | { | |
957 | switch (eviction) { | |
958 | case OFPUTIL_TABLE_EVICTION_DEFAULT: return "default"; | |
959 | case OFPUTIL_TABLE_EVICTION_ON: return "on"; | |
960 | case OFPUTIL_TABLE_EVICTION_OFF: return "off"; | |
961 | default: return "***error***"; | |
962 | } | |
963 | ||
964 | } | |
965 | ||
966 | static const char * | |
967 | ofputil_eviction_flag_to_string(uint32_t bit) | |
968 | { | |
969 | enum ofp14_table_mod_prop_eviction_flag eviction_flag = bit; | |
970 | ||
971 | switch (eviction_flag) { | |
972 | case OFPTMPEF14_OTHER: return "OTHER"; | |
973 | case OFPTMPEF14_IMPORTANCE: return "IMPORTANCE"; | |
974 | case OFPTMPEF14_LIFETIME: return "LIFETIME"; | |
975 | } | |
976 | ||
977 | return NULL; | |
978 | } | |
979 | ||
980 | /* Appends to 'string' a description of the bitmap of OFPTMPEF14_* values in | |
981 | * 'eviction_flags'. */ | |
982 | static void | |
983 | ofputil_put_eviction_flags(struct ds *string, uint32_t eviction_flags) | |
984 | { | |
985 | if (eviction_flags != UINT32_MAX) { | |
986 | ofp_print_bit_names(string, eviction_flags, | |
987 | ofputil_eviction_flag_to_string, '|'); | |
988 | } else { | |
989 | ds_put_cstr(string, "(default)"); | |
918f2b82 AZ |
990 | } |
991 | } | |
992 | ||
993 | static void | |
994 | ofp_print_table_mod(struct ds *string, const struct ofp_header *oh) | |
995 | { | |
996 | struct ofputil_table_mod pm; | |
997 | enum ofperr error; | |
998 | ||
999 | error = ofputil_decode_table_mod(oh, &pm); | |
1000 | if (error) { | |
1001 | ofp_print_error(string, error); | |
1002 | return; | |
1003 | } | |
1004 | ||
1005 | if (pm.table_id == 0xff) { | |
1006 | ds_put_cstr(string, " table_id: ALL_TABLES"); | |
1007 | } else { | |
1008 | ds_put_format(string, " table_id=%"PRIu8, pm.table_id); | |
1009 | } | |
1010 | ||
82c22d34 BP |
1011 | if (pm.miss != OFPUTIL_TABLE_MISS_DEFAULT) { |
1012 | ds_put_format(string, ", flow_miss_config=%s", | |
1013 | ofputil_table_miss_to_string(pm.miss)); | |
1014 | } | |
1015 | if (pm.eviction != OFPUTIL_TABLE_EVICTION_DEFAULT) { | |
1016 | ds_put_format(string, ", eviction=%s", | |
1017 | ofputil_table_eviction_to_string(pm.eviction)); | |
1018 | } | |
1019 | if (pm.eviction_flags != UINT32_MAX) { | |
1020 | ds_put_cstr(string, "eviction_flags="); | |
1021 | ofputil_put_eviction_flags(string, pm.eviction_flags); | |
3c1bb396 | 1022 | } |
918f2b82 AZ |
1023 | } |
1024 | ||
03c72922 BP |
1025 | /* This function will print the Table description properties. */ |
1026 | static void | |
1027 | ofp_print_table_desc(struct ds *string, const struct ofputil_table_desc *td) | |
1028 | { | |
1029 | ds_put_format(string, "\n table %"PRIu8, td->table_id); | |
1030 | ds_put_cstr(string, ":\n"); | |
1031 | ds_put_format(string, " eviction=%s eviction_flags=", | |
1032 | ofputil_table_eviction_to_string(td->eviction)); | |
1033 | ofputil_put_eviction_flags(string, td->eviction_flags); | |
1034 | ds_put_char(string, '\n'); | |
1035 | } | |
1036 | ||
e8f9a7bb VG |
1037 | static void |
1038 | ofp_print_queue_get_config_request(struct ds *string, | |
1039 | const struct ofp_header *oh) | |
1040 | { | |
1041 | enum ofperr error; | |
1042 | ofp_port_t port; | |
1043 | ||
1044 | error = ofputil_decode_queue_get_config_request(oh, &port); | |
1045 | if (error) { | |
1046 | ofp_print_error(string, error); | |
1047 | return; | |
1048 | } | |
1049 | ||
1050 | ds_put_cstr(string, " port="); | |
1051 | ofputil_format_port(port, string); | |
1052 | } | |
1053 | ||
1054 | static void | |
1055 | print_queue_rate(struct ds *string, const char *name, unsigned int rate) | |
1056 | { | |
1057 | if (rate <= 1000) { | |
1058 | ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10); | |
1059 | } else if (rate < UINT16_MAX) { | |
1060 | ds_put_format(string, " %s:(disabled)", name); | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | static void | |
1065 | ofp_print_queue_get_config_reply(struct ds *string, | |
1066 | const struct ofp_header *oh) | |
1067 | { | |
1068 | enum ofperr error; | |
1069 | struct ofpbuf b; | |
1070 | ofp_port_t port; | |
1071 | ||
1072 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1073 | error = ofputil_decode_queue_get_config_reply(&b, &port); | |
1074 | if (error) { | |
1075 | ofp_print_error(string, error); | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | ds_put_cstr(string, " port="); | |
1080 | ofputil_format_port(port, string); | |
1081 | ds_put_char(string, '\n'); | |
1082 | ||
1083 | for (;;) { | |
1084 | struct ofputil_queue_config queue; | |
1085 | int retval; | |
1086 | ||
1087 | retval = ofputil_pull_queue_get_config_reply(&b, &queue); | |
1088 | if (retval) { | |
1089 | if (retval != EOF) { | |
1090 | ofp_print_error(string, retval); | |
1091 | } | |
1092 | break; | |
1093 | } | |
1094 | ||
1095 | ds_put_format(string, "queue %"PRIu32":", queue.queue_id); | |
1096 | print_queue_rate(string, "min_rate", queue.min_rate); | |
1097 | print_queue_rate(string, "max_rate", queue.max_rate); | |
1098 | ds_put_char(string, '\n'); | |
1099 | } | |
1100 | } | |
1101 | ||
638a19b0 JR |
1102 | static void |
1103 | ofp_print_meter_flags(struct ds *s, uint16_t flags) | |
1104 | { | |
1105 | if (flags & OFPMF13_KBPS) { | |
1106 | ds_put_cstr(s, "kbps "); | |
1107 | } | |
1108 | if (flags & OFPMF13_PKTPS) { | |
1109 | ds_put_cstr(s, "pktps "); | |
1110 | } | |
1111 | if (flags & OFPMF13_BURST) { | |
1112 | ds_put_cstr(s, "burst "); | |
1113 | } | |
1114 | if (flags & OFPMF13_STATS) { | |
1115 | ds_put_cstr(s, "stats "); | |
1116 | } | |
1117 | ||
1118 | flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS); | |
1119 | if (flags) { | |
1120 | ds_put_format(s, "flags:0x%"PRIx16" ", flags); | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | static void | |
1125 | ofp_print_meter_band(struct ds *s, uint16_t flags, | |
1126 | const struct ofputil_meter_band *mb) | |
1127 | { | |
1128 | ds_put_cstr(s, "\ntype="); | |
1129 | switch (mb->type) { | |
1130 | case OFPMBT13_DROP: | |
1131 | ds_put_cstr(s, "drop"); | |
1132 | break; | |
1133 | case OFPMBT13_DSCP_REMARK: | |
1134 | ds_put_cstr(s, "dscp_remark"); | |
1135 | break; | |
1136 | default: | |
1137 | ds_put_format(s, "%u", mb->type); | |
1138 | } | |
1139 | ||
1140 | ds_put_format(s, " rate=%"PRIu32, mb->rate); | |
1141 | ||
1142 | if (flags & OFPMF13_BURST) { | |
1143 | ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size); | |
1144 | } | |
1145 | if (mb->type == OFPMBT13_DSCP_REMARK) { | |
1146 | ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level); | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | static void | |
1151 | ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms) | |
1152 | { | |
1153 | uint16_t i; | |
1154 | ||
1155 | ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id); | |
1156 | ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count); | |
1157 | ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count); | |
1158 | ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count); | |
1159 | ds_put_cstr(s, "duration:"); | |
1160 | ofp_print_duration(s, ms->duration_sec, ms->duration_nsec); | |
1161 | ds_put_char(s, ' '); | |
1162 | ||
1163 | ds_put_cstr(s, "bands:\n"); | |
1164 | for (i = 0; i < ms->n_bands; ++i) { | |
1165 | ds_put_format(s, "%d: ", i); | |
1166 | ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count); | |
1167 | ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count); | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | static void | |
1172 | ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc) | |
1173 | { | |
1174 | uint16_t i; | |
1175 | ||
1176 | ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id); | |
1177 | ||
1178 | ofp_print_meter_flags(s, mc->flags); | |
1179 | ||
1180 | ds_put_cstr(s, "bands="); | |
1181 | for (i = 0; i < mc->n_bands; ++i) { | |
1182 | ofp_print_meter_band(s, mc->flags, &mc->bands[i]); | |
1183 | } | |
1184 | ds_put_char(s, '\n'); | |
1185 | } | |
1186 | ||
1187 | static void | |
1188 | ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh) | |
1189 | { | |
1190 | struct ofputil_meter_mod mm; | |
1191 | struct ofpbuf bands; | |
1192 | enum ofperr error; | |
1193 | ||
1194 | ofpbuf_init(&bands, 64); | |
1195 | error = ofputil_decode_meter_mod(oh, &mm, &bands); | |
1196 | if (error) { | |
1197 | ofpbuf_uninit(&bands); | |
1198 | ofp_print_error(s, error); | |
1199 | return; | |
1200 | } | |
1201 | ||
1202 | switch (mm.command) { | |
1203 | case OFPMC13_ADD: | |
1204 | ds_put_cstr(s, " ADD "); | |
1205 | break; | |
1206 | case OFPMC13_MODIFY: | |
1207 | ds_put_cstr(s, " MOD "); | |
1208 | break; | |
1209 | case OFPMC13_DELETE: | |
1210 | ds_put_cstr(s, " DEL "); | |
1211 | break; | |
1212 | default: | |
1213 | ds_put_format(s, " cmd:%d ", mm.command); | |
1214 | } | |
1215 | ||
1216 | ofp_print_meter_config(s, &mm.meter); | |
1217 | ofpbuf_uninit(&bands); | |
1218 | } | |
1219 | ||
1220 | static void | |
1221 | ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh) | |
1222 | { | |
1223 | uint32_t meter_id; | |
1224 | ||
1225 | ofputil_decode_meter_request(oh, &meter_id); | |
1226 | ||
1227 | ds_put_format(s, " meter=%"PRIu32, meter_id); | |
1228 | } | |
1229 | ||
1230 | static const char * | |
1231 | ofputil_meter_capabilities_to_name(uint32_t bit) | |
1232 | { | |
1233 | enum ofp13_meter_flags flag = bit; | |
1234 | ||
1235 | switch (flag) { | |
1236 | case OFPMF13_KBPS: return "kbps"; | |
1237 | case OFPMF13_PKTPS: return "pktps"; | |
1238 | case OFPMF13_BURST: return "burst"; | |
1239 | case OFPMF13_STATS: return "stats"; | |
1240 | } | |
1241 | ||
1242 | return NULL; | |
1243 | } | |
1244 | ||
1245 | static const char * | |
1246 | ofputil_meter_band_types_to_name(uint32_t bit) | |
1247 | { | |
638a19b0 | 1248 | switch (bit) { |
6e055a6c BP |
1249 | case 1 << OFPMBT13_DROP: return "drop"; |
1250 | case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark"; | |
638a19b0 JR |
1251 | } |
1252 | ||
1253 | return NULL; | |
1254 | } | |
1255 | ||
1256 | static void | |
1257 | ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh) | |
1258 | { | |
1259 | struct ofputil_meter_features mf; | |
1260 | ||
1261 | ofputil_decode_meter_features(oh, &mf); | |
1262 | ||
1263 | ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters); | |
1264 | ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands); | |
1265 | ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color); | |
1266 | ||
1267 | ds_put_cstr(s, "band_types: "); | |
1268 | ofp_print_bit_names(s, mf.band_types, | |
1269 | ofputil_meter_band_types_to_name, ' '); | |
1270 | ds_put_char(s, '\n'); | |
1271 | ||
1272 | ds_put_cstr(s, "capabilities: "); | |
1273 | ofp_print_bit_names(s, mf.capabilities, | |
1274 | ofputil_meter_capabilities_to_name, ' '); | |
1275 | ds_put_char(s, '\n'); | |
1276 | } | |
1277 | ||
1278 | static void | |
1279 | ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh) | |
1280 | { | |
1281 | struct ofpbuf bands; | |
1282 | struct ofpbuf b; | |
1283 | ||
1284 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1285 | ofpbuf_init(&bands, 64); | |
1286 | for (;;) { | |
1287 | struct ofputil_meter_config mc; | |
1288 | int retval; | |
1289 | ||
1290 | retval = ofputil_decode_meter_config(&b, &mc, &bands); | |
1291 | if (retval) { | |
1292 | if (retval != EOF) { | |
1293 | ofp_print_error(s, retval); | |
1294 | } | |
1295 | break; | |
1296 | } | |
1297 | ds_put_char(s, '\n'); | |
1298 | ofp_print_meter_config(s, &mc); | |
1299 | } | |
1300 | ofpbuf_uninit(&bands); | |
1301 | } | |
1302 | ||
1303 | static void | |
1304 | ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh) | |
1305 | { | |
1306 | struct ofpbuf bands; | |
1307 | struct ofpbuf b; | |
1308 | ||
1309 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1310 | ofpbuf_init(&bands, 64); | |
1311 | for (;;) { | |
1312 | struct ofputil_meter_stats ms; | |
1313 | int retval; | |
1314 | ||
1315 | retval = ofputil_decode_meter_stats(&b, &ms, &bands); | |
1316 | if (retval) { | |
1317 | if (retval != EOF) { | |
1318 | ofp_print_error(s, retval); | |
1319 | } | |
1320 | break; | |
1321 | } | |
1322 | ds_put_char(s, '\n'); | |
1323 | ofp_print_meter_stats(s, &ms); | |
1324 | } | |
1325 | ofpbuf_uninit(&bands); | |
1326 | } | |
1327 | ||
7fa91113 | 1328 | static void |
90bf1e07 | 1329 | ofp_print_error(struct ds *string, enum ofperr error) |
7fa91113 | 1330 | { |
7fa91113 BP |
1331 | if (string->length) { |
1332 | ds_put_char(string, ' '); | |
1333 | } | |
90bf1e07 | 1334 | ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error)); |
f74be05a JP |
1335 | } |
1336 | ||
de6c85b0 SH |
1337 | static void |
1338 | ofp_print_hello(struct ds *string, const struct ofp_header *oh) | |
1339 | { | |
1340 | uint32_t allowed_versions; | |
1341 | bool ok; | |
1342 | ||
1343 | ok = ofputil_decode_hello(oh, &allowed_versions); | |
1344 | ||
1345 | ds_put_cstr(string, "\n version bitmap: "); | |
1346 | ofputil_format_version_bitmap(string, allowed_versions); | |
1347 | ||
1348 | if (!ok) { | |
1349 | ds_put_cstr(string, "\n unknown data in hello:\n"); | |
1350 | ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true); | |
1351 | } | |
1352 | } | |
1353 | ||
064af421 | 1354 | static void |
982697a4 | 1355 | ofp_print_error_msg(struct ds *string, const struct ofp_header *oh) |
064af421 | 1356 | { |
982697a4 BP |
1357 | size_t len = ntohs(oh->length); |
1358 | struct ofpbuf payload; | |
90bf1e07 | 1359 | enum ofperr error; |
064af421 BP |
1360 | char *s; |
1361 | ||
982697a4 | 1362 | error = ofperr_decode_msg(oh, &payload); |
90bf1e07 BP |
1363 | if (!error) { |
1364 | ds_put_cstr(string, "***decode error***"); | |
982697a4 | 1365 | ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true); |
dc4762ed | 1366 | return; |
f74be05a JP |
1367 | } |
1368 | ||
90bf1e07 | 1369 | ds_put_format(string, " %s\n", ofperr_get_name(error)); |
064af421 | 1370 | |
90bf1e07 | 1371 | if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) { |
6fd6ed71 | 1372 | ds_put_printable(string, payload.data, payload.size); |
90bf1e07 | 1373 | } else { |
6fd6ed71 | 1374 | s = ofp_to_string(payload.data, payload.size, 1); |
064af421 BP |
1375 | ds_put_cstr(string, s); |
1376 | free(s); | |
064af421 | 1377 | } |
dea241f1 | 1378 | ofpbuf_uninit(&payload); |
064af421 BP |
1379 | } |
1380 | ||
064af421 | 1381 | static void |
982697a4 | 1382 | ofp_print_port_status(struct ds *string, const struct ofp_header *oh) |
064af421 | 1383 | { |
9e1fd49b BP |
1384 | struct ofputil_port_status ps; |
1385 | enum ofperr error; | |
1386 | ||
982697a4 | 1387 | error = ofputil_decode_port_status(oh, &ps); |
9e1fd49b BP |
1388 | if (error) { |
1389 | ofp_print_error(string, error); | |
1390 | return; | |
1391 | } | |
1392 | ||
1393 | if (ps.reason == OFPPR_ADD) { | |
064af421 | 1394 | ds_put_format(string, " ADD:"); |
9e1fd49b | 1395 | } else if (ps.reason == OFPPR_DELETE) { |
064af421 | 1396 | ds_put_format(string, " DEL:"); |
9e1fd49b | 1397 | } else if (ps.reason == OFPPR_MODIFY) { |
064af421 BP |
1398 | ds_put_format(string, " MOD:"); |
1399 | } | |
1400 | ||
9e1fd49b | 1401 | ofp_print_phy_port(string, &ps.desc); |
064af421 BP |
1402 | } |
1403 | ||
1404 | static void | |
982697a4 | 1405 | ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1406 | { |
982697a4 BP |
1407 | const struct ofp_desc_stats *ods = ofpmsg_body(oh); |
1408 | ||
fbd76b2e | 1409 | ds_put_char(string, '\n'); |
d295e8e9 | 1410 | ds_put_format(string, "Manufacturer: %.*s\n", |
dd70b475 JP |
1411 | (int) sizeof ods->mfr_desc, ods->mfr_desc); |
1412 | ds_put_format(string, "Hardware: %.*s\n", | |
1413 | (int) sizeof ods->hw_desc, ods->hw_desc); | |
1414 | ds_put_format(string, "Software: %.*s\n", | |
1415 | (int) sizeof ods->sw_desc, ods->sw_desc); | |
1416 | ds_put_format(string, "Serial Num: %.*s\n", | |
1417 | (int) sizeof ods->serial_num, ods->serial_num); | |
1418 | ds_put_format(string, "DP Description: %.*s\n", | |
1419 | (int) sizeof ods->dp_desc, ods->dp_desc); | |
064af421 BP |
1420 | } |
1421 | ||
1422 | static void | |
982697a4 | 1423 | ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh) |
064af421 | 1424 | { |
81d1ea94 | 1425 | struct ofputil_flow_stats_request fsr; |
90bf1e07 | 1426 | enum ofperr error; |
064af421 | 1427 | |
982697a4 | 1428 | error = ofputil_decode_flow_stats_request(&fsr, oh); |
2af0c0ef BP |
1429 | if (error) { |
1430 | ofp_print_error(string, error); | |
1431 | return; | |
1432 | } | |
1433 | ||
1434 | if (fsr.table_id != 0xff) { | |
e896c2d4 | 1435 | ds_put_format(string, " table=%"PRIu8, fsr.table_id); |
064af421 BP |
1436 | } |
1437 | ||
7f05e7ab | 1438 | if (fsr.out_port != OFPP_ANY) { |
2af0c0ef | 1439 | ds_put_cstr(string, " out_port="); |
39dc9082 | 1440 | ofputil_format_port(fsr.out_port, string); |
2af0c0ef BP |
1441 | } |
1442 | ||
1443 | ds_put_char(string, ' '); | |
81a76618 | 1444 | match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY); |
064af421 BP |
1445 | } |
1446 | ||
bdcc5925 BP |
1447 | void |
1448 | ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs) | |
1449 | { | |
1450 | ds_put_format(string, " cookie=0x%"PRIx64", duration=", | |
1451 | ntohll(fs->cookie)); | |
1452 | ||
1453 | ofp_print_duration(string, fs->duration_sec, fs->duration_nsec); | |
1454 | ds_put_format(string, ", table=%"PRIu8", ", fs->table_id); | |
1455 | ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count); | |
1456 | ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count); | |
1457 | if (fs->idle_timeout != OFP_FLOW_PERMANENT) { | |
1458 | ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout); | |
1459 | } | |
1460 | if (fs->hard_timeout != OFP_FLOW_PERMANENT) { | |
1461 | ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout); | |
1462 | } | |
2e1ae200 JR |
1463 | if (fs->flags) { |
1464 | ofp_print_flow_flags(string, fs->flags); | |
1465 | } | |
ca26eb44 RB |
1466 | if (fs->importance != 0) { |
1467 | ds_put_format(string, "importance=%"PRIu16", ", fs->importance); | |
1468 | } | |
bdcc5925 BP |
1469 | if (fs->idle_age >= 0) { |
1470 | ds_put_format(string, "idle_age=%d, ", fs->idle_age); | |
1471 | } | |
1472 | if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) { | |
1473 | ds_put_format(string, "hard_age=%d, ", fs->hard_age); | |
1474 | } | |
1475 | ||
81a76618 | 1476 | match_format(&fs->match, string, fs->priority); |
bdcc5925 BP |
1477 | if (string->string[string->length - 1] != ' ') { |
1478 | ds_put_char(string, ' '); | |
1479 | } | |
1480 | ||
455ecd77 | 1481 | ds_put_cstr(string, "actions="); |
bdcc5925 BP |
1482 | ofpacts_format(fs->ofpacts, fs->ofpacts_len, string); |
1483 | } | |
1484 | ||
064af421 | 1485 | static void |
4ffd1b43 | 1486 | ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1487 | { |
f25d0cf3 | 1488 | struct ofpbuf ofpacts; |
4ffd1b43 | 1489 | struct ofpbuf b; |
064af421 | 1490 | |
4ffd1b43 | 1491 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
f25d0cf3 | 1492 | ofpbuf_init(&ofpacts, 64); |
4ffd1b43 BP |
1493 | for (;;) { |
1494 | struct ofputil_flow_stats fs; | |
1495 | int retval; | |
fab8fadb | 1496 | |
f25d0cf3 | 1497 | retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts); |
4ffd1b43 BP |
1498 | if (retval) { |
1499 | if (retval != EOF) { | |
1500 | ds_put_cstr(string, " ***parse error***"); | |
064af421 BP |
1501 | } |
1502 | break; | |
1503 | } | |
8961de6a | 1504 | ds_put_char(string, '\n'); |
bdcc5925 BP |
1505 | ofp_print_flow_stats(string, &fs); |
1506 | } | |
cb80d803 | 1507 | ofpbuf_uninit(&ofpacts); |
c6430da5 BP |
1508 | } |
1509 | ||
064af421 | 1510 | static void |
982697a4 | 1511 | ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1512 | { |
982697a4 BP |
1513 | struct ofputil_aggregate_stats as; |
1514 | enum ofperr error; | |
064af421 | 1515 | |
982697a4 BP |
1516 | error = ofputil_decode_aggregate_stats_reply(&as, oh); |
1517 | if (error) { | |
1518 | ofp_print_error(string, error); | |
1519 | return; | |
1520 | } | |
1521 | ||
1522 | ds_put_format(string, " packet_count=%"PRIu64, as.packet_count); | |
1523 | ds_put_format(string, " byte_count=%"PRIu64, as.byte_count); | |
1524 | ds_put_format(string, " flow_count=%"PRIu32, as.flow_count); | |
a2ad9ecd BP |
1525 | } |
1526 | ||
f8e4867e SH |
1527 | static void |
1528 | print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more) | |
064af421 BP |
1529 | { |
1530 | ds_put_cstr(string, leader); | |
c4617b3c | 1531 | if (stat != UINT64_MAX) { |
064af421 BP |
1532 | ds_put_format(string, "%"PRIu64, stat); |
1533 | } else { | |
1534 | ds_put_char(string, '?'); | |
1535 | } | |
1536 | if (more) { | |
1537 | ds_put_cstr(string, ", "); | |
1538 | } else { | |
1539 | ds_put_cstr(string, "\n"); | |
1540 | } | |
1541 | } | |
1542 | ||
abaad8cf | 1543 | static void |
982697a4 | 1544 | ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh) |
abaad8cf | 1545 | { |
4e022ec0 | 1546 | ofp_port_t ofp10_port; |
f8e4867e SH |
1547 | enum ofperr error; |
1548 | ||
1549 | error = ofputil_decode_port_stats_request(oh, &ofp10_port); | |
1550 | if (error) { | |
1551 | ofp_print_error(string, error); | |
1552 | return; | |
1553 | } | |
1554 | ||
e1db42d6 JR |
1555 | ds_put_cstr(string, " port_no="); |
1556 | ofputil_format_port(ofp10_port, string); | |
abaad8cf JP |
1557 | } |
1558 | ||
064af421 | 1559 | static void |
d1e2cf21 BP |
1560 | ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh, |
1561 | int verbosity) | |
064af421 | 1562 | { |
982697a4 | 1563 | struct ofpbuf b; |
982697a4 | 1564 | |
34582733 | 1565 | ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh)); |
064af421 BP |
1566 | if (verbosity < 1) { |
1567 | return; | |
1568 | } | |
1569 | ||
f8e4867e | 1570 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
982697a4 | 1571 | for (;;) { |
f8e4867e SH |
1572 | struct ofputil_port_stats ps; |
1573 | int retval; | |
1574 | ||
1575 | retval = ofputil_decode_port_stats(&ps, &b); | |
1576 | if (retval) { | |
1577 | if (retval != EOF) { | |
1578 | ds_put_cstr(string, " ***parse error***"); | |
1579 | } | |
982697a4 BP |
1580 | return; |
1581 | } | |
1582 | ||
e1db42d6 | 1583 | ds_put_cstr(string, " port "); |
4e022ec0 | 1584 | if (ofp_to_u16(ps.port_no) < 10) { |
e1db42d6 JR |
1585 | ds_put_char(string, ' '); |
1586 | } | |
1587 | ofputil_format_port(ps.port_no, string); | |
064af421 | 1588 | |
f8e4867e SH |
1589 | ds_put_cstr(string, ": rx "); |
1590 | print_port_stat(string, "pkts=", ps.stats.rx_packets, 1); | |
1591 | print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1); | |
1592 | print_port_stat(string, "drop=", ps.stats.rx_dropped, 1); | |
1593 | print_port_stat(string, "errs=", ps.stats.rx_errors, 1); | |
1594 | print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1); | |
1595 | print_port_stat(string, "over=", ps.stats.rx_over_errors, 1); | |
1596 | print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0); | |
064af421 BP |
1597 | |
1598 | ds_put_cstr(string, " tx "); | |
f8e4867e SH |
1599 | print_port_stat(string, "pkts=", ps.stats.tx_packets, 1); |
1600 | print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1); | |
1601 | print_port_stat(string, "drop=", ps.stats.tx_dropped, 1); | |
1602 | print_port_stat(string, "errs=", ps.stats.tx_errors, 1); | |
1603 | print_port_stat(string, "coll=", ps.stats.collisions, 0); | |
65e0be10 BP |
1604 | |
1605 | if (ps.duration_sec != UINT32_MAX) { | |
1606 | ds_put_cstr(string, " duration="); | |
1607 | ofp_print_duration(string, ps.duration_sec, ps.duration_nsec); | |
1608 | ds_put_char(string, '\n'); | |
1609 | } | |
064af421 BP |
1610 | } |
1611 | } | |
1612 | ||
1613 | static void | |
3c1bb396 | 1614 | ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh) |
26df8b3e | 1615 | { |
26df8b3e | 1616 | struct ofpbuf b; |
26df8b3e SH |
1617 | |
1618 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1619 | ofpraw_pull_assert(&b); | |
1620 | ||
8811fc0a BP |
1621 | struct ofputil_table_features prev_features; |
1622 | struct ofputil_table_stats prev_stats; | |
1623 | for (int i = 0;; i++) { | |
3c1bb396 BP |
1624 | struct ofputil_table_features features; |
1625 | struct ofputil_table_stats stats; | |
1626 | int retval; | |
982697a4 | 1627 | |
3c1bb396 BP |
1628 | retval = ofputil_decode_table_stats_reply(&b, &stats, &features); |
1629 | if (retval) { | |
1630 | if (retval != EOF) { | |
1631 | ofp_print_error(string, retval); | |
1632 | } | |
982697a4 BP |
1633 | return; |
1634 | } | |
1635 | ||
8811fc0a BP |
1636 | ds_put_char(string, '\n'); |
1637 | ofp_print_table_features(string, | |
1638 | &features, i ? &prev_features : NULL, | |
1639 | &stats, i ? &prev_stats : NULL); | |
1640 | prev_features = features; | |
1641 | prev_stats = stats; | |
26df8b3e SH |
1642 | } |
1643 | } | |
1644 | ||
d2805da2 BP |
1645 | static void |
1646 | ofp_print_queue_name(struct ds *string, uint32_t queue_id) | |
1647 | { | |
1648 | if (queue_id == OFPQ_ALL) { | |
1649 | ds_put_cstr(string, "ALL"); | |
1650 | } else { | |
1651 | ds_put_format(string, "%"PRIu32, queue_id); | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | static void | |
982697a4 | 1656 | ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh) |
d2805da2 | 1657 | { |
64626975 SH |
1658 | struct ofputil_queue_stats_request oqsr; |
1659 | enum ofperr error; | |
1660 | ||
1661 | error = ofputil_decode_queue_stats_request(oh, &oqsr); | |
1662 | if (error) { | |
1663 | ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error)); | |
1664 | return; | |
1665 | } | |
982697a4 | 1666 | |
d2805da2 | 1667 | ds_put_cstr(string, "port="); |
64626975 | 1668 | ofputil_format_port(oqsr.port_no, string); |
d2805da2 BP |
1669 | |
1670 | ds_put_cstr(string, " queue="); | |
64626975 | 1671 | ofp_print_queue_name(string, oqsr.queue_id); |
f8e4867e SH |
1672 | } |
1673 | ||
d2805da2 | 1674 | static void |
d1e2cf21 BP |
1675 | ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh, |
1676 | int verbosity) | |
d2805da2 | 1677 | { |
982697a4 | 1678 | struct ofpbuf b; |
982697a4 | 1679 | |
34582733 | 1680 | ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh)); |
d2805da2 BP |
1681 | if (verbosity < 1) { |
1682 | return; | |
1683 | } | |
1684 | ||
64626975 | 1685 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
982697a4 | 1686 | for (;;) { |
64626975 SH |
1687 | struct ofputil_queue_stats qs; |
1688 | int retval; | |
1689 | ||
1690 | retval = ofputil_decode_queue_stats(&qs, &b); | |
1691 | if (retval) { | |
1692 | if (retval != EOF) { | |
1693 | ds_put_cstr(string, " ***parse error***"); | |
1694 | } | |
982697a4 BP |
1695 | return; |
1696 | } | |
1697 | ||
d2805da2 | 1698 | ds_put_cstr(string, " port "); |
64626975 | 1699 | ofputil_format_port(qs.port_no, string); |
d2805da2 | 1700 | ds_put_cstr(string, " queue "); |
64626975 | 1701 | ofp_print_queue_name(string, qs.queue_id); |
d2805da2 BP |
1702 | ds_put_cstr(string, ": "); |
1703 | ||
6dc34a0d BP |
1704 | print_port_stat(string, "bytes=", qs.tx_bytes, 1); |
1705 | print_port_stat(string, "pkts=", qs.tx_packets, 1); | |
1706 | print_port_stat(string, "errors=", qs.tx_errors, 1); | |
1707 | ||
1708 | ds_put_cstr(string, "duration="); | |
1709 | if (qs.duration_sec != UINT32_MAX) { | |
1710 | ofp_print_duration(string, qs.duration_sec, qs.duration_nsec); | |
1711 | } else { | |
1712 | ds_put_char(string, '?'); | |
1713 | } | |
1714 | ds_put_char(string, '\n'); | |
d2805da2 BP |
1715 | } |
1716 | } | |
1717 | ||
70ae4f93 BP |
1718 | static void |
1719 | ofp_print_ofpst_port_desc_request(struct ds *string, | |
1720 | const struct ofp_header *oh) | |
1721 | { | |
1722 | enum ofperr error; | |
1723 | ofp_port_t port; | |
1724 | ||
1725 | error = ofputil_decode_port_desc_stats_request(oh, &port); | |
1726 | if (error) { | |
1727 | ofp_print_error(string, error); | |
1728 | return; | |
1729 | } | |
1730 | ||
1731 | ds_put_cstr(string, " port="); | |
1732 | ofputil_format_port(port, string); | |
1733 | } | |
1734 | ||
2be393ed JP |
1735 | static void |
1736 | ofp_print_ofpst_port_desc_reply(struct ds *string, | |
1737 | const struct ofp_header *oh) | |
1738 | { | |
1739 | struct ofpbuf b; | |
1740 | ||
1741 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
982697a4 | 1742 | ofpraw_pull_assert(&b); |
2be393ed JP |
1743 | ds_put_char(string, '\n'); |
1744 | ofp_print_phy_ports(string, oh->version, &b); | |
1745 | } | |
1746 | ||
064af421 | 1747 | static void |
5d40fc57 | 1748 | ofp_print_stats(struct ds *string, const struct ofp_header *oh) |
064af421 | 1749 | { |
982697a4 | 1750 | uint16_t flags = ofpmp_flags(oh); |
d1e2cf21 | 1751 | |
982697a4 | 1752 | if (flags) { |
d1e2cf21 | 1753 | ds_put_cstr(string, " flags="); |
5d40fc57 SH |
1754 | if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION) |
1755 | && (flags & OFPSF_REPLY_MORE)) { | |
064af421 BP |
1756 | ds_put_cstr(string, "[more]"); |
1757 | flags &= ~OFPSF_REPLY_MORE; | |
1758 | } | |
1759 | if (flags) { | |
d1e2cf21 BP |
1760 | ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]", |
1761 | flags); | |
064af421 BP |
1762 | } |
1763 | } | |
064af421 BP |
1764 | } |
1765 | ||
1766 | static void | |
d1e2cf21 | 1767 | ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity) |
064af421 | 1768 | { |
d1e2cf21 | 1769 | size_t len = ntohs(oh->length); |
064af421 | 1770 | |
34582733 | 1771 | ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh); |
064af421 | 1772 | if (verbosity > 1) { |
d1e2cf21 | 1773 | ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true); |
064af421 BP |
1774 | } |
1775 | } | |
1776 | ||
61fe3a7b | 1777 | static void |
00467f73 AC |
1778 | ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role, |
1779 | uint64_t generation_id) | |
61fe3a7b | 1780 | { |
61fe3a7b | 1781 | ds_put_cstr(string, " role="); |
6ea4776b | 1782 | |
00467f73 | 1783 | switch (role) { |
f4f1ea7e BP |
1784 | case OFPCR12_ROLE_NOCHANGE: |
1785 | ds_put_cstr(string, "nochange"); | |
1786 | break; | |
1787 | case OFPCR12_ROLE_EQUAL: | |
6ea4776b JR |
1788 | ds_put_cstr(string, "equal"); /* OF 1.2 wording */ |
1789 | break; | |
f4f1ea7e | 1790 | case OFPCR12_ROLE_MASTER: |
61fe3a7b | 1791 | ds_put_cstr(string, "master"); |
6ea4776b | 1792 | break; |
f4f1ea7e | 1793 | case OFPCR12_ROLE_SLAVE: |
61fe3a7b | 1794 | ds_put_cstr(string, "slave"); |
6ea4776b JR |
1795 | break; |
1796 | default: | |
428b2edd | 1797 | OVS_NOT_REACHED(); |
6ea4776b JR |
1798 | } |
1799 | ||
00467f73 AC |
1800 | if (generation_id != UINT64_MAX) { |
1801 | ds_put_format(string, " generation_id=%"PRIu64, generation_id); | |
1802 | } | |
1803 | } | |
1804 | ||
1805 | static void | |
1806 | ofp_print_role_message(struct ds *string, const struct ofp_header *oh) | |
1807 | { | |
1808 | struct ofputil_role_request rr; | |
1809 | enum ofperr error; | |
1810 | ||
1811 | error = ofputil_decode_role_message(oh, &rr); | |
1812 | if (error) { | |
1813 | ofp_print_error(string, error); | |
1814 | return; | |
1815 | } | |
1816 | ||
1817 | ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX); | |
1818 | } | |
1819 | ||
1820 | static void | |
1821 | ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh) | |
1822 | { | |
1823 | struct ofputil_role_status rs; | |
1824 | enum ofperr error; | |
1825 | ||
1826 | error = ofputil_decode_role_status(oh, &rs); | |
1827 | if (error) { | |
1828 | ofp_print_error(string, error); | |
1829 | return; | |
1830 | } | |
1831 | ||
1832 | ofp_print_role_generic(string, rs.role, rs.generation_id); | |
1833 | ||
1834 | ds_put_cstr(string, " reason="); | |
1835 | ||
1836 | switch (rs.reason) { | |
1837 | case OFPCRR_MASTER_REQUEST: | |
1838 | ds_put_cstr(string, "master_request"); | |
1839 | break; | |
1840 | case OFPCRR_CONFIG: | |
1841 | ds_put_cstr(string, "configuration_changed"); | |
1842 | break; | |
1843 | case OFPCRR_EXPERIMENTER: | |
1844 | ds_put_cstr(string, "experimenter_data_changed"); | |
1845 | break; | |
1846 | default: | |
428b2edd | 1847 | OVS_NOT_REACHED(); |
61fe3a7b BP |
1848 | } |
1849 | } | |
1850 | ||
6c1491fb BP |
1851 | static void |
1852 | ofp_print_nxt_flow_mod_table_id(struct ds *string, | |
73dbf4ab | 1853 | const struct nx_flow_mod_table_id *nfmti) |
6c1491fb BP |
1854 | { |
1855 | ds_put_format(string, " %s", nfmti->set ? "enable" : "disable"); | |
1856 | } | |
1857 | ||
7fa91113 BP |
1858 | static void |
1859 | ofp_print_nxt_set_flow_format(struct ds *string, | |
73dbf4ab | 1860 | const struct nx_set_flow_format *nsff) |
7fa91113 BP |
1861 | { |
1862 | uint32_t format = ntohl(nsff->format); | |
1863 | ||
1864 | ds_put_cstr(string, " format="); | |
27527aa0 BP |
1865 | if (ofputil_nx_flow_format_is_valid(format)) { |
1866 | ds_put_cstr(string, ofputil_nx_flow_format_to_string(format)); | |
7fa91113 BP |
1867 | } else { |
1868 | ds_put_format(string, "%"PRIu32, format); | |
1869 | } | |
1870 | } | |
1871 | ||
54834960 EJ |
1872 | static void |
1873 | ofp_print_nxt_set_packet_in_format(struct ds *string, | |
73dbf4ab | 1874 | const struct nx_set_packet_in_format *nspf) |
54834960 EJ |
1875 | { |
1876 | uint32_t format = ntohl(nspf->format); | |
1877 | ||
1878 | ds_put_cstr(string, " format="); | |
1879 | if (ofputil_packet_in_format_is_valid(format)) { | |
1880 | ds_put_cstr(string, ofputil_packet_in_format_to_string(format)); | |
1881 | } else { | |
1882 | ds_put_format(string, "%"PRIu32, format); | |
1883 | } | |
1884 | } | |
1885 | ||
8961699e BP |
1886 | /* Returns a string form of 'reason'. The return value is either a statically |
1887 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
1888 | * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */ | |
1889 | #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1) | |
80d5aefd | 1890 | static const char * |
8961699e BP |
1891 | ofp_port_reason_to_string(enum ofp_port_reason reason, |
1892 | char *reasonbuf, size_t bufsize) | |
80d5aefd | 1893 | { |
80d5aefd BP |
1894 | switch (reason) { |
1895 | case OFPPR_ADD: | |
1896 | return "add"; | |
1897 | ||
1898 | case OFPPR_DELETE: | |
1899 | return "delete"; | |
1900 | ||
1901 | case OFPPR_MODIFY: | |
1902 | return "modify"; | |
1903 | ||
1904 | default: | |
8961699e BP |
1905 | snprintf(reasonbuf, bufsize, "%d", (int) reason); |
1906 | return reasonbuf; | |
80d5aefd BP |
1907 | } |
1908 | } | |
1909 | ||
98090482 NR |
1910 | /* Returns a string form of 'reason'. The return value is either a statically |
1911 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
1912 | * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */ | |
1913 | static const char* | |
1914 | ofp_role_reason_to_string(enum ofp14_controller_role_reason reason, | |
1915 | char *reasonbuf, size_t bufsize) | |
1916 | { | |
1917 | switch (reason) { | |
1918 | case OFPCRR_MASTER_REQUEST: | |
1919 | return "master_request"; | |
1920 | ||
1921 | case OFPCRR_CONFIG: | |
1922 | return "configuration_changed"; | |
1923 | ||
1924 | case OFPCRR_EXPERIMENTER: | |
1925 | return "experimenter_data_changed"; | |
1926 | ||
1927 | default: | |
1928 | snprintf(reasonbuf, bufsize, "%d", (int) reason); | |
1929 | return reasonbuf; | |
1930 | } | |
1931 | } | |
1932 | ||
1933 | /* Returns a string form of 'reason'. The return value is either a statically | |
1934 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
1935 | * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */ | |
1936 | static const char* | |
1937 | ofp_table_reason_to_string(enum ofp14_table_reason reason, | |
1938 | char *reasonbuf, size_t bufsize) | |
1939 | { | |
1940 | switch (reason) { | |
1941 | case OFPTR_VACANCY_DOWN: | |
1942 | return "vacancy_down"; | |
1943 | ||
1944 | case OFPTR_VACANCY_UP: | |
1945 | return "vacancy_up"; | |
1946 | ||
1947 | default: | |
1948 | snprintf(reasonbuf, bufsize, "%d", (int) reason); | |
1949 | return reasonbuf; | |
1950 | } | |
1951 | } | |
1952 | ||
1953 | /* Returns a string form of 'reason'. The return value is either a statically | |
1954 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
1955 | * 'bufsize' should be at least OFP_ASYNC_CONFIG_REASON_BUFSIZE. */ | |
1956 | static const char* | |
1957 | ofp_requestforward_reason_to_string(enum ofp14_requestforward_reason reason, | |
1958 | char *reasonbuf, size_t bufsize) | |
1959 | { | |
1960 | switch (reason) { | |
1961 | case OFPRFR_GROUP_MOD: | |
1962 | return "group_mod_request"; | |
1963 | ||
1964 | case OFPRFR_METER_MOD: | |
1965 | return "meter_mod_request"; | |
1966 | ||
1967 | default: | |
1968 | snprintf(reasonbuf, bufsize, "%d", (int) reason); | |
1969 | return reasonbuf; | |
1970 | } | |
1971 | } | |
1972 | ||
1973 | static const char * | |
1974 | ofp_async_config_reason_to_string(uint32_t reason, | |
1975 | enum ofputil_async_msg_type type, | |
1976 | char *reasonbuf, size_t bufsize) | |
1977 | { | |
1978 | switch (type) { | |
1979 | case OAM_PACKET_IN: | |
1980 | return ofputil_packet_in_reason_to_string(reason, reasonbuf, bufsize); | |
1981 | ||
1982 | case OAM_PORT_STATUS: | |
1983 | return ofp_port_reason_to_string(reason, reasonbuf, bufsize); | |
1984 | ||
1985 | case OAM_FLOW_REMOVED: | |
1986 | return ofp_flow_removed_reason_to_string(reason, reasonbuf, bufsize); | |
1987 | ||
1988 | case OAM_ROLE_STATUS: | |
1989 | return ofp_role_reason_to_string(reason, reasonbuf, bufsize); | |
1990 | ||
1991 | case OAM_TABLE_STATUS: | |
1992 | return ofp_table_reason_to_string(reason, reasonbuf, bufsize); | |
1993 | ||
1994 | case OAM_REQUESTFORWARD: | |
1995 | return ofp_requestforward_reason_to_string(reason, reasonbuf, bufsize); | |
1996 | ||
1997 | case OAM_N_TYPES: | |
1998 | default: | |
1999 | return "Unknown asynchronous configuration message type"; | |
2000 | } | |
2001 | } | |
2002 | ||
2003 | ||
2004 | #define OFP_ASYNC_CONFIG_REASON_BUFSIZE (INT_STRLEN(int) + 1) | |
80d5aefd BP |
2005 | static void |
2006 | ofp_print_nxt_set_async_config(struct ds *string, | |
98090482 | 2007 | const struct ofp_header *oh) |
80d5aefd | 2008 | { |
98090482 NR |
2009 | int i, j; |
2010 | enum ofpraw raw; | |
80d5aefd | 2011 | |
98090482 NR |
2012 | ofpraw_decode(&raw, oh); |
2013 | ||
2014 | if (raw == OFPRAW_OFPT13_SET_ASYNC || | |
2015 | raw == OFPRAW_NXT_SET_ASYNC_CONFIG || | |
2016 | raw == OFPRAW_OFPT13_GET_ASYNC_REPLY) { | |
2017 | const struct nx_async_config *nac = ofpmsg_body(oh); | |
2018 | ||
2019 | for (i = 0; i < 2; i++) { | |
80d5aefd | 2020 | |
98090482 | 2021 | ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave"); |
80d5aefd | 2022 | |
98090482 NR |
2023 | ds_put_cstr(string, " PACKET_IN:"); |
2024 | for (j = 0; j < 32; j++) { | |
2025 | if (nac->packet_in_mask[i] & htonl(1u << j)) { | |
2026 | char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE]; | |
2027 | const char *reason; | |
5014a89d | 2028 | |
98090482 | 2029 | reason = ofputil_packet_in_reason_to_string(j, reasonbuf, |
5014a89d | 2030 | sizeof reasonbuf); |
98090482 NR |
2031 | ds_put_format(string, " %s", reason); |
2032 | } | |
80d5aefd | 2033 | } |
98090482 NR |
2034 | if (!nac->packet_in_mask[i]) { |
2035 | ds_put_cstr(string, " (off)"); | |
2036 | } | |
2037 | ds_put_char(string, '\n'); | |
80d5aefd | 2038 | |
98090482 NR |
2039 | ds_put_cstr(string, " PORT_STATUS:"); |
2040 | for (j = 0; j < 32; j++) { | |
2041 | if (nac->port_status_mask[i] & htonl(1u << j)) { | |
2042 | char reasonbuf[OFP_PORT_REASON_BUFSIZE]; | |
2043 | const char *reason; | |
8961699e | 2044 | |
98090482 NR |
2045 | reason = ofp_port_reason_to_string(j, reasonbuf, |
2046 | sizeof reasonbuf); | |
2047 | ds_put_format(string, " %s", reason); | |
2048 | } | |
80d5aefd | 2049 | } |
98090482 NR |
2050 | if (!nac->port_status_mask[i]) { |
2051 | ds_put_cstr(string, " (off)"); | |
2052 | } | |
2053 | ds_put_char(string, '\n'); | |
80d5aefd | 2054 | |
98090482 NR |
2055 | ds_put_cstr(string, " FLOW_REMOVED:"); |
2056 | for (j = 0; j < 32; j++) { | |
2057 | if (nac->flow_removed_mask[i] & htonl(1u << j)) { | |
2058 | char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE]; | |
2059 | const char *reason; | |
8961699e | 2060 | |
98090482 | 2061 | reason = ofp_flow_removed_reason_to_string(j, reasonbuf, |
8961699e | 2062 | sizeof reasonbuf); |
98090482 NR |
2063 | ds_put_format(string, " %s", reason); |
2064 | } | |
80d5aefd | 2065 | } |
98090482 NR |
2066 | if (!nac->flow_removed_mask[i]) { |
2067 | ds_put_cstr(string, " (off)"); | |
2068 | } | |
2069 | ds_put_char(string, '\n'); | |
80d5aefd | 2070 | } |
98090482 NR |
2071 | } else if (raw == OFPRAW_OFPT14_SET_ASYNC || |
2072 | raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) { | |
2073 | uint32_t role[2][OAM_N_TYPES] = {{0}}; | |
2074 | uint32_t type; | |
2075 | ||
2076 | ofputil_decode_set_async_config(oh, role[0], role[1], true); | |
2077 | for (i = 0; i < 2; i++) { | |
2078 | ||
2079 | ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave"); | |
2080 | for (type = 0; type < OAM_N_TYPES; type++) { | |
2081 | switch (type) { | |
2082 | case OAM_PACKET_IN: | |
2083 | ds_put_cstr(string, " PACKET_IN:"); | |
2084 | break; | |
2085 | ||
2086 | case OAM_PORT_STATUS: | |
2087 | ds_put_cstr(string, " PORT_STATUS:"); | |
2088 | break; | |
2089 | ||
2090 | case OAM_FLOW_REMOVED: | |
2091 | ds_put_cstr(string, " FLOW_REMOVED:"); | |
2092 | break; | |
2093 | ||
2094 | case OAM_ROLE_STATUS: | |
2095 | ds_put_cstr(string, " ROLE_STATUS:"); | |
2096 | break; | |
2097 | ||
2098 | case OAM_TABLE_STATUS: | |
2099 | ds_put_cstr(string, " TABLE_STATUS:"); | |
2100 | break; | |
2101 | ||
2102 | case OAM_REQUESTFORWARD: | |
2103 | ds_put_cstr(string, " REQUESTFORWARD:"); | |
2104 | break; | |
2105 | } | |
2106 | ||
2107 | for (j = 0; j < 32; j++) { | |
2108 | if (role[i][type] & (1u << j)) { | |
2109 | char reasonbuf[OFP_ASYNC_CONFIG_REASON_BUFSIZE]; | |
2110 | const char *reason; | |
2111 | ||
2112 | reason = ofp_async_config_reason_to_string(j, type, | |
2113 | reasonbuf, | |
2114 | sizeof reasonbuf); | |
2115 | ds_put_format(string, " %s", reason); | |
2116 | } | |
2117 | } | |
2118 | if (!role[i][type]) { | |
2119 | ds_put_cstr(string, " (off)"); | |
2120 | } | |
2121 | ds_put_char(string, '\n'); | |
2122 | } | |
80d5aefd | 2123 | } |
80d5aefd BP |
2124 | } |
2125 | } | |
2126 | ||
a7349929 BP |
2127 | static void |
2128 | ofp_print_nxt_set_controller_id(struct ds *string, | |
2129 | const struct nx_controller_id *nci) | |
2130 | { | |
2131 | ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id)); | |
2132 | } | |
2133 | ||
2b07c8b1 BP |
2134 | static void |
2135 | ofp_print_nxt_flow_monitor_cancel(struct ds *string, | |
2136 | const struct ofp_header *oh) | |
2137 | { | |
2138 | ds_put_format(string, " id=%"PRIu32, | |
2139 | ofputil_decode_flow_monitor_cancel(oh)); | |
2140 | } | |
2141 | ||
2142 | static const char * | |
2143 | nx_flow_monitor_flags_to_name(uint32_t bit) | |
2144 | { | |
2145 | enum nx_flow_monitor_flags fmf = bit; | |
2146 | ||
2147 | switch (fmf) { | |
2148 | case NXFMF_INITIAL: return "initial"; | |
2149 | case NXFMF_ADD: return "add"; | |
2150 | case NXFMF_DELETE: return "delete"; | |
2151 | case NXFMF_MODIFY: return "modify"; | |
2152 | case NXFMF_ACTIONS: return "actions"; | |
2153 | case NXFMF_OWN: return "own"; | |
2154 | } | |
2155 | ||
2156 | return NULL; | |
2157 | } | |
2158 | ||
2159 | static void | |
2160 | ofp_print_nxst_flow_monitor_request(struct ds *string, | |
2161 | const struct ofp_header *oh) | |
2162 | { | |
2163 | struct ofpbuf b; | |
2164 | ||
2165 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2166 | for (;;) { | |
2167 | struct ofputil_flow_monitor_request request; | |
2168 | int retval; | |
2169 | ||
2170 | retval = ofputil_decode_flow_monitor_request(&request, &b); | |
2171 | if (retval) { | |
2172 | if (retval != EOF) { | |
2173 | ofp_print_error(string, retval); | |
2174 | } | |
2175 | return; | |
2176 | } | |
2177 | ||
2178 | ds_put_format(string, "\n id=%"PRIu32" flags=", request.id); | |
2179 | ofp_print_bit_names(string, request.flags, | |
2180 | nx_flow_monitor_flags_to_name, ','); | |
2181 | ||
2182 | if (request.out_port != OFPP_NONE) { | |
2183 | ds_put_cstr(string, " out_port="); | |
2184 | ofputil_format_port(request.out_port, string); | |
2185 | } | |
2186 | ||
2187 | if (request.table_id != 0xff) { | |
2188 | ds_put_format(string, " table=%"PRIu8, request.table_id); | |
2189 | } | |
2190 | ||
2191 | ds_put_char(string, ' '); | |
81a76618 | 2192 | match_format(&request.match, string, OFP_DEFAULT_PRIORITY); |
2b07c8b1 BP |
2193 | ds_chomp(string, ' '); |
2194 | } | |
2195 | } | |
2196 | ||
2197 | static void | |
2198 | ofp_print_nxst_flow_monitor_reply(struct ds *string, | |
2199 | const struct ofp_header *oh) | |
2200 | { | |
2201 | uint64_t ofpacts_stub[1024 / 8]; | |
2202 | struct ofpbuf ofpacts; | |
2203 | struct ofpbuf b; | |
2204 | ||
2205 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2206 | ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub); | |
2207 | for (;;) { | |
8961699e | 2208 | char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE]; |
2b07c8b1 | 2209 | struct ofputil_flow_update update; |
81a76618 | 2210 | struct match match; |
2b07c8b1 BP |
2211 | int retval; |
2212 | ||
2213 | update.match = &match; | |
2214 | retval = ofputil_decode_flow_update(&update, &b, &ofpacts); | |
2215 | if (retval) { | |
2216 | if (retval != EOF) { | |
2217 | ofp_print_error(string, retval); | |
2218 | } | |
2219 | ofpbuf_uninit(&ofpacts); | |
2220 | return; | |
2221 | } | |
2222 | ||
2223 | ds_put_cstr(string, "\n event="); | |
2224 | switch (update.event) { | |
2225 | case NXFME_ADDED: | |
2226 | ds_put_cstr(string, "ADDED"); | |
2227 | break; | |
2228 | ||
2229 | case NXFME_DELETED: | |
2230 | ds_put_format(string, "DELETED reason=%s", | |
8961699e BP |
2231 | ofp_flow_removed_reason_to_string(update.reason, |
2232 | reasonbuf, | |
2233 | sizeof reasonbuf)); | |
2b07c8b1 BP |
2234 | break; |
2235 | ||
2236 | case NXFME_MODIFIED: | |
2237 | ds_put_cstr(string, "MODIFIED"); | |
2238 | break; | |
2239 | ||
2240 | case NXFME_ABBREV: | |
2241 | ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid)); | |
2242 | continue; | |
2243 | } | |
2244 | ||
2245 | ds_put_format(string, " table=%"PRIu8, update.table_id); | |
2246 | if (update.idle_timeout != OFP_FLOW_PERMANENT) { | |
2247 | ds_put_format(string, " idle_timeout=%"PRIu16, | |
2248 | update.idle_timeout); | |
2249 | } | |
2250 | if (update.hard_timeout != OFP_FLOW_PERMANENT) { | |
2251 | ds_put_format(string, " hard_timeout=%"PRIu16, | |
2252 | update.hard_timeout); | |
2253 | } | |
2254 | ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie)); | |
2255 | ||
2256 | ds_put_char(string, ' '); | |
81a76618 | 2257 | match_format(update.match, string, OFP_DEFAULT_PRIORITY); |
2b07c8b1 BP |
2258 | |
2259 | if (update.ofpacts_len) { | |
2260 | if (string->string[string->length - 1] != ' ') { | |
2261 | ds_put_char(string, ' '); | |
2262 | } | |
455ecd77 | 2263 | ds_put_cstr(string, "actions="); |
2b07c8b1 BP |
2264 | ofpacts_format(update.ofpacts, update.ofpacts_len, string); |
2265 | } | |
2266 | } | |
2267 | } | |
2268 | ||
bdcc5925 BP |
2269 | void |
2270 | ofp_print_version(const struct ofp_header *oh, | |
2271 | struct ds *string) | |
d1e2cf21 | 2272 | { |
3811e66b BP |
2273 | switch (oh->version) { |
2274 | case OFP10_VERSION: | |
2275 | break; | |
2276 | case OFP11_VERSION: | |
2277 | ds_put_cstr(string, " (OF1.1)"); | |
4232ef77 SH |
2278 | break; |
2279 | case OFP12_VERSION: | |
2280 | ds_put_cstr(string, " (OF1.2)"); | |
3811e66b | 2281 | break; |
2e1ae200 JR |
2282 | case OFP13_VERSION: |
2283 | ds_put_cstr(string, " (OF1.3)"); | |
2284 | break; | |
9620f50c AC |
2285 | case OFP14_VERSION: |
2286 | ds_put_cstr(string, " (OF1.4)"); | |
2287 | break; | |
42dccab5 BP |
2288 | case OFP15_VERSION: |
2289 | ds_put_cstr(string, " (OF1.5)"); | |
2290 | break; | |
3811e66b BP |
2291 | default: |
2292 | ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version); | |
2293 | break; | |
2294 | } | |
2295 | ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid)); | |
bdcc5925 | 2296 | } |
d1e2cf21 | 2297 | |
f25b4a81 | 2298 | static void |
982697a4 BP |
2299 | ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw, |
2300 | struct ds *string) | |
f25b4a81 | 2301 | { |
982697a4 | 2302 | ds_put_cstr(string, ofpraw_get_name(raw)); |
f25b4a81 BP |
2303 | ofp_print_version(oh, string); |
2304 | } | |
2305 | ||
1c4c05af | 2306 | static void |
76c41209 | 2307 | ofp_print_bucket_id(struct ds *s, const char *label, uint32_t bucket_id, |
1c4c05af SH |
2308 | enum ofp_version ofp_version) |
2309 | { | |
2310 | if (ofp_version < OFP15_VERSION) { | |
2311 | return; | |
2312 | } | |
2313 | ||
76c41209 | 2314 | ds_put_cstr(s, label); |
1c4c05af SH |
2315 | |
2316 | switch (bucket_id) { | |
2317 | case OFPG15_BUCKET_FIRST: | |
2318 | ds_put_cstr(s, "first"); | |
2319 | break; | |
2320 | case OFPG15_BUCKET_LAST: | |
2321 | ds_put_cstr(s, "last"); | |
2322 | break; | |
2323 | case OFPG15_BUCKET_ALL: | |
2324 | ds_put_cstr(s, "all"); | |
2325 | break; | |
2326 | default: | |
2327 | ds_put_format(s, "%"PRIu32, bucket_id); | |
2328 | break; | |
2329 | } | |
2330 | ||
2331 | ds_put_char(s, ','); | |
2332 | } | |
2333 | ||
7395c052 NZ |
2334 | static void |
2335 | ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type, | |
53eb84a5 SH |
2336 | struct ovs_list *p_buckets, struct ofputil_group_props *props, |
2337 | enum ofp_version ofp_version, bool suppress_type) | |
7395c052 | 2338 | { |
7395c052 NZ |
2339 | struct ofputil_bucket *bucket; |
2340 | ||
76c41209 SH |
2341 | ds_put_format(s, "group_id=%"PRIu32, group_id); |
2342 | ||
2343 | if (!suppress_type) { | |
2344 | static const char *type_str[] = { "all", "select", "indirect", | |
2345 | "ff", "unknown" }; | |
2346 | ds_put_format(s, ",type=%s", type_str[type > 4 ? 4 : type]); | |
2347 | } | |
2348 | ||
53eb84a5 SH |
2349 | if (props->selection_method[0]) { |
2350 | size_t mark, start; | |
2351 | ||
2352 | ds_put_format(s, ",selection_method=%s,", props->selection_method); | |
2353 | if (props->selection_method_param) { | |
2354 | ds_put_format(s, "selection_method_param=%"PRIu64",", | |
2355 | props->selection_method_param); | |
2356 | } | |
2357 | ||
2358 | /* Allow rewinding to immediately before the trailing ',' */ | |
2359 | mark = s->length - 1; | |
2360 | ||
2361 | ds_put_cstr(s, "fields="); | |
2362 | start = s->length; | |
2363 | oxm_format_field_array(s, &props->fields); | |
2364 | if (s->length == start) { | |
2365 | ds_truncate(s, mark); | |
2366 | } | |
2367 | } | |
2368 | ||
7395c052 NZ |
2369 | if (!p_buckets) { |
2370 | return; | |
2371 | } | |
2372 | ||
76c41209 SH |
2373 | ds_put_char(s, ','); |
2374 | ||
7395c052 | 2375 | LIST_FOR_EACH (bucket, list_node, p_buckets) { |
76c41209 | 2376 | ds_put_cstr(s, "bucket="); |
7395c052 | 2377 | |
76c41209 | 2378 | ofp_print_bucket_id(s, "bucket_id:", bucket->bucket_id, ofp_version); |
64e8c446 | 2379 | if (bucket->weight != (type == OFPGT11_SELECT ? 1 : 0)) { |
7395c052 NZ |
2380 | ds_put_format(s, "weight:%"PRIu16",", bucket->weight); |
2381 | } | |
2382 | if (bucket->watch_port != OFPP_NONE) { | |
2383 | ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port); | |
2384 | } | |
2385 | if (bucket->watch_group != OFPG11_ANY) { | |
2386 | ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group); | |
2387 | } | |
2388 | ||
455ecd77 | 2389 | ds_put_cstr(s, "actions="); |
7395c052 | 2390 | ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s); |
76c41209 | 2391 | ds_put_char(s, ','); |
7395c052 | 2392 | } |
76c41209 SH |
2393 | |
2394 | ds_chomp(s, ','); | |
7395c052 NZ |
2395 | } |
2396 | ||
19187a71 BP |
2397 | static void |
2398 | ofp_print_ofpst_group_desc_request(struct ds *string, | |
2399 | const struct ofp_header *oh) | |
2400 | { | |
2401 | uint32_t group_id = ofputil_decode_group_desc_request(oh); | |
2402 | ds_put_cstr(string, " group_id="); | |
2403 | ofputil_format_group(group_id, string); | |
2404 | } | |
2405 | ||
7395c052 NZ |
2406 | static void |
2407 | ofp_print_group_desc(struct ds *s, const struct ofp_header *oh) | |
2408 | { | |
2409 | struct ofpbuf b; | |
2410 | ||
2411 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2412 | for (;;) { | |
2413 | struct ofputil_group_desc gd; | |
2414 | int retval; | |
2415 | ||
a7a2d006 | 2416 | retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version); |
7395c052 NZ |
2417 | if (retval) { |
2418 | if (retval != EOF) { | |
2419 | ds_put_cstr(s, " ***parse error***"); | |
2420 | } | |
2421 | break; | |
2422 | } | |
2423 | ||
2424 | ds_put_char(s, '\n'); | |
2425 | ds_put_char(s, ' '); | |
53eb84a5 SH |
2426 | ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, &gd.props, |
2427 | oh->version, false); | |
fa03bb9e | 2428 | ofputil_bucket_list_destroy(&gd.buckets); |
7395c052 NZ |
2429 | } |
2430 | } | |
2431 | ||
2432 | static void | |
2433 | ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh) | |
2434 | { | |
2435 | enum ofperr error; | |
2436 | uint32_t group_id; | |
2437 | ||
2438 | error = ofputil_decode_group_stats_request(oh, &group_id); | |
2439 | if (error) { | |
2440 | ofp_print_error(string, error); | |
2441 | return; | |
2442 | } | |
2443 | ||
2444 | ds_put_cstr(string, " group_id="); | |
2445 | ofputil_format_group(group_id, string); | |
2446 | } | |
2447 | ||
2448 | static void | |
2449 | ofp_print_group_stats(struct ds *s, const struct ofp_header *oh) | |
2450 | { | |
2451 | struct ofpbuf b; | |
2452 | uint32_t bucket_i; | |
2453 | ||
2454 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2455 | ||
2456 | for (;;) { | |
2457 | struct ofputil_group_stats gs; | |
2458 | int retval; | |
2459 | ||
2460 | retval = ofputil_decode_group_stats_reply(&b, &gs); | |
2461 | if (retval) { | |
2462 | if (retval != EOF) { | |
2463 | ds_put_cstr(s, " ***parse error***"); | |
2464 | } | |
2465 | break; | |
2466 | } | |
2467 | ||
2468 | ds_put_char(s, '\n'); | |
2469 | ||
2470 | ds_put_char(s, ' '); | |
2471 | ds_put_format(s, "group_id=%"PRIu32",", gs.group_id); | |
2472 | ||
2473 | if (gs.duration_sec != UINT32_MAX) { | |
2474 | ds_put_cstr(s, "duration="); | |
2475 | ofp_print_duration(s, gs.duration_sec, gs.duration_nsec); | |
2476 | ds_put_char(s, ','); | |
2477 | } | |
2478 | ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count); | |
2479 | ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count); | |
2480 | ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count); | |
2481 | ||
2482 | for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) { | |
2483 | if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) { | |
2484 | ds_put_format(s, ",bucket%"PRIu32":", bucket_i); | |
2485 | ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count); | |
2486 | ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count); | |
2487 | } | |
2488 | } | |
646b2a9c SH |
2489 | |
2490 | free(gs.bucket_stats); | |
7395c052 NZ |
2491 | } |
2492 | } | |
2493 | ||
08d1e234 BP |
2494 | static const char * |
2495 | group_type_to_string(enum ofp11_group_type type) | |
2496 | { | |
2497 | switch (type) { | |
2498 | case OFPGT11_ALL: return "all"; | |
2499 | case OFPGT11_SELECT: return "select"; | |
2500 | case OFPGT11_INDIRECT: return "indirect"; | |
2501 | case OFPGT11_FF: return "fast failover"; | |
2502 | default: OVS_NOT_REACHED(); | |
2503 | } | |
2504 | } | |
2505 | ||
7395c052 NZ |
2506 | static void |
2507 | ofp_print_group_features(struct ds *string, const struct ofp_header *oh) | |
2508 | { | |
2509 | struct ofputil_group_features features; | |
08d1e234 | 2510 | int i; |
7395c052 NZ |
2511 | |
2512 | ofputil_decode_group_features_reply(oh, &features); | |
2513 | ||
2514 | ds_put_format(string, "\n Group table:\n"); | |
2515 | ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types); | |
2516 | ds_put_format(string, " Capabilities: 0x%"PRIx32"\n", | |
2517 | features.capabilities); | |
2518 | ||
08d1e234 BP |
2519 | for (i = 0; i < OFPGT12_N_TYPES; i++) { |
2520 | if (features.types & (1u << i)) { | |
2521 | ds_put_format(string, " %s group:\n", group_type_to_string(i)); | |
2522 | ds_put_format(string, " max_groups=%#"PRIx32"\n", | |
2523 | features.max_groups[i]); | |
2524 | ds_put_format(string, " actions: "); | |
2525 | ofpact_bitmap_format(features.ofpacts[i], string); | |
2526 | ds_put_char(string, '\n'); | |
2527 | } | |
7395c052 NZ |
2528 | } |
2529 | } | |
2530 | ||
2531 | static void | |
2532 | ofp_print_group_mod(struct ds *s, const struct ofp_header *oh) | |
2533 | { | |
2534 | struct ofputil_group_mod gm; | |
2535 | int error; | |
76c41209 | 2536 | bool bucket_command = false; |
7395c052 NZ |
2537 | |
2538 | error = ofputil_decode_group_mod(oh, &gm); | |
2539 | if (error) { | |
2540 | ofp_print_error(s, error); | |
2541 | return; | |
2542 | } | |
2543 | ||
2544 | ds_put_char(s, '\n'); | |
2545 | ||
2546 | ds_put_char(s, ' '); | |
2547 | switch (gm.command) { | |
2548 | case OFPGC11_ADD: | |
2549 | ds_put_cstr(s, "ADD"); | |
2550 | break; | |
2551 | ||
2552 | case OFPGC11_MODIFY: | |
2553 | ds_put_cstr(s, "MOD"); | |
2554 | break; | |
2555 | ||
2556 | case OFPGC11_DELETE: | |
2557 | ds_put_cstr(s, "DEL"); | |
2558 | break; | |
2559 | ||
76c41209 SH |
2560 | case OFPGC15_INSERT_BUCKET: |
2561 | ds_put_cstr(s, "INSERT_BUCKET"); | |
2562 | bucket_command = true; | |
2563 | break; | |
2564 | ||
2565 | case OFPGC15_REMOVE_BUCKET: | |
2566 | ds_put_cstr(s, "REMOVE_BUCKET"); | |
2567 | bucket_command = true; | |
2568 | break; | |
2569 | ||
7395c052 NZ |
2570 | default: |
2571 | ds_put_format(s, "cmd:%"PRIu16"", gm.command); | |
2572 | } | |
2573 | ds_put_char(s, ' '); | |
2574 | ||
76c41209 SH |
2575 | if (bucket_command) { |
2576 | ofp_print_bucket_id(s, "command_bucket_id:", | |
2577 | gm.command_bucket_id, oh->version); | |
2578 | } | |
2579 | ||
53eb84a5 SH |
2580 | ofp_print_group(s, gm.group_id, gm.type, &gm.buckets, &gm.props, |
2581 | oh->version, bucket_command); | |
fa03bb9e | 2582 | ofputil_bucket_list_destroy(&gm.buckets); |
7395c052 NZ |
2583 | } |
2584 | ||
5deff5aa AW |
2585 | static void |
2586 | print_table_action_features(struct ds *s, | |
2587 | const struct ofputil_table_action_features *taf) | |
2588 | { | |
3c1bb396 BP |
2589 | if (taf->ofpacts) { |
2590 | ds_put_cstr(s, " actions: "); | |
2591 | ofpact_bitmap_format(taf->ofpacts, s); | |
2592 | ds_put_char(s, '\n'); | |
2593 | } | |
5deff5aa | 2594 | |
abadfcb0 | 2595 | if (!bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS)) { |
5deff5aa AW |
2596 | int i; |
2597 | ||
3c1bb396 | 2598 | ds_put_cstr(s, " supported on Set-Field:"); |
abadfcb0 | 2599 | BITMAP_FOR_EACH_1 (i, MFF_N_IDS, taf->set_fields.bm) { |
3c1bb396 | 2600 | ds_put_format(s, " %s", mf_from_id(i)->name); |
5deff5aa | 2601 | } |
3c1bb396 | 2602 | ds_put_char(s, '\n'); |
5deff5aa | 2603 | } |
5deff5aa AW |
2604 | } |
2605 | ||
2606 | static bool | |
2607 | table_action_features_equal(const struct ofputil_table_action_features *a, | |
2608 | const struct ofputil_table_action_features *b) | |
2609 | { | |
08d1e234 | 2610 | return (a->ofpacts == b->ofpacts |
abadfcb0 | 2611 | && bitmap_equal(a->set_fields.bm, b->set_fields.bm, MFF_N_IDS)); |
5deff5aa AW |
2612 | } |
2613 | ||
3c1bb396 BP |
2614 | static bool |
2615 | table_action_features_empty(const struct ofputil_table_action_features *taf) | |
2616 | { | |
2617 | return !taf->ofpacts && bitmap_is_all_zeros(taf->set_fields.bm, MFF_N_IDS); | |
2618 | } | |
2619 | ||
5deff5aa AW |
2620 | static void |
2621 | print_table_instruction_features( | |
8811fc0a BP |
2622 | struct ds *s, |
2623 | const struct ofputil_table_instruction_features *tif, | |
2624 | const struct ofputil_table_instruction_features *prev_tif) | |
5deff5aa AW |
2625 | { |
2626 | int start, end; | |
2627 | ||
3c1bb396 BP |
2628 | if (!bitmap_is_all_zeros(tif->next, 255)) { |
2629 | ds_put_cstr(s, " next tables: "); | |
2630 | for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255; | |
2631 | start = bitmap_scan(tif->next, 1, end, 255)) { | |
2632 | end = bitmap_scan(tif->next, 0, start + 1, 255); | |
2633 | if (end == start + 1) { | |
2634 | ds_put_format(s, "%d,", start); | |
2635 | } else { | |
2636 | ds_put_format(s, "%d-%d,", start, end - 1); | |
2637 | } | |
5deff5aa | 2638 | } |
3c1bb396 BP |
2639 | ds_chomp(s, ','); |
2640 | if (ds_last(s) == ' ') { | |
2641 | ds_put_cstr(s, "none"); | |
2642 | } | |
2643 | ds_put_char(s, '\n'); | |
5deff5aa | 2644 | } |
5deff5aa | 2645 | |
5deff5aa | 2646 | if (tif->instructions) { |
8811fc0a BP |
2647 | if (prev_tif && tif->instructions == prev_tif->instructions) { |
2648 | ds_put_cstr(s, " (same instructions)\n"); | |
2649 | } else { | |
2650 | ds_put_cstr(s, " instructions: "); | |
2651 | int i; | |
5deff5aa | 2652 | |
8811fc0a BP |
2653 | for (i = 0; i < 32; i++) { |
2654 | if (tif->instructions & (1u << i)) { | |
2655 | ds_put_format(s, "%s,", ovs_instruction_name_from_type(i)); | |
2656 | } | |
5deff5aa | 2657 | } |
8811fc0a BP |
2658 | ds_chomp(s, ','); |
2659 | ds_put_char(s, '\n'); | |
5deff5aa | 2660 | } |
5deff5aa | 2661 | } |
5deff5aa | 2662 | |
8811fc0a BP |
2663 | if (prev_tif |
2664 | && table_action_features_equal(&tif->write, &prev_tif->write) | |
2665 | && table_action_features_equal(&tif->apply, &prev_tif->apply) | |
2666 | && !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) { | |
2667 | ds_put_cstr(s, " (same actions)\n"); | |
2668 | } else if (!table_action_features_equal(&tif->write, &tif->apply)) { | |
5deff5aa AW |
2669 | ds_put_cstr(s, " Write-Actions features:\n"); |
2670 | print_table_action_features(s, &tif->write); | |
2671 | ds_put_cstr(s, " Apply-Actions features:\n"); | |
2672 | print_table_action_features(s, &tif->apply); | |
3c1bb396 BP |
2673 | } else if (tif->write.ofpacts |
2674 | || !bitmap_is_all_zeros(tif->write.set_fields.bm, MFF_N_IDS)) { | |
2675 | ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n"); | |
2676 | print_table_action_features(s, &tif->write); | |
5deff5aa AW |
2677 | } |
2678 | } | |
2679 | ||
2680 | static bool | |
2681 | table_instruction_features_equal( | |
2682 | const struct ofputil_table_instruction_features *a, | |
2683 | const struct ofputil_table_instruction_features *b) | |
2684 | { | |
2685 | return (bitmap_equal(a->next, b->next, 255) | |
2686 | && a->instructions == b->instructions | |
2687 | && table_action_features_equal(&a->write, &b->write) | |
2688 | && table_action_features_equal(&a->apply, &b->apply)); | |
2689 | } | |
2690 | ||
3c1bb396 BP |
2691 | static bool |
2692 | table_instruction_features_empty( | |
2693 | const struct ofputil_table_instruction_features *tif) | |
5deff5aa | 2694 | { |
3c1bb396 BP |
2695 | return (bitmap_is_all_zeros(tif->next, 255) |
2696 | && !tif->instructions | |
2697 | && table_action_features_empty(&tif->write) | |
2698 | && table_action_features_empty(&tif->apply)); | |
2699 | } | |
5deff5aa | 2700 | |
8811fc0a BP |
2701 | static bool |
2702 | table_features_equal(const struct ofputil_table_features *a, | |
2703 | const struct ofputil_table_features *b) | |
2704 | { | |
2705 | return (a->metadata_match == b->metadata_match | |
2706 | && a->metadata_write == b->metadata_write | |
2707 | && a->miss_config == b->miss_config | |
2708 | && a->supports_eviction == b->supports_eviction | |
2709 | && a->supports_vacancy_events == b->supports_vacancy_events | |
2710 | && a->max_entries == b->max_entries | |
2711 | && table_instruction_features_equal(&a->nonmiss, &b->nonmiss) | |
2712 | && table_instruction_features_equal(&a->miss, &b->miss) | |
2713 | && bitmap_equal(a->match.bm, b->match.bm, MFF_N_IDS)); | |
2714 | } | |
2715 | ||
2716 | static bool | |
2717 | table_features_empty(const struct ofputil_table_features *tf) | |
2718 | { | |
2719 | return (!tf->metadata_match | |
2720 | && !tf->metadata_write | |
2721 | && tf->miss_config == OFPUTIL_TABLE_MISS_DEFAULT | |
2722 | && tf->supports_eviction < 0 | |
2723 | && tf->supports_vacancy_events < 0 | |
2724 | && !tf->max_entries | |
2725 | && table_instruction_features_empty(&tf->nonmiss) | |
2726 | && table_instruction_features_empty(&tf->miss) | |
2727 | && bitmap_is_all_zeros(tf->match.bm, MFF_N_IDS)); | |
2728 | } | |
2729 | ||
2730 | static bool | |
2731 | table_stats_equal(const struct ofputil_table_stats *a, | |
2732 | const struct ofputil_table_stats *b) | |
2733 | { | |
2734 | return (a->active_count == b->active_count | |
2735 | && a->lookup_count == b->lookup_count | |
2736 | && a->matched_count == b->matched_count); | |
2737 | } | |
2738 | ||
2739 | void | |
3c1bb396 BP |
2740 | ofp_print_table_features(struct ds *s, |
2741 | const struct ofputil_table_features *features, | |
8811fc0a BP |
2742 | const struct ofputil_table_features *prev_features, |
2743 | const struct ofputil_table_stats *stats, | |
2744 | const struct ofputil_table_stats *prev_stats) | |
3c1bb396 BP |
2745 | { |
2746 | int i; | |
5deff5aa | 2747 | |
8811fc0a | 2748 | ds_put_format(s, " table %"PRIu8, features->table_id); |
3c1bb396 BP |
2749 | if (features->name[0]) { |
2750 | ds_put_format(s, " (\"%s\")", features->name); | |
2751 | } | |
8811fc0a BP |
2752 | ds_put_char(s, ':'); |
2753 | ||
2754 | bool same_stats = prev_stats && table_stats_equal(stats, prev_stats); | |
2755 | bool same_features = prev_features && table_features_equal(features, | |
2756 | prev_features); | |
2757 | if ((!stats || same_stats) && (!features || same_features)) { | |
2758 | ds_put_cstr(s, " ditto"); | |
2759 | return; | |
2760 | } | |
2761 | ds_put_char(s, '\n'); | |
3c1bb396 BP |
2762 | if (stats) { |
2763 | ds_put_format(s, " active=%"PRIu32", ", stats->active_count); | |
2764 | ds_put_format(s, "lookup=%"PRIu64", ", stats->lookup_count); | |
2765 | ds_put_format(s, "matched=%"PRIu64"\n", stats->matched_count); | |
2766 | } | |
8811fc0a BP |
2767 | if (same_features) { |
2768 | if (!table_features_empty(features)) { | |
2769 | ds_put_cstr(s, " (same features)\n"); | |
2770 | } | |
2771 | return; | |
2772 | } | |
2773 | if (features->metadata_match || features->metadata_write) { | |
5deff5aa | 2774 | ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n", |
3c1bb396 BP |
2775 | ntohll(features->metadata_match), |
2776 | ntohll(features->metadata_write)); | |
2777 | } | |
5deff5aa | 2778 | |
3c1bb396 | 2779 | if (features->miss_config != OFPUTIL_TABLE_MISS_DEFAULT) { |
82c22d34 BP |
2780 | ds_put_format(s, " config=%s\n", |
2781 | ofputil_table_miss_to_string(features->miss_config)); | |
2782 | } | |
2783 | ||
2784 | if (features->supports_eviction >= 0) { | |
2785 | ds_put_format(s, " eviction: %ssupported\n", | |
2786 | features->supports_eviction ? "" : "not "); | |
2787 | ||
2788 | } | |
2789 | if (features->supports_vacancy_events >= 0) { | |
2790 | ds_put_format(s, " vacancy events: %ssupported\n", | |
2791 | features->supports_vacancy_events ? "" : "not "); | |
2792 | ||
3c1bb396 | 2793 | } |
5deff5aa | 2794 | |
3c1bb396 BP |
2795 | if (features->max_entries) { |
2796 | ds_put_format(s, " max_entries=%"PRIu32"\n", features->max_entries); | |
2797 | } | |
5deff5aa | 2798 | |
8811fc0a BP |
2799 | const struct ofputil_table_instruction_features *prev_nonmiss |
2800 | = prev_features ? &prev_features->nonmiss : NULL; | |
2801 | const struct ofputil_table_instruction_features *prev_miss | |
2802 | = prev_features ? &prev_features->miss : NULL; | |
2803 | if (prev_features | |
2804 | && table_instruction_features_equal(&features->nonmiss, prev_nonmiss) | |
2805 | && table_instruction_features_equal(&features->miss, prev_miss)) { | |
2806 | if (!table_instruction_features_empty(&features->nonmiss)) { | |
2807 | ds_put_cstr(s, " (same instructions)\n"); | |
2808 | } | |
2809 | } else if (!table_instruction_features_equal(&features->nonmiss, | |
2810 | &features->miss)) { | |
3c1bb396 | 2811 | ds_put_cstr(s, " instructions (other than table miss):\n"); |
8811fc0a | 2812 | print_table_instruction_features(s, &features->nonmiss, prev_nonmiss); |
3c1bb396 | 2813 | ds_put_cstr(s, " instructions (table miss):\n"); |
8811fc0a | 2814 | print_table_instruction_features(s, &features->miss, prev_miss); |
3c1bb396 BP |
2815 | } else if (!table_instruction_features_empty(&features->nonmiss)) { |
2816 | ds_put_cstr(s, " instructions (table miss and others):\n"); | |
8811fc0a | 2817 | print_table_instruction_features(s, &features->nonmiss, prev_nonmiss); |
3c1bb396 | 2818 | } |
5deff5aa | 2819 | |
8811fc0a BP |
2820 | if (!bitmap_is_all_zeros(features->match.bm, MFF_N_IDS)) { |
2821 | if (prev_features | |
2822 | && bitmap_equal(features->match.bm, prev_features->match.bm, | |
2823 | MFF_N_IDS)) { | |
2824 | ds_put_cstr(s, " (same matching)\n"); | |
2825 | } else { | |
2826 | ds_put_cstr(s, " matching:\n"); | |
2827 | BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) { | |
2828 | const struct mf_field *f = mf_from_id(i); | |
2829 | bool mask = bitmap_is_set(features->mask.bm, i); | |
2830 | bool wildcard = bitmap_is_set(features->wildcard.bm, i); | |
2831 | ||
2832 | ds_put_format(s, " %s: %s\n", | |
2833 | f->name, | |
2834 | (mask ? "arbitrary mask" | |
2835 | : wildcard ? "exact match or wildcard" | |
2836 | : "must exact match")); | |
2837 | } | |
5deff5aa AW |
2838 | } |
2839 | } | |
2840 | } | |
2841 | ||
3c1bb396 BP |
2842 | static void |
2843 | ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh) | |
2844 | { | |
2845 | struct ofpbuf b; | |
2846 | ||
2847 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2848 | ||
8811fc0a BP |
2849 | struct ofputil_table_features prev; |
2850 | for (int i = 0; ; i++) { | |
3c1bb396 BP |
2851 | struct ofputil_table_features tf; |
2852 | int retval; | |
2853 | ||
2854 | retval = ofputil_decode_table_features(&b, &tf, true); | |
2855 | if (retval) { | |
2856 | if (retval != EOF) { | |
2857 | ofp_print_error(s, retval); | |
2858 | } | |
2859 | return; | |
2860 | } | |
8811fc0a BP |
2861 | |
2862 | ds_put_char(s, '\n'); | |
2863 | ofp_print_table_features(s, &tf, i ? &prev : NULL, NULL, NULL); | |
2864 | prev = tf; | |
3c1bb396 BP |
2865 | } |
2866 | } | |
2867 | ||
03c72922 BP |
2868 | static void |
2869 | ofp_print_table_desc_reply(struct ds *s, const struct ofp_header *oh) | |
2870 | { | |
2871 | struct ofpbuf b; | |
2872 | ||
2873 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2874 | ||
2875 | for (;;) { | |
2876 | struct ofputil_table_desc td; | |
2877 | int retval; | |
2878 | ||
2879 | retval = ofputil_decode_table_desc(&b, &td, oh->version); | |
2880 | if (retval) { | |
2881 | if (retval != EOF) { | |
2882 | ofp_print_error(s, retval); | |
2883 | } | |
2884 | return; | |
2885 | } | |
2886 | ofp_print_table_desc(s, &td); | |
2887 | } | |
2888 | } | |
2889 | ||
777af88d AC |
2890 | static const char * |
2891 | bundle_flags_to_name(uint32_t bit) | |
2892 | { | |
2893 | switch (bit) { | |
2894 | case OFPBF_ATOMIC: | |
2895 | return "atomic"; | |
2896 | case OFPBF_ORDERED: | |
2897 | return "ordered"; | |
2898 | default: | |
2899 | return NULL; | |
2900 | } | |
2901 | } | |
2902 | ||
2903 | static void | |
2904 | ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh) | |
2905 | { | |
2906 | int error; | |
2907 | struct ofputil_bundle_ctrl_msg bctrl; | |
2908 | ||
2909 | error = ofputil_decode_bundle_ctrl(oh, &bctrl); | |
2910 | if (error) { | |
2911 | ofp_print_error(s, error); | |
2912 | return; | |
2913 | } | |
2914 | ||
2915 | ds_put_char(s, '\n'); | |
2916 | ||
2917 | ds_put_format(s, " bundle_id=%#"PRIx32" type=", bctrl.bundle_id); | |
2918 | switch (bctrl.type) { | |
2919 | case OFPBCT_OPEN_REQUEST: | |
2920 | ds_put_cstr(s, "OPEN_REQUEST"); | |
2921 | break; | |
2922 | case OFPBCT_OPEN_REPLY: | |
2923 | ds_put_cstr(s, "OPEN_REPLY"); | |
2924 | break; | |
2925 | case OFPBCT_CLOSE_REQUEST: | |
2926 | ds_put_cstr(s, "CLOSE_REQUEST"); | |
2927 | break; | |
2928 | case OFPBCT_CLOSE_REPLY: | |
2929 | ds_put_cstr(s, "CLOSE_REPLY"); | |
2930 | break; | |
2931 | case OFPBCT_COMMIT_REQUEST: | |
2932 | ds_put_cstr(s, "COMMIT_REQUEST"); | |
2933 | break; | |
2934 | case OFPBCT_COMMIT_REPLY: | |
2935 | ds_put_cstr(s, "COMMIT_REPLY"); | |
2936 | break; | |
2937 | case OFPBCT_DISCARD_REQUEST: | |
2938 | ds_put_cstr(s, "DISCARD_REQUEST"); | |
2939 | break; | |
2940 | case OFPBCT_DISCARD_REPLY: | |
2941 | ds_put_cstr(s, "DISCARD_REPLY"); | |
2942 | break; | |
2943 | } | |
2944 | ||
2945 | ds_put_cstr(s, " flags="); | |
2946 | ofp_print_bit_names(s, bctrl.flags, bundle_flags_to_name, ' '); | |
2947 | } | |
2948 | ||
2949 | static void | |
2950 | ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity) | |
2951 | { | |
2952 | int error; | |
2953 | struct ofputil_bundle_add_msg badd; | |
2954 | char *msg; | |
2955 | ||
7ac27a04 | 2956 | error = ofputil_decode_bundle_add(oh, &badd, NULL); |
777af88d AC |
2957 | if (error) { |
2958 | ofp_print_error(s, error); | |
2959 | return; | |
2960 | } | |
2961 | ||
2962 | ds_put_char(s, '\n'); | |
2963 | ds_put_format(s, " bundle_id=%#"PRIx32, badd.bundle_id); | |
2964 | ds_put_cstr(s, " flags="); | |
2965 | ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' '); | |
2966 | ||
2967 | ds_put_char(s, '\n'); | |
2968 | msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity); | |
2969 | if (msg) { | |
2970 | ds_put_cstr(s, msg); | |
2971 | } | |
2972 | } | |
2973 | ||
6159c531 JG |
2974 | static void |
2975 | print_geneve_table(struct ds *s, struct ovs_list *mappings) | |
2976 | { | |
2977 | struct ofputil_geneve_map *map; | |
2978 | ||
2979 | ds_put_cstr(s, " mapping table:\n"); | |
2980 | ds_put_cstr(s, " class\ttype\tlength\tmatch field\n"); | |
2981 | ds_put_cstr(s, " -----\t----\t------\t-----------"); | |
2982 | ||
2983 | LIST_FOR_EACH (map, list_node, mappings) { | |
2984 | ds_put_char(s, '\n'); | |
2985 | ds_put_format(s, " 0x%"PRIx16"\t0x%"PRIx8"\t%"PRIu8"\ttun_metadata%"PRIu16, | |
2986 | map->option_class, map->option_type, map->option_len, | |
2987 | map->index); | |
2988 | } | |
2989 | } | |
2990 | ||
2991 | static void | |
2992 | ofp_print_geneve_table_mod(struct ds *s, const struct ofp_header *oh) | |
2993 | { | |
2994 | int error; | |
2995 | struct ofputil_geneve_table_mod gtm; | |
2996 | ||
2997 | error = ofputil_decode_geneve_table_mod(oh, >m); | |
2998 | if (error) { | |
2999 | ofp_print_error(s, error); | |
3000 | return; | |
3001 | } | |
3002 | ||
3003 | ds_put_cstr(s, "\n "); | |
3004 | ||
3005 | switch (gtm.command) { | |
3006 | case NXGTMC_ADD: | |
3007 | ds_put_cstr(s, "ADD"); | |
3008 | break; | |
3009 | case NXGTMC_DELETE: | |
3010 | ds_put_cstr(s, "DEL"); | |
3011 | break; | |
3012 | case NXGTMC_CLEAR: | |
3013 | ds_put_cstr(s, "CLEAR"); | |
3014 | break; | |
3015 | } | |
3016 | ||
3017 | if (gtm.command != NXGTMC_CLEAR) { | |
3018 | print_geneve_table(s, >m.mappings); | |
3019 | } | |
3020 | ||
3021 | ofputil_uninit_geneve_table(>m.mappings); | |
3022 | } | |
3023 | ||
3024 | static void | |
3025 | ofp_print_geneve_table_reply(struct ds *s, const struct ofp_header *oh) | |
3026 | { | |
3027 | int error; | |
3028 | struct ofputil_geneve_table_reply gtr; | |
3029 | struct ofputil_geneve_map *map; | |
3030 | int allocated_space = 0; | |
3031 | ||
3032 | error = ofputil_decode_geneve_table_reply(oh, >r); | |
3033 | if (error) { | |
3034 | ofp_print_error(s, error); | |
3035 | return; | |
3036 | } | |
3037 | ||
3038 | ds_put_char(s, '\n'); | |
3039 | ||
3040 | LIST_FOR_EACH (map, list_node, >r.mappings) { | |
3041 | allocated_space += map->option_len; | |
3042 | } | |
3043 | ||
3044 | ds_put_format(s, " max option space=%"PRIu32" max fields=%"PRIu16"\n", | |
3045 | gtr.max_option_space, gtr.max_fields); | |
3046 | ds_put_format(s, " allocated option space=%d\n", allocated_space); | |
3047 | ds_put_char(s, '\n'); | |
3048 | print_geneve_table(s, >r.mappings); | |
3049 | ||
3050 | ofputil_uninit_geneve_table(>r.mappings); | |
3051 | } | |
3052 | ||
bdcc5925 | 3053 | static void |
982697a4 BP |
3054 | ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw, |
3055 | struct ds *string, int verbosity) | |
bdcc5925 | 3056 | { |
bdcc5925 BP |
3057 | const void *msg = oh; |
3058 | ||
982697a4 BP |
3059 | ofp_header_to_string__(oh, raw, string); |
3060 | switch (ofptype_from_ofpraw(raw)) { | |
2e1ae200 | 3061 | |
261bd854 | 3062 | case OFPTYPE_GROUP_STATS_REQUEST: |
5d40fc57 | 3063 | ofp_print_stats(string, oh); |
7395c052 NZ |
3064 | ofp_print_ofpst_group_request(string, oh); |
3065 | break; | |
3066 | ||
261bd854 | 3067 | case OFPTYPE_GROUP_STATS_REPLY: |
7395c052 NZ |
3068 | ofp_print_group_stats(string, oh); |
3069 | break; | |
3070 | ||
261bd854 | 3071 | case OFPTYPE_GROUP_DESC_STATS_REQUEST: |
5d40fc57 | 3072 | ofp_print_stats(string, oh); |
19187a71 | 3073 | ofp_print_ofpst_group_desc_request(string, oh); |
7395c052 NZ |
3074 | break; |
3075 | ||
261bd854 | 3076 | case OFPTYPE_GROUP_DESC_STATS_REPLY: |
7395c052 NZ |
3077 | ofp_print_group_desc(string, oh); |
3078 | break; | |
3079 | ||
261bd854 | 3080 | case OFPTYPE_GROUP_FEATURES_STATS_REQUEST: |
5d40fc57 | 3081 | ofp_print_stats(string, oh); |
7395c052 NZ |
3082 | break; |
3083 | ||
261bd854 | 3084 | case OFPTYPE_GROUP_FEATURES_STATS_REPLY: |
7395c052 NZ |
3085 | ofp_print_group_features(string, oh); |
3086 | break; | |
3087 | ||
3088 | case OFPTYPE_GROUP_MOD: | |
3089 | ofp_print_group_mod(string, oh); | |
3090 | break; | |
3091 | ||
261bd854 BP |
3092 | case OFPTYPE_TABLE_FEATURES_STATS_REQUEST: |
3093 | case OFPTYPE_TABLE_FEATURES_STATS_REPLY: | |
3c1bb396 | 3094 | ofp_print_table_features_reply(string, oh); |
2e1ae200 JR |
3095 | break; |
3096 | ||
03c72922 BP |
3097 | case OFPTYPE_TABLE_DESC_REQUEST: |
3098 | case OFPTYPE_TABLE_DESC_REPLY: | |
3099 | ofp_print_table_desc_reply(string, oh); | |
3100 | break; | |
3101 | ||
982697a4 | 3102 | case OFPTYPE_HELLO: |
de6c85b0 | 3103 | ofp_print_hello(string, oh); |
d1e2cf21 BP |
3104 | break; |
3105 | ||
982697a4 BP |
3106 | case OFPTYPE_ERROR: |
3107 | ofp_print_error_msg(string, oh); | |
d1e2cf21 BP |
3108 | break; |
3109 | ||
982697a4 BP |
3110 | case OFPTYPE_ECHO_REQUEST: |
3111 | case OFPTYPE_ECHO_REPLY: | |
d1e2cf21 BP |
3112 | ofp_print_echo(string, oh, verbosity); |
3113 | break; | |
3114 | ||
982697a4 | 3115 | case OFPTYPE_FEATURES_REQUEST: |
d1e2cf21 BP |
3116 | break; |
3117 | ||
982697a4 BP |
3118 | case OFPTYPE_FEATURES_REPLY: |
3119 | ofp_print_switch_features(string, oh); | |
d1e2cf21 BP |
3120 | break; |
3121 | ||
982697a4 | 3122 | case OFPTYPE_GET_CONFIG_REQUEST: |
d1e2cf21 BP |
3123 | break; |
3124 | ||
982697a4 BP |
3125 | case OFPTYPE_GET_CONFIG_REPLY: |
3126 | case OFPTYPE_SET_CONFIG: | |
3127 | ofp_print_switch_config(string, ofpmsg_body(oh)); | |
d1e2cf21 BP |
3128 | break; |
3129 | ||
982697a4 BP |
3130 | case OFPTYPE_PACKET_IN: |
3131 | ofp_print_packet_in(string, oh, verbosity); | |
d1e2cf21 BP |
3132 | break; |
3133 | ||
982697a4 BP |
3134 | case OFPTYPE_FLOW_REMOVED: |
3135 | ofp_print_flow_removed(string, oh); | |
d1e2cf21 BP |
3136 | break; |
3137 | ||
982697a4 BP |
3138 | case OFPTYPE_PORT_STATUS: |
3139 | ofp_print_port_status(string, oh); | |
d1e2cf21 BP |
3140 | break; |
3141 | ||
982697a4 BP |
3142 | case OFPTYPE_PACKET_OUT: |
3143 | ofp_print_packet_out(string, oh, verbosity); | |
d1e2cf21 BP |
3144 | break; |
3145 | ||
982697a4 BP |
3146 | case OFPTYPE_FLOW_MOD: |
3147 | ofp_print_flow_mod(string, oh, verbosity); | |
d1e2cf21 BP |
3148 | break; |
3149 | ||
982697a4 BP |
3150 | case OFPTYPE_PORT_MOD: |
3151 | ofp_print_port_mod(string, oh); | |
d1e2cf21 BP |
3152 | break; |
3153 | ||
918f2b82 AZ |
3154 | case OFPTYPE_TABLE_MOD: |
3155 | ofp_print_table_mod(string, oh); | |
3156 | break; | |
3157 | ||
638a19b0 JR |
3158 | case OFPTYPE_METER_MOD: |
3159 | ofp_print_meter_mod(string, oh); | |
3160 | break; | |
3161 | ||
982697a4 BP |
3162 | case OFPTYPE_BARRIER_REQUEST: |
3163 | case OFPTYPE_BARRIER_REPLY: | |
d1e2cf21 BP |
3164 | break; |
3165 | ||
e8f9a7bb VG |
3166 | case OFPTYPE_QUEUE_GET_CONFIG_REQUEST: |
3167 | ofp_print_queue_get_config_request(string, oh); | |
3168 | break; | |
3169 | ||
3170 | case OFPTYPE_QUEUE_GET_CONFIG_REPLY: | |
3171 | ofp_print_queue_get_config_reply(string, oh); | |
3172 | break; | |
3173 | ||
6ea4776b JR |
3174 | case OFPTYPE_ROLE_REQUEST: |
3175 | case OFPTYPE_ROLE_REPLY: | |
3176 | ofp_print_role_message(string, oh); | |
3177 | break; | |
252f3411 | 3178 | case OFPTYPE_ROLE_STATUS: |
00467f73 | 3179 | ofp_print_role_status_message(string, oh); |
252f3411 | 3180 | break; |
6ea4776b | 3181 | |
261bd854 BP |
3182 | case OFPTYPE_METER_STATS_REQUEST: |
3183 | case OFPTYPE_METER_CONFIG_STATS_REQUEST: | |
5d40fc57 | 3184 | ofp_print_stats(string, oh); |
638a19b0 JR |
3185 | ofp_print_meter_stats_request(string, oh); |
3186 | break; | |
3187 | ||
261bd854 | 3188 | case OFPTYPE_METER_STATS_REPLY: |
5d40fc57 | 3189 | ofp_print_stats(string, oh); |
638a19b0 JR |
3190 | ofp_print_meter_stats_reply(string, oh); |
3191 | break; | |
3192 | ||
261bd854 | 3193 | case OFPTYPE_METER_CONFIG_STATS_REPLY: |
5d40fc57 | 3194 | ofp_print_stats(string, oh); |
638a19b0 JR |
3195 | ofp_print_meter_config_reply(string, oh); |
3196 | break; | |
3197 | ||
261bd854 | 3198 | case OFPTYPE_METER_FEATURES_STATS_REPLY: |
5d40fc57 | 3199 | ofp_print_stats(string, oh); |
638a19b0 JR |
3200 | ofp_print_meter_features_reply(string, oh); |
3201 | break; | |
3202 | ||
982697a4 | 3203 | case OFPTYPE_DESC_STATS_REQUEST: |
261bd854 | 3204 | case OFPTYPE_METER_FEATURES_STATS_REQUEST: |
5d40fc57 | 3205 | ofp_print_stats(string, oh); |
d1e2cf21 BP |
3206 | break; |
3207 | ||
982697a4 BP |
3208 | case OFPTYPE_FLOW_STATS_REQUEST: |
3209 | case OFPTYPE_AGGREGATE_STATS_REQUEST: | |
5d40fc57 | 3210 | ofp_print_stats(string, oh); |
982697a4 | 3211 | ofp_print_flow_stats_request(string, oh); |
d1e2cf21 BP |
3212 | break; |
3213 | ||
982697a4 | 3214 | case OFPTYPE_TABLE_STATS_REQUEST: |
5d40fc57 | 3215 | ofp_print_stats(string, oh); |
d1e2cf21 BP |
3216 | break; |
3217 | ||
982697a4 | 3218 | case OFPTYPE_PORT_STATS_REQUEST: |
5d40fc57 | 3219 | ofp_print_stats(string, oh); |
982697a4 | 3220 | ofp_print_ofpst_port_request(string, oh); |
d1e2cf21 BP |
3221 | break; |
3222 | ||
982697a4 | 3223 | case OFPTYPE_QUEUE_STATS_REQUEST: |
5d40fc57 | 3224 | ofp_print_stats(string, oh); |
982697a4 | 3225 | ofp_print_ofpst_queue_request(string, oh); |
d1e2cf21 BP |
3226 | break; |
3227 | ||
982697a4 | 3228 | case OFPTYPE_DESC_STATS_REPLY: |
5d40fc57 | 3229 | ofp_print_stats(string, oh); |
982697a4 | 3230 | ofp_print_ofpst_desc_reply(string, oh); |
d1e2cf21 BP |
3231 | break; |
3232 | ||
982697a4 | 3233 | case OFPTYPE_FLOW_STATS_REPLY: |
5d40fc57 | 3234 | ofp_print_stats(string, oh); |
4ffd1b43 | 3235 | ofp_print_flow_stats_reply(string, oh); |
d1e2cf21 BP |
3236 | break; |
3237 | ||
982697a4 | 3238 | case OFPTYPE_QUEUE_STATS_REPLY: |
5d40fc57 | 3239 | ofp_print_stats(string, oh); |
d1e2cf21 BP |
3240 | ofp_print_ofpst_queue_reply(string, oh, verbosity); |
3241 | break; | |
3242 | ||
982697a4 | 3243 | case OFPTYPE_PORT_STATS_REPLY: |
5d40fc57 | 3244 | ofp_print_stats(string, oh); |
d1e2cf21 BP |
3245 | ofp_print_ofpst_port_reply(string, oh, verbosity); |
3246 | break; | |
3247 | ||
982697a4 | 3248 | case OFPTYPE_TABLE_STATS_REPLY: |
5d40fc57 | 3249 | ofp_print_stats(string, oh); |
3c1bb396 | 3250 | ofp_print_table_stats_reply(string, oh); |
d1e2cf21 BP |
3251 | break; |
3252 | ||
982697a4 | 3253 | case OFPTYPE_AGGREGATE_STATS_REPLY: |
5d40fc57 | 3254 | ofp_print_stats(string, oh); |
982697a4 | 3255 | ofp_print_aggregate_stats_reply(string, oh); |
d1e2cf21 | 3256 | break; |
064af421 | 3257 | |
70ae4f93 | 3258 | case OFPTYPE_PORT_DESC_STATS_REQUEST: |
5d40fc57 | 3259 | ofp_print_stats(string, oh); |
70ae4f93 BP |
3260 | ofp_print_ofpst_port_desc_request(string, oh); |
3261 | break; | |
3262 | ||
982697a4 | 3263 | case OFPTYPE_PORT_DESC_STATS_REPLY: |
5d40fc57 | 3264 | ofp_print_stats(string, oh); |
2be393ed JP |
3265 | ofp_print_ofpst_port_desc_reply(string, oh); |
3266 | break; | |
3267 | ||
982697a4 BP |
3268 | case OFPTYPE_FLOW_MOD_TABLE_ID: |
3269 | ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh)); | |
6c1491fb BP |
3270 | break; |
3271 | ||
982697a4 BP |
3272 | case OFPTYPE_SET_FLOW_FORMAT: |
3273 | ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh)); | |
7fa91113 BP |
3274 | break; |
3275 | ||
982697a4 BP |
3276 | case OFPTYPE_SET_PACKET_IN_FORMAT: |
3277 | ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh)); | |
54834960 EJ |
3278 | break; |
3279 | ||
982697a4 | 3280 | case OFPTYPE_FLOW_AGE: |
f27f2134 BP |
3281 | break; |
3282 | ||
982697a4 BP |
3283 | case OFPTYPE_SET_CONTROLLER_ID: |
3284 | ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh)); | |
a7349929 BP |
3285 | break; |
3286 | ||
db09e430 | 3287 | case OFPTYPE_GET_ASYNC_REPLY: |
982697a4 | 3288 | case OFPTYPE_SET_ASYNC_CONFIG: |
98090482 | 3289 | ofp_print_nxt_set_async_config(string, oh); |
d1e2cf21 | 3290 | break; |
db09e430 AC |
3291 | case OFPTYPE_GET_ASYNC_REQUEST: |
3292 | break; | |
982697a4 | 3293 | case OFPTYPE_FLOW_MONITOR_CANCEL: |
2b07c8b1 BP |
3294 | ofp_print_nxt_flow_monitor_cancel(string, msg); |
3295 | break; | |
3296 | ||
982697a4 BP |
3297 | case OFPTYPE_FLOW_MONITOR_PAUSED: |
3298 | case OFPTYPE_FLOW_MONITOR_RESUMED: | |
2b07c8b1 BP |
3299 | break; |
3300 | ||
982697a4 | 3301 | case OFPTYPE_FLOW_MONITOR_STATS_REQUEST: |
2b07c8b1 BP |
3302 | ofp_print_nxst_flow_monitor_request(string, msg); |
3303 | break; | |
3304 | ||
982697a4 | 3305 | case OFPTYPE_FLOW_MONITOR_STATS_REPLY: |
2b07c8b1 BP |
3306 | ofp_print_nxst_flow_monitor_reply(string, msg); |
3307 | break; | |
777af88d AC |
3308 | |
3309 | case OFPTYPE_BUNDLE_CONTROL: | |
3310 | ofp_print_bundle_ctrl(string, msg); | |
3311 | break; | |
3312 | ||
3313 | case OFPTYPE_BUNDLE_ADD_MESSAGE: | |
3314 | ofp_print_bundle_add(string, msg, verbosity); | |
3315 | break; | |
6159c531 JG |
3316 | |
3317 | case OFPTYPE_NXT_GENEVE_TABLE_MOD: | |
3318 | ofp_print_geneve_table_mod(string, msg); | |
3319 | break; | |
3320 | ||
3321 | case OFPTYPE_NXT_GENEVE_TABLE_REQUEST: | |
3322 | break; | |
3323 | ||
3324 | case OFPTYPE_NXT_GENEVE_TABLE_REPLY: | |
3325 | ofp_print_geneve_table_reply(string, msg); | |
3326 | break; | |
3327 | ||
246e61ea | 3328 | } |
d1e2cf21 | 3329 | } |
064af421 BP |
3330 | |
3331 | /* Composes and returns a string representing the OpenFlow packet of 'len' | |
3332 | * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of | |
3333 | * verbosity and higher numbers increase verbosity. The caller is responsible | |
3334 | * for freeing the string. */ | |
3335 | char * | |
3336 | ofp_to_string(const void *oh_, size_t len, int verbosity) | |
3337 | { | |
3338 | struct ds string = DS_EMPTY_INITIALIZER; | |
3339 | const struct ofp_header *oh = oh_; | |
064af421 | 3340 | |
49ad0403 BP |
3341 | if (!len) { |
3342 | ds_put_cstr(&string, "OpenFlow message is empty\n"); | |
3343 | } else if (len < sizeof(struct ofp_header)) { | |
34582733 | 3344 | ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n", |
49ad0403 | 3345 | len); |
d1e2cf21 | 3346 | } else if (ntohs(oh->length) > len) { |
f25b4a81 | 3347 | enum ofperr error; |
982697a4 | 3348 | enum ofpraw raw; |
f25b4a81 | 3349 | |
982697a4 | 3350 | error = ofpraw_decode_partial(&raw, oh, len); |
f25b4a81 | 3351 | if (!error) { |
982697a4 | 3352 | ofp_header_to_string__(oh, raw, &string); |
f25b4a81 BP |
3353 | ds_put_char(&string, '\n'); |
3354 | } | |
3355 | ||
d1e2cf21 | 3356 | ds_put_format(&string, |
34582733 | 3357 | "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n", |
d1e2cf21 BP |
3358 | len, ntohs(oh->length)); |
3359 | } else if (ntohs(oh->length) < len) { | |
3360 | ds_put_format(&string, | |
34582733 | 3361 | "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n", |
d1e2cf21 BP |
3362 | ntohs(oh->length), len); |
3363 | } else { | |
90bf1e07 | 3364 | enum ofperr error; |
982697a4 | 3365 | enum ofpraw raw; |
d1e2cf21 | 3366 | |
982697a4 | 3367 | error = ofpraw_decode(&raw, oh); |
d1e2cf21 | 3368 | if (!error) { |
982697a4 | 3369 | ofp_to_string__(oh, raw, &string, verbosity); |
7fa91113 BP |
3370 | if (verbosity >= 5) { |
3371 | if (ds_last(&string) != '\n') { | |
3372 | ds_put_char(&string, '\n'); | |
3373 | } | |
d1e2cf21 BP |
3374 | ds_put_hex_dump(&string, oh, len, 0, true); |
3375 | } | |
7fa91113 | 3376 | if (ds_last(&string) != '\n') { |
d1e2cf21 BP |
3377 | ds_put_char(&string, '\n'); |
3378 | } | |
3379 | return ds_steal_cstr(&string); | |
064af421 | 3380 | } |
064af421 | 3381 | |
7fa91113 | 3382 | ofp_print_error(&string, error); |
064af421 | 3383 | } |
d1e2cf21 BP |
3384 | ds_put_hex_dump(&string, oh, len, 0, true); |
3385 | return ds_steal_cstr(&string); | |
064af421 | 3386 | } |
064af421 BP |
3387 | \f |
3388 | static void | |
d295e8e9 | 3389 | print_and_free(FILE *stream, char *string) |
064af421 BP |
3390 | { |
3391 | fputs(string, stream); | |
3392 | free(string); | |
3393 | } | |
3394 | ||
3395 | /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the | |
3396 | * given 'verbosity' level. 0 is a minimal amount of verbosity and higher | |
3397 | * numbers increase verbosity. */ | |
3398 | void | |
3399 | ofp_print(FILE *stream, const void *oh, size_t len, int verbosity) | |
3400 | { | |
3401 | print_and_free(stream, ofp_to_string(oh, len, verbosity)); | |
3402 | } | |
3403 | ||
3404 | /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at | |
897a8e07 | 3405 | * 'data' to 'stream'. */ |
064af421 | 3406 | void |
c499c75d | 3407 | ofp_print_packet(FILE *stream, const void *data, size_t len) |
064af421 | 3408 | { |
c499c75d | 3409 | print_and_free(stream, ofp_packet_to_string(data, len)); |
064af421 | 3410 | } |