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