2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
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.
21 #include <sys/socket.h>
30 #include "byte-order.h"
31 #include "classifier.h"
32 #include "command-line.h"
36 #include "dynamic-string.h"
40 #include "ofp-errors.h"
41 #include "ofp-parse.h"
42 #include "ofp-print.h"
45 #include "ofproto/ofproto.h"
46 #include "openflow/nicira-ext.h"
47 #include "openflow/openflow.h"
49 #include "poll-loop.h"
51 #include "stream-ssl.h"
58 VLOG_DEFINE_THIS_MODULE(ofctl);
60 /* --strict: Use strict matching for flow mod commands? Additionally governs
61 * use of nx_pull_match() instead of nx_pull_match_loose() in parse-nx-match.
65 /* --readd: If true, on replace-flows, re-add even flows that have not changed
66 * (to reset flow counters). */
69 /* -F, --flow-format: Flow format to use. Either one of NXFF_* to force a
70 * particular flow format or -1 to let ovs-ofctl choose intelligently. */
71 static int preferred_flow_format = -1;
73 /* -P, --packet-in-format: Packet IN format to use in monitor and snoop
74 * commands. Either one of NXPIF_* to force a particular packet_in format, or
75 * -1 to let ovs-ofctl choose the default. */
76 static int preferred_packet_in_format = -1;
78 /* -m, --more: Additional verbosity for ofp-print functions. */
81 static const struct command all_commands[];
83 static void usage(void) NO_RETURN;
84 static void parse_options(int argc, char *argv[]);
87 main(int argc, char *argv[])
89 set_program_name(argv[0]);
90 parse_options(argc, argv);
91 signal(SIGPIPE, SIG_IGN);
92 run_command(argc - optind, argv + optind, all_commands);
97 parse_options(int argc, char *argv[])
100 OPT_STRICT = UCHAR_MAX + 1,
105 static struct option long_options[] = {
106 {"timeout", required_argument, NULL, 't'},
107 {"strict", no_argument, NULL, OPT_STRICT},
108 {"readd", no_argument, NULL, OPT_READD},
109 {"flow-format", required_argument, NULL, 'F'},
110 {"packet-in-format", required_argument, NULL, 'P'},
111 {"more", no_argument, NULL, 'm'},
112 {"help", no_argument, NULL, 'h'},
113 {"version", no_argument, NULL, 'V'},
116 STREAM_SSL_LONG_OPTIONS,
119 char *short_options = long_options_to_short_options(long_options);
122 unsigned long int timeout;
125 c = getopt_long(argc, argv, short_options, long_options, NULL);
132 timeout = strtoul(optarg, NULL, 10);
134 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
142 preferred_flow_format = ofputil_flow_format_from_string(optarg);
143 if (preferred_flow_format < 0) {
144 ovs_fatal(0, "unknown flow format `%s'", optarg);
149 preferred_packet_in_format =
150 ofputil_packet_in_format_from_string(optarg);
151 if (preferred_packet_in_format < 0) {
152 ovs_fatal(0, "unknown packet-in format `%s'", optarg);
164 ovs_print_version(OFP_VERSION, OFP_VERSION);
175 DAEMON_OPTION_HANDLERS
177 STREAM_SSL_OPTION_HANDLERS
192 printf("%s: OpenFlow switch management utility\n"
193 "usage: %s [OPTIONS] COMMAND [ARG...]\n"
194 "\nFor OpenFlow switches:\n"
195 " show SWITCH show OpenFlow information\n"
196 " dump-desc SWITCH print switch description\n"
197 " dump-tables SWITCH print table stats\n"
198 " mod-port SWITCH IFACE ACT modify port behavior\n"
199 " get-frags SWITCH print fragment handling behavior\n"
200 " set-frags SWITCH FRAG_MODE set fragment handling behavior\n"
201 " dump-ports SWITCH [PORT] print port statistics\n"
202 " dump-flows SWITCH print all flow entries\n"
203 " dump-flows SWITCH FLOW print matching FLOWs\n"
204 " dump-aggregate SWITCH print aggregate flow statistics\n"
205 " dump-aggregate SWITCH FLOW print aggregate stats for FLOWs\n"
206 " queue-stats SWITCH [PORT [QUEUE]] dump queue stats\n"
207 " add-flow SWITCH FLOW add flow described by FLOW\n"
208 " add-flows SWITCH FILE add flows from FILE\n"
209 " mod-flows SWITCH FLOW modify actions of matching FLOWs\n"
210 " del-flows SWITCH [FLOW] delete matching FLOWs\n"
211 " replace-flows SWITCH FILE replace flows with those in FILE\n"
212 " diff-flows SOURCE1 SOURCE2 compare flows from two sources\n"
213 " packet-out SWITCH IN_PORT ACTIONS PACKET...\n"
214 " execute ACTIONS on PACKET\n"
215 " monitor SWITCH [MISSLEN] [invalid_ttl]\n"
216 " print packets received from SWITCH\n"
217 " snoop SWITCH snoop on SWITCH and its controller\n"
218 "\nFor OpenFlow switches and controllers:\n"
219 " probe TARGET probe whether TARGET is up\n"
220 " ping TARGET [N] latency of N-byte echos\n"
221 " benchmark TARGET N COUNT bandwidth of COUNT N-byte echos\n"
222 "where SWITCH or TARGET is an active OpenFlow connection method.\n",
223 program_name, program_name);
224 vconn_usage(true, false, false);
227 printf("\nOther options:\n"
228 " --strict use strict match for flow commands\n"
229 " --readd replace flows that haven't changed\n"
230 " -F, --flow-format=FORMAT force particular flow format\n"
231 " -P, --packet-in-format=FRMT force particular packet in format\n"
232 " -m, --more be more verbose printing OpenFlow\n"
233 " -t, --timeout=SECS give up after SECS seconds\n"
234 " -h, --help display this help message\n"
235 " -V, --version display version information\n");
240 ofctl_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
241 const char *argv[] OVS_UNUSED, void *exiting_)
243 bool *exiting = exiting_;
245 unixctl_command_reply(conn, 200, "");
248 static void run(int retval, const char *message, ...)
251 static void run(int retval, const char *message, ...)
256 va_start(args, message);
257 ovs_fatal_valist(retval, message, args);
261 /* Generic commands. */
264 open_vconn_socket(const char *name, struct vconn **vconnp)
266 char *vconn_name = xasprintf("unix:%s", name);
267 VLOG_DBG("connecting to %s", vconn_name);
268 run(vconn_open_block(vconn_name, OFP_VERSION, vconnp),
269 "connecting to %s", vconn_name);
274 open_vconn__(const char *name, const char *default_suffix,
275 struct vconn **vconnp)
277 char *datapath_name, *datapath_type, *socket_name;
281 bridge_path = xasprintf("%s/%s.%s", ovs_rundir(), name, default_suffix);
283 ofproto_parse_name(name, &datapath_name, &datapath_type);
284 socket_name = xasprintf("%s/%s.%s",
285 ovs_rundir(), datapath_name, default_suffix);
289 if (strchr(name, ':')) {
290 run(vconn_open_block(name, OFP_VERSION, vconnp),
291 "connecting to %s", name);
292 } else if (!stat(name, &s) && S_ISSOCK(s.st_mode)) {
293 open_vconn_socket(name, vconnp);
294 } else if (!stat(bridge_path, &s) && S_ISSOCK(s.st_mode)) {
295 open_vconn_socket(bridge_path, vconnp);
296 } else if (!stat(socket_name, &s)) {
297 if (!S_ISSOCK(s.st_mode)) {
298 ovs_fatal(0, "cannot connect to %s: %s is not a socket",
301 open_vconn_socket(socket_name, vconnp);
303 ovs_fatal(0, "%s is not a bridge or a socket", name);
311 open_vconn(const char *name, struct vconn **vconnp)
313 return open_vconn__(name, "mgmt", vconnp);
317 alloc_stats_request(size_t rq_len, uint16_t type, struct ofpbuf **bufferp)
319 struct ofp_stats_msg *rq;
321 rq = make_openflow(rq_len, OFPT_STATS_REQUEST, bufferp);
322 rq->type = htons(type);
323 rq->flags = htons(0);
328 send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
330 update_openflow_length(buffer);
331 run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
335 dump_transaction(const char *vconn_name, struct ofpbuf *request)
338 struct ofpbuf *reply;
340 update_openflow_length(request);
341 open_vconn(vconn_name, &vconn);
342 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
343 ofp_print(stdout, reply->data, reply->size, verbosity + 1);
348 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
350 struct ofpbuf *request;
351 make_openflow(sizeof(struct ofp_header), request_type, &request);
352 dump_transaction(vconn_name, request);
356 dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
358 ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
362 open_vconn(vconn_name, &vconn);
363 send_openflow_buffer(vconn, request);
366 struct ofpbuf *reply;
368 run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
369 recv_xid = ((struct ofp_header *) reply->data)->xid;
370 if (send_xid == recv_xid) {
371 struct ofp_stats_msg *osm;
373 ofp_print(stdout, reply->data, reply->size, verbosity + 1);
375 osm = ofpbuf_at(reply, 0, sizeof *osm);
376 done = !osm || !(ntohs(osm->flags) & OFPSF_REPLY_MORE);
378 VLOG_DBG("received reply with xid %08"PRIx32" "
379 "!= expected %08"PRIx32, recv_xid, send_xid);
381 ofpbuf_delete(reply);
387 dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
389 struct ofpbuf *request;
390 alloc_stats_request(sizeof(struct ofp_stats_msg), stats_type, &request);
391 dump_stats_transaction(vconn_name, request);
394 /* Sends 'request', which should be a request that only has a reply if an error
395 * occurs, and waits for it to succeed or fail. If an error does occur, prints
396 * it and exits with an error.
398 * Destroys all of the 'requests'. */
400 transact_multiple_noreply(struct vconn *vconn, struct list *requests)
402 struct ofpbuf *request, *reply;
404 LIST_FOR_EACH (request, list_node, requests) {
405 update_openflow_length(request);
408 run(vconn_transact_multiple_noreply(vconn, requests, &reply),
409 "talking to %s", vconn_get_name(vconn));
411 ofp_print(stderr, reply->data, reply->size, verbosity + 2);
414 ofpbuf_delete(reply);
417 /* Sends 'request', which should be a request that only has a reply if an error
418 * occurs, and waits for it to succeed or fail. If an error does occur, prints
419 * it and exits with an error.
421 * Destroys 'request'. */
423 transact_noreply(struct vconn *vconn, struct ofpbuf *request)
425 struct list requests;
427 list_init(&requests);
428 list_push_back(&requests, &request->list_node);
429 transact_multiple_noreply(vconn, &requests);
433 fetch_switch_config(struct vconn *vconn, struct ofp_switch_config *config_)
435 struct ofp_switch_config *config;
436 struct ofp_header *header;
437 struct ofpbuf *request;
438 struct ofpbuf *reply;
440 make_openflow(sizeof(struct ofp_header), OFPT_GET_CONFIG_REQUEST,
442 run(vconn_transact(vconn, request, &reply),
443 "talking to %s", vconn_get_name(vconn));
445 header = reply->data;
446 if (header->type != OFPT_GET_CONFIG_REPLY ||
447 header->length != htons(sizeof *config)) {
448 ovs_fatal(0, "%s: bad reply to config request", vconn_get_name(vconn));
451 config = reply->data;
454 ofpbuf_delete(reply);
458 set_switch_config(struct vconn *vconn, struct ofp_switch_config *config_)
460 struct ofp_switch_config *config;
461 struct ofp_header save_header;
462 struct ofpbuf *request;
464 config = make_openflow(sizeof *config, OFPT_SET_CONFIG, &request);
465 save_header = config->header;
467 config->header = save_header;
469 transact_noreply(vconn, request);
473 do_show(int argc OVS_UNUSED, char *argv[])
475 dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
476 dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
480 do_dump_desc(int argc OVS_UNUSED, char *argv[])
482 dump_trivial_stats_transaction(argv[1], OFPST_DESC);
486 do_dump_tables(int argc OVS_UNUSED, char *argv[])
488 dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
491 /* Opens a connection to 'vconn_name', fetches the ofp_phy_port structure for
492 * 'port_name' (which may be a port name or number), and copies it into
495 fetch_ofp_phy_port(const char *vconn_name, const char *port_name,
496 struct ofp_phy_port *oppp)
498 struct ofpbuf *request, *reply;
499 struct ofp_switch_features *osf;
500 unsigned int port_no;
505 /* Try to interpret the argument as a port number. */
506 if (!str_to_uint(port_name, 10, &port_no)) {
510 /* Fetch the switch's ofp_switch_features. */
511 make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
512 open_vconn(vconn_name, &vconn);
513 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
516 if (reply->size < sizeof *osf) {
517 ovs_fatal(0, "%s: received too-short features reply (only %zu bytes)",
518 vconn_name, reply->size);
520 n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
522 for (port_idx = 0; port_idx < n_ports; port_idx++) {
523 const struct ofp_phy_port *opp = &osf->ports[port_idx];
525 if (port_no != UINT_MAX
526 ? htons(port_no) == opp->port_no
527 : !strncmp(opp->name, port_name, sizeof opp->name)) {
529 ofpbuf_delete(reply);
534 ovs_fatal(0, "%s: couldn't find port `%s'", vconn_name, port_name);
537 /* Returns the port number corresponding to 'port_name' (which may be a port
538 * name or number) within the switch 'vconn_name'. */
540 str_to_port_no(const char *vconn_name, const char *port_name)
542 unsigned int port_no;
544 if (str_to_uint(port_name, 10, &port_no)) {
547 struct ofp_phy_port opp;
549 fetch_ofp_phy_port(vconn_name, port_name, &opp);
550 return ntohs(opp.port_no);
555 try_set_flow_format(struct vconn *vconn, enum nx_flow_format flow_format)
557 struct ofpbuf *sff, *reply;
559 sff = ofputil_make_set_flow_format(flow_format);
560 run(vconn_transact_noreply(vconn, sff, &reply),
561 "talking to %s", vconn_get_name(vconn));
563 char *s = ofp_to_string(reply->data, reply->size, 2);
564 VLOG_DBG("%s: failed to set flow format %s, controller replied: %s",
565 vconn_get_name(vconn),
566 ofputil_flow_format_to_string(flow_format),
569 ofpbuf_delete(reply);
576 set_flow_format(struct vconn *vconn, enum nx_flow_format flow_format)
578 struct ofpbuf *sff = ofputil_make_set_flow_format(flow_format);
579 transact_noreply(vconn, sff);
580 VLOG_DBG("%s: using user-specified flow format %s",
581 vconn_get_name(vconn),
582 ofputil_flow_format_to_string(flow_format));
585 static enum nx_flow_format
586 negotiate_highest_flow_format(struct vconn *vconn,
587 enum nx_flow_format min_format)
589 if (preferred_flow_format != -1) {
590 if (preferred_flow_format < min_format) {
591 ovs_fatal(0, "%s: cannot use requested flow format %s for "
592 "specified flow", vconn_get_name(vconn),
593 ofputil_flow_format_to_string(min_format));
596 set_flow_format(vconn, preferred_flow_format);
597 return preferred_flow_format;
599 enum nx_flow_format flow_format;
601 if (try_set_flow_format(vconn, NXFF_NXM)) {
602 flow_format = NXFF_NXM;
604 flow_format = NXFF_OPENFLOW10;
607 if (flow_format < min_format) {
608 ovs_fatal(0, "%s: cannot use switch's most advanced flow format "
609 "%s for specified flow", vconn_get_name(vconn),
610 ofputil_flow_format_to_string(min_format));
613 VLOG_DBG("%s: negotiated flow format %s", vconn_get_name(vconn),
614 ofputil_flow_format_to_string(flow_format));
620 do_dump_flows__(int argc, char *argv[], bool aggregate)
622 enum nx_flow_format min_flow_format, flow_format;
623 struct ofputil_flow_stats_request fsr;
624 struct ofpbuf *request;
627 parse_ofp_flow_stats_request_str(&fsr, aggregate, argc > 2 ? argv[2] : "");
629 open_vconn(argv[1], &vconn);
630 min_flow_format = ofputil_min_flow_format(&fsr.match);
631 if (fsr.cookie_mask != htonll(0)) {
632 min_flow_format = NXFF_NXM;
634 flow_format = negotiate_highest_flow_format(vconn, min_flow_format);
635 request = ofputil_encode_flow_stats_request(&fsr, flow_format);
636 dump_stats_transaction(argv[1], request);
641 do_dump_flows(int argc, char *argv[])
643 return do_dump_flows__(argc, argv, false);
647 do_dump_aggregate(int argc, char *argv[])
649 return do_dump_flows__(argc, argv, true);
653 do_queue_stats(int argc, char *argv[])
655 struct ofp_queue_stats_request *req;
656 struct ofpbuf *request;
658 req = alloc_stats_request(sizeof *req, OFPST_QUEUE, &request);
660 if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) {
661 req->port_no = htons(str_to_port_no(argv[1], argv[2]));
663 req->port_no = htons(OFPP_ALL);
665 if (argc > 3 && argv[3][0] && strcasecmp(argv[3], "all")) {
666 req->queue_id = htonl(atoi(argv[3]));
668 req->queue_id = htonl(OFPQ_ALL);
671 memset(req->pad, 0, sizeof req->pad);
673 dump_stats_transaction(argv[1], request);
676 /* Sets up the flow format for a vconn that will be used to modify the flow
677 * table. Returns the flow format used, after possibly adding an OpenFlow
678 * request to 'requests'.
680 * If 'preferred_flow_format' is -1, returns NXFF_OPENFLOW10 without modifying
681 * 'requests', since NXFF_OPENFLOW10 is the default flow format for any
682 * OpenFlow connection.
684 * If 'preferred_flow_format' is a specific format, adds a request to set that
685 * format to 'requests' and returns the format. */
686 static enum nx_flow_format
687 set_initial_format_for_flow_mod(struct list *requests)
689 if (preferred_flow_format < 0) {
690 return NXFF_OPENFLOW10;
694 sff = ofputil_make_set_flow_format(preferred_flow_format);
695 list_push_back(requests, &sff->list_node);
696 return preferred_flow_format;
700 /* Checks that 'flow_format' is acceptable as a flow format after a flow_mod
701 * operation, given the global 'preferred_flow_format'. */
703 check_final_format_for_flow_mod(enum nx_flow_format flow_format)
705 if (preferred_flow_format >= 0 && flow_format > preferred_flow_format) {
706 ovs_fatal(0, "flow cannot be expressed in flow format %s "
707 "(flow format %s or better is required)",
708 ofputil_flow_format_to_string(preferred_flow_format),
709 ofputil_flow_format_to_string(flow_format));
714 do_flow_mod_file__(int argc OVS_UNUSED, char *argv[], uint16_t command)
716 enum nx_flow_format flow_format;
717 bool flow_mod_table_id;
718 struct list requests;
722 file = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r");
724 ovs_fatal(errno, "%s: open", argv[2]);
727 list_init(&requests);
728 flow_format = set_initial_format_for_flow_mod(&requests);
729 flow_mod_table_id = false;
731 open_vconn(argv[1], &vconn);
732 while (parse_ofp_flow_mod_file(&requests, &flow_format, &flow_mod_table_id,
734 check_final_format_for_flow_mod(flow_format);
735 transact_multiple_noreply(vconn, &requests);
745 do_flow_mod__(int argc, char *argv[], uint16_t command)
747 enum nx_flow_format flow_format;
748 bool flow_mod_table_id;
749 struct list requests;
752 if (argc > 2 && !strcmp(argv[2], "-")) {
753 do_flow_mod_file__(argc, argv, command);
757 list_init(&requests);
758 flow_format = set_initial_format_for_flow_mod(&requests);
759 flow_mod_table_id = false;
761 parse_ofp_flow_mod_str(&requests, &flow_format, &flow_mod_table_id,
762 argc > 2 ? argv[2] : "", command, false);
763 check_final_format_for_flow_mod(flow_format);
765 open_vconn(argv[1], &vconn);
766 transact_multiple_noreply(vconn, &requests);
771 do_add_flow(int argc, char *argv[])
773 do_flow_mod__(argc, argv, OFPFC_ADD);
777 do_add_flows(int argc, char *argv[])
779 do_flow_mod_file__(argc, argv, OFPFC_ADD);
783 do_mod_flows(int argc, char *argv[])
785 do_flow_mod__(argc, argv, strict ? OFPFC_MODIFY_STRICT : OFPFC_MODIFY);
789 do_del_flows(int argc, char *argv[])
791 do_flow_mod__(argc, argv, strict ? OFPFC_DELETE_STRICT : OFPFC_DELETE);
795 set_packet_in_format(struct vconn *vconn,
796 enum nx_packet_in_format packet_in_format)
798 struct ofpbuf *spif = ofputil_make_set_packet_in_format(packet_in_format);
799 transact_noreply(vconn, spif);
800 VLOG_DBG("%s: using user-specified packet in format %s",
801 vconn_get_name(vconn),
802 ofputil_packet_in_format_to_string(packet_in_format));
806 monitor_set_invalid_ttl_to_controller(struct vconn *vconn)
808 struct ofp_switch_config config;
809 enum ofp_config_flags flags;
811 fetch_switch_config(vconn, &config);
812 flags = ntohs(config.flags);
813 if (!(flags & OFPC_INVALID_TTL_TO_CONTROLLER)) {
814 /* Set the invalid ttl config. */
815 flags |= OFPC_INVALID_TTL_TO_CONTROLLER;
817 config.flags = htons(flags);
818 set_switch_config(vconn, &config);
820 /* Then retrieve the configuration to see if it really took. OpenFlow
821 * doesn't define error reporting for bad modes, so this is all we can
823 fetch_switch_config(vconn, &config);
824 flags = ntohs(config.flags);
825 if (!(flags & OFPC_INVALID_TTL_TO_CONTROLLER)) {
826 ovs_fatal(0, "setting invalid_ttl_to_controller failed (this "
827 "switch probably doesn't support mode)");
835 monitor_vconn(struct vconn *vconn)
837 struct unixctl_server *server;
838 bool exiting = false;
841 daemon_save_fd(STDERR_FILENO);
843 error = unixctl_server_create(NULL, &server);
845 ovs_fatal(error, "failed to create unixctl server");
847 unixctl_command_register("exit", "", 0, 0, ofctl_exit, &exiting);
848 daemonize_complete();
854 unixctl_server_run(server);
857 retval = vconn_recv(vconn, &b);
858 if (retval == EAGAIN) {
862 run(retval, "vconn_recv");
863 ofp_print(stderr, b->data, b->size, verbosity + 2);
872 vconn_run_wait(vconn);
873 vconn_recv_wait(vconn);
874 unixctl_server_wait(server);
878 unixctl_server_destroy(server);
882 do_monitor(int argc, char *argv[])
886 open_vconn(argv[1], &vconn);
888 struct ofp_switch_config config;
890 fetch_switch_config(vconn, &config);
891 config.miss_send_len = htons(atoi(argv[2]));
892 set_switch_config(vconn, &config);
895 if (!strcmp(argv[3], "invalid_ttl")) {
896 monitor_set_invalid_ttl_to_controller(vconn);
899 if (preferred_packet_in_format >= 0) {
900 set_packet_in_format(vconn, preferred_packet_in_format);
902 struct ofpbuf *spif, *reply;
904 spif = ofputil_make_set_packet_in_format(NXPIF_NXM);
905 run(vconn_transact_noreply(vconn, spif, &reply),
906 "talking to %s", vconn_get_name(vconn));
908 char *s = ofp_to_string(reply->data, reply->size, 2);
909 VLOG_DBG("%s: failed to set packet in format to nxm, controller"
910 " replied: %s. Falling back to the switch default.",
911 vconn_get_name(vconn), s);
913 ofpbuf_delete(reply);
917 monitor_vconn(vconn);
921 do_snoop(int argc OVS_UNUSED, char *argv[])
925 open_vconn__(argv[1], "snoop", &vconn);
926 monitor_vconn(vconn);
930 do_dump_ports(int argc, char *argv[])
932 struct ofp_port_stats_request *req;
933 struct ofpbuf *request;
936 req = alloc_stats_request(sizeof *req, OFPST_PORT, &request);
937 port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_NONE;
938 req->port_no = htons(port);
939 dump_stats_transaction(argv[1], request);
943 do_probe(int argc OVS_UNUSED, char *argv[])
945 struct ofpbuf *request;
947 struct ofpbuf *reply;
949 make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
950 open_vconn(argv[1], &vconn);
951 run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
952 if (reply->size != sizeof(struct ofp_header)) {
953 ovs_fatal(0, "reply does not match request");
955 ofpbuf_delete(reply);
960 do_packet_out(int argc, char *argv[])
962 struct ofputil_packet_out po;
963 struct ofpbuf actions;
967 ofpbuf_init(&actions, sizeof(union ofp_action));
968 parse_ofp_actions(argv[3], &actions);
970 po.buffer_id = UINT32_MAX;
971 po.in_port = (!strcasecmp(argv[2], "none") ? OFPP_NONE
972 : !strcasecmp(argv[2], "local") ? OFPP_LOCAL
973 : str_to_port_no(argv[1], argv[2]));
974 po.actions = actions.data;
975 po.n_actions = actions.size / sizeof(union ofp_action);
977 open_vconn(argv[1], &vconn);
978 for (i = 4; i < argc; i++) {
979 struct ofpbuf *packet, *opo;
980 const char *error_msg;
982 error_msg = eth_from_hex(argv[i], &packet);
984 ovs_fatal(0, "%s", error_msg);
987 po.packet = packet->data;
988 po.packet_len = packet->size;
989 opo = ofputil_encode_packet_out(&po);
990 transact_noreply(vconn, opo);
991 ofpbuf_delete(packet);
997 do_mod_port(int argc OVS_UNUSED, char *argv[])
999 struct ofp_port_mod *opm;
1000 struct ofp_phy_port opp;
1001 struct ofpbuf *request;
1002 struct vconn *vconn;
1004 fetch_ofp_phy_port(argv[1], argv[2], &opp);
1006 opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
1007 opm->port_no = opp.port_no;
1008 memcpy(opm->hw_addr, opp.hw_addr, sizeof opm->hw_addr);
1009 opm->config = htonl(0);
1010 opm->mask = htonl(0);
1011 opm->advertise = htonl(0);
1013 if (!strcasecmp(argv[3], "up")) {
1014 opm->mask |= htonl(OFPPC_PORT_DOWN);
1015 } else if (!strcasecmp(argv[3], "down")) {
1016 opm->mask |= htonl(OFPPC_PORT_DOWN);
1017 opm->config |= htonl(OFPPC_PORT_DOWN);
1018 } else if (!strcasecmp(argv[3], "flood")) {
1019 opm->mask |= htonl(OFPPC_NO_FLOOD);
1020 } else if (!strcasecmp(argv[3], "noflood")) {
1021 opm->mask |= htonl(OFPPC_NO_FLOOD);
1022 opm->config |= htonl(OFPPC_NO_FLOOD);
1023 } else if (!strcasecmp(argv[3], "forward")) {
1024 opm->mask |= htonl(OFPPC_NO_FWD);
1025 } else if (!strcasecmp(argv[3], "noforward")) {
1026 opm->mask |= htonl(OFPPC_NO_FWD);
1027 opm->config |= htonl(OFPPC_NO_FWD);
1029 ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
1032 open_vconn(argv[1], &vconn);
1033 transact_noreply(vconn, request);
1038 do_get_frags(int argc OVS_UNUSED, char *argv[])
1040 struct ofp_switch_config config;
1041 struct vconn *vconn;
1043 open_vconn(argv[1], &vconn);
1044 fetch_switch_config(vconn, &config);
1045 puts(ofputil_frag_handling_to_string(ntohs(config.flags)));
1050 do_set_frags(int argc OVS_UNUSED, char *argv[])
1052 struct ofp_switch_config config;
1053 enum ofp_config_flags mode;
1054 struct vconn *vconn;
1057 if (!ofputil_frag_handling_from_string(argv[2], &mode)) {
1058 ovs_fatal(0, "%s: unknown fragment handling mode", argv[2]);
1061 open_vconn(argv[1], &vconn);
1062 fetch_switch_config(vconn, &config);
1063 flags = htons(mode) | (config.flags & htons(~OFPC_FRAG_MASK));
1064 if (flags != config.flags) {
1065 /* Set the configuration. */
1066 config.flags = flags;
1067 set_switch_config(vconn, &config);
1069 /* Then retrieve the configuration to see if it really took. OpenFlow
1070 * doesn't define error reporting for bad modes, so this is all we can
1072 fetch_switch_config(vconn, &config);
1073 if (flags != config.flags) {
1074 ovs_fatal(0, "%s: setting fragment handling mode failed (this "
1075 "switch probably doesn't support mode \"%s\")",
1076 argv[1], ofputil_frag_handling_to_string(mode));
1083 do_ping(int argc, char *argv[])
1085 size_t max_payload = 65535 - sizeof(struct ofp_header);
1086 unsigned int payload;
1087 struct vconn *vconn;
1090 payload = argc > 2 ? atoi(argv[2]) : 64;
1091 if (payload > max_payload) {
1092 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
1095 open_vconn(argv[1], &vconn);
1096 for (i = 0; i < 10; i++) {
1097 struct timeval start, end;
1098 struct ofpbuf *request, *reply;
1099 struct ofp_header *rq_hdr, *rpy_hdr;
1101 rq_hdr = make_openflow(sizeof(struct ofp_header) + payload,
1102 OFPT_ECHO_REQUEST, &request);
1103 random_bytes(rq_hdr + 1, payload);
1105 xgettimeofday(&start);
1106 run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
1107 xgettimeofday(&end);
1109 rpy_hdr = reply->data;
1110 if (reply->size != request->size
1111 || memcmp(rpy_hdr + 1, rq_hdr + 1, payload)
1112 || rpy_hdr->xid != rq_hdr->xid
1113 || rpy_hdr->type != OFPT_ECHO_REPLY) {
1114 printf("Reply does not match request. Request:\n");
1115 ofp_print(stdout, request, request->size, verbosity + 2);
1117 ofp_print(stdout, reply, reply->size, verbosity + 2);
1119 printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
1120 reply->size - sizeof *rpy_hdr, argv[1], ntohl(rpy_hdr->xid),
1121 (1000*(double)(end.tv_sec - start.tv_sec))
1122 + (.001*(end.tv_usec - start.tv_usec)));
1123 ofpbuf_delete(request);
1124 ofpbuf_delete(reply);
1130 do_benchmark(int argc OVS_UNUSED, char *argv[])
1132 size_t max_payload = 65535 - sizeof(struct ofp_header);
1133 struct timeval start, end;
1134 unsigned int payload_size, message_size;
1135 struct vconn *vconn;
1140 payload_size = atoi(argv[2]);
1141 if (payload_size > max_payload) {
1142 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
1144 message_size = sizeof(struct ofp_header) + payload_size;
1146 count = atoi(argv[3]);
1148 printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
1149 count, message_size, count * message_size);
1151 open_vconn(argv[1], &vconn);
1152 xgettimeofday(&start);
1153 for (i = 0; i < count; i++) {
1154 struct ofpbuf *request, *reply;
1155 struct ofp_header *rq_hdr;
1157 rq_hdr = make_openflow(message_size, OFPT_ECHO_REQUEST, &request);
1158 memset(rq_hdr + 1, 0, payload_size);
1159 run(vconn_transact(vconn, request, &reply), "transact");
1160 ofpbuf_delete(reply);
1162 xgettimeofday(&end);
1165 duration = ((1000*(double)(end.tv_sec - start.tv_sec))
1166 + (.001*(end.tv_usec - start.tv_usec)));
1167 printf("Finished in %.1f ms (%.0f packets/s) (%.0f bytes/s)\n",
1168 duration, count / (duration / 1000.0),
1169 count * message_size / (duration / 1000.0));
1173 do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1178 /* replace-flows and diff-flows commands. */
1180 /* A flow table entry, possibly with two different versions. */
1182 struct cls_rule rule; /* Within a "struct classifier". */
1183 struct fte_version *versions[2];
1186 /* One version of a Flow Table Entry. */
1187 struct fte_version {
1189 uint16_t idle_timeout;
1190 uint16_t hard_timeout;
1192 union ofp_action *actions;
1196 /* Frees 'version' and the data that it owns. */
1198 fte_version_free(struct fte_version *version)
1201 free(version->actions);
1206 /* Returns true if 'a' and 'b' are the same, false if they differ.
1208 * Ignores differences in 'flags' because there's no way to retrieve flags from
1209 * an OpenFlow switch. We have to assume that they are the same. */
1211 fte_version_equals(const struct fte_version *a, const struct fte_version *b)
1213 return (a->cookie == b->cookie
1214 && a->idle_timeout == b->idle_timeout
1215 && a->hard_timeout == b->hard_timeout
1216 && a->n_actions == b->n_actions
1217 && !memcmp(a->actions, b->actions,
1218 a->n_actions * sizeof *a->actions));
1221 /* Prints 'version' on stdout. Expects the caller to have printed the rule
1222 * associated with the version. */
1224 fte_version_print(const struct fte_version *version)
1228 if (version->cookie != htonll(0)) {
1229 printf(" cookie=0x%"PRIx64, ntohll(version->cookie));
1231 if (version->idle_timeout != OFP_FLOW_PERMANENT) {
1232 printf(" idle_timeout=%"PRIu16, version->idle_timeout);
1234 if (version->hard_timeout != OFP_FLOW_PERMANENT) {
1235 printf(" hard_timeout=%"PRIu16, version->hard_timeout);
1239 ofp_print_actions(&s, version->actions, version->n_actions);
1240 printf(" %s\n", ds_cstr(&s));
1245 fte_from_cls_rule(const struct cls_rule *cls_rule)
1247 return cls_rule ? CONTAINER_OF(cls_rule, struct fte, rule) : NULL;
1250 /* Frees 'fte' and its versions. */
1252 fte_free(struct fte *fte)
1255 fte_version_free(fte->versions[0]);
1256 fte_version_free(fte->versions[1]);
1261 /* Frees all of the FTEs within 'cls'. */
1263 fte_free_all(struct classifier *cls)
1265 struct cls_cursor cursor;
1266 struct fte *fte, *next;
1268 cls_cursor_init(&cursor, cls, NULL);
1269 CLS_CURSOR_FOR_EACH_SAFE (fte, next, rule, &cursor) {
1270 classifier_remove(cls, &fte->rule);
1275 /* Searches 'cls' for an FTE matching 'rule', inserting a new one if
1276 * necessary. Sets 'version' as the version of that rule with the given
1277 * 'index', replacing any existing version, if any.
1279 * Takes ownership of 'version'. */
1281 fte_insert(struct classifier *cls, const struct cls_rule *rule,
1282 struct fte_version *version, int index)
1284 struct fte *old, *fte;
1286 fte = xzalloc(sizeof *fte);
1288 fte->versions[index] = version;
1290 old = fte_from_cls_rule(classifier_replace(cls, &fte->rule));
1292 fte_version_free(old->versions[index]);
1293 fte->versions[!index] = old->versions[!index];
1298 /* Reads the flows in 'filename' as flow table entries in 'cls' for the version
1299 * with the specified 'index'. Returns the minimum flow format required to
1300 * represent the flows that were read. */
1301 static enum nx_flow_format
1302 read_flows_from_file(const char *filename, struct classifier *cls, int index)
1304 enum nx_flow_format min_flow_format;
1308 file = !strcmp(filename, "-") ? stdin : fopen(filename, "r");
1310 ovs_fatal(errno, "%s: open", filename);
1314 min_flow_format = NXFF_OPENFLOW10;
1315 while (!ds_get_preprocessed_line(&s, file)) {
1316 struct fte_version *version;
1317 struct ofputil_flow_mod fm;
1318 enum nx_flow_format min_ff;
1320 parse_ofp_str(&fm, OFPFC_ADD, ds_cstr(&s), true);
1322 version = xmalloc(sizeof *version);
1323 version->cookie = fm.cookie;
1324 version->idle_timeout = fm.idle_timeout;
1325 version->hard_timeout = fm.hard_timeout;
1326 version->flags = fm.flags & (OFPFF_SEND_FLOW_REM | OFPFF_EMERG);
1327 version->actions = fm.actions;
1328 version->n_actions = fm.n_actions;
1330 min_ff = ofputil_min_flow_format(&fm.cr);
1331 min_flow_format = MAX(min_flow_format, min_ff);
1332 check_final_format_for_flow_mod(min_flow_format);
1334 fte_insert(cls, &fm.cr, version, index);
1338 if (file != stdin) {
1342 return min_flow_format;
1345 /* Reads the OpenFlow flow table from 'vconn', which has currently active flow
1346 * format 'flow_format', and adds them as flow table entries in 'cls' for the
1347 * version with the specified 'index'. */
1349 read_flows_from_switch(struct vconn *vconn, enum nx_flow_format flow_format,
1350 struct classifier *cls, int index)
1352 struct ofputil_flow_stats_request fsr;
1353 struct ofpbuf *request;
1357 fsr.aggregate = false;
1358 cls_rule_init_catchall(&fsr.match, 0);
1359 fsr.out_port = OFPP_NONE;
1360 fsr.table_id = 0xff;
1361 fsr.cookie = fsr.cookie_mask = htonll(0);
1362 request = ofputil_encode_flow_stats_request(&fsr, flow_format);
1363 send_xid = ((struct ofp_header *) request->data)->xid;
1364 send_openflow_buffer(vconn, request);
1369 struct ofpbuf *reply;
1371 run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
1372 recv_xid = ((struct ofp_header *) reply->data)->xid;
1373 if (send_xid == recv_xid) {
1374 const struct ofputil_msg_type *type;
1375 const struct ofp_stats_msg *osm;
1376 enum ofputil_msg_code code;
1378 ofputil_decode_msg_type(reply->data, &type);
1379 code = ofputil_msg_type_code(type);
1380 if (code != OFPUTIL_OFPST_FLOW_REPLY &&
1381 code != OFPUTIL_NXST_FLOW_REPLY) {
1382 ovs_fatal(0, "received bad reply: %s",
1383 ofp_to_string(reply->data, reply->size,
1388 if (!(osm->flags & htons(OFPSF_REPLY_MORE))) {
1393 struct fte_version *version;
1394 struct ofputil_flow_stats fs;
1397 retval = ofputil_decode_flow_stats_reply(&fs, reply, false);
1399 if (retval != EOF) {
1400 ovs_fatal(0, "parse error in reply");
1405 version = xmalloc(sizeof *version);
1406 version->cookie = fs.cookie;
1407 version->idle_timeout = fs.idle_timeout;
1408 version->hard_timeout = fs.hard_timeout;
1410 version->n_actions = fs.n_actions;
1411 version->actions = xmemdup(fs.actions,
1412 fs.n_actions * sizeof *fs.actions);
1414 fte_insert(cls, &fs.rule, version, index);
1417 VLOG_DBG("received reply with xid %08"PRIx32" "
1418 "!= expected %08"PRIx32, recv_xid, send_xid);
1420 ofpbuf_delete(reply);
1425 fte_make_flow_mod(const struct fte *fte, int index, uint16_t command,
1426 enum nx_flow_format flow_format, struct list *packets)
1428 const struct fte_version *version = fte->versions[index];
1429 struct ofputil_flow_mod fm;
1433 fm.cookie = version->cookie;
1435 fm.command = command;
1436 fm.idle_timeout = version->idle_timeout;
1437 fm.hard_timeout = version->hard_timeout;
1438 fm.buffer_id = UINT32_MAX;
1439 fm.out_port = OFPP_NONE;
1440 fm.flags = version->flags;
1441 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1442 command == OFPFC_MODIFY_STRICT) {
1443 fm.actions = version->actions;
1444 fm.n_actions = version->n_actions;
1450 ofm = ofputil_encode_flow_mod(&fm, flow_format, false);
1451 list_push_back(packets, &ofm->list_node);
1455 do_replace_flows(int argc OVS_UNUSED, char *argv[])
1457 enum { FILE_IDX = 0, SWITCH_IDX = 1 };
1458 enum nx_flow_format min_flow_format, flow_format;
1459 struct cls_cursor cursor;
1460 struct classifier cls;
1461 struct list requests;
1462 struct vconn *vconn;
1465 classifier_init(&cls);
1466 min_flow_format = read_flows_from_file(argv[2], &cls, FILE_IDX);
1468 open_vconn(argv[1], &vconn);
1469 flow_format = negotiate_highest_flow_format(vconn, min_flow_format);
1470 read_flows_from_switch(vconn, flow_format, &cls, SWITCH_IDX);
1472 list_init(&requests);
1474 /* Delete flows that exist on the switch but not in the file. */
1475 cls_cursor_init(&cursor, &cls, NULL);
1476 CLS_CURSOR_FOR_EACH (fte, rule, &cursor) {
1477 struct fte_version *file_ver = fte->versions[FILE_IDX];
1478 struct fte_version *sw_ver = fte->versions[SWITCH_IDX];
1480 if (sw_ver && !file_ver) {
1481 fte_make_flow_mod(fte, SWITCH_IDX, OFPFC_DELETE_STRICT,
1482 flow_format, &requests);
1486 /* Add flows that exist in the file but not on the switch.
1487 * Update flows that exist in both places but differ. */
1488 cls_cursor_init(&cursor, &cls, NULL);
1489 CLS_CURSOR_FOR_EACH (fte, rule, &cursor) {
1490 struct fte_version *file_ver = fte->versions[FILE_IDX];
1491 struct fte_version *sw_ver = fte->versions[SWITCH_IDX];
1494 && (readd || !sw_ver || !fte_version_equals(sw_ver, file_ver))) {
1495 fte_make_flow_mod(fte, FILE_IDX, OFPFC_ADD, flow_format,
1499 transact_multiple_noreply(vconn, &requests);
1506 read_flows_from_source(const char *source, struct classifier *cls, int index)
1510 if (source[0] == '/' || source[0] == '.'
1511 || (!strchr(source, ':') && !stat(source, &s))) {
1512 read_flows_from_file(source, cls, index);
1514 enum nx_flow_format flow_format;
1515 struct vconn *vconn;
1517 open_vconn(source, &vconn);
1518 flow_format = negotiate_highest_flow_format(vconn, NXFF_OPENFLOW10);
1519 read_flows_from_switch(vconn, flow_format, cls, index);
1525 do_diff_flows(int argc OVS_UNUSED, char *argv[])
1527 bool differences = false;
1528 struct cls_cursor cursor;
1529 struct classifier cls;
1532 classifier_init(&cls);
1533 read_flows_from_source(argv[1], &cls, 0);
1534 read_flows_from_source(argv[2], &cls, 1);
1536 cls_cursor_init(&cursor, &cls, NULL);
1537 CLS_CURSOR_FOR_EACH (fte, rule, &cursor) {
1538 struct fte_version *a = fte->versions[0];
1539 struct fte_version *b = fte->versions[1];
1541 if (!a || !b || !fte_version_equals(a, b)) {
1542 char *rule_s = cls_rule_to_string(&fte->rule);
1544 printf("-%s", rule_s);
1545 fte_version_print(a);
1548 printf("+%s", rule_s);
1549 fte_version_print(b);
1564 /* Undocumented commands for unit testing. */
1567 print_packet_list(struct list *packets)
1569 struct ofpbuf *packet, *next;
1571 LIST_FOR_EACH_SAFE (packet, next, list_node, packets) {
1572 ofp_print(stdout, packet->data, packet->size, verbosity);
1573 list_remove(&packet->list_node);
1574 ofpbuf_delete(packet);
1578 /* "parse-flow FLOW": parses the argument as a flow (like add-flow) and prints
1579 * it back to stdout. */
1581 do_parse_flow(int argc OVS_UNUSED, char *argv[])
1583 enum nx_flow_format flow_format;
1584 bool flow_mod_table_id;
1585 struct list packets;
1587 flow_format = NXFF_OPENFLOW10;
1588 if (preferred_flow_format > 0) {
1589 flow_format = preferred_flow_format;
1591 flow_mod_table_id = false;
1593 list_init(&packets);
1594 parse_ofp_flow_mod_str(&packets, &flow_format, &flow_mod_table_id,
1595 argv[1], OFPFC_ADD, false);
1596 print_packet_list(&packets);
1599 /* "parse-flows FILENAME": reads the named file as a sequence of flows (like
1600 * add-flows) and prints each of the flows back to stdout. */
1602 do_parse_flows(int argc OVS_UNUSED, char *argv[])
1604 enum nx_flow_format flow_format;
1605 bool flow_mod_table_id;
1606 struct list packets;
1609 file = fopen(argv[1], "r");
1611 ovs_fatal(errno, "%s: open", argv[1]);
1614 flow_format = NXFF_OPENFLOW10;
1615 if (preferred_flow_format > 0) {
1616 flow_format = preferred_flow_format;
1618 flow_mod_table_id = false;
1620 list_init(&packets);
1621 while (parse_ofp_flow_mod_file(&packets, &flow_format, &flow_mod_table_id,
1623 print_packet_list(&packets);
1628 /* "parse-nx-match": reads a series of nx_match specifications as strings from
1629 * stdin, does some internal fussing with them, and then prints them back as
1630 * strings on stdout. */
1632 do_parse_nx_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1637 while (!ds_get_line(&in, stdin)) {
1638 struct ofpbuf nx_match;
1639 struct cls_rule rule;
1640 ovs_be64 cookie, cookie_mask;
1645 /* Delete comments, skip blank lines. */
1651 if (strchr(s, '#')) {
1652 *strchr(s, '#') = '\0';
1654 if (s[strspn(s, " ")] == '\0') {
1659 /* Convert string to nx_match. */
1660 ofpbuf_init(&nx_match, 0);
1661 match_len = nx_match_from_string(ds_cstr(&in), &nx_match);
1663 /* Convert nx_match to cls_rule. */
1665 error = nx_pull_match(&nx_match, match_len, 0, &rule,
1666 &cookie, &cookie_mask);
1668 error = nx_pull_match_loose(&nx_match, match_len, 0, &rule,
1669 &cookie, &cookie_mask);
1675 /* Convert cls_rule back to nx_match. */
1676 ofpbuf_uninit(&nx_match);
1677 ofpbuf_init(&nx_match, 0);
1678 match_len = nx_put_match(&nx_match, &rule, cookie, cookie_mask);
1680 /* Convert nx_match to string. */
1681 out = nx_match_to_string(nx_match.data, match_len);
1685 printf("nx_pull_match() returned error %s\n",
1686 ofperr_get_name(error));
1689 ofpbuf_uninit(&nx_match);
1694 /* "ofp-print HEXSTRING [VERBOSITY]": Converts the hex digits in HEXSTRING into
1695 * binary data, interpreting them as an OpenFlow message, and prints the
1696 * OpenFlow message on stdout, at VERBOSITY (level 2 by default). */
1698 do_ofp_print(int argc, char *argv[])
1700 struct ofpbuf packet;
1702 ofpbuf_init(&packet, strlen(argv[1]) / 2);
1703 if (ofpbuf_put_hex(&packet, argv[1], NULL)[0] != '\0') {
1704 ovs_fatal(0, "trailing garbage following hex bytes");
1706 ofp_print(stdout, packet.data, packet.size, argc > 2 ? atoi(argv[2]) : 2);
1707 ofpbuf_uninit(&packet);
1710 static const struct command all_commands[] = {
1711 { "show", 1, 1, do_show },
1712 { "monitor", 1, 3, do_monitor },
1713 { "snoop", 1, 1, do_snoop },
1714 { "dump-desc", 1, 1, do_dump_desc },
1715 { "dump-tables", 1, 1, do_dump_tables },
1716 { "dump-flows", 1, 2, do_dump_flows },
1717 { "dump-aggregate", 1, 2, do_dump_aggregate },
1718 { "queue-stats", 1, 3, do_queue_stats },
1719 { "add-flow", 2, 2, do_add_flow },
1720 { "add-flows", 2, 2, do_add_flows },
1721 { "mod-flows", 2, 2, do_mod_flows },
1722 { "del-flows", 1, 2, do_del_flows },
1723 { "replace-flows", 2, 2, do_replace_flows },
1724 { "diff-flows", 2, 2, do_diff_flows },
1725 { "packet-out", 4, INT_MAX, do_packet_out },
1726 { "dump-ports", 1, 2, do_dump_ports },
1727 { "mod-port", 3, 3, do_mod_port },
1728 { "get-frags", 1, 1, do_get_frags },
1729 { "set-frags", 2, 2, do_set_frags },
1730 { "probe", 1, 1, do_probe },
1731 { "ping", 1, 2, do_ping },
1732 { "benchmark", 3, 3, do_benchmark },
1733 { "help", 0, INT_MAX, do_help },
1735 /* Undocumented commands for testing. */
1736 { "parse-flow", 1, 1, do_parse_flow },
1737 { "parse-flows", 1, 1, do_parse_flows },
1738 { "parse-nx-match", 0, 0, do_parse_nx_match },
1739 { "ofp-print", 1, 2, do_ofp_print },
1741 { NULL, 0, 0, NULL },