/src/openvswitch/lib/ofp-print.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2008-2017 Nicira, Inc. |
3 | | * |
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: |
7 | | * |
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. |
15 | | */ |
16 | | |
17 | | #include <config.h> |
18 | | |
19 | | #include "openvswitch/ofp-print.h" |
20 | | |
21 | | #include <errno.h> |
22 | | #include <inttypes.h> |
23 | | #include <sys/types.h> |
24 | | #include <netinet/in.h> |
25 | | #include <sys/wait.h> |
26 | | #include <stdarg.h> |
27 | | #include <stdlib.h> |
28 | | #include <ctype.h> |
29 | | |
30 | | #include "bundle.h" |
31 | | #include "byte-order.h" |
32 | | #include "colors.h" |
33 | | #include "compiler.h" |
34 | | #include "dp-packet.h" |
35 | | #include "flow.h" |
36 | | #include "learn.h" |
37 | | #include "multipath.h" |
38 | | #include "netdev.h" |
39 | | #include "nx-match.h" |
40 | | #include "odp-util.h" |
41 | | #include "openflow/nicira-ext.h" |
42 | | #include "openflow/openflow.h" |
43 | | #include "openvswitch/dynamic-string.h" |
44 | | #include "openvswitch/meta-flow.h" |
45 | | #include "openvswitch/ofp-actions.h" |
46 | | #include "openvswitch/ofp-bundle.h" |
47 | | #include "openvswitch/ofp-connection.h" |
48 | | #include "openvswitch/ofp-ct.h" |
49 | | #include "openvswitch/ofp-errors.h" |
50 | | #include "openvswitch/ofp-group.h" |
51 | | #include "openvswitch/ofp-ipfix.h" |
52 | | #include "openvswitch/ofp-match.h" |
53 | | #include "openvswitch/ofp-meter.h" |
54 | | #include "openvswitch/ofp-monitor.h" |
55 | | #include "openvswitch/ofp-msgs.h" |
56 | | #include "openvswitch/ofp-port.h" |
57 | | #include "openvswitch/ofp-queue.h" |
58 | | #include "openvswitch/ofp-switch.h" |
59 | | #include "openvswitch/ofp-table.h" |
60 | | #include "openvswitch/ofp-util.h" |
61 | | #include "openvswitch/ofpbuf.h" |
62 | | #include "openvswitch/type-props.h" |
63 | | #include "packets.h" |
64 | | #include "unaligned.h" |
65 | | #include "util.h" |
66 | | #include "uuid.h" |
67 | | |
68 | | static void ofp_print_error(struct ds *, enum ofperr); |
69 | | |
70 | | /* Returns a string that represents the contents of the Ethernet frame in the |
71 | | * 'len' bytes starting at 'data'. The caller must free the returned string.*/ |
72 | | char * |
73 | | ofp_packet_to_string(const void *data, size_t len, ovs_be32 packet_type) |
74 | 0 | { |
75 | 0 | struct ds ds = DS_EMPTY_INITIALIZER; |
76 | 0 | struct dp_packet buf; |
77 | 0 | struct flow flow; |
78 | 0 | size_t l4_size; |
79 | |
|
80 | 0 | dp_packet_use_const(&buf, data, len); |
81 | 0 | buf.packet_type = packet_type; |
82 | 0 | flow_extract(&buf, &flow); |
83 | 0 | flow_format(&ds, &flow, NULL); |
84 | |
|
85 | 0 | l4_size = dp_packet_l4_size(&buf); |
86 | |
|
87 | 0 | if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) { |
88 | 0 | struct tcp_header *th = dp_packet_l4(&buf); |
89 | 0 | ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum)); |
90 | 0 | } else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) { |
91 | 0 | struct udp_header *uh = dp_packet_l4(&buf); |
92 | 0 | ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum)); |
93 | 0 | } else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) { |
94 | 0 | struct sctp_header *sh = dp_packet_l4(&buf); |
95 | 0 | ds_put_format(&ds, " sctp_csum:%"PRIx32, |
96 | 0 | ntohl(get_16aligned_be32(&sh->sctp_csum))); |
97 | 0 | } else if (flow.nw_proto == IPPROTO_ICMP && l4_size >= ICMP_HEADER_LEN) { |
98 | 0 | struct icmp_header *icmph = dp_packet_l4(&buf); |
99 | 0 | ds_put_format(&ds, " icmp_csum:%"PRIx16, |
100 | 0 | ntohs(icmph->icmp_csum)); |
101 | 0 | } else if (flow.nw_proto == IPPROTO_ICMPV6 && l4_size >= ICMP6_HEADER_LEN) { |
102 | 0 | struct icmp6_header *icmp6h = dp_packet_l4(&buf); |
103 | 0 | ds_put_format(&ds, " icmp6_csum:%"PRIx16, |
104 | 0 | ntohs(icmp6h->icmp6_cksum)); |
105 | 0 | } |
106 | |
|
107 | 0 | ds_put_char(&ds, '\n'); |
108 | |
|
109 | 0 | return ds_cstr(&ds); |
110 | 0 | } |
111 | | |
112 | | char * |
113 | | ofp_dp_packet_to_string(const struct dp_packet *packet) |
114 | 0 | { |
115 | 0 | return ofp_packet_to_string(dp_packet_data(packet), |
116 | 0 | dp_packet_size(packet), |
117 | 0 | packet->packet_type); |
118 | 0 | } |
119 | | |
120 | | static enum ofperr |
121 | | ofp_print_packet_in(struct ds *string, const struct ofp_header *oh, |
122 | | const struct ofputil_port_map *port_map, |
123 | | const struct ofputil_table_map *table_map, int verbosity) |
124 | 0 | { |
125 | 0 | struct ofputil_packet_in_private pin; |
126 | 0 | uint32_t buffer_id; |
127 | 0 | size_t total_len; |
128 | 0 | enum ofperr error = ofputil_decode_packet_in_private(oh, true, NULL, NULL, |
129 | 0 | &pin, &total_len, |
130 | 0 | &buffer_id); |
131 | 0 | if (!error) { |
132 | 0 | ofputil_packet_in_private_format(string, &pin, total_len, buffer_id, |
133 | 0 | port_map, table_map, verbosity); |
134 | 0 | ofputil_packet_in_private_destroy(&pin); |
135 | 0 | } |
136 | 0 | return error; |
137 | 0 | } |
138 | | |
139 | | static enum ofperr |
140 | | ofp_print_packet_out(struct ds *string, const struct ofp_header *oh, |
141 | | const struct ofputil_port_map *port_map, |
142 | | const struct ofputil_table_map *table_map, int verbosity) |
143 | 0 | { |
144 | 0 | struct ofputil_packet_out po; |
145 | 0 | struct ofpbuf ofpacts; |
146 | 0 | enum ofperr error; |
147 | |
|
148 | 0 | ofpbuf_init(&ofpacts, 64); |
149 | 0 | error = ofputil_decode_packet_out(&po, oh, NULL, &ofpacts); |
150 | 0 | if (!error) { |
151 | 0 | ofputil_packet_out_format(string, &po, port_map, table_map, verbosity); |
152 | 0 | } |
153 | 0 | ofpbuf_uninit(&ofpacts); |
154 | 0 | return error; |
155 | 0 | } |
156 | | |
157 | | void |
158 | | ofp_print_bit_names(struct ds *string, uint32_t bits, |
159 | | const char *(*bit_to_name)(uint32_t bit), |
160 | | char separator) |
161 | 0 | { |
162 | 0 | int n = 0; |
163 | 0 | int i; |
164 | |
|
165 | 0 | if (!bits) { |
166 | 0 | ds_put_cstr(string, "0"); |
167 | 0 | return; |
168 | 0 | } |
169 | | |
170 | 0 | for (i = 0; i < 32; i++) { |
171 | 0 | uint32_t bit = UINT32_C(1) << i; |
172 | |
|
173 | 0 | if (bits & bit) { |
174 | 0 | const char *name = bit_to_name(bit); |
175 | 0 | if (name) { |
176 | 0 | if (n++) { |
177 | 0 | ds_put_char(string, separator); |
178 | 0 | } |
179 | 0 | ds_put_cstr(string, name); |
180 | 0 | bits &= ~bit; |
181 | 0 | } |
182 | 0 | } |
183 | 0 | } |
184 | |
|
185 | 0 | if (bits) { |
186 | 0 | if (n) { |
187 | 0 | ds_put_char(string, separator); |
188 | 0 | } |
189 | 0 | ds_put_format(string, "0x%"PRIx32, bits); |
190 | 0 | } |
191 | 0 | } |
192 | | |
193 | | static enum ofperr |
194 | | ofp_print_switch_features(struct ds *string, const struct ofp_header *oh) |
195 | 0 | { |
196 | 0 | struct ofputil_switch_features features; |
197 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
198 | 0 | enum ofperr error = ofputil_pull_switch_features(&b, &features); |
199 | 0 | if (!error) { |
200 | 0 | ofputil_switch_features_format(string, &features); |
201 | 0 | error = ofputil_phy_ports_format(string, oh->version, &b); |
202 | 0 | } |
203 | 0 | return error; |
204 | 0 | } |
205 | | |
206 | | static enum ofperr |
207 | | ofp_print_set_config(struct ds *string, const struct ofp_header *oh) |
208 | 0 | { |
209 | 0 | struct ofputil_switch_config config; |
210 | 0 | enum ofperr error; |
211 | |
|
212 | 0 | error = ofputil_decode_set_config(oh, &config); |
213 | 0 | if (error) { |
214 | 0 | return error; |
215 | 0 | } |
216 | 0 | ofputil_switch_config_format(string, &config); |
217 | 0 | return 0; |
218 | 0 | } |
219 | | |
220 | | static enum ofperr |
221 | | ofp_print_get_config_reply(struct ds *string, const struct ofp_header *oh) |
222 | 0 | { |
223 | 0 | struct ofputil_switch_config config; |
224 | 0 | ofputil_decode_get_config_reply(oh, &config); |
225 | 0 | ofputil_switch_config_format(string, &config); |
226 | 0 | return 0; |
227 | 0 | } |
228 | | |
229 | | static enum ofperr |
230 | | ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh) |
231 | 0 | { |
232 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
233 | |
|
234 | 0 | struct ofputil_table_features prev; |
235 | 0 | int first_ditto = -1, last_ditto = -1; |
236 | 0 | for (int i = 0; ; i++) { |
237 | 0 | struct ofputil_table_features tf; |
238 | 0 | struct ofpbuf raw_properties; |
239 | 0 | int retval = ofputil_decode_table_features(&b, &tf, &raw_properties); |
240 | 0 | if (retval) { |
241 | 0 | ofputil_table_features_format_finish(s, first_ditto, last_ditto); |
242 | 0 | return retval != EOF ? retval : 0; |
243 | 0 | } |
244 | | |
245 | 0 | ofputil_table_features_format(s, &tf, i ? &prev : NULL, NULL, NULL, |
246 | 0 | &first_ditto, &last_ditto); |
247 | 0 | prev = tf; |
248 | 0 | } |
249 | 0 | } |
250 | | |
251 | | void |
252 | | ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec) |
253 | 0 | { |
254 | 0 | ds_put_format(string, "%u", sec); |
255 | | |
256 | | /* If there are no fractional seconds, don't print any decimals. |
257 | | * |
258 | | * If the fractional seconds can be expressed exactly as milliseconds, |
259 | | * print 3 decimals. Open vSwitch provides millisecond precision for most |
260 | | * time measurements, so printing 3 decimals every time makes it easier to |
261 | | * spot real changes in flow dumps that refresh themselves quickly. |
262 | | * |
263 | | * If the fractional seconds are more precise than milliseconds, print the |
264 | | * number of decimals needed to express them exactly. |
265 | | */ |
266 | 0 | if (nsec > 0) { |
267 | 0 | unsigned int msec = nsec / 1000000; |
268 | 0 | if (msec * 1000000 == nsec) { |
269 | 0 | ds_put_format(string, ".%03u", msec); |
270 | 0 | } else { |
271 | 0 | ds_put_format(string, ".%09u", nsec); |
272 | 0 | while (string->string[string->length - 1] == '0') { |
273 | 0 | string->length--; |
274 | 0 | } |
275 | 0 | } |
276 | 0 | } |
277 | 0 | ds_put_char(string, 's'); |
278 | 0 | } |
279 | | |
280 | | static enum ofperr |
281 | | ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh, |
282 | | const struct ofputil_port_map *port_map, |
283 | | const struct ofputil_table_map *table_map) |
284 | 0 | { |
285 | 0 | struct ofputil_flow_removed fr; |
286 | 0 | enum ofperr error = ofputil_decode_flow_removed(&fr, oh); |
287 | 0 | if (!error) { |
288 | 0 | ofputil_flow_removed_format(string, &fr, port_map, table_map); |
289 | 0 | } |
290 | 0 | return error; |
291 | 0 | } |
292 | | |
293 | | static enum ofperr |
294 | | ofp_print_port_mod(struct ds *string, const struct ofp_header *oh, |
295 | | const struct ofputil_port_map *port_map) |
296 | 0 | { |
297 | 0 | struct ofputil_port_mod pm; |
298 | 0 | enum ofperr error = ofputil_decode_port_mod(oh, &pm, true); |
299 | 0 | if (!error) { |
300 | 0 | ofputil_port_mod_format(string, &pm, port_map); |
301 | 0 | } |
302 | 0 | return error; |
303 | 0 | } |
304 | | |
305 | | static enum ofperr |
306 | | ofp_print_table_mod(struct ds *string, const struct ofp_header *oh, |
307 | | const struct ofputil_table_map *table_map) |
308 | 0 | { |
309 | 0 | struct ofputil_table_mod tm; |
310 | 0 | enum ofperr error = ofputil_decode_table_mod(oh, &tm); |
311 | 0 | if (!error) { |
312 | 0 | ofputil_table_mod_format(string, &tm, table_map); |
313 | 0 | } |
314 | 0 | return error; |
315 | 0 | } |
316 | | |
317 | | static enum ofperr |
318 | | ofp_print_table_status_message(struct ds *string, const struct ofp_header *oh, |
319 | | const struct ofputil_table_map *table_map) |
320 | 0 | { |
321 | 0 | struct ofputil_table_status ts; |
322 | 0 | enum ofperr error = ofputil_decode_table_status(oh, &ts); |
323 | 0 | if (!error) { |
324 | 0 | ofputil_format_table_status(string, &ts, table_map); |
325 | 0 | } |
326 | 0 | return error; |
327 | 0 | } |
328 | | |
329 | | static enum ofperr |
330 | | ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh) |
331 | 0 | { |
332 | 0 | struct ofputil_meter_mod mm; |
333 | 0 | struct ofpbuf bands; |
334 | |
|
335 | 0 | ofpbuf_init(&bands, 64); |
336 | 0 | enum ofperr error = ofputil_decode_meter_mod(oh, &mm, &bands); |
337 | 0 | if (!error) { |
338 | 0 | ofputil_format_meter_mod(s, &mm); |
339 | 0 | } |
340 | 0 | ofpbuf_uninit(&bands); |
341 | |
|
342 | 0 | return error; |
343 | 0 | } |
344 | | |
345 | | static enum ofperr |
346 | | ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh) |
347 | 0 | { |
348 | 0 | uint32_t meter_id; |
349 | |
|
350 | 0 | ofputil_decode_meter_request(oh, &meter_id); |
351 | 0 | ds_put_char(s, ' '); |
352 | |
|
353 | 0 | ofputil_format_meter_id(s, meter_id, '='); |
354 | |
|
355 | 0 | return 0; |
356 | 0 | } |
357 | | |
358 | | static enum ofperr |
359 | | ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh) |
360 | 0 | { |
361 | 0 | struct ofputil_meter_features mf; |
362 | 0 | ofputil_decode_meter_features(oh, &mf); |
363 | 0 | ofputil_format_meter_features(s, &mf); |
364 | 0 | return 0; |
365 | 0 | } |
366 | | |
367 | | static enum ofperr |
368 | | ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh) |
369 | 0 | { |
370 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
371 | 0 | struct ofpbuf bands; |
372 | 0 | int retval; |
373 | |
|
374 | 0 | ofpbuf_init(&bands, 64); |
375 | 0 | for (;;) { |
376 | 0 | struct ofputil_meter_config mc; |
377 | |
|
378 | 0 | retval = ofputil_decode_meter_config(&b, &mc, &bands); |
379 | 0 | if (retval) { |
380 | 0 | break; |
381 | 0 | } |
382 | 0 | ds_put_char(s, '\n'); |
383 | 0 | ofputil_format_meter_config(s, &mc); |
384 | 0 | } |
385 | 0 | ofpbuf_uninit(&bands); |
386 | |
|
387 | 0 | return retval != EOF ? retval : 0; |
388 | 0 | } |
389 | | |
390 | | static enum ofperr |
391 | | ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh) |
392 | 0 | { |
393 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
394 | 0 | struct ofpbuf bands; |
395 | 0 | int retval; |
396 | |
|
397 | 0 | ofpbuf_init(&bands, 64); |
398 | 0 | for (;;) { |
399 | 0 | struct ofputil_meter_stats ms; |
400 | |
|
401 | 0 | retval = ofputil_decode_meter_stats(&b, &ms, &bands); |
402 | 0 | if (retval) { |
403 | 0 | break; |
404 | 0 | } |
405 | 0 | ds_put_char(s, '\n'); |
406 | 0 | ofputil_format_meter_stats(s, &ms); |
407 | 0 | } |
408 | 0 | ofpbuf_uninit(&bands); |
409 | |
|
410 | 0 | return retval != EOF ? retval : 0; |
411 | 0 | } |
412 | | |
413 | | static void |
414 | | ofp_print_error(struct ds *string, enum ofperr error) |
415 | 0 | { |
416 | 0 | ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error)); |
417 | 0 | } |
418 | | |
419 | | static enum ofperr |
420 | | ofp_print_hello(struct ds *string, const struct ofp_header *oh) |
421 | 0 | { |
422 | 0 | ofputil_hello_format(string, oh); |
423 | 0 | return 0; |
424 | 0 | } |
425 | | |
426 | | static enum ofperr |
427 | | ofp_print_error_msg(struct ds *string, const struct ofp_header *oh, |
428 | | const struct ofputil_port_map *port_map, |
429 | | const struct ofputil_table_map *table_map) |
430 | 0 | { |
431 | 0 | struct ofpbuf payload; |
432 | 0 | enum ofperr error = ofperr_decode_msg(oh, &payload); |
433 | 0 | if (!error) { |
434 | 0 | return OFPERR_OFPBRC_BAD_LEN; |
435 | 0 | } |
436 | 0 | ofperr_msg_format(string, error, &payload, port_map, table_map); |
437 | 0 | ofpbuf_uninit(&payload); |
438 | |
|
439 | 0 | return 0; |
440 | 0 | } |
441 | | |
442 | | static enum ofperr |
443 | | ofp_print_port_status(struct ds *string, const struct ofp_header *oh) |
444 | 0 | { |
445 | 0 | struct ofputil_port_status ps; |
446 | 0 | enum ofperr error = ofputil_decode_port_status(oh, &ps); |
447 | 0 | if (!error) { |
448 | 0 | ofputil_port_status_format(string, &ps); |
449 | 0 | } |
450 | 0 | return error; |
451 | 0 | } |
452 | | |
453 | | static enum ofperr |
454 | | ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh) |
455 | 0 | { |
456 | 0 | const struct ofp_desc_stats *ods = ofpmsg_body(oh); |
457 | |
|
458 | 0 | ds_put_char(string, '\n'); |
459 | 0 | ds_put_format(string, "Manufacturer: %.*s\n", |
460 | 0 | (int) sizeof ods->mfr_desc, ods->mfr_desc); |
461 | 0 | ds_put_format(string, "Hardware: %.*s\n", |
462 | 0 | (int) sizeof ods->hw_desc, ods->hw_desc); |
463 | 0 | ds_put_format(string, "Software: %.*s\n", |
464 | 0 | (int) sizeof ods->sw_desc, ods->sw_desc); |
465 | 0 | ds_put_format(string, "Serial Num: %.*s\n", |
466 | 0 | (int) sizeof ods->serial_num, ods->serial_num); |
467 | 0 | ds_put_format(string, "DP Description: %.*s\n", |
468 | 0 | (int) sizeof ods->dp_desc, ods->dp_desc); |
469 | |
|
470 | 0 | return 0; |
471 | 0 | } |
472 | | |
473 | | static enum ofperr |
474 | | ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh, |
475 | | const struct ofputil_port_map *port_map, |
476 | | const struct ofputil_table_map *table_map) |
477 | 0 | { |
478 | 0 | struct ofputil_flow_stats_request fsr; |
479 | 0 | enum ofperr error = ofputil_decode_flow_stats_request(&fsr, oh, NULL, |
480 | 0 | NULL); |
481 | 0 | if (!error) { |
482 | 0 | ofputil_flow_stats_request_format(string, &fsr, port_map, table_map); |
483 | 0 | } |
484 | 0 | return error; |
485 | 0 | } |
486 | | |
487 | | static enum ofperr |
488 | | ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh, |
489 | | const struct ofputil_port_map *port_map, |
490 | | const struct ofputil_table_map *table_map) |
491 | 0 | { |
492 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
493 | 0 | struct ofpbuf ofpacts; |
494 | 0 | int retval; |
495 | |
|
496 | 0 | ofpbuf_init(&ofpacts, 64); |
497 | 0 | for (;;) { |
498 | 0 | struct ofputil_flow_stats fs; |
499 | |
|
500 | 0 | retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts); |
501 | 0 | if (retval) { |
502 | 0 | break; |
503 | 0 | } |
504 | 0 | ds_put_cstr(string, "\n "); |
505 | 0 | ofputil_flow_stats_format(string, &fs, port_map, table_map, true); |
506 | 0 | } |
507 | 0 | ofpbuf_uninit(&ofpacts); |
508 | |
|
509 | 0 | return retval != EOF ? retval : 0; |
510 | 0 | } |
511 | | |
512 | | static enum ofperr |
513 | | ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh) |
514 | 0 | { |
515 | 0 | struct ofputil_aggregate_stats as; |
516 | 0 | enum ofperr error; |
517 | |
|
518 | 0 | error = ofputil_decode_aggregate_stats_reply(&as, oh); |
519 | 0 | if (!error) { |
520 | 0 | ofputil_aggregate_stats_format(string, &as); |
521 | 0 | } |
522 | 0 | return error; |
523 | 0 | } |
524 | | |
525 | | static enum ofperr |
526 | | ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh, |
527 | | const struct ofputil_port_map *port_map) |
528 | 0 | { |
529 | 0 | ofp_port_t ofp10_port; |
530 | 0 | enum ofperr error; |
531 | |
|
532 | 0 | error = ofputil_decode_port_stats_request(oh, &ofp10_port); |
533 | 0 | if (error) { |
534 | 0 | return error; |
535 | 0 | } |
536 | | |
537 | 0 | ds_put_cstr(string, " port_no="); |
538 | 0 | ofputil_format_port(ofp10_port, port_map, string); |
539 | |
|
540 | 0 | return 0; |
541 | 0 | } |
542 | | |
543 | | static enum ofperr |
544 | | ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh, |
545 | | const struct ofputil_port_map *port_map, |
546 | | int verbosity) |
547 | 0 | { |
548 | 0 | ds_put_format(string, " %"PRIuSIZE" ports\n", |
549 | 0 | ofputil_count_port_stats(oh)); |
550 | 0 | if (verbosity < 1) { |
551 | 0 | return 0; |
552 | 0 | } |
553 | | |
554 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
555 | 0 | for (;;) { |
556 | 0 | struct ofputil_port_stats ps; |
557 | 0 | int retval; |
558 | |
|
559 | 0 | retval = ofputil_decode_port_stats(&ps, &b); |
560 | 0 | if (retval) { |
561 | 0 | return retval != EOF ? retval : 0; |
562 | 0 | } |
563 | 0 | ofputil_format_port_stats(string, &ps, port_map); |
564 | 0 | netdev_free_custom_stats_counters(&ps.custom_stats); |
565 | 0 | } |
566 | 0 | } |
567 | | |
568 | | static enum ofperr |
569 | | ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh) |
570 | 0 | { |
571 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
572 | 0 | ofpraw_pull_assert(&b); |
573 | |
|
574 | 0 | struct ofputil_table_features prev_features; |
575 | 0 | struct ofputil_table_stats prev_stats; |
576 | 0 | int first_ditto = -1, last_ditto = -1; |
577 | 0 | for (int i = 0;; i++) { |
578 | 0 | struct ofputil_table_features features; |
579 | 0 | struct ofputil_table_stats stats; |
580 | 0 | int retval; |
581 | |
|
582 | 0 | retval = ofputil_decode_table_stats_reply(&b, &stats, &features); |
583 | 0 | if (retval) { |
584 | 0 | ofputil_table_features_format_finish(string, |
585 | 0 | first_ditto, last_ditto); |
586 | 0 | return retval != EOF ? retval : 0; |
587 | 0 | } |
588 | | |
589 | 0 | ofputil_table_features_format(string, |
590 | 0 | &features, i ? &prev_features : NULL, |
591 | 0 | &stats, i ? &prev_stats : NULL, |
592 | 0 | &first_ditto, &last_ditto); |
593 | 0 | prev_features = features; |
594 | 0 | prev_stats = stats; |
595 | 0 | } |
596 | 0 | } |
597 | | |
598 | | static enum ofperr |
599 | | ofp_print_ofpst_port_desc_request(struct ds *string, |
600 | | const struct ofp_header *oh, |
601 | | const struct ofputil_port_map *port_map) |
602 | 0 | { |
603 | 0 | enum ofperr error; |
604 | 0 | ofp_port_t port; |
605 | |
|
606 | 0 | error = ofputil_decode_port_desc_stats_request(oh, &port); |
607 | 0 | if (error) { |
608 | 0 | return error; |
609 | 0 | } |
610 | | |
611 | 0 | ds_put_cstr(string, " port="); |
612 | 0 | ofputil_format_port(port, port_map, string); |
613 | |
|
614 | 0 | return 0; |
615 | 0 | } |
616 | | |
617 | | static enum ofperr |
618 | | ofp_print_ofpst_port_desc_reply(struct ds *string, |
619 | | const struct ofp_header *oh) |
620 | 0 | { |
621 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
622 | 0 | ofpraw_pull_assert(&b); |
623 | 0 | ds_put_char(string, '\n'); |
624 | 0 | return ofputil_phy_ports_format(string, oh->version, &b); |
625 | 0 | } |
626 | | |
627 | | static void |
628 | | ofp_print_stats(struct ds *string, const struct ofp_header *oh) |
629 | 0 | { |
630 | 0 | uint16_t flags = ofpmp_flags(oh); |
631 | |
|
632 | 0 | if (flags) { |
633 | 0 | ds_put_cstr(string, " flags="); |
634 | 0 | if ((!ofpmsg_is_stat_request(oh) || oh->version >= OFP13_VERSION) |
635 | 0 | && (flags & OFPSF_REPLY_MORE)) { |
636 | 0 | ds_put_cstr(string, "[more]"); |
637 | 0 | flags &= ~OFPSF_REPLY_MORE; |
638 | 0 | } |
639 | 0 | if (flags) { |
640 | 0 | ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]", |
641 | 0 | flags); |
642 | 0 | } |
643 | 0 | } |
644 | 0 | } |
645 | | |
646 | | static enum ofperr |
647 | | ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity) |
648 | 0 | { |
649 | 0 | size_t len = ntohs(oh->length); |
650 | |
|
651 | 0 | ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh); |
652 | 0 | if (verbosity > 1) { |
653 | 0 | ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true); |
654 | 0 | } |
655 | |
|
656 | 0 | return 0; |
657 | 0 | } |
658 | | |
659 | | static enum ofperr |
660 | | ofp_print_role_message(struct ds *string, const struct ofp_header *oh) |
661 | 0 | { |
662 | 0 | struct ofputil_role_request rr; |
663 | 0 | enum ofperr error = ofputil_decode_role_message(oh, &rr); |
664 | 0 | if (!error) { |
665 | 0 | ofputil_format_role_message(string, &rr); |
666 | 0 | } |
667 | 0 | return error; |
668 | 0 | } |
669 | | |
670 | | static enum ofperr |
671 | | ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh) |
672 | 0 | { |
673 | 0 | struct ofputil_role_status rs; |
674 | 0 | enum ofperr error = ofputil_decode_role_status(oh, &rs); |
675 | 0 | if (!error) { |
676 | 0 | ofputil_format_role_status(string, &rs); |
677 | 0 | } |
678 | 0 | return error; |
679 | 0 | } |
680 | | |
681 | | static enum ofperr |
682 | | ofp_print_nxt_flow_mod_table_id(struct ds *string, const struct ofp_header *oh) |
683 | 0 | { |
684 | 0 | bool enable = ofputil_decode_nx_flow_mod_table_id(oh); |
685 | 0 | ds_put_format(string, " %s", enable ? "enable" : "disable"); |
686 | 0 | return 0; |
687 | 0 | } |
688 | | |
689 | | static enum ofperr |
690 | | ofp_print_nxt_set_flow_format(struct ds *string, const struct ofp_header *oh) |
691 | 0 | { |
692 | 0 | enum ofputil_protocol p = ofputil_decode_nx_set_flow_format(oh); |
693 | 0 | ds_put_format(string, " format=%s", |
694 | 0 | p == OFPUTIL_P_OF10_STD ? "openflow10" |
695 | 0 | : p == OFPUTIL_P_OF10_NXM ? "nxm" |
696 | 0 | : "(unknown)"); |
697 | 0 | return 0; |
698 | 0 | } |
699 | | |
700 | | static enum ofperr |
701 | | ofp_print_nxt_set_packet_in_format(struct ds *string, |
702 | | const struct ofp_header *oh) |
703 | 0 | { |
704 | 0 | enum ofputil_packet_in_format format; |
705 | 0 | enum ofperr error = ofputil_decode_set_packet_in_format(oh, &format); |
706 | 0 | if (!error) { |
707 | 0 | ds_put_format(string, " format=%s", |
708 | 0 | ofputil_packet_in_format_to_string(format)); |
709 | 0 | } |
710 | 0 | return error; |
711 | 0 | } |
712 | | |
713 | | static enum ofperr |
714 | | ofp_print_set_async_config(struct ds *string, const struct ofp_header *oh, |
715 | | enum ofptype ofptype) |
716 | 0 | { |
717 | 0 | struct ofputil_async_cfg basis = OFPUTIL_ASYNC_CFG_INIT; |
718 | 0 | struct ofputil_async_cfg ac; |
719 | |
|
720 | 0 | bool is_reply = ofptype == OFPTYPE_GET_ASYNC_REPLY; |
721 | 0 | enum ofperr error = ofputil_decode_set_async_config(oh, is_reply, |
722 | 0 | &basis, &ac); |
723 | 0 | if (error) { |
724 | 0 | return error; |
725 | 0 | } |
726 | 0 | ofputil_format_set_async_config(string, &ac); |
727 | 0 | return 0; |
728 | 0 | } |
729 | | |
730 | | static enum ofperr |
731 | | ofp_print_nxt_set_controller_id(struct ds *string, |
732 | | const struct nx_controller_id *nci) |
733 | 0 | { |
734 | 0 | ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id)); |
735 | 0 | return 0; |
736 | 0 | } |
737 | | |
738 | | static enum ofperr |
739 | | ofp_print_nxt_flow_monitor_cancel(struct ds *string, |
740 | | const struct ofp_header *oh) |
741 | 0 | { |
742 | 0 | ds_put_format(string, " id=%"PRIu32, |
743 | 0 | ofputil_decode_flow_monitor_cancel(oh)); |
744 | 0 | return 0; |
745 | 0 | } |
746 | | |
747 | | static enum ofperr |
748 | | ofp_print_flow_monitor_request(struct ds *string, |
749 | | const struct ofp_header *oh, |
750 | | const struct ofputil_port_map *port_map, |
751 | | const struct ofputil_table_map *table_map) |
752 | 0 | { |
753 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
754 | 0 | for (;;) { |
755 | 0 | struct ofputil_flow_monitor_request request; |
756 | 0 | int retval; |
757 | |
|
758 | 0 | retval = ofputil_decode_flow_monitor_request(&request, &b); |
759 | 0 | if (retval) { |
760 | 0 | return retval != EOF ? retval : 0; |
761 | 0 | } |
762 | | |
763 | 0 | ofputil_flow_monitor_request_format(string, &request, |
764 | 0 | port_map, table_map); |
765 | 0 | } |
766 | 0 | } |
767 | | |
768 | | static enum ofperr |
769 | | ofp_print_flow_monitor_reply(struct ds *string, |
770 | | const struct ofp_header *oh, |
771 | | const struct ofputil_port_map *port_map, |
772 | | const struct ofputil_table_map *table_map) |
773 | 0 | { |
774 | 0 | uint64_t ofpacts_stub[1024 / 8]; |
775 | 0 | struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub); |
776 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
777 | |
|
778 | 0 | for (;;) { |
779 | 0 | struct ofputil_flow_update update; |
780 | 0 | int retval = ofputil_decode_flow_update(&update, &b, &ofpacts); |
781 | 0 | if (retval) { |
782 | 0 | ofpbuf_uninit(&ofpacts); |
783 | 0 | return retval != EOF ? retval : 0; |
784 | 0 | } |
785 | 0 | ofputil_flow_update_format(string, &update, port_map, table_map); |
786 | 0 | } |
787 | 0 | } |
788 | | |
789 | | void |
790 | | ofp_print_version(const struct ofp_header *oh, |
791 | | struct ds *string) |
792 | 0 | { |
793 | 0 | switch (oh->version) { |
794 | 0 | case OFP10_VERSION: |
795 | 0 | break; |
796 | 0 | case OFP11_VERSION: |
797 | 0 | ds_put_cstr(string, " (OF1.1)"); |
798 | 0 | break; |
799 | 0 | case OFP12_VERSION: |
800 | 0 | ds_put_cstr(string, " (OF1.2)"); |
801 | 0 | break; |
802 | 0 | case OFP13_VERSION: |
803 | 0 | ds_put_cstr(string, " (OF1.3)"); |
804 | 0 | break; |
805 | 0 | case OFP14_VERSION: |
806 | 0 | ds_put_cstr(string, " (OF1.4)"); |
807 | 0 | break; |
808 | 0 | case OFP15_VERSION: |
809 | 0 | ds_put_cstr(string, " (OF1.5)"); |
810 | 0 | break; |
811 | 0 | default: |
812 | 0 | ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version); |
813 | 0 | break; |
814 | 0 | } |
815 | 0 | ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid)); |
816 | 0 | } |
817 | | |
818 | | static void |
819 | | ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw, |
820 | | struct ds *string) |
821 | 0 | { |
822 | 0 | ds_put_cstr(string, ofpraw_get_name(raw)); |
823 | 0 | ofp_print_version(oh, string); |
824 | 0 | } |
825 | | |
826 | | static enum ofperr |
827 | | ofp_print_table_desc_reply(struct ds *s, const struct ofp_header *oh, |
828 | | const struct ofputil_table_map *table_map) |
829 | 0 | { |
830 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
831 | 0 | for (;;) { |
832 | 0 | struct ofputil_table_desc td; |
833 | 0 | int retval; |
834 | |
|
835 | 0 | retval = ofputil_decode_table_desc(&b, &td, oh->version); |
836 | 0 | if (retval) { |
837 | 0 | return retval != EOF ? retval : 0; |
838 | 0 | } |
839 | 0 | ofputil_table_desc_format(s, &td, table_map); |
840 | 0 | } |
841 | 0 | } |
842 | | |
843 | | static enum ofperr |
844 | | ofp_print_bundle_ctrl(struct ds *s, const struct ofp_header *oh) |
845 | 0 | { |
846 | 0 | int error; |
847 | 0 | struct ofputil_bundle_ctrl_msg bctrl; |
848 | |
|
849 | 0 | error = ofputil_decode_bundle_ctrl(oh, &bctrl); |
850 | 0 | if (error) { |
851 | 0 | return error; |
852 | 0 | } |
853 | 0 | ofputil_format_bundle_ctrl_request(s, &bctrl); |
854 | 0 | return 0; |
855 | 0 | } |
856 | | |
857 | | static enum ofperr |
858 | | ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, |
859 | | const struct ofputil_port_map *port_map, |
860 | | const struct ofputil_table_map *table_map, |
861 | | int verbosity) |
862 | 0 | { |
863 | 0 | struct ofputil_bundle_add_msg badd; |
864 | 0 | int error = ofputil_decode_bundle_add(oh, &badd, NULL); |
865 | 0 | if (!error) { |
866 | 0 | ofputil_format_bundle_add(s, &badd, port_map, table_map, verbosity); |
867 | 0 | } |
868 | 0 | return error; |
869 | 0 | } |
870 | | |
871 | | static enum ofperr |
872 | | ofp_print_tlv_table_mod(struct ds *s, const struct ofp_header *oh) |
873 | 0 | { |
874 | 0 | struct ofputil_tlv_table_mod ttm; |
875 | 0 | int error = ofputil_decode_tlv_table_mod(oh, &ttm); |
876 | 0 | if (!error) { |
877 | 0 | ofputil_format_tlv_table_mod(s, &ttm); |
878 | 0 | ofputil_uninit_tlv_table(&ttm.mappings); |
879 | 0 | } |
880 | 0 | return error; |
881 | 0 | } |
882 | | |
883 | | static enum ofperr |
884 | | ofp_print_tlv_table_reply(struct ds *s, const struct ofp_header *oh) |
885 | 0 | { |
886 | 0 | struct ofputil_tlv_table_reply ttr; |
887 | 0 | int error = ofputil_decode_tlv_table_reply(oh, &ttr); |
888 | 0 | if (!error) { |
889 | 0 | ofputil_format_tlv_table_reply(s, &ttr); |
890 | 0 | ofputil_uninit_tlv_table(&ttr.mappings); |
891 | 0 | } |
892 | 0 | return error; |
893 | 0 | } |
894 | | |
895 | | /* This function will print the request forward message. The reason for |
896 | | * request forward is taken from rf.request.type */ |
897 | | static enum ofperr |
898 | | ofp_print_requestforward(struct ds *string, const struct ofp_header *oh, |
899 | | const struct ofputil_port_map *port_map, |
900 | | const struct ofputil_table_map *table_map) |
901 | 0 | { |
902 | 0 | struct ofputil_requestforward rf; |
903 | 0 | enum ofperr error = ofputil_decode_requestforward(oh, &rf); |
904 | 0 | if (!error) { |
905 | 0 | ofputil_format_requestforward(string, oh->version, |
906 | 0 | &rf, port_map, table_map); |
907 | 0 | ofputil_destroy_requestforward(&rf); |
908 | 0 | } |
909 | 0 | return error; |
910 | 0 | } |
911 | | |
912 | | static enum ofperr |
913 | | ofp_print_nxst_ipfix_bridge_reply(struct ds *string, const struct ofp_header *oh) |
914 | 0 | { |
915 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
916 | 0 | for (;;) { |
917 | 0 | struct ofputil_ipfix_stats is; |
918 | 0 | int retval; |
919 | |
|
920 | 0 | retval = ofputil_pull_ipfix_stats(&is, &b); |
921 | 0 | if (retval) { |
922 | 0 | return retval != EOF ? retval : 0; |
923 | 0 | } |
924 | 0 | ofputil_format_ipfix_stats_bridge(string, &is); |
925 | 0 | } |
926 | 0 | } |
927 | | |
928 | | static enum ofperr |
929 | | ofp_print_nxst_ipfix_flow_reply(struct ds *string, const struct ofp_header *oh) |
930 | 0 | { |
931 | 0 | ds_put_format(string, " %"PRIuSIZE" ids\n", ofputil_count_ipfix_stats(oh)); |
932 | |
|
933 | 0 | struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length)); |
934 | 0 | for (;;) { |
935 | 0 | struct ofputil_ipfix_stats is; |
936 | 0 | int retval; |
937 | |
|
938 | 0 | retval = ofputil_pull_ipfix_stats(&is, &b); |
939 | 0 | if (retval) { |
940 | 0 | return retval != EOF ? retval : 0; |
941 | 0 | } |
942 | 0 | ofputil_format_ipfix_stats_flow(string, &is); |
943 | 0 | } |
944 | 0 | } |
945 | | |
946 | | static enum ofperr |
947 | | ofp_print_nxt_ct_flush_zone(struct ds *string, const struct nx_zone_id *nzi) |
948 | 0 | { |
949 | 0 | ds_put_format(string, " zone_id=%"PRIu16, ntohs(nzi->zone_id)); |
950 | 0 | return 0; |
951 | 0 | } |
952 | | |
953 | | static enum ofperr |
954 | | ofp_print_nxt_ct_flush(struct ds *string, const struct ofp_header *oh) |
955 | 0 | { |
956 | 0 | uint16_t zone_id = 0; |
957 | 0 | struct ofp_ct_match match = {0}; |
958 | |
|
959 | 0 | enum ofperr error = ofp_ct_match_decode(&match, NULL, &zone_id, oh); |
960 | 0 | if (error) { |
961 | 0 | return error; |
962 | 0 | } |
963 | | |
964 | 0 | ds_put_format(string, " zone=%"PRIu16" ", zone_id); |
965 | 0 | ofp_ct_match_format(string, &match); |
966 | |
|
967 | 0 | return 0; |
968 | 0 | } |
969 | | |
970 | | static enum ofperr |
971 | | ofp_to_string__(const struct ofp_header *oh, |
972 | | const struct ofputil_port_map *port_map, |
973 | | const struct ofputil_table_map *table_map, enum ofpraw raw, |
974 | | struct ds *string, int verbosity) |
975 | 0 | { |
976 | 0 | if (ofpmsg_is_stat(oh)) { |
977 | 0 | ofp_print_stats(string, oh); |
978 | 0 | } |
979 | |
|
980 | 0 | const void *msg = oh; |
981 | 0 | enum ofptype type = ofptype_from_ofpraw(raw); |
982 | 0 | switch (type) { |
983 | 0 | case OFPTYPE_GROUP_STATS_REQUEST: |
984 | 0 | return ofputil_group_stats_request_format(string, oh); |
985 | | |
986 | 0 | case OFPTYPE_GROUP_STATS_REPLY: |
987 | 0 | return ofputil_group_stats_format(string, oh); |
988 | | |
989 | 0 | case OFPTYPE_GROUP_DESC_STATS_REQUEST: |
990 | 0 | return ofputil_group_desc_request_format(string, oh); |
991 | | |
992 | 0 | case OFPTYPE_GROUP_DESC_STATS_REPLY: |
993 | 0 | return ofputil_group_desc_format(string, oh, port_map, table_map); |
994 | | |
995 | 0 | case OFPTYPE_GROUP_FEATURES_STATS_REQUEST: |
996 | 0 | break; |
997 | | |
998 | 0 | case OFPTYPE_GROUP_FEATURES_STATS_REPLY: |
999 | 0 | return ofputil_group_features_format(string, oh); |
1000 | | |
1001 | 0 | case OFPTYPE_GROUP_MOD: |
1002 | 0 | return ofputil_group_mod_format(string, oh, port_map, table_map); |
1003 | | |
1004 | 0 | case OFPTYPE_TABLE_FEATURES_STATS_REQUEST: |
1005 | 0 | case OFPTYPE_TABLE_FEATURES_STATS_REPLY: |
1006 | 0 | return ofp_print_table_features_reply(string, oh); |
1007 | | |
1008 | 0 | case OFPTYPE_TABLE_DESC_REQUEST: |
1009 | 0 | case OFPTYPE_TABLE_DESC_REPLY: |
1010 | 0 | return ofp_print_table_desc_reply(string, oh, table_map); |
1011 | | |
1012 | 0 | case OFPTYPE_HELLO: |
1013 | 0 | return ofp_print_hello(string, oh); |
1014 | | |
1015 | 0 | case OFPTYPE_ERROR: |
1016 | 0 | return ofp_print_error_msg(string, oh, port_map, table_map); |
1017 | | |
1018 | 0 | case OFPTYPE_ECHO_REQUEST: |
1019 | 0 | case OFPTYPE_ECHO_REPLY: |
1020 | 0 | return ofp_print_echo(string, oh, verbosity); |
1021 | | |
1022 | 0 | case OFPTYPE_FEATURES_REQUEST: |
1023 | 0 | break; |
1024 | | |
1025 | 0 | case OFPTYPE_FEATURES_REPLY: |
1026 | 0 | return ofp_print_switch_features(string, oh); |
1027 | | |
1028 | 0 | case OFPTYPE_GET_CONFIG_REQUEST: |
1029 | 0 | break; |
1030 | | |
1031 | 0 | case OFPTYPE_GET_CONFIG_REPLY: |
1032 | 0 | return ofp_print_get_config_reply(string, oh); |
1033 | | |
1034 | 0 | case OFPTYPE_SET_CONFIG: |
1035 | 0 | return ofp_print_set_config(string, oh); |
1036 | | |
1037 | 0 | case OFPTYPE_PACKET_IN: |
1038 | 0 | return ofp_print_packet_in(string, oh, port_map, table_map, verbosity); |
1039 | | |
1040 | 0 | case OFPTYPE_FLOW_REMOVED: |
1041 | 0 | return ofp_print_flow_removed(string, oh, port_map, table_map); |
1042 | | |
1043 | 0 | case OFPTYPE_PORT_STATUS: |
1044 | 0 | return ofp_print_port_status(string, oh); |
1045 | | |
1046 | 0 | case OFPTYPE_PACKET_OUT: |
1047 | 0 | return ofp_print_packet_out(string, oh, port_map, table_map, |
1048 | 0 | verbosity); |
1049 | | |
1050 | 0 | case OFPTYPE_FLOW_MOD: |
1051 | 0 | return ofputil_flow_mod_format(string, oh, port_map, table_map, |
1052 | 0 | verbosity); |
1053 | | |
1054 | 0 | case OFPTYPE_PORT_MOD: |
1055 | 0 | return ofp_print_port_mod(string, oh, port_map); |
1056 | | |
1057 | 0 | case OFPTYPE_TABLE_MOD: |
1058 | 0 | return ofp_print_table_mod(string, oh, table_map); |
1059 | | |
1060 | 0 | case OFPTYPE_METER_MOD: |
1061 | 0 | return ofp_print_meter_mod(string, oh); |
1062 | | |
1063 | 0 | case OFPTYPE_BARRIER_REQUEST: |
1064 | 0 | case OFPTYPE_BARRIER_REPLY: |
1065 | 0 | break; |
1066 | | |
1067 | 0 | case OFPTYPE_QUEUE_GET_CONFIG_REQUEST: |
1068 | 0 | return ofputil_queue_get_config_request_format(string, oh, port_map); |
1069 | | |
1070 | 0 | case OFPTYPE_QUEUE_GET_CONFIG_REPLY: |
1071 | 0 | return ofputil_queue_get_config_reply_format(string, oh, port_map); |
1072 | | |
1073 | 0 | case OFPTYPE_ROLE_REQUEST: |
1074 | 0 | case OFPTYPE_ROLE_REPLY: |
1075 | 0 | return ofp_print_role_message(string, oh); |
1076 | 0 | case OFPTYPE_ROLE_STATUS: |
1077 | 0 | return ofp_print_role_status_message(string, oh); |
1078 | | |
1079 | 0 | case OFPTYPE_REQUESTFORWARD: |
1080 | 0 | return ofp_print_requestforward(string, oh, port_map, table_map); |
1081 | | |
1082 | 0 | case OFPTYPE_TABLE_STATUS: |
1083 | 0 | return ofp_print_table_status_message(string, oh, table_map); |
1084 | | |
1085 | 0 | case OFPTYPE_METER_STATS_REQUEST: |
1086 | 0 | case OFPTYPE_METER_CONFIG_STATS_REQUEST: |
1087 | 0 | return ofp_print_meter_stats_request(string, oh); |
1088 | | |
1089 | 0 | case OFPTYPE_METER_STATS_REPLY: |
1090 | 0 | return ofp_print_meter_stats_reply(string, oh); |
1091 | | |
1092 | 0 | case OFPTYPE_METER_CONFIG_STATS_REPLY: |
1093 | 0 | return ofp_print_meter_config_reply(string, oh); |
1094 | | |
1095 | 0 | case OFPTYPE_METER_FEATURES_STATS_REPLY: |
1096 | 0 | return ofp_print_meter_features_reply(string, oh); |
1097 | | |
1098 | 0 | case OFPTYPE_DESC_STATS_REQUEST: |
1099 | 0 | case OFPTYPE_METER_FEATURES_STATS_REQUEST: |
1100 | 0 | break; |
1101 | | |
1102 | 0 | case OFPTYPE_FLOW_STATS_REQUEST: |
1103 | 0 | case OFPTYPE_AGGREGATE_STATS_REQUEST: |
1104 | 0 | return ofp_print_flow_stats_request(string, oh, port_map, table_map); |
1105 | | |
1106 | 0 | case OFPTYPE_TABLE_STATS_REQUEST: |
1107 | 0 | break; |
1108 | | |
1109 | 0 | case OFPTYPE_PORT_STATS_REQUEST: |
1110 | 0 | return ofp_print_ofpst_port_request(string, oh, port_map); |
1111 | | |
1112 | 0 | case OFPTYPE_QUEUE_STATS_REQUEST: |
1113 | 0 | return ofputil_queue_stats_request_format(string, oh, port_map); |
1114 | | |
1115 | 0 | case OFPTYPE_DESC_STATS_REPLY: |
1116 | 0 | return ofp_print_ofpst_desc_reply(string, oh); |
1117 | | |
1118 | 0 | case OFPTYPE_FLOW_STATS_REPLY: |
1119 | 0 | return ofp_print_flow_stats_reply(string, oh, port_map, table_map); |
1120 | | |
1121 | 0 | case OFPTYPE_QUEUE_STATS_REPLY: |
1122 | 0 | return ofputil_queue_stats_reply_format(string, oh, port_map, |
1123 | 0 | verbosity); |
1124 | | |
1125 | 0 | case OFPTYPE_PORT_STATS_REPLY: |
1126 | 0 | return ofp_print_ofpst_port_reply(string, oh, port_map, verbosity); |
1127 | | |
1128 | 0 | case OFPTYPE_TABLE_STATS_REPLY: |
1129 | 0 | return ofp_print_table_stats_reply(string, oh); |
1130 | | |
1131 | 0 | case OFPTYPE_AGGREGATE_STATS_REPLY: |
1132 | 0 | return ofp_print_aggregate_stats_reply(string, oh); |
1133 | | |
1134 | 0 | case OFPTYPE_PORT_DESC_STATS_REQUEST: |
1135 | 0 | return ofp_print_ofpst_port_desc_request(string, oh, port_map); |
1136 | | |
1137 | 0 | case OFPTYPE_PORT_DESC_STATS_REPLY: |
1138 | 0 | return ofp_print_ofpst_port_desc_reply(string, oh); |
1139 | | |
1140 | 0 | case OFPTYPE_FLOW_MOD_TABLE_ID: |
1141 | 0 | return ofp_print_nxt_flow_mod_table_id(string, oh); |
1142 | | |
1143 | 0 | case OFPTYPE_SET_FLOW_FORMAT: |
1144 | 0 | return ofp_print_nxt_set_flow_format(string, oh); |
1145 | | |
1146 | 0 | case OFPTYPE_SET_PACKET_IN_FORMAT: |
1147 | 0 | return ofp_print_nxt_set_packet_in_format(string, oh); |
1148 | | |
1149 | 0 | case OFPTYPE_FLOW_AGE: |
1150 | 0 | break; |
1151 | | |
1152 | 0 | case OFPTYPE_SET_CONTROLLER_ID: |
1153 | 0 | return ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh)); |
1154 | | |
1155 | 0 | case OFPTYPE_GET_ASYNC_REPLY: |
1156 | 0 | case OFPTYPE_SET_ASYNC_CONFIG: |
1157 | 0 | return ofp_print_set_async_config(string, oh, type); |
1158 | 0 | case OFPTYPE_GET_ASYNC_REQUEST: |
1159 | 0 | break; |
1160 | 0 | case OFPTYPE_FLOW_MONITOR_CANCEL: |
1161 | 0 | return ofp_print_nxt_flow_monitor_cancel(string, msg); |
1162 | | |
1163 | 0 | case OFPTYPE_FLOW_MONITOR_PAUSED: |
1164 | 0 | case OFPTYPE_FLOW_MONITOR_RESUMED: |
1165 | 0 | break; |
1166 | | |
1167 | 0 | case OFPTYPE_FLOW_MONITOR_STATS_REQUEST: |
1168 | 0 | return ofp_print_flow_monitor_request(string, msg, port_map, |
1169 | 0 | table_map); |
1170 | | |
1171 | 0 | case OFPTYPE_FLOW_MONITOR_STATS_REPLY: |
1172 | 0 | return ofp_print_flow_monitor_reply(string, msg, port_map, |
1173 | 0 | table_map); |
1174 | | |
1175 | 0 | case OFPTYPE_BUNDLE_CONTROL: |
1176 | 0 | return ofp_print_bundle_ctrl(string, msg); |
1177 | | |
1178 | 0 | case OFPTYPE_BUNDLE_ADD_MESSAGE: |
1179 | 0 | return ofp_print_bundle_add(string, msg, port_map, table_map, |
1180 | 0 | verbosity); |
1181 | | |
1182 | 0 | case OFPTYPE_NXT_TLV_TABLE_MOD: |
1183 | 0 | return ofp_print_tlv_table_mod(string, msg); |
1184 | | |
1185 | 0 | case OFPTYPE_NXT_TLV_TABLE_REQUEST: |
1186 | 0 | break; |
1187 | | |
1188 | 0 | case OFPTYPE_NXT_TLV_TABLE_REPLY: |
1189 | 0 | return ofp_print_tlv_table_reply(string, msg); |
1190 | | |
1191 | 0 | case OFPTYPE_NXT_RESUME: |
1192 | 0 | return ofp_print_packet_in(string, msg, port_map, table_map, |
1193 | 0 | verbosity); |
1194 | 0 | case OFPTYPE_IPFIX_BRIDGE_STATS_REQUEST: |
1195 | 0 | break; |
1196 | 0 | case OFPTYPE_IPFIX_BRIDGE_STATS_REPLY: |
1197 | 0 | return ofp_print_nxst_ipfix_bridge_reply(string, oh); |
1198 | 0 | case OFPTYPE_IPFIX_FLOW_STATS_REQUEST: |
1199 | 0 | break; |
1200 | 0 | case OFPTYPE_IPFIX_FLOW_STATS_REPLY: |
1201 | 0 | return ofp_print_nxst_ipfix_flow_reply(string, oh); |
1202 | | |
1203 | 0 | case OFPTYPE_CT_FLUSH_ZONE: |
1204 | 0 | return ofp_print_nxt_ct_flush_zone(string, ofpmsg_body(oh)); |
1205 | 0 | case OFPTYPE_CT_FLUSH: |
1206 | 0 | return ofp_print_nxt_ct_flush(string, oh); |
1207 | 0 | } |
1208 | | |
1209 | 0 | return 0; |
1210 | 0 | } |
1211 | | |
1212 | | static void |
1213 | | add_newline(struct ds *s) |
1214 | 0 | { |
1215 | 0 | if (s->length && s->string[s->length - 1] != '\n') { |
1216 | 0 | ds_put_char(s, '\n'); |
1217 | 0 | } |
1218 | 0 | } |
1219 | | |
1220 | | /* Composes and returns a string representing the OpenFlow packet of 'len' |
1221 | | * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of |
1222 | | * verbosity and higher numbers increase verbosity. The caller is responsible |
1223 | | * for freeing the string. */ |
1224 | | char * |
1225 | | ofp_to_string(const void *oh_, size_t len, |
1226 | | const struct ofputil_port_map *port_map, |
1227 | | const struct ofputil_table_map *table_map, |
1228 | | int verbosity) |
1229 | 0 | { |
1230 | 0 | struct ds string = DS_EMPTY_INITIALIZER; |
1231 | 0 | const struct ofp_header *oh = oh_; |
1232 | |
|
1233 | 0 | if (!len) { |
1234 | 0 | ds_put_cstr(&string, "OpenFlow message is empty\n"); |
1235 | 0 | } else if (len < sizeof(struct ofp_header)) { |
1236 | 0 | ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n", |
1237 | 0 | len); |
1238 | 0 | } else if (ntohs(oh->length) > len) { |
1239 | 0 | enum ofperr error; |
1240 | 0 | enum ofpraw raw; |
1241 | |
|
1242 | 0 | error = ofpraw_decode_partial(&raw, oh, len); |
1243 | 0 | if (!error) { |
1244 | 0 | ofp_header_to_string__(oh, raw, &string); |
1245 | 0 | ds_put_char(&string, '\n'); |
1246 | 0 | } |
1247 | |
|
1248 | 0 | ds_put_format(&string, |
1249 | 0 | "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n", |
1250 | 0 | len, ntohs(oh->length)); |
1251 | 0 | } else if (ntohs(oh->length) < len) { |
1252 | 0 | ds_put_format(&string, |
1253 | 0 | "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n", |
1254 | 0 | ntohs(oh->length), len); |
1255 | 0 | } else { |
1256 | 0 | enum ofperr error; |
1257 | 0 | enum ofpraw raw; |
1258 | |
|
1259 | 0 | error = ofpraw_decode(&raw, oh); |
1260 | 0 | if (!error) { |
1261 | 0 | ofp_header_to_string__(oh, raw, &string); |
1262 | 0 | size_t header_len = string.length; |
1263 | |
|
1264 | 0 | error = ofp_to_string__(oh, port_map, table_map, |
1265 | 0 | raw, &string, verbosity); |
1266 | 0 | if (error) { |
1267 | 0 | if (string.length > header_len) { |
1268 | 0 | ds_chomp(&string, ' '); |
1269 | 0 | add_newline(&string); |
1270 | 0 | } else { |
1271 | 0 | ds_put_char(&string, ' '); |
1272 | 0 | } |
1273 | 0 | ofp_print_error(&string, error); |
1274 | 0 | } else { |
1275 | 0 | ds_chomp(&string, ' '); |
1276 | 0 | } |
1277 | 0 | } else { |
1278 | 0 | ofp_print_error(&string, error); |
1279 | 0 | } |
1280 | |
|
1281 | 0 | if (verbosity >= 5 || error) { |
1282 | 0 | add_newline(&string); |
1283 | 0 | ds_put_hex_dump(&string, oh, len, 0, true); |
1284 | 0 | } |
1285 | |
|
1286 | 0 | add_newline(&string); |
1287 | 0 | return ds_steal_cstr(&string); |
1288 | 0 | } |
1289 | 0 | ds_put_hex_dump(&string, oh, len, 0, true); |
1290 | 0 | return ds_steal_cstr(&string); |
1291 | 0 | } |
1292 | | |
1293 | | static void |
1294 | | print_and_free(FILE *stream, char *string) |
1295 | 0 | { |
1296 | 0 | fputs(string, stream); |
1297 | 0 | free(string); |
1298 | 0 | } |
1299 | | |
1300 | | /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the |
1301 | | * given 'verbosity' level. 0 is a minimal amount of verbosity and higher |
1302 | | * numbers increase verbosity. */ |
1303 | | void |
1304 | | ofp_print(FILE *stream, const void *oh, size_t len, |
1305 | | const struct ofputil_port_map *port_map, |
1306 | | const struct ofputil_table_map *table_map, int verbosity) |
1307 | 0 | { |
1308 | 0 | print_and_free(stream, ofp_to_string(oh, len, port_map, table_map, |
1309 | 0 | verbosity)); |
1310 | 0 | } |
1311 | | |
1312 | | /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at |
1313 | | * 'data' to 'stream'. */ |
1314 | | void |
1315 | | ofp_print_packet(FILE *stream, const void *data, size_t len, |
1316 | | ovs_be32 packet_type) |
1317 | 0 | { |
1318 | 0 | print_and_free(stream, ofp_packet_to_string(data, len, packet_type)); |
1319 | 0 | } |
1320 | | |
1321 | | void |
1322 | | ofp_print_dp_packet(FILE *stream, const struct dp_packet *packet) |
1323 | 0 | { |
1324 | 0 | print_and_free(stream, ofp_dp_packet_to_string(packet)); |
1325 | 0 | } |