]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
82c8c53c | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. |
064af421 | 3 | * |
a14bc59f BP |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
064af421 | 7 | * |
a14bc59f BP |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
064af421 BP |
15 | */ |
16 | ||
17 | #include <config.h> | |
2b07c8b1 | 18 | #include <ctype.h> |
064af421 BP |
19 | #include <errno.h> |
20 | #include <getopt.h> | |
21 | #include <inttypes.h> | |
bd6b7545 | 22 | #include <sys/socket.h> |
064af421 | 23 | #include <net/if.h> |
064af421 | 24 | #include <signal.h> |
064af421 BP |
25 | #include <stdlib.h> |
26 | #include <string.h> | |
27 | #include <unistd.h> | |
1e1d00a5 | 28 | #include <sys/fcntl.h> |
064af421 BP |
29 | #include <sys/stat.h> |
30 | #include <sys/time.h> | |
31 | ||
10a24935 | 32 | #include "byte-order.h" |
09246b99 | 33 | #include "classifier.h" |
064af421 | 34 | #include "command-line.h" |
1eb85ef5 | 35 | #include "daemon.h" |
064af421 BP |
36 | #include "compiler.h" |
37 | #include "dirs.h" | |
09246b99 | 38 | #include "dynamic-string.h" |
09246b99 | 39 | #include "nx-match.h" |
064af421 | 40 | #include "odp-util.h" |
f25d0cf3 | 41 | #include "ofp-actions.h" |
90bf1e07 | 42 | #include "ofp-errors.h" |
982697a4 | 43 | #include "ofp-msgs.h" |
f22716dc | 44 | #include "ofp-parse.h" |
064af421 | 45 | #include "ofp-print.h" |
fa37b408 | 46 | #include "ofp-util.h" |
a53a8efa | 47 | #include "ofp-version-opt.h" |
064af421 | 48 | #include "ofpbuf.h" |
63d347ce | 49 | #include "ofproto/ofproto.h" |
064af421 BP |
50 | #include "openflow/nicira-ext.h" |
51 | #include "openflow/openflow.h" | |
0c3d5fc8 | 52 | #include "packets.h" |
1eb85ef5 | 53 | #include "poll-loop.h" |
064af421 | 54 | #include "random.h" |
fe55ad15 | 55 | #include "stream-ssl.h" |
c3f25389 | 56 | #include "socket-util.h" |
064af421 | 57 | #include "timeval.h" |
1eb85ef5 | 58 | #include "unixctl.h" |
064af421 | 59 | #include "util.h" |
064af421 | 60 | #include "vconn.h" |
5136ce49 | 61 | #include "vlog.h" |
bdcc5925 BP |
62 | #include "meta-flow.h" |
63 | #include "sort.h" | |
064af421 | 64 | |
d98e6007 | 65 | VLOG_DEFINE_THIS_MODULE(ofctl); |
064af421 | 66 | |
102ce766 EJ |
67 | /* --strict: Use strict matching for flow mod commands? Additionally governs |
68 | * use of nx_pull_match() instead of nx_pull_match_loose() in parse-nx-match. | |
69 | */ | |
675febfa | 70 | static bool strict; |
064af421 | 71 | |
96989efc | 72 | /* --readd: If true, on replace-flows, re-add even flows that have not changed |
c4ea79bf BP |
73 | * (to reset flow counters). */ |
74 | static bool readd; | |
75 | ||
27527aa0 BP |
76 | /* -F, --flow-format: Allowed protocols. By default, any protocol is |
77 | * allowed. */ | |
78 | static enum ofputil_protocol allowed_protocols = OFPUTIL_P_ANY; | |
88ca35ee | 79 | |
54834960 EJ |
80 | /* -P, --packet-in-format: Packet IN format to use in monitor and snoop |
81 | * commands. Either one of NXPIF_* to force a particular packet_in format, or | |
82 | * -1 to let ovs-ofctl choose the default. */ | |
83 | static int preferred_packet_in_format = -1; | |
84 | ||
4f564f8d BP |
85 | /* -m, --more: Additional verbosity for ofp-print functions. */ |
86 | static int verbosity; | |
87 | ||
0c9560b7 BP |
88 | /* --timestamp: Print a timestamp before each received packet on "monitor" and |
89 | * "snoop" command? */ | |
90 | static bool timestamp; | |
91 | ||
bdcc5925 BP |
92 | /* --sort, --rsort: Sort order. */ |
93 | enum sort_order { SORT_ASC, SORT_DESC }; | |
94 | struct sort_criterion { | |
95 | const struct mf_field *field; /* NULL means to sort by priority. */ | |
96 | enum sort_order order; | |
97 | }; | |
98 | static struct sort_criterion *criteria; | |
99 | static size_t n_criteria, allocated_criteria; | |
100 | ||
675febfa | 101 | static const struct command all_commands[]; |
064af421 BP |
102 | |
103 | static void usage(void) NO_RETURN; | |
675febfa | 104 | static void parse_options(int argc, char *argv[]); |
064af421 | 105 | |
bdcc5925 BP |
106 | static bool recv_flow_stats_reply(struct vconn *, ovs_be32 send_xid, |
107 | struct ofpbuf **replyp, | |
108 | struct ofputil_flow_stats *, | |
109 | struct ofpbuf *ofpacts); | |
675febfa BP |
110 | int |
111 | main(int argc, char *argv[]) | |
064af421 | 112 | { |
064af421 | 113 | set_program_name(argv[0]); |
675febfa | 114 | parse_options(argc, argv); |
064af421 | 115 | signal(SIGPIPE, SIG_IGN); |
675febfa | 116 | run_command(argc - optind, argv + optind, all_commands); |
064af421 BP |
117 | return 0; |
118 | } | |
119 | ||
bdcc5925 BP |
120 | static void |
121 | add_sort_criterion(enum sort_order order, const char *field) | |
122 | { | |
123 | struct sort_criterion *sc; | |
124 | ||
125 | if (n_criteria >= allocated_criteria) { | |
126 | criteria = x2nrealloc(criteria, &allocated_criteria, sizeof *criteria); | |
127 | } | |
128 | ||
129 | sc = &criteria[n_criteria++]; | |
130 | if (!field || !strcasecmp(field, "priority")) { | |
131 | sc->field = NULL; | |
132 | } else { | |
133 | sc->field = mf_from_name(field); | |
134 | if (!sc->field) { | |
135 | ovs_fatal(0, "%s: unknown field name", field); | |
136 | } | |
137 | } | |
138 | sc->order = order; | |
139 | } | |
140 | ||
064af421 | 141 | static void |
675febfa | 142 | parse_options(int argc, char *argv[]) |
064af421 BP |
143 | { |
144 | enum { | |
87c84891 | 145 | OPT_STRICT = UCHAR_MAX + 1, |
c4ea79bf | 146 | OPT_READD, |
0c9560b7 | 147 | OPT_TIMESTAMP, |
bdcc5925 BP |
148 | OPT_SORT, |
149 | OPT_RSORT, | |
1eb85ef5 | 150 | DAEMON_OPTION_ENUMS, |
a53a8efa | 151 | OFP_VERSION_OPTION_ENUMS, |
87c84891 | 152 | VLOG_OPTION_ENUMS |
064af421 BP |
153 | }; |
154 | static struct option long_options[] = { | |
e3c17733 BP |
155 | {"timeout", required_argument, NULL, 't'}, |
156 | {"strict", no_argument, NULL, OPT_STRICT}, | |
c4ea79bf | 157 | {"readd", no_argument, NULL, OPT_READD}, |
e3c17733 | 158 | {"flow-format", required_argument, NULL, 'F'}, |
54834960 | 159 | {"packet-in-format", required_argument, NULL, 'P'}, |
e3c17733 | 160 | {"more", no_argument, NULL, 'm'}, |
0c9560b7 | 161 | {"timestamp", no_argument, NULL, OPT_TIMESTAMP}, |
bdcc5925 BP |
162 | {"sort", optional_argument, NULL, OPT_SORT}, |
163 | {"rsort", optional_argument, NULL, OPT_RSORT}, | |
e3c17733 | 164 | {"help", no_argument, NULL, 'h'}, |
1eb85ef5 | 165 | DAEMON_LONG_OPTIONS, |
a53a8efa | 166 | OFP_VERSION_LONG_OPTIONS, |
87c84891 | 167 | VLOG_LONG_OPTIONS, |
bf8f2167 | 168 | STREAM_SSL_LONG_OPTIONS, |
e3c17733 | 169 | {NULL, 0, NULL, 0}, |
064af421 BP |
170 | }; |
171 | char *short_options = long_options_to_short_options(long_options); | |
37923ac7 BP |
172 | uint32_t versions; |
173 | enum ofputil_protocol version_protocols; | |
064af421 | 174 | |
064af421 BP |
175 | for (;;) { |
176 | unsigned long int timeout; | |
177 | int c; | |
178 | ||
179 | c = getopt_long(argc, argv, short_options, long_options, NULL); | |
180 | if (c == -1) { | |
181 | break; | |
182 | } | |
183 | ||
184 | switch (c) { | |
185 | case 't': | |
186 | timeout = strtoul(optarg, NULL, 10); | |
187 | if (timeout <= 0) { | |
188 | ovs_fatal(0, "value %s on -t or --timeout is not at least 1", | |
189 | optarg); | |
190 | } else { | |
191 | time_alarm(timeout); | |
192 | } | |
193 | break; | |
194 | ||
88ca35ee | 195 | case 'F': |
27527aa0 BP |
196 | allowed_protocols = ofputil_protocols_from_string(optarg); |
197 | if (!allowed_protocols) { | |
198 | ovs_fatal(0, "%s: invalid flow format(s)", optarg); | |
88ca35ee BP |
199 | } |
200 | break; | |
201 | ||
54834960 EJ |
202 | case 'P': |
203 | preferred_packet_in_format = | |
204 | ofputil_packet_in_format_from_string(optarg); | |
205 | if (preferred_packet_in_format < 0) { | |
206 | ovs_fatal(0, "unknown packet-in format `%s'", optarg); | |
207 | } | |
208 | break; | |
209 | ||
4f564f8d BP |
210 | case 'm': |
211 | verbosity++; | |
212 | break; | |
213 | ||
064af421 BP |
214 | case 'h': |
215 | usage(); | |
216 | ||
064af421 | 217 | case OPT_STRICT: |
675febfa | 218 | strict = true; |
064af421 BP |
219 | break; |
220 | ||
c4ea79bf BP |
221 | case OPT_READD: |
222 | readd = true; | |
223 | break; | |
224 | ||
0c9560b7 BP |
225 | case OPT_TIMESTAMP: |
226 | timestamp = true; | |
227 | break; | |
228 | ||
bdcc5925 BP |
229 | case OPT_SORT: |
230 | add_sort_criterion(SORT_ASC, optarg); | |
231 | break; | |
232 | ||
233 | case OPT_RSORT: | |
234 | add_sort_criterion(SORT_DESC, optarg); | |
235 | break; | |
236 | ||
1eb85ef5 | 237 | DAEMON_OPTION_HANDLERS |
a53a8efa | 238 | OFP_VERSION_OPTION_HANDLERS |
87c84891 | 239 | VLOG_OPTION_HANDLERS |
fe55ad15 | 240 | STREAM_SSL_OPTION_HANDLERS |
064af421 BP |
241 | |
242 | case '?': | |
243 | exit(EXIT_FAILURE); | |
244 | ||
245 | default: | |
246 | abort(); | |
247 | } | |
248 | } | |
bdcc5925 BP |
249 | |
250 | if (n_criteria) { | |
251 | /* Always do a final sort pass based on priority. */ | |
252 | add_sort_criterion(SORT_DESC, "priority"); | |
253 | } | |
254 | ||
064af421 | 255 | free(short_options); |
37923ac7 BP |
256 | |
257 | versions = get_allowed_ofp_versions(); | |
258 | version_protocols = ofputil_protocols_from_version_bitmap(versions); | |
259 | if (!(allowed_protocols & version_protocols)) { | |
260 | char *protocols = ofputil_protocols_to_string(allowed_protocols); | |
261 | struct ds version_s = DS_EMPTY_INITIALIZER; | |
262 | ||
263 | ofputil_format_version_bitmap_names(&version_s, versions); | |
264 | ovs_fatal(0, "None of the enabled OpenFlow versions (%s) supports " | |
265 | "any of the enabled flow formats (%s). (Use -O to enable " | |
266 | "additional OpenFlow versions or -F to enable additional " | |
267 | "flow formats.)", ds_cstr(&version_s), protocols); | |
268 | } | |
269 | allowed_protocols &= version_protocols; | |
270 | mask_allowed_ofp_versions(ofputil_protocols_to_version_bitmap( | |
271 | allowed_protocols)); | |
064af421 BP |
272 | } |
273 | ||
274 | static void | |
275 | usage(void) | |
276 | { | |
277 | printf("%s: OpenFlow switch management utility\n" | |
278 | "usage: %s [OPTIONS] COMMAND [ARG...]\n" | |
279 | "\nFor OpenFlow switches:\n" | |
280 | " show SWITCH show OpenFlow information\n" | |
064af421 BP |
281 | " dump-desc SWITCH print switch description\n" |
282 | " dump-tables SWITCH print table stats\n" | |
283 | " mod-port SWITCH IFACE ACT modify port behavior\n" | |
7257b535 BP |
284 | " get-frags SWITCH print fragment handling behavior\n" |
285 | " set-frags SWITCH FRAG_MODE set fragment handling behavior\n" | |
abaad8cf | 286 | " dump-ports SWITCH [PORT] print port statistics\n" |
2be393ed | 287 | " dump-ports-desc SWITCH print port descriptions\n" |
064af421 BP |
288 | " dump-flows SWITCH print all flow entries\n" |
289 | " dump-flows SWITCH FLOW print matching FLOWs\n" | |
290 | " dump-aggregate SWITCH print aggregate flow statistics\n" | |
291 | " dump-aggregate SWITCH FLOW print aggregate stats for FLOWs\n" | |
d2805da2 | 292 | " queue-stats SWITCH [PORT [QUEUE]] dump queue stats\n" |
064af421 BP |
293 | " add-flow SWITCH FLOW add flow described by FLOW\n" |
294 | " add-flows SWITCH FILE add flows from FILE\n" | |
295 | " mod-flows SWITCH FLOW modify actions of matching FLOWs\n" | |
296 | " del-flows SWITCH [FLOW] delete matching FLOWs\n" | |
5ff660c6 | 297 | " replace-flows SWITCH FILE replace flows with those in FILE\n" |
1dac118c | 298 | " diff-flows SOURCE1 SOURCE2 compare flows from two sources\n" |
0c3d5fc8 BP |
299 | " packet-out SWITCH IN_PORT ACTIONS PACKET...\n" |
300 | " execute ACTIONS on PACKET\n" | |
2b07c8b1 | 301 | " monitor SWITCH [MISSLEN] [invalid_ttl] [watch:[...]]\n" |
1dac118c BP |
302 | " print packets received from SWITCH\n" |
303 | " snoop SWITCH snoop on SWITCH and its controller\n" | |
064af421 | 304 | "\nFor OpenFlow switches and controllers:\n" |
2daadadd BP |
305 | " probe TARGET probe whether TARGET is up\n" |
306 | " ping TARGET [N] latency of N-byte echos\n" | |
307 | " benchmark TARGET N COUNT bandwidth of COUNT N-byte echos\n" | |
308 | "where SWITCH or TARGET is an active OpenFlow connection method.\n", | |
064af421 BP |
309 | program_name, program_name); |
310 | vconn_usage(true, false, false); | |
1eb85ef5 | 311 | daemon_usage(); |
a53a8efa | 312 | ofp_version_usage(); |
064af421 BP |
313 | vlog_usage(); |
314 | printf("\nOther options:\n" | |
315 | " --strict use strict match for flow commands\n" | |
c4ea79bf | 316 | " --readd replace flows that haven't changed\n" |
88ca35ee | 317 | " -F, --flow-format=FORMAT force particular flow format\n" |
54834960 | 318 | " -P, --packet-in-format=FRMT force particular packet in format\n" |
4f564f8d | 319 | " -m, --more be more verbose printing OpenFlow\n" |
0c9560b7 | 320 | " --timestamp (monitor, snoop) print timestamps\n" |
064af421 | 321 | " -t, --timeout=SECS give up after SECS seconds\n" |
bdcc5925 BP |
322 | " --sort[=field] sort in ascending order\n" |
323 | " --rsort[=field] sort in descending order\n" | |
064af421 BP |
324 | " -h, --help display this help message\n" |
325 | " -V, --version display version information\n"); | |
326 | exit(EXIT_SUCCESS); | |
327 | } | |
328 | ||
1eb85ef5 EJ |
329 | static void |
330 | ofctl_exit(struct unixctl_conn *conn, int argc OVS_UNUSED, | |
331 | const char *argv[] OVS_UNUSED, void *exiting_) | |
332 | { | |
333 | bool *exiting = exiting_; | |
334 | *exiting = true; | |
bde9f75d | 335 | unixctl_command_reply(conn, NULL); |
1eb85ef5 EJ |
336 | } |
337 | ||
064af421 BP |
338 | static void run(int retval, const char *message, ...) |
339 | PRINTF_FORMAT(2, 3); | |
340 | ||
473f65a2 BP |
341 | static void |
342 | run(int retval, const char *message, ...) | |
064af421 BP |
343 | { |
344 | if (retval) { | |
345 | va_list args; | |
346 | ||
064af421 | 347 | va_start(args, message); |
fcaddd4d | 348 | ovs_fatal_valist(retval, message, args); |
064af421 BP |
349 | } |
350 | } | |
351 | \f | |
352 | /* Generic commands. */ | |
353 | ||
c3f25389 | 354 | static int |
1a6f1e2a JG |
355 | open_vconn_socket(const char *name, struct vconn **vconnp) |
356 | { | |
357 | char *vconn_name = xasprintf("unix:%s", name); | |
c3f25389 EJ |
358 | int error; |
359 | ||
82c8c53c BP |
360 | error = vconn_open(vconn_name, get_allowed_ofp_versions(), DSCP_DEFAULT, |
361 | vconnp); | |
c3f25389 EJ |
362 | if (error && error != ENOENT) { |
363 | ovs_fatal(0, "%s: failed to open socket (%s)", name, | |
364 | strerror(error)); | |
365 | } | |
1a6f1e2a | 366 | free(vconn_name); |
c3f25389 EJ |
367 | |
368 | return error; | |
1a6f1e2a JG |
369 | } |
370 | ||
27527aa0 | 371 | static enum ofputil_protocol |
0caf6bde BP |
372 | open_vconn__(const char *name, const char *default_suffix, |
373 | struct vconn **vconnp) | |
064af421 | 374 | { |
63d347ce | 375 | char *datapath_name, *datapath_type, *socket_name; |
27527aa0 | 376 | enum ofputil_protocol protocol; |
63d347ce | 377 | char *bridge_path; |
27527aa0 | 378 | int ofp_version; |
c3f25389 | 379 | int error; |
1a6f1e2a | 380 | |
b43c6fe2 | 381 | bridge_path = xasprintf("%s/%s.%s", ovs_rundir(), name, default_suffix); |
63d347ce BP |
382 | |
383 | ofproto_parse_name(name, &datapath_name, &datapath_type); | |
384 | socket_name = xasprintf("%s/%s.%s", | |
385 | ovs_rundir(), datapath_name, default_suffix); | |
386 | free(datapath_name); | |
387 | free(datapath_type); | |
064af421 | 388 | |
3a27375e | 389 | if (strchr(name, ':')) { |
539b741f | 390 | run(vconn_open(name, get_allowed_ofp_versions(), DSCP_DEFAULT, vconnp), |
a53a8efa | 391 | "connecting to %s", name); |
c3f25389 EJ |
392 | } else if (!open_vconn_socket(name, vconnp)) { |
393 | /* Fall Through. */ | |
394 | } else if (!open_vconn_socket(bridge_path, vconnp)) { | |
395 | /* Fall Through. */ | |
396 | } else if (!open_vconn_socket(socket_name, vconnp)) { | |
397 | /* Fall Through. */ | |
064af421 | 398 | } else { |
2c0e6eb4 | 399 | ovs_fatal(0, "%s is not a bridge or a socket", name); |
064af421 | 400 | } |
1a6f1e2a | 401 | |
1a6f1e2a | 402 | free(bridge_path); |
63d347ce | 403 | free(socket_name); |
27527aa0 | 404 | |
c3f25389 EJ |
405 | VLOG_DBG("connecting to %s", vconn_get_name(*vconnp)); |
406 | error = vconn_connect_block(*vconnp); | |
407 | if (error) { | |
408 | ovs_fatal(0, "%s: failed to connect to socket (%s)", name, | |
409 | strerror(error)); | |
410 | } | |
411 | ||
27527aa0 BP |
412 | ofp_version = vconn_get_version(*vconnp); |
413 | protocol = ofputil_protocol_from_ofp_version(ofp_version); | |
414 | if (!protocol) { | |
415 | ovs_fatal(0, "%s: unsupported OpenFlow version 0x%02x", | |
416 | name, ofp_version); | |
417 | } | |
418 | return protocol; | |
064af421 BP |
419 | } |
420 | ||
27527aa0 | 421 | static enum ofputil_protocol |
0caf6bde BP |
422 | open_vconn(const char *name, struct vconn **vconnp) |
423 | { | |
424 | return open_vconn__(name, "mgmt", vconnp); | |
425 | } | |
426 | ||
064af421 BP |
427 | static void |
428 | send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer) | |
429 | { | |
982697a4 | 430 | ofpmsg_update_length(buffer); |
064af421 BP |
431 | run(vconn_send_block(vconn, buffer), "failed to send packet to switch"); |
432 | } | |
433 | ||
434 | static void | |
a53a8efa | 435 | dump_transaction(struct vconn *vconn, struct ofpbuf *request) |
064af421 | 436 | { |
064af421 BP |
437 | struct ofpbuf *reply; |
438 | ||
982697a4 | 439 | ofpmsg_update_length(request); |
a53a8efa SH |
440 | run(vconn_transact(vconn, request, &reply), "talking to %s", |
441 | vconn_get_name(vconn)); | |
4f564f8d | 442 | ofp_print(stdout, reply->data, reply->size, verbosity + 1); |
e49190c4 | 443 | ofpbuf_delete(reply); |
064af421 BP |
444 | } |
445 | ||
446 | static void | |
982697a4 | 447 | dump_trivial_transaction(const char *vconn_name, enum ofpraw raw) |
064af421 BP |
448 | { |
449 | struct ofpbuf *request; | |
a53a8efa SH |
450 | struct vconn *vconn; |
451 | ||
452 | open_vconn(vconn_name, &vconn); | |
453 | request = ofpraw_alloc(raw, vconn_get_version(vconn), 0); | |
454 | dump_transaction(vconn, request); | |
455 | vconn_close(vconn); | |
064af421 BP |
456 | } |
457 | ||
458 | static void | |
53514387 | 459 | dump_stats_transaction(struct vconn *vconn, struct ofpbuf *request) |
064af421 | 460 | { |
982697a4 BP |
461 | const struct ofp_header *request_oh = request->data; |
462 | ovs_be32 send_xid = request_oh->xid; | |
463 | enum ofpraw request_raw; | |
464 | enum ofpraw reply_raw; | |
064af421 BP |
465 | bool done = false; |
466 | ||
982697a4 BP |
467 | ofpraw_decode_partial(&request_raw, request->data, request->size); |
468 | reply_raw = ofpraw_stats_request_to_reply(request_raw, | |
469 | request_oh->version); | |
470 | ||
064af421 BP |
471 | send_openflow_buffer(vconn, request); |
472 | while (!done) { | |
02833365 | 473 | ovs_be32 recv_xid; |
064af421 BP |
474 | struct ofpbuf *reply; |
475 | ||
476 | run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed"); | |
477 | recv_xid = ((struct ofp_header *) reply->data)->xid; | |
478 | if (send_xid == recv_xid) { | |
982697a4 | 479 | enum ofpraw raw; |
064af421 | 480 | |
4f564f8d | 481 | ofp_print(stdout, reply->data, reply->size, verbosity + 1); |
064af421 | 482 | |
982697a4 BP |
483 | ofpraw_decode(&raw, reply->data); |
484 | if (ofptype_from_ofpraw(raw) == OFPTYPE_ERROR) { | |
a76150b1 | 485 | done = true; |
982697a4 BP |
486 | } else if (raw == reply_raw) { |
487 | done = !ofpmp_more(reply->data); | |
a76150b1 BP |
488 | } else { |
489 | ovs_fatal(0, "received bad reply: %s", | |
490 | ofp_to_string(reply->data, reply->size, | |
491 | verbosity + 1)); | |
492 | } | |
064af421 BP |
493 | } else { |
494 | VLOG_DBG("received reply with xid %08"PRIx32" " | |
495 | "!= expected %08"PRIx32, recv_xid, send_xid); | |
496 | } | |
497 | ofpbuf_delete(reply); | |
498 | } | |
9abfe557 BP |
499 | } |
500 | ||
501 | static void | |
53514387 | 502 | dump_trivial_stats_transaction(const char *vconn_name, enum ofpraw raw) |
9abfe557 | 503 | { |
53514387 | 504 | struct ofpbuf *request; |
9abfe557 BP |
505 | struct vconn *vconn; |
506 | ||
507 | open_vconn(vconn_name, &vconn); | |
53514387 SH |
508 | request = ofpraw_alloc(raw, vconn_get_version(vconn), 0); |
509 | dump_stats_transaction(vconn, request); | |
064af421 BP |
510 | vconn_close(vconn); |
511 | } | |
512 | ||
d12513f7 BP |
513 | /* Sends 'request', which should be a request that only has a reply if an error |
514 | * occurs, and waits for it to succeed or fail. If an error does occur, prints | |
7257b535 BP |
515 | * it and exits with an error. |
516 | * | |
517 | * Destroys all of the 'requests'. */ | |
d12513f7 | 518 | static void |
88ca35ee | 519 | transact_multiple_noreply(struct vconn *vconn, struct list *requests) |
d12513f7 | 520 | { |
88ca35ee | 521 | struct ofpbuf *request, *reply; |
d12513f7 | 522 | |
88ca35ee | 523 | LIST_FOR_EACH (request, list_node, requests) { |
982697a4 | 524 | ofpmsg_update_length(request); |
88ca35ee BP |
525 | } |
526 | ||
527 | run(vconn_transact_multiple_noreply(vconn, requests, &reply), | |
d12513f7 BP |
528 | "talking to %s", vconn_get_name(vconn)); |
529 | if (reply) { | |
4f564f8d | 530 | ofp_print(stderr, reply->data, reply->size, verbosity + 2); |
d12513f7 BP |
531 | exit(1); |
532 | } | |
533 | ofpbuf_delete(reply); | |
534 | } | |
535 | ||
88ca35ee BP |
536 | /* Sends 'request', which should be a request that only has a reply if an error |
537 | * occurs, and waits for it to succeed or fail. If an error does occur, prints | |
7257b535 BP |
538 | * it and exits with an error. |
539 | * | |
540 | * Destroys 'request'. */ | |
88ca35ee BP |
541 | static void |
542 | transact_noreply(struct vconn *vconn, struct ofpbuf *request) | |
543 | { | |
544 | struct list requests; | |
545 | ||
546 | list_init(&requests); | |
547 | list_push_back(&requests, &request->list_node); | |
548 | transact_multiple_noreply(vconn, &requests); | |
549 | } | |
550 | ||
7257b535 BP |
551 | static void |
552 | fetch_switch_config(struct vconn *vconn, struct ofp_switch_config *config_) | |
553 | { | |
554 | struct ofp_switch_config *config; | |
7257b535 BP |
555 | struct ofpbuf *request; |
556 | struct ofpbuf *reply; | |
982697a4 | 557 | enum ofptype type; |
7257b535 | 558 | |
a53a8efa SH |
559 | request = ofpraw_alloc(OFPRAW_OFPT_GET_CONFIG_REQUEST, |
560 | vconn_get_version(vconn), 0); | |
7257b535 BP |
561 | run(vconn_transact(vconn, request, &reply), |
562 | "talking to %s", vconn_get_name(vconn)); | |
563 | ||
982697a4 | 564 | if (ofptype_pull(&type, reply) || type != OFPTYPE_GET_CONFIG_REPLY) { |
7257b535 BP |
565 | ovs_fatal(0, "%s: bad reply to config request", vconn_get_name(vconn)); |
566 | } | |
567 | ||
982697a4 | 568 | config = ofpbuf_pull(reply, sizeof *config); |
7257b535 | 569 | *config_ = *config; |
828c72d0 BP |
570 | |
571 | ofpbuf_delete(reply); | |
7257b535 BP |
572 | } |
573 | ||
574 | static void | |
982697a4 | 575 | set_switch_config(struct vconn *vconn, const struct ofp_switch_config *config) |
7257b535 | 576 | { |
7257b535 BP |
577 | struct ofpbuf *request; |
578 | ||
a53a8efa | 579 | request = ofpraw_alloc(OFPRAW_OFPT_SET_CONFIG, vconn_get_version(vconn), 0); |
982697a4 | 580 | ofpbuf_put(request, config, sizeof *config); |
7257b535 BP |
581 | |
582 | transact_noreply(vconn, request); | |
583 | } | |
584 | ||
064af421 | 585 | static void |
e1fef0f9 | 586 | ofctl_show(int argc OVS_UNUSED, char *argv[]) |
064af421 | 587 | { |
ae0e7009 JP |
588 | const char *vconn_name = argv[1]; |
589 | struct vconn *vconn; | |
590 | struct ofpbuf *request; | |
591 | struct ofpbuf *reply; | |
592 | bool trunc; | |
593 | ||
ae0e7009 | 594 | open_vconn(vconn_name, &vconn); |
a53a8efa SH |
595 | request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST, |
596 | vconn_get_version(vconn), 0); | |
ae0e7009 JP |
597 | run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name); |
598 | ||
599 | trunc = ofputil_switch_features_ports_trunc(reply); | |
600 | ofp_print(stdout, reply->data, reply->size, verbosity + 1); | |
601 | ||
602 | ofpbuf_delete(reply); | |
ae0e7009 JP |
603 | |
604 | if (trunc) { | |
605 | /* The Features Reply may not contain all the ports, so send a | |
606 | * Port Description stats request, which doesn't have size | |
607 | * constraints. */ | |
982697a4 BP |
608 | dump_trivial_stats_transaction(vconn_name, |
609 | OFPRAW_OFPST_PORT_DESC_REQUEST); | |
ae0e7009 | 610 | } |
982697a4 | 611 | dump_trivial_transaction(vconn_name, OFPRAW_OFPT_GET_CONFIG_REQUEST); |
a53a8efa | 612 | vconn_close(vconn); |
064af421 BP |
613 | } |
614 | ||
064af421 | 615 | static void |
e1fef0f9 | 616 | ofctl_dump_desc(int argc OVS_UNUSED, char *argv[]) |
064af421 | 617 | { |
982697a4 | 618 | dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_DESC_REQUEST); |
064af421 BP |
619 | } |
620 | ||
621 | static void | |
e1fef0f9 | 622 | ofctl_dump_tables(int argc OVS_UNUSED, char *argv[]) |
064af421 | 623 | { |
982697a4 | 624 | dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_TABLE_REQUEST); |
064af421 BP |
625 | } |
626 | ||
da91750f JP |
627 | static bool |
628 | fetch_port_by_features(const char *vconn_name, | |
629 | const char *port_name, unsigned int port_no, | |
630 | struct ofputil_phy_port *pp, bool *trunc) | |
abaad8cf | 631 | { |
9e1fd49b | 632 | struct ofputil_switch_features features; |
982697a4 | 633 | const struct ofp_header *oh; |
abaad8cf | 634 | struct ofpbuf *request, *reply; |
abaad8cf | 635 | struct vconn *vconn; |
9e1fd49b | 636 | enum ofperr error; |
982697a4 | 637 | enum ofptype type; |
9e1fd49b | 638 | struct ofpbuf b; |
da91750f | 639 | bool found = false; |
abaad8cf | 640 | |
0df0e81d | 641 | /* Fetch the switch's ofp_switch_features. */ |
abaad8cf | 642 | open_vconn(vconn_name, &vconn); |
a53a8efa SH |
643 | request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST, |
644 | vconn_get_version(vconn), 0); | |
abaad8cf | 645 | run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name); |
da91750f | 646 | vconn_close(vconn); |
abaad8cf | 647 | |
982697a4 BP |
648 | oh = reply->data; |
649 | if (ofptype_decode(&type, reply->data) | |
650 | || type != OFPTYPE_FEATURES_REPLY) { | |
651 | ovs_fatal(0, "%s: received bad features reply", vconn_name); | |
0df0e81d | 652 | } |
da91750f JP |
653 | |
654 | *trunc = false; | |
655 | if (ofputil_switch_features_ports_trunc(reply)) { | |
656 | *trunc = true; | |
657 | goto exit; | |
658 | } | |
659 | ||
982697a4 | 660 | error = ofputil_decode_switch_features(oh, &features, &b); |
9e1fd49b BP |
661 | if (error) { |
662 | ovs_fatal(0, "%s: failed to decode features reply (%s)", | |
663 | vconn_name, ofperr_to_string(error)); | |
664 | } | |
0df0e81d | 665 | |
982697a4 | 666 | while (!ofputil_pull_phy_port(oh->version, &b, pp)) { |
0df0e81d | 667 | if (port_no != UINT_MAX |
9e1fd49b BP |
668 | ? port_no == pp->port_no |
669 | : !strcmp(pp->name, port_name)) { | |
da91750f JP |
670 | found = true; |
671 | goto exit; | |
abaad8cf JP |
672 | } |
673 | } | |
da91750f JP |
674 | |
675 | exit: | |
676 | ofpbuf_delete(reply); | |
677 | return found; | |
678 | } | |
679 | ||
680 | static bool | |
681 | fetch_port_by_stats(const char *vconn_name, | |
682 | const char *port_name, unsigned int port_no, | |
683 | struct ofputil_phy_port *pp) | |
684 | { | |
685 | struct ofpbuf *request; | |
686 | struct vconn *vconn; | |
687 | ovs_be32 send_xid; | |
da91750f JP |
688 | bool done = false; |
689 | bool found = false; | |
690 | ||
982697a4 | 691 | request = ofpraw_alloc(OFPRAW_OFPST_PORT_DESC_REQUEST, OFP10_VERSION, 0); |
da91750f JP |
692 | send_xid = ((struct ofp_header *) request->data)->xid; |
693 | ||
694 | open_vconn(vconn_name, &vconn); | |
695 | send_openflow_buffer(vconn, request); | |
696 | while (!done) { | |
697 | ovs_be32 recv_xid; | |
698 | struct ofpbuf *reply; | |
699 | ||
700 | run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed"); | |
701 | recv_xid = ((struct ofp_header *) reply->data)->xid; | |
702 | if (send_xid == recv_xid) { | |
982697a4 BP |
703 | struct ofp_header *oh = reply->data; |
704 | enum ofptype type; | |
705 | struct ofpbuf b; | |
706 | uint16_t flags; | |
707 | ||
708 | ofpbuf_use_const(&b, oh, ntohs(oh->length)); | |
709 | if (ofptype_pull(&type, &b) | |
710 | || type != OFPTYPE_PORT_DESC_STATS_REPLY) { | |
da91750f JP |
711 | ovs_fatal(0, "received bad reply: %s", |
712 | ofp_to_string(reply->data, reply->size, | |
713 | verbosity + 1)); | |
714 | } | |
715 | ||
982697a4 BP |
716 | flags = ofpmp_flags(oh); |
717 | done = !(flags & OFPSF_REPLY_MORE); | |
da91750f JP |
718 | |
719 | if (found) { | |
720 | /* We've already found the port, but we need to drain | |
721 | * the queue of any other replies for this request. */ | |
722 | continue; | |
723 | } | |
724 | ||
982697a4 | 725 | while (!ofputil_pull_phy_port(oh->version, &b, pp)) { |
da91750f JP |
726 | if (port_no != UINT_MAX ? port_no == pp->port_no |
727 | : !strcmp(pp->name, port_name)) { | |
728 | found = true; | |
729 | break; | |
730 | } | |
731 | } | |
732 | } else { | |
733 | VLOG_DBG("received reply with xid %08"PRIx32" " | |
734 | "!= expected %08"PRIx32, recv_xid, send_xid); | |
735 | } | |
736 | ofpbuf_delete(reply); | |
737 | } | |
738 | vconn_close(vconn); | |
739 | ||
740 | return found; | |
741 | } | |
742 | ||
743 | ||
744 | /* Opens a connection to 'vconn_name', fetches the port structure for | |
745 | * 'port_name' (which may be a port name or number), and copies it into | |
746 | * '*pp'. */ | |
747 | static void | |
748 | fetch_ofputil_phy_port(const char *vconn_name, const char *port_name, | |
749 | struct ofputil_phy_port *pp) | |
750 | { | |
751 | unsigned int port_no; | |
752 | bool found; | |
753 | bool trunc; | |
754 | ||
755 | /* Try to interpret the argument as a port number. */ | |
756 | if (!str_to_uint(port_name, 10, &port_no)) { | |
757 | port_no = UINT_MAX; | |
758 | } | |
759 | ||
760 | /* Try to find the port based on the Features Reply. If it looks | |
761 | * like the results may be truncated, then use the Port Description | |
762 | * stats message introduced in OVS 1.7. */ | |
763 | found = fetch_port_by_features(vconn_name, port_name, port_no, pp, | |
764 | &trunc); | |
765 | if (trunc) { | |
766 | found = fetch_port_by_stats(vconn_name, port_name, port_no, pp); | |
767 | } | |
768 | ||
769 | if (!found) { | |
770 | ovs_fatal(0, "%s: couldn't find port `%s'", vconn_name, port_name); | |
771 | } | |
0df0e81d | 772 | } |
abaad8cf | 773 | |
0df0e81d BP |
774 | /* Returns the port number corresponding to 'port_name' (which may be a port |
775 | * name or number) within the switch 'vconn_name'. */ | |
776 | static uint16_t | |
777 | str_to_port_no(const char *vconn_name, const char *port_name) | |
778 | { | |
8010100b BP |
779 | uint16_t port_no; |
780 | ||
781 | if (ofputil_port_from_string(port_name, &port_no)) { | |
0df0e81d BP |
782 | return port_no; |
783 | } else { | |
9e1fd49b | 784 | struct ofputil_phy_port pp; |
abaad8cf | 785 | |
9e1fd49b BP |
786 | fetch_ofputil_phy_port(vconn_name, port_name, &pp); |
787 | return pp.port_no; | |
0df0e81d | 788 | } |
abaad8cf JP |
789 | } |
790 | ||
88ca35ee | 791 | static bool |
27527aa0 BP |
792 | try_set_protocol(struct vconn *vconn, enum ofputil_protocol want, |
793 | enum ofputil_protocol *cur) | |
88ca35ee | 794 | { |
27527aa0 BP |
795 | for (;;) { |
796 | struct ofpbuf *request, *reply; | |
797 | enum ofputil_protocol next; | |
88ca35ee | 798 | |
27527aa0 BP |
799 | request = ofputil_encode_set_protocol(*cur, want, &next); |
800 | if (!request) { | |
e43928f2 | 801 | return *cur == want; |
27527aa0 BP |
802 | } |
803 | ||
804 | run(vconn_transact_noreply(vconn, request, &reply), | |
805 | "talking to %s", vconn_get_name(vconn)); | |
806 | if (reply) { | |
807 | char *s = ofp_to_string(reply->data, reply->size, 2); | |
808 | VLOG_DBG("%s: failed to set protocol, switch replied: %s", | |
809 | vconn_get_name(vconn), s); | |
810 | free(s); | |
811 | ofpbuf_delete(reply); | |
812 | return false; | |
813 | } | |
814 | ||
815 | *cur = next; | |
88ca35ee | 816 | } |
88ca35ee BP |
817 | } |
818 | ||
27527aa0 BP |
819 | static enum ofputil_protocol |
820 | set_protocol_for_flow_dump(struct vconn *vconn, | |
821 | enum ofputil_protocol cur_protocol, | |
822 | enum ofputil_protocol usable_protocols) | |
064af421 | 823 | { |
27527aa0 BP |
824 | char *usable_s; |
825 | int i; | |
064af421 | 826 | |
27527aa0 BP |
827 | for (i = 0; i < ofputil_n_flow_dump_protocols; i++) { |
828 | enum ofputil_protocol f = ofputil_flow_dump_protocols[i]; | |
829 | if (f & usable_protocols & allowed_protocols | |
830 | && try_set_protocol(vconn, f, &cur_protocol)) { | |
831 | return f; | |
f9cbfbe4 | 832 | } |
27527aa0 | 833 | } |
f9cbfbe4 | 834 | |
27527aa0 BP |
835 | usable_s = ofputil_protocols_to_string(usable_protocols); |
836 | if (usable_protocols & allowed_protocols) { | |
837 | ovs_fatal(0, "switch does not support any of the usable flow " | |
838 | "formats (%s)", usable_s); | |
f9cbfbe4 | 839 | } else { |
27527aa0 BP |
840 | char *allowed_s = ofputil_protocols_to_string(allowed_protocols); |
841 | ovs_fatal(0, "none of the usable flow formats (%s) is among the " | |
842 | "allowed flow formats (%s)", usable_s, allowed_s); | |
88ca35ee | 843 | } |
064af421 BP |
844 | } |
845 | ||
bdcc5925 BP |
846 | static struct vconn * |
847 | prepare_dump_flows(int argc, char *argv[], bool aggregate, | |
848 | struct ofpbuf **requestp) | |
064af421 | 849 | { |
27527aa0 | 850 | enum ofputil_protocol usable_protocols, protocol; |
81d1ea94 | 851 | struct ofputil_flow_stats_request fsr; |
88ca35ee | 852 | struct vconn *vconn; |
064af421 | 853 | |
88ca35ee | 854 | parse_ofp_flow_stats_request_str(&fsr, aggregate, argc > 2 ? argv[2] : ""); |
27527aa0 | 855 | usable_protocols = ofputil_flow_stats_request_usable_protocols(&fsr); |
064af421 | 856 | |
27527aa0 BP |
857 | protocol = open_vconn(argv[1], &vconn); |
858 | protocol = set_protocol_for_flow_dump(vconn, protocol, usable_protocols); | |
bdcc5925 BP |
859 | *requestp = ofputil_encode_flow_stats_request(&fsr, protocol); |
860 | return vconn; | |
861 | } | |
862 | ||
863 | static void | |
864 | ofctl_dump_flows__(int argc, char *argv[], bool aggregate) | |
865 | { | |
866 | struct ofpbuf *request; | |
867 | struct vconn *vconn; | |
868 | ||
869 | vconn = prepare_dump_flows(argc, argv, aggregate, &request); | |
53514387 | 870 | dump_stats_transaction(vconn, request); |
88ca35ee BP |
871 | vconn_close(vconn); |
872 | } | |
873 | ||
bdcc5925 BP |
874 | static int |
875 | compare_flows(const void *afs_, const void *bfs_) | |
876 | { | |
877 | const struct ofputil_flow_stats *afs = afs_; | |
878 | const struct ofputil_flow_stats *bfs = bfs_; | |
81a76618 BP |
879 | const struct match *a = &afs->match; |
880 | const struct match *b = &bfs->match; | |
bdcc5925 BP |
881 | const struct sort_criterion *sc; |
882 | ||
883 | for (sc = criteria; sc < &criteria[n_criteria]; sc++) { | |
884 | const struct mf_field *f = sc->field; | |
885 | int ret; | |
886 | ||
887 | if (!f) { | |
81a76618 BP |
888 | unsigned int a_pri = afs->priority; |
889 | unsigned int b_pri = bfs->priority; | |
890 | ret = a_pri < b_pri ? -1 : a_pri > b_pri; | |
bdcc5925 BP |
891 | } else { |
892 | bool ina, inb; | |
893 | ||
894 | ina = mf_are_prereqs_ok(f, &a->flow) && !mf_is_all_wild(f, &a->wc); | |
895 | inb = mf_are_prereqs_ok(f, &b->flow) && !mf_is_all_wild(f, &b->wc); | |
896 | if (ina != inb) { | |
897 | /* Skip the test for sc->order, so that missing fields always | |
898 | * sort to the end whether we're sorting in ascending or | |
899 | * descending order. */ | |
900 | return ina ? -1 : 1; | |
901 | } else { | |
902 | union mf_value aval, bval; | |
903 | ||
904 | mf_get_value(f, &a->flow, &aval); | |
905 | mf_get_value(f, &b->flow, &bval); | |
906 | ret = memcmp(&aval, &bval, f->n_bytes); | |
907 | } | |
908 | } | |
909 | ||
910 | if (ret) { | |
911 | return sc->order == SORT_ASC ? ret : -ret; | |
912 | } | |
913 | } | |
914 | ||
915 | return 0; | |
916 | } | |
917 | ||
88ca35ee | 918 | static void |
e1fef0f9 | 919 | ofctl_dump_flows(int argc, char *argv[]) |
88ca35ee | 920 | { |
bdcc5925 BP |
921 | if (!n_criteria) { |
922 | return ofctl_dump_flows__(argc, argv, false); | |
923 | } else { | |
924 | struct ofputil_flow_stats *fses; | |
925 | size_t n_fses, allocated_fses; | |
926 | struct ofpbuf *request; | |
927 | struct ofpbuf ofpacts; | |
928 | struct ofpbuf *reply; | |
929 | struct vconn *vconn; | |
930 | ovs_be32 send_xid; | |
931 | struct ds s; | |
932 | size_t i; | |
933 | ||
934 | vconn = prepare_dump_flows(argc, argv, false, &request); | |
935 | send_xid = ((struct ofp_header *) request->data)->xid; | |
936 | send_openflow_buffer(vconn, request); | |
937 | ||
938 | fses = NULL; | |
939 | n_fses = allocated_fses = 0; | |
940 | reply = NULL; | |
941 | ofpbuf_init(&ofpacts, 0); | |
942 | for (;;) { | |
943 | struct ofputil_flow_stats *fs; | |
944 | ||
945 | if (n_fses >= allocated_fses) { | |
946 | fses = x2nrealloc(fses, &allocated_fses, sizeof *fses); | |
947 | } | |
948 | ||
949 | fs = &fses[n_fses]; | |
950 | if (!recv_flow_stats_reply(vconn, send_xid, &reply, fs, | |
951 | &ofpacts)) { | |
952 | break; | |
953 | } | |
954 | fs->ofpacts = xmemdup(fs->ofpacts, fs->ofpacts_len); | |
955 | n_fses++; | |
956 | } | |
957 | ofpbuf_uninit(&ofpacts); | |
958 | ||
959 | qsort(fses, n_fses, sizeof *fses, compare_flows); | |
960 | ||
961 | ds_init(&s); | |
962 | for (i = 0; i < n_fses; i++) { | |
963 | ds_clear(&s); | |
964 | ofp_print_flow_stats(&s, &fses[i]); | |
965 | puts(ds_cstr(&s)); | |
966 | } | |
967 | ds_destroy(&s); | |
968 | ||
969 | for (i = 0; i < n_fses; i++) { | |
970 | free(fses[i].ofpacts); | |
971 | } | |
972 | free(fses); | |
973 | ||
974 | vconn_close(vconn); | |
975 | } | |
88ca35ee BP |
976 | } |
977 | ||
978 | static void | |
e1fef0f9 | 979 | ofctl_dump_aggregate(int argc, char *argv[]) |
88ca35ee | 980 | { |
e1fef0f9 | 981 | return ofctl_dump_flows__(argc, argv, true); |
064af421 BP |
982 | } |
983 | ||
d2805da2 | 984 | static void |
e1fef0f9 | 985 | ofctl_queue_stats(int argc, char *argv[]) |
d2805da2 | 986 | { |
d2805da2 | 987 | struct ofpbuf *request; |
53514387 | 988 | struct vconn *vconn; |
64626975 | 989 | struct ofputil_queue_stats_request oqs; |
d2805da2 | 990 | |
53514387 | 991 | open_vconn(argv[1], &vconn); |
d2805da2 BP |
992 | |
993 | if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) { | |
64626975 | 994 | oqs.port_no = str_to_port_no(argv[1], argv[2]); |
d2805da2 | 995 | } else { |
7f05e7ab | 996 | oqs.port_no = OFPP_ANY; |
d2805da2 BP |
997 | } |
998 | if (argc > 3 && argv[3][0] && strcasecmp(argv[3], "all")) { | |
64626975 | 999 | oqs.queue_id = atoi(argv[3]); |
d2805da2 | 1000 | } else { |
64626975 | 1001 | oqs.queue_id = OFPQ_ALL; |
d2805da2 BP |
1002 | } |
1003 | ||
64626975 | 1004 | request = ofputil_encode_queue_stats_request(vconn_get_version(vconn), &oqs); |
53514387 SH |
1005 | dump_stats_transaction(vconn, request); |
1006 | vconn_close(vconn); | |
d2805da2 BP |
1007 | } |
1008 | ||
27527aa0 BP |
1009 | static enum ofputil_protocol |
1010 | open_vconn_for_flow_mod(const char *remote, | |
1011 | const struct ofputil_flow_mod *fms, size_t n_fms, | |
1012 | struct vconn **vconnp) | |
0fbc9f11 | 1013 | { |
27527aa0 BP |
1014 | enum ofputil_protocol usable_protocols; |
1015 | enum ofputil_protocol cur_protocol; | |
1016 | char *usable_s; | |
1017 | int i; | |
0fbc9f11 | 1018 | |
27527aa0 BP |
1019 | /* Figure out what flow formats will work. */ |
1020 | usable_protocols = ofputil_flow_mod_usable_protocols(fms, n_fms); | |
1021 | if (!(usable_protocols & allowed_protocols)) { | |
1022 | char *allowed_s = ofputil_protocols_to_string(allowed_protocols); | |
1023 | usable_s = ofputil_protocols_to_string(usable_protocols); | |
1024 | ovs_fatal(0, "none of the usable flow formats (%s) is among the " | |
1025 | "allowed flow formats (%s)", usable_s, allowed_s); | |
0fbc9f11 | 1026 | } |
0fbc9f11 | 1027 | |
27527aa0 BP |
1028 | /* If the initial flow format is allowed and usable, keep it. */ |
1029 | cur_protocol = open_vconn(remote, vconnp); | |
1030 | if (usable_protocols & allowed_protocols & cur_protocol) { | |
1031 | return cur_protocol; | |
1032 | } | |
1033 | ||
1034 | /* Otherwise try each flow format in turn. */ | |
1035 | for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) { | |
1036 | enum ofputil_protocol f = 1 << i; | |
1037 | ||
1038 | if (f != cur_protocol | |
1039 | && f & usable_protocols & allowed_protocols | |
1040 | && try_set_protocol(*vconnp, f, &cur_protocol)) { | |
1041 | return f; | |
1042 | } | |
0fbc9f11 | 1043 | } |
27527aa0 BP |
1044 | |
1045 | usable_s = ofputil_protocols_to_string(usable_protocols); | |
1046 | ovs_fatal(0, "switch does not support any of the usable flow " | |
1047 | "formats (%s)", usable_s); | |
0fbc9f11 BP |
1048 | } |
1049 | ||
064af421 | 1050 | static void |
e1fef0f9 AS |
1051 | ofctl_flow_mod__(const char *remote, struct ofputil_flow_mod *fms, |
1052 | size_t n_fms) | |
064af421 | 1053 | { |
27527aa0 | 1054 | enum ofputil_protocol protocol; |
064af421 | 1055 | struct vconn *vconn; |
27527aa0 | 1056 | size_t i; |
4989c59f | 1057 | |
27527aa0 | 1058 | protocol = open_vconn_for_flow_mod(remote, fms, n_fms, &vconn); |
049c8dc2 | 1059 | |
27527aa0 BP |
1060 | for (i = 0; i < n_fms; i++) { |
1061 | struct ofputil_flow_mod *fm = &fms[i]; | |
0fbc9f11 | 1062 | |
27527aa0 | 1063 | transact_noreply(vconn, ofputil_encode_flow_mod(fm, protocol)); |
f25d0cf3 | 1064 | free(fm->ofpacts); |
4989c59f | 1065 | } |
064af421 | 1066 | vconn_close(vconn); |
88ca35ee BP |
1067 | } |
1068 | ||
064af421 | 1069 | static void |
e1fef0f9 | 1070 | ofctl_flow_mod_file(int argc OVS_UNUSED, char *argv[], uint16_t command) |
064af421 | 1071 | { |
27527aa0 BP |
1072 | struct ofputil_flow_mod *fms = NULL; |
1073 | size_t n_fms = 0; | |
064af421 | 1074 | |
27527aa0 | 1075 | parse_ofp_flow_mod_file(argv[2], command, &fms, &n_fms); |
e1fef0f9 | 1076 | ofctl_flow_mod__(argv[1], fms, n_fms); |
27527aa0 BP |
1077 | free(fms); |
1078 | } | |
1079 | ||
1080 | static void | |
e1fef0f9 | 1081 | ofctl_flow_mod(int argc, char *argv[], uint16_t command) |
27527aa0 | 1082 | { |
4989c59f | 1083 | if (argc > 2 && !strcmp(argv[2], "-")) { |
e1fef0f9 | 1084 | ofctl_flow_mod_file(argc, argv, command); |
27527aa0 BP |
1085 | } else { |
1086 | struct ofputil_flow_mod fm; | |
1087 | parse_ofp_flow_mod_str(&fm, argc > 2 ? argv[2] : "", command, false); | |
e1fef0f9 | 1088 | ofctl_flow_mod__(argv[1], &fm, 1); |
064af421 | 1089 | } |
4989c59f | 1090 | } |
88ca35ee | 1091 | |
4989c59f | 1092 | static void |
e1fef0f9 | 1093 | ofctl_add_flow(int argc, char *argv[]) |
4989c59f | 1094 | { |
e1fef0f9 | 1095 | ofctl_flow_mod(argc, argv, OFPFC_ADD); |
4989c59f BP |
1096 | } |
1097 | ||
1098 | static void | |
e1fef0f9 | 1099 | ofctl_add_flows(int argc, char *argv[]) |
4989c59f | 1100 | { |
e1fef0f9 | 1101 | ofctl_flow_mod_file(argc, argv, OFPFC_ADD); |
064af421 BP |
1102 | } |
1103 | ||
1104 | static void | |
e1fef0f9 | 1105 | ofctl_mod_flows(int argc, char *argv[]) |
064af421 | 1106 | { |
e1fef0f9 | 1107 | ofctl_flow_mod(argc, argv, strict ? OFPFC_MODIFY_STRICT : OFPFC_MODIFY); |
064af421 BP |
1108 | } |
1109 | ||
88ca35ee | 1110 | static void |
e1fef0f9 | 1111 | ofctl_del_flows(int argc, char *argv[]) |
064af421 | 1112 | { |
e1fef0f9 | 1113 | ofctl_flow_mod(argc, argv, strict ? OFPFC_DELETE_STRICT : OFPFC_DELETE); |
064af421 BP |
1114 | } |
1115 | ||
54834960 EJ |
1116 | static void |
1117 | set_packet_in_format(struct vconn *vconn, | |
1118 | enum nx_packet_in_format packet_in_format) | |
1119 | { | |
3f4a1939 SH |
1120 | struct ofpbuf *spif; |
1121 | ||
1122 | spif = ofputil_make_set_packet_in_format(vconn_get_version(vconn), | |
1123 | packet_in_format); | |
54834960 EJ |
1124 | transact_noreply(vconn, spif); |
1125 | VLOG_DBG("%s: using user-specified packet in format %s", | |
1126 | vconn_get_name(vconn), | |
1127 | ofputil_packet_in_format_to_string(packet_in_format)); | |
1128 | } | |
1129 | ||
f0fd1a17 PS |
1130 | static int |
1131 | monitor_set_invalid_ttl_to_controller(struct vconn *vconn) | |
1132 | { | |
1133 | struct ofp_switch_config config; | |
1134 | enum ofp_config_flags flags; | |
1135 | ||
1136 | fetch_switch_config(vconn, &config); | |
1137 | flags = ntohs(config.flags); | |
1138 | if (!(flags & OFPC_INVALID_TTL_TO_CONTROLLER)) { | |
1139 | /* Set the invalid ttl config. */ | |
1140 | flags |= OFPC_INVALID_TTL_TO_CONTROLLER; | |
1141 | ||
1142 | config.flags = htons(flags); | |
1143 | set_switch_config(vconn, &config); | |
1144 | ||
1145 | /* Then retrieve the configuration to see if it really took. OpenFlow | |
1146 | * doesn't define error reporting for bad modes, so this is all we can | |
1147 | * do. */ | |
1148 | fetch_switch_config(vconn, &config); | |
1149 | flags = ntohs(config.flags); | |
1150 | if (!(flags & OFPC_INVALID_TTL_TO_CONTROLLER)) { | |
1151 | ovs_fatal(0, "setting invalid_ttl_to_controller failed (this " | |
1152 | "switch probably doesn't support mode)"); | |
1153 | return -EOPNOTSUPP; | |
1154 | } | |
1155 | } | |
1156 | return 0; | |
1157 | } | |
1158 | ||
96761f58 BP |
1159 | /* Converts hex digits in 'hex' to an OpenFlow message in '*msgp'. The |
1160 | * caller must free '*msgp'. On success, returns NULL. On failure, returns | |
1161 | * an error message and stores NULL in '*msgp'. */ | |
1162 | static const char * | |
1163 | openflow_from_hex(const char *hex, struct ofpbuf **msgp) | |
1164 | { | |
1165 | struct ofp_header *oh; | |
1166 | struct ofpbuf *msg; | |
1167 | ||
1168 | msg = ofpbuf_new(strlen(hex) / 2); | |
1169 | *msgp = NULL; | |
1170 | ||
1171 | if (ofpbuf_put_hex(msg, hex, NULL)[0] != '\0') { | |
1172 | ofpbuf_delete(msg); | |
1173 | return "Trailing garbage in hex data"; | |
1174 | } | |
1175 | ||
1176 | if (msg->size < sizeof(struct ofp_header)) { | |
1177 | ofpbuf_delete(msg); | |
1178 | return "Message too short for OpenFlow"; | |
1179 | } | |
1180 | ||
1181 | oh = msg->data; | |
1182 | if (msg->size != ntohs(oh->length)) { | |
1183 | ofpbuf_delete(msg); | |
1184 | return "Message size does not match length in OpenFlow header"; | |
1185 | } | |
1186 | ||
1187 | *msgp = msg; | |
1188 | return NULL; | |
1189 | } | |
1190 | ||
1191 | static void | |
1192 | ofctl_send(struct unixctl_conn *conn, int argc, | |
1193 | const char *argv[], void *vconn_) | |
1194 | { | |
1195 | struct vconn *vconn = vconn_; | |
1196 | struct ds reply; | |
1197 | bool ok; | |
1198 | int i; | |
1199 | ||
1200 | ok = true; | |
1201 | ds_init(&reply); | |
1202 | for (i = 1; i < argc; i++) { | |
1203 | const char *error_msg; | |
1204 | struct ofpbuf *msg; | |
1205 | int error; | |
1206 | ||
1207 | error_msg = openflow_from_hex(argv[i], &msg); | |
1208 | if (error_msg) { | |
1209 | ds_put_format(&reply, "%s\n", error_msg); | |
1210 | ok = false; | |
1211 | continue; | |
1212 | } | |
1213 | ||
1214 | fprintf(stderr, "send: "); | |
1215 | ofp_print(stderr, msg->data, msg->size, verbosity); | |
1216 | ||
1217 | error = vconn_send_block(vconn, msg); | |
1218 | if (error) { | |
1219 | ofpbuf_delete(msg); | |
1220 | ds_put_format(&reply, "%s\n", strerror(error)); | |
1221 | ok = false; | |
1222 | } else { | |
1223 | ds_put_cstr(&reply, "sent\n"); | |
1224 | } | |
1225 | } | |
bde9f75d EJ |
1226 | |
1227 | if (ok) { | |
1228 | unixctl_command_reply(conn, ds_cstr(&reply)); | |
1229 | } else { | |
1230 | unixctl_command_reply_error(conn, ds_cstr(&reply)); | |
1231 | } | |
96761f58 BP |
1232 | ds_destroy(&reply); |
1233 | } | |
1234 | ||
bb638b9a BP |
1235 | struct barrier_aux { |
1236 | struct vconn *vconn; /* OpenFlow connection for sending barrier. */ | |
1237 | struct unixctl_conn *conn; /* Connection waiting for barrier response. */ | |
1238 | }; | |
1239 | ||
1240 | static void | |
1241 | ofctl_barrier(struct unixctl_conn *conn, int argc OVS_UNUSED, | |
1242 | const char *argv[] OVS_UNUSED, void *aux_) | |
1243 | { | |
1244 | struct barrier_aux *aux = aux_; | |
1245 | struct ofpbuf *msg; | |
1246 | int error; | |
1247 | ||
1248 | if (aux->conn) { | |
bde9f75d | 1249 | unixctl_command_reply_error(conn, "already waiting for barrier reply"); |
bb638b9a BP |
1250 | return; |
1251 | } | |
1252 | ||
a0ae0b6e | 1253 | msg = ofputil_encode_barrier_request(vconn_get_version(aux->vconn)); |
bb638b9a BP |
1254 | error = vconn_send_block(aux->vconn, msg); |
1255 | if (error) { | |
1256 | ofpbuf_delete(msg); | |
bde9f75d | 1257 | unixctl_command_reply_error(conn, strerror(error)); |
bb638b9a BP |
1258 | } else { |
1259 | aux->conn = conn; | |
1260 | } | |
1261 | } | |
1262 | ||
1e1d00a5 BP |
1263 | static void |
1264 | ofctl_set_output_file(struct unixctl_conn *conn, int argc OVS_UNUSED, | |
1265 | const char *argv[], void *aux OVS_UNUSED) | |
1266 | { | |
1267 | int fd; | |
1268 | ||
1269 | fd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666); | |
1270 | if (fd < 0) { | |
bde9f75d | 1271 | unixctl_command_reply_error(conn, strerror(errno)); |
1e1d00a5 BP |
1272 | return; |
1273 | } | |
1274 | ||
1275 | fflush(stderr); | |
1276 | dup2(fd, STDERR_FILENO); | |
1277 | close(fd); | |
bde9f75d | 1278 | unixctl_command_reply(conn, NULL); |
1e1d00a5 BP |
1279 | } |
1280 | ||
2b07c8b1 BP |
1281 | static void |
1282 | ofctl_block(struct unixctl_conn *conn, int argc OVS_UNUSED, | |
4f8f2439 | 1283 | const char *argv[] OVS_UNUSED, void *blocked_) |
2b07c8b1 | 1284 | { |
4f8f2439 | 1285 | bool *blocked = blocked_; |
2b07c8b1 | 1286 | |
4f8f2439 BP |
1287 | if (!*blocked) { |
1288 | *blocked = true; | |
1289 | unixctl_command_reply(conn, NULL); | |
1290 | } else { | |
2b07c8b1 | 1291 | unixctl_command_reply(conn, "already blocking"); |
2b07c8b1 BP |
1292 | } |
1293 | } | |
1294 | ||
1295 | static void | |
1296 | ofctl_unblock(struct unixctl_conn *conn, int argc OVS_UNUSED, | |
4f8f2439 | 1297 | const char *argv[] OVS_UNUSED, void *blocked_) |
2b07c8b1 | 1298 | { |
4f8f2439 | 1299 | bool *blocked = blocked_; |
2b07c8b1 | 1300 | |
4f8f2439 BP |
1301 | if (*blocked) { |
1302 | *blocked = false; | |
2b07c8b1 | 1303 | unixctl_command_reply(conn, NULL); |
4f8f2439 BP |
1304 | } else { |
1305 | unixctl_command_reply(conn, "already unblocked"); | |
2b07c8b1 BP |
1306 | } |
1307 | } | |
1308 | ||
064af421 | 1309 | static void |
0caf6bde BP |
1310 | monitor_vconn(struct vconn *vconn) |
1311 | { | |
bb638b9a | 1312 | struct barrier_aux barrier_aux = { vconn, NULL }; |
1eb85ef5 EJ |
1313 | struct unixctl_server *server; |
1314 | bool exiting = false; | |
4f8f2439 | 1315 | bool blocked = false; |
7d0c5973 | 1316 | int error; |
1eb85ef5 | 1317 | |
7d0c5973 | 1318 | daemon_save_fd(STDERR_FILENO); |
1eb85ef5 EJ |
1319 | daemonize_start(); |
1320 | error = unixctl_server_create(NULL, &server); | |
1321 | if (error) { | |
1322 | ovs_fatal(error, "failed to create unixctl server"); | |
1323 | } | |
1324 | unixctl_command_register("exit", "", 0, 0, ofctl_exit, &exiting); | |
96761f58 BP |
1325 | unixctl_command_register("ofctl/send", "OFMSG...", 1, INT_MAX, |
1326 | ofctl_send, vconn); | |
bb638b9a BP |
1327 | unixctl_command_register("ofctl/barrier", "", 0, 0, |
1328 | ofctl_barrier, &barrier_aux); | |
1e1d00a5 BP |
1329 | unixctl_command_register("ofctl/set-output-file", "FILE", 1, 1, |
1330 | ofctl_set_output_file, NULL); | |
2b07c8b1 | 1331 | |
4f8f2439 BP |
1332 | unixctl_command_register("ofctl/block", "", 0, 0, ofctl_block, &blocked); |
1333 | unixctl_command_register("ofctl/unblock", "", 0, 0, ofctl_unblock, | |
1334 | &blocked); | |
2b07c8b1 | 1335 | |
1eb85ef5 EJ |
1336 | daemonize_complete(); |
1337 | ||
0caf6bde BP |
1338 | for (;;) { |
1339 | struct ofpbuf *b; | |
1eb85ef5 EJ |
1340 | int retval; |
1341 | ||
1342 | unixctl_server_run(server); | |
982697a4 | 1343 | |
4f8f2439 | 1344 | while (!blocked) { |
982697a4 | 1345 | enum ofptype type; |
bb638b9a | 1346 | |
1eb85ef5 EJ |
1347 | retval = vconn_recv(vconn, &b); |
1348 | if (retval == EAGAIN) { | |
1349 | break; | |
1350 | } | |
1eb85ef5 | 1351 | run(retval, "vconn_recv"); |
31c6fcd7 | 1352 | |
0c9560b7 BP |
1353 | if (timestamp) { |
1354 | time_t now = time_wall(); | |
1355 | char s[32]; | |
1356 | ||
3123c8fd | 1357 | strftime(s, sizeof s, "%Y-%m-%d %H:%M:%S: ", gmtime(&now)); |
0c9560b7 BP |
1358 | fputs(s, stderr); |
1359 | } | |
31c6fcd7 | 1360 | |
982697a4 | 1361 | ofptype_decode(&type, b->data); |
1eb85ef5 EJ |
1362 | ofp_print(stderr, b->data, b->size, verbosity + 2); |
1363 | ofpbuf_delete(b); | |
bb638b9a | 1364 | |
982697a4 | 1365 | if (barrier_aux.conn && type == OFPTYPE_BARRIER_REPLY) { |
bde9f75d | 1366 | unixctl_command_reply(barrier_aux.conn, NULL); |
bb638b9a BP |
1367 | barrier_aux.conn = NULL; |
1368 | } | |
1eb85ef5 EJ |
1369 | } |
1370 | ||
1371 | if (exiting) { | |
1372 | break; | |
1373 | } | |
1374 | ||
1375 | vconn_run(vconn); | |
1376 | vconn_run_wait(vconn); | |
4f8f2439 BP |
1377 | if (!blocked) { |
1378 | vconn_recv_wait(vconn); | |
1379 | } | |
1eb85ef5 EJ |
1380 | unixctl_server_wait(server); |
1381 | poll_block(); | |
0caf6bde | 1382 | } |
828c72d0 BP |
1383 | vconn_close(vconn); |
1384 | unixctl_server_destroy(server); | |
0caf6bde BP |
1385 | } |
1386 | ||
1387 | static void | |
e1fef0f9 | 1388 | ofctl_monitor(int argc, char *argv[]) |
064af421 BP |
1389 | { |
1390 | struct vconn *vconn; | |
2b07c8b1 | 1391 | int i; |
064af421 BP |
1392 | |
1393 | open_vconn(argv[1], &vconn); | |
2b07c8b1 BP |
1394 | for (i = 2; i < argc; i++) { |
1395 | const char *arg = argv[i]; | |
064af421 | 1396 | |
2b07c8b1 BP |
1397 | if (isdigit((unsigned char) *arg)) { |
1398 | struct ofp_switch_config config; | |
1399 | ||
1400 | fetch_switch_config(vconn, &config); | |
1401 | config.miss_send_len = htons(atoi(arg)); | |
1402 | set_switch_config(vconn, &config); | |
1403 | } else if (!strcmp(arg, "invalid_ttl")) { | |
f0fd1a17 | 1404 | monitor_set_invalid_ttl_to_controller(vconn); |
2b07c8b1 BP |
1405 | } else if (!strncmp(arg, "watch:", 6)) { |
1406 | struct ofputil_flow_monitor_request fmr; | |
1407 | struct ofpbuf *msg; | |
1408 | ||
1409 | parse_flow_monitor_request(&fmr, arg + 6); | |
1410 | ||
1411 | msg = ofpbuf_new(0); | |
1412 | ofputil_append_flow_monitor_request(&fmr, msg); | |
53514387 | 1413 | dump_stats_transaction(vconn, msg); |
2b07c8b1 BP |
1414 | } else { |
1415 | ovs_fatal(0, "%s: unsupported \"monitor\" argument", arg); | |
f0fd1a17 PS |
1416 | } |
1417 | } | |
2b07c8b1 | 1418 | |
ca8526e0 BP |
1419 | if (preferred_packet_in_format >= 0) { |
1420 | set_packet_in_format(vconn, preferred_packet_in_format); | |
1421 | } else { | |
f02b12c4 SH |
1422 | enum ofp_version version = vconn_get_version(vconn); |
1423 | ||
1424 | switch (version) { | |
1425 | case OFP10_VERSION: { | |
1426 | struct ofpbuf *spif, *reply; | |
1427 | ||
1428 | spif = ofputil_make_set_packet_in_format(vconn_get_version(vconn), | |
1429 | NXPIF_NXM); | |
1430 | run(vconn_transact_noreply(vconn, spif, &reply), | |
1431 | "talking to %s", vconn_get_name(vconn)); | |
1432 | if (reply) { | |
1433 | char *s = ofp_to_string(reply->data, reply->size, 2); | |
1434 | VLOG_DBG("%s: failed to set packet in format to nxm, controller" | |
1435 | " replied: %s. Falling back to the switch default.", | |
1436 | vconn_get_name(vconn), s); | |
1437 | free(s); | |
1438 | ofpbuf_delete(reply); | |
1439 | } | |
1440 | break; | |
1441 | } | |
1442 | case OFP11_VERSION: | |
1443 | case OFP12_VERSION: | |
1444 | case OFP13_VERSION: | |
1445 | break; | |
1446 | default: | |
1447 | NOT_REACHED(); | |
ca8526e0 BP |
1448 | } |
1449 | } | |
1450 | ||
0caf6bde BP |
1451 | monitor_vconn(vconn); |
1452 | } | |
1453 | ||
1454 | static void | |
e1fef0f9 | 1455 | ofctl_snoop(int argc OVS_UNUSED, char *argv[]) |
0caf6bde BP |
1456 | { |
1457 | struct vconn *vconn; | |
1458 | ||
1459 | open_vconn__(argv[1], "snoop", &vconn); | |
1460 | monitor_vconn(vconn); | |
064af421 BP |
1461 | } |
1462 | ||
1463 | static void | |
e1fef0f9 | 1464 | ofctl_dump_ports(int argc, char *argv[]) |
064af421 | 1465 | { |
abaad8cf | 1466 | struct ofpbuf *request; |
53514387 | 1467 | struct vconn *vconn; |
abaad8cf JP |
1468 | uint16_t port; |
1469 | ||
53514387 | 1470 | open_vconn(argv[1], &vconn); |
7f05e7ab | 1471 | port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_ANY; |
f8e4867e | 1472 | request = ofputil_encode_dump_ports_request(vconn_get_version(vconn), port); |
53514387 SH |
1473 | dump_stats_transaction(vconn, request); |
1474 | vconn_close(vconn); | |
064af421 BP |
1475 | } |
1476 | ||
2be393ed | 1477 | static void |
e1fef0f9 | 1478 | ofctl_dump_ports_desc(int argc OVS_UNUSED, char *argv[]) |
2be393ed | 1479 | { |
982697a4 | 1480 | dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_PORT_DESC_REQUEST); |
2be393ed JP |
1481 | } |
1482 | ||
064af421 | 1483 | static void |
e1fef0f9 | 1484 | ofctl_probe(int argc OVS_UNUSED, char *argv[]) |
064af421 BP |
1485 | { |
1486 | struct ofpbuf *request; | |
1487 | struct vconn *vconn; | |
1488 | struct ofpbuf *reply; | |
1489 | ||
064af421 | 1490 | open_vconn(argv[1], &vconn); |
1a126c0c | 1491 | request = make_echo_request(vconn_get_version(vconn)); |
064af421 BP |
1492 | run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]); |
1493 | if (reply->size != sizeof(struct ofp_header)) { | |
1494 | ovs_fatal(0, "reply does not match request"); | |
1495 | } | |
1496 | ofpbuf_delete(reply); | |
1497 | vconn_close(vconn); | |
1498 | } | |
1499 | ||
0c3d5fc8 | 1500 | static void |
e1fef0f9 | 1501 | ofctl_packet_out(int argc, char *argv[]) |
0c3d5fc8 | 1502 | { |
de0f3156 | 1503 | enum ofputil_protocol protocol; |
0c3d5fc8 | 1504 | struct ofputil_packet_out po; |
f25d0cf3 | 1505 | struct ofpbuf ofpacts; |
0c3d5fc8 BP |
1506 | struct vconn *vconn; |
1507 | int i; | |
1508 | ||
f25d0cf3 BP |
1509 | ofpbuf_init(&ofpacts, 64); |
1510 | parse_ofpacts(argv[3], &ofpacts); | |
0c3d5fc8 BP |
1511 | |
1512 | po.buffer_id = UINT32_MAX; | |
c6100d92 | 1513 | po.in_port = str_to_port_no(argv[1], argv[2]); |
f25d0cf3 BP |
1514 | po.ofpacts = ofpacts.data; |
1515 | po.ofpacts_len = ofpacts.size; | |
0c3d5fc8 | 1516 | |
de0f3156 | 1517 | protocol = open_vconn(argv[1], &vconn); |
0c3d5fc8 BP |
1518 | for (i = 4; i < argc; i++) { |
1519 | struct ofpbuf *packet, *opo; | |
1520 | const char *error_msg; | |
1521 | ||
1522 | error_msg = eth_from_hex(argv[i], &packet); | |
1523 | if (error_msg) { | |
1524 | ovs_fatal(0, "%s", error_msg); | |
1525 | } | |
1526 | ||
1527 | po.packet = packet->data; | |
1528 | po.packet_len = packet->size; | |
de0f3156 | 1529 | opo = ofputil_encode_packet_out(&po, protocol); |
0c3d5fc8 BP |
1530 | transact_noreply(vconn, opo); |
1531 | ofpbuf_delete(packet); | |
1532 | } | |
1533 | vconn_close(vconn); | |
f25d0cf3 | 1534 | ofpbuf_uninit(&ofpacts); |
0c3d5fc8 BP |
1535 | } |
1536 | ||
064af421 | 1537 | static void |
e1fef0f9 | 1538 | ofctl_mod_port(int argc OVS_UNUSED, char *argv[]) |
064af421 | 1539 | { |
28124950 BP |
1540 | struct ofp_config_flag { |
1541 | const char *name; /* The flag's name. */ | |
1542 | enum ofputil_port_config bit; /* Bit to turn on or off. */ | |
1543 | bool on; /* Value to set the bit to. */ | |
1544 | }; | |
1545 | static const struct ofp_config_flag flags[] = { | |
1546 | { "up", OFPUTIL_PC_PORT_DOWN, false }, | |
1547 | { "down", OFPUTIL_PC_PORT_DOWN, true }, | |
1548 | { "stp", OFPUTIL_PC_NO_STP, false }, | |
1549 | { "receive", OFPUTIL_PC_NO_RECV, false }, | |
1550 | { "receive-stp", OFPUTIL_PC_NO_RECV_STP, false }, | |
1551 | { "flood", OFPUTIL_PC_NO_FLOOD, false }, | |
1552 | { "forward", OFPUTIL_PC_NO_FWD, false }, | |
1553 | { "packet-in", OFPUTIL_PC_NO_PACKET_IN, false }, | |
1554 | }; | |
1555 | ||
1556 | const struct ofp_config_flag *flag; | |
9e1fd49b BP |
1557 | enum ofputil_protocol protocol; |
1558 | struct ofputil_port_mod pm; | |
1559 | struct ofputil_phy_port pp; | |
064af421 | 1560 | struct vconn *vconn; |
28124950 BP |
1561 | const char *command; |
1562 | bool not; | |
064af421 | 1563 | |
9e1fd49b | 1564 | fetch_ofputil_phy_port(argv[1], argv[2], &pp); |
064af421 | 1565 | |
9e1fd49b BP |
1566 | pm.port_no = pp.port_no; |
1567 | memcpy(pm.hw_addr, pp.hw_addr, ETH_ADDR_LEN); | |
1568 | pm.config = 0; | |
1569 | pm.mask = 0; | |
1570 | pm.advertise = 0; | |
064af421 | 1571 | |
28124950 BP |
1572 | if (!strncasecmp(argv[3], "no-", 3)) { |
1573 | command = argv[3] + 3; | |
1574 | not = true; | |
1575 | } else if (!strncasecmp(argv[3], "no", 2)) { | |
1576 | command = argv[3] + 2; | |
1577 | not = true; | |
064af421 | 1578 | } else { |
28124950 BP |
1579 | command = argv[3]; |
1580 | not = false; | |
1581 | } | |
1582 | for (flag = flags; flag < &flags[ARRAY_SIZE(flags)]; flag++) { | |
1583 | if (!strcasecmp(command, flag->name)) { | |
1584 | pm.mask = flag->bit; | |
1585 | pm.config = flag->on ^ not ? flag->bit : 0; | |
1586 | goto found; | |
1587 | } | |
064af421 | 1588 | } |
28124950 | 1589 | ovs_fatal(0, "unknown mod-port command '%s'", argv[3]); |
064af421 | 1590 | |
28124950 | 1591 | found: |
9e1fd49b BP |
1592 | protocol = open_vconn(argv[1], &vconn); |
1593 | transact_noreply(vconn, ofputil_encode_port_mod(&pm, protocol)); | |
064af421 BP |
1594 | vconn_close(vconn); |
1595 | } | |
1596 | ||
7257b535 | 1597 | static void |
e1fef0f9 | 1598 | ofctl_get_frags(int argc OVS_UNUSED, char *argv[]) |
7257b535 BP |
1599 | { |
1600 | struct ofp_switch_config config; | |
1601 | struct vconn *vconn; | |
1602 | ||
1603 | open_vconn(argv[1], &vconn); | |
1604 | fetch_switch_config(vconn, &config); | |
1605 | puts(ofputil_frag_handling_to_string(ntohs(config.flags))); | |
1606 | vconn_close(vconn); | |
1607 | } | |
1608 | ||
1609 | static void | |
e1fef0f9 | 1610 | ofctl_set_frags(int argc OVS_UNUSED, char *argv[]) |
7257b535 BP |
1611 | { |
1612 | struct ofp_switch_config config; | |
1613 | enum ofp_config_flags mode; | |
1614 | struct vconn *vconn; | |
1615 | ovs_be16 flags; | |
1616 | ||
1617 | if (!ofputil_frag_handling_from_string(argv[2], &mode)) { | |
1618 | ovs_fatal(0, "%s: unknown fragment handling mode", argv[2]); | |
1619 | } | |
1620 | ||
1621 | open_vconn(argv[1], &vconn); | |
1622 | fetch_switch_config(vconn, &config); | |
1623 | flags = htons(mode) | (config.flags & htons(~OFPC_FRAG_MASK)); | |
1624 | if (flags != config.flags) { | |
1625 | /* Set the configuration. */ | |
1626 | config.flags = flags; | |
1627 | set_switch_config(vconn, &config); | |
1628 | ||
1629 | /* Then retrieve the configuration to see if it really took. OpenFlow | |
1630 | * doesn't define error reporting for bad modes, so this is all we can | |
1631 | * do. */ | |
1632 | fetch_switch_config(vconn, &config); | |
1633 | if (flags != config.flags) { | |
1634 | ovs_fatal(0, "%s: setting fragment handling mode failed (this " | |
1635 | "switch probably doesn't support mode \"%s\")", | |
1636 | argv[1], ofputil_frag_handling_to_string(mode)); | |
1637 | } | |
1638 | } | |
1639 | vconn_close(vconn); | |
1640 | } | |
1641 | ||
064af421 | 1642 | static void |
e1fef0f9 | 1643 | ofctl_ping(int argc, char *argv[]) |
064af421 BP |
1644 | { |
1645 | size_t max_payload = 65535 - sizeof(struct ofp_header); | |
1646 | unsigned int payload; | |
1647 | struct vconn *vconn; | |
1648 | int i; | |
1649 | ||
1650 | payload = argc > 2 ? atoi(argv[2]) : 64; | |
1651 | if (payload > max_payload) { | |
1652 | ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload); | |
1653 | } | |
1654 | ||
1655 | open_vconn(argv[1], &vconn); | |
1656 | for (i = 0; i < 10; i++) { | |
1657 | struct timeval start, end; | |
1658 | struct ofpbuf *request, *reply; | |
982697a4 BP |
1659 | const struct ofp_header *rpy_hdr; |
1660 | enum ofptype type; | |
064af421 | 1661 | |
a53a8efa SH |
1662 | request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST, |
1663 | vconn_get_version(vconn), payload); | |
982697a4 | 1664 | random_bytes(ofpbuf_put_uninit(request, payload), payload); |
064af421 | 1665 | |
279c9e03 | 1666 | xgettimeofday(&start); |
064af421 | 1667 | run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact"); |
279c9e03 | 1668 | xgettimeofday(&end); |
064af421 BP |
1669 | |
1670 | rpy_hdr = reply->data; | |
982697a4 BP |
1671 | if (ofptype_pull(&type, reply) |
1672 | || type != OFPTYPE_ECHO_REPLY | |
1673 | || reply->size != payload | |
1674 | || memcmp(request->l3, reply->l3, payload)) { | |
064af421 | 1675 | printf("Reply does not match request. Request:\n"); |
4f564f8d | 1676 | ofp_print(stdout, request, request->size, verbosity + 2); |
064af421 | 1677 | printf("Reply:\n"); |
4f564f8d | 1678 | ofp_print(stdout, reply, reply->size, verbosity + 2); |
064af421 | 1679 | } |
2886875a | 1680 | printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n", |
982697a4 | 1681 | reply->size, argv[1], ntohl(rpy_hdr->xid), |
064af421 BP |
1682 | (1000*(double)(end.tv_sec - start.tv_sec)) |
1683 | + (.001*(end.tv_usec - start.tv_usec))); | |
1684 | ofpbuf_delete(request); | |
1685 | ofpbuf_delete(reply); | |
1686 | } | |
1687 | vconn_close(vconn); | |
1688 | } | |
1689 | ||
1690 | static void | |
e1fef0f9 | 1691 | ofctl_benchmark(int argc OVS_UNUSED, char *argv[]) |
064af421 BP |
1692 | { |
1693 | size_t max_payload = 65535 - sizeof(struct ofp_header); | |
1694 | struct timeval start, end; | |
1695 | unsigned int payload_size, message_size; | |
1696 | struct vconn *vconn; | |
1697 | double duration; | |
1698 | int count; | |
1699 | int i; | |
1700 | ||
1701 | payload_size = atoi(argv[2]); | |
1702 | if (payload_size > max_payload) { | |
1703 | ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload); | |
1704 | } | |
1705 | message_size = sizeof(struct ofp_header) + payload_size; | |
1706 | ||
1707 | count = atoi(argv[3]); | |
1708 | ||
1709 | printf("Sending %d packets * %u bytes (with header) = %u bytes total\n", | |
1710 | count, message_size, count * message_size); | |
1711 | ||
1712 | open_vconn(argv[1], &vconn); | |
279c9e03 | 1713 | xgettimeofday(&start); |
064af421 BP |
1714 | for (i = 0; i < count; i++) { |
1715 | struct ofpbuf *request, *reply; | |
064af421 | 1716 | |
a53a8efa SH |
1717 | request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST, |
1718 | vconn_get_version(vconn), payload_size); | |
982697a4 | 1719 | ofpbuf_put_zeros(request, payload_size); |
064af421 BP |
1720 | run(vconn_transact(vconn, request, &reply), "transact"); |
1721 | ofpbuf_delete(reply); | |
1722 | } | |
279c9e03 | 1723 | xgettimeofday(&end); |
064af421 BP |
1724 | vconn_close(vconn); |
1725 | ||
1726 | duration = ((1000*(double)(end.tv_sec - start.tv_sec)) | |
1727 | + (.001*(end.tv_usec - start.tv_usec))); | |
1728 | printf("Finished in %.1f ms (%.0f packets/s) (%.0f bytes/s)\n", | |
1729 | duration, count / (duration / 1000.0), | |
1730 | count * message_size / (duration / 1000.0)); | |
1731 | } | |
1732 | ||
09246b99 | 1733 | static void |
e1fef0f9 | 1734 | ofctl_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
09246b99 BP |
1735 | { |
1736 | usage(); | |
1737 | } | |
1738 | \f | |
0199c526 BP |
1739 | /* replace-flows and diff-flows commands. */ |
1740 | ||
1741 | /* A flow table entry, possibly with two different versions. */ | |
1742 | struct fte { | |
1743 | struct cls_rule rule; /* Within a "struct classifier". */ | |
1744 | struct fte_version *versions[2]; | |
1745 | }; | |
1746 | ||
1747 | /* One version of a Flow Table Entry. */ | |
1748 | struct fte_version { | |
1749 | ovs_be64 cookie; | |
1750 | uint16_t idle_timeout; | |
1751 | uint16_t hard_timeout; | |
1752 | uint16_t flags; | |
f25d0cf3 BP |
1753 | struct ofpact *ofpacts; |
1754 | size_t ofpacts_len; | |
0199c526 BP |
1755 | }; |
1756 | ||
1757 | /* Frees 'version' and the data that it owns. */ | |
1758 | static void | |
1759 | fte_version_free(struct fte_version *version) | |
1760 | { | |
1761 | if (version) { | |
f25d0cf3 | 1762 | free(version->ofpacts); |
0199c526 BP |
1763 | free(version); |
1764 | } | |
1765 | } | |
1766 | ||
1767 | /* Returns true if 'a' and 'b' are the same, false if they differ. | |
1768 | * | |
1769 | * Ignores differences in 'flags' because there's no way to retrieve flags from | |
1770 | * an OpenFlow switch. We have to assume that they are the same. */ | |
1771 | static bool | |
1772 | fte_version_equals(const struct fte_version *a, const struct fte_version *b) | |
1773 | { | |
1774 | return (a->cookie == b->cookie | |
1775 | && a->idle_timeout == b->idle_timeout | |
1776 | && a->hard_timeout == b->hard_timeout | |
f25d0cf3 BP |
1777 | && ofpacts_equal(a->ofpacts, a->ofpacts_len, |
1778 | b->ofpacts, b->ofpacts_len)); | |
0199c526 BP |
1779 | } |
1780 | ||
98f7f427 BP |
1781 | /* Clears 's', then if 's' has a version 'index', formats 'fte' and version |
1782 | * 'index' into 's', followed by a new-line. */ | |
0199c526 | 1783 | static void |
98f7f427 | 1784 | fte_version_format(const struct fte *fte, int index, struct ds *s) |
0199c526 | 1785 | { |
98f7f427 | 1786 | const struct fte_version *version = fte->versions[index]; |
0199c526 | 1787 | |
98f7f427 BP |
1788 | ds_clear(s); |
1789 | if (!version) { | |
1790 | return; | |
1791 | } | |
1792 | ||
1793 | cls_rule_format(&fte->rule, s); | |
0199c526 | 1794 | if (version->cookie != htonll(0)) { |
98f7f427 | 1795 | ds_put_format(s, " cookie=0x%"PRIx64, ntohll(version->cookie)); |
0199c526 BP |
1796 | } |
1797 | if (version->idle_timeout != OFP_FLOW_PERMANENT) { | |
98f7f427 | 1798 | ds_put_format(s, " idle_timeout=%"PRIu16, version->idle_timeout); |
0199c526 BP |
1799 | } |
1800 | if (version->hard_timeout != OFP_FLOW_PERMANENT) { | |
98f7f427 | 1801 | ds_put_format(s, " hard_timeout=%"PRIu16, version->hard_timeout); |
0199c526 BP |
1802 | } |
1803 | ||
98f7f427 BP |
1804 | ds_put_char(s, ' '); |
1805 | ofpacts_format(version->ofpacts, version->ofpacts_len, s); | |
1806 | ||
1807 | ds_put_char(s, '\n'); | |
0199c526 BP |
1808 | } |
1809 | ||
1810 | static struct fte * | |
1811 | fte_from_cls_rule(const struct cls_rule *cls_rule) | |
1812 | { | |
1813 | return cls_rule ? CONTAINER_OF(cls_rule, struct fte, rule) : NULL; | |
1814 | } | |
1815 | ||
1816 | /* Frees 'fte' and its versions. */ | |
1817 | static void | |
1818 | fte_free(struct fte *fte) | |
1819 | { | |
1820 | if (fte) { | |
1821 | fte_version_free(fte->versions[0]); | |
1822 | fte_version_free(fte->versions[1]); | |
48d28ac1 | 1823 | cls_rule_destroy(&fte->rule); |
0199c526 BP |
1824 | free(fte); |
1825 | } | |
1826 | } | |
1827 | ||
1828 | /* Frees all of the FTEs within 'cls'. */ | |
1829 | static void | |
1830 | fte_free_all(struct classifier *cls) | |
1831 | { | |
1832 | struct cls_cursor cursor; | |
1833 | struct fte *fte, *next; | |
1834 | ||
1835 | cls_cursor_init(&cursor, cls, NULL); | |
1836 | CLS_CURSOR_FOR_EACH_SAFE (fte, next, rule, &cursor) { | |
1837 | classifier_remove(cls, &fte->rule); | |
1838 | fte_free(fte); | |
1839 | } | |
e49190c4 | 1840 | classifier_destroy(cls); |
0199c526 BP |
1841 | } |
1842 | ||
1843 | /* Searches 'cls' for an FTE matching 'rule', inserting a new one if | |
1844 | * necessary. Sets 'version' as the version of that rule with the given | |
1845 | * 'index', replacing any existing version, if any. | |
1846 | * | |
1847 | * Takes ownership of 'version'. */ | |
1848 | static void | |
81a76618 BP |
1849 | fte_insert(struct classifier *cls, const struct match *match, |
1850 | unsigned int priority, struct fte_version *version, int index) | |
0199c526 BP |
1851 | { |
1852 | struct fte *old, *fte; | |
1853 | ||
1854 | fte = xzalloc(sizeof *fte); | |
81a76618 | 1855 | cls_rule_init(&fte->rule, match, priority); |
0199c526 BP |
1856 | fte->versions[index] = version; |
1857 | ||
08944c1d | 1858 | old = fte_from_cls_rule(classifier_replace(cls, &fte->rule)); |
0199c526 BP |
1859 | if (old) { |
1860 | fte_version_free(old->versions[index]); | |
1861 | fte->versions[!index] = old->versions[!index]; | |
48d28ac1 | 1862 | cls_rule_destroy(&old->rule); |
0199c526 BP |
1863 | free(old); |
1864 | } | |
1865 | } | |
1866 | ||
1867 | /* Reads the flows in 'filename' as flow table entries in 'cls' for the version | |
27527aa0 BP |
1868 | * with the specified 'index'. Returns the flow formats able to represent the |
1869 | * flows that were read. */ | |
1870 | static enum ofputil_protocol | |
0199c526 BP |
1871 | read_flows_from_file(const char *filename, struct classifier *cls, int index) |
1872 | { | |
27527aa0 | 1873 | enum ofputil_protocol usable_protocols; |
0199c526 BP |
1874 | struct ds s; |
1875 | FILE *file; | |
1876 | ||
1877 | file = !strcmp(filename, "-") ? stdin : fopen(filename, "r"); | |
1878 | if (file == NULL) { | |
1879 | ovs_fatal(errno, "%s: open", filename); | |
1880 | } | |
1881 | ||
1882 | ds_init(&s); | |
27527aa0 | 1883 | usable_protocols = OFPUTIL_P_ANY; |
0199c526 BP |
1884 | while (!ds_get_preprocessed_line(&s, file)) { |
1885 | struct fte_version *version; | |
a9a2da38 | 1886 | struct ofputil_flow_mod fm; |
0199c526 | 1887 | |
c821124b | 1888 | parse_ofp_str(&fm, OFPFC_ADD, ds_cstr(&s), true); |
0199c526 BP |
1889 | |
1890 | version = xmalloc(sizeof *version); | |
623e1caf | 1891 | version->cookie = fm.new_cookie; |
0199c526 BP |
1892 | version->idle_timeout = fm.idle_timeout; |
1893 | version->hard_timeout = fm.hard_timeout; | |
35805806 | 1894 | version->flags = fm.flags & (OFPFF_SEND_FLOW_REM | OFPFF10_EMERG); |
f25d0cf3 BP |
1895 | version->ofpacts = fm.ofpacts; |
1896 | version->ofpacts_len = fm.ofpacts_len; | |
0199c526 | 1897 | |
81a76618 | 1898 | usable_protocols &= ofputil_usable_protocols(&fm.match); |
0199c526 | 1899 | |
81a76618 | 1900 | fte_insert(cls, &fm.match, fm.priority, version, index); |
0199c526 BP |
1901 | } |
1902 | ds_destroy(&s); | |
1903 | ||
1904 | if (file != stdin) { | |
1905 | fclose(file); | |
1906 | } | |
1907 | ||
27527aa0 | 1908 | return usable_protocols; |
0199c526 BP |
1909 | } |
1910 | ||
4ce9c315 BP |
1911 | static bool |
1912 | recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid, | |
1913 | struct ofpbuf **replyp, | |
1914 | struct ofputil_flow_stats *fs, struct ofpbuf *ofpacts) | |
1915 | { | |
1916 | struct ofpbuf *reply = *replyp; | |
1917 | ||
1918 | for (;;) { | |
4ce9c315 | 1919 | int retval; |
35805806 | 1920 | bool more; |
4ce9c315 BP |
1921 | |
1922 | /* Get a flow stats reply message, if we don't already have one. */ | |
1923 | if (!reply) { | |
982697a4 BP |
1924 | enum ofptype type; |
1925 | enum ofperr error; | |
4ce9c315 BP |
1926 | |
1927 | do { | |
1928 | run(vconn_recv_block(vconn, &reply), | |
1929 | "OpenFlow packet receive failed"); | |
1930 | } while (((struct ofp_header *) reply->data)->xid != send_xid); | |
1931 | ||
982697a4 BP |
1932 | error = ofptype_decode(&type, reply->data); |
1933 | if (error || type != OFPTYPE_FLOW_STATS_REPLY) { | |
4ce9c315 BP |
1934 | ovs_fatal(0, "received bad reply: %s", |
1935 | ofp_to_string(reply->data, reply->size, | |
1936 | verbosity + 1)); | |
1937 | } | |
1938 | } | |
1939 | ||
1940 | /* Pull an individual flow stats reply out of the message. */ | |
1941 | retval = ofputil_decode_flow_stats_reply(fs, reply, false, ofpacts); | |
1942 | switch (retval) { | |
1943 | case 0: | |
1944 | *replyp = reply; | |
1945 | return true; | |
1946 | ||
1947 | case EOF: | |
35805806 | 1948 | more = ofpmp_more(reply->l2); |
4ce9c315 | 1949 | ofpbuf_delete(reply); |
296ed880 | 1950 | reply = NULL; |
35805806 | 1951 | if (!more) { |
4ce9c315 BP |
1952 | *replyp = NULL; |
1953 | return false; | |
1954 | } | |
1955 | break; | |
1956 | ||
1957 | default: | |
1958 | ovs_fatal(0, "parse error in reply (%s)", | |
1959 | ofperr_to_string(retval)); | |
1960 | } | |
1961 | } | |
1962 | } | |
1963 | ||
0199c526 | 1964 | /* Reads the OpenFlow flow table from 'vconn', which has currently active flow |
27527aa0 | 1965 | * format 'protocol', and adds them as flow table entries in 'cls' for the |
0199c526 BP |
1966 | * version with the specified 'index'. */ |
1967 | static void | |
27527aa0 BP |
1968 | read_flows_from_switch(struct vconn *vconn, |
1969 | enum ofputil_protocol protocol, | |
0199c526 BP |
1970 | struct classifier *cls, int index) |
1971 | { | |
81d1ea94 | 1972 | struct ofputil_flow_stats_request fsr; |
4ce9c315 | 1973 | struct ofputil_flow_stats fs; |
0199c526 | 1974 | struct ofpbuf *request; |
4ce9c315 BP |
1975 | struct ofpbuf ofpacts; |
1976 | struct ofpbuf *reply; | |
0199c526 | 1977 | ovs_be32 send_xid; |
0199c526 BP |
1978 | |
1979 | fsr.aggregate = false; | |
81a76618 | 1980 | match_init_catchall(&fsr.match); |
7f05e7ab | 1981 | fsr.out_port = OFPP_ANY; |
0199c526 | 1982 | fsr.table_id = 0xff; |
ecc798ab | 1983 | fsr.cookie = fsr.cookie_mask = htonll(0); |
27527aa0 | 1984 | request = ofputil_encode_flow_stats_request(&fsr, protocol); |
0199c526 BP |
1985 | send_xid = ((struct ofp_header *) request->data)->xid; |
1986 | send_openflow_buffer(vconn, request); | |
1987 | ||
4ce9c315 BP |
1988 | reply = NULL; |
1989 | ofpbuf_init(&ofpacts, 0); | |
1990 | while (recv_flow_stats_reply(vconn, send_xid, &reply, &fs, &ofpacts)) { | |
1991 | struct fte_version *version; | |
0199c526 | 1992 | |
4ce9c315 BP |
1993 | version = xmalloc(sizeof *version); |
1994 | version->cookie = fs.cookie; | |
1995 | version->idle_timeout = fs.idle_timeout; | |
1996 | version->hard_timeout = fs.hard_timeout; | |
1997 | version->flags = 0; | |
1998 | version->ofpacts_len = fs.ofpacts_len; | |
1999 | version->ofpacts = xmemdup(fs.ofpacts, fs.ofpacts_len); | |
2000 | ||
81a76618 | 2001 | fte_insert(cls, &fs.match, fs.priority, version, index); |
0199c526 | 2002 | } |
4ce9c315 | 2003 | ofpbuf_uninit(&ofpacts); |
0199c526 BP |
2004 | } |
2005 | ||
2006 | static void | |
2007 | fte_make_flow_mod(const struct fte *fte, int index, uint16_t command, | |
27527aa0 | 2008 | enum ofputil_protocol protocol, struct list *packets) |
0199c526 BP |
2009 | { |
2010 | const struct fte_version *version = fte->versions[index]; | |
a9a2da38 | 2011 | struct ofputil_flow_mod fm; |
0199c526 BP |
2012 | struct ofpbuf *ofm; |
2013 | ||
5cb7a798 | 2014 | minimatch_expand(&fte->rule.match, &fm.match); |
81a76618 | 2015 | fm.priority = fte->rule.priority; |
623e1caf JP |
2016 | fm.cookie = htonll(0); |
2017 | fm.cookie_mask = htonll(0); | |
2018 | fm.new_cookie = version->cookie; | |
6c1491fb | 2019 | fm.table_id = 0xff; |
0199c526 BP |
2020 | fm.command = command; |
2021 | fm.idle_timeout = version->idle_timeout; | |
2022 | fm.hard_timeout = version->hard_timeout; | |
2023 | fm.buffer_id = UINT32_MAX; | |
7f05e7ab | 2024 | fm.out_port = OFPP_ANY; |
0199c526 BP |
2025 | fm.flags = version->flags; |
2026 | if (command == OFPFC_ADD || command == OFPFC_MODIFY || | |
2027 | command == OFPFC_MODIFY_STRICT) { | |
f25d0cf3 BP |
2028 | fm.ofpacts = version->ofpacts; |
2029 | fm.ofpacts_len = version->ofpacts_len; | |
0199c526 | 2030 | } else { |
f25d0cf3 BP |
2031 | fm.ofpacts = NULL; |
2032 | fm.ofpacts_len = 0; | |
0199c526 BP |
2033 | } |
2034 | ||
27527aa0 | 2035 | ofm = ofputil_encode_flow_mod(&fm, protocol); |
0199c526 BP |
2036 | list_push_back(packets, &ofm->list_node); |
2037 | } | |
2038 | ||
2039 | static void | |
e1fef0f9 | 2040 | ofctl_replace_flows(int argc OVS_UNUSED, char *argv[]) |
0199c526 BP |
2041 | { |
2042 | enum { FILE_IDX = 0, SWITCH_IDX = 1 }; | |
27527aa0 | 2043 | enum ofputil_protocol usable_protocols, protocol; |
0199c526 BP |
2044 | struct cls_cursor cursor; |
2045 | struct classifier cls; | |
2046 | struct list requests; | |
2047 | struct vconn *vconn; | |
2048 | struct fte *fte; | |
2049 | ||
2050 | classifier_init(&cls); | |
27527aa0 | 2051 | usable_protocols = read_flows_from_file(argv[2], &cls, FILE_IDX); |
0199c526 | 2052 | |
27527aa0 BP |
2053 | protocol = open_vconn(argv[1], &vconn); |
2054 | protocol = set_protocol_for_flow_dump(vconn, protocol, usable_protocols); | |
2055 | ||
2056 | read_flows_from_switch(vconn, protocol, &cls, SWITCH_IDX); | |
0199c526 BP |
2057 | |
2058 | list_init(&requests); | |
2059 | ||
2060 | /* Delete flows that exist on the switch but not in the file. */ | |
2061 | cls_cursor_init(&cursor, &cls, NULL); | |
2062 | CLS_CURSOR_FOR_EACH (fte, rule, &cursor) { | |
2063 | struct fte_version *file_ver = fte->versions[FILE_IDX]; | |
2064 | struct fte_version *sw_ver = fte->versions[SWITCH_IDX]; | |
2065 | ||
2066 | if (sw_ver && !file_ver) { | |
2067 | fte_make_flow_mod(fte, SWITCH_IDX, OFPFC_DELETE_STRICT, | |
27527aa0 | 2068 | protocol, &requests); |
0199c526 BP |
2069 | } |
2070 | } | |
2071 | ||
2072 | /* Add flows that exist in the file but not on the switch. | |
2073 | * Update flows that exist in both places but differ. */ | |
2074 | cls_cursor_init(&cursor, &cls, NULL); | |
2075 | CLS_CURSOR_FOR_EACH (fte, rule, &cursor) { | |
2076 | struct fte_version *file_ver = fte->versions[FILE_IDX]; | |
2077 | struct fte_version *sw_ver = fte->versions[SWITCH_IDX]; | |
2078 | ||
c4ea79bf BP |
2079 | if (file_ver |
2080 | && (readd || !sw_ver || !fte_version_equals(sw_ver, file_ver))) { | |
27527aa0 | 2081 | fte_make_flow_mod(fte, FILE_IDX, OFPFC_ADD, protocol, &requests); |
0199c526 BP |
2082 | } |
2083 | } | |
2084 | transact_multiple_noreply(vconn, &requests); | |
2085 | vconn_close(vconn); | |
2086 | ||
2087 | fte_free_all(&cls); | |
2088 | } | |
2089 | ||
2090 | static void | |
2091 | read_flows_from_source(const char *source, struct classifier *cls, int index) | |
2092 | { | |
2093 | struct stat s; | |
2094 | ||
2095 | if (source[0] == '/' || source[0] == '.' | |
2096 | || (!strchr(source, ':') && !stat(source, &s))) { | |
2097 | read_flows_from_file(source, cls, index); | |
2098 | } else { | |
27527aa0 | 2099 | enum ofputil_protocol protocol; |
0199c526 BP |
2100 | struct vconn *vconn; |
2101 | ||
27527aa0 BP |
2102 | protocol = open_vconn(source, &vconn); |
2103 | protocol = set_protocol_for_flow_dump(vconn, protocol, OFPUTIL_P_ANY); | |
2104 | read_flows_from_switch(vconn, protocol, cls, index); | |
0199c526 BP |
2105 | vconn_close(vconn); |
2106 | } | |
2107 | } | |
2108 | ||
2109 | static void | |
e1fef0f9 | 2110 | ofctl_diff_flows(int argc OVS_UNUSED, char *argv[]) |
0199c526 BP |
2111 | { |
2112 | bool differences = false; | |
2113 | struct cls_cursor cursor; | |
2114 | struct classifier cls; | |
98f7f427 | 2115 | struct ds a_s, b_s; |
0199c526 BP |
2116 | struct fte *fte; |
2117 | ||
2118 | classifier_init(&cls); | |
2119 | read_flows_from_source(argv[1], &cls, 0); | |
2120 | read_flows_from_source(argv[2], &cls, 1); | |
2121 | ||
98f7f427 BP |
2122 | ds_init(&a_s); |
2123 | ds_init(&b_s); | |
2124 | ||
0199c526 BP |
2125 | cls_cursor_init(&cursor, &cls, NULL); |
2126 | CLS_CURSOR_FOR_EACH (fte, rule, &cursor) { | |
2127 | struct fte_version *a = fte->versions[0]; | |
2128 | struct fte_version *b = fte->versions[1]; | |
2129 | ||
2130 | if (!a || !b || !fte_version_equals(a, b)) { | |
98f7f427 BP |
2131 | fte_version_format(fte, 0, &a_s); |
2132 | fte_version_format(fte, 1, &b_s); | |
2133 | if (strcmp(ds_cstr(&a_s), ds_cstr(&b_s))) { | |
2134 | if (a_s.length) { | |
2135 | printf("-%s", ds_cstr(&a_s)); | |
2136 | } | |
2137 | if (b_s.length) { | |
2138 | printf("+%s", ds_cstr(&b_s)); | |
2139 | } | |
2140 | differences = true; | |
0199c526 | 2141 | } |
0199c526 BP |
2142 | } |
2143 | } | |
2144 | ||
98f7f427 BP |
2145 | ds_destroy(&a_s); |
2146 | ds_destroy(&b_s); | |
2147 | ||
0199c526 BP |
2148 | fte_free_all(&cls); |
2149 | ||
2150 | if (differences) { | |
2151 | exit(2); | |
2152 | } | |
2153 | } | |
2154 | \f | |
09246b99 BP |
2155 | /* Undocumented commands for unit testing. */ |
2156 | ||
770f1f66 | 2157 | static void |
e1fef0f9 | 2158 | ofctl_parse_flows__(struct ofputil_flow_mod *fms, size_t n_fms) |
770f1f66 | 2159 | { |
27527aa0 BP |
2160 | enum ofputil_protocol usable_protocols; |
2161 | enum ofputil_protocol protocol = 0; | |
2162 | char *usable_s; | |
2163 | size_t i; | |
770f1f66 | 2164 | |
27527aa0 BP |
2165 | usable_protocols = ofputil_flow_mod_usable_protocols(fms, n_fms); |
2166 | usable_s = ofputil_protocols_to_string(usable_protocols); | |
2167 | printf("usable protocols: %s\n", usable_s); | |
2168 | free(usable_s); | |
2169 | ||
2170 | if (!(usable_protocols & allowed_protocols)) { | |
2171 | ovs_fatal(0, "no usable protocol"); | |
2172 | } | |
2173 | for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) { | |
2174 | protocol = 1 << i; | |
2175 | if (protocol & usable_protocols & allowed_protocols) { | |
2176 | break; | |
2177 | } | |
2178 | } | |
cb22974d | 2179 | ovs_assert(IS_POW2(protocol)); |
27527aa0 BP |
2180 | |
2181 | printf("chosen protocol: %s\n", ofputil_protocol_to_string(protocol)); | |
2182 | ||
2183 | for (i = 0; i < n_fms; i++) { | |
2184 | struct ofputil_flow_mod *fm = &fms[i]; | |
2185 | struct ofpbuf *msg; | |
2186 | ||
2187 | msg = ofputil_encode_flow_mod(fm, protocol); | |
2188 | ofp_print(stdout, msg->data, msg->size, verbosity); | |
2189 | ofpbuf_delete(msg); | |
2190 | ||
f25d0cf3 | 2191 | free(fm->ofpacts); |
770f1f66 BP |
2192 | } |
2193 | } | |
2194 | ||
2195 | /* "parse-flow FLOW": parses the argument as a flow (like add-flow) and prints | |
2196 | * it back to stdout. */ | |
2197 | static void | |
e1fef0f9 | 2198 | ofctl_parse_flow(int argc OVS_UNUSED, char *argv[]) |
770f1f66 | 2199 | { |
27527aa0 | 2200 | struct ofputil_flow_mod fm; |
770f1f66 | 2201 | |
27527aa0 | 2202 | parse_ofp_flow_mod_str(&fm, argv[1], OFPFC_ADD, false); |
e1fef0f9 | 2203 | ofctl_parse_flows__(&fm, 1); |
770f1f66 BP |
2204 | } |
2205 | ||
fec00620 BP |
2206 | /* "parse-flows FILENAME": reads the named file as a sequence of flows (like |
2207 | * add-flows) and prints each of the flows back to stdout. */ | |
0e581146 | 2208 | static void |
e1fef0f9 | 2209 | ofctl_parse_flows(int argc OVS_UNUSED, char *argv[]) |
0e581146 | 2210 | { |
27527aa0 BP |
2211 | struct ofputil_flow_mod *fms = NULL; |
2212 | size_t n_fms = 0; | |
0e581146 | 2213 | |
27527aa0 | 2214 | parse_ofp_flow_mod_file(argv[1], OFPFC_ADD, &fms, &n_fms); |
e1fef0f9 | 2215 | ofctl_parse_flows__(fms, n_fms); |
27527aa0 | 2216 | free(fms); |
0e581146 BP |
2217 | } |
2218 | ||
064af421 | 2219 | static void |
e1fef0f9 | 2220 | ofctl_parse_nxm__(bool oxm) |
09246b99 BP |
2221 | { |
2222 | struct ds in; | |
2223 | ||
2224 | ds_init(&in); | |
06d7ae7d | 2225 | while (!ds_get_test_line(&in, stdin)) { |
09246b99 | 2226 | struct ofpbuf nx_match; |
81a76618 | 2227 | struct match match; |
e729e793 | 2228 | ovs_be64 cookie, cookie_mask; |
90bf1e07 | 2229 | enum ofperr error; |
09246b99 | 2230 | int match_len; |
09246b99 BP |
2231 | |
2232 | /* Convert string to nx_match. */ | |
2233 | ofpbuf_init(&nx_match, 0); | |
7623f4dd SH |
2234 | if (oxm) { |
2235 | match_len = oxm_match_from_string(ds_cstr(&in), &nx_match); | |
2236 | } else { | |
2237 | match_len = nx_match_from_string(ds_cstr(&in), &nx_match); | |
2238 | } | |
09246b99 | 2239 | |
81a76618 | 2240 | /* Convert nx_match to match. */ |
102ce766 | 2241 | if (strict) { |
7623f4dd | 2242 | if (oxm) { |
81a76618 | 2243 | error = oxm_pull_match(&nx_match, &match); |
7623f4dd | 2244 | } else { |
81a76618 | 2245 | error = nx_pull_match(&nx_match, match_len, &match, |
7623f4dd SH |
2246 | &cookie, &cookie_mask); |
2247 | } | |
102ce766 | 2248 | } else { |
7623f4dd | 2249 | if (oxm) { |
81a76618 | 2250 | error = oxm_pull_match_loose(&nx_match, &match); |
7623f4dd | 2251 | } else { |
81a76618 | 2252 | error = nx_pull_match_loose(&nx_match, match_len, &match, |
7623f4dd SH |
2253 | &cookie, &cookie_mask); |
2254 | } | |
102ce766 EJ |
2255 | } |
2256 | ||
7623f4dd | 2257 | |
09246b99 BP |
2258 | if (!error) { |
2259 | char *out; | |
2260 | ||
81a76618 | 2261 | /* Convert match back to nx_match. */ |
09246b99 BP |
2262 | ofpbuf_uninit(&nx_match); |
2263 | ofpbuf_init(&nx_match, 0); | |
7623f4dd | 2264 | if (oxm) { |
81a76618 | 2265 | match_len = oxm_put_match(&nx_match, &match); |
7623f4dd SH |
2266 | out = oxm_match_to_string(nx_match.data, match_len); |
2267 | } else { | |
81a76618 | 2268 | match_len = nx_put_match(&nx_match, &match, |
7623f4dd SH |
2269 | cookie, cookie_mask); |
2270 | out = nx_match_to_string(nx_match.data, match_len); | |
2271 | } | |
09246b99 | 2272 | |
09246b99 BP |
2273 | puts(out); |
2274 | free(out); | |
2275 | } else { | |
90bf1e07 BP |
2276 | printf("nx_pull_match() returned error %s\n", |
2277 | ofperr_get_name(error)); | |
09246b99 BP |
2278 | } |
2279 | ||
2280 | ofpbuf_uninit(&nx_match); | |
2281 | } | |
2282 | ds_destroy(&in); | |
064af421 BP |
2283 | } |
2284 | ||
b5ae8913 SH |
2285 | /* "parse-nxm": reads a series of NXM nx_match specifications as strings from |
2286 | * stdin, does some internal fussing with them, and then prints them back as | |
2287 | * strings on stdout. */ | |
2288 | static void | |
e1fef0f9 | 2289 | ofctl_parse_nxm(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
b5ae8913 | 2290 | { |
e1fef0f9 | 2291 | return ofctl_parse_nxm__(false); |
b5ae8913 SH |
2292 | } |
2293 | ||
2294 | /* "parse-oxm": reads a series of OXM nx_match specifications as strings from | |
2295 | * stdin, does some internal fussing with them, and then prints them back as | |
2296 | * strings on stdout. */ | |
2297 | static void | |
e1fef0f9 | 2298 | ofctl_parse_oxm(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
b5ae8913 | 2299 | { |
e1fef0f9 | 2300 | return ofctl_parse_nxm__(true); |
b5ae8913 SH |
2301 | } |
2302 | ||
f25d0cf3 | 2303 | static void |
96628ae8 BP |
2304 | print_differences(const char *prefix, |
2305 | const void *a_, size_t a_len, | |
f25d0cf3 BP |
2306 | const void *b_, size_t b_len) |
2307 | { | |
2308 | const uint8_t *a = a_; | |
2309 | const uint8_t *b = b_; | |
2310 | size_t i; | |
2311 | ||
2312 | for (i = 0; i < MIN(a_len, b_len); i++) { | |
2313 | if (a[i] != b[i]) { | |
96628ae8 BP |
2314 | printf("%s%2zu: %02"PRIx8" -> %02"PRIx8"\n", |
2315 | prefix, i, a[i], b[i]); | |
f25d0cf3 BP |
2316 | } |
2317 | } | |
2318 | for (i = a_len; i < b_len; i++) { | |
96628ae8 | 2319 | printf("%s%2zu: (none) -> %02"PRIx8"\n", prefix, i, b[i]); |
f25d0cf3 BP |
2320 | } |
2321 | for (i = b_len; i < a_len; i++) { | |
96628ae8 | 2322 | printf("%s%2zu: %02"PRIx8" -> (none)\n", prefix, i, a[i]); |
f25d0cf3 BP |
2323 | } |
2324 | } | |
2325 | ||
2326 | /* "parse-ofp10-actions": reads a series of OpenFlow 1.0 action specifications | |
2327 | * as hex bytes from stdin, converts them to ofpacts, prints them as strings | |
2328 | * on stdout, and then converts them back to hex bytes and prints any | |
2329 | * differences from the input. */ | |
2330 | static void | |
e1fef0f9 | 2331 | ofctl_parse_ofp10_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
f25d0cf3 BP |
2332 | { |
2333 | struct ds in; | |
2334 | ||
2335 | ds_init(&in); | |
2336 | while (!ds_get_preprocessed_line(&in, stdin)) { | |
2337 | struct ofpbuf of10_out; | |
2338 | struct ofpbuf of10_in; | |
2339 | struct ofpbuf ofpacts; | |
2340 | enum ofperr error; | |
2341 | size_t size; | |
2342 | struct ds s; | |
2343 | ||
2344 | /* Parse hex bytes. */ | |
2345 | ofpbuf_init(&of10_in, 0); | |
2346 | if (ofpbuf_put_hex(&of10_in, ds_cstr(&in), NULL)[0] != '\0') { | |
2347 | ovs_fatal(0, "Trailing garbage in hex data"); | |
2348 | } | |
2349 | ||
2350 | /* Convert to ofpacts. */ | |
2351 | ofpbuf_init(&ofpacts, 0); | |
2352 | size = of10_in.size; | |
d01c980f | 2353 | error = ofpacts_pull_openflow10(&of10_in, of10_in.size, &ofpacts); |
f25d0cf3 BP |
2354 | if (error) { |
2355 | printf("bad OF1.1 actions: %s\n\n", ofperr_get_name(error)); | |
2356 | ofpbuf_uninit(&ofpacts); | |
2357 | ofpbuf_uninit(&of10_in); | |
2358 | continue; | |
2359 | } | |
2360 | ofpbuf_push_uninit(&of10_in, size); | |
2361 | ||
2362 | /* Print cls_rule. */ | |
2363 | ds_init(&s); | |
2364 | ofpacts_format(ofpacts.data, ofpacts.size, &s); | |
2365 | puts(ds_cstr(&s)); | |
2366 | ds_destroy(&s); | |
2367 | ||
2368 | /* Convert back to ofp10 actions and print differences from input. */ | |
2369 | ofpbuf_init(&of10_out, 0); | |
d01c980f | 2370 | ofpacts_put_openflow10(ofpacts.data, ofpacts.size, &of10_out); |
f25d0cf3 | 2371 | |
96628ae8 | 2372 | print_differences("", of10_in.data, of10_in.size, |
f25d0cf3 BP |
2373 | of10_out.data, of10_out.size); |
2374 | putchar('\n'); | |
2375 | ||
2376 | ofpbuf_uninit(&ofpacts); | |
2377 | ofpbuf_uninit(&of10_in); | |
2378 | ofpbuf_uninit(&of10_out); | |
2379 | } | |
2380 | ds_destroy(&in); | |
2381 | } | |
2382 | ||
96628ae8 BP |
2383 | /* "parse-ofp10-match": reads a series of ofp10_match specifications as hex |
2384 | * bytes from stdin, converts them to cls_rules, prints them as strings on | |
2385 | * stdout, and then converts them back to hex bytes and prints any differences | |
8812ec2c BP |
2386 | * from the input. |
2387 | * | |
2388 | * The input hex bytes may contain "x"s to represent "don't-cares", bytes whose | |
2389 | * values are ignored in the input and will be set to zero when OVS converts | |
2390 | * them back to hex bytes. ovs-ofctl actually sets "x"s to random bits when | |
2391 | * it does the conversion to hex, to ensure that in fact they are ignored. */ | |
96628ae8 BP |
2392 | static void |
2393 | ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) | |
2394 | { | |
8812ec2c | 2395 | struct ds expout; |
96628ae8 BP |
2396 | struct ds in; |
2397 | ||
2398 | ds_init(&in); | |
8812ec2c | 2399 | ds_init(&expout); |
96628ae8 | 2400 | while (!ds_get_preprocessed_line(&in, stdin)) { |
8812ec2c | 2401 | struct ofpbuf match_in, match_expout; |
96628ae8 BP |
2402 | struct ofp10_match match_out; |
2403 | struct ofp10_match match_normal; | |
81a76618 | 2404 | struct match match; |
8812ec2c BP |
2405 | char *p; |
2406 | ||
2407 | /* Parse hex bytes to use for expected output. */ | |
2408 | ds_clear(&expout); | |
2409 | ds_put_cstr(&expout, ds_cstr(&in)); | |
2410 | for (p = ds_cstr(&expout); *p; p++) { | |
2411 | if (*p == 'x') { | |
2412 | *p = '0'; | |
2413 | } | |
2414 | } | |
2415 | ofpbuf_init(&match_expout, 0); | |
2416 | if (ofpbuf_put_hex(&match_expout, ds_cstr(&expout), NULL)[0] != '\0') { | |
2417 | ovs_fatal(0, "Trailing garbage in hex data"); | |
2418 | } | |
2419 | if (match_expout.size != sizeof(struct ofp10_match)) { | |
2420 | ovs_fatal(0, "Input is %zu bytes, expected %zu", | |
2421 | match_expout.size, sizeof(struct ofp10_match)); | |
2422 | } | |
96628ae8 | 2423 | |
8812ec2c BP |
2424 | /* Parse hex bytes for input. */ |
2425 | for (p = ds_cstr(&in); *p; p++) { | |
2426 | if (*p == 'x') { | |
2427 | *p = "0123456789abcdef"[random_uint32() & 0xf]; | |
2428 | } | |
2429 | } | |
96628ae8 BP |
2430 | ofpbuf_init(&match_in, 0); |
2431 | if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') { | |
2432 | ovs_fatal(0, "Trailing garbage in hex data"); | |
2433 | } | |
2434 | if (match_in.size != sizeof(struct ofp10_match)) { | |
2435 | ovs_fatal(0, "Input is %zu bytes, expected %zu", | |
2436 | match_in.size, sizeof(struct ofp10_match)); | |
2437 | } | |
2438 | ||
2439 | /* Convert to cls_rule and print. */ | |
81a76618 BP |
2440 | ofputil_match_from_ofp10_match(match_in.data, &match); |
2441 | match_print(&match); | |
96628ae8 BP |
2442 | |
2443 | /* Convert back to ofp10_match and print differences from input. */ | |
81a76618 | 2444 | ofputil_match_to_ofp10_match(&match, &match_out); |
8812ec2c | 2445 | print_differences("", match_expout.data, match_expout.size, |
96628ae8 BP |
2446 | &match_out, sizeof match_out); |
2447 | ||
2448 | /* Normalize, then convert and compare again. */ | |
81a76618 BP |
2449 | ofputil_normalize_match(&match); |
2450 | ofputil_match_to_ofp10_match(&match, &match_normal); | |
96628ae8 BP |
2451 | print_differences("normal: ", &match_out, sizeof match_out, |
2452 | &match_normal, sizeof match_normal); | |
2453 | putchar('\n'); | |
2454 | ||
2455 | ofpbuf_uninit(&match_in); | |
8812ec2c | 2456 | ofpbuf_uninit(&match_expout); |
96628ae8 BP |
2457 | } |
2458 | ds_destroy(&in); | |
8812ec2c | 2459 | ds_destroy(&expout); |
96628ae8 BP |
2460 | } |
2461 | ||
410698cf | 2462 | /* "parse-ofp11-match": reads a series of ofp11_match specifications as hex |
81a76618 BP |
2463 | * bytes from stdin, converts them to "struct match"es, prints them as strings |
2464 | * on stdout, and then converts them back to hex bytes and prints any | |
2465 | * differences from the input. */ | |
410698cf | 2466 | static void |
e1fef0f9 | 2467 | ofctl_parse_ofp11_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
410698cf BP |
2468 | { |
2469 | struct ds in; | |
2470 | ||
2471 | ds_init(&in); | |
2472 | while (!ds_get_preprocessed_line(&in, stdin)) { | |
2473 | struct ofpbuf match_in; | |
2474 | struct ofp11_match match_out; | |
81a76618 | 2475 | struct match match; |
410698cf | 2476 | enum ofperr error; |
410698cf BP |
2477 | |
2478 | /* Parse hex bytes. */ | |
2479 | ofpbuf_init(&match_in, 0); | |
2480 | if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') { | |
2481 | ovs_fatal(0, "Trailing garbage in hex data"); | |
2482 | } | |
2483 | if (match_in.size != sizeof(struct ofp11_match)) { | |
2484 | ovs_fatal(0, "Input is %zu bytes, expected %zu", | |
2485 | match_in.size, sizeof(struct ofp11_match)); | |
2486 | } | |
2487 | ||
81a76618 BP |
2488 | /* Convert to match. */ |
2489 | error = ofputil_match_from_ofp11_match(match_in.data, &match); | |
410698cf BP |
2490 | if (error) { |
2491 | printf("bad ofp11_match: %s\n\n", ofperr_get_name(error)); | |
2492 | ofpbuf_uninit(&match_in); | |
2493 | continue; | |
2494 | } | |
2495 | ||
81a76618 BP |
2496 | /* Print match. */ |
2497 | match_print(&match); | |
410698cf BP |
2498 | |
2499 | /* Convert back to ofp11_match and print differences from input. */ | |
81a76618 | 2500 | ofputil_match_to_ofp11_match(&match, &match_out); |
410698cf | 2501 | |
96628ae8 | 2502 | print_differences("", match_in.data, match_in.size, |
d01c980f BP |
2503 | &match_out, sizeof match_out); |
2504 | putchar('\n'); | |
410698cf | 2505 | |
d01c980f BP |
2506 | ofpbuf_uninit(&match_in); |
2507 | } | |
2508 | ds_destroy(&in); | |
2509 | } | |
2510 | ||
2511 | /* "parse-ofp11-actions": reads a series of OpenFlow 1.1 action specifications | |
2512 | * as hex bytes from stdin, converts them to ofpacts, prints them as strings | |
2513 | * on stdout, and then converts them back to hex bytes and prints any | |
2514 | * differences from the input. */ | |
2515 | static void | |
e1fef0f9 | 2516 | ofctl_parse_ofp11_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
d01c980f BP |
2517 | { |
2518 | struct ds in; | |
2519 | ||
2520 | ds_init(&in); | |
2521 | while (!ds_get_preprocessed_line(&in, stdin)) { | |
2522 | struct ofpbuf of11_out; | |
2523 | struct ofpbuf of11_in; | |
2524 | struct ofpbuf ofpacts; | |
2525 | enum ofperr error; | |
2526 | size_t size; | |
2527 | struct ds s; | |
2528 | ||
2529 | /* Parse hex bytes. */ | |
2530 | ofpbuf_init(&of11_in, 0); | |
2531 | if (ofpbuf_put_hex(&of11_in, ds_cstr(&in), NULL)[0] != '\0') { | |
2532 | ovs_fatal(0, "Trailing garbage in hex data"); | |
410698cf | 2533 | } |
d01c980f BP |
2534 | |
2535 | /* Convert to ofpacts. */ | |
2536 | ofpbuf_init(&ofpacts, 0); | |
2537 | size = of11_in.size; | |
2538 | error = ofpacts_pull_openflow11_actions(&of11_in, of11_in.size, | |
2539 | &ofpacts); | |
2540 | if (error) { | |
2541 | printf("bad OF1.1 actions: %s\n\n", ofperr_get_name(error)); | |
2542 | ofpbuf_uninit(&ofpacts); | |
2543 | ofpbuf_uninit(&of11_in); | |
2544 | continue; | |
2545 | } | |
2546 | ofpbuf_push_uninit(&of11_in, size); | |
2547 | ||
2548 | /* Print cls_rule. */ | |
2549 | ds_init(&s); | |
2550 | ofpacts_format(ofpacts.data, ofpacts.size, &s); | |
2551 | puts(ds_cstr(&s)); | |
2552 | ds_destroy(&s); | |
2553 | ||
2554 | /* Convert back to ofp11 actions and print differences from input. */ | |
2555 | ofpbuf_init(&of11_out, 0); | |
2556 | ofpacts_put_openflow11_actions(ofpacts.data, ofpacts.size, &of11_out); | |
2557 | ||
96628ae8 | 2558 | print_differences("", of11_in.data, of11_in.size, |
d01c980f | 2559 | of11_out.data, of11_out.size); |
410698cf BP |
2560 | putchar('\n'); |
2561 | ||
d01c980f BP |
2562 | ofpbuf_uninit(&ofpacts); |
2563 | ofpbuf_uninit(&of11_in); | |
2564 | ofpbuf_uninit(&of11_out); | |
2565 | } | |
2566 | ds_destroy(&in); | |
2567 | } | |
2568 | ||
2569 | /* "parse-ofp11-instructions": reads a series of OpenFlow 1.1 instruction | |
2570 | * specifications as hex bytes from stdin, converts them to ofpacts, prints | |
2571 | * them as strings on stdout, and then converts them back to hex bytes and | |
2572 | * prints any differences from the input. */ | |
2573 | static void | |
e1fef0f9 | 2574 | ofctl_parse_ofp11_instructions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) |
d01c980f BP |
2575 | { |
2576 | struct ds in; | |
2577 | ||
2578 | ds_init(&in); | |
2579 | while (!ds_get_preprocessed_line(&in, stdin)) { | |
2580 | struct ofpbuf of11_out; | |
2581 | struct ofpbuf of11_in; | |
2582 | struct ofpbuf ofpacts; | |
2583 | enum ofperr error; | |
2584 | size_t size; | |
2585 | struct ds s; | |
2586 | ||
2587 | /* Parse hex bytes. */ | |
2588 | ofpbuf_init(&of11_in, 0); | |
2589 | if (ofpbuf_put_hex(&of11_in, ds_cstr(&in), NULL)[0] != '\0') { | |
2590 | ovs_fatal(0, "Trailing garbage in hex data"); | |
2591 | } | |
2592 | ||
2593 | /* Convert to ofpacts. */ | |
2594 | ofpbuf_init(&ofpacts, 0); | |
2595 | size = of11_in.size; | |
2596 | error = ofpacts_pull_openflow11_instructions(&of11_in, of11_in.size, | |
2597 | &ofpacts); | |
2598 | if (error) { | |
2599 | printf("bad OF1.1 instructions: %s\n\n", ofperr_get_name(error)); | |
2600 | ofpbuf_uninit(&ofpacts); | |
2601 | ofpbuf_uninit(&of11_in); | |
2602 | continue; | |
2603 | } | |
2604 | ofpbuf_push_uninit(&of11_in, size); | |
2605 | ||
2606 | /* Print cls_rule. */ | |
2607 | ds_init(&s); | |
2608 | ofpacts_format(ofpacts.data, ofpacts.size, &s); | |
2609 | puts(ds_cstr(&s)); | |
2610 | ds_destroy(&s); | |
2611 | ||
2612 | /* Convert back to ofp11 instructions and print differences from | |
2613 | * input. */ | |
2614 | ofpbuf_init(&of11_out, 0); | |
2615 | ofpacts_put_openflow11_instructions(ofpacts.data, ofpacts.size, | |
2616 | &of11_out); | |
2617 | ||
96628ae8 | 2618 | print_differences("", of11_in.data, of11_in.size, |
d01c980f BP |
2619 | of11_out.data, of11_out.size); |
2620 | putchar('\n'); | |
2621 | ||
2622 | ofpbuf_uninit(&ofpacts); | |
2623 | ofpbuf_uninit(&of11_in); | |
2624 | ofpbuf_uninit(&of11_out); | |
410698cf BP |
2625 | } |
2626 | ds_destroy(&in); | |
2627 | } | |
2628 | ||
df778240 BP |
2629 | /* "check-vlan VLAN_TCI VLAN_TCI_MASK": converts the specified vlan_tci and |
2630 | * mask values to and from various formats and prints the results. */ | |
2631 | static void | |
2632 | ofctl_check_vlan(int argc OVS_UNUSED, char *argv[]) | |
2633 | { | |
81a76618 | 2634 | struct match match; |
df778240 BP |
2635 | |
2636 | char *string_s; | |
2637 | struct ofputil_flow_mod fm; | |
2638 | ||
2639 | struct ofpbuf nxm; | |
81a76618 | 2640 | struct match nxm_match; |
df778240 BP |
2641 | int nxm_match_len; |
2642 | char *nxm_s; | |
2643 | ||
81a76618 BP |
2644 | struct ofp10_match of10_raw; |
2645 | struct match of10_match; | |
df778240 | 2646 | |
81a76618 BP |
2647 | struct ofp11_match of11_raw; |
2648 | struct match of11_match; | |
df778240 BP |
2649 | |
2650 | enum ofperr error; | |
2651 | ||
81a76618 BP |
2652 | match_init_catchall(&match); |
2653 | match.flow.vlan_tci = htons(strtoul(argv[1], NULL, 16)); | |
2654 | match.wc.masks.vlan_tci = htons(strtoul(argv[2], NULL, 16)); | |
df778240 BP |
2655 | |
2656 | /* Convert to and from string. */ | |
81a76618 | 2657 | string_s = match_to_string(&match, OFP_DEFAULT_PRIORITY); |
df778240 BP |
2658 | printf("%s -> ", string_s); |
2659 | fflush(stdout); | |
2660 | parse_ofp_str(&fm, -1, string_s, false); | |
2661 | printf("%04"PRIx16"/%04"PRIx16"\n", | |
81a76618 BP |
2662 | ntohs(fm.match.flow.vlan_tci), |
2663 | ntohs(fm.match.wc.masks.vlan_tci)); | |
4d859fa9 | 2664 | free(string_s); |
df778240 BP |
2665 | |
2666 | /* Convert to and from NXM. */ | |
2667 | ofpbuf_init(&nxm, 0); | |
81a76618 | 2668 | nxm_match_len = nx_put_match(&nxm, &match, htonll(0), htonll(0)); |
df778240 | 2669 | nxm_s = nx_match_to_string(nxm.data, nxm_match_len); |
81a76618 | 2670 | error = nx_pull_match(&nxm, nxm_match_len, &nxm_match, NULL, NULL); |
df778240 BP |
2671 | printf("NXM: %s -> ", nxm_s); |
2672 | if (error) { | |
2673 | printf("%s\n", ofperr_to_string(error)); | |
2674 | } else { | |
2675 | printf("%04"PRIx16"/%04"PRIx16"\n", | |
81a76618 BP |
2676 | ntohs(nxm_match.flow.vlan_tci), |
2677 | ntohs(nxm_match.wc.masks.vlan_tci)); | |
df778240 BP |
2678 | } |
2679 | free(nxm_s); | |
2680 | ofpbuf_uninit(&nxm); | |
2681 | ||
476a0e9e SH |
2682 | /* Convert to and from OXM. */ |
2683 | ofpbuf_init(&nxm, 0); | |
81a76618 | 2684 | nxm_match_len = oxm_put_match(&nxm, &match); |
7623f4dd | 2685 | nxm_s = oxm_match_to_string(nxm.data, nxm_match_len); |
81a76618 | 2686 | error = oxm_pull_match(&nxm, &nxm_match); |
476a0e9e SH |
2687 | printf("OXM: %s -> ", nxm_s); |
2688 | if (error) { | |
2689 | printf("%s\n", ofperr_to_string(error)); | |
2690 | } else { | |
81a76618 | 2691 | uint16_t vid = ntohs(nxm_match.flow.vlan_tci) & |
476a0e9e | 2692 | (VLAN_VID_MASK | VLAN_CFI); |
81a76618 | 2693 | uint16_t mask = ntohs(nxm_match.wc.masks.vlan_tci) & |
476a0e9e SH |
2694 | (VLAN_VID_MASK | VLAN_CFI); |
2695 | ||
2696 | printf("%04"PRIx16"/%04"PRIx16",", vid, mask); | |
81a76618 BP |
2697 | if (vid && vlan_tci_to_pcp(nxm_match.wc.masks.vlan_tci)) { |
2698 | printf("%02"PRIx8"\n", vlan_tci_to_pcp(nxm_match.flow.vlan_tci)); | |
476a0e9e SH |
2699 | } else { |
2700 | printf("--\n"); | |
2701 | } | |
2702 | } | |
2703 | free(nxm_s); | |
2704 | ofpbuf_uninit(&nxm); | |
2705 | ||
df778240 | 2706 | /* Convert to and from OpenFlow 1.0. */ |
81a76618 BP |
2707 | ofputil_match_to_ofp10_match(&match, &of10_raw); |
2708 | ofputil_match_from_ofp10_match(&of10_raw, &of10_match); | |
df778240 | 2709 | printf("OF1.0: %04"PRIx16"/%d,%02"PRIx8"/%d -> %04"PRIx16"/%04"PRIx16"\n", |
81a76618 BP |
2710 | ntohs(of10_raw.dl_vlan), |
2711 | (of10_raw.wildcards & htonl(OFPFW10_DL_VLAN)) != 0, | |
2712 | of10_raw.dl_vlan_pcp, | |
2713 | (of10_raw.wildcards & htonl(OFPFW10_DL_VLAN_PCP)) != 0, | |
2714 | ntohs(of10_match.flow.vlan_tci), | |
2715 | ntohs(of10_match.wc.masks.vlan_tci)); | |
df778240 BP |
2716 | |
2717 | /* Convert to and from OpenFlow 1.1. */ | |
81a76618 BP |
2718 | ofputil_match_to_ofp11_match(&match, &of11_raw); |
2719 | ofputil_match_from_ofp11_match(&of11_raw, &of11_match); | |
df778240 | 2720 | printf("OF1.1: %04"PRIx16"/%d,%02"PRIx8"/%d -> %04"PRIx16"/%04"PRIx16"\n", |
81a76618 BP |
2721 | ntohs(of11_raw.dl_vlan), |
2722 | (of11_raw.wildcards & htonl(OFPFW11_DL_VLAN)) != 0, | |
2723 | of11_raw.dl_vlan_pcp, | |
2724 | (of11_raw.wildcards & htonl(OFPFW11_DL_VLAN_PCP)) != 0, | |
2725 | ntohs(of11_match.flow.vlan_tci), | |
2726 | ntohs(of11_match.wc.masks.vlan_tci)); | |
df778240 BP |
2727 | } |
2728 | ||
2e0525bc SH |
2729 | /* "print-error ENUM": Prints the type and code of ENUM for every OpenFlow |
2730 | * version. */ | |
2731 | static void | |
e1fef0f9 | 2732 | ofctl_print_error(int argc OVS_UNUSED, char *argv[]) |
2e0525bc SH |
2733 | { |
2734 | enum ofperr error; | |
2735 | int version; | |
2736 | ||
2737 | error = ofperr_from_name(argv[1]); | |
2738 | if (!error) { | |
2739 | ovs_fatal(0, "unknown error \"%s\"", argv[1]); | |
2740 | } | |
2741 | ||
2742 | for (version = 0; version <= UINT8_MAX; version++) { | |
688e86e1 SH |
2743 | const char *name = ofperr_domain_get_name(version); |
2744 | if (!name) { | |
2e0525bc SH |
2745 | continue; |
2746 | } | |
2e0525bc | 2747 | printf("%s: %d,%d\n", |
688e86e1 SH |
2748 | ofperr_domain_get_name(version), |
2749 | ofperr_get_type(error, version), | |
2750 | ofperr_get_code(error, version)); | |
2e0525bc SH |
2751 | } |
2752 | } | |
2753 | ||
edd70aa7 BP |
2754 | /* "encode-error-reply ENUM REQUEST": Encodes an error reply to REQUEST for the |
2755 | * error named ENUM and prints the error reply in hex. */ | |
2756 | static void | |
2757 | ofctl_encode_error_reply(int argc OVS_UNUSED, char *argv[]) | |
2758 | { | |
2759 | const struct ofp_header *oh; | |
2760 | struct ofpbuf request, *reply; | |
2761 | enum ofperr error; | |
2762 | ||
2763 | error = ofperr_from_name(argv[1]); | |
2764 | if (!error) { | |
2765 | ovs_fatal(0, "unknown error \"%s\"", argv[1]); | |
2766 | } | |
2767 | ||
2768 | ofpbuf_init(&request, 0); | |
2769 | if (ofpbuf_put_hex(&request, argv[2], NULL)[0] != '\0') { | |
2770 | ovs_fatal(0, "Trailing garbage in hex data"); | |
2771 | } | |
2772 | if (request.size < sizeof(struct ofp_header)) { | |
2773 | ovs_fatal(0, "Request too short"); | |
2774 | } | |
2775 | ||
2776 | oh = request.data; | |
2777 | if (request.size != ntohs(oh->length)) { | |
2778 | ovs_fatal(0, "Request size inconsistent"); | |
2779 | } | |
2780 | ||
2781 | reply = ofperr_encode_reply(error, request.data); | |
2782 | ofpbuf_uninit(&request); | |
2783 | ||
2784 | ovs_hex_dump(stdout, reply->data, reply->size, 0, false); | |
2785 | ofpbuf_delete(reply); | |
2786 | } | |
2787 | ||
fec00620 BP |
2788 | /* "ofp-print HEXSTRING [VERBOSITY]": Converts the hex digits in HEXSTRING into |
2789 | * binary data, interpreting them as an OpenFlow message, and prints the | |
2790 | * OpenFlow message on stdout, at VERBOSITY (level 2 by default). */ | |
2791 | static void | |
e1fef0f9 | 2792 | ofctl_ofp_print(int argc, char *argv[]) |
fec00620 BP |
2793 | { |
2794 | struct ofpbuf packet; | |
2795 | ||
2796 | ofpbuf_init(&packet, strlen(argv[1]) / 2); | |
2797 | if (ofpbuf_put_hex(&packet, argv[1], NULL)[0] != '\0') { | |
2798 | ovs_fatal(0, "trailing garbage following hex bytes"); | |
2799 | } | |
2800 | ofp_print(stdout, packet.data, packet.size, argc > 2 ? atoi(argv[2]) : 2); | |
2801 | ofpbuf_uninit(&packet); | |
2802 | } | |
2803 | ||
681ea7a0 BP |
2804 | /* "encode-hello BITMAP...": Encodes each BITMAP as an OpenFlow hello message |
2805 | * and dumps each message in hex. */ | |
2806 | static void | |
2807 | ofctl_encode_hello(int argc OVS_UNUSED, char *argv[]) | |
2808 | { | |
2809 | uint32_t bitmap = strtol(argv[1], NULL, 0); | |
2810 | struct ofpbuf *hello; | |
2811 | ||
2812 | hello = ofputil_encode_hello(bitmap); | |
2813 | ovs_hex_dump(stdout, hello->data, hello->size, 0, false); | |
2814 | ofp_print(stdout, hello->data, hello->size, verbosity); | |
2815 | ofpbuf_delete(hello); | |
2816 | } | |
2817 | ||
675febfa | 2818 | static const struct command all_commands[] = { |
e1fef0f9 AS |
2819 | { "show", 1, 1, ofctl_show }, |
2820 | { "monitor", 1, 3, ofctl_monitor }, | |
2821 | { "snoop", 1, 1, ofctl_snoop }, | |
2822 | { "dump-desc", 1, 1, ofctl_dump_desc }, | |
2823 | { "dump-tables", 1, 1, ofctl_dump_tables }, | |
2824 | { "dump-flows", 1, 2, ofctl_dump_flows }, | |
2825 | { "dump-aggregate", 1, 2, ofctl_dump_aggregate }, | |
2826 | { "queue-stats", 1, 3, ofctl_queue_stats }, | |
2827 | { "add-flow", 2, 2, ofctl_add_flow }, | |
2828 | { "add-flows", 2, 2, ofctl_add_flows }, | |
2829 | { "mod-flows", 2, 2, ofctl_mod_flows }, | |
2830 | { "del-flows", 1, 2, ofctl_del_flows }, | |
2831 | { "replace-flows", 2, 2, ofctl_replace_flows }, | |
2832 | { "diff-flows", 2, 2, ofctl_diff_flows }, | |
2833 | { "packet-out", 4, INT_MAX, ofctl_packet_out }, | |
2834 | { "dump-ports", 1, 2, ofctl_dump_ports }, | |
2835 | { "dump-ports-desc", 1, 1, ofctl_dump_ports_desc }, | |
2836 | { "mod-port", 3, 3, ofctl_mod_port }, | |
2837 | { "get-frags", 1, 1, ofctl_get_frags }, | |
2838 | { "set-frags", 2, 2, ofctl_set_frags }, | |
2839 | { "probe", 1, 1, ofctl_probe }, | |
2840 | { "ping", 1, 2, ofctl_ping }, | |
2841 | { "benchmark", 3, 3, ofctl_benchmark }, | |
2842 | { "help", 0, INT_MAX, ofctl_help }, | |
09246b99 BP |
2843 | |
2844 | /* Undocumented commands for testing. */ | |
e1fef0f9 AS |
2845 | { "parse-flow", 1, 1, ofctl_parse_flow }, |
2846 | { "parse-flows", 1, 1, ofctl_parse_flows }, | |
2847 | { "parse-nx-match", 0, 0, ofctl_parse_nxm }, | |
2848 | { "parse-nxm", 0, 0, ofctl_parse_nxm }, | |
2849 | { "parse-oxm", 0, 0, ofctl_parse_oxm }, | |
2850 | { "parse-ofp10-actions", 0, 0, ofctl_parse_ofp10_actions }, | |
96628ae8 | 2851 | { "parse-ofp10-match", 0, 0, ofctl_parse_ofp10_match }, |
e1fef0f9 AS |
2852 | { "parse-ofp11-match", 0, 0, ofctl_parse_ofp11_match }, |
2853 | { "parse-ofp11-actions", 0, 0, ofctl_parse_ofp11_actions }, | |
2854 | { "parse-ofp11-instructions", 0, 0, ofctl_parse_ofp11_instructions }, | |
df778240 | 2855 | { "check-vlan", 2, 2, ofctl_check_vlan }, |
e1fef0f9 | 2856 | { "print-error", 1, 1, ofctl_print_error }, |
edd70aa7 | 2857 | { "encode-error-reply", 2, 2, ofctl_encode_error_reply }, |
e1fef0f9 | 2858 | { "ofp-print", 1, 2, ofctl_ofp_print }, |
681ea7a0 | 2859 | { "encode-hello", 1, 1, ofctl_encode_hello }, |
09246b99 | 2860 | |
064af421 BP |
2861 | { NULL, 0, 0, NULL }, |
2862 | }; |