2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/socket.h>
28 #include <sys/fcntl.h>
32 #include "byte-order.h"
33 #include "classifier.h"
34 #include "command-line.h"
38 #include "dynamic-string.h"
41 #include "ofp-actions.h"
42 #include "ofp-errors.h"
44 #include "ofp-parse.h"
45 #include "ofp-print.h"
47 #include "ofp-version-opt.h"
49 #include "ofproto/ofproto.h"
50 #include "openflow/nicira-ext.h"
51 #include "openflow/openflow.h"
53 #include "poll-loop.h"
55 #include "stream-ssl.h"
56 #include "socket-util.h"
62 #include "meta-flow.h"
65 VLOG_DEFINE_THIS_MODULE(ofctl);
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.
72 /* --readd: If true, on replace-flows, re-add even flows that have not changed
73 * (to reset flow counters). */
76 /* -F, --flow-format: Allowed protocols. By default, any protocol is
78 static enum ofputil_protocol allowed_protocols = OFPUTIL_P_ANY;
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;
85 /* -m, --more: Additional verbosity for ofp-print functions. */
88 /* --timestamp: Print a timestamp before each received packet on "monitor" and
90 static bool timestamp;
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;
98 static struct sort_criterion *criteria;
99 static size_t n_criteria, allocated_criteria;
101 static const struct command *get_all_commands(void);
103 static void usage(void) NO_RETURN;
104 static void parse_options(int argc, char *argv[]);
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);
111 main(int argc, char *argv[])
113 set_program_name(argv[0]);
114 parse_options(argc, argv);
115 signal(SIGPIPE, SIG_IGN);
116 run_command(argc - optind, argv + optind, get_all_commands());
121 add_sort_criterion(enum sort_order order, const char *field)
123 struct sort_criterion *sc;
125 if (n_criteria >= allocated_criteria) {
126 criteria = x2nrealloc(criteria, &allocated_criteria, sizeof *criteria);
129 sc = &criteria[n_criteria++];
130 if (!field || !strcasecmp(field, "priority")) {
133 sc->field = mf_from_name(field);
135 ovs_fatal(0, "%s: unknown field name", field);
142 parse_options(int argc, char *argv[])
145 OPT_STRICT = UCHAR_MAX + 1,
151 OFP_VERSION_OPTION_ENUMS,
154 static const struct option long_options[] = {
155 {"timeout", required_argument, NULL, 't'},
156 {"strict", no_argument, NULL, OPT_STRICT},
157 {"readd", no_argument, NULL, OPT_READD},
158 {"flow-format", required_argument, NULL, 'F'},
159 {"packet-in-format", required_argument, NULL, 'P'},
160 {"more", no_argument, NULL, 'm'},
161 {"timestamp", no_argument, NULL, OPT_TIMESTAMP},
162 {"sort", optional_argument, NULL, OPT_SORT},
163 {"rsort", optional_argument, NULL, OPT_RSORT},
164 {"help", no_argument, NULL, 'h'},
166 OFP_VERSION_LONG_OPTIONS,
168 STREAM_SSL_LONG_OPTIONS,
171 char *short_options = long_options_to_short_options(long_options);
173 enum ofputil_protocol version_protocols;
176 unsigned long int timeout;
179 c = getopt_long(argc, argv, short_options, long_options, NULL);
186 timeout = strtoul(optarg, NULL, 10);
188 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
196 allowed_protocols = ofputil_protocols_from_string(optarg);
197 if (!allowed_protocols) {
198 ovs_fatal(0, "%s: invalid flow format(s)", optarg);
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);
230 add_sort_criterion(SORT_ASC, optarg);
234 add_sort_criterion(SORT_DESC, optarg);
237 DAEMON_OPTION_HANDLERS
238 OFP_VERSION_OPTION_HANDLERS
240 STREAM_SSL_OPTION_HANDLERS
251 /* Always do a final sort pass based on priority. */
252 add_sort_criterion(SORT_DESC, "priority");
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;
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);
269 allowed_protocols &= version_protocols;
270 mask_allowed_ofp_versions(ofputil_protocols_to_version_bitmap(
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"
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"
284 " mod-table SWITCH MOD modify flow table behavior\n"
285 " get-frags SWITCH print fragment handling behavior\n"
286 " set-frags SWITCH FRAG_MODE set fragment handling behavior\n"
287 " dump-ports SWITCH [PORT] print port statistics\n"
288 " dump-ports-desc SWITCH print port descriptions\n"
289 " dump-flows SWITCH print all flow entries\n"
290 " dump-flows SWITCH FLOW print matching FLOWs\n"
291 " dump-aggregate SWITCH print aggregate flow statistics\n"
292 " dump-aggregate SWITCH FLOW print aggregate stats for FLOWs\n"
293 " queue-stats SWITCH [PORT [QUEUE]] dump queue stats\n"
294 " add-flow SWITCH FLOW add flow described by FLOW\n"
295 " add-flows SWITCH FILE add flows from FILE\n"
296 " mod-flows SWITCH FLOW modify actions of matching FLOWs\n"
297 " del-flows SWITCH [FLOW] delete matching FLOWs\n"
298 " replace-flows SWITCH FILE replace flows with those in FILE\n"
299 " diff-flows SOURCE1 SOURCE2 compare flows from two sources\n"
300 " packet-out SWITCH IN_PORT ACTIONS PACKET...\n"
301 " execute ACTIONS on PACKET\n"
302 " monitor SWITCH [MISSLEN] [invalid_ttl] [watch:[...]]\n"
303 " print packets received from SWITCH\n"
304 " snoop SWITCH snoop on SWITCH and its controller\n"
305 " add-group SWITCH GROUP add group described by GROUP\n"
306 " add-group SWITCH FILE add group from FILE\n"
307 " mod-group SWITCH GROUP modify specific group\n"
308 " del-groups SWITCH [GROUP] delete matching GROUPs\n"
309 " dump-group-features SWITCH print group features\n"
310 " dump-groups SWITCH print group description\n"
311 " dump-group-stats SWITCH [GROUP] print group statistics\n"
312 " add-meter SWITCH METER add meter described by METER\n"
313 " mod-meter SWITCH METER modify specific METER\n"
314 " del-meter SWITCH METER delete METER\n"
315 " del-meters SWITCH delete all meters\n"
316 " dump-meter SWITCH METER print METER configuration\n"
317 " dump-meters SWITCH print all meter configuration\n"
318 " meter-stats SWITCH [METER] print meter statistics\n"
319 " meter-features SWITCH print meter features\n"
320 "\nFor OpenFlow switches and controllers:\n"
321 " probe TARGET probe whether TARGET is up\n"
322 " ping TARGET [N] latency of N-byte echos\n"
323 " benchmark TARGET N COUNT bandwidth of COUNT N-byte echos\n"
324 "SWITCH or TARGET is an active OpenFlow connection method.\n"
325 "\nOther commands:\n"
326 " ofp-parse FILE print messages read from FILE\n",
327 program_name, program_name);
328 vconn_usage(true, false, false);
332 printf("\nOther options:\n"
333 " --strict use strict match for flow commands\n"
334 " --readd replace flows that haven't changed\n"
335 " -F, --flow-format=FORMAT force particular flow format\n"
336 " -P, --packet-in-format=FRMT force particular packet in format\n"
337 " -m, --more be more verbose printing OpenFlow\n"
338 " --timestamp (monitor, snoop) print timestamps\n"
339 " -t, --timeout=SECS give up after SECS seconds\n"
340 " --sort[=field] sort in ascending order\n"
341 " --rsort[=field] sort in descending order\n"
342 " -h, --help display this help message\n"
343 " -V, --version display version information\n");
348 ofctl_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
349 const char *argv[] OVS_UNUSED, void *exiting_)
351 bool *exiting = exiting_;
353 unixctl_command_reply(conn, NULL);
356 static void run(int retval, const char *message, ...)
360 run(int retval, const char *message, ...)
365 va_start(args, message);
366 ovs_fatal_valist(retval, message, args);
370 /* Generic commands. */
373 open_vconn_socket(const char *name, struct vconn **vconnp)
375 char *vconn_name = xasprintf("unix:%s", name);
378 error = vconn_open(vconn_name, get_allowed_ofp_versions(), DSCP_DEFAULT,
380 if (error && error != ENOENT) {
381 ovs_fatal(0, "%s: failed to open socket (%s)", name,
382 ovs_strerror(error));
389 enum open_target { MGMT, SNOOP };
391 static enum ofputil_protocol
392 open_vconn__(const char *name, enum open_target target,
393 struct vconn **vconnp)
395 const char *suffix = target == MGMT ? "mgmt" : "snoop";
396 char *datapath_name, *datapath_type, *socket_name;
397 enum ofputil_protocol protocol;
402 bridge_path = xasprintf("%s/%s.%s", ovs_rundir(), name, suffix);
404 ofproto_parse_name(name, &datapath_name, &datapath_type);
405 socket_name = xasprintf("%s/%s.%s", ovs_rundir(), datapath_name, suffix);
409 if (strchr(name, ':')) {
410 run(vconn_open(name, get_allowed_ofp_versions(), DSCP_DEFAULT, vconnp),
411 "connecting to %s", name);
412 } else if (!open_vconn_socket(name, vconnp)) {
414 } else if (!open_vconn_socket(bridge_path, vconnp)) {
416 } else if (!open_vconn_socket(socket_name, vconnp)) {
419 ovs_fatal(0, "%s is not a bridge or a socket", name);
422 if (target == SNOOP) {
423 vconn_set_recv_any_version(*vconnp);
429 VLOG_DBG("connecting to %s", vconn_get_name(*vconnp));
430 error = vconn_connect_block(*vconnp);
432 ovs_fatal(0, "%s: failed to connect to socket (%s)", name,
433 ovs_strerror(error));
436 ofp_version = vconn_get_version(*vconnp);
437 protocol = ofputil_protocol_from_ofp_version(ofp_version);
439 ovs_fatal(0, "%s: unsupported OpenFlow version 0x%02x",
445 static enum ofputil_protocol
446 open_vconn(const char *name, struct vconn **vconnp)
448 return open_vconn__(name, MGMT, vconnp);
452 send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
454 ofpmsg_update_length(buffer);
455 run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
459 dump_transaction(struct vconn *vconn, struct ofpbuf *request)
461 struct ofpbuf *reply;
463 ofpmsg_update_length(request);
464 run(vconn_transact(vconn, request, &reply), "talking to %s",
465 vconn_get_name(vconn));
466 ofp_print(stdout, reply->data, reply->size, verbosity + 1);
467 ofpbuf_delete(reply);
471 dump_trivial_transaction(const char *vconn_name, enum ofpraw raw)
473 struct ofpbuf *request;
476 open_vconn(vconn_name, &vconn);
477 request = ofpraw_alloc(raw, vconn_get_version(vconn), 0);
478 dump_transaction(vconn, request);
483 dump_stats_transaction(struct vconn *vconn, struct ofpbuf *request)
485 const struct ofp_header *request_oh = request->data;
486 ovs_be32 send_xid = request_oh->xid;
487 enum ofpraw request_raw;
488 enum ofpraw reply_raw;
491 ofpraw_decode_partial(&request_raw, request->data, request->size);
492 reply_raw = ofpraw_stats_request_to_reply(request_raw,
493 request_oh->version);
495 send_openflow_buffer(vconn, request);
498 struct ofpbuf *reply;
500 run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
501 recv_xid = ((struct ofp_header *) reply->data)->xid;
502 if (send_xid == recv_xid) {
505 ofp_print(stdout, reply->data, reply->size, verbosity + 1);
507 ofpraw_decode(&raw, reply->data);
508 if (ofptype_from_ofpraw(raw) == OFPTYPE_ERROR) {
510 } else if (raw == reply_raw) {
511 done = !ofpmp_more(reply->data);
513 ovs_fatal(0, "received bad reply: %s",
514 ofp_to_string(reply->data, reply->size,
518 VLOG_DBG("received reply with xid %08"PRIx32" "
519 "!= expected %08"PRIx32, recv_xid, send_xid);
521 ofpbuf_delete(reply);
526 dump_trivial_stats_transaction(const char *vconn_name, enum ofpraw raw)
528 struct ofpbuf *request;
531 open_vconn(vconn_name, &vconn);
532 request = ofpraw_alloc(raw, vconn_get_version(vconn), 0);
533 dump_stats_transaction(vconn, request);
537 /* Sends all of the 'requests', which should be requests that only have replies
538 * if an error occurs, and waits for them to succeed or fail. If an error does
539 * occur, prints it and exits with an error.
541 * Destroys all of the 'requests'. */
543 transact_multiple_noreply(struct vconn *vconn, struct list *requests)
545 struct ofpbuf *request, *reply;
547 LIST_FOR_EACH (request, list_node, requests) {
548 ofpmsg_update_length(request);
551 run(vconn_transact_multiple_noreply(vconn, requests, &reply),
552 "talking to %s", vconn_get_name(vconn));
554 ofp_print(stderr, reply->data, reply->size, verbosity + 2);
557 ofpbuf_delete(reply);
560 /* Sends 'request', which should be a request that only has a reply if an error
561 * occurs, and waits for it to succeed or fail. If an error does occur, prints
562 * it and exits with an error.
564 * Destroys 'request'. */
566 transact_noreply(struct vconn *vconn, struct ofpbuf *request)
568 struct list requests;
570 list_init(&requests);
571 list_push_back(&requests, &request->list_node);
572 transact_multiple_noreply(vconn, &requests);
576 fetch_switch_config(struct vconn *vconn, struct ofp_switch_config *config_)
578 struct ofp_switch_config *config;
579 struct ofpbuf *request;
580 struct ofpbuf *reply;
583 request = ofpraw_alloc(OFPRAW_OFPT_GET_CONFIG_REQUEST,
584 vconn_get_version(vconn), 0);
585 run(vconn_transact(vconn, request, &reply),
586 "talking to %s", vconn_get_name(vconn));
588 if (ofptype_pull(&type, reply) || type != OFPTYPE_GET_CONFIG_REPLY) {
589 ovs_fatal(0, "%s: bad reply to config request", vconn_get_name(vconn));
592 config = ofpbuf_pull(reply, sizeof *config);
595 ofpbuf_delete(reply);
599 set_switch_config(struct vconn *vconn, const struct ofp_switch_config *config)
601 struct ofpbuf *request;
603 request = ofpraw_alloc(OFPRAW_OFPT_SET_CONFIG, vconn_get_version(vconn), 0);
604 ofpbuf_put(request, config, sizeof *config);
606 transact_noreply(vconn, request);
610 ofctl_show(int argc OVS_UNUSED, char *argv[])
612 const char *vconn_name = argv[1];
614 struct ofpbuf *request;
615 struct ofpbuf *reply;
618 open_vconn(vconn_name, &vconn);
619 request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST,
620 vconn_get_version(vconn), 0);
621 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
623 trunc = ofputil_switch_features_ports_trunc(reply);
624 ofp_print(stdout, reply->data, reply->size, verbosity + 1);
626 ofpbuf_delete(reply);
629 /* The Features Reply may not contain all the ports, so send a
630 * Port Description stats request, which doesn't have size
632 dump_trivial_stats_transaction(vconn_name,
633 OFPRAW_OFPST_PORT_DESC_REQUEST);
635 dump_trivial_transaction(vconn_name, OFPRAW_OFPT_GET_CONFIG_REQUEST);
640 ofctl_dump_desc(int argc OVS_UNUSED, char *argv[])
642 dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_DESC_REQUEST);
646 ofctl_dump_tables(int argc OVS_UNUSED, char *argv[])
648 dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_TABLE_REQUEST);
652 fetch_port_by_features(const char *vconn_name,
653 const char *port_name, ofp_port_t port_no,
654 struct ofputil_phy_port *pp, bool *trunc)
656 struct ofputil_switch_features features;
657 const struct ofp_header *oh;
658 struct ofpbuf *request, *reply;
665 /* Fetch the switch's ofp_switch_features. */
666 open_vconn(vconn_name, &vconn);
667 request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST,
668 vconn_get_version(vconn), 0);
669 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
673 if (ofptype_decode(&type, reply->data)
674 || type != OFPTYPE_FEATURES_REPLY) {
675 ovs_fatal(0, "%s: received bad features reply", vconn_name);
679 if (ofputil_switch_features_ports_trunc(reply)) {
684 error = ofputil_decode_switch_features(oh, &features, &b);
686 ovs_fatal(0, "%s: failed to decode features reply (%s)",
687 vconn_name, ofperr_to_string(error));
690 while (!ofputil_pull_phy_port(oh->version, &b, pp)) {
691 if (port_no != OFPP_NONE
692 ? port_no == pp->port_no
693 : !strcmp(pp->name, port_name)) {
700 ofpbuf_delete(reply);
705 fetch_port_by_stats(const char *vconn_name,
706 const char *port_name, ofp_port_t port_no,
707 struct ofputil_phy_port *pp)
709 struct ofpbuf *request;
715 request = ofpraw_alloc(OFPRAW_OFPST_PORT_DESC_REQUEST, OFP10_VERSION, 0);
716 send_xid = ((struct ofp_header *) request->data)->xid;
718 open_vconn(vconn_name, &vconn);
719 send_openflow_buffer(vconn, request);
722 struct ofpbuf *reply;
724 run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
725 recv_xid = ((struct ofp_header *) reply->data)->xid;
726 if (send_xid == recv_xid) {
727 struct ofp_header *oh = reply->data;
732 ofpbuf_use_const(&b, oh, ntohs(oh->length));
733 if (ofptype_pull(&type, &b)
734 || type != OFPTYPE_PORT_DESC_STATS_REPLY) {
735 ovs_fatal(0, "received bad reply: %s",
736 ofp_to_string(reply->data, reply->size,
740 flags = ofpmp_flags(oh);
741 done = !(flags & OFPSF_REPLY_MORE);
744 /* We've already found the port, but we need to drain
745 * the queue of any other replies for this request. */
749 while (!ofputil_pull_phy_port(oh->version, &b, pp)) {
750 if (port_no != OFPP_NONE ? port_no == pp->port_no
751 : !strcmp(pp->name, port_name)) {
757 VLOG_DBG("received reply with xid %08"PRIx32" "
758 "!= expected %08"PRIx32, recv_xid, send_xid);
760 ofpbuf_delete(reply);
768 str_to_ofp(const char *s, ofp_port_t *ofp_port)
773 ret = str_to_uint(s, 10, &port_);
774 *ofp_port = u16_to_ofp(port_);
778 /* Opens a connection to 'vconn_name', fetches the port structure for
779 * 'port_name' (which may be a port name or number), and copies it into
782 fetch_ofputil_phy_port(const char *vconn_name, const char *port_name,
783 struct ofputil_phy_port *pp)
789 /* Try to interpret the argument as a port number. */
790 if (!str_to_ofp(port_name, &port_no)) {
794 /* Try to find the port based on the Features Reply. If it looks
795 * like the results may be truncated, then use the Port Description
796 * stats message introduced in OVS 1.7. */
797 found = fetch_port_by_features(vconn_name, port_name, port_no, pp,
800 found = fetch_port_by_stats(vconn_name, port_name, port_no, pp);
804 ovs_fatal(0, "%s: couldn't find port `%s'", vconn_name, port_name);
808 /* Returns the port number corresponding to 'port_name' (which may be a port
809 * name or number) within the switch 'vconn_name'. */
811 str_to_port_no(const char *vconn_name, const char *port_name)
815 if (ofputil_port_from_string(port_name, &port_no)) {
818 struct ofputil_phy_port pp;
820 fetch_ofputil_phy_port(vconn_name, port_name, &pp);
826 try_set_protocol(struct vconn *vconn, enum ofputil_protocol want,
827 enum ofputil_protocol *cur)
830 struct ofpbuf *request, *reply;
831 enum ofputil_protocol next;
833 request = ofputil_encode_set_protocol(*cur, want, &next);
838 run(vconn_transact_noreply(vconn, request, &reply),
839 "talking to %s", vconn_get_name(vconn));
841 char *s = ofp_to_string(reply->data, reply->size, 2);
842 VLOG_DBG("%s: failed to set protocol, switch replied: %s",
843 vconn_get_name(vconn), s);
845 ofpbuf_delete(reply);
853 static enum ofputil_protocol
854 set_protocol_for_flow_dump(struct vconn *vconn,
855 enum ofputil_protocol cur_protocol,
856 enum ofputil_protocol usable_protocols)
861 for (i = 0; i < ofputil_n_flow_dump_protocols; i++) {
862 enum ofputil_protocol f = ofputil_flow_dump_protocols[i];
863 if (f & usable_protocols & allowed_protocols
864 && try_set_protocol(vconn, f, &cur_protocol)) {
869 usable_s = ofputil_protocols_to_string(usable_protocols);
870 if (usable_protocols & allowed_protocols) {
871 ovs_fatal(0, "switch does not support any of the usable flow "
872 "formats (%s)", usable_s);
874 char *allowed_s = ofputil_protocols_to_string(allowed_protocols);
875 ovs_fatal(0, "none of the usable flow formats (%s) is among the "
876 "allowed flow formats (%s)", usable_s, allowed_s);
880 static struct vconn *
881 prepare_dump_flows(int argc, char *argv[], bool aggregate,
882 struct ofpbuf **requestp)
884 enum ofputil_protocol usable_protocols, protocol;
885 struct ofputil_flow_stats_request fsr;
889 error = parse_ofp_flow_stats_request_str(&fsr, aggregate,
890 argc > 2 ? argv[2] : "",
893 ovs_fatal(0, "%s", error);
896 protocol = open_vconn(argv[1], &vconn);
897 protocol = set_protocol_for_flow_dump(vconn, protocol, usable_protocols);
898 *requestp = ofputil_encode_flow_stats_request(&fsr, protocol);
903 ofctl_dump_flows__(int argc, char *argv[], bool aggregate)
905 struct ofpbuf *request;
908 vconn = prepare_dump_flows(argc, argv, aggregate, &request);
909 dump_stats_transaction(vconn, request);
914 compare_flows(const void *afs_, const void *bfs_)
916 const struct ofputil_flow_stats *afs = afs_;
917 const struct ofputil_flow_stats *bfs = bfs_;
918 const struct match *a = &afs->match;
919 const struct match *b = &bfs->match;
920 const struct sort_criterion *sc;
922 for (sc = criteria; sc < &criteria[n_criteria]; sc++) {
923 const struct mf_field *f = sc->field;
927 unsigned int a_pri = afs->priority;
928 unsigned int b_pri = bfs->priority;
929 ret = a_pri < b_pri ? -1 : a_pri > b_pri;
933 ina = mf_are_prereqs_ok(f, &a->flow) && !mf_is_all_wild(f, &a->wc);
934 inb = mf_are_prereqs_ok(f, &b->flow) && !mf_is_all_wild(f, &b->wc);
936 /* Skip the test for sc->order, so that missing fields always
937 * sort to the end whether we're sorting in ascending or
938 * descending order. */
941 union mf_value aval, bval;
943 mf_get_value(f, &a->flow, &aval);
944 mf_get_value(f, &b->flow, &bval);
945 ret = memcmp(&aval, &bval, f->n_bytes);
950 return sc->order == SORT_ASC ? ret : -ret;
958 ofctl_dump_flows(int argc, char *argv[])
961 return ofctl_dump_flows__(argc, argv, false);
963 struct ofputil_flow_stats *fses;
964 size_t n_fses, allocated_fses;
965 struct ofpbuf *request;
966 struct ofpbuf ofpacts;
967 struct ofpbuf *reply;
973 vconn = prepare_dump_flows(argc, argv, false, &request);
974 send_xid = ((struct ofp_header *) request->data)->xid;
975 send_openflow_buffer(vconn, request);
978 n_fses = allocated_fses = 0;
980 ofpbuf_init(&ofpacts, 0);
982 struct ofputil_flow_stats *fs;
984 if (n_fses >= allocated_fses) {
985 fses = x2nrealloc(fses, &allocated_fses, sizeof *fses);
989 if (!recv_flow_stats_reply(vconn, send_xid, &reply, fs,
993 fs->ofpacts = xmemdup(fs->ofpacts, fs->ofpacts_len);
996 ofpbuf_uninit(&ofpacts);
998 qsort(fses, n_fses, sizeof *fses, compare_flows);
1001 for (i = 0; i < n_fses; i++) {
1003 ofp_print_flow_stats(&s, &fses[i]);
1008 for (i = 0; i < n_fses; i++) {
1009 free(fses[i].ofpacts);
1018 ofctl_dump_aggregate(int argc, char *argv[])
1020 return ofctl_dump_flows__(argc, argv, true);
1024 ofctl_queue_stats(int argc, char *argv[])
1026 struct ofpbuf *request;
1027 struct vconn *vconn;
1028 struct ofputil_queue_stats_request oqs;
1030 open_vconn(argv[1], &vconn);
1032 if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) {
1033 oqs.port_no = str_to_port_no(argv[1], argv[2]);
1035 oqs.port_no = OFPP_ANY;
1037 if (argc > 3 && argv[3][0] && strcasecmp(argv[3], "all")) {
1038 oqs.queue_id = atoi(argv[3]);
1040 oqs.queue_id = OFPQ_ALL;
1043 request = ofputil_encode_queue_stats_request(vconn_get_version(vconn), &oqs);
1044 dump_stats_transaction(vconn, request);
1048 static enum ofputil_protocol
1049 open_vconn_for_flow_mod(const char *remote, struct vconn **vconnp,
1050 enum ofputil_protocol usable_protocols)
1052 enum ofputil_protocol cur_protocol;
1056 if (!(usable_protocols & allowed_protocols)) {
1057 char *allowed_s = ofputil_protocols_to_string(allowed_protocols);
1058 usable_s = ofputil_protocols_to_string(usable_protocols);
1059 ovs_fatal(0, "none of the usable flow formats (%s) is among the "
1060 "allowed flow formats (%s)", usable_s, allowed_s);
1063 /* If the initial flow format is allowed and usable, keep it. */
1064 cur_protocol = open_vconn(remote, vconnp);
1065 if (usable_protocols & allowed_protocols & cur_protocol) {
1066 return cur_protocol;
1069 /* Otherwise try each flow format in turn. */
1070 for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) {
1071 enum ofputil_protocol f = 1 << i;
1073 if (f != cur_protocol
1074 && f & usable_protocols & allowed_protocols
1075 && try_set_protocol(*vconnp, f, &cur_protocol)) {
1080 usable_s = ofputil_protocols_to_string(usable_protocols);
1081 ovs_fatal(0, "switch does not support any of the usable flow "
1082 "formats (%s)", usable_s);
1086 ofctl_flow_mod__(const char *remote, struct ofputil_flow_mod *fms,
1087 size_t n_fms, enum ofputil_protocol usable_protocols)
1089 enum ofputil_protocol protocol;
1090 struct vconn *vconn;
1093 protocol = open_vconn_for_flow_mod(remote, &vconn, usable_protocols);
1095 for (i = 0; i < n_fms; i++) {
1096 struct ofputil_flow_mod *fm = &fms[i];
1098 transact_noreply(vconn, ofputil_encode_flow_mod(fm, protocol));
1105 ofctl_flow_mod_file(int argc OVS_UNUSED, char *argv[], uint16_t command)
1107 enum ofputil_protocol usable_protocols;
1108 struct ofputil_flow_mod *fms = NULL;
1112 error = parse_ofp_flow_mod_file(argv[2], command, &fms, &n_fms,
1115 ovs_fatal(0, "%s", error);
1117 ofctl_flow_mod__(argv[1], fms, n_fms, usable_protocols);
1122 ofctl_flow_mod(int argc, char *argv[], uint16_t command)
1124 if (argc > 2 && !strcmp(argv[2], "-")) {
1125 ofctl_flow_mod_file(argc, argv, command);
1127 struct ofputil_flow_mod fm;
1129 enum ofputil_protocol usable_protocols;
1131 error = parse_ofp_flow_mod_str(&fm, argc > 2 ? argv[2] : "", command,
1134 ovs_fatal(0, "%s", error);
1136 ofctl_flow_mod__(argv[1], &fm, 1, usable_protocols);
1141 ofctl_add_flow(int argc, char *argv[])
1143 ofctl_flow_mod(argc, argv, OFPFC_ADD);
1147 ofctl_add_flows(int argc, char *argv[])
1149 ofctl_flow_mod_file(argc, argv, OFPFC_ADD);
1153 ofctl_mod_flows(int argc, char *argv[])
1155 ofctl_flow_mod(argc, argv, strict ? OFPFC_MODIFY_STRICT : OFPFC_MODIFY);
1159 ofctl_del_flows(int argc, char *argv[])
1161 ofctl_flow_mod(argc, argv, strict ? OFPFC_DELETE_STRICT : OFPFC_DELETE);
1165 set_packet_in_format(struct vconn *vconn,
1166 enum nx_packet_in_format packet_in_format)
1168 struct ofpbuf *spif;
1170 spif = ofputil_make_set_packet_in_format(vconn_get_version(vconn),
1172 transact_noreply(vconn, spif);
1173 VLOG_DBG("%s: using user-specified packet in format %s",
1174 vconn_get_name(vconn),
1175 ofputil_packet_in_format_to_string(packet_in_format));
1179 monitor_set_invalid_ttl_to_controller(struct vconn *vconn)
1181 struct ofp_switch_config config;
1182 enum ofp_config_flags flags;
1184 fetch_switch_config(vconn, &config);
1185 flags = ntohs(config.flags);
1186 if (!(flags & OFPC_INVALID_TTL_TO_CONTROLLER)) {
1187 /* Set the invalid ttl config. */
1188 flags |= OFPC_INVALID_TTL_TO_CONTROLLER;
1190 config.flags = htons(flags);
1191 set_switch_config(vconn, &config);
1193 /* Then retrieve the configuration to see if it really took. OpenFlow
1194 * doesn't define error reporting for bad modes, so this is all we can
1196 fetch_switch_config(vconn, &config);
1197 flags = ntohs(config.flags);
1198 if (!(flags & OFPC_INVALID_TTL_TO_CONTROLLER)) {
1199 ovs_fatal(0, "setting invalid_ttl_to_controller failed (this "
1200 "switch probably doesn't support mode)");
1207 /* Converts hex digits in 'hex' to an OpenFlow message in '*msgp'. The
1208 * caller must free '*msgp'. On success, returns NULL. On failure, returns
1209 * an error message and stores NULL in '*msgp'. */
1211 openflow_from_hex(const char *hex, struct ofpbuf **msgp)
1213 struct ofp_header *oh;
1216 msg = ofpbuf_new(strlen(hex) / 2);
1219 if (ofpbuf_put_hex(msg, hex, NULL)[0] != '\0') {
1221 return "Trailing garbage in hex data";
1224 if (msg->size < sizeof(struct ofp_header)) {
1226 return "Message too short for OpenFlow";
1230 if (msg->size != ntohs(oh->length)) {
1232 return "Message size does not match length in OpenFlow header";
1240 ofctl_send(struct unixctl_conn *conn, int argc,
1241 const char *argv[], void *vconn_)
1243 struct vconn *vconn = vconn_;
1250 for (i = 1; i < argc; i++) {
1251 const char *error_msg;
1255 error_msg = openflow_from_hex(argv[i], &msg);
1257 ds_put_format(&reply, "%s\n", error_msg);
1262 fprintf(stderr, "send: ");
1263 ofp_print(stderr, msg->data, msg->size, verbosity);
1265 error = vconn_send_block(vconn, msg);
1268 ds_put_format(&reply, "%s\n", ovs_strerror(error));
1271 ds_put_cstr(&reply, "sent\n");
1276 unixctl_command_reply(conn, ds_cstr(&reply));
1278 unixctl_command_reply_error(conn, ds_cstr(&reply));
1283 struct barrier_aux {
1284 struct vconn *vconn; /* OpenFlow connection for sending barrier. */
1285 struct unixctl_conn *conn; /* Connection waiting for barrier response. */
1289 ofctl_barrier(struct unixctl_conn *conn, int argc OVS_UNUSED,
1290 const char *argv[] OVS_UNUSED, void *aux_)
1292 struct barrier_aux *aux = aux_;
1297 unixctl_command_reply_error(conn, "already waiting for barrier reply");
1301 msg = ofputil_encode_barrier_request(vconn_get_version(aux->vconn));
1302 error = vconn_send_block(aux->vconn, msg);
1305 unixctl_command_reply_error(conn, ovs_strerror(error));
1312 ofctl_set_output_file(struct unixctl_conn *conn, int argc OVS_UNUSED,
1313 const char *argv[], void *aux OVS_UNUSED)
1317 fd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666);
1319 unixctl_command_reply_error(conn, ovs_strerror(errno));
1324 dup2(fd, STDERR_FILENO);
1326 unixctl_command_reply(conn, NULL);
1330 ofctl_block(struct unixctl_conn *conn, int argc OVS_UNUSED,
1331 const char *argv[] OVS_UNUSED, void *blocked_)
1333 bool *blocked = blocked_;
1337 unixctl_command_reply(conn, NULL);
1339 unixctl_command_reply(conn, "already blocking");
1344 ofctl_unblock(struct unixctl_conn *conn, int argc OVS_UNUSED,
1345 const char *argv[] OVS_UNUSED, void *blocked_)
1347 bool *blocked = blocked_;
1351 unixctl_command_reply(conn, NULL);
1353 unixctl_command_reply(conn, "already unblocked");
1357 /* Prints to stdout all of the messages received on 'vconn'.
1359 * Iff 'reply_to_echo_requests' is true, sends a reply to any echo request
1360 * received on 'vconn'. */
1362 monitor_vconn(struct vconn *vconn, bool reply_to_echo_requests)
1364 struct barrier_aux barrier_aux = { vconn, NULL };
1365 struct unixctl_server *server;
1366 bool exiting = false;
1367 bool blocked = false;
1370 daemon_save_fd(STDERR_FILENO);
1372 error = unixctl_server_create(NULL, &server);
1374 ovs_fatal(error, "failed to create unixctl server");
1376 unixctl_command_register("exit", "", 0, 0, ofctl_exit, &exiting);
1377 unixctl_command_register("ofctl/send", "OFMSG...", 1, INT_MAX,
1379 unixctl_command_register("ofctl/barrier", "", 0, 0,
1380 ofctl_barrier, &barrier_aux);
1381 unixctl_command_register("ofctl/set-output-file", "FILE", 1, 1,
1382 ofctl_set_output_file, NULL);
1384 unixctl_command_register("ofctl/block", "", 0, 0, ofctl_block, &blocked);
1385 unixctl_command_register("ofctl/unblock", "", 0, 0, ofctl_unblock,
1388 daemonize_complete();
1394 unixctl_server_run(server);
1399 retval = vconn_recv(vconn, &b);
1400 if (retval == EAGAIN) {
1403 run(retval, "vconn_recv");
1406 char *s = xastrftime_msec("%Y-%m-%d %H:%M:%S.###: ",
1407 time_wall_msec(), true);
1412 ofptype_decode(&type, b->data);
1413 ofp_print(stderr, b->data, b->size, verbosity + 2);
1415 switch ((int) type) {
1416 case OFPTYPE_BARRIER_REPLY:
1417 if (barrier_aux.conn) {
1418 unixctl_command_reply(barrier_aux.conn, NULL);
1419 barrier_aux.conn = NULL;
1423 case OFPTYPE_ECHO_REQUEST:
1424 if (reply_to_echo_requests) {
1425 struct ofpbuf *reply;
1427 reply = make_echo_reply(b->data);
1428 retval = vconn_send_block(vconn, reply);
1430 ovs_fatal(retval, "failed to send echo reply");
1443 vconn_run_wait(vconn);
1445 vconn_recv_wait(vconn);
1447 unixctl_server_wait(server);
1451 unixctl_server_destroy(server);
1455 ofctl_monitor(int argc, char *argv[])
1457 struct vconn *vconn;
1459 enum ofputil_protocol usable_protocols;
1461 open_vconn(argv[1], &vconn);
1462 for (i = 2; i < argc; i++) {
1463 const char *arg = argv[i];
1465 if (isdigit((unsigned char) *arg)) {
1466 struct ofp_switch_config config;
1468 fetch_switch_config(vconn, &config);
1469 config.miss_send_len = htons(atoi(arg));
1470 set_switch_config(vconn, &config);
1471 } else if (!strcmp(arg, "invalid_ttl")) {
1472 monitor_set_invalid_ttl_to_controller(vconn);
1473 } else if (!strncmp(arg, "watch:", 6)) {
1474 struct ofputil_flow_monitor_request fmr;
1478 error = parse_flow_monitor_request(&fmr, arg + 6,
1481 ovs_fatal(0, "%s", error);
1484 msg = ofpbuf_new(0);
1485 ofputil_append_flow_monitor_request(&fmr, msg);
1486 dump_stats_transaction(vconn, msg);
1488 ovs_fatal(0, "%s: unsupported \"monitor\" argument", arg);
1492 if (preferred_packet_in_format >= 0) {
1493 set_packet_in_format(vconn, preferred_packet_in_format);
1495 enum ofp_version version = vconn_get_version(vconn);
1498 case OFP10_VERSION: {
1499 struct ofpbuf *spif, *reply;
1501 spif = ofputil_make_set_packet_in_format(vconn_get_version(vconn),
1503 run(vconn_transact_noreply(vconn, spif, &reply),
1504 "talking to %s", vconn_get_name(vconn));
1506 char *s = ofp_to_string(reply->data, reply->size, 2);
1507 VLOG_DBG("%s: failed to set packet in format to nxm, controller"
1508 " replied: %s. Falling back to the switch default.",
1509 vconn_get_name(vconn), s);
1511 ofpbuf_delete(reply);
1524 monitor_vconn(vconn, true);
1528 ofctl_snoop(int argc OVS_UNUSED, char *argv[])
1530 struct vconn *vconn;
1532 open_vconn__(argv[1], SNOOP, &vconn);
1533 monitor_vconn(vconn, false);
1537 ofctl_dump_ports(int argc, char *argv[])
1539 struct ofpbuf *request;
1540 struct vconn *vconn;
1543 open_vconn(argv[1], &vconn);
1544 port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_ANY;
1545 request = ofputil_encode_dump_ports_request(vconn_get_version(vconn), port);
1546 dump_stats_transaction(vconn, request);
1551 ofctl_dump_ports_desc(int argc OVS_UNUSED, char *argv[])
1553 dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_PORT_DESC_REQUEST);
1557 ofctl_probe(int argc OVS_UNUSED, char *argv[])
1559 struct ofpbuf *request;
1560 struct vconn *vconn;
1561 struct ofpbuf *reply;
1563 open_vconn(argv[1], &vconn);
1564 request = make_echo_request(vconn_get_version(vconn));
1565 run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
1566 if (reply->size != sizeof(struct ofp_header)) {
1567 ovs_fatal(0, "reply does not match request");
1569 ofpbuf_delete(reply);
1574 ofctl_packet_out(int argc, char *argv[])
1576 enum ofputil_protocol protocol;
1577 struct ofputil_packet_out po;
1578 struct ofpbuf ofpacts;
1579 struct vconn *vconn;
1582 enum ofputil_protocol usable_protocols; /* TODO: Use in proto selection */
1584 ofpbuf_init(&ofpacts, 64);
1585 error = parse_ofpacts(argv[3], &ofpacts, &usable_protocols);
1587 ovs_fatal(0, "%s", error);
1590 po.buffer_id = UINT32_MAX;
1591 po.in_port = str_to_port_no(argv[1], argv[2]);
1592 po.ofpacts = ofpacts.data;
1593 po.ofpacts_len = ofpacts.size;
1595 protocol = open_vconn(argv[1], &vconn);
1596 for (i = 4; i < argc; i++) {
1597 struct ofpbuf *packet, *opo;
1598 const char *error_msg;
1600 error_msg = eth_from_hex(argv[i], &packet);
1602 ovs_fatal(0, "%s", error_msg);
1605 po.packet = packet->data;
1606 po.packet_len = packet->size;
1607 opo = ofputil_encode_packet_out(&po, protocol);
1608 transact_noreply(vconn, opo);
1609 ofpbuf_delete(packet);
1612 ofpbuf_uninit(&ofpacts);
1616 ofctl_mod_port(int argc OVS_UNUSED, char *argv[])
1618 struct ofp_config_flag {
1619 const char *name; /* The flag's name. */
1620 enum ofputil_port_config bit; /* Bit to turn on or off. */
1621 bool on; /* Value to set the bit to. */
1623 static const struct ofp_config_flag flags[] = {
1624 { "up", OFPUTIL_PC_PORT_DOWN, false },
1625 { "down", OFPUTIL_PC_PORT_DOWN, true },
1626 { "stp", OFPUTIL_PC_NO_STP, false },
1627 { "receive", OFPUTIL_PC_NO_RECV, false },
1628 { "receive-stp", OFPUTIL_PC_NO_RECV_STP, false },
1629 { "flood", OFPUTIL_PC_NO_FLOOD, false },
1630 { "forward", OFPUTIL_PC_NO_FWD, false },
1631 { "packet-in", OFPUTIL_PC_NO_PACKET_IN, false },
1634 const struct ofp_config_flag *flag;
1635 enum ofputil_protocol protocol;
1636 struct ofputil_port_mod pm;
1637 struct ofputil_phy_port pp;
1638 struct vconn *vconn;
1639 const char *command;
1642 fetch_ofputil_phy_port(argv[1], argv[2], &pp);
1644 pm.port_no = pp.port_no;
1645 memcpy(pm.hw_addr, pp.hw_addr, ETH_ADDR_LEN);
1650 if (!strncasecmp(argv[3], "no-", 3)) {
1651 command = argv[3] + 3;
1653 } else if (!strncasecmp(argv[3], "no", 2)) {
1654 command = argv[3] + 2;
1660 for (flag = flags; flag < &flags[ARRAY_SIZE(flags)]; flag++) {
1661 if (!strcasecmp(command, flag->name)) {
1662 pm.mask = flag->bit;
1663 pm.config = flag->on ^ not ? flag->bit : 0;
1667 ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
1670 protocol = open_vconn(argv[1], &vconn);
1671 transact_noreply(vconn, ofputil_encode_port_mod(&pm, protocol));
1676 ofctl_mod_table(int argc OVS_UNUSED, char *argv[])
1678 enum ofputil_protocol protocol, usable_protocols;
1679 struct ofputil_table_mod tm;
1680 struct vconn *vconn;
1684 error = parse_ofp_table_mod(&tm, argv[2], argv[3], &usable_protocols);
1686 ovs_fatal(0, "%s", error);
1689 protocol = open_vconn(argv[1], &vconn);
1690 if (!(protocol & usable_protocols)) {
1691 for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) {
1692 enum ofputil_protocol f = 1 << i;
1694 && f & usable_protocols
1695 && try_set_protocol(vconn, f, &protocol)) {
1702 if (!(protocol & usable_protocols)) {
1703 char *usable_s = ofputil_protocols_to_string(usable_protocols);
1704 ovs_fatal(0, "Switch does not support table mod message(%s)", usable_s);
1707 transact_noreply(vconn, ofputil_encode_table_mod(&tm, protocol));
1712 ofctl_get_frags(int argc OVS_UNUSED, char *argv[])
1714 struct ofp_switch_config config;
1715 struct vconn *vconn;
1717 open_vconn(argv[1], &vconn);
1718 fetch_switch_config(vconn, &config);
1719 puts(ofputil_frag_handling_to_string(ntohs(config.flags)));
1724 ofctl_set_frags(int argc OVS_UNUSED, char *argv[])
1726 struct ofp_switch_config config;
1727 enum ofp_config_flags mode;
1728 struct vconn *vconn;
1731 if (!ofputil_frag_handling_from_string(argv[2], &mode)) {
1732 ovs_fatal(0, "%s: unknown fragment handling mode", argv[2]);
1735 open_vconn(argv[1], &vconn);
1736 fetch_switch_config(vconn, &config);
1737 flags = htons(mode) | (config.flags & htons(~OFPC_FRAG_MASK));
1738 if (flags != config.flags) {
1739 /* Set the configuration. */
1740 config.flags = flags;
1741 set_switch_config(vconn, &config);
1743 /* Then retrieve the configuration to see if it really took. OpenFlow
1744 * doesn't define error reporting for bad modes, so this is all we can
1746 fetch_switch_config(vconn, &config);
1747 if (flags != config.flags) {
1748 ovs_fatal(0, "%s: setting fragment handling mode failed (this "
1749 "switch probably doesn't support mode \"%s\")",
1750 argv[1], ofputil_frag_handling_to_string(mode));
1757 ofctl_ofp_parse(int argc OVS_UNUSED, char *argv[])
1759 const char *filename = argv[1];
1763 file = !strcmp(filename, "-") ? stdin : fopen(filename, "r");
1765 ovs_fatal(errno, "%s: open", filename);
1768 ofpbuf_init(&b, 65536);
1770 struct ofp_header *oh;
1771 size_t length, tail_len;
1776 oh = ofpbuf_put_uninit(&b, sizeof *oh);
1777 n = fread(oh, 1, sizeof *oh, file);
1780 } else if (n < sizeof *oh) {
1781 ovs_fatal(0, "%s: unexpected end of file mid-message", filename);
1784 length = ntohs(oh->length);
1785 if (length < sizeof *oh) {
1786 ovs_fatal(0, "%s: %zu-byte message is too short for OpenFlow",
1790 tail_len = length - sizeof *oh;
1791 tail = ofpbuf_put_uninit(&b, tail_len);
1792 n = fread(tail, 1, tail_len, file);
1794 ovs_fatal(0, "%s: unexpected end of file mid-message", filename);
1797 ofp_print(stdout, b.data, b.size, verbosity + 2);
1801 if (file != stdin) {
1807 ofctl_ping(int argc, char *argv[])
1809 size_t max_payload = 65535 - sizeof(struct ofp_header);
1810 unsigned int payload;
1811 struct vconn *vconn;
1814 payload = argc > 2 ? atoi(argv[2]) : 64;
1815 if (payload > max_payload) {
1816 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
1819 open_vconn(argv[1], &vconn);
1820 for (i = 0; i < 10; i++) {
1821 struct timeval start, end;
1822 struct ofpbuf *request, *reply;
1823 const struct ofp_header *rpy_hdr;
1826 request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST,
1827 vconn_get_version(vconn), payload);
1828 random_bytes(ofpbuf_put_uninit(request, payload), payload);
1830 xgettimeofday(&start);
1831 run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
1832 xgettimeofday(&end);
1834 rpy_hdr = reply->data;
1835 if (ofptype_pull(&type, reply)
1836 || type != OFPTYPE_ECHO_REPLY
1837 || reply->size != payload
1838 || memcmp(request->l3, reply->l3, payload)) {
1839 printf("Reply does not match request. Request:\n");
1840 ofp_print(stdout, request, request->size, verbosity + 2);
1842 ofp_print(stdout, reply, reply->size, verbosity + 2);
1844 printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
1845 reply->size, argv[1], ntohl(rpy_hdr->xid),
1846 (1000*(double)(end.tv_sec - start.tv_sec))
1847 + (.001*(end.tv_usec - start.tv_usec)));
1848 ofpbuf_delete(request);
1849 ofpbuf_delete(reply);
1855 ofctl_benchmark(int argc OVS_UNUSED, char *argv[])
1857 size_t max_payload = 65535 - sizeof(struct ofp_header);
1858 struct timeval start, end;
1859 unsigned int payload_size, message_size;
1860 struct vconn *vconn;
1865 payload_size = atoi(argv[2]);
1866 if (payload_size > max_payload) {
1867 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
1869 message_size = sizeof(struct ofp_header) + payload_size;
1871 count = atoi(argv[3]);
1873 printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
1874 count, message_size, count * message_size);
1876 open_vconn(argv[1], &vconn);
1877 xgettimeofday(&start);
1878 for (i = 0; i < count; i++) {
1879 struct ofpbuf *request, *reply;
1881 request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST,
1882 vconn_get_version(vconn), payload_size);
1883 ofpbuf_put_zeros(request, payload_size);
1884 run(vconn_transact(vconn, request, &reply), "transact");
1885 ofpbuf_delete(reply);
1887 xgettimeofday(&end);
1890 duration = ((1000*(double)(end.tv_sec - start.tv_sec))
1891 + (.001*(end.tv_usec - start.tv_usec)));
1892 printf("Finished in %.1f ms (%.0f packets/s) (%.0f bytes/s)\n",
1893 duration, count / (duration / 1000.0),
1894 count * message_size / (duration / 1000.0));
1898 ofctl_group_mod__(const char *remote, struct ofputil_group_mod *gms,
1901 struct ofputil_group_mod *gm;
1902 struct ofpbuf *request;
1904 struct vconn *vconn;
1907 open_vconn(remote, &vconn);
1909 for (i = 0; i < n_gms; i++) {
1911 request = ofputil_encode_group_mod(vconn_get_version(vconn), gm);
1913 transact_noreply(vconn, request);
1923 ofctl_group_mod_file(int argc OVS_UNUSED, char *argv[], uint16_t command)
1925 struct ofputil_group_mod *gms = NULL;
1926 enum ofputil_protocol usable_protocols;
1930 error = parse_ofp_group_mod_file(argv[2], command, &gms, &n_gms,
1933 ovs_fatal(0, "%s", error);
1935 ofctl_group_mod__(argv[1], gms, n_gms);
1940 ofctl_group_mod(int argc, char *argv[], uint16_t command)
1942 if (argc > 2 && !strcmp(argv[2], "-")) {
1943 ofctl_group_mod_file(argc, argv, command);
1945 enum ofputil_protocol usable_protocols;
1946 struct ofputil_group_mod gm;
1949 error = parse_ofp_group_mod_str(&gm, command, argc > 2 ? argv[2] : "",
1952 ovs_fatal(0, "%s", error);
1954 ofctl_group_mod__(argv[1], &gm, 1);
1959 ofctl_add_group(int argc, char *argv[])
1961 ofctl_group_mod(argc, argv, OFPGC11_ADD);
1965 ofctl_add_groups(int argc, char *argv[])
1967 ofctl_group_mod_file(argc, argv, OFPGC11_ADD);
1971 ofctl_mod_group(int argc, char *argv[])
1973 ofctl_group_mod(argc, argv, OFPGC11_MODIFY);
1977 ofctl_del_groups(int argc, char *argv[])
1979 ofctl_group_mod(argc, argv, OFPGC11_DELETE);
1983 ofctl_dump_group_stats(int argc, char *argv[])
1985 enum ofputil_protocol usable_protocols;
1986 struct ofputil_group_mod gm;
1987 struct ofpbuf *request;
1988 struct vconn *vconn;
1992 memset(&gm, 0, sizeof gm);
1994 error = parse_ofp_group_mod_str(&gm, OFPGC11_DELETE,
1995 argc > 2 ? argv[2] : "",
1998 ovs_fatal(0, "%s", error);
2001 group_id = gm.group_id;
2003 open_vconn(argv[1], &vconn);
2004 request = ofputil_encode_group_stats_request(vconn_get_version(vconn),
2007 dump_stats_transaction(vconn, request);
2014 ofctl_dump_group_desc(int argc OVS_UNUSED, char *argv[])
2016 struct ofpbuf *request;
2017 struct vconn *vconn;
2019 open_vconn(argv[1], &vconn);
2021 request = ofputil_encode_group_desc_request(vconn_get_version(vconn));
2023 dump_stats_transaction(vconn, request);
2030 ofctl_dump_group_features(int argc OVS_UNUSED, char *argv[])
2032 struct ofpbuf *request;
2033 struct vconn *vconn;
2035 open_vconn(argv[1], &vconn);
2036 request = ofputil_encode_group_features_request(vconn_get_version(vconn));
2038 dump_stats_transaction(vconn, request);
2045 ofctl_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2050 /* replace-flows and diff-flows commands. */
2052 /* A flow table entry, possibly with two different versions. */
2054 struct cls_rule rule; /* Within a "struct classifier". */
2055 struct fte_version *versions[2];
2058 /* One version of a Flow Table Entry. */
2059 struct fte_version {
2061 uint16_t idle_timeout;
2062 uint16_t hard_timeout;
2064 struct ofpact *ofpacts;
2068 /* Frees 'version' and the data that it owns. */
2070 fte_version_free(struct fte_version *version)
2073 free(version->ofpacts);
2078 /* Returns true if 'a' and 'b' are the same, false if they differ.
2080 * Ignores differences in 'flags' because there's no way to retrieve flags from
2081 * an OpenFlow switch. We have to assume that they are the same. */
2083 fte_version_equals(const struct fte_version *a, const struct fte_version *b)
2085 return (a->cookie == b->cookie
2086 && a->idle_timeout == b->idle_timeout
2087 && a->hard_timeout == b->hard_timeout
2088 && ofpacts_equal(a->ofpacts, a->ofpacts_len,
2089 b->ofpacts, b->ofpacts_len));
2092 /* Clears 's', then if 's' has a version 'index', formats 'fte' and version
2093 * 'index' into 's', followed by a new-line. */
2095 fte_version_format(const struct fte *fte, int index, struct ds *s)
2097 const struct fte_version *version = fte->versions[index];
2104 cls_rule_format(&fte->rule, s);
2105 if (version->cookie != htonll(0)) {
2106 ds_put_format(s, " cookie=0x%"PRIx64, ntohll(version->cookie));
2108 if (version->idle_timeout != OFP_FLOW_PERMANENT) {
2109 ds_put_format(s, " idle_timeout=%"PRIu16, version->idle_timeout);
2111 if (version->hard_timeout != OFP_FLOW_PERMANENT) {
2112 ds_put_format(s, " hard_timeout=%"PRIu16, version->hard_timeout);
2115 ds_put_char(s, ' ');
2116 ofpacts_format(version->ofpacts, version->ofpacts_len, s);
2118 ds_put_char(s, '\n');
2122 fte_from_cls_rule(const struct cls_rule *cls_rule)
2124 return cls_rule ? CONTAINER_OF(cls_rule, struct fte, rule) : NULL;
2127 /* Frees 'fte' and its versions. */
2129 fte_free(struct fte *fte)
2132 fte_version_free(fte->versions[0]);
2133 fte_version_free(fte->versions[1]);
2134 cls_rule_destroy(&fte->rule);
2139 /* Frees all of the FTEs within 'cls'. */
2141 fte_free_all(struct classifier *cls)
2143 struct cls_cursor cursor;
2144 struct fte *fte, *next;
2146 ovs_rwlock_wrlock(&cls->rwlock);
2147 cls_cursor_init(&cursor, cls, NULL);
2148 CLS_CURSOR_FOR_EACH_SAFE (fte, next, rule, &cursor) {
2149 classifier_remove(cls, &fte->rule);
2152 ovs_rwlock_unlock(&cls->rwlock);
2153 classifier_destroy(cls);
2156 /* Searches 'cls' for an FTE matching 'rule', inserting a new one if
2157 * necessary. Sets 'version' as the version of that rule with the given
2158 * 'index', replacing any existing version, if any.
2160 * Takes ownership of 'version'. */
2162 fte_insert(struct classifier *cls, const struct match *match,
2163 unsigned int priority, struct fte_version *version, int index)
2165 struct fte *old, *fte;
2167 fte = xzalloc(sizeof *fte);
2168 cls_rule_init(&fte->rule, match, priority);
2169 fte->versions[index] = version;
2171 ovs_rwlock_wrlock(&cls->rwlock);
2172 old = fte_from_cls_rule(classifier_replace(cls, &fte->rule));
2173 ovs_rwlock_unlock(&cls->rwlock);
2175 fte_version_free(old->versions[index]);
2176 fte->versions[!index] = old->versions[!index];
2177 cls_rule_destroy(&old->rule);
2182 /* Reads the flows in 'filename' as flow table entries in 'cls' for the version
2183 * with the specified 'index'. Returns the flow formats able to represent the
2184 * flows that were read. */
2185 static enum ofputil_protocol
2186 read_flows_from_file(const char *filename, struct classifier *cls, int index)
2188 enum ofputil_protocol usable_protocols;
2193 file = !strcmp(filename, "-") ? stdin : fopen(filename, "r");
2195 ovs_fatal(errno, "%s: open", filename);
2199 usable_protocols = OFPUTIL_P_ANY;
2201 while (!ds_get_preprocessed_line(&s, file, &line_number)) {
2202 struct fte_version *version;
2203 struct ofputil_flow_mod fm;
2205 enum ofputil_protocol usable;
2207 error = parse_ofp_str(&fm, OFPFC_ADD, ds_cstr(&s), &usable);
2209 ovs_fatal(0, "%s:%d: %s", filename, line_number, error);
2211 usable_protocols &= usable;
2213 version = xmalloc(sizeof *version);
2214 version->cookie = fm.new_cookie;
2215 version->idle_timeout = fm.idle_timeout;
2216 version->hard_timeout = fm.hard_timeout;
2217 version->flags = fm.flags & (OFPUTIL_FF_SEND_FLOW_REM
2218 | OFPUTIL_FF_EMERG);
2219 version->ofpacts = fm.ofpacts;
2220 version->ofpacts_len = fm.ofpacts_len;
2222 fte_insert(cls, &fm.match, fm.priority, version, index);
2226 if (file != stdin) {
2230 return usable_protocols;
2234 recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid,
2235 struct ofpbuf **replyp,
2236 struct ofputil_flow_stats *fs, struct ofpbuf *ofpacts)
2238 struct ofpbuf *reply = *replyp;
2244 /* Get a flow stats reply message, if we don't already have one. */
2250 run(vconn_recv_block(vconn, &reply),
2251 "OpenFlow packet receive failed");
2252 } while (((struct ofp_header *) reply->data)->xid != send_xid);
2254 error = ofptype_decode(&type, reply->data);
2255 if (error || type != OFPTYPE_FLOW_STATS_REPLY) {
2256 ovs_fatal(0, "received bad reply: %s",
2257 ofp_to_string(reply->data, reply->size,
2262 /* Pull an individual flow stats reply out of the message. */
2263 retval = ofputil_decode_flow_stats_reply(fs, reply, false, ofpacts);
2270 more = ofpmp_more(reply->l2);
2271 ofpbuf_delete(reply);
2280 ovs_fatal(0, "parse error in reply (%s)",
2281 ofperr_to_string(retval));
2286 /* Reads the OpenFlow flow table from 'vconn', which has currently active flow
2287 * format 'protocol', and adds them as flow table entries in 'cls' for the
2288 * version with the specified 'index'. */
2290 read_flows_from_switch(struct vconn *vconn,
2291 enum ofputil_protocol protocol,
2292 struct classifier *cls, int index)
2294 struct ofputil_flow_stats_request fsr;
2295 struct ofputil_flow_stats fs;
2296 struct ofpbuf *request;
2297 struct ofpbuf ofpacts;
2298 struct ofpbuf *reply;
2301 fsr.aggregate = false;
2302 match_init_catchall(&fsr.match);
2303 fsr.out_port = OFPP_ANY;
2304 fsr.table_id = 0xff;
2305 fsr.cookie = fsr.cookie_mask = htonll(0);
2306 request = ofputil_encode_flow_stats_request(&fsr, protocol);
2307 send_xid = ((struct ofp_header *) request->data)->xid;
2308 send_openflow_buffer(vconn, request);
2311 ofpbuf_init(&ofpacts, 0);
2312 while (recv_flow_stats_reply(vconn, send_xid, &reply, &fs, &ofpacts)) {
2313 struct fte_version *version;
2315 version = xmalloc(sizeof *version);
2316 version->cookie = fs.cookie;
2317 version->idle_timeout = fs.idle_timeout;
2318 version->hard_timeout = fs.hard_timeout;
2320 version->ofpacts_len = fs.ofpacts_len;
2321 version->ofpacts = xmemdup(fs.ofpacts, fs.ofpacts_len);
2323 fte_insert(cls, &fs.match, fs.priority, version, index);
2325 ofpbuf_uninit(&ofpacts);
2329 fte_make_flow_mod(const struct fte *fte, int index, uint16_t command,
2330 enum ofputil_protocol protocol, struct list *packets)
2332 const struct fte_version *version = fte->versions[index];
2333 struct ofputil_flow_mod fm;
2336 minimatch_expand(&fte->rule.match, &fm.match);
2337 fm.priority = fte->rule.priority;
2338 fm.cookie = htonll(0);
2339 fm.cookie_mask = htonll(0);
2340 fm.new_cookie = version->cookie;
2341 fm.modify_cookie = true;
2343 fm.command = command;
2344 fm.idle_timeout = version->idle_timeout;
2345 fm.hard_timeout = version->hard_timeout;
2346 fm.buffer_id = UINT32_MAX;
2347 fm.out_port = OFPP_ANY;
2348 fm.flags = version->flags;
2349 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
2350 command == OFPFC_MODIFY_STRICT) {
2351 fm.ofpacts = version->ofpacts;
2352 fm.ofpacts_len = version->ofpacts_len;
2358 ofm = ofputil_encode_flow_mod(&fm, protocol);
2359 list_push_back(packets, &ofm->list_node);
2363 ofctl_replace_flows(int argc OVS_UNUSED, char *argv[])
2365 enum { FILE_IDX = 0, SWITCH_IDX = 1 };
2366 enum ofputil_protocol usable_protocols, protocol;
2367 struct cls_cursor cursor;
2368 struct classifier cls;
2369 struct list requests;
2370 struct vconn *vconn;
2373 classifier_init(&cls);
2374 usable_protocols = read_flows_from_file(argv[2], &cls, FILE_IDX);
2376 protocol = open_vconn(argv[1], &vconn);
2377 protocol = set_protocol_for_flow_dump(vconn, protocol, usable_protocols);
2379 read_flows_from_switch(vconn, protocol, &cls, SWITCH_IDX);
2381 list_init(&requests);
2383 /* Delete flows that exist on the switch but not in the file. */
2384 ovs_rwlock_rdlock(&cls.rwlock);
2385 cls_cursor_init(&cursor, &cls, NULL);
2386 CLS_CURSOR_FOR_EACH (fte, rule, &cursor) {
2387 struct fte_version *file_ver = fte->versions[FILE_IDX];
2388 struct fte_version *sw_ver = fte->versions[SWITCH_IDX];
2390 if (sw_ver && !file_ver) {
2391 fte_make_flow_mod(fte, SWITCH_IDX, OFPFC_DELETE_STRICT,
2392 protocol, &requests);
2396 /* Add flows that exist in the file but not on the switch.
2397 * Update flows that exist in both places but differ. */
2398 cls_cursor_init(&cursor, &cls, NULL);
2399 CLS_CURSOR_FOR_EACH (fte, rule, &cursor) {
2400 struct fte_version *file_ver = fte->versions[FILE_IDX];
2401 struct fte_version *sw_ver = fte->versions[SWITCH_IDX];
2404 && (readd || !sw_ver || !fte_version_equals(sw_ver, file_ver))) {
2405 fte_make_flow_mod(fte, FILE_IDX, OFPFC_ADD, protocol, &requests);
2408 ovs_rwlock_unlock(&cls.rwlock);
2409 transact_multiple_noreply(vconn, &requests);
2416 read_flows_from_source(const char *source, struct classifier *cls, int index)
2420 if (source[0] == '/' || source[0] == '.'
2421 || (!strchr(source, ':') && !stat(source, &s))) {
2422 read_flows_from_file(source, cls, index);
2424 enum ofputil_protocol protocol;
2425 struct vconn *vconn;
2427 protocol = open_vconn(source, &vconn);
2428 protocol = set_protocol_for_flow_dump(vconn, protocol, OFPUTIL_P_ANY);
2429 read_flows_from_switch(vconn, protocol, cls, index);
2435 ofctl_diff_flows(int argc OVS_UNUSED, char *argv[])
2437 bool differences = false;
2438 struct cls_cursor cursor;
2439 struct classifier cls;
2443 classifier_init(&cls);
2444 read_flows_from_source(argv[1], &cls, 0);
2445 read_flows_from_source(argv[2], &cls, 1);
2450 ovs_rwlock_rdlock(&cls.rwlock);
2451 cls_cursor_init(&cursor, &cls, NULL);
2452 CLS_CURSOR_FOR_EACH (fte, rule, &cursor) {
2453 struct fte_version *a = fte->versions[0];
2454 struct fte_version *b = fte->versions[1];
2456 if (!a || !b || !fte_version_equals(a, b)) {
2457 fte_version_format(fte, 0, &a_s);
2458 fte_version_format(fte, 1, &b_s);
2459 if (strcmp(ds_cstr(&a_s), ds_cstr(&b_s))) {
2461 printf("-%s", ds_cstr(&a_s));
2464 printf("+%s", ds_cstr(&b_s));
2470 ovs_rwlock_unlock(&cls.rwlock);
2483 ofctl_meter_mod__(const char *bridge, const char *str, int command)
2485 struct ofputil_meter_mod mm;
2486 struct vconn *vconn;
2487 enum ofputil_protocol protocol;
2488 enum ofputil_protocol usable_protocols;
2489 enum ofp_version version;
2493 error = parse_ofp_meter_mod_str(&mm, str, command, &usable_protocols);
2495 ovs_fatal(0, "%s", error);
2498 usable_protocols = OFPUTIL_P_OF13_UP;
2499 mm.command = command;
2500 mm.meter.meter_id = OFPM13_ALL;
2503 protocol = open_vconn_for_flow_mod(bridge, &vconn, usable_protocols);
2504 version = ofputil_protocol_to_ofp_version(protocol);
2505 transact_noreply(vconn, ofputil_encode_meter_mod(version, &mm));
2510 ofctl_meter_request__(const char *bridge, const char *str,
2511 enum ofputil_meter_request_type type)
2513 struct ofputil_meter_mod mm;
2514 struct vconn *vconn;
2515 enum ofputil_protocol usable_protocols;
2516 enum ofputil_protocol protocol;
2517 enum ofp_version version;
2521 error = parse_ofp_meter_mod_str(&mm, str, -1, &usable_protocols);
2523 ovs_fatal(0, "%s", error);
2526 usable_protocols = OFPUTIL_P_OF13_UP;
2527 mm.meter.meter_id = OFPM13_ALL;
2530 protocol = open_vconn_for_flow_mod(bridge, &vconn, usable_protocols);
2531 version = ofputil_protocol_to_ofp_version(protocol);
2532 transact_noreply(vconn, ofputil_encode_meter_request(version,
2534 mm.meter.meter_id));
2540 ofctl_add_meter(int argc OVS_UNUSED, char *argv[])
2542 ofctl_meter_mod__(argv[1], argv[2], OFPMC13_ADD);
2546 ofctl_mod_meter(int argc OVS_UNUSED, char *argv[])
2548 ofctl_meter_mod__(argv[1], argv[2], OFPMC13_MODIFY);
2552 ofctl_del_meters(int argc, char *argv[])
2554 ofctl_meter_mod__(argv[1], argc > 2 ? argv[2] : NULL, OFPMC13_DELETE);
2558 ofctl_dump_meters(int argc, char *argv[])
2560 ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
2561 OFPUTIL_METER_CONFIG);
2565 ofctl_meter_stats(int argc, char *argv[])
2567 ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
2568 OFPUTIL_METER_STATS);
2572 ofctl_meter_features(int argc OVS_UNUSED, char *argv[])
2574 ofctl_meter_request__(argv[1], NULL, OFPUTIL_METER_FEATURES);
2578 /* Undocumented commands for unit testing. */
2581 ofctl_parse_flows__(struct ofputil_flow_mod *fms, size_t n_fms,
2582 enum ofputil_protocol usable_protocols)
2584 enum ofputil_protocol protocol = 0;
2588 usable_s = ofputil_protocols_to_string(usable_protocols);
2589 printf("usable protocols: %s\n", usable_s);
2592 if (!(usable_protocols & allowed_protocols)) {
2593 ovs_fatal(0, "no usable protocol");
2595 for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) {
2597 if (protocol & usable_protocols & allowed_protocols) {
2601 ovs_assert(is_pow2(protocol));
2603 printf("chosen protocol: %s\n", ofputil_protocol_to_string(protocol));
2605 for (i = 0; i < n_fms; i++) {
2606 struct ofputil_flow_mod *fm = &fms[i];
2609 msg = ofputil_encode_flow_mod(fm, protocol);
2610 ofp_print(stdout, msg->data, msg->size, verbosity);
2617 /* "parse-flow FLOW": parses the argument as a flow (like add-flow) and prints
2618 * it back to stdout. */
2620 ofctl_parse_flow(int argc OVS_UNUSED, char *argv[])
2622 enum ofputil_protocol usable_protocols;
2623 struct ofputil_flow_mod fm;
2626 error = parse_ofp_flow_mod_str(&fm, argv[1], OFPFC_ADD, &usable_protocols);
2628 ovs_fatal(0, "%s", error);
2630 ofctl_parse_flows__(&fm, 1, usable_protocols);
2633 /* "parse-flows FILENAME": reads the named file as a sequence of flows (like
2634 * add-flows) and prints each of the flows back to stdout. */
2636 ofctl_parse_flows(int argc OVS_UNUSED, char *argv[])
2638 enum ofputil_protocol usable_protocols;
2639 struct ofputil_flow_mod *fms = NULL;
2643 error = parse_ofp_flow_mod_file(argv[1], OFPFC_ADD, &fms, &n_fms,
2646 ovs_fatal(0, "%s", error);
2648 ofctl_parse_flows__(fms, n_fms, usable_protocols);
2653 ofctl_parse_nxm__(bool oxm)
2658 while (!ds_get_test_line(&in, stdin)) {
2659 struct ofpbuf nx_match;
2661 ovs_be64 cookie, cookie_mask;
2665 /* Convert string to nx_match. */
2666 ofpbuf_init(&nx_match, 0);
2668 match_len = oxm_match_from_string(ds_cstr(&in), &nx_match);
2670 match_len = nx_match_from_string(ds_cstr(&in), &nx_match);
2673 /* Convert nx_match to match. */
2676 error = oxm_pull_match(&nx_match, &match);
2678 error = nx_pull_match(&nx_match, match_len, &match,
2679 &cookie, &cookie_mask);
2683 error = oxm_pull_match_loose(&nx_match, &match);
2685 error = nx_pull_match_loose(&nx_match, match_len, &match,
2686 &cookie, &cookie_mask);
2694 /* Convert match back to nx_match. */
2695 ofpbuf_uninit(&nx_match);
2696 ofpbuf_init(&nx_match, 0);
2698 match_len = oxm_put_match(&nx_match, &match);
2699 out = oxm_match_to_string(&nx_match, match_len);
2701 match_len = nx_put_match(&nx_match, &match,
2702 cookie, cookie_mask);
2703 out = nx_match_to_string(nx_match.data, match_len);
2709 printf("nx_pull_match() returned error %s\n",
2710 ofperr_get_name(error));
2713 ofpbuf_uninit(&nx_match);
2718 /* "parse-nxm": reads a series of NXM nx_match specifications as strings from
2719 * stdin, does some internal fussing with them, and then prints them back as
2720 * strings on stdout. */
2722 ofctl_parse_nxm(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2724 return ofctl_parse_nxm__(false);
2727 /* "parse-oxm": reads a series of OXM nx_match specifications as strings from
2728 * stdin, does some internal fussing with them, and then prints them back as
2729 * strings on stdout. */
2731 ofctl_parse_oxm(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2733 return ofctl_parse_nxm__(true);
2737 print_differences(const char *prefix,
2738 const void *a_, size_t a_len,
2739 const void *b_, size_t b_len)
2741 const uint8_t *a = a_;
2742 const uint8_t *b = b_;
2745 for (i = 0; i < MIN(a_len, b_len); i++) {
2747 printf("%s%2zu: %02"PRIx8" -> %02"PRIx8"\n",
2748 prefix, i, a[i], b[i]);
2751 for (i = a_len; i < b_len; i++) {
2752 printf("%s%2zu: (none) -> %02"PRIx8"\n", prefix, i, b[i]);
2754 for (i = b_len; i < a_len; i++) {
2755 printf("%s%2zu: %02"PRIx8" -> (none)\n", prefix, i, a[i]);
2759 /* "parse-ofp10-actions": reads a series of OpenFlow 1.0 action specifications
2760 * as hex bytes from stdin, converts them to ofpacts, prints them as strings
2761 * on stdout, and then converts them back to hex bytes and prints any
2762 * differences from the input. */
2764 ofctl_parse_ofp10_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2769 while (!ds_get_preprocessed_line(&in, stdin, NULL)) {
2770 struct ofpbuf of10_out;
2771 struct ofpbuf of10_in;
2772 struct ofpbuf ofpacts;
2777 /* Parse hex bytes. */
2778 ofpbuf_init(&of10_in, 0);
2779 if (ofpbuf_put_hex(&of10_in, ds_cstr(&in), NULL)[0] != '\0') {
2780 ovs_fatal(0, "Trailing garbage in hex data");
2783 /* Convert to ofpacts. */
2784 ofpbuf_init(&ofpacts, 0);
2785 size = of10_in.size;
2786 error = ofpacts_pull_openflow10(&of10_in, of10_in.size, &ofpacts);
2788 printf("bad OF1.1 actions: %s\n\n", ofperr_get_name(error));
2789 ofpbuf_uninit(&ofpacts);
2790 ofpbuf_uninit(&of10_in);
2793 ofpbuf_push_uninit(&of10_in, size);
2795 /* Print cls_rule. */
2797 ofpacts_format(ofpacts.data, ofpacts.size, &s);
2801 /* Convert back to ofp10 actions and print differences from input. */
2802 ofpbuf_init(&of10_out, 0);
2803 ofpacts_put_openflow10(ofpacts.data, ofpacts.size, &of10_out);
2805 print_differences("", of10_in.data, of10_in.size,
2806 of10_out.data, of10_out.size);
2809 ofpbuf_uninit(&ofpacts);
2810 ofpbuf_uninit(&of10_in);
2811 ofpbuf_uninit(&of10_out);
2816 /* "parse-ofp10-match": reads a series of ofp10_match specifications as hex
2817 * bytes from stdin, converts them to cls_rules, prints them as strings on
2818 * stdout, and then converts them back to hex bytes and prints any differences
2821 * The input hex bytes may contain "x"s to represent "don't-cares", bytes whose
2822 * values are ignored in the input and will be set to zero when OVS converts
2823 * them back to hex bytes. ovs-ofctl actually sets "x"s to random bits when
2824 * it does the conversion to hex, to ensure that in fact they are ignored. */
2826 ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2833 while (!ds_get_preprocessed_line(&in, stdin, NULL)) {
2834 struct ofpbuf match_in, match_expout;
2835 struct ofp10_match match_out;
2836 struct ofp10_match match_normal;
2840 /* Parse hex bytes to use for expected output. */
2842 ds_put_cstr(&expout, ds_cstr(&in));
2843 for (p = ds_cstr(&expout); *p; p++) {
2848 ofpbuf_init(&match_expout, 0);
2849 if (ofpbuf_put_hex(&match_expout, ds_cstr(&expout), NULL)[0] != '\0') {
2850 ovs_fatal(0, "Trailing garbage in hex data");
2852 if (match_expout.size != sizeof(struct ofp10_match)) {
2853 ovs_fatal(0, "Input is %zu bytes, expected %zu",
2854 match_expout.size, sizeof(struct ofp10_match));
2857 /* Parse hex bytes for input. */
2858 for (p = ds_cstr(&in); *p; p++) {
2860 *p = "0123456789abcdef"[random_uint32() & 0xf];
2863 ofpbuf_init(&match_in, 0);
2864 if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') {
2865 ovs_fatal(0, "Trailing garbage in hex data");
2867 if (match_in.size != sizeof(struct ofp10_match)) {
2868 ovs_fatal(0, "Input is %zu bytes, expected %zu",
2869 match_in.size, sizeof(struct ofp10_match));
2872 /* Convert to cls_rule and print. */
2873 ofputil_match_from_ofp10_match(match_in.data, &match);
2874 match_print(&match);
2876 /* Convert back to ofp10_match and print differences from input. */
2877 ofputil_match_to_ofp10_match(&match, &match_out);
2878 print_differences("", match_expout.data, match_expout.size,
2879 &match_out, sizeof match_out);
2881 /* Normalize, then convert and compare again. */
2882 ofputil_normalize_match(&match);
2883 ofputil_match_to_ofp10_match(&match, &match_normal);
2884 print_differences("normal: ", &match_out, sizeof match_out,
2885 &match_normal, sizeof match_normal);
2888 ofpbuf_uninit(&match_in);
2889 ofpbuf_uninit(&match_expout);
2892 ds_destroy(&expout);
2895 /* "parse-ofp11-match": reads a series of ofp11_match specifications as hex
2896 * bytes from stdin, converts them to "struct match"es, prints them as strings
2897 * on stdout, and then converts them back to hex bytes and prints any
2898 * differences from the input. */
2900 ofctl_parse_ofp11_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2905 while (!ds_get_preprocessed_line(&in, stdin, NULL)) {
2906 struct ofpbuf match_in;
2907 struct ofp11_match match_out;
2911 /* Parse hex bytes. */
2912 ofpbuf_init(&match_in, 0);
2913 if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') {
2914 ovs_fatal(0, "Trailing garbage in hex data");
2916 if (match_in.size != sizeof(struct ofp11_match)) {
2917 ovs_fatal(0, "Input is %zu bytes, expected %zu",
2918 match_in.size, sizeof(struct ofp11_match));
2921 /* Convert to match. */
2922 error = ofputil_match_from_ofp11_match(match_in.data, &match);
2924 printf("bad ofp11_match: %s\n\n", ofperr_get_name(error));
2925 ofpbuf_uninit(&match_in);
2930 match_print(&match);
2932 /* Convert back to ofp11_match and print differences from input. */
2933 ofputil_match_to_ofp11_match(&match, &match_out);
2935 print_differences("", match_in.data, match_in.size,
2936 &match_out, sizeof match_out);
2939 ofpbuf_uninit(&match_in);
2944 /* "parse-ofp11-actions": reads a series of OpenFlow 1.1 action specifications
2945 * as hex bytes from stdin, converts them to ofpacts, prints them as strings
2946 * on stdout, and then converts them back to hex bytes and prints any
2947 * differences from the input. */
2949 ofctl_parse_ofp11_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
2954 while (!ds_get_preprocessed_line(&in, stdin, NULL)) {
2955 struct ofpbuf of11_out;
2956 struct ofpbuf of11_in;
2957 struct ofpbuf ofpacts;
2962 /* Parse hex bytes. */
2963 ofpbuf_init(&of11_in, 0);
2964 if (ofpbuf_put_hex(&of11_in, ds_cstr(&in), NULL)[0] != '\0') {
2965 ovs_fatal(0, "Trailing garbage in hex data");
2968 /* Convert to ofpacts. */
2969 ofpbuf_init(&ofpacts, 0);
2970 size = of11_in.size;
2971 error = ofpacts_pull_openflow11_actions(&of11_in, of11_in.size,
2974 printf("bad OF1.1 actions: %s\n\n", ofperr_get_name(error));
2975 ofpbuf_uninit(&ofpacts);
2976 ofpbuf_uninit(&of11_in);
2979 ofpbuf_push_uninit(&of11_in, size);
2981 /* Print cls_rule. */
2983 ofpacts_format(ofpacts.data, ofpacts.size, &s);
2987 /* Convert back to ofp11 actions and print differences from input. */
2988 ofpbuf_init(&of11_out, 0);
2989 ofpacts_put_openflow11_actions(ofpacts.data, ofpacts.size, &of11_out);
2991 print_differences("", of11_in.data, of11_in.size,
2992 of11_out.data, of11_out.size);
2995 ofpbuf_uninit(&ofpacts);
2996 ofpbuf_uninit(&of11_in);
2997 ofpbuf_uninit(&of11_out);
3002 /* "parse-ofp11-instructions": reads a series of OpenFlow 1.1 instruction
3003 * specifications as hex bytes from stdin, converts them to ofpacts, prints
3004 * them as strings on stdout, and then converts them back to hex bytes and
3005 * prints any differences from the input. */
3007 ofctl_parse_ofp11_instructions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
3012 while (!ds_get_preprocessed_line(&in, stdin, NULL)) {
3013 struct ofpbuf of11_out;
3014 struct ofpbuf of11_in;
3015 struct ofpbuf ofpacts;
3019 const char *table_id;
3022 /* Parse table_id separated with the follow-up instructions by ",", if
3024 instructions = ds_cstr(&in);
3026 if (strstr(instructions, ",")) {
3027 table_id = strsep(&instructions, ",");
3030 /* Parse hex bytes. */
3031 ofpbuf_init(&of11_in, 0);
3032 if (ofpbuf_put_hex(&of11_in, instructions, NULL)[0] != '\0') {
3033 ovs_fatal(0, "Trailing garbage in hex data");
3036 /* Convert to ofpacts. */
3037 ofpbuf_init(&ofpacts, 0);
3038 size = of11_in.size;
3039 error = ofpacts_pull_openflow11_instructions(&of11_in, of11_in.size,
3042 /* Verify actions. */
3044 memset(&flow, 0, sizeof flow);
3045 error = ofpacts_check(ofpacts.data, ofpacts.size, &flow, OFPP_MAX,
3046 table_id ? atoi(table_id) : 0);
3049 printf("bad OF1.1 instructions: %s\n\n", ofperr_get_name(error));
3050 ofpbuf_uninit(&ofpacts);
3051 ofpbuf_uninit(&of11_in);
3054 ofpbuf_push_uninit(&of11_in, size);
3056 /* Print cls_rule. */
3058 ofpacts_format(ofpacts.data, ofpacts.size, &s);
3062 /* Convert back to ofp11 instructions and print differences from
3064 ofpbuf_init(&of11_out, 0);
3065 ofpacts_put_openflow11_instructions(ofpacts.data, ofpacts.size,
3068 print_differences("", of11_in.data, of11_in.size,
3069 of11_out.data, of11_out.size);
3072 ofpbuf_uninit(&ofpacts);
3073 ofpbuf_uninit(&of11_in);
3074 ofpbuf_uninit(&of11_out);
3079 /* "check-vlan VLAN_TCI VLAN_TCI_MASK": converts the specified vlan_tci and
3080 * mask values to and from various formats and prints the results. */
3082 ofctl_check_vlan(int argc OVS_UNUSED, char *argv[])
3087 struct ofputil_flow_mod fm;
3090 struct match nxm_match;
3094 struct ofp10_match of10_raw;
3095 struct match of10_match;
3097 struct ofp11_match of11_raw;
3098 struct match of11_match;
3103 enum ofputil_protocol usable_protocols; /* Unused for now. */
3105 match_init_catchall(&match);
3106 match.flow.vlan_tci = htons(strtoul(argv[1], NULL, 16));
3107 match.wc.masks.vlan_tci = htons(strtoul(argv[2], NULL, 16));
3109 /* Convert to and from string. */
3110 string_s = match_to_string(&match, OFP_DEFAULT_PRIORITY);
3111 printf("%s -> ", string_s);
3113 error_s = parse_ofp_str(&fm, -1, string_s, &usable_protocols);
3115 ovs_fatal(0, "%s", error_s);
3117 printf("%04"PRIx16"/%04"PRIx16"\n",
3118 ntohs(fm.match.flow.vlan_tci),
3119 ntohs(fm.match.wc.masks.vlan_tci));
3122 /* Convert to and from NXM. */
3123 ofpbuf_init(&nxm, 0);
3124 nxm_match_len = nx_put_match(&nxm, &match, htonll(0), htonll(0));
3125 nxm_s = nx_match_to_string(nxm.data, nxm_match_len);
3126 error = nx_pull_match(&nxm, nxm_match_len, &nxm_match, NULL, NULL);
3127 printf("NXM: %s -> ", nxm_s);
3129 printf("%s\n", ofperr_to_string(error));
3131 printf("%04"PRIx16"/%04"PRIx16"\n",
3132 ntohs(nxm_match.flow.vlan_tci),
3133 ntohs(nxm_match.wc.masks.vlan_tci));
3136 ofpbuf_uninit(&nxm);
3138 /* Convert to and from OXM. */
3139 ofpbuf_init(&nxm, 0);
3140 nxm_match_len = oxm_put_match(&nxm, &match);
3141 nxm_s = oxm_match_to_string(&nxm, nxm_match_len);
3142 error = oxm_pull_match(&nxm, &nxm_match);
3143 printf("OXM: %s -> ", nxm_s);
3145 printf("%s\n", ofperr_to_string(error));
3147 uint16_t vid = ntohs(nxm_match.flow.vlan_tci) &
3148 (VLAN_VID_MASK | VLAN_CFI);
3149 uint16_t mask = ntohs(nxm_match.wc.masks.vlan_tci) &
3150 (VLAN_VID_MASK | VLAN_CFI);
3152 printf("%04"PRIx16"/%04"PRIx16",", vid, mask);
3153 if (vid && vlan_tci_to_pcp(nxm_match.wc.masks.vlan_tci)) {
3154 printf("%02"PRIx8"\n", vlan_tci_to_pcp(nxm_match.flow.vlan_tci));
3160 ofpbuf_uninit(&nxm);
3162 /* Convert to and from OpenFlow 1.0. */
3163 ofputil_match_to_ofp10_match(&match, &of10_raw);
3164 ofputil_match_from_ofp10_match(&of10_raw, &of10_match);
3165 printf("OF1.0: %04"PRIx16"/%d,%02"PRIx8"/%d -> %04"PRIx16"/%04"PRIx16"\n",
3166 ntohs(of10_raw.dl_vlan),
3167 (of10_raw.wildcards & htonl(OFPFW10_DL_VLAN)) != 0,
3168 of10_raw.dl_vlan_pcp,
3169 (of10_raw.wildcards & htonl(OFPFW10_DL_VLAN_PCP)) != 0,
3170 ntohs(of10_match.flow.vlan_tci),
3171 ntohs(of10_match.wc.masks.vlan_tci));
3173 /* Convert to and from OpenFlow 1.1. */
3174 ofputil_match_to_ofp11_match(&match, &of11_raw);
3175 ofputil_match_from_ofp11_match(&of11_raw, &of11_match);
3176 printf("OF1.1: %04"PRIx16"/%d,%02"PRIx8"/%d -> %04"PRIx16"/%04"PRIx16"\n",
3177 ntohs(of11_raw.dl_vlan),
3178 (of11_raw.wildcards & htonl(OFPFW11_DL_VLAN)) != 0,
3179 of11_raw.dl_vlan_pcp,
3180 (of11_raw.wildcards & htonl(OFPFW11_DL_VLAN_PCP)) != 0,
3181 ntohs(of11_match.flow.vlan_tci),
3182 ntohs(of11_match.wc.masks.vlan_tci));
3185 /* "print-error ENUM": Prints the type and code of ENUM for every OpenFlow
3188 ofctl_print_error(int argc OVS_UNUSED, char *argv[])
3193 error = ofperr_from_name(argv[1]);
3195 ovs_fatal(0, "unknown error \"%s\"", argv[1]);
3198 for (version = 0; version <= UINT8_MAX; version++) {
3199 const char *name = ofperr_domain_get_name(version);
3201 int vendor = ofperr_get_vendor(error, version);
3202 int type = ofperr_get_type(error, version);
3203 int code = ofperr_get_code(error, version);
3205 if (vendor != -1 || type != -1 || code != -1) {
3206 printf("%s: vendor %#x, type %d, code %d\n",
3207 name, vendor, type, code);
3213 /* "encode-error-reply ENUM REQUEST": Encodes an error reply to REQUEST for the
3214 * error named ENUM and prints the error reply in hex. */
3216 ofctl_encode_error_reply(int argc OVS_UNUSED, char *argv[])
3218 const struct ofp_header *oh;
3219 struct ofpbuf request, *reply;
3222 error = ofperr_from_name(argv[1]);
3224 ovs_fatal(0, "unknown error \"%s\"", argv[1]);
3227 ofpbuf_init(&request, 0);
3228 if (ofpbuf_put_hex(&request, argv[2], NULL)[0] != '\0') {
3229 ovs_fatal(0, "Trailing garbage in hex data");
3231 if (request.size < sizeof(struct ofp_header)) {
3232 ovs_fatal(0, "Request too short");
3236 if (request.size != ntohs(oh->length)) {
3237 ovs_fatal(0, "Request size inconsistent");
3240 reply = ofperr_encode_reply(error, request.data);
3241 ofpbuf_uninit(&request);
3243 ovs_hex_dump(stdout, reply->data, reply->size, 0, false);
3244 ofpbuf_delete(reply);
3247 /* "ofp-print HEXSTRING [VERBOSITY]": Converts the hex digits in HEXSTRING into
3248 * binary data, interpreting them as an OpenFlow message, and prints the
3249 * OpenFlow message on stdout, at VERBOSITY (level 2 by default). */
3251 ofctl_ofp_print(int argc, char *argv[])
3253 struct ofpbuf packet;
3255 ofpbuf_init(&packet, strlen(argv[1]) / 2);
3256 if (ofpbuf_put_hex(&packet, argv[1], NULL)[0] != '\0') {
3257 ovs_fatal(0, "trailing garbage following hex bytes");
3259 ofp_print(stdout, packet.data, packet.size, argc > 2 ? atoi(argv[2]) : 2);
3260 ofpbuf_uninit(&packet);
3263 /* "encode-hello BITMAP...": Encodes each BITMAP as an OpenFlow hello message
3264 * and dumps each message in hex. */
3266 ofctl_encode_hello(int argc OVS_UNUSED, char *argv[])
3268 uint32_t bitmap = strtol(argv[1], NULL, 0);
3269 struct ofpbuf *hello;
3271 hello = ofputil_encode_hello(bitmap);
3272 ovs_hex_dump(stdout, hello->data, hello->size, 0, false);
3273 ofp_print(stdout, hello->data, hello->size, verbosity);
3274 ofpbuf_delete(hello);
3277 static const struct command all_commands[] = {
3278 { "show", 1, 1, ofctl_show },
3279 { "monitor", 1, 3, ofctl_monitor },
3280 { "snoop", 1, 1, ofctl_snoop },
3281 { "dump-desc", 1, 1, ofctl_dump_desc },
3282 { "dump-tables", 1, 1, ofctl_dump_tables },
3283 { "dump-flows", 1, 2, ofctl_dump_flows },
3284 { "dump-aggregate", 1, 2, ofctl_dump_aggregate },
3285 { "queue-stats", 1, 3, ofctl_queue_stats },
3286 { "add-flow", 2, 2, ofctl_add_flow },
3287 { "add-flows", 2, 2, ofctl_add_flows },
3288 { "mod-flows", 2, 2, ofctl_mod_flows },
3289 { "del-flows", 1, 2, ofctl_del_flows },
3290 { "replace-flows", 2, 2, ofctl_replace_flows },
3291 { "diff-flows", 2, 2, ofctl_diff_flows },
3292 { "add-meter", 2, 2, ofctl_add_meter },
3293 { "mod-meter", 2, 2, ofctl_mod_meter },
3294 { "del-meter", 2, 2, ofctl_del_meters },
3295 { "del-meters", 1, 1, ofctl_del_meters },
3296 { "dump-meter", 2, 2, ofctl_dump_meters },
3297 { "dump-meters", 1, 1, ofctl_dump_meters },
3298 { "meter-stats", 1, 2, ofctl_meter_stats },
3299 { "meter-features", 1, 1, ofctl_meter_features },
3300 { "packet-out", 4, INT_MAX, ofctl_packet_out },
3301 { "dump-ports", 1, 2, ofctl_dump_ports },
3302 { "dump-ports-desc", 1, 1, ofctl_dump_ports_desc },
3303 { "mod-port", 3, 3, ofctl_mod_port },
3304 { "mod-table", 3, 3, ofctl_mod_table },
3305 { "get-frags", 1, 1, ofctl_get_frags },
3306 { "set-frags", 2, 2, ofctl_set_frags },
3307 { "ofp-parse", 1, 1, ofctl_ofp_parse },
3308 { "probe", 1, 1, ofctl_probe },
3309 { "ping", 1, 2, ofctl_ping },
3310 { "benchmark", 3, 3, ofctl_benchmark },
3312 { "add-group", 1, 2, ofctl_add_group },
3313 { "add-groups", 1, 2, ofctl_add_groups },
3314 { "mod-group", 1, 2, ofctl_mod_group },
3315 { "del-groups", 1, 2, ofctl_del_groups },
3316 { "dump-groups", 1, 1, ofctl_dump_group_desc },
3317 { "dump-group-stats", 1, 2, ofctl_dump_group_stats },
3318 { "dump-group-features", 1, 1, ofctl_dump_group_features },
3319 { "help", 0, INT_MAX, ofctl_help },
3321 /* Undocumented commands for testing. */
3322 { "parse-flow", 1, 1, ofctl_parse_flow },
3323 { "parse-flows", 1, 1, ofctl_parse_flows },
3324 { "parse-nx-match", 0, 0, ofctl_parse_nxm },
3325 { "parse-nxm", 0, 0, ofctl_parse_nxm },
3326 { "parse-oxm", 0, 0, ofctl_parse_oxm },
3327 { "parse-ofp10-actions", 0, 0, ofctl_parse_ofp10_actions },
3328 { "parse-ofp10-match", 0, 0, ofctl_parse_ofp10_match },
3329 { "parse-ofp11-match", 0, 0, ofctl_parse_ofp11_match },
3330 { "parse-ofp11-actions", 0, 0, ofctl_parse_ofp11_actions },
3331 { "parse-ofp11-instructions", 0, 0, ofctl_parse_ofp11_instructions },
3332 { "check-vlan", 2, 2, ofctl_check_vlan },
3333 { "print-error", 1, 1, ofctl_print_error },
3334 { "encode-error-reply", 2, 2, ofctl_encode_error_reply },
3335 { "ofp-print", 1, 2, ofctl_ofp_print },
3336 { "encode-hello", 1, 1, ofctl_encode_hello },
3338 { NULL, 0, 0, NULL },
3341 static const struct command *get_all_commands(void)
3343 return all_commands;