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