2 * Copyright (c) 2008, 2009, 2010 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.
29 #include "command-line.h"
32 #include "dynamic-string.h"
35 #include "ofp-parse.h"
36 #include "ofp-print.h"
39 #include "openflow/nicira-ext.h"
40 #include "openflow/openflow.h"
42 #include "stream-ssl.h"
48 #include "xflow-util.h"
51 VLOG_DEFINE_THIS_MODULE(ofctl)
54 #define MOD_PORT_CMD_UP "up"
55 #define MOD_PORT_CMD_DOWN "down"
56 #define MOD_PORT_CMD_FLOOD "flood"
57 #define MOD_PORT_CMD_NOFLOOD "noflood"
59 /* Use strict matching for flow mod commands? */
62 static const struct command all_commands[];
64 static void usage(void) NO_RETURN;
65 static void parse_options(int argc, char *argv[]);
68 main(int argc, char *argv[])
70 set_program_name(argv[0]);
71 parse_options(argc, argv);
72 signal(SIGPIPE, SIG_IGN);
73 run_command(argc - optind, argv + optind, all_commands);
78 parse_options(int argc, char *argv[])
81 OPT_STRICT = UCHAR_MAX + 1,
84 static struct option long_options[] = {
85 {"timeout", required_argument, 0, 't'},
86 {"strict", no_argument, 0, OPT_STRICT},
87 {"help", no_argument, 0, 'h'},
88 {"version", no_argument, 0, 'V'},
90 STREAM_SSL_LONG_OPTIONS
93 char *short_options = long_options_to_short_options(long_options);
96 unsigned long int timeout;
99 c = getopt_long(argc, argv, short_options, long_options, NULL);
106 timeout = strtoul(optarg, NULL, 10);
108 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
119 OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
127 STREAM_SSL_OPTION_HANDLERS
142 printf("%s: OpenFlow switch management utility\n"
143 "usage: %s [OPTIONS] COMMAND [ARG...]\n"
144 "\nFor OpenFlow switches:\n"
145 " show SWITCH show OpenFlow information\n"
146 " status SWITCH [KEY] report statistics (about KEY)\n"
147 " dump-desc SWITCH print switch description\n"
148 " dump-tables SWITCH print table stats\n"
149 " mod-port SWITCH IFACE ACT modify port behavior\n"
150 " dump-ports SWITCH [PORT] print port statistics\n"
151 " dump-flows SWITCH print all flow entries\n"
152 " dump-flows SWITCH FLOW print matching FLOWs\n"
153 " dump-aggregate SWITCH print aggregate flow statistics\n"
154 " dump-aggregate SWITCH FLOW print aggregate stats for FLOWs\n"
155 " add-flow SWITCH FLOW add flow described by FLOW\n"
156 " add-flows SWITCH FILE add flows from FILE\n"
157 " mod-flows SWITCH FLOW modify actions of matching FLOWs\n"
158 " del-flows SWITCH [FLOW] delete matching FLOWs\n"
159 " monitor SWITCH [MISSLEN] print packets received from SWITCH\n"
160 "\nFor OpenFlow switches and controllers:\n"
161 " probe VCONN probe whether VCONN is up\n"
162 " ping VCONN [N] latency of N-byte echos\n"
163 " benchmark VCONN N COUNT bandwidth of COUNT N-byte echos\n"
164 "where each SWITCH is an active OpenFlow connection method.\n",
165 program_name, program_name);
166 vconn_usage(true, false, false);
168 printf("\nOther options:\n"
169 " --strict use strict match for flow commands\n"
170 " -t, --timeout=SECS give up after SECS seconds\n"
171 " -h, --help display this help message\n"
172 " -V, --version display version information\n");
176 static void run(int retval, const char *message, ...)
179 static void run(int retval, const char *message, ...)
184 fprintf(stderr, "%s: ", program_name);
185 va_start(args, message);
186 vfprintf(stderr, message, args);
189 fputs(": unexpected end of file\n", stderr);
191 fprintf(stderr, ": %s\n", strerror(retval));
198 /* Generic commands. */
201 open_vconn_socket(const char *name, struct vconn **vconnp)
203 char *vconn_name = xasprintf("unix:%s", name);
204 VLOG_INFO("connecting to %s", vconn_name);
205 run(vconn_open_block(vconn_name, OFP_VERSION, vconnp),
206 "connecting to %s", vconn_name);
211 open_vconn__(const char *name, const char *default_suffix,
212 struct vconn **vconnp)
216 char *bridge_path, *datapath_name, *datapath_type;
218 bridge_path = xasprintf("%s/%s.%s", ovs_rundir, name, default_suffix);
219 xf_parse_name(name, &datapath_name, &datapath_type);
221 if (strstr(name, ":")) {
222 run(vconn_open_block(name, OFP_VERSION, vconnp),
223 "connecting to %s", name);
224 } else if (!stat(name, &s) && S_ISSOCK(s.st_mode)) {
225 open_vconn_socket(name, vconnp);
226 } else if (!stat(bridge_path, &s) && S_ISSOCK(s.st_mode)) {
227 open_vconn_socket(bridge_path, vconnp);
228 } else if (!xfif_open(datapath_name, datapath_type, &xfif)) {
229 char xfif_name[IF_NAMESIZE + 1];
232 run(xfif_port_get_name(xfif, XFLOWP_LOCAL, xfif_name, sizeof xfif_name),
233 "obtaining name of %s", xfif_name);
235 if (strcmp(xfif_name, name)) {
236 VLOG_INFO("datapath %s is named %s", name, xfif_name);
239 socket_name = xasprintf("%s/%s.%s",
240 ovs_rundir, xfif_name, default_suffix);
241 if (stat(socket_name, &s)) {
242 ovs_fatal(errno, "cannot connect to %s: stat failed on %s",
244 } else if (!S_ISSOCK(s.st_mode)) {
245 ovs_fatal(0, "cannot connect to %s: %s is not a socket",
249 open_vconn_socket(socket_name, vconnp);
252 ovs_fatal(0, "%s is not a valid connection method", name);
261 open_vconn(const char *name, struct vconn **vconnp)
263 return open_vconn__(name, "mgmt", vconnp);
267 alloc_stats_request(size_t body_len, uint16_t type, struct ofpbuf **bufferp)
269 struct ofp_stats_request *rq;
270 rq = make_openflow((offsetof(struct ofp_stats_request, body)
271 + body_len), OFPT_STATS_REQUEST, bufferp);
272 rq->type = htons(type);
273 rq->flags = htons(0);
278 send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
280 update_openflow_length(buffer);
281 run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
285 dump_transaction(const char *vconn_name, struct ofpbuf *request)
288 struct ofpbuf *reply;
290 update_openflow_length(request);
291 open_vconn(vconn_name, &vconn);
292 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
293 ofp_print(stdout, reply->data, reply->size, 1);
298 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
300 struct ofpbuf *request;
301 make_openflow(sizeof(struct ofp_header), request_type, &request);
302 dump_transaction(vconn_name, request);
306 dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
308 uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
312 open_vconn(vconn_name, &vconn);
313 send_openflow_buffer(vconn, request);
316 struct ofpbuf *reply;
318 run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
319 recv_xid = ((struct ofp_header *) reply->data)->xid;
320 if (send_xid == recv_xid) {
321 struct ofp_stats_reply *osr;
323 ofp_print(stdout, reply->data, reply->size, 1);
325 osr = ofpbuf_at(reply, 0, sizeof *osr);
326 done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
328 VLOG_DBG("received reply with xid %08"PRIx32" "
329 "!= expected %08"PRIx32, recv_xid, send_xid);
331 ofpbuf_delete(reply);
337 dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
339 struct ofpbuf *request;
340 alloc_stats_request(0, stats_type, &request);
341 dump_stats_transaction(vconn_name, request);
345 do_show(int argc OVS_UNUSED, char *argv[])
347 dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
348 dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
352 do_status(int argc, char *argv[])
354 struct nicira_header *request, *reply;
358 request = make_openflow(sizeof *request, OFPT_VENDOR, &b);
359 request->vendor = htonl(NX_VENDOR_ID);
360 request->subtype = htonl(NXT_STATUS_REQUEST);
362 ofpbuf_put(b, argv[2], strlen(argv[2]));
363 update_openflow_length(b);
365 open_vconn(argv[1], &vconn);
366 run(vconn_transact(vconn, b, &b), "talking to %s", argv[1]);
369 if (b->size < sizeof *reply) {
370 ovs_fatal(0, "short reply (%zu bytes)", b->size);
373 if (reply->header.type != OFPT_VENDOR
374 || reply->vendor != ntohl(NX_VENDOR_ID)
375 || reply->subtype != ntohl(NXT_STATUS_REPLY)) {
376 ofp_print(stderr, b->data, b->size, 2);
377 ovs_fatal(0, "bad reply");
380 fwrite(reply + 1, b->size - sizeof *reply, 1, stdout);
384 do_dump_desc(int argc OVS_UNUSED, char *argv[])
386 dump_trivial_stats_transaction(argv[1], OFPST_DESC);
390 do_dump_tables(int argc OVS_UNUSED, char *argv[])
392 dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
396 str_to_port_no(const char *vconn_name, const char *str)
398 struct ofpbuf *request, *reply;
399 struct ofp_switch_features *osf;
403 unsigned int port_no;
406 /* Check if the argument is a port index. Otherwise, treat it as
408 if (str_to_uint(str, 10, &port_no)) {
412 /* Send a "Features Request" to resolve the name into a number. */
413 make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
414 open_vconn(vconn_name, &vconn);
415 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
418 n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
420 for (port_idx = 0; port_idx < n_ports; port_idx++) {
421 /* Check argument as an interface name */
422 if (!strncmp((char *)osf->ports[port_idx].name, str,
423 sizeof osf->ports[0].name)) {
427 if (port_idx == n_ports) {
428 ovs_fatal(0, "couldn't find monitored port: %s", str);
431 ofpbuf_delete(reply);
438 do_dump_flows(int argc, char *argv[])
440 struct ofp_flow_stats_request *req;
442 struct ofpbuf *request;
444 req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
445 parse_ofp_str(argc > 2 ? argv[2] : "", &req->match, NULL,
446 &req->table_id, &out_port, NULL, NULL, NULL, NULL);
447 memset(&req->pad, 0, sizeof req->pad);
448 req->out_port = htons(out_port);
450 dump_stats_transaction(argv[1], request);
454 do_dump_aggregate(int argc, char *argv[])
456 struct ofp_aggregate_stats_request *req;
457 struct ofpbuf *request;
460 req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
461 parse_ofp_str(argc > 2 ? argv[2] : "", &req->match, NULL,
462 &req->table_id, &out_port, NULL, NULL, NULL, NULL);
463 memset(&req->pad, 0, sizeof req->pad);
464 req->out_port = htons(out_port);
466 dump_stats_transaction(argv[1], request);
470 enable_flow_mod_table_id_ext(struct vconn *vconn, uint8_t enable)
472 struct nxt_flow_mod_table_id *flow_mod_table_id;
473 struct ofpbuf *buffer;
475 flow_mod_table_id = make_openflow(sizeof *flow_mod_table_id, OFPT_VENDOR, &buffer);
477 flow_mod_table_id->vendor = htonl(NX_VENDOR_ID);
478 flow_mod_table_id->subtype = htonl(NXT_FLOW_MOD_TABLE_ID);
479 flow_mod_table_id->set = enable;
481 send_openflow_buffer(vconn, buffer);
485 do_add_flow(int argc OVS_UNUSED, char *argv[])
488 struct ofpbuf *buffer;
489 struct ofp_flow_mod *ofm;
490 uint16_t priority, idle_timeout, hard_timeout;
492 struct ofp_match match;
495 /* Parse and send. parse_ofp_str() will expand and reallocate the
496 * data in 'buffer', so we can't keep pointers to across the
497 * parse_ofp_str() call. */
498 make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
499 parse_ofp_str(argv[2], &match, buffer,
500 &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
504 ofm->command = htons(OFPFC_ADD);
505 ofm->cookie = htonll(cookie);
506 ofm->idle_timeout = htons(idle_timeout);
507 ofm->hard_timeout = htons(hard_timeout);
508 ofm->buffer_id = htonl(UINT32_MAX);
509 ofm->priority = htons(priority);
511 open_vconn(argv[1], &vconn);
512 if (table_idx != 0xff) {
513 enable_flow_mod_table_id_ext(vconn, 1);
514 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
516 send_openflow_buffer(vconn, buffer);
521 do_add_flows(int argc OVS_UNUSED, char *argv[])
527 int table_id_enabled = 0;
529 file = fopen(argv[2], "r");
531 ovs_fatal(errno, "%s: open", argv[2]);
534 open_vconn(argv[1], &vconn);
535 while (fgets(line, sizeof line, file)) {
536 struct ofpbuf *buffer;
537 struct ofp_flow_mod *ofm;
538 uint16_t priority, idle_timeout, hard_timeout;
540 struct ofp_match match;
544 /* Delete comments. */
545 comment = strchr(line, '#');
550 /* Drop empty lines. */
551 if (line[strspn(line, " \t\n")] == '\0') {
555 /* Parse and send. parse_ofp_str() will expand and reallocate
556 * the data in 'buffer', so we can't keep pointers to across the
557 * parse_ofp_str() call. */
558 make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
559 parse_ofp_str(line, &match, buffer, &table_idx, NULL, &priority,
560 &idle_timeout, &hard_timeout, &cookie);
563 ofm->command = htons(OFPFC_ADD);
564 ofm->cookie = htonll(cookie);
565 ofm->idle_timeout = htons(idle_timeout);
566 ofm->hard_timeout = htons(hard_timeout);
567 ofm->buffer_id = htonl(UINT32_MAX);
568 ofm->priority = htons(priority);
570 if (table_idx != 0xff) {
571 if (!table_id_enabled) {
572 enable_flow_mod_table_id_ext(vconn, 1);
573 table_id_enabled = 1;
575 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
577 if (table_id_enabled) {
578 enable_flow_mod_table_id_ext(vconn, 0);
579 table_id_enabled = 0;
582 send_openflow_buffer(vconn, buffer);
589 do_mod_flows(int argc OVS_UNUSED, char *argv[])
591 uint16_t priority, idle_timeout, hard_timeout;
594 struct ofpbuf *buffer;
595 struct ofp_flow_mod *ofm;
596 struct ofp_match match;
599 /* Parse and send. parse_ofp_str() will expand and reallocate the
600 * data in 'buffer', so we can't keep pointers to across the
601 * parse_ofp_str() call. */
602 make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
603 parse_ofp_str(argv[2], &match, buffer,
604 &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
609 ofm->command = htons(OFPFC_MODIFY_STRICT);
611 ofm->command = htons(OFPFC_MODIFY);
613 ofm->idle_timeout = htons(idle_timeout);
614 ofm->hard_timeout = htons(hard_timeout);
615 ofm->cookie = htonll(cookie);
616 ofm->buffer_id = htonl(UINT32_MAX);
617 ofm->priority = htons(priority);
619 open_vconn(argv[1], &vconn);
620 if (table_idx != 0xff) {
621 enable_flow_mod_table_id_ext(vconn, 1);
622 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
624 send_openflow_buffer(vconn, buffer);
628 static void do_del_flows(int argc, char *argv[])
633 struct ofpbuf *buffer;
634 struct ofp_flow_mod *ofm;
637 /* Parse and send. */
638 ofm = make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
639 parse_ofp_str(argc > 2 ? argv[2] : "", &ofm->match, NULL, &table_idx,
640 &out_port, &priority, NULL, NULL, NULL);
642 ofm->command = htons(OFPFC_DELETE_STRICT);
644 ofm->command = htons(OFPFC_DELETE);
646 ofm->idle_timeout = htons(0);
647 ofm->hard_timeout = htons(0);
648 ofm->buffer_id = htonl(UINT32_MAX);
649 ofm->out_port = htons(out_port);
650 ofm->priority = htons(priority);
652 open_vconn(argv[1], &vconn);
653 if (table_idx != 0xff) {
654 enable_flow_mod_table_id_ext(vconn, 1);
655 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
657 send_openflow_buffer(vconn, buffer);
662 do_tun_cookie(int argc OVS_UNUSED, char *argv[])
664 struct nxt_tun_id_cookie *tun_id_cookie;
665 struct ofpbuf *buffer;
668 tun_id_cookie = make_openflow(sizeof *tun_id_cookie, OFPT_VENDOR, &buffer);
670 tun_id_cookie->vendor = htonl(NX_VENDOR_ID);
671 tun_id_cookie->subtype = htonl(NXT_TUN_ID_FROM_COOKIE);
672 tun_id_cookie->set = !strcmp(argv[2], "true");
674 open_vconn(argv[1], &vconn);
675 send_openflow_buffer(vconn, buffer);
680 monitor_vconn(struct vconn *vconn)
684 run(vconn_recv_block(vconn, &b), "vconn_recv");
685 ofp_print(stderr, b->data, b->size, 2);
691 do_monitor(int argc, char *argv[])
695 open_vconn(argv[1], &vconn);
697 int miss_send_len = atoi(argv[2]);
698 struct ofp_switch_config *osc;
701 osc = make_openflow(sizeof *osc, OFPT_SET_CONFIG, &buf);
702 osc->miss_send_len = htons(miss_send_len);
703 send_openflow_buffer(vconn, buf);
705 monitor_vconn(vconn);
709 do_snoop(int argc OVS_UNUSED, char *argv[])
713 open_vconn__(argv[1], "snoop", &vconn);
714 monitor_vconn(vconn);
718 do_dump_ports(int argc, char *argv[])
720 struct ofp_port_stats_request *req;
721 struct ofpbuf *request;
724 req = alloc_stats_request(sizeof *req, OFPST_PORT, &request);
725 port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_NONE;
726 req->port_no = htons(port);
727 dump_stats_transaction(argv[1], request);
731 do_probe(int argc OVS_UNUSED, char *argv[])
733 struct ofpbuf *request;
735 struct ofpbuf *reply;
737 make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
738 open_vconn(argv[1], &vconn);
739 run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
740 if (reply->size != sizeof(struct ofp_header)) {
741 ovs_fatal(0, "reply does not match request");
743 ofpbuf_delete(reply);
748 do_mod_port(int argc OVS_UNUSED, char *argv[])
750 struct ofpbuf *request, *reply;
751 struct ofp_switch_features *osf;
752 struct ofp_port_mod *opm;
760 /* Check if the argument is a port index. Otherwise, treat it as
762 port_no = strtol(argv[2], &endptr, 10);
763 if (port_no == 0 && endptr == argv[2]) {
767 /* Send a "Features Request" to get the information we need in order
768 * to modify the port. */
769 make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
770 open_vconn(argv[1], &vconn);
771 run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
774 n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
776 for (port_idx = 0; port_idx < n_ports; port_idx++) {
778 /* Check argument as a port index */
779 if (osf->ports[port_idx].port_no == htons(port_no)) {
783 /* Check argument as an interface name */
784 if (!strncmp((char *)osf->ports[port_idx].name, argv[2],
785 sizeof osf->ports[0].name)) {
791 if (port_idx == n_ports) {
792 ovs_fatal(0, "couldn't find monitored port: %s", argv[2]);
795 opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
796 opm->port_no = osf->ports[port_idx].port_no;
797 memcpy(opm->hw_addr, osf->ports[port_idx].hw_addr, sizeof opm->hw_addr);
798 opm->config = htonl(0);
799 opm->mask = htonl(0);
800 opm->advertise = htonl(0);
802 printf("modifying port: %s\n", osf->ports[port_idx].name);
804 if (!strncasecmp(argv[3], MOD_PORT_CMD_UP, sizeof MOD_PORT_CMD_UP)) {
805 opm->mask |= htonl(OFPPC_PORT_DOWN);
806 } else if (!strncasecmp(argv[3], MOD_PORT_CMD_DOWN,
807 sizeof MOD_PORT_CMD_DOWN)) {
808 opm->mask |= htonl(OFPPC_PORT_DOWN);
809 opm->config |= htonl(OFPPC_PORT_DOWN);
810 } else if (!strncasecmp(argv[3], MOD_PORT_CMD_FLOOD,
811 sizeof MOD_PORT_CMD_FLOOD)) {
812 opm->mask |= htonl(OFPPC_NO_FLOOD);
813 } else if (!strncasecmp(argv[3], MOD_PORT_CMD_NOFLOOD,
814 sizeof MOD_PORT_CMD_NOFLOOD)) {
815 opm->mask |= htonl(OFPPC_NO_FLOOD);
816 opm->config |= htonl(OFPPC_NO_FLOOD);
818 ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
821 send_openflow_buffer(vconn, request);
823 ofpbuf_delete(reply);
828 do_ping(int argc, char *argv[])
830 size_t max_payload = 65535 - sizeof(struct ofp_header);
831 unsigned int payload;
835 payload = argc > 2 ? atoi(argv[2]) : 64;
836 if (payload > max_payload) {
837 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
840 open_vconn(argv[1], &vconn);
841 for (i = 0; i < 10; i++) {
842 struct timeval start, end;
843 struct ofpbuf *request, *reply;
844 struct ofp_header *rq_hdr, *rpy_hdr;
846 rq_hdr = make_openflow(sizeof(struct ofp_header) + payload,
847 OFPT_ECHO_REQUEST, &request);
848 random_bytes(rq_hdr + 1, payload);
850 gettimeofday(&start, NULL);
851 run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
852 gettimeofday(&end, NULL);
854 rpy_hdr = reply->data;
855 if (reply->size != request->size
856 || memcmp(rpy_hdr + 1, rq_hdr + 1, payload)
857 || rpy_hdr->xid != rq_hdr->xid
858 || rpy_hdr->type != OFPT_ECHO_REPLY) {
859 printf("Reply does not match request. Request:\n");
860 ofp_print(stdout, request, request->size, 2);
862 ofp_print(stdout, reply, reply->size, 2);
864 printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
865 reply->size - sizeof *rpy_hdr, argv[1], rpy_hdr->xid,
866 (1000*(double)(end.tv_sec - start.tv_sec))
867 + (.001*(end.tv_usec - start.tv_usec)));
868 ofpbuf_delete(request);
869 ofpbuf_delete(reply);
875 do_benchmark(int argc OVS_UNUSED, char *argv[])
877 size_t max_payload = 65535 - sizeof(struct ofp_header);
878 struct timeval start, end;
879 unsigned int payload_size, message_size;
885 payload_size = atoi(argv[2]);
886 if (payload_size > max_payload) {
887 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
889 message_size = sizeof(struct ofp_header) + payload_size;
891 count = atoi(argv[3]);
893 printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
894 count, message_size, count * message_size);
896 open_vconn(argv[1], &vconn);
897 gettimeofday(&start, NULL);
898 for (i = 0; i < count; i++) {
899 struct ofpbuf *request, *reply;
900 struct ofp_header *rq_hdr;
902 rq_hdr = make_openflow(message_size, OFPT_ECHO_REQUEST, &request);
903 memset(rq_hdr + 1, 0, payload_size);
904 run(vconn_transact(vconn, request, &reply), "transact");
905 ofpbuf_delete(reply);
907 gettimeofday(&end, NULL);
910 duration = ((1000*(double)(end.tv_sec - start.tv_sec))
911 + (.001*(end.tv_usec - start.tv_usec)));
912 printf("Finished in %.1f ms (%.0f packets/s) (%.0f bytes/s)\n",
913 duration, count / (duration / 1000.0),
914 count * message_size / (duration / 1000.0));
918 do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
923 static const struct command all_commands[] = {
924 { "show", 1, 1, do_show },
925 { "status", 1, 2, do_status },
926 { "monitor", 1, 2, do_monitor },
927 { "snoop", 1, 1, do_snoop },
928 { "dump-desc", 1, 1, do_dump_desc },
929 { "dump-tables", 1, 1, do_dump_tables },
930 { "dump-flows", 1, 2, do_dump_flows },
931 { "dump-aggregate", 1, 2, do_dump_aggregate },
932 { "add-flow", 2, 2, do_add_flow },
933 { "add-flows", 2, 2, do_add_flows },
934 { "mod-flows", 2, 2, do_mod_flows },
935 { "del-flows", 1, 2, do_del_flows },
936 { "tun-cookie", 2, 2, do_tun_cookie },
937 { "dump-ports", 1, 2, do_dump_ports },
938 { "mod-port", 3, 3, do_mod_port },
939 { "probe", 1, 1, do_probe },
940 { "ping", 1, 2, do_ping },
941 { "benchmark", 3, 3, do_benchmark },
942 { "help", 0, INT_MAX, do_help },
943 { NULL, 0, 0, NULL },