]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
f4f1ea7e | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. |
064af421 | 3 | * |
a14bc59f BP |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
064af421 | 7 | * |
a14bc59f BP |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
064af421 BP |
15 | */ |
16 | ||
17 | #include <config.h> | |
18 | #include "ofp-print.h" | |
064af421 BP |
19 | |
20 | #include <errno.h> | |
21 | #include <inttypes.h> | |
7f3adc00 | 22 | #include <sys/types.h> |
064af421 BP |
23 | #include <netinet/in.h> |
24 | #include <sys/wait.h> | |
25 | #include <stdarg.h> | |
26 | #include <stdlib.h> | |
27 | #include <ctype.h> | |
28 | ||
daff3353 | 29 | #include "bundle.h" |
10a24935 | 30 | #include "byte-order.h" |
064af421 BP |
31 | #include "compiler.h" |
32 | #include "dynamic-string.h" | |
33 | #include "flow.h" | |
75a75043 | 34 | #include "learn.h" |
53ddd40a | 35 | #include "multipath.h" |
816fd533 | 36 | #include "meta-flow.h" |
9e1fd49b | 37 | #include "netdev.h" |
7fa91113 | 38 | #include "nx-match.h" |
f25d0cf3 | 39 | #include "ofp-actions.h" |
90bf1e07 | 40 | #include "ofp-errors.h" |
982697a4 | 41 | #include "ofp-msgs.h" |
69b6be19 | 42 | #include "ofp-util.h" |
064af421 BP |
43 | #include "ofpbuf.h" |
44 | #include "openflow/openflow.h" | |
45 | #include "openflow/nicira-ext.h" | |
46 | #include "packets.h" | |
e41a9130 | 47 | #include "type-props.h" |
c4617b3c | 48 | #include "unaligned.h" |
064af421 BP |
49 | #include "util.h" |
50 | ||
d2805da2 | 51 | static void ofp_print_queue_name(struct ds *string, uint32_t port); |
90bf1e07 | 52 | static void ofp_print_error(struct ds *, enum ofperr); |
7fa91113 | 53 | |
064af421 BP |
54 | |
55 | /* Returns a string that represents the contents of the Ethernet frame in the | |
897a8e07 | 56 | * 'len' bytes starting at 'data'. The caller must free the returned string.*/ |
064af421 | 57 | char * |
c499c75d | 58 | ofp_packet_to_string(const void *data, size_t len) |
064af421 BP |
59 | { |
60 | struct ds ds = DS_EMPTY_INITIALIZER; | |
61 | struct ofpbuf buf; | |
897a8e07 | 62 | struct flow flow; |
064af421 | 63 | |
0bc9407d | 64 | ofpbuf_use_const(&buf, data, len); |
4e022ec0 | 65 | flow_extract(&buf, 0, 0, NULL, NULL, &flow); |
897a8e07 | 66 | flow_format(&ds, &flow); |
e50abca5 EJ |
67 | |
68 | if (buf.l7) { | |
69 | if (flow.nw_proto == IPPROTO_TCP) { | |
70 | struct tcp_header *th = buf.l4; | |
71 | ds_put_format(&ds, " tcp_csum:%"PRIx16, | |
72 | ntohs(th->tcp_csum)); | |
73 | } else if (flow.nw_proto == IPPROTO_UDP) { | |
74 | struct udp_header *uh = buf.l4; | |
75 | ds_put_format(&ds, " udp_csum:%"PRIx16, | |
76 | ntohs(uh->udp_csum)); | |
0d56eaf2 JS |
77 | } else if (flow.nw_proto == IPPROTO_SCTP) { |
78 | struct sctp_header *sh = buf.l4; | |
79 | ds_put_format(&ds, " sctp_csum:%"PRIx32, | |
80 | ntohl(sh->sctp_csum)); | |
e50abca5 EJ |
81 | } |
82 | } | |
83 | ||
897a8e07 | 84 | ds_put_char(&ds, '\n'); |
064af421 | 85 | |
064af421 BP |
86 | return ds_cstr(&ds); |
87 | } | |
88 | ||
064af421 | 89 | static void |
65120a8a | 90 | ofp_print_packet_in(struct ds *string, const struct ofp_header *oh, |
d1e2cf21 | 91 | int verbosity) |
064af421 | 92 | { |
5014a89d | 93 | char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE]; |
65120a8a EJ |
94 | struct ofputil_packet_in pin; |
95 | int error; | |
5d6c3af0 | 96 | int i; |
064af421 | 97 | |
65120a8a EJ |
98 | error = ofputil_decode_packet_in(&pin, oh); |
99 | if (error) { | |
100 | ofp_print_error(string, error); | |
101 | return; | |
102 | } | |
103 | ||
54834960 EJ |
104 | if (pin.table_id) { |
105 | ds_put_format(string, " table_id=%"PRIu8, pin.table_id); | |
106 | } | |
107 | ||
d4fa4e79 | 108 | if (pin.cookie != OVS_BE64_MAX) { |
54834960 EJ |
109 | ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie)); |
110 | } | |
111 | ||
34582733 | 112 | ds_put_format(string, " total_len=%"PRIuSIZE" in_port=", pin.total_len); |
5d6c3af0 EJ |
113 | ofputil_format_port(pin.fmd.in_port, string); |
114 | ||
42edbe39 | 115 | if (pin.fmd.tun_id != htonll(0)) { |
5d6c3af0 | 116 | ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id)); |
5d6c3af0 EJ |
117 | } |
118 | ||
0ad90c84 JR |
119 | if (pin.fmd.tun_src != htonl(0)) { |
120 | ds_put_format(string, " tun_src="IP_FMT, IP_ARGS(pin.fmd.tun_src)); | |
121 | } | |
122 | ||
123 | if (pin.fmd.tun_dst != htonl(0)) { | |
124 | ds_put_format(string, " tun_dst="IP_FMT, IP_ARGS(pin.fmd.tun_dst)); | |
125 | } | |
126 | ||
42edbe39 | 127 | if (pin.fmd.metadata != htonll(0)) { |
969fc56c | 128 | ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata)); |
969fc56c JS |
129 | } |
130 | ||
5d6c3af0 | 131 | for (i = 0; i < FLOW_N_REGS; i++) { |
42edbe39 | 132 | if (pin.fmd.regs[i]) { |
5d6c3af0 | 133 | ds_put_format(string, " reg%d=0x%"PRIx32, i, pin.fmd.regs[i]); |
5d6c3af0 EJ |
134 | } |
135 | } | |
064af421 | 136 | |
ac923e91 JG |
137 | if (pin.fmd.pkt_mark != 0) { |
138 | ds_put_format(string, " pkt_mark=0x%"PRIx32, pin.fmd.pkt_mark); | |
139 | } | |
140 | ||
80d5aefd | 141 | ds_put_format(string, " (via %s)", |
5014a89d BP |
142 | ofputil_packet_in_reason_to_string(pin.reason, reasonbuf, |
143 | sizeof reasonbuf)); | |
064af421 | 144 | |
34582733 | 145 | ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len); |
65120a8a | 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 | } | |
b4ccee75 SH |
164 | if (verbosity > 2) { |
165 | ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false); | |
166 | } | |
064af421 BP |
167 | } |
168 | ||
d1e2cf21 | 169 | static void |
982697a4 | 170 | ofp_print_packet_out(struct ds *string, const struct ofp_header *oh, |
d1e2cf21 | 171 | int verbosity) |
064af421 | 172 | { |
c6a93eb7 | 173 | struct ofputil_packet_out po; |
f25d0cf3 | 174 | struct ofpbuf ofpacts; |
c6a93eb7 | 175 | enum ofperr error; |
064af421 | 176 | |
f25d0cf3 | 177 | ofpbuf_init(&ofpacts, 64); |
982697a4 | 178 | error = ofputil_decode_packet_out(&po, oh, &ofpacts); |
c6a93eb7 | 179 | if (error) { |
f25d0cf3 | 180 | ofpbuf_uninit(&ofpacts); |
c6a93eb7 | 181 | ofp_print_error(string, error); |
064af421 BP |
182 | return; |
183 | } | |
c6a93eb7 BP |
184 | |
185 | ds_put_cstr(string, " in_port="); | |
186 | ofputil_format_port(po.in_port, string); | |
187 | ||
455ecd77 | 188 | ds_put_cstr(string, " actions="); |
f25d0cf3 | 189 | ofpacts_format(po.ofpacts, po.ofpacts_len, string); |
c6a93eb7 BP |
190 | |
191 | if (po.buffer_id == UINT32_MAX) { | |
34582733 | 192 | ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len); |
c6a93eb7 BP |
193 | if (verbosity > 0 && po.packet_len > 0) { |
194 | char *packet = ofp_packet_to_string(po.packet, po.packet_len); | |
064af421 BP |
195 | ds_put_char(string, '\n'); |
196 | ds_put_cstr(string, packet); | |
197 | free(packet); | |
198 | } | |
b4ccee75 SH |
199 | if (verbosity > 2) { |
200 | ds_put_hex_dump(string, po.packet, po.packet_len, 0, false); | |
201 | } | |
064af421 | 202 | } else { |
c6a93eb7 | 203 | ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id); |
064af421 | 204 | } |
f25d0cf3 BP |
205 | |
206 | ofpbuf_uninit(&ofpacts); | |
064af421 BP |
207 | } |
208 | ||
209 | /* qsort comparison function. */ | |
210 | static int | |
211 | compare_ports(const void *a_, const void *b_) | |
212 | { | |
9e1fd49b BP |
213 | const struct ofputil_phy_port *a = a_; |
214 | const struct ofputil_phy_port *b = b_; | |
4e022ec0 AW |
215 | uint16_t ap = ofp_to_u16(a->port_no); |
216 | uint16_t bp = ofp_to_u16(b->port_no); | |
064af421 BP |
217 | |
218 | return ap < bp ? -1 : ap > bp; | |
219 | } | |
220 | ||
0ab14c8e BP |
221 | static void |
222 | ofp_print_bit_names(struct ds *string, uint32_t bits, | |
e8fa940e BP |
223 | const char *(*bit_to_name)(uint32_t bit), |
224 | char separator) | |
064af421 | 225 | { |
0ab14c8e | 226 | int n = 0; |
9e1fd49b | 227 | int i; |
0ab14c8e BP |
228 | |
229 | if (!bits) { | |
230 | ds_put_cstr(string, "0"); | |
064af421 BP |
231 | return; |
232 | } | |
0ab14c8e | 233 | |
9e1fd49b BP |
234 | for (i = 0; i < 32; i++) { |
235 | uint32_t bit = UINT32_C(1) << i; | |
236 | ||
237 | if (bits & bit) { | |
238 | const char *name = bit_to_name(bit); | |
239 | if (name) { | |
240 | if (n++) { | |
e8fa940e | 241 | ds_put_char(string, separator); |
9e1fd49b BP |
242 | } |
243 | ds_put_cstr(string, name); | |
244 | bits &= ~bit; | |
0ab14c8e | 245 | } |
0ab14c8e | 246 | } |
064af421 | 247 | } |
0ab14c8e BP |
248 | |
249 | if (bits) { | |
f5cd6874 | 250 | if (n) { |
e8fa940e | 251 | ds_put_char(string, separator); |
0ab14c8e BP |
252 | } |
253 | ds_put_format(string, "0x%"PRIx32, bits); | |
064af421 | 254 | } |
0ab14c8e BP |
255 | } |
256 | ||
9e1fd49b BP |
257 | static const char * |
258 | netdev_feature_to_name(uint32_t bit) | |
259 | { | |
260 | enum netdev_features f = bit; | |
261 | ||
262 | switch (f) { | |
263 | case NETDEV_F_10MB_HD: return "10MB-HD"; | |
264 | case NETDEV_F_10MB_FD: return "10MB-FD"; | |
265 | case NETDEV_F_100MB_HD: return "100MB-HD"; | |
266 | case NETDEV_F_100MB_FD: return "100MB-FD"; | |
267 | case NETDEV_F_1GB_HD: return "1GB-HD"; | |
268 | case NETDEV_F_1GB_FD: return "1GB-FD"; | |
269 | case NETDEV_F_10GB_FD: return "10GB-FD"; | |
270 | case NETDEV_F_40GB_FD: return "40GB-FD"; | |
271 | case NETDEV_F_100GB_FD: return "100GB-FD"; | |
272 | case NETDEV_F_1TB_FD: return "1TB-FD"; | |
273 | case NETDEV_F_OTHER: return "OTHER"; | |
274 | case NETDEV_F_COPPER: return "COPPER"; | |
275 | case NETDEV_F_FIBER: return "FIBER"; | |
276 | case NETDEV_F_AUTONEG: return "AUTO_NEG"; | |
277 | case NETDEV_F_PAUSE: return "AUTO_PAUSE"; | |
278 | case NETDEV_F_PAUSE_ASYM: return "AUTO_PAUSE_ASYM"; | |
279 | } | |
280 | ||
281 | return NULL; | |
282 | } | |
283 | ||
0ab14c8e | 284 | static void |
9e1fd49b | 285 | ofp_print_port_features(struct ds *string, enum netdev_features features) |
0ab14c8e | 286 | { |
e8fa940e | 287 | ofp_print_bit_names(string, features, netdev_feature_to_name, ' '); |
0ab14c8e BP |
288 | ds_put_char(string, '\n'); |
289 | } | |
290 | ||
9e1fd49b BP |
291 | static const char * |
292 | ofputil_port_config_to_name(uint32_t bit) | |
293 | { | |
294 | enum ofputil_port_config pc = bit; | |
295 | ||
296 | switch (pc) { | |
297 | case OFPUTIL_PC_PORT_DOWN: return "PORT_DOWN"; | |
298 | case OFPUTIL_PC_NO_STP: return "NO_STP"; | |
299 | case OFPUTIL_PC_NO_RECV: return "NO_RECV"; | |
300 | case OFPUTIL_PC_NO_RECV_STP: return "NO_RECV_STP"; | |
301 | case OFPUTIL_PC_NO_FLOOD: return "NO_FLOOD"; | |
302 | case OFPUTIL_PC_NO_FWD: return "NO_FWD"; | |
303 | case OFPUTIL_PC_NO_PACKET_IN: return "NO_PACKET_IN"; | |
304 | } | |
305 | ||
306 | return NULL; | |
307 | } | |
308 | ||
0ab14c8e | 309 | static void |
9e1fd49b | 310 | ofp_print_port_config(struct ds *string, enum ofputil_port_config config) |
0ab14c8e | 311 | { |
e8fa940e | 312 | ofp_print_bit_names(string, config, ofputil_port_config_to_name, ' '); |
0ab14c8e BP |
313 | ds_put_char(string, '\n'); |
314 | } | |
315 | ||
9e1fd49b BP |
316 | static const char * |
317 | ofputil_port_state_to_name(uint32_t bit) | |
318 | { | |
319 | enum ofputil_port_state ps = bit; | |
320 | ||
321 | switch (ps) { | |
322 | case OFPUTIL_PS_LINK_DOWN: return "LINK_DOWN"; | |
323 | case OFPUTIL_PS_BLOCKED: return "BLOCKED"; | |
324 | case OFPUTIL_PS_LIVE: return "LIVE"; | |
325 | ||
326 | case OFPUTIL_PS_STP_LISTEN: | |
327 | case OFPUTIL_PS_STP_LEARN: | |
328 | case OFPUTIL_PS_STP_FORWARD: | |
329 | case OFPUTIL_PS_STP_BLOCK: | |
330 | /* Handled elsewhere. */ | |
331 | return NULL; | |
332 | } | |
333 | ||
334 | return NULL; | |
335 | } | |
336 | ||
0ab14c8e | 337 | static void |
9e1fd49b | 338 | ofp_print_port_state(struct ds *string, enum ofputil_port_state state) |
0ab14c8e | 339 | { |
9e1fd49b | 340 | enum ofputil_port_state stp_state; |
0ab14c8e BP |
341 | |
342 | /* The STP state is a 2-bit field so it doesn't fit in with the bitmask | |
343 | * pattern. We have to special case it. | |
344 | * | |
345 | * OVS doesn't support STP, so this field will always be 0 if we are | |
346 | * talking to OVS, so we'd always print STP_LISTEN in that case. | |
347 | * Therefore, we don't print anything at all if the value is STP_LISTEN, to | |
348 | * avoid confusing users. */ | |
9e1fd49b | 349 | stp_state = state & OFPUTIL_PS_STP_MASK; |
0ab14c8e | 350 | if (stp_state) { |
9e1fd49b BP |
351 | ds_put_cstr(string, |
352 | (stp_state == OFPUTIL_PS_STP_LEARN ? "STP_LEARN" | |
353 | : stp_state == OFPUTIL_PS_STP_FORWARD ? "STP_FORWARD" | |
354 | : "STP_BLOCK")); | |
355 | state &= ~OFPUTIL_PS_STP_MASK; | |
0ab14c8e | 356 | if (state) { |
e8fa940e BP |
357 | ofp_print_bit_names(string, state, ofputil_port_state_to_name, |
358 | ' '); | |
0ab14c8e BP |
359 | } |
360 | } else { | |
e8fa940e | 361 | ofp_print_bit_names(string, state, ofputil_port_state_to_name, ' '); |
064af421 BP |
362 | } |
363 | ds_put_char(string, '\n'); | |
364 | } | |
365 | ||
366 | static void | |
9e1fd49b | 367 | ofp_print_phy_port(struct ds *string, const struct ofputil_phy_port *port) |
064af421 | 368 | { |
9e1fd49b | 369 | char name[sizeof port->name]; |
064af421 BP |
370 | int j; |
371 | ||
372 | memcpy(name, port->name, sizeof name); | |
373 | for (j = 0; j < sizeof name - 1; j++) { | |
858f2852 | 374 | if (!isprint((unsigned char) name[j])) { |
064af421 BP |
375 | break; |
376 | } | |
377 | } | |
378 | name[j] = '\0'; | |
379 | ||
380 | ds_put_char(string, ' '); | |
9e1fd49b | 381 | ofputil_format_port(port->port_no, string); |
0ab14c8e BP |
382 | ds_put_format(string, "(%s): addr:"ETH_ADDR_FMT"\n", |
383 | name, ETH_ADDR_ARGS(port->hw_addr)); | |
384 | ||
385 | ds_put_cstr(string, " config: "); | |
9e1fd49b | 386 | ofp_print_port_config(string, port->config); |
0ab14c8e BP |
387 | |
388 | ds_put_cstr(string, " state: "); | |
9e1fd49b | 389 | ofp_print_port_state(string, port->state); |
0ab14c8e | 390 | |
064af421 BP |
391 | if (port->curr) { |
392 | ds_put_format(string, " current: "); | |
9e1fd49b | 393 | ofp_print_port_features(string, port->curr); |
064af421 BP |
394 | } |
395 | if (port->advertised) { | |
396 | ds_put_format(string, " advertised: "); | |
9e1fd49b | 397 | ofp_print_port_features(string, port->advertised); |
064af421 BP |
398 | } |
399 | if (port->supported) { | |
400 | ds_put_format(string, " supported: "); | |
9e1fd49b | 401 | ofp_print_port_features(string, port->supported); |
064af421 BP |
402 | } |
403 | if (port->peer) { | |
404 | ds_put_format(string, " peer: "); | |
9e1fd49b BP |
405 | ofp_print_port_features(string, port->peer); |
406 | } | |
407 | ds_put_format(string, " speed: %"PRIu32" Mbps now, " | |
408 | "%"PRIu32" Mbps max\n", | |
409 | port->curr_speed / UINT32_C(1000), | |
410 | port->max_speed / UINT32_C(1000)); | |
411 | } | |
412 | ||
2be393ed JP |
413 | /* Given a buffer 'b' that contains an array of OpenFlow ports of type |
414 | * 'ofp_version', writes a detailed description of each port into | |
415 | * 'string'. */ | |
416 | static void | |
417 | ofp_print_phy_ports(struct ds *string, uint8_t ofp_version, | |
418 | struct ofpbuf *b) | |
419 | { | |
420 | size_t n_ports; | |
421 | struct ofputil_phy_port *ports; | |
422 | enum ofperr error; | |
423 | size_t i; | |
424 | ||
425 | n_ports = ofputil_count_phy_ports(ofp_version, b); | |
426 | ||
427 | ports = xmalloc(n_ports * sizeof *ports); | |
428 | for (i = 0; i < n_ports; i++) { | |
429 | error = ofputil_pull_phy_port(ofp_version, b, &ports[i]); | |
430 | if (error) { | |
431 | ofp_print_error(string, error); | |
432 | goto exit; | |
433 | } | |
434 | } | |
435 | qsort(ports, n_ports, sizeof *ports, compare_ports); | |
436 | for (i = 0; i < n_ports; i++) { | |
437 | ofp_print_phy_port(string, &ports[i]); | |
438 | } | |
439 | ||
440 | exit: | |
441 | free(ports); | |
442 | } | |
443 | ||
9e1fd49b BP |
444 | static const char * |
445 | ofputil_capabilities_to_name(uint32_t bit) | |
446 | { | |
447 | enum ofputil_capabilities capabilities = bit; | |
448 | ||
449 | switch (capabilities) { | |
450 | case OFPUTIL_C_FLOW_STATS: return "FLOW_STATS"; | |
451 | case OFPUTIL_C_TABLE_STATS: return "TABLE_STATS"; | |
452 | case OFPUTIL_C_PORT_STATS: return "PORT_STATS"; | |
453 | case OFPUTIL_C_IP_REASM: return "IP_REASM"; | |
454 | case OFPUTIL_C_QUEUE_STATS: return "QUEUE_STATS"; | |
455 | case OFPUTIL_C_ARP_MATCH_IP: return "ARP_MATCH_IP"; | |
456 | case OFPUTIL_C_STP: return "STP"; | |
457 | case OFPUTIL_C_GROUP_STATS: return "GROUP_STATS"; | |
60202987 | 458 | case OFPUTIL_C_PORT_BLOCKED: return "PORT_BLOCKED"; |
9e1fd49b BP |
459 | } |
460 | ||
461 | return NULL; | |
462 | } | |
463 | ||
464 | static const char * | |
465 | ofputil_action_bitmap_to_name(uint32_t bit) | |
466 | { | |
467 | enum ofputil_action_bitmap action = bit; | |
468 | ||
469 | switch (action) { | |
470 | case OFPUTIL_A_OUTPUT: return "OUTPUT"; | |
471 | case OFPUTIL_A_SET_VLAN_VID: return "SET_VLAN_VID"; | |
472 | case OFPUTIL_A_SET_VLAN_PCP: return "SET_VLAN_PCP"; | |
473 | case OFPUTIL_A_STRIP_VLAN: return "STRIP_VLAN"; | |
474 | case OFPUTIL_A_SET_DL_SRC: return "SET_DL_SRC"; | |
475 | case OFPUTIL_A_SET_DL_DST: return "SET_DL_DST"; | |
476 | case OFPUTIL_A_SET_NW_SRC: return "SET_NW_SRC"; | |
477 | case OFPUTIL_A_SET_NW_DST: return "SET_NW_DST"; | |
478 | case OFPUTIL_A_SET_NW_ECN: return "SET_NW_ECN"; | |
479 | case OFPUTIL_A_SET_NW_TOS: return "SET_NW_TOS"; | |
480 | case OFPUTIL_A_SET_TP_SRC: return "SET_TP_SRC"; | |
481 | case OFPUTIL_A_SET_TP_DST: return "SET_TP_DST"; | |
78a3fff6 | 482 | case OFPUTIL_A_SET_FIELD: return "SET_FIELD"; |
9e1fd49b BP |
483 | case OFPUTIL_A_ENQUEUE: return "ENQUEUE"; |
484 | case OFPUTIL_A_COPY_TTL_OUT: return "COPY_TTL_OUT"; | |
485 | case OFPUTIL_A_COPY_TTL_IN: return "COPY_TTL_IN"; | |
486 | case OFPUTIL_A_SET_MPLS_LABEL: return "SET_MPLS_LABEL"; | |
487 | case OFPUTIL_A_SET_MPLS_TC: return "SET_MPLS_TC"; | |
488 | case OFPUTIL_A_SET_MPLS_TTL: return "SET_MPLS_TTL"; | |
489 | case OFPUTIL_A_DEC_MPLS_TTL: return "DEC_MPLS_TTL"; | |
490 | case OFPUTIL_A_PUSH_VLAN: return "PUSH_VLAN"; | |
491 | case OFPUTIL_A_POP_VLAN: return "POP_VLAN"; | |
492 | case OFPUTIL_A_PUSH_MPLS: return "PUSH_MPLS"; | |
493 | case OFPUTIL_A_POP_MPLS: return "POP_MPLS"; | |
494 | case OFPUTIL_A_SET_QUEUE: return "SET_QUEUE"; | |
495 | case OFPUTIL_A_GROUP: return "GROUP"; | |
496 | case OFPUTIL_A_SET_NW_TTL: return "SET_NW_TTL"; | |
497 | case OFPUTIL_A_DEC_NW_TTL: return "DEC_NW_TTL"; | |
064af421 | 498 | } |
9e1fd49b BP |
499 | |
500 | return NULL; | |
064af421 BP |
501 | } |
502 | ||
064af421 | 503 | static void |
982697a4 | 504 | ofp_print_switch_features(struct ds *string, const struct ofp_header *oh) |
064af421 | 505 | { |
9e1fd49b | 506 | struct ofputil_switch_features features; |
9e1fd49b BP |
507 | enum ofperr error; |
508 | struct ofpbuf b; | |
064af421 | 509 | |
982697a4 | 510 | error = ofputil_decode_switch_features(oh, &features, &b); |
9e1fd49b BP |
511 | if (error) { |
512 | ofp_print_error(string, error); | |
513 | return; | |
514 | } | |
064af421 | 515 | |
9e1fd49b | 516 | ds_put_format(string, " dpid:%016"PRIx64"\n", features.datapath_id); |
2e1ae200 JR |
517 | |
518 | ds_put_format(string, "n_tables:%"PRIu8", n_buffers:%"PRIu32, | |
9e1fd49b | 519 | features.n_tables, features.n_buffers); |
2e1ae200 JR |
520 | if (features.auxiliary_id) { |
521 | ds_put_format(string, ", auxiliary_id:%"PRIu8, features.auxiliary_id); | |
522 | } | |
523 | ds_put_char(string, '\n'); | |
064af421 | 524 | |
9e1fd49b BP |
525 | ds_put_cstr(string, "capabilities: "); |
526 | ofp_print_bit_names(string, features.capabilities, | |
e8fa940e | 527 | ofputil_capabilities_to_name, ' '); |
9e1fd49b BP |
528 | ds_put_char(string, '\n'); |
529 | ||
210d8d9c SH |
530 | switch ((enum ofp_version)oh->version) { |
531 | case OFP10_VERSION: | |
532 | ds_put_cstr(string, "actions: "); | |
533 | ofp_print_bit_names(string, features.actions, | |
534 | ofputil_action_bitmap_to_name, ' '); | |
535 | ds_put_char(string, '\n'); | |
536 | break; | |
537 | case OFP11_VERSION: | |
538 | case OFP12_VERSION: | |
539 | break; | |
2e1ae200 JR |
540 | case OFP13_VERSION: |
541 | return; /* no ports in ofp13_switch_features */ | |
210d8d9c SH |
542 | default: |
543 | NOT_REACHED(); | |
544 | } | |
9e1fd49b | 545 | |
982697a4 | 546 | ofp_print_phy_ports(string, oh->version, &b); |
064af421 BP |
547 | } |
548 | ||
064af421 | 549 | static void |
d1e2cf21 | 550 | ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc) |
064af421 | 551 | { |
f0fd1a17 | 552 | enum ofp_config_flags flags; |
064af421 BP |
553 | |
554 | flags = ntohs(osc->flags); | |
3b62feba | 555 | |
7257b535 BP |
556 | ds_put_format(string, " frags=%s", ofputil_frag_handling_to_string(flags)); |
557 | flags &= ~OFPC_FRAG_MASK; | |
558 | ||
f0fd1a17 PS |
559 | if (flags & OFPC_INVALID_TTL_TO_CONTROLLER) { |
560 | ds_put_format(string, " invalid_ttl_to_controller"); | |
561 | flags &= ~OFPC_INVALID_TTL_TO_CONTROLLER; | |
562 | } | |
563 | ||
064af421 BP |
564 | if (flags) { |
565 | ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags); | |
566 | } | |
567 | ||
568 | ds_put_format(string, " miss_send_len=%"PRIu16"\n", ntohs(osc->miss_send_len)); | |
569 | } | |
570 | ||
571 | static void print_wild(struct ds *string, const char *leader, int is_wild, | |
d295e8e9 | 572 | int verbosity, const char *format, ...) |
064af421 BP |
573 | __attribute__((format(printf, 5, 6))); |
574 | ||
575 | static void print_wild(struct ds *string, const char *leader, int is_wild, | |
d295e8e9 | 576 | int verbosity, const char *format, ...) |
064af421 BP |
577 | { |
578 | if (is_wild && verbosity < 2) { | |
579 | return; | |
580 | } | |
581 | ds_put_cstr(string, leader); | |
582 | if (!is_wild) { | |
583 | va_list args; | |
584 | ||
585 | va_start(args, format); | |
586 | ds_put_format_valist(string, format, args); | |
587 | va_end(args); | |
588 | } else { | |
589 | ds_put_char(string, '*'); | |
590 | } | |
591 | ds_put_char(string, ','); | |
592 | } | |
593 | ||
e1db42d6 JR |
594 | static void |
595 | print_wild_port(struct ds *string, const char *leader, int is_wild, | |
4e022ec0 | 596 | int verbosity, ofp_port_t port) |
e1db42d6 JR |
597 | { |
598 | if (is_wild && verbosity < 2) { | |
599 | return; | |
600 | } | |
601 | ds_put_cstr(string, leader); | |
602 | if (!is_wild) { | |
603 | ofputil_format_port(port, string); | |
604 | } else { | |
605 | ds_put_char(string, '*'); | |
606 | } | |
607 | ds_put_char(string, ','); | |
608 | } | |
609 | ||
064af421 | 610 | static void |
dbba996b | 611 | print_ip_netmask(struct ds *string, const char *leader, ovs_be32 ip, |
064af421 BP |
612 | uint32_t wild_bits, int verbosity) |
613 | { | |
614 | if (wild_bits >= 32 && verbosity < 2) { | |
615 | return; | |
616 | } | |
617 | ds_put_cstr(string, leader); | |
618 | if (wild_bits < 32) { | |
ed36537e | 619 | ds_put_format(string, IP_FMT, IP_ARGS(ip)); |
064af421 BP |
620 | if (wild_bits) { |
621 | ds_put_format(string, "/%d", 32 - wild_bits); | |
622 | } | |
623 | } else { | |
624 | ds_put_char(string, '*'); | |
625 | } | |
626 | ds_put_char(string, ','); | |
627 | } | |
628 | ||
4f2cad2c | 629 | void |
eec25dc1 | 630 | ofp10_match_print(struct ds *f, const struct ofp10_match *om, int verbosity) |
064af421 | 631 | { |
eec25dc1 | 632 | char *s = ofp10_match_to_string(om, verbosity); |
064af421 BP |
633 | ds_put_cstr(f, s); |
634 | free(s); | |
635 | } | |
636 | ||
637 | char * | |
eec25dc1 | 638 | ofp10_match_to_string(const struct ofp10_match *om, int verbosity) |
064af421 BP |
639 | { |
640 | struct ds f = DS_EMPTY_INITIALIZER; | |
641 | uint32_t w = ntohl(om->wildcards); | |
642 | bool skip_type = false; | |
643 | bool skip_proto = false; | |
644 | ||
eec25dc1 | 645 | if (!(w & OFPFW10_DL_TYPE)) { |
064af421 BP |
646 | skip_type = true; |
647 | if (om->dl_type == htons(ETH_TYPE_IP)) { | |
eec25dc1 | 648 | if (!(w & OFPFW10_NW_PROTO)) { |
064af421 | 649 | skip_proto = true; |
6767a2cc | 650 | if (om->nw_proto == IPPROTO_ICMP) { |
064af421 | 651 | ds_put_cstr(&f, "icmp,"); |
6767a2cc | 652 | } else if (om->nw_proto == IPPROTO_TCP) { |
064af421 | 653 | ds_put_cstr(&f, "tcp,"); |
6767a2cc | 654 | } else if (om->nw_proto == IPPROTO_UDP) { |
064af421 | 655 | ds_put_cstr(&f, "udp,"); |
0d56eaf2 JS |
656 | } else if (om->nw_proto == IPPROTO_SCTP) { |
657 | ds_put_cstr(&f, "sctp,"); | |
064af421 BP |
658 | } else { |
659 | ds_put_cstr(&f, "ip,"); | |
660 | skip_proto = false; | |
661 | } | |
662 | } else { | |
663 | ds_put_cstr(&f, "ip,"); | |
664 | } | |
665 | } else if (om->dl_type == htons(ETH_TYPE_ARP)) { | |
666 | ds_put_cstr(&f, "arp,"); | |
8087f5ff MM |
667 | } else if (om->dl_type == htons(ETH_TYPE_RARP)){ |
668 | ds_put_cstr(&f, "rarp,"); | |
b02475c5 SH |
669 | } else if (om->dl_type == htons(ETH_TYPE_MPLS)) { |
670 | ds_put_cstr(&f, "mpls,"); | |
671 | } else if (om->dl_type == htons(ETH_TYPE_MPLS_MCAST)) { | |
672 | ds_put_cstr(&f, "mplsm,"); | |
064af421 BP |
673 | } else { |
674 | skip_type = false; | |
675 | } | |
676 | } | |
e1db42d6 | 677 | print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity, |
4e022ec0 | 678 | u16_to_ofp(ntohs(om->in_port))); |
eec25dc1 | 679 | print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity, |
6a1f89c8 | 680 | "%d", ntohs(om->dl_vlan)); |
eec25dc1 | 681 | print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity, |
959a2ecd | 682 | "%d", om->dl_vlan_pcp); |
eec25dc1 | 683 | print_wild(&f, "dl_src=", w & OFPFW10_DL_SRC, verbosity, |
064af421 | 684 | ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src)); |
eec25dc1 | 685 | print_wild(&f, "dl_dst=", w & OFPFW10_DL_DST, verbosity, |
064af421 BP |
686 | ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst)); |
687 | if (!skip_type) { | |
eec25dc1 | 688 | print_wild(&f, "dl_type=", w & OFPFW10_DL_TYPE, verbosity, |
064af421 BP |
689 | "0x%04x", ntohs(om->dl_type)); |
690 | } | |
691 | print_ip_netmask(&f, "nw_src=", om->nw_src, | |
eec25dc1 BP |
692 | (w & OFPFW10_NW_SRC_MASK) >> OFPFW10_NW_SRC_SHIFT, |
693 | verbosity); | |
064af421 | 694 | print_ip_netmask(&f, "nw_dst=", om->nw_dst, |
eec25dc1 BP |
695 | (w & OFPFW10_NW_DST_MASK) >> OFPFW10_NW_DST_SHIFT, |
696 | verbosity); | |
064af421 | 697 | if (!skip_proto) { |
8087f5ff MM |
698 | if (om->dl_type == htons(ETH_TYPE_ARP) || |
699 | om->dl_type == htons(ETH_TYPE_RARP)) { | |
eec25dc1 | 700 | print_wild(&f, "arp_op=", w & OFPFW10_NW_PROTO, verbosity, |
fb892732 JP |
701 | "%u", om->nw_proto); |
702 | } else { | |
eec25dc1 | 703 | print_wild(&f, "nw_proto=", w & OFPFW10_NW_PROTO, verbosity, |
fb892732 JP |
704 | "%u", om->nw_proto); |
705 | } | |
064af421 | 706 | } |
eec25dc1 | 707 | print_wild(&f, "nw_tos=", w & OFPFW10_NW_TOS, verbosity, |
1a960c80 | 708 | "%u", om->nw_tos); |
6767a2cc | 709 | if (om->nw_proto == IPPROTO_ICMP) { |
eec25dc1 | 710 | print_wild(&f, "icmp_type=", w & OFPFW10_ICMP_TYPE, verbosity, |
3ee8a9f0 | 711 | "%d", ntohs(om->tp_src)); |
eec25dc1 | 712 | print_wild(&f, "icmp_code=", w & OFPFW10_ICMP_CODE, verbosity, |
3ee8a9f0 | 713 | "%d", ntohs(om->tp_dst)); |
064af421 | 714 | } else { |
eec25dc1 | 715 | print_wild(&f, "tp_src=", w & OFPFW10_TP_SRC, verbosity, |
064af421 | 716 | "%d", ntohs(om->tp_src)); |
eec25dc1 | 717 | print_wild(&f, "tp_dst=", w & OFPFW10_TP_DST, verbosity, |
064af421 BP |
718 | "%d", ntohs(om->tp_dst)); |
719 | } | |
7fa91113 BP |
720 | if (ds_last(&f) == ',') { |
721 | f.length--; | |
722 | } | |
064af421 BP |
723 | return ds_cstr(&f); |
724 | } | |
725 | ||
2e1ae200 | 726 | static void |
0fb88c18 | 727 | ofp_print_flow_flags(struct ds *s, enum ofputil_flow_mod_flags flags) |
2e1ae200 | 728 | { |
0fb88c18 | 729 | if (flags & OFPUTIL_FF_SEND_FLOW_REM) { |
2e1ae200 JR |
730 | ds_put_cstr(s, "send_flow_rem "); |
731 | } | |
0fb88c18 | 732 | if (flags & OFPUTIL_FF_CHECK_OVERLAP) { |
2e1ae200 JR |
733 | ds_put_cstr(s, "check_overlap "); |
734 | } | |
0fb88c18 | 735 | if (flags & OFPUTIL_FF_RESET_COUNTS) { |
2e1ae200 JR |
736 | ds_put_cstr(s, "reset_counts "); |
737 | } | |
0fb88c18 | 738 | if (flags & OFPUTIL_FF_NO_PKT_COUNTS) { |
2e1ae200 JR |
739 | ds_put_cstr(s, "no_packet_counts "); |
740 | } | |
0fb88c18 | 741 | if (flags & OFPUTIL_FF_NO_BYT_COUNTS) { |
2e1ae200 JR |
742 | ds_put_cstr(s, "no_byte_counts "); |
743 | } | |
2e1ae200 JR |
744 | } |
745 | ||
064af421 | 746 | static void |
982697a4 | 747 | ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity) |
064af421 | 748 | { |
a9a2da38 | 749 | struct ofputil_flow_mod fm; |
f25d0cf3 | 750 | struct ofpbuf ofpacts; |
f904747b | 751 | bool need_priority; |
90bf1e07 | 752 | enum ofperr error; |
982697a4 | 753 | enum ofpraw raw; |
981c5fdd SH |
754 | enum ofputil_protocol protocol; |
755 | ||
756 | protocol = ofputil_protocol_from_ofp_version(oh->version); | |
757 | protocol = ofputil_protocol_set_tid(protocol, true); | |
064af421 | 758 | |
f25d0cf3 | 759 | ofpbuf_init(&ofpacts, 64); |
7e9f8266 BP |
760 | error = ofputil_decode_flow_mod(&fm, oh, protocol, &ofpacts, |
761 | OFPP_MAX, 255); | |
7fa91113 | 762 | if (error) { |
f25d0cf3 | 763 | ofpbuf_uninit(&ofpacts); |
7fa91113 BP |
764 | ofp_print_error(s, error); |
765 | return; | |
3ff4f871 BP |
766 | } |
767 | ||
7fa91113 BP |
768 | ds_put_char(s, ' '); |
769 | switch (fm.command) { | |
064af421 | 770 | case OFPFC_ADD: |
7fa91113 | 771 | ds_put_cstr(s, "ADD"); |
064af421 BP |
772 | break; |
773 | case OFPFC_MODIFY: | |
7fa91113 | 774 | ds_put_cstr(s, "MOD"); |
064af421 BP |
775 | break; |
776 | case OFPFC_MODIFY_STRICT: | |
7fa91113 | 777 | ds_put_cstr(s, "MOD_STRICT"); |
064af421 BP |
778 | break; |
779 | case OFPFC_DELETE: | |
7fa91113 | 780 | ds_put_cstr(s, "DEL"); |
064af421 BP |
781 | break; |
782 | case OFPFC_DELETE_STRICT: | |
7fa91113 | 783 | ds_put_cstr(s, "DEL_STRICT"); |
064af421 BP |
784 | break; |
785 | default: | |
7fa91113 BP |
786 | ds_put_format(s, "cmd:%d", fm.command); |
787 | } | |
6c1491fb | 788 | if (fm.table_id != 0) { |
e896c2d4 | 789 | ds_put_format(s, " table:%d", fm.table_id); |
6c1491fb | 790 | } |
7fa91113 BP |
791 | |
792 | ds_put_char(s, ' '); | |
982697a4 BP |
793 | ofpraw_decode(&raw, oh); |
794 | if (verbosity >= 3 && raw == OFPRAW_OFPT10_FLOW_MOD) { | |
35805806 | 795 | const struct ofp10_flow_mod *ofm = ofpmsg_body(oh); |
eec25dc1 | 796 | ofp10_match_print(s, &ofm->match, verbosity); |
f904747b BP |
797 | |
798 | /* ofp_print_match() doesn't print priority. */ | |
799 | need_priority = true; | |
982697a4 BP |
800 | } else if (verbosity >= 3 && raw == OFPRAW_NXT_FLOW_MOD) { |
801 | const struct nx_flow_mod *nfm = ofpmsg_body(oh); | |
7fa91113 | 802 | const void *nxm = nfm + 1; |
f904747b BP |
803 | char *nxm_s; |
804 | ||
805 | nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len)); | |
7fa91113 BP |
806 | ds_put_cstr(s, nxm_s); |
807 | free(nxm_s); | |
f904747b BP |
808 | |
809 | /* nx_match_to_string() doesn't print priority. */ | |
810 | need_priority = true; | |
7fa91113 | 811 | } else { |
81a76618 | 812 | match_format(&fm.match, s, fm.priority); |
f904747b | 813 | |
81a76618 | 814 | /* match_format() does print priority. */ |
f904747b | 815 | need_priority = false; |
3ff4f871 | 816 | } |
7fa91113 BP |
817 | |
818 | if (ds_last(s) != ' ') { | |
819 | ds_put_char(s, ' '); | |
3ff4f871 | 820 | } |
b8266395 | 821 | if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) { |
623e1caf JP |
822 | ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie)); |
823 | } | |
824 | if (fm.cookie_mask != htonll(0)) { | |
825 | ds_put_format(s, "cookie:0x%"PRIx64"/0x%"PRIx64" ", | |
826 | ntohll(fm.cookie), ntohll(fm.cookie_mask)); | |
3ff4f871 | 827 | } |
7fa91113 BP |
828 | if (fm.idle_timeout != OFP_FLOW_PERMANENT) { |
829 | ds_put_format(s, "idle:%"PRIu16" ", fm.idle_timeout); | |
064af421 | 830 | } |
7fa91113 BP |
831 | if (fm.hard_timeout != OFP_FLOW_PERMANENT) { |
832 | ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout); | |
3ff4f871 | 833 | } |
81a76618 BP |
834 | if (fm.priority != OFP_DEFAULT_PRIORITY && need_priority) { |
835 | ds_put_format(s, "pri:%"PRIu16" ", fm.priority); | |
3ff4f871 | 836 | } |
7fa91113 BP |
837 | if (fm.buffer_id != UINT32_MAX) { |
838 | ds_put_format(s, "buf:0x%"PRIx32" ", fm.buffer_id); | |
3ff4f871 | 839 | } |
7f05e7ab | 840 | if (fm.out_port != OFPP_ANY) { |
de0f16bc BP |
841 | ds_put_format(s, "out_port:"); |
842 | ofputil_format_port(fm.out_port, s); | |
843 | ds_put_char(s, ' '); | |
844 | } | |
0fb88c18 BP |
845 | |
846 | if (oh->version == OFP10_VERSION || oh->version == OFP11_VERSION) { | |
847 | /* Don't print the reset_counts flag for OF1.0 and OF1.1 because those | |
848 | * versions don't really have such a flag and printing one is likely to | |
849 | * confuse people. */ | |
850 | fm.flags &= ~OFPUTIL_FF_RESET_COUNTS; | |
7fa91113 | 851 | } |
0fb88c18 | 852 | ofp_print_flow_flags(s, fm.flags); |
7fa91113 | 853 | |
455ecd77 | 854 | ds_put_cstr(s, "actions="); |
f25d0cf3 BP |
855 | ofpacts_format(fm.ofpacts, fm.ofpacts_len, s); |
856 | ofpbuf_uninit(&ofpacts); | |
064af421 BP |
857 | } |
858 | ||
09862ec6 BP |
859 | static void |
860 | ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec) | |
861 | { | |
862 | ds_put_format(string, "%u", sec); | |
863 | if (nsec > 0) { | |
864 | ds_put_format(string, ".%09u", nsec); | |
865 | while (string->string[string->length - 1] == '0') { | |
866 | string->length--; | |
867 | } | |
868 | } | |
869 | ds_put_char(string, 's'); | |
870 | } | |
871 | ||
8961699e BP |
872 | /* Returns a string form of 'reason'. The return value is either a statically |
873 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
874 | * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */ | |
875 | #define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1) | |
80d5aefd | 876 | static const char * |
8961699e BP |
877 | ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason, |
878 | char *reasonbuf, size_t bufsize) | |
80d5aefd | 879 | { |
80d5aefd BP |
880 | switch (reason) { |
881 | case OFPRR_IDLE_TIMEOUT: | |
882 | return "idle"; | |
883 | case OFPRR_HARD_TIMEOUT: | |
884 | return "hard"; | |
885 | case OFPRR_DELETE: | |
886 | return "delete"; | |
04f68eb2 SH |
887 | case OFPRR_GROUP_DELETE: |
888 | return "group_delete"; | |
1d31ece9 BP |
889 | case OFPRR_EVICTION: |
890 | return "eviction"; | |
638a19b0 JR |
891 | case OFPRR_METER_DELETE: |
892 | return "meter_delete"; | |
80d5aefd | 893 | default: |
8961699e BP |
894 | snprintf(reasonbuf, bufsize, "%d", (int) reason); |
895 | return reasonbuf; | |
80d5aefd BP |
896 | } |
897 | } | |
898 | ||
064af421 | 899 | static void |
9b045a0c | 900 | ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh) |
064af421 | 901 | { |
8961699e | 902 | char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE]; |
9b045a0c | 903 | struct ofputil_flow_removed fr; |
90bf1e07 | 904 | enum ofperr error; |
9b045a0c | 905 | |
b78f6b77 | 906 | error = ofputil_decode_flow_removed(&fr, oh); |
9b045a0c BP |
907 | if (error) { |
908 | ofp_print_error(string, error); | |
909 | return; | |
910 | } | |
911 | ||
fbd76b2e | 912 | ds_put_char(string, ' '); |
81a76618 | 913 | match_format(&fr.match, string, fr.priority); |
9b045a0c | 914 | |
80d5aefd | 915 | ds_put_format(string, " reason=%s", |
8961699e BP |
916 | ofp_flow_removed_reason_to_string(fr.reason, reasonbuf, |
917 | sizeof reasonbuf)); | |
3ff4f871 | 918 | |
95216219 SH |
919 | if (fr.table_id != 255) { |
920 | ds_put_format(string, " table_id=%"PRIu8, fr.table_id); | |
921 | } | |
922 | ||
9b045a0c BP |
923 | if (fr.cookie != htonll(0)) { |
924 | ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie)); | |
3ff4f871 | 925 | } |
09862ec6 | 926 | ds_put_cstr(string, " duration"); |
9b045a0c | 927 | ofp_print_duration(string, fr.duration_sec, fr.duration_nsec); |
fa2bad0f BP |
928 | ds_put_format(string, " idle%"PRIu16, fr.idle_timeout); |
929 | if (fr.hard_timeout) { | |
930 | /* The hard timeout was only added in OF1.2, so only print it if it is | |
931 | * actually in use to avoid gratuitous change to the formatting. */ | |
932 | ds_put_format(string, " hard%"PRIu16, fr.hard_timeout); | |
933 | } | |
934 | ds_put_format(string, " pkts%"PRIu64" bytes%"PRIu64"\n", | |
935 | fr.packet_count, fr.byte_count); | |
064af421 BP |
936 | } |
937 | ||
938 | static void | |
9e1fd49b | 939 | ofp_print_port_mod(struct ds *string, const struct ofp_header *oh) |
064af421 | 940 | { |
9e1fd49b BP |
941 | struct ofputil_port_mod pm; |
942 | enum ofperr error; | |
943 | ||
944 | error = ofputil_decode_port_mod(oh, &pm); | |
945 | if (error) { | |
946 | ofp_print_error(string, error); | |
947 | return; | |
948 | } | |
949 | ||
e1db42d6 JR |
950 | ds_put_cstr(string, "port: "); |
951 | ofputil_format_port(pm.port_no, string); | |
952 | ds_put_format(string, ": addr:"ETH_ADDR_FMT"\n", | |
953 | ETH_ADDR_ARGS(pm.hw_addr)); | |
9e1fd49b | 954 | |
e1db42d6 | 955 | ds_put_cstr(string, " config: "); |
9e1fd49b BP |
956 | ofp_print_port_config(string, pm.config); |
957 | ||
e1db42d6 | 958 | ds_put_cstr(string, " mask: "); |
9e1fd49b BP |
959 | ofp_print_port_config(string, pm.mask); |
960 | ||
e1db42d6 | 961 | ds_put_cstr(string, " advertise: "); |
9e1fd49b BP |
962 | if (pm.advertise) { |
963 | ofp_print_port_features(string, pm.advertise); | |
064af421 | 964 | } else { |
e1db42d6 | 965 | ds_put_cstr(string, "UNCHANGED\n"); |
064af421 BP |
966 | } |
967 | } | |
968 | ||
918f2b82 AZ |
969 | static void |
970 | ofp_print_table_miss_config(struct ds *string, const uint32_t config) | |
971 | { | |
972 | uint32_t table_miss_config = config & OFPTC11_TABLE_MISS_MASK; | |
973 | ||
974 | switch (table_miss_config) { | |
975 | case OFPTC11_TABLE_MISS_CONTROLLER: | |
976 | ds_put_cstr(string, "controller\n"); | |
977 | break; | |
978 | case OFPTC11_TABLE_MISS_CONTINUE: | |
979 | ds_put_cstr(string, "continue\n"); | |
980 | break; | |
981 | case OFPTC11_TABLE_MISS_DROP: | |
982 | ds_put_cstr(string, "drop\n"); | |
983 | break; | |
984 | default: | |
985 | ds_put_cstr(string, "Unknown\n"); | |
986 | break; | |
987 | } | |
988 | } | |
989 | ||
990 | static void | |
991 | ofp_print_table_mod(struct ds *string, const struct ofp_header *oh) | |
992 | { | |
993 | struct ofputil_table_mod pm; | |
994 | enum ofperr error; | |
995 | ||
996 | error = ofputil_decode_table_mod(oh, &pm); | |
997 | if (error) { | |
998 | ofp_print_error(string, error); | |
999 | return; | |
1000 | } | |
1001 | ||
1002 | if (pm.table_id == 0xff) { | |
1003 | ds_put_cstr(string, " table_id: ALL_TABLES"); | |
1004 | } else { | |
1005 | ds_put_format(string, " table_id=%"PRIu8, pm.table_id); | |
1006 | } | |
1007 | ||
1008 | ds_put_cstr(string, ", flow_miss_config="); | |
1009 | ofp_print_table_miss_config(string, pm.config); | |
1010 | } | |
1011 | ||
e8f9a7bb VG |
1012 | static void |
1013 | ofp_print_queue_get_config_request(struct ds *string, | |
1014 | const struct ofp_header *oh) | |
1015 | { | |
1016 | enum ofperr error; | |
1017 | ofp_port_t port; | |
1018 | ||
1019 | error = ofputil_decode_queue_get_config_request(oh, &port); | |
1020 | if (error) { | |
1021 | ofp_print_error(string, error); | |
1022 | return; | |
1023 | } | |
1024 | ||
1025 | ds_put_cstr(string, " port="); | |
1026 | ofputil_format_port(port, string); | |
1027 | } | |
1028 | ||
1029 | static void | |
1030 | print_queue_rate(struct ds *string, const char *name, unsigned int rate) | |
1031 | { | |
1032 | if (rate <= 1000) { | |
1033 | ds_put_format(string, " %s:%u.%u%%", name, rate / 10, rate % 10); | |
1034 | } else if (rate < UINT16_MAX) { | |
1035 | ds_put_format(string, " %s:(disabled)", name); | |
1036 | } | |
1037 | } | |
1038 | ||
1039 | static void | |
1040 | ofp_print_queue_get_config_reply(struct ds *string, | |
1041 | const struct ofp_header *oh) | |
1042 | { | |
1043 | enum ofperr error; | |
1044 | struct ofpbuf b; | |
1045 | ofp_port_t port; | |
1046 | ||
1047 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1048 | error = ofputil_decode_queue_get_config_reply(&b, &port); | |
1049 | if (error) { | |
1050 | ofp_print_error(string, error); | |
1051 | return; | |
1052 | } | |
1053 | ||
1054 | ds_put_cstr(string, " port="); | |
1055 | ofputil_format_port(port, string); | |
1056 | ds_put_char(string, '\n'); | |
1057 | ||
1058 | for (;;) { | |
1059 | struct ofputil_queue_config queue; | |
1060 | int retval; | |
1061 | ||
1062 | retval = ofputil_pull_queue_get_config_reply(&b, &queue); | |
1063 | if (retval) { | |
1064 | if (retval != EOF) { | |
1065 | ofp_print_error(string, retval); | |
1066 | } | |
1067 | break; | |
1068 | } | |
1069 | ||
1070 | ds_put_format(string, "queue %"PRIu32":", queue.queue_id); | |
1071 | print_queue_rate(string, "min_rate", queue.min_rate); | |
1072 | print_queue_rate(string, "max_rate", queue.max_rate); | |
1073 | ds_put_char(string, '\n'); | |
1074 | } | |
1075 | } | |
1076 | ||
638a19b0 JR |
1077 | static void |
1078 | ofp_print_meter_flags(struct ds *s, uint16_t flags) | |
1079 | { | |
1080 | if (flags & OFPMF13_KBPS) { | |
1081 | ds_put_cstr(s, "kbps "); | |
1082 | } | |
1083 | if (flags & OFPMF13_PKTPS) { | |
1084 | ds_put_cstr(s, "pktps "); | |
1085 | } | |
1086 | if (flags & OFPMF13_BURST) { | |
1087 | ds_put_cstr(s, "burst "); | |
1088 | } | |
1089 | if (flags & OFPMF13_STATS) { | |
1090 | ds_put_cstr(s, "stats "); | |
1091 | } | |
1092 | ||
1093 | flags &= ~(OFPMF13_KBPS | OFPMF13_PKTPS | OFPMF13_BURST | OFPMF13_STATS); | |
1094 | if (flags) { | |
1095 | ds_put_format(s, "flags:0x%"PRIx16" ", flags); | |
1096 | } | |
1097 | } | |
1098 | ||
1099 | static void | |
1100 | ofp_print_meter_band(struct ds *s, uint16_t flags, | |
1101 | const struct ofputil_meter_band *mb) | |
1102 | { | |
1103 | ds_put_cstr(s, "\ntype="); | |
1104 | switch (mb->type) { | |
1105 | case OFPMBT13_DROP: | |
1106 | ds_put_cstr(s, "drop"); | |
1107 | break; | |
1108 | case OFPMBT13_DSCP_REMARK: | |
1109 | ds_put_cstr(s, "dscp_remark"); | |
1110 | break; | |
1111 | default: | |
1112 | ds_put_format(s, "%u", mb->type); | |
1113 | } | |
1114 | ||
1115 | ds_put_format(s, " rate=%"PRIu32, mb->rate); | |
1116 | ||
1117 | if (flags & OFPMF13_BURST) { | |
1118 | ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size); | |
1119 | } | |
1120 | if (mb->type == OFPMBT13_DSCP_REMARK) { | |
1121 | ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level); | |
1122 | } | |
1123 | } | |
1124 | ||
1125 | static void | |
1126 | ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms) | |
1127 | { | |
1128 | uint16_t i; | |
1129 | ||
1130 | ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id); | |
1131 | ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count); | |
1132 | ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count); | |
1133 | ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count); | |
1134 | ds_put_cstr(s, "duration:"); | |
1135 | ofp_print_duration(s, ms->duration_sec, ms->duration_nsec); | |
1136 | ds_put_char(s, ' '); | |
1137 | ||
1138 | ds_put_cstr(s, "bands:\n"); | |
1139 | for (i = 0; i < ms->n_bands; ++i) { | |
1140 | ds_put_format(s, "%d: ", i); | |
1141 | ds_put_format(s, "packet_count:%"PRIu64" ", ms->bands[i].packet_count); | |
1142 | ds_put_format(s, "byte_count:%"PRIu64"\n", ms->bands[i].byte_count); | |
1143 | } | |
1144 | } | |
1145 | ||
1146 | static void | |
1147 | ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc) | |
1148 | { | |
1149 | uint16_t i; | |
1150 | ||
1151 | ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id); | |
1152 | ||
1153 | ofp_print_meter_flags(s, mc->flags); | |
1154 | ||
1155 | ds_put_cstr(s, "bands="); | |
1156 | for (i = 0; i < mc->n_bands; ++i) { | |
1157 | ofp_print_meter_band(s, mc->flags, &mc->bands[i]); | |
1158 | } | |
1159 | ds_put_char(s, '\n'); | |
1160 | } | |
1161 | ||
1162 | static void | |
1163 | ofp_print_meter_mod(struct ds *s, const struct ofp_header *oh) | |
1164 | { | |
1165 | struct ofputil_meter_mod mm; | |
1166 | struct ofpbuf bands; | |
1167 | enum ofperr error; | |
1168 | ||
1169 | ofpbuf_init(&bands, 64); | |
1170 | error = ofputil_decode_meter_mod(oh, &mm, &bands); | |
1171 | if (error) { | |
1172 | ofpbuf_uninit(&bands); | |
1173 | ofp_print_error(s, error); | |
1174 | return; | |
1175 | } | |
1176 | ||
1177 | switch (mm.command) { | |
1178 | case OFPMC13_ADD: | |
1179 | ds_put_cstr(s, " ADD "); | |
1180 | break; | |
1181 | case OFPMC13_MODIFY: | |
1182 | ds_put_cstr(s, " MOD "); | |
1183 | break; | |
1184 | case OFPMC13_DELETE: | |
1185 | ds_put_cstr(s, " DEL "); | |
1186 | break; | |
1187 | default: | |
1188 | ds_put_format(s, " cmd:%d ", mm.command); | |
1189 | } | |
1190 | ||
1191 | ofp_print_meter_config(s, &mm.meter); | |
1192 | ofpbuf_uninit(&bands); | |
1193 | } | |
1194 | ||
1195 | static void | |
1196 | ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh) | |
1197 | { | |
1198 | uint32_t meter_id; | |
1199 | ||
1200 | ofputil_decode_meter_request(oh, &meter_id); | |
1201 | ||
1202 | ds_put_format(s, " meter=%"PRIu32, meter_id); | |
1203 | } | |
1204 | ||
1205 | static const char * | |
1206 | ofputil_meter_capabilities_to_name(uint32_t bit) | |
1207 | { | |
1208 | enum ofp13_meter_flags flag = bit; | |
1209 | ||
1210 | switch (flag) { | |
1211 | case OFPMF13_KBPS: return "kbps"; | |
1212 | case OFPMF13_PKTPS: return "pktps"; | |
1213 | case OFPMF13_BURST: return "burst"; | |
1214 | case OFPMF13_STATS: return "stats"; | |
1215 | } | |
1216 | ||
1217 | return NULL; | |
1218 | } | |
1219 | ||
1220 | static const char * | |
1221 | ofputil_meter_band_types_to_name(uint32_t bit) | |
1222 | { | |
638a19b0 | 1223 | switch (bit) { |
6e055a6c BP |
1224 | case 1 << OFPMBT13_DROP: return "drop"; |
1225 | case 1 << OFPMBT13_DSCP_REMARK: return "dscp_remark"; | |
638a19b0 JR |
1226 | } |
1227 | ||
1228 | return NULL; | |
1229 | } | |
1230 | ||
1231 | static void | |
1232 | ofp_print_meter_features_reply(struct ds *s, const struct ofp_header *oh) | |
1233 | { | |
1234 | struct ofputil_meter_features mf; | |
1235 | ||
1236 | ofputil_decode_meter_features(oh, &mf); | |
1237 | ||
1238 | ds_put_format(s, "\nmax_meter:%"PRIu32, mf.max_meters); | |
1239 | ds_put_format(s, " max_bands:%"PRIu8, mf.max_bands); | |
1240 | ds_put_format(s, " max_color:%"PRIu8"\n", mf.max_color); | |
1241 | ||
1242 | ds_put_cstr(s, "band_types: "); | |
1243 | ofp_print_bit_names(s, mf.band_types, | |
1244 | ofputil_meter_band_types_to_name, ' '); | |
1245 | ds_put_char(s, '\n'); | |
1246 | ||
1247 | ds_put_cstr(s, "capabilities: "); | |
1248 | ofp_print_bit_names(s, mf.capabilities, | |
1249 | ofputil_meter_capabilities_to_name, ' '); | |
1250 | ds_put_char(s, '\n'); | |
1251 | } | |
1252 | ||
1253 | static void | |
1254 | ofp_print_meter_config_reply(struct ds *s, const struct ofp_header *oh) | |
1255 | { | |
1256 | struct ofpbuf bands; | |
1257 | struct ofpbuf b; | |
1258 | ||
1259 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1260 | ofpbuf_init(&bands, 64); | |
1261 | for (;;) { | |
1262 | struct ofputil_meter_config mc; | |
1263 | int retval; | |
1264 | ||
1265 | retval = ofputil_decode_meter_config(&b, &mc, &bands); | |
1266 | if (retval) { | |
1267 | if (retval != EOF) { | |
1268 | ofp_print_error(s, retval); | |
1269 | } | |
1270 | break; | |
1271 | } | |
1272 | ds_put_char(s, '\n'); | |
1273 | ofp_print_meter_config(s, &mc); | |
1274 | } | |
1275 | ofpbuf_uninit(&bands); | |
1276 | } | |
1277 | ||
1278 | static void | |
1279 | ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh) | |
1280 | { | |
1281 | struct ofpbuf bands; | |
1282 | struct ofpbuf b; | |
1283 | ||
1284 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1285 | ofpbuf_init(&bands, 64); | |
1286 | for (;;) { | |
1287 | struct ofputil_meter_stats ms; | |
1288 | int retval; | |
1289 | ||
1290 | retval = ofputil_decode_meter_stats(&b, &ms, &bands); | |
1291 | if (retval) { | |
1292 | if (retval != EOF) { | |
1293 | ofp_print_error(s, retval); | |
1294 | } | |
1295 | break; | |
1296 | } | |
1297 | ds_put_char(s, '\n'); | |
1298 | ofp_print_meter_stats(s, &ms); | |
1299 | } | |
1300 | ofpbuf_uninit(&bands); | |
1301 | } | |
1302 | ||
7fa91113 | 1303 | static void |
90bf1e07 | 1304 | ofp_print_error(struct ds *string, enum ofperr error) |
7fa91113 | 1305 | { |
7fa91113 BP |
1306 | if (string->length) { |
1307 | ds_put_char(string, ' '); | |
1308 | } | |
90bf1e07 | 1309 | ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error)); |
f74be05a JP |
1310 | } |
1311 | ||
de6c85b0 SH |
1312 | static void |
1313 | ofp_print_hello(struct ds *string, const struct ofp_header *oh) | |
1314 | { | |
1315 | uint32_t allowed_versions; | |
1316 | bool ok; | |
1317 | ||
1318 | ok = ofputil_decode_hello(oh, &allowed_versions); | |
1319 | ||
1320 | ds_put_cstr(string, "\n version bitmap: "); | |
1321 | ofputil_format_version_bitmap(string, allowed_versions); | |
1322 | ||
1323 | if (!ok) { | |
1324 | ds_put_cstr(string, "\n unknown data in hello:\n"); | |
1325 | ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true); | |
1326 | } | |
1327 | } | |
1328 | ||
064af421 | 1329 | static void |
982697a4 | 1330 | ofp_print_error_msg(struct ds *string, const struct ofp_header *oh) |
064af421 | 1331 | { |
982697a4 BP |
1332 | size_t len = ntohs(oh->length); |
1333 | struct ofpbuf payload; | |
90bf1e07 | 1334 | enum ofperr error; |
064af421 BP |
1335 | char *s; |
1336 | ||
982697a4 | 1337 | error = ofperr_decode_msg(oh, &payload); |
90bf1e07 BP |
1338 | if (!error) { |
1339 | ds_put_cstr(string, "***decode error***"); | |
982697a4 | 1340 | ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true); |
dc4762ed | 1341 | return; |
f74be05a JP |
1342 | } |
1343 | ||
90bf1e07 | 1344 | ds_put_format(string, " %s\n", ofperr_get_name(error)); |
064af421 | 1345 | |
90bf1e07 | 1346 | if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) { |
982697a4 | 1347 | ds_put_printable(string, payload.data, payload.size); |
90bf1e07 | 1348 | } else { |
982697a4 | 1349 | s = ofp_to_string(payload.data, payload.size, 1); |
064af421 BP |
1350 | ds_put_cstr(string, s); |
1351 | free(s); | |
064af421 BP |
1352 | } |
1353 | } | |
1354 | ||
064af421 | 1355 | static void |
982697a4 | 1356 | ofp_print_port_status(struct ds *string, const struct ofp_header *oh) |
064af421 | 1357 | { |
9e1fd49b BP |
1358 | struct ofputil_port_status ps; |
1359 | enum ofperr error; | |
1360 | ||
982697a4 | 1361 | error = ofputil_decode_port_status(oh, &ps); |
9e1fd49b BP |
1362 | if (error) { |
1363 | ofp_print_error(string, error); | |
1364 | return; | |
1365 | } | |
1366 | ||
1367 | if (ps.reason == OFPPR_ADD) { | |
064af421 | 1368 | ds_put_format(string, " ADD:"); |
9e1fd49b | 1369 | } else if (ps.reason == OFPPR_DELETE) { |
064af421 | 1370 | ds_put_format(string, " DEL:"); |
9e1fd49b | 1371 | } else if (ps.reason == OFPPR_MODIFY) { |
064af421 BP |
1372 | ds_put_format(string, " MOD:"); |
1373 | } | |
1374 | ||
9e1fd49b | 1375 | ofp_print_phy_port(string, &ps.desc); |
064af421 BP |
1376 | } |
1377 | ||
1378 | static void | |
982697a4 | 1379 | ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1380 | { |
982697a4 BP |
1381 | const struct ofp_desc_stats *ods = ofpmsg_body(oh); |
1382 | ||
fbd76b2e | 1383 | ds_put_char(string, '\n'); |
d295e8e9 | 1384 | ds_put_format(string, "Manufacturer: %.*s\n", |
dd70b475 JP |
1385 | (int) sizeof ods->mfr_desc, ods->mfr_desc); |
1386 | ds_put_format(string, "Hardware: %.*s\n", | |
1387 | (int) sizeof ods->hw_desc, ods->hw_desc); | |
1388 | ds_put_format(string, "Software: %.*s\n", | |
1389 | (int) sizeof ods->sw_desc, ods->sw_desc); | |
1390 | ds_put_format(string, "Serial Num: %.*s\n", | |
1391 | (int) sizeof ods->serial_num, ods->serial_num); | |
1392 | ds_put_format(string, "DP Description: %.*s\n", | |
1393 | (int) sizeof ods->dp_desc, ods->dp_desc); | |
064af421 BP |
1394 | } |
1395 | ||
1396 | static void | |
982697a4 | 1397 | ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh) |
064af421 | 1398 | { |
81d1ea94 | 1399 | struct ofputil_flow_stats_request fsr; |
90bf1e07 | 1400 | enum ofperr error; |
064af421 | 1401 | |
982697a4 | 1402 | error = ofputil_decode_flow_stats_request(&fsr, oh); |
2af0c0ef BP |
1403 | if (error) { |
1404 | ofp_print_error(string, error); | |
1405 | return; | |
1406 | } | |
1407 | ||
1408 | if (fsr.table_id != 0xff) { | |
e896c2d4 | 1409 | ds_put_format(string, " table=%"PRIu8, fsr.table_id); |
064af421 BP |
1410 | } |
1411 | ||
7f05e7ab | 1412 | if (fsr.out_port != OFPP_ANY) { |
2af0c0ef | 1413 | ds_put_cstr(string, " out_port="); |
39dc9082 | 1414 | ofputil_format_port(fsr.out_port, string); |
2af0c0ef BP |
1415 | } |
1416 | ||
1417 | ds_put_char(string, ' '); | |
81a76618 | 1418 | match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY); |
064af421 BP |
1419 | } |
1420 | ||
bdcc5925 BP |
1421 | void |
1422 | ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs) | |
1423 | { | |
1424 | ds_put_format(string, " cookie=0x%"PRIx64", duration=", | |
1425 | ntohll(fs->cookie)); | |
1426 | ||
1427 | ofp_print_duration(string, fs->duration_sec, fs->duration_nsec); | |
1428 | ds_put_format(string, ", table=%"PRIu8", ", fs->table_id); | |
1429 | ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count); | |
1430 | ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count); | |
1431 | if (fs->idle_timeout != OFP_FLOW_PERMANENT) { | |
1432 | ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout); | |
1433 | } | |
1434 | if (fs->hard_timeout != OFP_FLOW_PERMANENT) { | |
1435 | ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout); | |
1436 | } | |
2e1ae200 JR |
1437 | if (fs->flags) { |
1438 | ofp_print_flow_flags(string, fs->flags); | |
1439 | } | |
bdcc5925 BP |
1440 | if (fs->idle_age >= 0) { |
1441 | ds_put_format(string, "idle_age=%d, ", fs->idle_age); | |
1442 | } | |
1443 | if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) { | |
1444 | ds_put_format(string, "hard_age=%d, ", fs->hard_age); | |
1445 | } | |
1446 | ||
81a76618 | 1447 | match_format(&fs->match, string, fs->priority); |
bdcc5925 BP |
1448 | if (string->string[string->length - 1] != ' ') { |
1449 | ds_put_char(string, ' '); | |
1450 | } | |
1451 | ||
455ecd77 | 1452 | ds_put_cstr(string, "actions="); |
bdcc5925 BP |
1453 | ofpacts_format(fs->ofpacts, fs->ofpacts_len, string); |
1454 | } | |
1455 | ||
064af421 | 1456 | static void |
4ffd1b43 | 1457 | ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1458 | { |
f25d0cf3 | 1459 | struct ofpbuf ofpacts; |
4ffd1b43 | 1460 | struct ofpbuf b; |
064af421 | 1461 | |
4ffd1b43 | 1462 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
f25d0cf3 | 1463 | ofpbuf_init(&ofpacts, 64); |
4ffd1b43 BP |
1464 | for (;;) { |
1465 | struct ofputil_flow_stats fs; | |
1466 | int retval; | |
fab8fadb | 1467 | |
f25d0cf3 | 1468 | retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts); |
4ffd1b43 BP |
1469 | if (retval) { |
1470 | if (retval != EOF) { | |
1471 | ds_put_cstr(string, " ***parse error***"); | |
064af421 BP |
1472 | } |
1473 | break; | |
1474 | } | |
8961de6a | 1475 | ds_put_char(string, '\n'); |
bdcc5925 BP |
1476 | ofp_print_flow_stats(string, &fs); |
1477 | } | |
cb80d803 | 1478 | ofpbuf_uninit(&ofpacts); |
c6430da5 BP |
1479 | } |
1480 | ||
064af421 | 1481 | static void |
982697a4 | 1482 | ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1483 | { |
982697a4 BP |
1484 | struct ofputil_aggregate_stats as; |
1485 | enum ofperr error; | |
064af421 | 1486 | |
982697a4 BP |
1487 | error = ofputil_decode_aggregate_stats_reply(&as, oh); |
1488 | if (error) { | |
1489 | ofp_print_error(string, error); | |
1490 | return; | |
1491 | } | |
1492 | ||
1493 | ds_put_format(string, " packet_count=%"PRIu64, as.packet_count); | |
1494 | ds_put_format(string, " byte_count=%"PRIu64, as.byte_count); | |
1495 | ds_put_format(string, " flow_count=%"PRIu32, as.flow_count); | |
a2ad9ecd BP |
1496 | } |
1497 | ||
f8e4867e SH |
1498 | static void |
1499 | print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more) | |
064af421 BP |
1500 | { |
1501 | ds_put_cstr(string, leader); | |
c4617b3c | 1502 | if (stat != UINT64_MAX) { |
064af421 BP |
1503 | ds_put_format(string, "%"PRIu64, stat); |
1504 | } else { | |
1505 | ds_put_char(string, '?'); | |
1506 | } | |
1507 | if (more) { | |
1508 | ds_put_cstr(string, ", "); | |
1509 | } else { | |
1510 | ds_put_cstr(string, "\n"); | |
1511 | } | |
1512 | } | |
1513 | ||
abaad8cf | 1514 | static void |
982697a4 | 1515 | ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh) |
abaad8cf | 1516 | { |
4e022ec0 | 1517 | ofp_port_t ofp10_port; |
f8e4867e SH |
1518 | enum ofperr error; |
1519 | ||
1520 | error = ofputil_decode_port_stats_request(oh, &ofp10_port); | |
1521 | if (error) { | |
1522 | ofp_print_error(string, error); | |
1523 | return; | |
1524 | } | |
1525 | ||
e1db42d6 JR |
1526 | ds_put_cstr(string, " port_no="); |
1527 | ofputil_format_port(ofp10_port, string); | |
abaad8cf JP |
1528 | } |
1529 | ||
064af421 | 1530 | static void |
d1e2cf21 BP |
1531 | ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh, |
1532 | int verbosity) | |
064af421 | 1533 | { |
982697a4 | 1534 | struct ofpbuf b; |
982697a4 | 1535 | |
34582733 | 1536 | ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh)); |
064af421 BP |
1537 | if (verbosity < 1) { |
1538 | return; | |
1539 | } | |
1540 | ||
f8e4867e | 1541 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
982697a4 | 1542 | for (;;) { |
f8e4867e SH |
1543 | struct ofputil_port_stats ps; |
1544 | int retval; | |
1545 | ||
1546 | retval = ofputil_decode_port_stats(&ps, &b); | |
1547 | if (retval) { | |
1548 | if (retval != EOF) { | |
1549 | ds_put_cstr(string, " ***parse error***"); | |
1550 | } | |
982697a4 BP |
1551 | return; |
1552 | } | |
1553 | ||
e1db42d6 | 1554 | ds_put_cstr(string, " port "); |
4e022ec0 | 1555 | if (ofp_to_u16(ps.port_no) < 10) { |
e1db42d6 JR |
1556 | ds_put_char(string, ' '); |
1557 | } | |
1558 | ofputil_format_port(ps.port_no, string); | |
064af421 | 1559 | |
f8e4867e SH |
1560 | ds_put_cstr(string, ": rx "); |
1561 | print_port_stat(string, "pkts=", ps.stats.rx_packets, 1); | |
1562 | print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1); | |
1563 | print_port_stat(string, "drop=", ps.stats.rx_dropped, 1); | |
1564 | print_port_stat(string, "errs=", ps.stats.rx_errors, 1); | |
1565 | print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1); | |
1566 | print_port_stat(string, "over=", ps.stats.rx_over_errors, 1); | |
1567 | print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0); | |
064af421 BP |
1568 | |
1569 | ds_put_cstr(string, " tx "); | |
f8e4867e SH |
1570 | print_port_stat(string, "pkts=", ps.stats.tx_packets, 1); |
1571 | print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1); | |
1572 | print_port_stat(string, "drop=", ps.stats.tx_dropped, 1); | |
1573 | print_port_stat(string, "errs=", ps.stats.tx_errors, 1); | |
1574 | print_port_stat(string, "coll=", ps.stats.collisions, 0); | |
65e0be10 BP |
1575 | |
1576 | if (ps.duration_sec != UINT32_MAX) { | |
1577 | ds_put_cstr(string, " duration="); | |
1578 | ofp_print_duration(string, ps.duration_sec, ps.duration_nsec); | |
1579 | ds_put_char(string, '\n'); | |
1580 | } | |
064af421 BP |
1581 | } |
1582 | } | |
1583 | ||
1584 | static void | |
26df8b3e SH |
1585 | ofp_print_one_ofpst_table_reply(struct ds *string, enum ofp_version ofp_version, |
1586 | const char *name, struct ofp12_table_stats *ts) | |
1587 | { | |
1588 | char name_[OFP_MAX_TABLE_NAME_LEN + 1]; | |
1589 | ||
2e1ae200 JR |
1590 | /* ofp13_table_stats is different */ |
1591 | if (ofp_version > OFP12_VERSION) { | |
1592 | return; | |
1593 | } | |
1594 | ||
26df8b3e SH |
1595 | ovs_strlcpy(name_, name, sizeof name_); |
1596 | ||
1597 | ds_put_format(string, " %d: %-8s: ", ts->table_id, name_); | |
1598 | ds_put_format(string, "wild=0x%05"PRIx64", ", ntohll(ts->wildcards)); | |
1599 | ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries)); | |
1600 | ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count)); | |
1601 | ds_put_cstr(string, " "); | |
1602 | ds_put_format(string, "lookup=%"PRIu64", ", ntohll(ts->lookup_count)); | |
1603 | ds_put_format(string, "matched=%"PRIu64"\n", ntohll(ts->matched_count)); | |
1604 | ||
1605 | if (ofp_version < OFP11_VERSION) { | |
1606 | return; | |
1607 | } | |
1608 | ||
1609 | ds_put_cstr(string, " "); | |
1610 | ds_put_format(string, "match=0x%08"PRIx64", ", ntohll(ts->match)); | |
1611 | ds_put_format(string, "instructions=0x%08"PRIx32", ", | |
1612 | ntohl(ts->instructions)); | |
1613 | ds_put_format(string, "config=0x%08"PRIx32"\n", ntohl(ts->config)); | |
1614 | ds_put_cstr(string, " "); | |
1615 | ds_put_format(string, "write_actions=0x%08"PRIx32", ", | |
1616 | ntohl(ts->write_actions)); | |
1617 | ds_put_format(string, "apply_actions=0x%08"PRIx32"\n", | |
1618 | ntohl(ts->apply_actions)); | |
1619 | ||
1620 | if (ofp_version < OFP12_VERSION) { | |
1621 | return; | |
1622 | } | |
1623 | ||
1624 | ds_put_cstr(string, " "); | |
1625 | ds_put_format(string, "write_setfields=0x%016"PRIx64"\n", | |
1626 | ntohll(ts->write_setfields)); | |
1627 | ds_put_cstr(string, " "); | |
1628 | ds_put_format(string, "apply_setfields=0x%016"PRIx64"\n", | |
1629 | ntohll(ts->apply_setfields)); | |
1630 | ds_put_cstr(string, " "); | |
1631 | ds_put_format(string, "metadata_match=0x%016"PRIx64"\n", | |
1632 | ntohll(ts->metadata_match)); | |
1633 | ds_put_cstr(string, " "); | |
1634 | ds_put_format(string, "metadata_write=0x%016"PRIx64"\n", | |
1635 | ntohll(ts->metadata_write)); | |
1636 | } | |
1637 | ||
2e1ae200 JR |
1638 | static void |
1639 | ofp_print_ofpst_table_reply13(struct ds *string, const struct ofp_header *oh, | |
1640 | int verbosity) | |
1641 | { | |
1642 | struct ofp13_table_stats *ts; | |
1643 | struct ofpbuf b; | |
1644 | size_t n; | |
1645 | ||
1646 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1647 | ofpraw_pull_assert(&b); | |
1648 | ||
1649 | n = b.size / sizeof *ts; | |
34582733 | 1650 | ds_put_format(string, " %"PRIuSIZE" tables\n", n); |
2e1ae200 JR |
1651 | if (verbosity < 1) { |
1652 | return; | |
1653 | } | |
1654 | ||
1655 | for (;;) { | |
1656 | ts = ofpbuf_try_pull(&b, sizeof *ts); | |
1657 | if (!ts) { | |
1658 | return; | |
1659 | } | |
1660 | ds_put_format(string, | |
1661 | " %d: active=%"PRIu32", lookup=%"PRIu64 \ | |
1662 | ", matched=%"PRIu64"\n", | |
1663 | ts->table_id, ntohl(ts->active_count), | |
1664 | ntohll(ts->lookup_count), ntohll(ts->matched_count)); | |
1665 | } | |
1666 | } | |
1667 | ||
26df8b3e SH |
1668 | static void |
1669 | ofp_print_ofpst_table_reply12(struct ds *string, const struct ofp_header *oh, | |
1670 | int verbosity) | |
1671 | { | |
1672 | struct ofp12_table_stats *ts; | |
1673 | struct ofpbuf b; | |
1674 | size_t n; | |
1675 | ||
1676 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1677 | ofpraw_pull_assert(&b); | |
1678 | ||
1679 | n = b.size / sizeof *ts; | |
34582733 | 1680 | ds_put_format(string, " %"PRIuSIZE" tables\n", n); |
26df8b3e SH |
1681 | if (verbosity < 1) { |
1682 | return; | |
1683 | } | |
1684 | ||
1685 | for (;;) { | |
1686 | ts = ofpbuf_try_pull(&b, sizeof *ts); | |
1687 | if (!ts) { | |
1688 | return; | |
1689 | } | |
1690 | ||
1691 | ofp_print_one_ofpst_table_reply(string, OFP12_VERSION, ts->name, ts); | |
1692 | } | |
1693 | } | |
1694 | ||
1695 | static void | |
1696 | ofp_print_ofpst_table_reply11(struct ds *string, const struct ofp_header *oh, | |
1697 | int verbosity) | |
1698 | { | |
1699 | struct ofp11_table_stats *ts; | |
1700 | struct ofpbuf b; | |
1701 | size_t n; | |
1702 | ||
1703 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1704 | ofpraw_pull_assert(&b); | |
1705 | ||
1706 | n = b.size / sizeof *ts; | |
34582733 | 1707 | ds_put_format(string, " %"PRIuSIZE" tables\n", n); |
26df8b3e SH |
1708 | if (verbosity < 1) { |
1709 | return; | |
1710 | } | |
1711 | ||
1712 | for (;;) { | |
1713 | struct ofp12_table_stats ts12; | |
1714 | ||
1715 | ts = ofpbuf_try_pull(&b, sizeof *ts); | |
1716 | if (!ts) { | |
1717 | return; | |
1718 | } | |
1719 | ||
1720 | ts12.table_id = ts->table_id; | |
1721 | ts12.wildcards = htonll(ntohl(ts->wildcards)); | |
1722 | ts12.max_entries = ts->max_entries; | |
1723 | ts12.active_count = ts->active_count; | |
1724 | ts12.lookup_count = ts->lookup_count; | |
1725 | ts12.matched_count = ts->matched_count; | |
1726 | ts12.match = htonll(ntohl(ts->match)); | |
1727 | ts12.instructions = ts->instructions; | |
1728 | ts12.config = ts->config; | |
1729 | ts12.write_actions = ts->write_actions; | |
1730 | ts12.apply_actions = ts->apply_actions; | |
1731 | ofp_print_one_ofpst_table_reply(string, OFP11_VERSION, ts->name, &ts12); | |
1732 | } | |
1733 | } | |
1734 | ||
1735 | static void | |
1736 | ofp_print_ofpst_table_reply10(struct ds *string, const struct ofp_header *oh, | |
1737 | int verbosity) | |
064af421 | 1738 | { |
e2b9ac44 | 1739 | struct ofp10_table_stats *ts; |
982697a4 BP |
1740 | struct ofpbuf b; |
1741 | size_t n; | |
1742 | ||
1743 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
1744 | ofpraw_pull_assert(&b); | |
1745 | ||
1746 | n = b.size / sizeof *ts; | |
34582733 | 1747 | ds_put_format(string, " %"PRIuSIZE" tables\n", n); |
064af421 BP |
1748 | if (verbosity < 1) { |
1749 | return; | |
1750 | } | |
1751 | ||
982697a4 | 1752 | for (;;) { |
26df8b3e | 1753 | struct ofp12_table_stats ts12; |
982697a4 BP |
1754 | |
1755 | ts = ofpbuf_try_pull(&b, sizeof *ts); | |
1756 | if (!ts) { | |
1757 | return; | |
1758 | } | |
1759 | ||
26df8b3e SH |
1760 | ts12.table_id = ts->table_id; |
1761 | ts12.wildcards = htonll(ntohl(ts->wildcards)); | |
1762 | ts12.max_entries = ts->max_entries; | |
1763 | ts12.active_count = ts->active_count; | |
1764 | ts12.lookup_count = get_32aligned_be64(&ts->lookup_count); | |
1765 | ts12.matched_count = get_32aligned_be64(&ts->matched_count); | |
1766 | ofp_print_one_ofpst_table_reply(string, OFP10_VERSION, ts->name, &ts12); | |
064af421 BP |
1767 | } |
1768 | } | |
1769 | ||
26df8b3e SH |
1770 | static void |
1771 | ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh, | |
1772 | int verbosity) | |
1773 | { | |
1774 | switch ((enum ofp_version)oh->version) { | |
2e1ae200 JR |
1775 | case OFP13_VERSION: |
1776 | ofp_print_ofpst_table_reply13(string, oh, verbosity); | |
1777 | break; | |
1778 | ||
26df8b3e SH |
1779 | case OFP12_VERSION: |
1780 | ofp_print_ofpst_table_reply12(string, oh, verbosity); | |
1781 | break; | |
1782 | ||
1783 | case OFP11_VERSION: | |
1784 | ofp_print_ofpst_table_reply11(string, oh, verbosity); | |
1785 | break; | |
1786 | ||
1787 | case OFP10_VERSION: | |
1788 | ofp_print_ofpst_table_reply10(string, oh, verbosity); | |
1789 | break; | |
1790 | ||
1791 | default: | |
1792 | NOT_REACHED(); | |
1793 | } | |
1794 | } | |
1795 | ||
d2805da2 BP |
1796 | static void |
1797 | ofp_print_queue_name(struct ds *string, uint32_t queue_id) | |
1798 | { | |
1799 | if (queue_id == OFPQ_ALL) { | |
1800 | ds_put_cstr(string, "ALL"); | |
1801 | } else { | |
1802 | ds_put_format(string, "%"PRIu32, queue_id); | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | static void | |
982697a4 | 1807 | ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh) |
d2805da2 | 1808 | { |
64626975 SH |
1809 | struct ofputil_queue_stats_request oqsr; |
1810 | enum ofperr error; | |
1811 | ||
1812 | error = ofputil_decode_queue_stats_request(oh, &oqsr); | |
1813 | if (error) { | |
1814 | ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error)); | |
1815 | return; | |
1816 | } | |
982697a4 | 1817 | |
d2805da2 | 1818 | ds_put_cstr(string, "port="); |
64626975 | 1819 | ofputil_format_port(oqsr.port_no, string); |
d2805da2 BP |
1820 | |
1821 | ds_put_cstr(string, " queue="); | |
64626975 | 1822 | ofp_print_queue_name(string, oqsr.queue_id); |
f8e4867e SH |
1823 | } |
1824 | ||
d2805da2 | 1825 | static void |
d1e2cf21 BP |
1826 | ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh, |
1827 | int verbosity) | |
d2805da2 | 1828 | { |
982697a4 | 1829 | struct ofpbuf b; |
982697a4 | 1830 | |
34582733 | 1831 | ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh)); |
d2805da2 BP |
1832 | if (verbosity < 1) { |
1833 | return; | |
1834 | } | |
1835 | ||
64626975 | 1836 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); |
982697a4 | 1837 | for (;;) { |
64626975 SH |
1838 | struct ofputil_queue_stats qs; |
1839 | int retval; | |
1840 | ||
1841 | retval = ofputil_decode_queue_stats(&qs, &b); | |
1842 | if (retval) { | |
1843 | if (retval != EOF) { | |
1844 | ds_put_cstr(string, " ***parse error***"); | |
1845 | } | |
982697a4 BP |
1846 | return; |
1847 | } | |
1848 | ||
d2805da2 | 1849 | ds_put_cstr(string, " port "); |
64626975 | 1850 | ofputil_format_port(qs.port_no, string); |
d2805da2 | 1851 | ds_put_cstr(string, " queue "); |
64626975 | 1852 | ofp_print_queue_name(string, qs.queue_id); |
d2805da2 BP |
1853 | ds_put_cstr(string, ": "); |
1854 | ||
6dc34a0d BP |
1855 | print_port_stat(string, "bytes=", qs.tx_bytes, 1); |
1856 | print_port_stat(string, "pkts=", qs.tx_packets, 1); | |
1857 | print_port_stat(string, "errors=", qs.tx_errors, 1); | |
1858 | ||
1859 | ds_put_cstr(string, "duration="); | |
1860 | if (qs.duration_sec != UINT32_MAX) { | |
1861 | ofp_print_duration(string, qs.duration_sec, qs.duration_nsec); | |
1862 | } else { | |
1863 | ds_put_char(string, '?'); | |
1864 | } | |
1865 | ds_put_char(string, '\n'); | |
d2805da2 BP |
1866 | } |
1867 | } | |
1868 | ||
2be393ed JP |
1869 | static void |
1870 | ofp_print_ofpst_port_desc_reply(struct ds *string, | |
1871 | const struct ofp_header *oh) | |
1872 | { | |
1873 | struct ofpbuf b; | |
1874 | ||
1875 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
982697a4 | 1876 | ofpraw_pull_assert(&b); |
2be393ed JP |
1877 | ds_put_char(string, '\n'); |
1878 | ofp_print_phy_ports(string, oh->version, &b); | |
1879 | } | |
1880 | ||
064af421 | 1881 | static void |
d1e2cf21 | 1882 | ofp_print_stats_request(struct ds *string, const struct ofp_header *oh) |
064af421 | 1883 | { |
982697a4 | 1884 | uint16_t flags = ofpmp_flags(oh); |
064af421 | 1885 | |
982697a4 BP |
1886 | if (flags) { |
1887 | ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags); | |
064af421 | 1888 | } |
064af421 BP |
1889 | } |
1890 | ||
1891 | static void | |
d1e2cf21 | 1892 | ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh) |
064af421 | 1893 | { |
982697a4 | 1894 | uint16_t flags = ofpmp_flags(oh); |
d1e2cf21 | 1895 | |
982697a4 | 1896 | if (flags) { |
d1e2cf21 | 1897 | ds_put_cstr(string, " flags="); |
064af421 BP |
1898 | if (flags & OFPSF_REPLY_MORE) { |
1899 | ds_put_cstr(string, "[more]"); | |
1900 | flags &= ~OFPSF_REPLY_MORE; | |
1901 | } | |
1902 | if (flags) { | |
d1e2cf21 BP |
1903 | ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]", |
1904 | flags); | |
064af421 BP |
1905 | } |
1906 | } | |
064af421 BP |
1907 | } |
1908 | ||
1909 | static void | |
d1e2cf21 | 1910 | ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity) |
064af421 | 1911 | { |
d1e2cf21 | 1912 | size_t len = ntohs(oh->length); |
064af421 | 1913 | |
34582733 | 1914 | ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh); |
064af421 | 1915 | if (verbosity > 1) { |
d1e2cf21 | 1916 | ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true); |
064af421 BP |
1917 | } |
1918 | } | |
1919 | ||
61fe3a7b | 1920 | static void |
00467f73 AC |
1921 | ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role, |
1922 | uint64_t generation_id) | |
61fe3a7b | 1923 | { |
61fe3a7b | 1924 | ds_put_cstr(string, " role="); |
6ea4776b | 1925 | |
00467f73 | 1926 | switch (role) { |
f4f1ea7e BP |
1927 | case OFPCR12_ROLE_NOCHANGE: |
1928 | ds_put_cstr(string, "nochange"); | |
1929 | break; | |
1930 | case OFPCR12_ROLE_EQUAL: | |
6ea4776b JR |
1931 | ds_put_cstr(string, "equal"); /* OF 1.2 wording */ |
1932 | break; | |
f4f1ea7e | 1933 | case OFPCR12_ROLE_MASTER: |
61fe3a7b | 1934 | ds_put_cstr(string, "master"); |
6ea4776b | 1935 | break; |
f4f1ea7e | 1936 | case OFPCR12_ROLE_SLAVE: |
61fe3a7b | 1937 | ds_put_cstr(string, "slave"); |
6ea4776b JR |
1938 | break; |
1939 | default: | |
1940 | NOT_REACHED(); | |
1941 | } | |
1942 | ||
00467f73 AC |
1943 | if (generation_id != UINT64_MAX) { |
1944 | ds_put_format(string, " generation_id=%"PRIu64, generation_id); | |
1945 | } | |
1946 | } | |
1947 | ||
1948 | static void | |
1949 | ofp_print_role_message(struct ds *string, const struct ofp_header *oh) | |
1950 | { | |
1951 | struct ofputil_role_request rr; | |
1952 | enum ofperr error; | |
1953 | ||
1954 | error = ofputil_decode_role_message(oh, &rr); | |
1955 | if (error) { | |
1956 | ofp_print_error(string, error); | |
1957 | return; | |
1958 | } | |
1959 | ||
1960 | ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX); | |
1961 | } | |
1962 | ||
1963 | static void | |
1964 | ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh) | |
1965 | { | |
1966 | struct ofputil_role_status rs; | |
1967 | enum ofperr error; | |
1968 | ||
1969 | error = ofputil_decode_role_status(oh, &rs); | |
1970 | if (error) { | |
1971 | ofp_print_error(string, error); | |
1972 | return; | |
1973 | } | |
1974 | ||
1975 | ofp_print_role_generic(string, rs.role, rs.generation_id); | |
1976 | ||
1977 | ds_put_cstr(string, " reason="); | |
1978 | ||
1979 | switch (rs.reason) { | |
1980 | case OFPCRR_MASTER_REQUEST: | |
1981 | ds_put_cstr(string, "master_request"); | |
1982 | break; | |
1983 | case OFPCRR_CONFIG: | |
1984 | ds_put_cstr(string, "configuration_changed"); | |
1985 | break; | |
1986 | case OFPCRR_EXPERIMENTER: | |
1987 | ds_put_cstr(string, "experimenter_data_changed"); | |
1988 | break; | |
1989 | default: | |
1990 | NOT_REACHED(); | |
61fe3a7b BP |
1991 | } |
1992 | } | |
1993 | ||
6c1491fb BP |
1994 | static void |
1995 | ofp_print_nxt_flow_mod_table_id(struct ds *string, | |
73dbf4ab | 1996 | const struct nx_flow_mod_table_id *nfmti) |
6c1491fb BP |
1997 | { |
1998 | ds_put_format(string, " %s", nfmti->set ? "enable" : "disable"); | |
1999 | } | |
2000 | ||
7fa91113 BP |
2001 | static void |
2002 | ofp_print_nxt_set_flow_format(struct ds *string, | |
73dbf4ab | 2003 | const struct nx_set_flow_format *nsff) |
7fa91113 BP |
2004 | { |
2005 | uint32_t format = ntohl(nsff->format); | |
2006 | ||
2007 | ds_put_cstr(string, " format="); | |
27527aa0 BP |
2008 | if (ofputil_nx_flow_format_is_valid(format)) { |
2009 | ds_put_cstr(string, ofputil_nx_flow_format_to_string(format)); | |
7fa91113 BP |
2010 | } else { |
2011 | ds_put_format(string, "%"PRIu32, format); | |
2012 | } | |
2013 | } | |
2014 | ||
54834960 EJ |
2015 | static void |
2016 | ofp_print_nxt_set_packet_in_format(struct ds *string, | |
73dbf4ab | 2017 | const struct nx_set_packet_in_format *nspf) |
54834960 EJ |
2018 | { |
2019 | uint32_t format = ntohl(nspf->format); | |
2020 | ||
2021 | ds_put_cstr(string, " format="); | |
2022 | if (ofputil_packet_in_format_is_valid(format)) { | |
2023 | ds_put_cstr(string, ofputil_packet_in_format_to_string(format)); | |
2024 | } else { | |
2025 | ds_put_format(string, "%"PRIu32, format); | |
2026 | } | |
2027 | } | |
2028 | ||
8961699e BP |
2029 | /* Returns a string form of 'reason'. The return value is either a statically |
2030 | * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'. | |
2031 | * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */ | |
2032 | #define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1) | |
80d5aefd | 2033 | static const char * |
8961699e BP |
2034 | ofp_port_reason_to_string(enum ofp_port_reason reason, |
2035 | char *reasonbuf, size_t bufsize) | |
80d5aefd | 2036 | { |
80d5aefd BP |
2037 | switch (reason) { |
2038 | case OFPPR_ADD: | |
2039 | return "add"; | |
2040 | ||
2041 | case OFPPR_DELETE: | |
2042 | return "delete"; | |
2043 | ||
2044 | case OFPPR_MODIFY: | |
2045 | return "modify"; | |
2046 | ||
2047 | default: | |
8961699e BP |
2048 | snprintf(reasonbuf, bufsize, "%d", (int) reason); |
2049 | return reasonbuf; | |
80d5aefd BP |
2050 | } |
2051 | } | |
2052 | ||
2053 | static void | |
2054 | ofp_print_nxt_set_async_config(struct ds *string, | |
2055 | const struct nx_async_config *nac) | |
2056 | { | |
2057 | int i; | |
2058 | ||
2059 | for (i = 0; i < 2; i++) { | |
2060 | int j; | |
2061 | ||
2062 | ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave"); | |
2063 | ||
2064 | ds_put_cstr(string, " PACKET_IN:"); | |
2065 | for (j = 0; j < 32; j++) { | |
2066 | if (nac->packet_in_mask[i] & htonl(1u << j)) { | |
5014a89d BP |
2067 | char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE]; |
2068 | const char *reason; | |
2069 | ||
2070 | reason = ofputil_packet_in_reason_to_string(j, reasonbuf, | |
2071 | sizeof reasonbuf); | |
2072 | ds_put_format(string, " %s", reason); | |
80d5aefd BP |
2073 | } |
2074 | } | |
2075 | if (!nac->packet_in_mask[i]) { | |
2076 | ds_put_cstr(string, " (off)"); | |
2077 | } | |
2078 | ds_put_char(string, '\n'); | |
2079 | ||
2080 | ds_put_cstr(string, " PORT_STATUS:"); | |
2081 | for (j = 0; j < 32; j++) { | |
2082 | if (nac->port_status_mask[i] & htonl(1u << j)) { | |
8961699e BP |
2083 | char reasonbuf[OFP_PORT_REASON_BUFSIZE]; |
2084 | const char *reason; | |
2085 | ||
2086 | reason = ofp_port_reason_to_string(j, reasonbuf, | |
2087 | sizeof reasonbuf); | |
2088 | ds_put_format(string, " %s", reason); | |
80d5aefd BP |
2089 | } |
2090 | } | |
2091 | if (!nac->port_status_mask[i]) { | |
2092 | ds_put_cstr(string, " (off)"); | |
2093 | } | |
2094 | ds_put_char(string, '\n'); | |
2095 | ||
2096 | ds_put_cstr(string, " FLOW_REMOVED:"); | |
2097 | for (j = 0; j < 32; j++) { | |
2098 | if (nac->flow_removed_mask[i] & htonl(1u << j)) { | |
8961699e BP |
2099 | char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE]; |
2100 | const char *reason; | |
2101 | ||
2102 | reason = ofp_flow_removed_reason_to_string(j, reasonbuf, | |
2103 | sizeof reasonbuf); | |
2104 | ds_put_format(string, " %s", reason); | |
80d5aefd BP |
2105 | } |
2106 | } | |
2107 | if (!nac->flow_removed_mask[i]) { | |
2108 | ds_put_cstr(string, " (off)"); | |
2109 | } | |
2110 | ds_put_char(string, '\n'); | |
2111 | } | |
2112 | } | |
2113 | ||
a7349929 BP |
2114 | static void |
2115 | ofp_print_nxt_set_controller_id(struct ds *string, | |
2116 | const struct nx_controller_id *nci) | |
2117 | { | |
2118 | ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id)); | |
2119 | } | |
2120 | ||
2b07c8b1 BP |
2121 | static void |
2122 | ofp_print_nxt_flow_monitor_cancel(struct ds *string, | |
2123 | const struct ofp_header *oh) | |
2124 | { | |
2125 | ds_put_format(string, " id=%"PRIu32, | |
2126 | ofputil_decode_flow_monitor_cancel(oh)); | |
2127 | } | |
2128 | ||
2129 | static const char * | |
2130 | nx_flow_monitor_flags_to_name(uint32_t bit) | |
2131 | { | |
2132 | enum nx_flow_monitor_flags fmf = bit; | |
2133 | ||
2134 | switch (fmf) { | |
2135 | case NXFMF_INITIAL: return "initial"; | |
2136 | case NXFMF_ADD: return "add"; | |
2137 | case NXFMF_DELETE: return "delete"; | |
2138 | case NXFMF_MODIFY: return "modify"; | |
2139 | case NXFMF_ACTIONS: return "actions"; | |
2140 | case NXFMF_OWN: return "own"; | |
2141 | } | |
2142 | ||
2143 | return NULL; | |
2144 | } | |
2145 | ||
2146 | static void | |
2147 | ofp_print_nxst_flow_monitor_request(struct ds *string, | |
2148 | const struct ofp_header *oh) | |
2149 | { | |
2150 | struct ofpbuf b; | |
2151 | ||
2152 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2153 | for (;;) { | |
2154 | struct ofputil_flow_monitor_request request; | |
2155 | int retval; | |
2156 | ||
2157 | retval = ofputil_decode_flow_monitor_request(&request, &b); | |
2158 | if (retval) { | |
2159 | if (retval != EOF) { | |
2160 | ofp_print_error(string, retval); | |
2161 | } | |
2162 | return; | |
2163 | } | |
2164 | ||
2165 | ds_put_format(string, "\n id=%"PRIu32" flags=", request.id); | |
2166 | ofp_print_bit_names(string, request.flags, | |
2167 | nx_flow_monitor_flags_to_name, ','); | |
2168 | ||
2169 | if (request.out_port != OFPP_NONE) { | |
2170 | ds_put_cstr(string, " out_port="); | |
2171 | ofputil_format_port(request.out_port, string); | |
2172 | } | |
2173 | ||
2174 | if (request.table_id != 0xff) { | |
2175 | ds_put_format(string, " table=%"PRIu8, request.table_id); | |
2176 | } | |
2177 | ||
2178 | ds_put_char(string, ' '); | |
81a76618 | 2179 | match_format(&request.match, string, OFP_DEFAULT_PRIORITY); |
2b07c8b1 BP |
2180 | ds_chomp(string, ' '); |
2181 | } | |
2182 | } | |
2183 | ||
2184 | static void | |
2185 | ofp_print_nxst_flow_monitor_reply(struct ds *string, | |
2186 | const struct ofp_header *oh) | |
2187 | { | |
2188 | uint64_t ofpacts_stub[1024 / 8]; | |
2189 | struct ofpbuf ofpacts; | |
2190 | struct ofpbuf b; | |
2191 | ||
2192 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2193 | ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub); | |
2194 | for (;;) { | |
8961699e | 2195 | char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE]; |
2b07c8b1 | 2196 | struct ofputil_flow_update update; |
81a76618 | 2197 | struct match match; |
2b07c8b1 BP |
2198 | int retval; |
2199 | ||
2200 | update.match = &match; | |
2201 | retval = ofputil_decode_flow_update(&update, &b, &ofpacts); | |
2202 | if (retval) { | |
2203 | if (retval != EOF) { | |
2204 | ofp_print_error(string, retval); | |
2205 | } | |
2206 | ofpbuf_uninit(&ofpacts); | |
2207 | return; | |
2208 | } | |
2209 | ||
2210 | ds_put_cstr(string, "\n event="); | |
2211 | switch (update.event) { | |
2212 | case NXFME_ADDED: | |
2213 | ds_put_cstr(string, "ADDED"); | |
2214 | break; | |
2215 | ||
2216 | case NXFME_DELETED: | |
2217 | ds_put_format(string, "DELETED reason=%s", | |
8961699e BP |
2218 | ofp_flow_removed_reason_to_string(update.reason, |
2219 | reasonbuf, | |
2220 | sizeof reasonbuf)); | |
2b07c8b1 BP |
2221 | break; |
2222 | ||
2223 | case NXFME_MODIFIED: | |
2224 | ds_put_cstr(string, "MODIFIED"); | |
2225 | break; | |
2226 | ||
2227 | case NXFME_ABBREV: | |
2228 | ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid)); | |
2229 | continue; | |
2230 | } | |
2231 | ||
2232 | ds_put_format(string, " table=%"PRIu8, update.table_id); | |
2233 | if (update.idle_timeout != OFP_FLOW_PERMANENT) { | |
2234 | ds_put_format(string, " idle_timeout=%"PRIu16, | |
2235 | update.idle_timeout); | |
2236 | } | |
2237 | if (update.hard_timeout != OFP_FLOW_PERMANENT) { | |
2238 | ds_put_format(string, " hard_timeout=%"PRIu16, | |
2239 | update.hard_timeout); | |
2240 | } | |
2241 | ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie)); | |
2242 | ||
2243 | ds_put_char(string, ' '); | |
81a76618 | 2244 | match_format(update.match, string, OFP_DEFAULT_PRIORITY); |
2b07c8b1 BP |
2245 | |
2246 | if (update.ofpacts_len) { | |
2247 | if (string->string[string->length - 1] != ' ') { | |
2248 | ds_put_char(string, ' '); | |
2249 | } | |
455ecd77 | 2250 | ds_put_cstr(string, "actions="); |
2b07c8b1 BP |
2251 | ofpacts_format(update.ofpacts, update.ofpacts_len, string); |
2252 | } | |
2253 | } | |
2254 | } | |
2255 | ||
bdcc5925 BP |
2256 | void |
2257 | ofp_print_version(const struct ofp_header *oh, | |
2258 | struct ds *string) | |
d1e2cf21 | 2259 | { |
3811e66b BP |
2260 | switch (oh->version) { |
2261 | case OFP10_VERSION: | |
2262 | break; | |
2263 | case OFP11_VERSION: | |
2264 | ds_put_cstr(string, " (OF1.1)"); | |
4232ef77 SH |
2265 | break; |
2266 | case OFP12_VERSION: | |
2267 | ds_put_cstr(string, " (OF1.2)"); | |
3811e66b | 2268 | break; |
2e1ae200 JR |
2269 | case OFP13_VERSION: |
2270 | ds_put_cstr(string, " (OF1.3)"); | |
2271 | break; | |
3811e66b BP |
2272 | default: |
2273 | ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version); | |
2274 | break; | |
2275 | } | |
2276 | ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid)); | |
bdcc5925 | 2277 | } |
d1e2cf21 | 2278 | |
f25b4a81 | 2279 | static void |
982697a4 BP |
2280 | ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw, |
2281 | struct ds *string) | |
f25b4a81 | 2282 | { |
982697a4 | 2283 | ds_put_cstr(string, ofpraw_get_name(raw)); |
f25b4a81 BP |
2284 | ofp_print_version(oh, string); |
2285 | } | |
2286 | ||
2e1ae200 JR |
2287 | static void |
2288 | ofp_print_not_implemented(struct ds *string) | |
2289 | { | |
2290 | ds_put_cstr(string, "NOT IMPLEMENTED YET!\n"); | |
2291 | } | |
2292 | ||
7395c052 NZ |
2293 | static void |
2294 | ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type, | |
2295 | struct list *p_buckets) | |
2296 | { | |
2297 | static const char *type_str[] = { "all", "select", "indirect", | |
2298 | "ff", "unknown" }; | |
2299 | struct ofputil_bucket *bucket; | |
2300 | ||
2301 | ds_put_format(s, "group_id=%"PRIu32",type=%s", | |
2302 | group_id, type_str[type > 4 ? 4 : type]); | |
2303 | if (!p_buckets) { | |
2304 | return; | |
2305 | } | |
2306 | ||
2307 | LIST_FOR_EACH (bucket, list_node, p_buckets) { | |
2308 | ds_put_cstr(s, ",bucket="); | |
2309 | ||
2310 | if (bucket->weight != 1) { | |
2311 | ds_put_format(s, "weight:%"PRIu16",", bucket->weight); | |
2312 | } | |
2313 | if (bucket->watch_port != OFPP_NONE) { | |
2314 | ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port); | |
2315 | } | |
2316 | if (bucket->watch_group != OFPG11_ANY) { | |
2317 | ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group); | |
2318 | } | |
2319 | ||
455ecd77 | 2320 | ds_put_cstr(s, "actions="); |
7395c052 NZ |
2321 | ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s); |
2322 | } | |
2323 | } | |
2324 | ||
2325 | static void | |
2326 | ofp_print_group_desc(struct ds *s, const struct ofp_header *oh) | |
2327 | { | |
2328 | struct ofpbuf b; | |
2329 | ||
2330 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2331 | for (;;) { | |
2332 | struct ofputil_group_desc gd; | |
2333 | int retval; | |
2334 | ||
a7a2d006 | 2335 | retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version); |
7395c052 NZ |
2336 | if (retval) { |
2337 | if (retval != EOF) { | |
2338 | ds_put_cstr(s, " ***parse error***"); | |
2339 | } | |
2340 | break; | |
2341 | } | |
2342 | ||
2343 | ds_put_char(s, '\n'); | |
2344 | ds_put_char(s, ' '); | |
2345 | ofp_print_group(s, gd.group_id, gd.type, &gd.buckets); | |
2346 | } | |
2347 | } | |
2348 | ||
2349 | static void | |
2350 | ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh) | |
2351 | { | |
2352 | enum ofperr error; | |
2353 | uint32_t group_id; | |
2354 | ||
2355 | error = ofputil_decode_group_stats_request(oh, &group_id); | |
2356 | if (error) { | |
2357 | ofp_print_error(string, error); | |
2358 | return; | |
2359 | } | |
2360 | ||
2361 | ds_put_cstr(string, " group_id="); | |
2362 | ofputil_format_group(group_id, string); | |
2363 | } | |
2364 | ||
2365 | static void | |
2366 | ofp_print_group_stats(struct ds *s, const struct ofp_header *oh) | |
2367 | { | |
2368 | struct ofpbuf b; | |
2369 | uint32_t bucket_i; | |
2370 | ||
2371 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
2372 | ||
2373 | for (;;) { | |
2374 | struct ofputil_group_stats gs; | |
2375 | int retval; | |
2376 | ||
2377 | retval = ofputil_decode_group_stats_reply(&b, &gs); | |
2378 | if (retval) { | |
2379 | if (retval != EOF) { | |
2380 | ds_put_cstr(s, " ***parse error***"); | |
2381 | } | |
2382 | break; | |
2383 | } | |
2384 | ||
2385 | ds_put_char(s, '\n'); | |
2386 | ||
2387 | ds_put_char(s, ' '); | |
2388 | ds_put_format(s, "group_id=%"PRIu32",", gs.group_id); | |
2389 | ||
2390 | if (gs.duration_sec != UINT32_MAX) { | |
2391 | ds_put_cstr(s, "duration="); | |
2392 | ofp_print_duration(s, gs.duration_sec, gs.duration_nsec); | |
2393 | ds_put_char(s, ','); | |
2394 | } | |
2395 | ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count); | |
2396 | ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count); | |
2397 | ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count); | |
2398 | ||
2399 | for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) { | |
2400 | if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) { | |
2401 | ds_put_format(s, ",bucket%"PRIu32":", bucket_i); | |
2402 | ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count); | |
2403 | ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count); | |
2404 | } | |
2405 | } | |
646b2a9c SH |
2406 | |
2407 | free(gs.bucket_stats); | |
7395c052 NZ |
2408 | } |
2409 | } | |
2410 | ||
2411 | static void | |
2412 | ofp_print_group_features(struct ds *string, const struct ofp_header *oh) | |
2413 | { | |
2414 | struct ofputil_group_features features; | |
2415 | ||
2416 | ofputil_decode_group_features_reply(oh, &features); | |
2417 | ||
2418 | ds_put_format(string, "\n Group table:\n"); | |
2419 | ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types); | |
2420 | ds_put_format(string, " Capabilities: 0x%"PRIx32"\n", | |
2421 | features.capabilities); | |
2422 | ||
2423 | if (features.types & (1u << OFPGT11_ALL)) { | |
2424 | ds_put_format(string, " All group :\n"); | |
2425 | ds_put_format(string, | |
2426 | " max_groups = %#"PRIx32" actions=0x%08"PRIx32"\n", | |
2427 | features.max_groups[0], features.actions[0]); | |
2428 | } | |
2429 | ||
2430 | if (features.types & (1u << OFPGT11_SELECT)) { | |
2431 | ds_put_format(string, " Select group :\n"); | |
2432 | ds_put_format(string, " max_groups = %#"PRIx32" " | |
2433 | "actions=0x%08"PRIx32"\n", | |
2434 | features.max_groups[1], features.actions[1]); | |
2435 | } | |
2436 | ||
2437 | if (features.types & (1u << OFPGT11_INDIRECT)) { | |
2438 | ds_put_format(string, " Indirect group :\n"); | |
2439 | ds_put_format(string, " max_groups = %#"PRIx32" " | |
2440 | "actions=0x%08"PRIx32"\n", | |
2441 | features.max_groups[2], features.actions[2]); | |
2442 | } | |
2443 | ||
2444 | if (features.types & (1u << OFPGT11_FF)) { | |
2445 | ds_put_format(string, " Fast Failover group :\n"); | |
2446 | ds_put_format(string, " max_groups = %#"PRIx32" " | |
2447 | "actions=0x%08"PRIx32"\n", | |
2448 | features.max_groups[3], features.actions[3]); | |
2449 | } | |
2450 | } | |
2451 | ||
2452 | static void | |
2453 | ofp_print_group_mod(struct ds *s, const struct ofp_header *oh) | |
2454 | { | |
2455 | struct ofputil_group_mod gm; | |
2456 | int error; | |
2457 | ||
2458 | error = ofputil_decode_group_mod(oh, &gm); | |
2459 | if (error) { | |
2460 | ofp_print_error(s, error); | |
2461 | return; | |
2462 | } | |
2463 | ||
2464 | ds_put_char(s, '\n'); | |
2465 | ||
2466 | ds_put_char(s, ' '); | |
2467 | switch (gm.command) { | |
2468 | case OFPGC11_ADD: | |
2469 | ds_put_cstr(s, "ADD"); | |
2470 | break; | |
2471 | ||
2472 | case OFPGC11_MODIFY: | |
2473 | ds_put_cstr(s, "MOD"); | |
2474 | break; | |
2475 | ||
2476 | case OFPGC11_DELETE: | |
2477 | ds_put_cstr(s, "DEL"); | |
2478 | break; | |
2479 | ||
2480 | default: | |
2481 | ds_put_format(s, "cmd:%"PRIu16"", gm.command); | |
2482 | } | |
2483 | ds_put_char(s, ' '); | |
2484 | ||
2485 | ofp_print_group(s, gm.group_id, gm.type, &gm.buckets); | |
2486 | } | |
2487 | ||
bdcc5925 | 2488 | static void |
982697a4 BP |
2489 | ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw, |
2490 | struct ds *string, int verbosity) | |
bdcc5925 | 2491 | { |
bdcc5925 BP |
2492 | const void *msg = oh; |
2493 | ||
982697a4 BP |
2494 | ofp_header_to_string__(oh, raw, string); |
2495 | switch (ofptype_from_ofpraw(raw)) { | |
2e1ae200 | 2496 | |
261bd854 | 2497 | case OFPTYPE_GROUP_STATS_REQUEST: |
7395c052 NZ |
2498 | ofp_print_stats_request(string, oh); |
2499 | ofp_print_ofpst_group_request(string, oh); | |
2500 | break; | |
2501 | ||
261bd854 | 2502 | case OFPTYPE_GROUP_STATS_REPLY: |
7395c052 NZ |
2503 | ofp_print_group_stats(string, oh); |
2504 | break; | |
2505 | ||
261bd854 | 2506 | case OFPTYPE_GROUP_DESC_STATS_REQUEST: |
7395c052 NZ |
2507 | ofp_print_stats_request(string, oh); |
2508 | break; | |
2509 | ||
261bd854 | 2510 | case OFPTYPE_GROUP_DESC_STATS_REPLY: |
7395c052 NZ |
2511 | ofp_print_group_desc(string, oh); |
2512 | break; | |
2513 | ||
261bd854 | 2514 | case OFPTYPE_GROUP_FEATURES_STATS_REQUEST: |
7395c052 NZ |
2515 | ofp_print_stats_request(string, oh); |
2516 | break; | |
2517 | ||
261bd854 | 2518 | case OFPTYPE_GROUP_FEATURES_STATS_REPLY: |
7395c052 NZ |
2519 | ofp_print_group_features(string, oh); |
2520 | break; | |
2521 | ||
2522 | case OFPTYPE_GROUP_MOD: | |
2523 | ofp_print_group_mod(string, oh); | |
2524 | break; | |
2525 | ||
261bd854 BP |
2526 | case OFPTYPE_TABLE_FEATURES_STATS_REQUEST: |
2527 | case OFPTYPE_TABLE_FEATURES_STATS_REPLY: | |
2e1ae200 JR |
2528 | ofp_print_not_implemented(string); |
2529 | break; | |
2530 | ||
982697a4 | 2531 | case OFPTYPE_HELLO: |
de6c85b0 | 2532 | ofp_print_hello(string, oh); |
d1e2cf21 BP |
2533 | break; |
2534 | ||
982697a4 BP |
2535 | case OFPTYPE_ERROR: |
2536 | ofp_print_error_msg(string, oh); | |
d1e2cf21 BP |
2537 | break; |
2538 | ||
982697a4 BP |
2539 | case OFPTYPE_ECHO_REQUEST: |
2540 | case OFPTYPE_ECHO_REPLY: | |
d1e2cf21 BP |
2541 | ofp_print_echo(string, oh, verbosity); |
2542 | break; | |
2543 | ||
982697a4 | 2544 | case OFPTYPE_FEATURES_REQUEST: |
d1e2cf21 BP |
2545 | break; |
2546 | ||
982697a4 BP |
2547 | case OFPTYPE_FEATURES_REPLY: |
2548 | ofp_print_switch_features(string, oh); | |
d1e2cf21 BP |
2549 | break; |
2550 | ||
982697a4 | 2551 | case OFPTYPE_GET_CONFIG_REQUEST: |
d1e2cf21 BP |
2552 | break; |
2553 | ||
982697a4 BP |
2554 | case OFPTYPE_GET_CONFIG_REPLY: |
2555 | case OFPTYPE_SET_CONFIG: | |
2556 | ofp_print_switch_config(string, ofpmsg_body(oh)); | |
d1e2cf21 BP |
2557 | break; |
2558 | ||
982697a4 BP |
2559 | case OFPTYPE_PACKET_IN: |
2560 | ofp_print_packet_in(string, oh, verbosity); | |
d1e2cf21 BP |
2561 | break; |
2562 | ||
982697a4 BP |
2563 | case OFPTYPE_FLOW_REMOVED: |
2564 | ofp_print_flow_removed(string, oh); | |
d1e2cf21 BP |
2565 | break; |
2566 | ||
982697a4 BP |
2567 | case OFPTYPE_PORT_STATUS: |
2568 | ofp_print_port_status(string, oh); | |
d1e2cf21 BP |
2569 | break; |
2570 | ||
982697a4 BP |
2571 | case OFPTYPE_PACKET_OUT: |
2572 | ofp_print_packet_out(string, oh, verbosity); | |
d1e2cf21 BP |
2573 | break; |
2574 | ||
982697a4 BP |
2575 | case OFPTYPE_FLOW_MOD: |
2576 | ofp_print_flow_mod(string, oh, verbosity); | |
d1e2cf21 BP |
2577 | break; |
2578 | ||
982697a4 BP |
2579 | case OFPTYPE_PORT_MOD: |
2580 | ofp_print_port_mod(string, oh); | |
d1e2cf21 BP |
2581 | break; |
2582 | ||
918f2b82 AZ |
2583 | case OFPTYPE_TABLE_MOD: |
2584 | ofp_print_table_mod(string, oh); | |
2585 | break; | |
2586 | ||
638a19b0 JR |
2587 | case OFPTYPE_METER_MOD: |
2588 | ofp_print_meter_mod(string, oh); | |
2589 | break; | |
2590 | ||
982697a4 BP |
2591 | case OFPTYPE_BARRIER_REQUEST: |
2592 | case OFPTYPE_BARRIER_REPLY: | |
d1e2cf21 BP |
2593 | break; |
2594 | ||
e8f9a7bb VG |
2595 | case OFPTYPE_QUEUE_GET_CONFIG_REQUEST: |
2596 | ofp_print_queue_get_config_request(string, oh); | |
2597 | break; | |
2598 | ||
2599 | case OFPTYPE_QUEUE_GET_CONFIG_REPLY: | |
2600 | ofp_print_queue_get_config_reply(string, oh); | |
2601 | break; | |
2602 | ||
6ea4776b JR |
2603 | case OFPTYPE_ROLE_REQUEST: |
2604 | case OFPTYPE_ROLE_REPLY: | |
2605 | ofp_print_role_message(string, oh); | |
2606 | break; | |
252f3411 | 2607 | case OFPTYPE_ROLE_STATUS: |
00467f73 | 2608 | ofp_print_role_status_message(string, oh); |
252f3411 | 2609 | break; |
6ea4776b | 2610 | |
261bd854 BP |
2611 | case OFPTYPE_METER_STATS_REQUEST: |
2612 | case OFPTYPE_METER_CONFIG_STATS_REQUEST: | |
638a19b0 JR |
2613 | ofp_print_stats_request(string, oh); |
2614 | ofp_print_meter_stats_request(string, oh); | |
2615 | break; | |
2616 | ||
261bd854 | 2617 | case OFPTYPE_METER_STATS_REPLY: |
638a19b0 JR |
2618 | ofp_print_stats_reply(string, oh); |
2619 | ofp_print_meter_stats_reply(string, oh); | |
2620 | break; | |
2621 | ||
261bd854 | 2622 | case OFPTYPE_METER_CONFIG_STATS_REPLY: |
638a19b0 JR |
2623 | ofp_print_stats_reply(string, oh); |
2624 | ofp_print_meter_config_reply(string, oh); | |
2625 | break; | |
2626 | ||
261bd854 | 2627 | case OFPTYPE_METER_FEATURES_STATS_REPLY: |
638a19b0 JR |
2628 | ofp_print_stats_reply(string, oh); |
2629 | ofp_print_meter_features_reply(string, oh); | |
2630 | break; | |
2631 | ||
982697a4 BP |
2632 | case OFPTYPE_DESC_STATS_REQUEST: |
2633 | case OFPTYPE_PORT_DESC_STATS_REQUEST: | |
261bd854 | 2634 | case OFPTYPE_METER_FEATURES_STATS_REQUEST: |
d1e2cf21 BP |
2635 | ofp_print_stats_request(string, oh); |
2636 | break; | |
2637 | ||
982697a4 BP |
2638 | case OFPTYPE_FLOW_STATS_REQUEST: |
2639 | case OFPTYPE_AGGREGATE_STATS_REQUEST: | |
d1e2cf21 | 2640 | ofp_print_stats_request(string, oh); |
982697a4 | 2641 | ofp_print_flow_stats_request(string, oh); |
d1e2cf21 BP |
2642 | break; |
2643 | ||
982697a4 | 2644 | case OFPTYPE_TABLE_STATS_REQUEST: |
d1e2cf21 BP |
2645 | ofp_print_stats_request(string, oh); |
2646 | break; | |
2647 | ||
982697a4 | 2648 | case OFPTYPE_PORT_STATS_REQUEST: |
d1e2cf21 | 2649 | ofp_print_stats_request(string, oh); |
982697a4 | 2650 | ofp_print_ofpst_port_request(string, oh); |
d1e2cf21 BP |
2651 | break; |
2652 | ||
982697a4 | 2653 | case OFPTYPE_QUEUE_STATS_REQUEST: |
d1e2cf21 | 2654 | ofp_print_stats_request(string, oh); |
982697a4 | 2655 | ofp_print_ofpst_queue_request(string, oh); |
d1e2cf21 BP |
2656 | break; |
2657 | ||
982697a4 | 2658 | case OFPTYPE_DESC_STATS_REPLY: |
d1e2cf21 | 2659 | ofp_print_stats_reply(string, oh); |
982697a4 | 2660 | ofp_print_ofpst_desc_reply(string, oh); |
d1e2cf21 BP |
2661 | break; |
2662 | ||
982697a4 | 2663 | case OFPTYPE_FLOW_STATS_REPLY: |
d1e2cf21 | 2664 | ofp_print_stats_reply(string, oh); |
4ffd1b43 | 2665 | ofp_print_flow_stats_reply(string, oh); |
d1e2cf21 BP |
2666 | break; |
2667 | ||
982697a4 | 2668 | case OFPTYPE_QUEUE_STATS_REPLY: |
d1e2cf21 BP |
2669 | ofp_print_stats_reply(string, oh); |
2670 | ofp_print_ofpst_queue_reply(string, oh, verbosity); | |
2671 | break; | |
2672 | ||
982697a4 | 2673 | case OFPTYPE_PORT_STATS_REPLY: |
d1e2cf21 BP |
2674 | ofp_print_stats_reply(string, oh); |
2675 | ofp_print_ofpst_port_reply(string, oh, verbosity); | |
2676 | break; | |
2677 | ||
982697a4 | 2678 | case OFPTYPE_TABLE_STATS_REPLY: |
d1e2cf21 BP |
2679 | ofp_print_stats_reply(string, oh); |
2680 | ofp_print_ofpst_table_reply(string, oh, verbosity); | |
2681 | break; | |
2682 | ||
982697a4 | 2683 | case OFPTYPE_AGGREGATE_STATS_REPLY: |
d1e2cf21 | 2684 | ofp_print_stats_reply(string, oh); |
982697a4 | 2685 | ofp_print_aggregate_stats_reply(string, oh); |
d1e2cf21 | 2686 | break; |
064af421 | 2687 | |
982697a4 | 2688 | case OFPTYPE_PORT_DESC_STATS_REPLY: |
2be393ed JP |
2689 | ofp_print_stats_reply(string, oh); |
2690 | ofp_print_ofpst_port_desc_reply(string, oh); | |
2691 | break; | |
2692 | ||
982697a4 BP |
2693 | case OFPTYPE_FLOW_MOD_TABLE_ID: |
2694 | ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh)); | |
6c1491fb BP |
2695 | break; |
2696 | ||
982697a4 BP |
2697 | case OFPTYPE_SET_FLOW_FORMAT: |
2698 | ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh)); | |
7fa91113 BP |
2699 | break; |
2700 | ||
982697a4 BP |
2701 | case OFPTYPE_SET_PACKET_IN_FORMAT: |
2702 | ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh)); | |
54834960 EJ |
2703 | break; |
2704 | ||
982697a4 | 2705 | case OFPTYPE_FLOW_AGE: |
f27f2134 BP |
2706 | break; |
2707 | ||
982697a4 BP |
2708 | case OFPTYPE_SET_CONTROLLER_ID: |
2709 | ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh)); | |
a7349929 BP |
2710 | break; |
2711 | ||
db09e430 | 2712 | case OFPTYPE_GET_ASYNC_REPLY: |
982697a4 BP |
2713 | case OFPTYPE_SET_ASYNC_CONFIG: |
2714 | ofp_print_nxt_set_async_config(string, ofpmsg_body(oh)); | |
d1e2cf21 | 2715 | break; |
db09e430 AC |
2716 | case OFPTYPE_GET_ASYNC_REQUEST: |
2717 | break; | |
982697a4 | 2718 | case OFPTYPE_FLOW_MONITOR_CANCEL: |
2b07c8b1 BP |
2719 | ofp_print_nxt_flow_monitor_cancel(string, msg); |
2720 | break; | |
2721 | ||
982697a4 BP |
2722 | case OFPTYPE_FLOW_MONITOR_PAUSED: |
2723 | case OFPTYPE_FLOW_MONITOR_RESUMED: | |
2b07c8b1 BP |
2724 | break; |
2725 | ||
982697a4 | 2726 | case OFPTYPE_FLOW_MONITOR_STATS_REQUEST: |
2b07c8b1 BP |
2727 | ofp_print_nxst_flow_monitor_request(string, msg); |
2728 | break; | |
2729 | ||
982697a4 | 2730 | case OFPTYPE_FLOW_MONITOR_STATS_REPLY: |
2b07c8b1 BP |
2731 | ofp_print_nxst_flow_monitor_reply(string, msg); |
2732 | break; | |
246e61ea | 2733 | } |
d1e2cf21 | 2734 | } |
064af421 BP |
2735 | |
2736 | /* Composes and returns a string representing the OpenFlow packet of 'len' | |
2737 | * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of | |
2738 | * verbosity and higher numbers increase verbosity. The caller is responsible | |
2739 | * for freeing the string. */ | |
2740 | char * | |
2741 | ofp_to_string(const void *oh_, size_t len, int verbosity) | |
2742 | { | |
2743 | struct ds string = DS_EMPTY_INITIALIZER; | |
2744 | const struct ofp_header *oh = oh_; | |
064af421 | 2745 | |
49ad0403 BP |
2746 | if (!len) { |
2747 | ds_put_cstr(&string, "OpenFlow message is empty\n"); | |
2748 | } else if (len < sizeof(struct ofp_header)) { | |
34582733 | 2749 | ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n", |
49ad0403 | 2750 | len); |
d1e2cf21 | 2751 | } else if (ntohs(oh->length) > len) { |
f25b4a81 | 2752 | enum ofperr error; |
982697a4 | 2753 | enum ofpraw raw; |
f25b4a81 | 2754 | |
982697a4 | 2755 | error = ofpraw_decode_partial(&raw, oh, len); |
f25b4a81 | 2756 | if (!error) { |
982697a4 | 2757 | ofp_header_to_string__(oh, raw, &string); |
f25b4a81 BP |
2758 | ds_put_char(&string, '\n'); |
2759 | } | |
2760 | ||
d1e2cf21 | 2761 | ds_put_format(&string, |
34582733 | 2762 | "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n", |
d1e2cf21 BP |
2763 | len, ntohs(oh->length)); |
2764 | } else if (ntohs(oh->length) < len) { | |
2765 | ds_put_format(&string, | |
34582733 | 2766 | "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n", |
d1e2cf21 BP |
2767 | ntohs(oh->length), len); |
2768 | } else { | |
90bf1e07 | 2769 | enum ofperr error; |
982697a4 | 2770 | enum ofpraw raw; |
d1e2cf21 | 2771 | |
982697a4 | 2772 | error = ofpraw_decode(&raw, oh); |
d1e2cf21 | 2773 | if (!error) { |
982697a4 | 2774 | ofp_to_string__(oh, raw, &string, verbosity); |
7fa91113 BP |
2775 | if (verbosity >= 5) { |
2776 | if (ds_last(&string) != '\n') { | |
2777 | ds_put_char(&string, '\n'); | |
2778 | } | |
d1e2cf21 BP |
2779 | ds_put_hex_dump(&string, oh, len, 0, true); |
2780 | } | |
7fa91113 | 2781 | if (ds_last(&string) != '\n') { |
d1e2cf21 BP |
2782 | ds_put_char(&string, '\n'); |
2783 | } | |
2784 | return ds_steal_cstr(&string); | |
064af421 | 2785 | } |
064af421 | 2786 | |
7fa91113 | 2787 | ofp_print_error(&string, error); |
064af421 | 2788 | } |
d1e2cf21 BP |
2789 | ds_put_hex_dump(&string, oh, len, 0, true); |
2790 | return ds_steal_cstr(&string); | |
064af421 | 2791 | } |
064af421 BP |
2792 | \f |
2793 | static void | |
d295e8e9 | 2794 | print_and_free(FILE *stream, char *string) |
064af421 BP |
2795 | { |
2796 | fputs(string, stream); | |
2797 | free(string); | |
2798 | } | |
2799 | ||
2800 | /* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the | |
2801 | * given 'verbosity' level. 0 is a minimal amount of verbosity and higher | |
2802 | * numbers increase verbosity. */ | |
2803 | void | |
2804 | ofp_print(FILE *stream, const void *oh, size_t len, int verbosity) | |
2805 | { | |
2806 | print_and_free(stream, ofp_to_string(oh, len, verbosity)); | |
2807 | } | |
2808 | ||
2809 | /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at | |
897a8e07 | 2810 | * 'data' to 'stream'. */ |
064af421 | 2811 | void |
c499c75d | 2812 | ofp_print_packet(FILE *stream, const void *data, size_t len) |
064af421 | 2813 | { |
c499c75d | 2814 | print_and_free(stream, ofp_packet_to_string(data, len)); |
064af421 | 2815 | } |