]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
e0edde6f | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012 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" |
90bf1e07 | 39 | #include "ofp-errors.h" |
69b6be19 | 40 | #include "ofp-util.h" |
064af421 BP |
41 | #include "ofpbuf.h" |
42 | #include "openflow/openflow.h" | |
43 | #include "openflow/nicira-ext.h" | |
44 | #include "packets.h" | |
45 | #include "pcap.h" | |
e41a9130 | 46 | #include "type-props.h" |
c4617b3c | 47 | #include "unaligned.h" |
064af421 BP |
48 | #include "util.h" |
49 | ||
d2805da2 | 50 | static void ofp_print_queue_name(struct ds *string, uint32_t port); |
90bf1e07 | 51 | static void ofp_print_error(struct ds *, enum ofperr); |
7fa91113 | 52 | |
064af421 BP |
53 | |
54 | /* Returns a string that represents the contents of the Ethernet frame in the | |
897a8e07 | 55 | * 'len' bytes starting at 'data'. The caller must free the returned string.*/ |
064af421 | 56 | char * |
c499c75d | 57 | ofp_packet_to_string(const void *data, size_t len) |
064af421 BP |
58 | { |
59 | struct ds ds = DS_EMPTY_INITIALIZER; | |
60 | struct ofpbuf buf; | |
897a8e07 | 61 | struct flow flow; |
064af421 | 62 | |
0bc9407d | 63 | ofpbuf_use_const(&buf, data, len); |
897a8e07 EJ |
64 | flow_extract(&buf, 0, 0, 0, &flow); |
65 | flow_format(&ds, &flow); | |
e50abca5 EJ |
66 | |
67 | if (buf.l7) { | |
68 | if (flow.nw_proto == IPPROTO_TCP) { | |
69 | struct tcp_header *th = buf.l4; | |
70 | ds_put_format(&ds, " tcp_csum:%"PRIx16, | |
71 | ntohs(th->tcp_csum)); | |
72 | } else if (flow.nw_proto == IPPROTO_UDP) { | |
73 | struct udp_header *uh = buf.l4; | |
74 | ds_put_format(&ds, " udp_csum:%"PRIx16, | |
75 | ntohs(uh->udp_csum)); | |
76 | } | |
77 | } | |
78 | ||
897a8e07 | 79 | ds_put_char(&ds, '\n'); |
064af421 | 80 | |
064af421 BP |
81 | return ds_cstr(&ds); |
82 | } | |
83 | ||
064af421 | 84 | static void |
65120a8a | 85 | ofp_print_packet_in(struct ds *string, const struct ofp_header *oh, |
d1e2cf21 | 86 | int verbosity) |
064af421 | 87 | { |
65120a8a EJ |
88 | struct ofputil_packet_in pin; |
89 | int error; | |
5d6c3af0 | 90 | int i; |
064af421 | 91 | |
65120a8a EJ |
92 | error = ofputil_decode_packet_in(&pin, oh); |
93 | if (error) { | |
94 | ofp_print_error(string, error); | |
95 | return; | |
96 | } | |
97 | ||
54834960 EJ |
98 | if (pin.table_id) { |
99 | ds_put_format(string, " table_id=%"PRIu8, pin.table_id); | |
100 | } | |
101 | ||
102 | if (pin.cookie) { | |
103 | ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie)); | |
104 | } | |
105 | ||
65120a8a | 106 | ds_put_format(string, " total_len=%"PRIu16" in_port=", pin.total_len); |
5d6c3af0 EJ |
107 | ofputil_format_port(pin.fmd.in_port, string); |
108 | ||
109 | if (pin.fmd.tun_id_mask) { | |
110 | ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id)); | |
111 | if (pin.fmd.tun_id_mask != htonll(UINT64_MAX)) { | |
112 | ds_put_format(string, "/0x%"PRIx64, ntohll(pin.fmd.tun_id_mask)); | |
113 | } | |
114 | } | |
115 | ||
116 | for (i = 0; i < FLOW_N_REGS; i++) { | |
117 | if (pin.fmd.reg_masks[i]) { | |
118 | ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]); | |
119 | if (pin.fmd.reg_masks[i] != UINT32_MAX) { | |
120 | ds_put_format(string, "/0x%"PRIx32, pin.fmd.reg_masks[i]); | |
121 | } | |
122 | } | |
123 | } | |
064af421 | 124 | |
80d5aefd | 125 | ds_put_format(string, " (via %s)", |
7c1a76a4 | 126 | ofputil_packet_in_reason_to_string(pin.reason)); |
064af421 | 127 | |
65120a8a EJ |
128 | ds_put_format(string, " data_len=%zu", pin.packet_len); |
129 | if (pin.buffer_id == UINT32_MAX) { | |
064af421 | 130 | ds_put_format(string, " (unbuffered)"); |
65120a8a | 131 | if (pin.total_len != pin.packet_len) { |
064af421 | 132 | ds_put_format(string, " (***total_len != data_len***)"); |
65120a8a | 133 | } |
064af421 | 134 | } else { |
65120a8a EJ |
135 | ds_put_format(string, " buffer=0x%08"PRIx32, pin.buffer_id); |
136 | if (pin.total_len < pin.packet_len) { | |
064af421 | 137 | ds_put_format(string, " (***total_len < data_len***)"); |
65120a8a | 138 | } |
064af421 BP |
139 | } |
140 | ds_put_char(string, '\n'); | |
141 | ||
142 | if (verbosity > 0) { | |
65120a8a | 143 | char *packet = ofp_packet_to_string(pin.packet, pin.packet_len); |
064af421 BP |
144 | ds_put_cstr(string, packet); |
145 | free(packet); | |
146 | } | |
147 | } | |
148 | ||
96fc46e8 BP |
149 | static void |
150 | print_note(struct ds *string, const struct nx_action_note *nan) | |
151 | { | |
152 | size_t len; | |
153 | size_t i; | |
154 | ||
155 | ds_put_cstr(string, "note:"); | |
156 | len = ntohs(nan->len) - offsetof(struct nx_action_note, note); | |
157 | for (i = 0; i < len; i++) { | |
158 | if (i) { | |
159 | ds_put_char(string, '.'); | |
160 | } | |
161 | ds_put_format(string, "%02"PRIx8, nan->note[i]); | |
162 | } | |
163 | } | |
164 | ||
064af421 | 165 | static void |
38f2e360 BP |
166 | ofp_print_action(struct ds *s, const union ofp_action *a, |
167 | enum ofputil_action_code code) | |
064af421 | 168 | { |
38f2e360 BP |
169 | const struct ofp_action_enqueue *oae; |
170 | const struct ofp_action_dl_addr *oada; | |
171 | const struct nx_action_set_tunnel64 *nast64; | |
172 | const struct nx_action_set_tunnel *nast; | |
173 | const struct nx_action_set_queue *nasq; | |
174 | const struct nx_action_resubmit *nar; | |
175 | const struct nx_action_reg_move *move; | |
176 | const struct nx_action_reg_load *load; | |
177 | const struct nx_action_multipath *nam; | |
178 | const struct nx_action_autopath *naa; | |
f694937d | 179 | const struct nx_action_output_reg *naor; |
0e553d9c | 180 | const struct nx_action_fin_timeout *naft; |
a7349929 | 181 | const struct nx_action_controller *nac; |
816fd533 | 182 | struct mf_subfield subfield; |
38f2e360 BP |
183 | uint16_t port; |
184 | ||
185 | switch (code) { | |
08f94c0e | 186 | case OFPUTIL_OFPAT10_OUTPUT: |
38f2e360 BP |
187 | port = ntohs(a->output.port); |
188 | if (port < OFPP_MAX) { | |
189 | ds_put_format(s, "output:%"PRIu16, port); | |
190 | } else { | |
39dc9082 | 191 | ofputil_format_port(port, s); |
38f2e360 BP |
192 | if (port == OFPP_CONTROLLER) { |
193 | if (a->output.max_len != htons(0)) { | |
194 | ds_put_format(s, ":%"PRIu16, ntohs(a->output.max_len)); | |
195 | } else { | |
196 | ds_put_cstr(s, ":all"); | |
197 | } | |
198 | } | |
199 | } | |
200 | break; | |
f393f81e | 201 | |
08f94c0e | 202 | case OFPUTIL_OFPAT10_ENQUEUE: |
38f2e360 BP |
203 | oae = (const struct ofp_action_enqueue *) a; |
204 | ds_put_format(s, "enqueue:"); | |
39dc9082 | 205 | ofputil_format_port(ntohs(oae->port), s); |
38f2e360 BP |
206 | ds_put_format(s, "q%"PRIu32, ntohl(oae->queue_id)); |
207 | break; | |
e41a9130 | 208 | |
08f94c0e | 209 | case OFPUTIL_OFPAT10_SET_VLAN_VID: |
38f2e360 BP |
210 | ds_put_format(s, "mod_vlan_vid:%"PRIu16, |
211 | ntohs(a->vlan_vid.vlan_vid)); | |
212 | break; | |
eedc0097 | 213 | |
08f94c0e | 214 | case OFPUTIL_OFPAT10_SET_VLAN_PCP: |
38f2e360 BP |
215 | ds_put_format(s, "mod_vlan_pcp:%"PRIu8, a->vlan_pcp.vlan_pcp); |
216 | break; | |
96fc46e8 | 217 | |
08f94c0e | 218 | case OFPUTIL_OFPAT10_STRIP_VLAN: |
38f2e360 BP |
219 | ds_put_cstr(s, "strip_vlan"); |
220 | break; | |
064af421 | 221 | |
08f94c0e | 222 | case OFPUTIL_OFPAT10_SET_DL_SRC: |
38f2e360 BP |
223 | oada = (const struct ofp_action_dl_addr *) a; |
224 | ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT, | |
225 | ETH_ADDR_ARGS(oada->dl_addr)); | |
226 | break; | |
064af421 | 227 | |
08f94c0e | 228 | case OFPUTIL_OFPAT10_SET_DL_DST: |
38f2e360 BP |
229 | oada = (const struct ofp_action_dl_addr *) a; |
230 | ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT, | |
231 | ETH_ADDR_ARGS(oada->dl_addr)); | |
232 | break; | |
064af421 | 233 | |
08f94c0e | 234 | case OFPUTIL_OFPAT10_SET_NW_SRC: |
38f2e360 BP |
235 | ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr)); |
236 | break; | |
d295e8e9 | 237 | |
08f94c0e | 238 | case OFPUTIL_OFPAT10_SET_NW_DST: |
38f2e360 | 239 | ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(&a->nw_addr.nw_addr)); |
064af421 | 240 | break; |
064af421 | 241 | |
08f94c0e | 242 | case OFPUTIL_OFPAT10_SET_NW_TOS: |
38f2e360 | 243 | ds_put_format(s, "mod_nw_tos:%d", a->nw_tos.nw_tos); |
c4d279ab | 244 | break; |
c4d279ab | 245 | |
08f94c0e | 246 | case OFPUTIL_OFPAT10_SET_TP_SRC: |
38f2e360 | 247 | ds_put_format(s, "mod_tp_src:%d", ntohs(a->tp_port.tp_port)); |
064af421 | 248 | break; |
064af421 | 249 | |
08f94c0e | 250 | case OFPUTIL_OFPAT10_SET_TP_DST: |
38f2e360 | 251 | ds_put_format(s, "mod_tp_dst:%d", ntohs(a->tp_port.tp_port)); |
064af421 | 252 | break; |
064af421 | 253 | |
38f2e360 BP |
254 | case OFPUTIL_NXAST_RESUBMIT: |
255 | nar = (struct nx_action_resubmit *)a; | |
256 | ds_put_format(s, "resubmit:"); | |
39dc9082 | 257 | ofputil_format_port(ntohs(nar->in_port), s); |
064af421 BP |
258 | break; |
259 | ||
29901626 BP |
260 | case OFPUTIL_NXAST_RESUBMIT_TABLE: |
261 | nar = (struct nx_action_resubmit *)a; | |
262 | ds_put_format(s, "resubmit("); | |
263 | if (nar->in_port != htons(OFPP_IN_PORT)) { | |
39dc9082 | 264 | ofputil_format_port(ntohs(nar->in_port), s); |
29901626 BP |
265 | } |
266 | ds_put_char(s, ','); | |
267 | if (nar->table != 255) { | |
268 | ds_put_format(s, "%"PRIu8, nar->table); | |
269 | } | |
270 | ds_put_char(s, ')'); | |
271 | break; | |
272 | ||
38f2e360 BP |
273 | case OFPUTIL_NXAST_SET_TUNNEL: |
274 | nast = (struct nx_action_set_tunnel *)a; | |
275 | ds_put_format(s, "set_tunnel:%#"PRIx32, ntohl(nast->tun_id)); | |
064af421 | 276 | break; |
064af421 | 277 | |
38f2e360 BP |
278 | case OFPUTIL_NXAST_SET_QUEUE: |
279 | nasq = (struct nx_action_set_queue *)a; | |
280 | ds_put_format(s, "set_queue:%u", ntohl(nasq->queue_id)); | |
064af421 | 281 | break; |
064af421 | 282 | |
38f2e360 BP |
283 | case OFPUTIL_NXAST_POP_QUEUE: |
284 | ds_put_cstr(s, "pop_queue"); | |
064af421 | 285 | break; |
064af421 | 286 | |
38f2e360 BP |
287 | case OFPUTIL_NXAST_NOTE: |
288 | print_note(s, (const struct nx_action_note *) a); | |
064af421 | 289 | break; |
064af421 | 290 | |
38f2e360 BP |
291 | case OFPUTIL_NXAST_REG_MOVE: |
292 | move = (const struct nx_action_reg_move *) a; | |
293 | nxm_format_reg_move(move, s); | |
959a2ecd | 294 | break; |
959a2ecd | 295 | |
38f2e360 BP |
296 | case OFPUTIL_NXAST_REG_LOAD: |
297 | load = (const struct nx_action_reg_load *) a; | |
298 | nxm_format_reg_load(load, s); | |
064af421 | 299 | break; |
064af421 | 300 | |
38f2e360 BP |
301 | case OFPUTIL_NXAST_SET_TUNNEL64: |
302 | nast64 = (const struct nx_action_set_tunnel64 *) a; | |
303 | ds_put_format(s, "set_tunnel64:%#"PRIx64, | |
304 | ntohll(nast64->tun_id)); | |
064af421 | 305 | break; |
064af421 | 306 | |
38f2e360 BP |
307 | case OFPUTIL_NXAST_MULTIPATH: |
308 | nam = (const struct nx_action_multipath *) a; | |
309 | multipath_format(nam, s); | |
310 | break; | |
311 | ||
312 | case OFPUTIL_NXAST_AUTOPATH: | |
313 | naa = (const struct nx_action_autopath *)a; | |
314 | ds_put_format(s, "autopath(%u,", ntohl(naa->id)); | |
816fd533 BP |
315 | nxm_decode(&subfield, naa->dst, naa->ofs_nbits); |
316 | mf_format_subfield(&subfield, s); | |
38f2e360 | 317 | ds_put_char(s, ')'); |
064af421 | 318 | break; |
064af421 | 319 | |
daff3353 | 320 | case OFPUTIL_NXAST_BUNDLE: |
a368bb53 | 321 | case OFPUTIL_NXAST_BUNDLE_LOAD: |
daff3353 EJ |
322 | bundle_format((const struct nx_action_bundle *) a, s); |
323 | break; | |
324 | ||
f694937d EJ |
325 | case OFPUTIL_NXAST_OUTPUT_REG: |
326 | naor = (const struct nx_action_output_reg *) a; | |
327 | ds_put_cstr(s, "output:"); | |
816fd533 BP |
328 | nxm_decode(&subfield, naor->src, naor->ofs_nbits); |
329 | mf_format_subfield(&subfield, s); | |
0c58c0c4 | 330 | break; |
f694937d | 331 | |
75a75043 BP |
332 | case OFPUTIL_NXAST_LEARN: |
333 | learn_format((const struct nx_action_learn *) a, s); | |
334 | break; | |
335 | ||
f0fd1a17 PS |
336 | case OFPUTIL_NXAST_DEC_TTL: |
337 | ds_put_cstr(s, "dec_ttl"); | |
338 | break; | |
339 | ||
848e8809 EJ |
340 | case OFPUTIL_NXAST_EXIT: |
341 | ds_put_cstr(s, "exit"); | |
342 | break; | |
343 | ||
0e553d9c BP |
344 | case OFPUTIL_NXAST_FIN_TIMEOUT: |
345 | naft = (const struct nx_action_fin_timeout *) a; | |
346 | ds_put_cstr(s, "fin_timeout("); | |
347 | if (naft->fin_idle_timeout) { | |
348 | ds_put_format(s, "idle_timeout=%"PRIu16",", | |
349 | ntohs(naft->fin_idle_timeout)); | |
350 | } | |
351 | if (naft->fin_hard_timeout) { | |
352 | ds_put_format(s, "hard_timeout=%"PRIu16",", | |
353 | ntohs(naft->fin_hard_timeout)); | |
354 | } | |
355 | ds_chomp(s, ','); | |
356 | ds_put_char(s, ')'); | |
357 | break; | |
358 | ||
a7349929 BP |
359 | case OFPUTIL_NXAST_CONTROLLER: |
360 | nac = (const struct nx_action_controller *) a; | |
361 | ds_put_cstr(s, "controller("); | |
362 | if (nac->reason != OFPR_ACTION) { | |
363 | ds_put_format(s, "reason=%s,", | |
364 | ofputil_packet_in_reason_to_string(nac->reason)); | |
365 | } | |
366 | if (nac->max_len != htons(UINT16_MAX)) { | |
367 | ds_put_format(s, "max_len=%"PRIu16",", ntohs(nac->max_len)); | |
368 | } | |
369 | if (nac->controller_id != htons(0)) { | |
370 | ds_put_format(s, "id=%"PRIu16",", ntohs(nac->controller_id)); | |
371 | } | |
372 | ds_chomp(s, ','); | |
373 | ds_put_char(s, ')'); | |
374 | break; | |
375 | ||
064af421 | 376 | default: |
064af421 BP |
377 | break; |
378 | } | |
064af421 BP |
379 | } |
380 | ||
d295e8e9 | 381 | void |
b4b8c781 BP |
382 | ofp_print_actions(struct ds *string, const union ofp_action *actions, |
383 | size_t n_actions) | |
064af421 | 384 | { |
b4b8c781 BP |
385 | const union ofp_action *a; |
386 | size_t left; | |
064af421 BP |
387 | |
388 | ds_put_cstr(string, "actions="); | |
b4b8c781 | 389 | if (!n_actions) { |
064af421 BP |
390 | ds_put_cstr(string, "drop"); |
391 | } | |
38f2e360 | 392 | |
b4b8c781 | 393 | OFPUTIL_ACTION_FOR_EACH (a, left, actions, n_actions) { |
38f2e360 BP |
394 | int code = ofputil_decode_action(a); |
395 | if (code >= 0) { | |
396 | if (a != actions) { | |
397 | ds_put_cstr(string, ","); | |
398 | } | |
399 | ofp_print_action(string, a, code); | |
400 | } else { | |
401 | ofp_print_error(string, -code); | |
064af421 | 402 | } |
b4b8c781 BP |
403 | } |
404 | if (left > 0) { | |
405 | ds_put_format(string, " ***%zu leftover bytes following actions", | |
406 | left * sizeof *a); | |
064af421 BP |
407 | } |
408 | } | |
409 | ||
d1e2cf21 BP |
410 | static void |
411 | ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo, | |
412 | int verbosity) | |
064af421 | 413 | { |
c6a93eb7 BP |
414 | struct ofputil_packet_out po; |
415 | enum ofperr error; | |
064af421 | 416 | |
c6a93eb7 BP |
417 | error = ofputil_decode_packet_out(&po, opo); |
418 | if (error) { | |
419 | ofp_print_error(string, error); | |
064af421 BP |
420 | return; |
421 | } | |
c6a93eb7 BP |
422 | |
423 | ds_put_cstr(string, " in_port="); | |
424 | ofputil_format_port(po.in_port, string); | |
425 | ||
426 | ds_put_char(string, ' '); | |
427 | ofp_print_actions(string, po.actions, po.n_actions); | |
428 | ||
429 | if (po.buffer_id == UINT32_MAX) { | |
29530977 | 430 | ds_put_format(string, " data_len=%zu", po.packet_len); |
c6a93eb7 BP |
431 | if (verbosity > 0 && po.packet_len > 0) { |
432 | char *packet = ofp_packet_to_string(po.packet, po.packet_len); | |
064af421 BP |
433 | ds_put_char(string, '\n'); |
434 | ds_put_cstr(string, packet); | |
435 | free(packet); | |
436 | } | |
437 | } else { | |
c6a93eb7 | 438 | ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id); |
064af421 BP |
439 | } |
440 | ds_put_char(string, '\n'); | |
441 | } | |
442 | ||
443 | /* qsort comparison function. */ | |
444 | static int | |
445 | compare_ports(const void *a_, const void *b_) | |
446 | { | |
9e1fd49b BP |
447 | const struct ofputil_phy_port *a = a_; |
448 | const struct ofputil_phy_port *b = b_; | |
449 | uint16_t ap = a->port_no; | |
450 | uint16_t bp = b->port_no; | |
064af421 BP |
451 | |
452 | return ap < bp ? -1 : ap > bp; | |
453 | } | |
454 | ||
0ab14c8e BP |
455 | static void |
456 | ofp_print_bit_names(struct ds *string, uint32_t bits, | |
9e1fd49b | 457 | const char *(*bit_to_name)(uint32_t bit)) |
064af421 | 458 | { |
0ab14c8e | 459 | int n = 0; |
9e1fd49b | 460 | int i; |
0ab14c8e BP |
461 | |
462 | if (!bits) { | |
463 | ds_put_cstr(string, "0"); | |
064af421 BP |
464 | return; |
465 | } | |
0ab14c8e | 466 | |
9e1fd49b BP |
467 | for (i = 0; i < 32; i++) { |
468 | uint32_t bit = UINT32_C(1) << i; | |
469 | ||
470 | if (bits & bit) { | |
471 | const char *name = bit_to_name(bit); | |
472 | if (name) { | |
473 | if (n++) { | |
474 | ds_put_char(string, ' '); | |
475 | } | |
476 | ds_put_cstr(string, name); | |
477 | bits &= ~bit; | |
0ab14c8e | 478 | } |
0ab14c8e | 479 | } |
064af421 | 480 | } |
0ab14c8e BP |
481 | |
482 | if (bits) { | |
f5cd6874 | 483 | if (n) { |
0ab14c8e BP |
484 | ds_put_char(string, ' '); |
485 | } | |
486 | ds_put_format(string, "0x%"PRIx32, bits); | |
064af421 | 487 | } |
0ab14c8e BP |
488 | } |
489 | ||
9e1fd49b BP |
490 | static const char * |
491 | netdev_feature_to_name(uint32_t bit) | |
492 | { | |
493 | enum netdev_features f = bit; | |
494 | ||
495 | switch (f) { | |
496 | case NETDEV_F_10MB_HD: return "10MB-HD"; | |
497 | case NETDEV_F_10MB_FD: return "10MB-FD"; | |
498 | case NETDEV_F_100MB_HD: return "100MB-HD"; | |
499 | case NETDEV_F_100MB_FD: return "100MB-FD"; | |
500 | case NETDEV_F_1GB_HD: return "1GB-HD"; | |
501 | case NETDEV_F_1GB_FD: return "1GB-FD"; | |
502 | case NETDEV_F_10GB_FD: return "10GB-FD"; | |
503 | case NETDEV_F_40GB_FD: return "40GB-FD"; | |
504 | case NETDEV_F_100GB_FD: return "100GB-FD"; | |
505 | case NETDEV_F_1TB_FD: return "1TB-FD"; | |
506 | case NETDEV_F_OTHER: return "OTHER"; | |
507 | case NETDEV_F_COPPER: return "COPPER"; | |
508 | case NETDEV_F_FIBER: return "FIBER"; | |
509 | case NETDEV_F_AUTONEG: return "AUTO_NEG"; | |
510 | case NETDEV_F_PAUSE: return "AUTO_PAUSE"; | |
511 | case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM"; | |
512 | } | |
513 | ||
514 | return NULL; | |
515 | } | |
516 | ||
0ab14c8e | 517 | static void |
9e1fd49b | 518 | ofp_print_port_features(struct ds *string, enum netdev_features features) |
0ab14c8e | 519 | { |
9e1fd49b | 520 | ofp_print_bit_names(string, features, netdev_feature_to_name); |
0ab14c8e BP |
521 | ds_put_char(string, '\n'); |
522 | } | |
523 | ||
9e1fd49b BP |
524 | static const char * |
525 | ofputil_port_config_to_name(uint32_t bit) | |
526 | { | |
527 | enum ofputil_port_config pc = bit; | |
528 | ||
529 | switch (pc) { | |
530 | case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN"; | |
531 | case OFPUTIL_PC_NO_STP: return "NO_STP"; | |
532 | case OFPUTIL_PC_NO_RECV: return "NO_RECV"; | |
533 | case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP"; | |
534 | case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD"; | |
535 | case OFPUTIL_PC_NO_FWD: return "NO_FWD"; | |
536 | case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN"; | |
537 | } | |
538 | ||
539 | return NULL; | |
540 | } | |
541 | ||
0ab14c8e | 542 | static void |
9e1fd49b | 543 | ofp_print_port_config(struct ds *string, enum ofputil_port_config config) |
0ab14c8e | 544 | { |
9e1fd49b | 545 | ofp_print_bit_names(string, config, ofputil_port_config_to_name); |
0ab14c8e BP |
546 | ds_put_char(string, '\n'); |
547 | } | |
548 | ||
9e1fd49b BP |
549 | static const char * |
550 | ofputil_port_state_to_name(uint32_t bit) | |
551 | { | |
552 | enum ofputil_port_state ps = bit; | |
553 | ||
554 | switch (ps) { | |
555 | case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN"; | |
556 | case OFPUTIL_PS_BLOCKED: return "BLOCKED"; | |
557 | case OFPUTIL_PS_LIVE: return "LIVE"; | |
558 | ||
559 | case OFPUTIL_PS_STP_LISTEN: | |
560 | case OFPUTIL_PS_STP_LEARN: | |
561 | case OFPUTIL_PS_STP_FORWARD: | |
562 | case OFPUTIL_PS_STP_BLOCK: | |
563 | /* Handled elsewhere. */ | |
564 | return NULL; | |
565 | } | |
566 | ||
567 | return NULL; | |
568 | } | |
569 | ||
0ab14c8e | 570 | static void |
9e1fd49b | 571 | ofp_print_port_state(struct ds *string, enum ofputil_port_state state) |
0ab14c8e | 572 | { |
9e1fd49b | 573 | enum ofputil_port_state stp_state; |
0ab14c8e BP |
574 | |
575 | /* The STP state is a 2-bit field so it doesn't fit in with the bitmask | |
576 | * pattern. We have to special case it. | |
577 | * | |
578 | * OVS doesn't support STP, so this field will always be 0 if we are | |
579 | * talking to OVS, so we'd always print STP_LISTEN in that case. | |
580 | * Therefore, we don't print anything at all if the value is STP_LISTEN, to | |
581 | * avoid confusing users. */ | |
9e1fd49b | 582 | stp_state = state & OFPUTIL_PS_STP_MASK; |
0ab14c8e | 583 | if (stp_state) { |
9e1fd49b BP |
584 | ds_put_cstr(string, |
585 | (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN" | |
586 | : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD" | |
587 | : "STP_BLOCK")); | |
588 | state &= ~OFPUTIL_PS_STP_MASK; | |
0ab14c8e | 589 | if (state) { |
9e1fd49b | 590 | ofp_print_bit_names(string, state, ofputil_port_state_to_name); |
0ab14c8e BP |
591 | } |
592 | } else { | |
9e1fd49b | 593 | ofp_print_bit_names(string, state, ofputil_port_state_to_name); |
064af421 BP |
594 | } |
595 | ds_put_char(string, '\n'); | |
596 | } | |
597 | ||
598 | static void | |
9e1fd49b | 599 | ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port) |
064af421 | 600 | { |
9e1fd49b | 601 | char name[sizeof port->name]; |
064af421 BP |
602 | int j; |
603 | ||
604 | memcpy(name, port->name, sizeof name); | |
605 | for (j = 0; j < sizeof name - 1; j++) { | |
858f2852 | 606 | if (!isprint((unsigned char) name[j])) { |
064af421 BP |
607 | break; |
608 | } | |
609 | } | |
610 | name[j] = '\0'; | |
611 | ||
612 | ds_put_char(string, ' '); | |
9e1fd49b | 613 | ofputil_format_port(port->port_no, string); |
0ab14c8e BP |
614 | ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n", |
615 | name, ETH_ADDR_ARGS(port->hw_addr)); | |
616 | ||
617 | ds_put_cstr(string, " config: "); | |
9e1fd49b | 618 | ofp_print_port_config(string, port->config); |
0ab14c8e BP |
619 | |
620 | ds_put_cstr(string, " state: "); | |
9e1fd49b | 621 | ofp_print_port_state(string, port->state); |
0ab14c8e | 622 | |
064af421 BP |
623 | if (port->curr) { |
624 | ds_put_format(string, " current: "); | |
9e1fd49b | 625 | ofp_print_port_features(string, port->curr); |
064af421 BP |
626 | } |
627 | if (port->advertised) { | |
628 | ds_put_format(string, " advertised: "); | |
9e1fd49b | 629 | ofp_print_port_features(string, port->advertised); |
064af421 BP |
630 | } |
631 | if (port->supported) { | |
632 | ds_put_format(string, " supported: "); | |
9e1fd49b | 633 | ofp_print_port_features(string, port->supported); |
064af421 BP |
634 | } |
635 | if (port->peer) { | |
636 | ds_put_format(string, " peer: "); | |
9e1fd49b BP |
637 | ofp_print_port_features(string, port->peer); |
638 | } | |
639 | ds_put_format(string, " speed: %"PRIu32" Mbps now, " | |
640 | "%"PRIu32" Mbps max\n", | |
641 | port->curr_speed / UINT32_C(1000), | |
642 | port->max_speed / UINT32_C(1000)); | |
643 | } | |
644 | ||
2be393ed JP |
645 | /* Given a buffer 'b' that contains an array of OpenFlow ports of type |
646 | * 'ofp_version', writes a detailed description of each port into | |
647 | * 'string'. */ | |
648 | static void | |
649 | ofp_print_phy_ports(struct ds *string, uint8_t ofp_version, | |
650 | struct ofpbuf *b) | |
651 | { | |
652 | size_t n_ports; | |
653 | struct ofputil_phy_port *ports; | |
654 | enum ofperr error; | |
655 | size_t i; | |
656 | ||
657 | n_ports = ofputil_count_phy_ports(ofp_version, b); | |
658 | ||
659 | ports = xmalloc(n_ports * sizeof *ports); | |
660 | for (i = 0; i < n_ports; i++) { | |
661 | error = ofputil_pull_phy_port(ofp_version, b, &ports[i]); | |
662 | if (error) { | |
663 | ofp_print_error(string, error); | |
664 | goto exit; | |
665 | } | |
666 | } | |
667 | qsort(ports, n_ports, sizeof *ports, compare_ports); | |
668 | for (i = 0; i < n_ports; i++) { | |
669 | ofp_print_phy_port(string, &ports[i]); | |
670 | } | |
671 | ||
672 | exit: | |
673 | free(ports); | |
674 | } | |
675 | ||
9e1fd49b BP |
676 | static const char * |
677 | ofputil_capabilities_to_name(uint32_t bit) | |
678 | { | |
679 | enum ofputil_capabilities capabilities = bit; | |
680 | ||
681 | switch (capabilities) { | |
682 | case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS"; | |
683 | case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS"; | |
684 | case OFPUTIL_C_PORT_STATS: return "PORT_STATS"; | |
685 | case OFPUTIL_C_IP_REASM: return "IP_REASM"; | |
686 | case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS"; | |
687 | case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP"; | |
688 | case OFPUTIL_C_STP: return "STP"; | |
689 | case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS"; | |
690 | } | |
691 | ||
692 | return NULL; | |
693 | } | |
694 | ||
695 | static const char * | |
696 | ofputil_action_bitmap_to_name(uint32_t bit) | |
697 | { | |
698 | enum ofputil_action_bitmap action = bit; | |
699 | ||
700 | switch (action) { | |
701 | case OFPUTIL_A_OUTPUT: return "OUTPUT"; | |
702 | case OFPUTIL_A_SET_VLAN_VID: return "SET_VLAN_VID"; | |
703 | case OFPUTIL_A_SET_VLAN_PCP: return "SET_VLAN_PCP"; | |
704 | case OFPUTIL_A_STRIP_VLAN: return "STRIP_VLAN"; | |
705 | case OFPUTIL_A_SET_DL_SRC: return "SET_DL_SRC"; | |
706 | case OFPUTIL_A_SET_DL_DST: return "SET_DL_DST"; | |
707 | case OFPUTIL_A_SET_NW_SRC: return "SET_NW_SRC"; | |
708 | case OFPUTIL_A_SET_NW_DST: return "SET_NW_DST"; | |
709 | case OFPUTIL_A_SET_NW_ECN: return "SET_NW_ECN"; | |
710 | case OFPUTIL_A_SET_NW_TOS: return "SET_NW_TOS"; | |
711 | case OFPUTIL_A_SET_TP_SRC: return "SET_TP_SRC"; | |
712 | case OFPUTIL_A_SET_TP_DST: return "SET_TP_DST"; | |
713 | case OFPUTIL_A_ENQUEUE: return "ENQUEUE"; | |
714 | case OFPUTIL_A_COPY_TTL_OUT: return "COPY_TTL_OUT"; | |
715 | case OFPUTIL_A_COPY_TTL_IN: return "COPY_TTL_IN"; | |
716 | case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL"; | |
717 | case OFPUTIL_A_SET_MPLS_TC: return "SET_MPLS_TC"; | |
718 | case OFPUTIL_A_SET_MPLS_TTL: return "SET_MPLS_TTL"; | |
719 | case OFPUTIL_A_DEC_MPLS_TTL: return "DEC_MPLS_TTL"; | |
720 | case OFPUTIL_A_PUSH_VLAN: return "PUSH_VLAN"; | |
721 | case OFPUTIL_A_POP_VLAN: return "POP_VLAN"; | |
722 | case OFPUTIL_A_PUSH_MPLS: return "PUSH_MPLS"; | |
723 | case OFPUTIL_A_POP_MPLS: return "POP_MPLS"; | |
724 | case OFPUTIL_A_SET_QUEUE: return "SET_QUEUE"; | |
725 | case OFPUTIL_A_GROUP: return "GROUP"; | |
726 | case OFPUTIL_A_SET_NW_TTL: return "SET_NW_TTL"; | |
727 | case OFPUTIL_A_DEC_NW_TTL: return "DEC_NW_TTL"; | |
064af421 | 728 | } |
9e1fd49b BP |
729 | |
730 | return NULL; | |
064af421 BP |
731 | } |
732 | ||
064af421 | 733 | static void |
d1e2cf21 BP |
734 | ofp_print_switch_features(struct ds *string, |
735 | const struct ofp_switch_features *osf) | |
064af421 | 736 | { |
9e1fd49b | 737 | struct ofputil_switch_features features; |
9e1fd49b BP |
738 | enum ofperr error; |
739 | struct ofpbuf b; | |
064af421 | 740 | |
9e1fd49b BP |
741 | error = ofputil_decode_switch_features(osf, &features, &b); |
742 | if (error) { | |
743 | ofp_print_error(string, error); | |
744 | return; | |
745 | } | |
064af421 | 746 | |
9e1fd49b BP |
747 | ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id); |
748 | ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32"\n", | |
749 | features.n_tables, features.n_buffers); | |
064af421 | 750 | |
9e1fd49b BP |
751 | ds_put_cstr(string, "capabilities: "); |
752 | ofp_print_bit_names(string, features.capabilities, | |
753 | ofputil_capabilities_to_name); | |
754 | ds_put_char(string, '\n'); | |
755 | ||
756 | ds_put_cstr(string, "actions: "); | |
757 | ofp_print_bit_names(string, features.actions, | |
758 | ofputil_action_bitmap_to_name); | |
759 | ds_put_char(string, '\n'); | |
760 | ||
2be393ed | 761 | ofp_print_phy_ports(string, osf->header.version, &b); |
064af421 BP |
762 | } |
763 | ||
064af421 | 764 | static void |
d1e2cf21 | 765 | ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc) |
064af421 | 766 | { |
f0fd1a17 | 767 | enum ofp_config_flags flags; |
064af421 BP |
768 | |
769 | flags = ntohs(osc->flags); | |
3b62feba | 770 | |
7257b535 BP |
771 | ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags)); |
772 | flags &= ~OFPC_FRAG_MASK; | |
773 | ||
f0fd1a17 PS |
774 | if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) { |
775 | ds_put_format(string, " invalid_ttl_to_controller"); | |
776 | flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER; | |
777 | } | |
778 | ||
064af421 BP |
779 | if (flags) { |
780 | ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags); | |
781 | } | |
782 | ||
783 | ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len)); | |
784 | } | |
785 | ||
786 | static void print_wild(struct ds *string, const char *leader, int is_wild, | |
d295e8e9 | 787 | int verbosity, const char *format, ...) |
064af421 BP |
788 | __attribute__((format(printf, 5, 6))); |
789 | ||
790 | static void print_wild(struct ds *string, const char *leader, int is_wild, | |
d295e8e9 | 791 | int verbosity, const char *format, ...) |
064af421 BP |
792 | { |
793 | if (is_wild && verbosity < 2) { | |
794 | return; | |
795 | } | |
796 | ds_put_cstr(string, leader); | |
797 | if (!is_wild) { | |
798 | va_list args; | |
799 | ||
800 | va_start(args, format); | |
801 | ds_put_format_valist(string, format, args); | |
802 | va_end(args); | |
803 | } else { | |
804 | ds_put_char(string, '*'); | |
805 | } | |
806 | ds_put_char(string, ','); | |
807 | } | |
808 | ||
809 | static void | |
dbba996b | 810 | print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip, |
064af421 BP |
811 | uint32_t wild_bits, int verbosity) |
812 | { | |
813 | if (wild_bits >= 32 && verbosity < 2) { | |
814 | return; | |
815 | } | |
816 | ds_put_cstr(string, leader); | |
817 | if (wild_bits < 32) { | |
818 | ds_put_format(string, IP_FMT, IP_ARGS(&ip)); | |
819 | if (wild_bits) { | |
820 | ds_put_format(string, "/%d", 32 - wild_bits); | |
821 | } | |
822 | } else { | |
823 | ds_put_char(string, '*'); | |
824 | } | |
825 | ds_put_char(string, ','); | |
826 | } | |
827 | ||
4f2cad2c | 828 | void |
eec25dc1 | 829 | ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity) |
064af421 | 830 | { |
eec25dc1 | 831 | char *s = ofp10_match_to_string(om, verbosity); |
064af421 BP |
832 | ds_put_cstr(f, s); |
833 | free(s); | |
834 | } | |
835 | ||
836 | char * | |
eec25dc1 | 837 | ofp10_match_to_string(const struct ofp10_match *om, int verbosity) |
064af421 BP |
838 | { |
839 | struct ds f = DS_EMPTY_INITIALIZER; | |
840 | uint32_t w = ntohl(om->wildcards); | |
841 | bool skip_type = false; | |
842 | bool skip_proto = false; | |
843 | ||
eec25dc1 | 844 | if (!(w & OFPFW10_DL_TYPE)) { |
064af421 BP |
845 | skip_type = true; |
846 | if (om->dl_type == htons(ETH_TYPE_IP)) { | |
eec25dc1 | 847 | if (!(w & OFPFW10_NW_PROTO)) { |
064af421 | 848 | skip_proto = true; |
6767a2cc | 849 | if (om->nw_proto == IPPROTO_ICMP) { |
064af421 | 850 | ds_put_cstr(&f, "icmp,"); |
6767a2cc | 851 | } else if (om->nw_proto == IPPROTO_TCP) { |
064af421 | 852 | ds_put_cstr(&f, "tcp,"); |
6767a2cc | 853 | } else if (om->nw_proto == IPPROTO_UDP) { |
064af421 BP |
854 | ds_put_cstr(&f, "udp,"); |
855 | } else { | |
856 | ds_put_cstr(&f, "ip,"); | |
857 | skip_proto = false; | |
858 | } | |
859 | } else { | |
860 | ds_put_cstr(&f, "ip,"); | |
861 | } | |
862 | } else if (om->dl_type == htons(ETH_TYPE_ARP)) { | |
863 | ds_put_cstr(&f, "arp,"); | |
864 | } else { | |
865 | skip_type = false; | |
866 | } | |
867 | } | |
eec25dc1 | 868 | print_wild(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity, |
064af421 | 869 | "%d", ntohs(om->in_port)); |
eec25dc1 | 870 | print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity, |
6a1f89c8 | 871 | "%d", ntohs(om->dl_vlan)); |
eec25dc1 | 872 | print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity, |
959a2ecd | 873 | "%d", om->dl_vlan_pcp); |
eec25dc1 | 874 | print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity, |
064af421 | 875 | ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src)); |
eec25dc1 | 876 | print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity, |
064af421 BP |
877 | ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst)); |
878 | if (!skip_type) { | |
eec25dc1 | 879 | print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity, |
064af421 BP |
880 | "0x%04x", ntohs(om->dl_type)); |
881 | } | |
882 | print_ip_netmask(&f, "nw_src=", om->nw_src, | |
eec25dc1 BP |
883 | (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT, |
884 | verbosity); | |
064af421 | 885 | print_ip_netmask(&f, "nw_dst=", om->nw_dst, |
eec25dc1 BP |
886 | (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT, |
887 | verbosity); | |
064af421 | 888 | if (!skip_proto) { |
fb892732 | 889 | if (om->dl_type == htons(ETH_TYPE_ARP)) { |
eec25dc1 | 890 | print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity, |
fb892732 JP |
891 | "%u", om->nw_proto); |
892 | } else { | |
eec25dc1 | 893 | print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity, |
fb892732 JP |
894 | "%u", om->nw_proto); |
895 | } | |
064af421 | 896 | } |
eec25dc1 | 897 | print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity, |
1a960c80 | 898 | "%u", om->nw_tos); |
6767a2cc | 899 | if (om->nw_proto == IPPROTO_ICMP) { |
eec25dc1 | 900 | print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity, |
3ee8a9f0 | 901 | "%d", ntohs(om->tp_src)); |
eec25dc1 | 902 | print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity, |
3ee8a9f0 | 903 | "%d", ntohs(om->tp_dst)); |
064af421 | 904 | } else { |
eec25dc1 | 905 | print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity, |
064af421 | 906 | "%d", ntohs(om->tp_src)); |
eec25dc1 | 907 | print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity, |
064af421 BP |
908 | "%d", ntohs(om->tp_dst)); |
909 | } | |
7fa91113 BP |
910 | if (ds_last(&f) == ',') { |
911 | f.length--; | |
912 | } | |
064af421 BP |
913 | return ds_cstr(&f); |
914 | } | |
915 | ||
064af421 | 916 | static void |
7fa91113 BP |
917 | ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, |
918 | enum ofputil_msg_code code, int verbosity) | |
064af421 | 919 | { |
a9a2da38 | 920 | struct ofputil_flow_mod fm; |
f904747b | 921 | bool need_priority; |
90bf1e07 | 922 | enum ofperr error; |
064af421 | 923 | |
27527aa0 | 924 | error = ofputil_decode_flow_mod(&fm, oh, OFPUTIL_P_OF10_TID); |
7fa91113 BP |
925 | if (error) { |
926 | ofp_print_error(s, error); | |
927 | return; | |
3ff4f871 BP |
928 | } |
929 | ||
7fa91113 BP |
930 | ds_put_char(s, ' '); |
931 | switch (fm.command) { | |
064af421 | 932 | case OFPFC_ADD: |
7fa91113 | 933 | ds_put_cstr(s, "ADD"); |
064af421 BP |
934 | break; |
935 | case OFPFC_MODIFY: | |
7fa91113 | 936 | ds_put_cstr(s, "MOD"); |
064af421 BP |
937 | break; |
938 | case OFPFC_MODIFY_STRICT: | |
7fa91113 | 939 | ds_put_cstr(s, "MOD_STRICT"); |
064af421 BP |
940 | break; |
941 | case OFPFC_DELETE: | |
7fa91113 | 942 | ds_put_cstr(s, "DEL"); |
064af421 BP |
943 | break; |
944 | case OFPFC_DELETE_STRICT: | |
7fa91113 | 945 | ds_put_cstr(s, "DEL_STRICT"); |
064af421 BP |
946 | break; |
947 | default: | |
7fa91113 BP |
948 | ds_put_format(s, "cmd:%d", fm.command); |
949 | } | |
6c1491fb | 950 | if (fm.table_id != 0) { |
e896c2d4 | 951 | ds_put_format(s, " table:%d", fm.table_id); |
6c1491fb | 952 | } |
7fa91113 BP |
953 | |
954 | ds_put_char(s, ' '); | |
955 | if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) { | |
956 | const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh; | |
eec25dc1 | 957 | ofp10_match_print(s, &ofm->match, verbosity); |
f904747b BP |
958 | |
959 | /* ofp_print_match() doesn't print priority. */ | |
960 | need_priority = true; | |
7fa91113 BP |
961 | } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) { |
962 | const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh; | |
963 | const void *nxm = nfm + 1; | |
f904747b BP |
964 | char *nxm_s; |
965 | ||
966 | nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len)); | |
7fa91113 BP |
967 | ds_put_cstr(s, nxm_s); |
968 | free(nxm_s); | |
f904747b BP |
969 | |
970 | /* nx_match_to_string() doesn't print priority. */ | |
971 | need_priority = true; | |
7fa91113 BP |
972 | } else { |
973 | cls_rule_format(&fm.cr, s); | |
f904747b BP |
974 | |
975 | /* cls_rule_format() does print priority. */ | |
976 | need_priority = false; | |
3ff4f871 | 977 | } |
7fa91113 BP |
978 | |
979 | if (ds_last(s) != ' ') { | |
980 | ds_put_char(s, ' '); | |
3ff4f871 | 981 | } |
623e1caf JP |
982 | if (fm.new_cookie != htonll(0)) { |
983 | ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie)); | |
984 | } | |
985 | if (fm.cookie_mask != htonll(0)) { | |
986 | ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ", | |
987 | ntohll(fm.cookie), ntohll(fm.cookie_mask)); | |
3ff4f871 | 988 | } |
7fa91113 BP |
989 | if (fm.idle_timeout != OFP_FLOW_PERMANENT) { |
990 | ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout); | |
064af421 | 991 | } |
7fa91113 BP |
992 | if (fm.hard_timeout != OFP_FLOW_PERMANENT) { |
993 | ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout); | |
3ff4f871 | 994 | } |
f904747b | 995 | if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) { |
7fa91113 | 996 | ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority); |
3ff4f871 | 997 | } |
7fa91113 BP |
998 | if (fm.buffer_id != UINT32_MAX) { |
999 | ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id); | |
3ff4f871 | 1000 | } |
7fa91113 | 1001 | if (fm.flags != 0) { |
a993007b BP |
1002 | uint16_t flags = fm.flags; |
1003 | ||
1004 | if (flags & OFPFF_SEND_FLOW_REM) { | |
1005 | ds_put_cstr(s, "send_flow_rem "); | |
1006 | } | |
1007 | if (flags & OFPFF_CHECK_OVERLAP) { | |
1008 | ds_put_cstr(s, "check_overlap "); | |
1009 | } | |
1010 | if (flags & OFPFF_EMERG) { | |
1011 | ds_put_cstr(s, "emerg "); | |
1012 | } | |
1013 | ||
1014 | flags &= ~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG); | |
1015 | if (flags) { | |
1016 | ds_put_format(s, "flags:0x%"PRIx16" ", flags); | |
1017 | } | |
7fa91113 BP |
1018 | } |
1019 | ||
b4b8c781 | 1020 | ofp_print_actions(s, fm.actions, fm.n_actions); |
064af421 BP |
1021 | } |
1022 | ||
09862ec6 BP |
1023 | static void |
1024 | ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec) | |
1025 | { | |
1026 | ds_put_format(string, "%u", sec); | |
1027 | if (nsec > 0) { | |
1028 | ds_put_format(string, ".%09u", nsec); | |
1029 | while (string->string[string->length - 1] == '0') { | |
1030 | string->length--; | |
1031 | } | |
1032 | } | |
1033 | ds_put_char(string, 's'); | |
1034 | } | |
1035 | ||
80d5aefd BP |
1036 | static const char * |
1037 | ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason) | |
1038 | { | |
1039 | static char s[32]; | |
1040 | ||
1041 | switch (reason) { | |
1042 | case OFPRR_IDLE_TIMEOUT: | |
1043 | return "idle"; | |
1044 | case OFPRR_HARD_TIMEOUT: | |
1045 | return "hard"; | |
1046 | case OFPRR_DELETE: | |
1047 | return "delete"; | |
04f68eb2 SH |
1048 | case OFPRR_GROUP_DELETE: |
1049 | return "group_delete"; | |
80d5aefd BP |
1050 | default: |
1051 | sprintf(s, "%d", (int) reason); | |
1052 | return s; | |
1053 | } | |
1054 | } | |
1055 | ||
064af421 | 1056 | static void |
9b045a0c | 1057 | ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh) |
064af421 | 1058 | { |
9b045a0c | 1059 | struct ofputil_flow_removed fr; |
90bf1e07 | 1060 | enum ofperr error; |
9b045a0c | 1061 | |
b78f6b77 | 1062 | error = ofputil_decode_flow_removed(&fr, oh); |
9b045a0c BP |
1063 | if (error) { |
1064 | ofp_print_error(string, error); | |
1065 | return; | |
1066 | } | |
1067 | ||
fbd76b2e | 1068 | ds_put_char(string, ' '); |
9b045a0c BP |
1069 | cls_rule_format(&fr.rule, string); |
1070 | ||
80d5aefd BP |
1071 | ds_put_format(string, " reason=%s", |
1072 | ofp_flow_removed_reason_to_string(fr.reason)); | |
3ff4f871 | 1073 | |
9b045a0c BP |
1074 | if (fr.cookie != htonll(0)) { |
1075 | ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie)); | |
3ff4f871 | 1076 | } |
09862ec6 | 1077 | ds_put_cstr(string, " duration"); |
9b045a0c | 1078 | ofp_print_duration(string, fr.duration_sec, fr.duration_nsec); |
09862ec6 | 1079 | ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n", |
9b045a0c | 1080 | fr.idle_timeout, fr.packet_count, fr.byte_count); |
064af421 BP |
1081 | } |
1082 | ||
1083 | static void | |
9e1fd49b | 1084 | ofp_print_port_mod(struct ds *string, const struct ofp_header *oh) |
064af421 | 1085 | { |
9e1fd49b BP |
1086 | struct ofputil_port_mod pm; |
1087 | enum ofperr error; | |
1088 | ||
1089 | error = ofputil_decode_port_mod(oh, &pm); | |
1090 | if (error) { | |
1091 | ofp_print_error(string, error); | |
1092 | return; | |
1093 | } | |
1094 | ||
1095 | ds_put_format(string, "port: %"PRIu16": addr:"ETH_ADDR_FMT"\n", | |
1096 | pm.port_no, ETH_ADDR_ARGS(pm.hw_addr)); | |
1097 | ||
1098 | ds_put_format(string, " config: "); | |
1099 | ofp_print_port_config(string, pm.config); | |
1100 | ||
1101 | ds_put_format(string, " mask: "); | |
1102 | ofp_print_port_config(string, pm.mask); | |
1103 | ||
064af421 | 1104 | ds_put_format(string, " advertise: "); |
9e1fd49b BP |
1105 | if (pm.advertise) { |
1106 | ofp_print_port_features(string, pm.advertise); | |
064af421 BP |
1107 | } else { |
1108 | ds_put_format(string, "UNCHANGED\n"); | |
1109 | } | |
1110 | } | |
1111 | ||
7fa91113 | 1112 | static void |
90bf1e07 | 1113 | ofp_print_error(struct ds *string, enum ofperr error) |
7fa91113 | 1114 | { |
7fa91113 BP |
1115 | if (string->length) { |
1116 | ds_put_char(string, ' '); | |
1117 | } | |
90bf1e07 | 1118 | ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error)); |
f74be05a JP |
1119 | } |
1120 | ||
064af421 | 1121 | static void |
d1e2cf21 | 1122 | ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem) |
064af421 | 1123 | { |
d1e2cf21 | 1124 | size_t len = ntohs(oem->header.length); |
dc4762ed BP |
1125 | size_t payload_ofs, payload_len; |
1126 | const void *payload; | |
90bf1e07 | 1127 | enum ofperr error; |
064af421 BP |
1128 | char *s; |
1129 | ||
90bf1e07 BP |
1130 | error = ofperr_decode_msg(&oem->header, &payload_ofs); |
1131 | if (!error) { | |
1132 | ds_put_cstr(string, "***decode error***"); | |
dc4762ed BP |
1133 | ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true); |
1134 | return; | |
f74be05a JP |
1135 | } |
1136 | ||
90bf1e07 | 1137 | ds_put_format(string, " %s\n", ofperr_get_name(error)); |
064af421 | 1138 | |
dc4762ed BP |
1139 | payload = (const uint8_t *) oem + payload_ofs; |
1140 | payload_len = len - payload_ofs; | |
90bf1e07 | 1141 | if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) { |
dc4762ed | 1142 | ds_put_printable(string, payload, payload_len); |
90bf1e07 | 1143 | } else { |
dc4762ed | 1144 | s = ofp_to_string(payload, payload_len, 1); |
064af421 BP |
1145 | ds_put_cstr(string, s); |
1146 | free(s); | |
064af421 BP |
1147 | } |
1148 | } | |
1149 | ||
064af421 | 1150 | static void |
d1e2cf21 | 1151 | ofp_print_port_status(struct ds *string, const struct ofp_port_status *ops) |
064af421 | 1152 | { |
9e1fd49b BP |
1153 | struct ofputil_port_status ps; |
1154 | enum ofperr error; | |
1155 | ||
1156 | error = ofputil_decode_port_status(ops, &ps); | |
1157 | if (error) { | |
1158 | ofp_print_error(string, error); | |
1159 | return; | |
1160 | } | |
1161 | ||
1162 | if (ps.reason == OFPPR_ADD) { | |
064af421 | 1163 | ds_put_format(string, " ADD:"); |
9e1fd49b | 1164 | } else if (ps.reason == OFPPR_DELETE) { |
064af421 | 1165 | ds_put_format(string, " DEL:"); |
9e1fd49b | 1166 | } else if (ps.reason == OFPPR_MODIFY) { |
064af421 BP |
1167 | ds_put_format(string, " MOD:"); |
1168 | } | |
1169 | ||
9e1fd49b | 1170 | ofp_print_phy_port(string, &ps.desc); |
064af421 BP |
1171 | } |
1172 | ||
1173 | static void | |
63f2140a | 1174 | ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_desc_stats *ods) |
064af421 | 1175 | { |
fbd76b2e | 1176 | ds_put_char(string, '\n'); |
d295e8e9 | 1177 | ds_put_format(string, "Manufacturer: %.*s\n", |
dd70b475 JP |
1178 | (int) sizeof ods->mfr_desc, ods->mfr_desc); |
1179 | ds_put_format(string, "Hardware: %.*s\n", | |
1180 | (int) sizeof ods->hw_desc, ods->hw_desc); | |
1181 | ds_put_format(string, "Software: %.*s\n", | |
1182 | (int) sizeof ods->sw_desc, ods->sw_desc); | |
1183 | ds_put_format(string, "Serial Num: %.*s\n", | |
1184 | (int) sizeof ods->serial_num, ods->serial_num); | |
1185 | ds_put_format(string, "DP Description: %.*s\n", | |
1186 | (int) sizeof ods->dp_desc, ods->dp_desc); | |
064af421 BP |
1187 | } |
1188 | ||
1189 | static void | |
76c93b22 BP |
1190 | ofp_print_flow_stats_request(struct ds *string, |
1191 | const struct ofp_stats_msg *osm) | |
064af421 | 1192 | { |
81d1ea94 | 1193 | struct ofputil_flow_stats_request fsr; |
90bf1e07 | 1194 | enum ofperr error; |
064af421 | 1195 | |
76c93b22 | 1196 | error = ofputil_decode_flow_stats_request(&fsr, &osm->header); |
2af0c0ef BP |
1197 | if (error) { |
1198 | ofp_print_error(string, error); | |
1199 | return; | |
1200 | } | |
1201 | ||
1202 | if (fsr.table_id != 0xff) { | |
e896c2d4 | 1203 | ds_put_format(string, " table=%"PRIu8, fsr.table_id); |
064af421 BP |
1204 | } |
1205 | ||
2af0c0ef BP |
1206 | if (fsr.out_port != OFPP_NONE) { |
1207 | ds_put_cstr(string, " out_port="); | |
39dc9082 | 1208 | ofputil_format_port(fsr.out_port, string); |
2af0c0ef BP |
1209 | } |
1210 | ||
54ae6fa8 BP |
1211 | /* A flow stats request doesn't include a priority, but cls_rule_format() |
1212 | * will print one unless it is OFP_DEFAULT_PRIORITY. */ | |
1213 | fsr.match.priority = OFP_DEFAULT_PRIORITY; | |
1214 | ||
2af0c0ef BP |
1215 | ds_put_char(string, ' '); |
1216 | cls_rule_format(&fsr.match, string); | |
064af421 BP |
1217 | } |
1218 | ||
1219 | static void | |
4ffd1b43 | 1220 | ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1221 | { |
4ffd1b43 | 1222 | struct ofpbuf b; |
064af421 | 1223 | |
4ffd1b43 BP |
1224 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
1225 | for (;;) { | |
1226 | struct ofputil_flow_stats fs; | |
1227 | int retval; | |
fab8fadb | 1228 | |
f27f2134 | 1229 | retval = ofputil_decode_flow_stats_reply(&fs, &b, true); |
4ffd1b43 BP |
1230 | if (retval) { |
1231 | if (retval != EOF) { | |
1232 | ds_put_cstr(string, " ***parse error***"); | |
064af421 BP |
1233 | } |
1234 | break; | |
1235 | } | |
1236 | ||
8961de6a BP |
1237 | ds_put_char(string, '\n'); |
1238 | ||
09862ec6 | 1239 | ds_put_format(string, " cookie=0x%"PRIx64", duration=", |
4ffd1b43 BP |
1240 | ntohll(fs.cookie)); |
1241 | ofp_print_duration(string, fs.duration_sec, fs.duration_nsec); | |
e896c2d4 | 1242 | ds_put_format(string, ", table=%"PRIu8", ", fs.table_id); |
4ffd1b43 BP |
1243 | ds_put_format(string, "n_packets=%"PRIu64", ", fs.packet_count); |
1244 | ds_put_format(string, "n_bytes=%"PRIu64", ", fs.byte_count); | |
1245 | if (fs.idle_timeout != OFP_FLOW_PERMANENT) { | |
b9718b7b | 1246 | ds_put_format(string, "idle_timeout=%"PRIu16", ", fs.idle_timeout); |
c6430da5 | 1247 | } |
4ffd1b43 | 1248 | if (fs.hard_timeout != OFP_FLOW_PERMANENT) { |
b9718b7b | 1249 | ds_put_format(string, "hard_timeout=%"PRIu16", ", fs.hard_timeout); |
c6430da5 | 1250 | } |
f27f2134 | 1251 | if (fs.idle_age >= 0) { |
b9718b7b | 1252 | ds_put_format(string, "idle_age=%d, ", fs.idle_age); |
f27f2134 BP |
1253 | } |
1254 | if (fs.hard_age >= 0 && fs.hard_age != fs.duration_sec) { | |
b9718b7b | 1255 | ds_put_format(string, "hard_age=%d, ", fs.hard_age); |
f27f2134 | 1256 | } |
c6430da5 | 1257 | |
4ffd1b43 | 1258 | cls_rule_format(&fs.rule, string); |
05b8f1c2 BP |
1259 | if (string->string[string->length - 1] != ' ') { |
1260 | ds_put_char(string, ' '); | |
1261 | } | |
b4b8c781 | 1262 | ofp_print_actions(string, fs.actions, fs.n_actions); |
c6430da5 BP |
1263 | } |
1264 | } | |
1265 | ||
064af421 | 1266 | static void |
63f2140a BP |
1267 | ofp_print_ofpst_aggregate_reply(struct ds *string, |
1268 | const struct ofp_aggregate_stats_reply *asr) | |
064af421 | 1269 | { |
c4617b3c BP |
1270 | ds_put_format(string, " packet_count=%"PRIu64, |
1271 | ntohll(get_32aligned_be64(&asr->packet_count))); | |
1272 | ds_put_format(string, " byte_count=%"PRIu64, | |
1273 | ntohll(get_32aligned_be64(&asr->byte_count))); | |
064af421 BP |
1274 | ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count)); |
1275 | } | |
1276 | ||
a2ad9ecd BP |
1277 | static void |
1278 | ofp_print_nxst_aggregate_reply(struct ds *string, | |
1279 | const struct nx_aggregate_stats_reply *nasr) | |
1280 | { | |
675baf0c BP |
1281 | ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count)); |
1282 | ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count)); | |
1283 | ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count)); | |
a2ad9ecd BP |
1284 | } |
1285 | ||
d295e8e9 | 1286 | static void print_port_stat(struct ds *string, const char *leader, |
c4617b3c | 1287 | const ovs_32aligned_be64 *statp, int more) |
064af421 | 1288 | { |
c4617b3c BP |
1289 | uint64_t stat = ntohll(get_32aligned_be64(statp)); |
1290 | ||
064af421 | 1291 | ds_put_cstr(string, leader); |
c4617b3c | 1292 | if (stat != UINT64_MAX) { |
064af421 BP |
1293 | ds_put_format(string, "%"PRIu64, stat); |
1294 | } else { | |
1295 | ds_put_char(string, '?'); | |
1296 | } | |
1297 | if (more) { | |
1298 | ds_put_cstr(string, ", "); | |
1299 | } else { | |
1300 | ds_put_cstr(string, "\n"); | |
1301 | } | |
1302 | } | |
1303 | ||
abaad8cf | 1304 | static void |
63f2140a BP |
1305 | ofp_print_ofpst_port_request(struct ds *string, |
1306 | const struct ofp_port_stats_request *psr) | |
abaad8cf | 1307 | { |
fbd76b2e | 1308 | ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no)); |
abaad8cf JP |
1309 | } |
1310 | ||
064af421 | 1311 | static void |
d1e2cf21 BP |
1312 | ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh, |
1313 | int verbosity) | |
064af421 | 1314 | { |
d1e2cf21 BP |
1315 | const struct ofp_port_stats *ps = ofputil_stats_body(oh); |
1316 | size_t n = ofputil_stats_body_len(oh) / sizeof *ps; | |
064af421 BP |
1317 | ds_put_format(string, " %zu ports\n", n); |
1318 | if (verbosity < 1) { | |
1319 | return; | |
1320 | } | |
1321 | ||
1322 | for (; n--; ps++) { | |
1323 | ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no)); | |
1324 | ||
1325 | ds_put_cstr(string, "rx "); | |
c4617b3c BP |
1326 | print_port_stat(string, "pkts=", &ps->rx_packets, 1); |
1327 | print_port_stat(string, "bytes=", &ps->rx_bytes, 1); | |
1328 | print_port_stat(string, "drop=", &ps->rx_dropped, 1); | |
1329 | print_port_stat(string, "errs=", &ps->rx_errors, 1); | |
1330 | print_port_stat(string, "frame=", &ps->rx_frame_err, 1); | |
1331 | print_port_stat(string, "over=", &ps->rx_over_err, 1); | |
1332 | print_port_stat(string, "crc=", &ps->rx_crc_err, 0); | |
064af421 BP |
1333 | |
1334 | ds_put_cstr(string, " tx "); | |
c4617b3c BP |
1335 | print_port_stat(string, "pkts=", &ps->tx_packets, 1); |
1336 | print_port_stat(string, "bytes=", &ps->tx_bytes, 1); | |
1337 | print_port_stat(string, "drop=", &ps->tx_dropped, 1); | |
1338 | print_port_stat(string, "errs=", &ps->tx_errors, 1); | |
1339 | print_port_stat(string, "coll=", &ps->collisions, 0); | |
064af421 BP |
1340 | } |
1341 | } | |
1342 | ||
1343 | static void | |
d1e2cf21 BP |
1344 | ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh, |
1345 | int verbosity) | |
064af421 | 1346 | { |
d1e2cf21 BP |
1347 | const struct ofp_table_stats *ts = ofputil_stats_body(oh); |
1348 | size_t n = ofputil_stats_body_len(oh) / sizeof *ts; | |
064af421 BP |
1349 | ds_put_format(string, " %zu tables\n", n); |
1350 | if (verbosity < 1) { | |
1351 | return; | |
1352 | } | |
1353 | ||
1354 | for (; n--; ts++) { | |
1355 | char name[OFP_MAX_TABLE_NAME_LEN + 1]; | |
e868fb3d | 1356 | ovs_strlcpy(name, ts->name, sizeof name); |
064af421 BP |
1357 | |
1358 | ds_put_format(string, " %d: %-8s: ", ts->table_id, name); | |
1359 | ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards)); | |
1360 | ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries)); | |
1361 | ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count)); | |
1362 | ds_put_cstr(string, " "); | |
d295e8e9 | 1363 | ds_put_format(string, "lookup=%"PRIu64", ", |
c4617b3c | 1364 | ntohll(get_32aligned_be64(&ts->lookup_count))); |
064af421 | 1365 | ds_put_format(string, "matched=%"PRIu64"\n", |
c4617b3c | 1366 | ntohll(get_32aligned_be64(&ts->matched_count))); |
064af421 BP |
1367 | } |
1368 | } | |
1369 | ||
d2805da2 BP |
1370 | static void |
1371 | ofp_print_queue_name(struct ds *string, uint32_t queue_id) | |
1372 | { | |
1373 | if (queue_id == OFPQ_ALL) { | |
1374 | ds_put_cstr(string, "ALL"); | |
1375 | } else { | |
1376 | ds_put_format(string, "%"PRIu32, queue_id); | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | static void | |
63f2140a BP |
1381 | ofp_print_ofpst_queue_request(struct ds *string, |
1382 | const struct ofp_queue_stats_request *qsr) | |
d2805da2 | 1383 | { |
d2805da2 | 1384 | ds_put_cstr(string, "port="); |
39dc9082 | 1385 | ofputil_format_port(ntohs(qsr->port_no), string); |
d2805da2 BP |
1386 | |
1387 | ds_put_cstr(string, " queue="); | |
1388 | ofp_print_queue_name(string, ntohl(qsr->queue_id)); | |
1389 | } | |
1390 | ||
1391 | static void | |
d1e2cf21 BP |
1392 | ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh, |
1393 | int verbosity) | |
d2805da2 | 1394 | { |
d1e2cf21 BP |
1395 | const struct ofp_queue_stats *qs = ofputil_stats_body(oh); |
1396 | size_t n = ofputil_stats_body_len(oh) / sizeof *qs; | |
d2805da2 BP |
1397 | ds_put_format(string, " %zu queues\n", n); |
1398 | if (verbosity < 1) { | |
1399 | return; | |
1400 | } | |
1401 | ||
1402 | for (; n--; qs++) { | |
1403 | ds_put_cstr(string, " port "); | |
39dc9082 | 1404 | ofputil_format_port(ntohs(qs->port_no), string); |
d2805da2 BP |
1405 | ds_put_cstr(string, " queue "); |
1406 | ofp_print_queue_name(string, ntohl(qs->queue_id)); | |
1407 | ds_put_cstr(string, ": "); | |
1408 | ||
c4617b3c BP |
1409 | print_port_stat(string, "bytes=", &qs->tx_bytes, 1); |
1410 | print_port_stat(string, "pkts=", &qs->tx_packets, 1); | |
1411 | print_port_stat(string, "errors=", &qs->tx_errors, 0); | |
d2805da2 BP |
1412 | } |
1413 | } | |
1414 | ||
2be393ed JP |
1415 | static void |
1416 | ofp_print_ofpst_port_desc_reply(struct ds *string, | |
1417 | const struct ofp_header *oh) | |
1418 | { | |
1419 | struct ofpbuf b; | |
1420 | ||
1421 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1422 | ofpbuf_pull(&b, sizeof(struct ofp_stats_msg)); | |
1423 | ds_put_char(string, '\n'); | |
1424 | ofp_print_phy_ports(string, oh->version, &b); | |
1425 | } | |
1426 | ||
064af421 | 1427 | static void |
d1e2cf21 | 1428 | ofp_print_stats_request(struct ds *string, const struct ofp_header *oh) |
064af421 | 1429 | { |
28c8bad1 | 1430 | const struct ofp_stats_msg *srq = (const struct ofp_stats_msg *) oh; |
064af421 BP |
1431 | |
1432 | if (srq->flags) { | |
1433 | ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", | |
1434 | ntohs(srq->flags)); | |
1435 | } | |
064af421 BP |
1436 | } |
1437 | ||
1438 | static void | |
d1e2cf21 | 1439 | ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1440 | { |
28c8bad1 | 1441 | const struct ofp_stats_msg *srp = (const struct ofp_stats_msg *) oh; |
064af421 | 1442 | |
d1e2cf21 | 1443 | if (srp->flags) { |
064af421 | 1444 | uint16_t flags = ntohs(srp->flags); |
d1e2cf21 BP |
1445 | |
1446 | ds_put_cstr(string, " flags="); | |
064af421 BP |
1447 | if (flags & OFPSF_REPLY_MORE) { |
1448 | ds_put_cstr(string, "[more]"); | |
1449 | flags &= ~OFPSF_REPLY_MORE; | |
1450 | } | |
1451 | if (flags) { | |
d1e2cf21 BP |
1452 | ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]", |
1453 | flags); | |
064af421 BP |
1454 | } |
1455 | } | |
064af421 BP |
1456 | } |
1457 | ||
1458 | static void | |
d1e2cf21 | 1459 | ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity) |
064af421 | 1460 | { |
d1e2cf21 | 1461 | size_t len = ntohs(oh->length); |
064af421 | 1462 | |
d1e2cf21 | 1463 | ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh); |
064af421 | 1464 | if (verbosity > 1) { |
d1e2cf21 | 1465 | ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true); |
064af421 BP |
1466 | } |
1467 | } | |
1468 | ||
61fe3a7b BP |
1469 | static void |
1470 | ofp_print_nxt_role_message(struct ds *string, | |
1471 | const struct nx_role_request *nrr) | |
1472 | { | |
1473 | unsigned int role = ntohl(nrr->role); | |
1474 | ||
1475 | ds_put_cstr(string, " role="); | |
1476 | if (role == NX_ROLE_OTHER) { | |
1477 | ds_put_cstr(string, "other"); | |
1478 | } else if (role == NX_ROLE_MASTER) { | |
1479 | ds_put_cstr(string, "master"); | |
1480 | } else if (role == NX_ROLE_SLAVE) { | |
1481 | ds_put_cstr(string, "slave"); | |
1482 | } else { | |
1483 | ds_put_format(string, "%u", role); | |
1484 | } | |
1485 | } | |
1486 | ||
6c1491fb BP |
1487 | static void |
1488 | ofp_print_nxt_flow_mod_table_id(struct ds *string, | |
73dbf4ab | 1489 | const struct nx_flow_mod_table_id *nfmti) |
6c1491fb BP |
1490 | { |
1491 | ds_put_format(string, " %s", nfmti->set ? "enable" : "disable"); | |
1492 | } | |
1493 | ||
7fa91113 BP |
1494 | static void |
1495 | ofp_print_nxt_set_flow_format(struct ds *string, | |
73dbf4ab | 1496 | const struct nx_set_flow_format *nsff) |
7fa91113 BP |
1497 | { |
1498 | uint32_t format = ntohl(nsff->format); | |
1499 | ||
1500 | ds_put_cstr(string, " format="); | |
27527aa0 BP |
1501 | if (ofputil_nx_flow_format_is_valid(format)) { |
1502 | ds_put_cstr(string, ofputil_nx_flow_format_to_string(format)); | |
7fa91113 BP |
1503 | } else { |
1504 | ds_put_format(string, "%"PRIu32, format); | |
1505 | } | |
1506 | } | |
1507 | ||
54834960 EJ |
1508 | static void |
1509 | ofp_print_nxt_set_packet_in_format(struct ds *string, | |
73dbf4ab | 1510 | const struct nx_set_packet_in_format *nspf) |
54834960 EJ |
1511 | { |
1512 | uint32_t format = ntohl(nspf->format); | |
1513 | ||
1514 | ds_put_cstr(string, " format="); | |
1515 | if (ofputil_packet_in_format_is_valid(format)) { | |
1516 | ds_put_cstr(string, ofputil_packet_in_format_to_string(format)); | |
1517 | } else { | |
1518 | ds_put_format(string, "%"PRIu32, format); | |
1519 | } | |
1520 | } | |
1521 | ||
80d5aefd BP |
1522 | static const char * |
1523 | ofp_port_reason_to_string(enum ofp_port_reason reason) | |
1524 | { | |
1525 | static char s[32]; | |
1526 | ||
1527 | switch (reason) { | |
1528 | case OFPPR_ADD: | |
1529 | return "add"; | |
1530 | ||
1531 | case OFPPR_DELETE: | |
1532 | return "delete"; | |
1533 | ||
1534 | case OFPPR_MODIFY: | |
1535 | return "modify"; | |
1536 | ||
1537 | default: | |
1538 | sprintf(s, "%d", (int) reason); | |
1539 | return s; | |
1540 | } | |
1541 | } | |
1542 | ||
1543 | static void | |
1544 | ofp_print_nxt_set_async_config(struct ds *string, | |
1545 | const struct nx_async_config *nac) | |
1546 | { | |
1547 | int i; | |
1548 | ||
1549 | for (i = 0; i < 2; i++) { | |
1550 | int j; | |
1551 | ||
1552 | ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave"); | |
1553 | ||
1554 | ds_put_cstr(string, " PACKET_IN:"); | |
1555 | for (j = 0; j < 32; j++) { | |
1556 | if (nac->packet_in_mask[i] & htonl(1u << j)) { | |
1557 | ds_put_format(string, " %s", | |
7c1a76a4 | 1558 | ofputil_packet_in_reason_to_string(j)); |
80d5aefd BP |
1559 | } |
1560 | } | |
1561 | if (!nac->packet_in_mask[i]) { | |
1562 | ds_put_cstr(string, " (off)"); | |
1563 | } | |
1564 | ds_put_char(string, '\n'); | |
1565 | ||
1566 | ds_put_cstr(string, " PORT_STATUS:"); | |
1567 | for (j = 0; j < 32; j++) { | |
1568 | if (nac->port_status_mask[i] & htonl(1u << j)) { | |
1569 | ds_put_format(string, " %s", ofp_port_reason_to_string(j)); | |
1570 | } | |
1571 | } | |
1572 | if (!nac->port_status_mask[i]) { | |
1573 | ds_put_cstr(string, " (off)"); | |
1574 | } | |
1575 | ds_put_char(string, '\n'); | |
1576 | ||
1577 | ds_put_cstr(string, " FLOW_REMOVED:"); | |
1578 | for (j = 0; j < 32; j++) { | |
1579 | if (nac->flow_removed_mask[i] & htonl(1u << j)) { | |
1580 | ds_put_format(string, " %s", | |
1581 | ofp_flow_removed_reason_to_string(j)); | |
1582 | } | |
1583 | } | |
1584 | if (!nac->flow_removed_mask[i]) { | |
1585 | ds_put_cstr(string, " (off)"); | |
1586 | } | |
1587 | ds_put_char(string, '\n'); | |
1588 | } | |
1589 | } | |
1590 | ||
a7349929 BP |
1591 | static void |
1592 | ofp_print_nxt_set_controller_id(struct ds *string, | |
1593 | const struct nx_controller_id *nci) | |
1594 | { | |
1595 | ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id)); | |
1596 | } | |
1597 | ||
d1e2cf21 BP |
1598 | static void |
1599 | ofp_to_string__(const struct ofp_header *oh, | |
1600 | const struct ofputil_msg_type *type, struct ds *string, | |
1601 | int verbosity) | |
1602 | { | |
7fa91113 | 1603 | enum ofputil_msg_code code; |
d1e2cf21 BP |
1604 | const void *msg = oh; |
1605 | ||
3811e66b BP |
1606 | ds_put_cstr(string, ofputil_msg_type_name(type)); |
1607 | switch (oh->version) { | |
1608 | case OFP10_VERSION: | |
1609 | break; | |
1610 | case OFP11_VERSION: | |
1611 | ds_put_cstr(string, " (OF1.1)"); | |
1612 | break; | |
1613 | default: | |
1614 | ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version); | |
1615 | break; | |
1616 | } | |
1617 | ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid)); | |
d1e2cf21 | 1618 | |
7fa91113 BP |
1619 | code = ofputil_msg_type_code(type); |
1620 | switch (code) { | |
8f93e93c | 1621 | case OFPUTIL_MSG_INVALID: |
d1e2cf21 BP |
1622 | break; |
1623 | ||
1624 | case OFPUTIL_OFPT_HELLO: | |
dc4762ed BP |
1625 | ds_put_char(string, '\n'); |
1626 | ds_put_hex_dump(string, oh + 1, ntohs(oh->length) - sizeof *oh, | |
1627 | 0, true); | |
d1e2cf21 BP |
1628 | break; |
1629 | ||
1630 | case OFPUTIL_OFPT_ERROR: | |
1631 | ofp_print_error_msg(string, msg); | |
1632 | break; | |
1633 | ||
1634 | case OFPUTIL_OFPT_ECHO_REQUEST: | |
1635 | case OFPUTIL_OFPT_ECHO_REPLY: | |
1636 | ofp_print_echo(string, oh, verbosity); | |
1637 | break; | |
1638 | ||
1639 | case OFPUTIL_OFPT_FEATURES_REQUEST: | |
1640 | break; | |
1641 | ||
1642 | case OFPUTIL_OFPT_FEATURES_REPLY: | |
1643 | ofp_print_switch_features(string, msg); | |
1644 | break; | |
1645 | ||
1646 | case OFPUTIL_OFPT_GET_CONFIG_REQUEST: | |
1647 | break; | |
1648 | ||
1649 | case OFPUTIL_OFPT_GET_CONFIG_REPLY: | |
1650 | case OFPUTIL_OFPT_SET_CONFIG: | |
1651 | ofp_print_switch_config(string, msg); | |
1652 | break; | |
1653 | ||
1654 | case OFPUTIL_OFPT_PACKET_IN: | |
54834960 | 1655 | case OFPUTIL_NXT_PACKET_IN: |
d1e2cf21 BP |
1656 | ofp_print_packet_in(string, msg, verbosity); |
1657 | break; | |
1658 | ||
1659 | case OFPUTIL_OFPT_FLOW_REMOVED: | |
9b045a0c BP |
1660 | case OFPUTIL_NXT_FLOW_REMOVED: |
1661 | ofp_print_flow_removed(string, msg); | |
d1e2cf21 BP |
1662 | break; |
1663 | ||
1664 | case OFPUTIL_OFPT_PORT_STATUS: | |
1665 | ofp_print_port_status(string, msg); | |
1666 | break; | |
1667 | ||
1668 | case OFPUTIL_OFPT_PACKET_OUT: | |
1669 | ofp_print_packet_out(string, msg, verbosity); | |
1670 | break; | |
1671 | ||
1672 | case OFPUTIL_OFPT_FLOW_MOD: | |
3370cd3c | 1673 | case OFPUTIL_NXT_FLOW_MOD: |
7fa91113 | 1674 | ofp_print_flow_mod(string, msg, code, verbosity); |
d1e2cf21 BP |
1675 | break; |
1676 | ||
1677 | case OFPUTIL_OFPT_PORT_MOD: | |
1678 | ofp_print_port_mod(string, msg); | |
1679 | break; | |
1680 | ||
1681 | case OFPUTIL_OFPT_BARRIER_REQUEST: | |
1682 | case OFPUTIL_OFPT_BARRIER_REPLY: | |
1683 | break; | |
1684 | ||
1685 | case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REQUEST: | |
1686 | case OFPUTIL_OFPT_QUEUE_GET_CONFIG_REPLY: | |
1687 | /* XXX */ | |
1688 | break; | |
1689 | ||
1690 | case OFPUTIL_OFPST_DESC_REQUEST: | |
2be393ed | 1691 | case OFPUTIL_OFPST_PORT_DESC_REQUEST: |
d1e2cf21 BP |
1692 | ofp_print_stats_request(string, oh); |
1693 | break; | |
1694 | ||
1695 | case OFPUTIL_OFPST_FLOW_REQUEST: | |
2af0c0ef | 1696 | case OFPUTIL_NXST_FLOW_REQUEST: |
d1e2cf21 | 1697 | case OFPUTIL_OFPST_AGGREGATE_REQUEST: |
2af0c0ef | 1698 | case OFPUTIL_NXST_AGGREGATE_REQUEST: |
d1e2cf21 | 1699 | ofp_print_stats_request(string, oh); |
76c93b22 | 1700 | ofp_print_flow_stats_request(string, msg); |
d1e2cf21 BP |
1701 | break; |
1702 | ||
1703 | case OFPUTIL_OFPST_TABLE_REQUEST: | |
1704 | ofp_print_stats_request(string, oh); | |
1705 | break; | |
1706 | ||
1707 | case OFPUTIL_OFPST_PORT_REQUEST: | |
1708 | ofp_print_stats_request(string, oh); | |
63f2140a | 1709 | ofp_print_ofpst_port_request(string, msg); |
d1e2cf21 BP |
1710 | break; |
1711 | ||
1712 | case OFPUTIL_OFPST_QUEUE_REQUEST: | |
1713 | ofp_print_stats_request(string, oh); | |
63f2140a | 1714 | ofp_print_ofpst_queue_request(string, msg); |
d1e2cf21 BP |
1715 | break; |
1716 | ||
1717 | case OFPUTIL_OFPST_DESC_REPLY: | |
1718 | ofp_print_stats_reply(string, oh); | |
63f2140a | 1719 | ofp_print_ofpst_desc_reply(string, msg); |
d1e2cf21 BP |
1720 | break; |
1721 | ||
1722 | case OFPUTIL_OFPST_FLOW_REPLY: | |
4ffd1b43 | 1723 | case OFPUTIL_NXST_FLOW_REPLY: |
d1e2cf21 | 1724 | ofp_print_stats_reply(string, oh); |
4ffd1b43 | 1725 | ofp_print_flow_stats_reply(string, oh); |
d1e2cf21 BP |
1726 | break; |
1727 | ||
1728 | case OFPUTIL_OFPST_QUEUE_REPLY: | |
1729 | ofp_print_stats_reply(string, oh); | |
1730 | ofp_print_ofpst_queue_reply(string, oh, verbosity); | |
1731 | break; | |
1732 | ||
1733 | case OFPUTIL_OFPST_PORT_REPLY: | |
1734 | ofp_print_stats_reply(string, oh); | |
1735 | ofp_print_ofpst_port_reply(string, oh, verbosity); | |
1736 | break; | |
1737 | ||
1738 | case OFPUTIL_OFPST_TABLE_REPLY: | |
1739 | ofp_print_stats_reply(string, oh); | |
1740 | ofp_print_ofpst_table_reply(string, oh, verbosity); | |
1741 | break; | |
1742 | ||
1743 | case OFPUTIL_OFPST_AGGREGATE_REPLY: | |
1744 | ofp_print_stats_reply(string, oh); | |
63f2140a | 1745 | ofp_print_ofpst_aggregate_reply(string, msg); |
d1e2cf21 | 1746 | break; |
064af421 | 1747 | |
2be393ed JP |
1748 | case OFPUTIL_OFPST_PORT_DESC_REPLY: |
1749 | ofp_print_stats_reply(string, oh); | |
1750 | ofp_print_ofpst_port_desc_reply(string, oh); | |
1751 | break; | |
1752 | ||
d1e2cf21 BP |
1753 | case OFPUTIL_NXT_ROLE_REQUEST: |
1754 | case OFPUTIL_NXT_ROLE_REPLY: | |
61fe3a7b | 1755 | ofp_print_nxt_role_message(string, msg); |
7fa91113 BP |
1756 | break; |
1757 | ||
6c1491fb BP |
1758 | case OFPUTIL_NXT_FLOW_MOD_TABLE_ID: |
1759 | ofp_print_nxt_flow_mod_table_id(string, msg); | |
1760 | break; | |
1761 | ||
d1e2cf21 | 1762 | case OFPUTIL_NXT_SET_FLOW_FORMAT: |
7fa91113 BP |
1763 | ofp_print_nxt_set_flow_format(string, msg); |
1764 | break; | |
1765 | ||
54834960 EJ |
1766 | case OFPUTIL_NXT_SET_PACKET_IN_FORMAT: |
1767 | ofp_print_nxt_set_packet_in_format(string, msg); | |
1768 | break; | |
1769 | ||
f27f2134 BP |
1770 | case OFPUTIL_NXT_FLOW_AGE: |
1771 | break; | |
1772 | ||
a7349929 BP |
1773 | case OFPUTIL_NXT_SET_CONTROLLER_ID: |
1774 | ofp_print_nxt_set_controller_id(string, msg); | |
1775 | break; | |
1776 | ||
80d5aefd BP |
1777 | case OFPUTIL_NXT_SET_ASYNC_CONFIG: |
1778 | ofp_print_nxt_set_async_config(string, msg); | |
1779 | break; | |
1780 | ||
d1e2cf21 | 1781 | case OFPUTIL_NXST_AGGREGATE_REPLY: |
a2ad9ecd | 1782 | ofp_print_stats_reply(string, oh); |
9b045a0c | 1783 | ofp_print_nxst_aggregate_reply(string, msg); |
d1e2cf21 | 1784 | break; |
246e61ea | 1785 | } |
d1e2cf21 | 1786 | } |
064af421 BP |
1787 | |
1788 | /* Composes and returns a string representing the OpenFlow packet of 'len' | |
1789 | * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of | |
1790 | * verbosity and higher numbers increase verbosity. The caller is responsible | |
1791 | * for freeing the string. */ | |
1792 | char * | |
1793 | ofp_to_string(const void *oh_, size_t len, int verbosity) | |
1794 | { | |
1795 | struct ds string = DS_EMPTY_INITIALIZER; | |
1796 | const struct ofp_header *oh = oh_; | |
064af421 | 1797 | |
49ad0403 BP |
1798 | if (!len) { |
1799 | ds_put_cstr(&string, "OpenFlow message is empty\n"); | |
1800 | } else if (len < sizeof(struct ofp_header)) { | |
1801 | ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n", | |
1802 | len); | |
d1e2cf21 BP |
1803 | } else if (ntohs(oh->length) > len) { |
1804 | ds_put_format(&string, | |
49ad0403 | 1805 | "(***truncated to %zu bytes from %"PRIu16"***)\n", |
d1e2cf21 BP |
1806 | len, ntohs(oh->length)); |
1807 | } else if (ntohs(oh->length) < len) { | |
1808 | ds_put_format(&string, | |
1809 | "(***only uses %"PRIu16" bytes out of %zu***)\n", | |
1810 | ntohs(oh->length), len); | |
1811 | } else { | |
1812 | const struct ofputil_msg_type *type; | |
90bf1e07 | 1813 | enum ofperr error; |
d1e2cf21 BP |
1814 | |
1815 | error = ofputil_decode_msg_type(oh, &type); | |
1816 | if (!error) { | |
1817 | ofp_to_string__(oh, type, &string, verbosity); | |
7fa91113 BP |
1818 | if (verbosity >= 5) { |
1819 | if (ds_last(&string) != '\n') { | |
1820 | ds_put_char(&string, '\n'); | |
1821 | } | |
d1e2cf21 BP |
1822 | ds_put_hex_dump(&string, oh, len, 0, true); |
1823 | } | |
7fa91113 | 1824 | if (ds_last(&string) != '\n') { |
d1e2cf21 BP |
1825 | ds_put_char(&string, '\n'); |
1826 | } | |
1827 | return ds_steal_cstr(&string); | |
064af421 | 1828 | } |
064af421 | 1829 | |
7fa91113 | 1830 | ofp_print_error(&string, error); |
064af421 | 1831 | } |
d1e2cf21 BP |
1832 | ds_put_hex_dump(&string, oh, len, 0, true); |
1833 | return ds_steal_cstr(&string); | |
064af421 | 1834 | } |
064af421 BP |
1835 | \f |
1836 | static void | |
d295e8e9 | 1837 | print_and_free(FILE *stream, char *string) |
064af421 BP |
1838 | { |
1839 | fputs(string, stream); | |
1840 | free(string); | |
1841 | } | |
1842 | ||
1843 | /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the | |
1844 | * given 'verbosity' level. 0 is a minimal amount of verbosity and higher | |
1845 | * numbers increase verbosity. */ | |
1846 | void | |
1847 | ofp_print(FILE *stream, const void *oh, size_t len, int verbosity) | |
1848 | { | |
1849 | print_and_free(stream, ofp_to_string(oh, len, verbosity)); | |
1850 | } | |
1851 | ||
1852 | /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at | |
897a8e07 | 1853 | * 'data' to 'stream'. */ |
064af421 | 1854 | void |
c499c75d | 1855 | ofp_print_packet(FILE *stream, const void *data, size_t len) |
064af421 | 1856 | { |
c499c75d | 1857 | print_and_free(stream, ofp_packet_to_string(data, len)); |
064af421 | 1858 | } |