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 " queue-stats SWITCH [PORT [QUEUE]] dump queue stats\n"
156 " add-flow SWITCH FLOW add flow described by FLOW\n"
157 " add-flows SWITCH FILE add flows from FILE\n"
158 " mod-flows SWITCH FLOW modify actions of matching FLOWs\n"
159 " del-flows SWITCH [FLOW] delete matching FLOWs\n"
160 " monitor SWITCH [MISSLEN] print packets received from SWITCH\n"
161 "\nFor OpenFlow switches and controllers:\n"
162 " probe VCONN probe whether VCONN is up\n"
163 " ping VCONN [N] latency of N-byte echos\n"
164 " benchmark VCONN N COUNT bandwidth of COUNT N-byte echos\n"
165 "where each SWITCH is an active OpenFlow connection method.\n",
166 program_name, program_name);
167 vconn_usage(true, false, false);
169 printf("\nOther options:\n"
170 " --strict use strict match for flow commands\n"
171 " -t, --timeout=SECS give up after SECS seconds\n"
172 " -h, --help display this help message\n"
173 " -V, --version display version information\n");
177 static void run(int retval, const char *message, ...)
180 static void run(int retval, const char *message, ...)
185 fprintf(stderr, "%s: ", program_name);
186 va_start(args, message);
187 vfprintf(stderr, message, args);
190 fputs(": unexpected end of file\n", stderr);
192 fprintf(stderr, ": %s\n", strerror(retval));
199 /* Generic commands. */
202 open_vconn_socket(const char *name, struct vconn **vconnp)
204 char *vconn_name = xasprintf("unix:%s", name);
205 VLOG_INFO("connecting to %s", vconn_name);
206 run(vconn_open_block(vconn_name, OFP_VERSION, vconnp),
207 "connecting to %s", vconn_name);
212 open_vconn__(const char *name, const char *default_suffix,
213 struct vconn **vconnp)
217 char *bridge_path, *datapath_name, *datapath_type;
219 bridge_path = xasprintf("%s/%s.%s", ovs_rundir, name, default_suffix);
220 xf_parse_name(name, &datapath_name, &datapath_type);
222 if (strstr(name, ":")) {
223 run(vconn_open_block(name, OFP_VERSION, vconnp),
224 "connecting to %s", name);
225 } else if (!stat(name, &s) && S_ISSOCK(s.st_mode)) {
226 open_vconn_socket(name, vconnp);
227 } else if (!stat(bridge_path, &s) && S_ISSOCK(s.st_mode)) {
228 open_vconn_socket(bridge_path, vconnp);
229 } else if (!xfif_open(datapath_name, datapath_type, &xfif)) {
230 char xfif_name[IF_NAMESIZE + 1];
233 run(xfif_port_get_name(xfif, XFLOWP_LOCAL, xfif_name, sizeof xfif_name),
234 "obtaining name of %s", xfif_name);
236 if (strcmp(xfif_name, name)) {
237 VLOG_INFO("datapath %s is named %s", name, xfif_name);
240 socket_name = xasprintf("%s/%s.%s",
241 ovs_rundir, xfif_name, default_suffix);
242 if (stat(socket_name, &s)) {
243 ovs_fatal(errno, "cannot connect to %s: stat failed on %s",
245 } else if (!S_ISSOCK(s.st_mode)) {
246 ovs_fatal(0, "cannot connect to %s: %s is not a socket",
250 open_vconn_socket(socket_name, vconnp);
253 ovs_fatal(0, "%s is not a valid connection method", name);
262 open_vconn(const char *name, struct vconn **vconnp)
264 return open_vconn__(name, "mgmt", vconnp);
268 alloc_stats_request(size_t body_len, uint16_t type, struct ofpbuf **bufferp)
270 struct ofp_stats_request *rq;
271 rq = make_openflow((offsetof(struct ofp_stats_request, body)
272 + body_len), OFPT_STATS_REQUEST, bufferp);
273 rq->type = htons(type);
274 rq->flags = htons(0);
279 send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
281 update_openflow_length(buffer);
282 run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
286 dump_transaction(const char *vconn_name, struct ofpbuf *request)
289 struct ofpbuf *reply;
291 update_openflow_length(request);
292 open_vconn(vconn_name, &vconn);
293 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
294 ofp_print(stdout, reply->data, reply->size, 1);
299 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
301 struct ofpbuf *request;
302 make_openflow(sizeof(struct ofp_header), request_type, &request);
303 dump_transaction(vconn_name, request);
307 dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
309 uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
313 open_vconn(vconn_name, &vconn);
314 send_openflow_buffer(vconn, request);
317 struct ofpbuf *reply;
319 run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
320 recv_xid = ((struct ofp_header *) reply->data)->xid;
321 if (send_xid == recv_xid) {
322 struct ofp_stats_reply *osr;
324 ofp_print(stdout, reply->data, reply->size, 1);
326 osr = ofpbuf_at(reply, 0, sizeof *osr);
327 done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
329 VLOG_DBG("received reply with xid %08"PRIx32" "
330 "!= expected %08"PRIx32, recv_xid, send_xid);
332 ofpbuf_delete(reply);
338 dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
340 struct ofpbuf *request;
341 alloc_stats_request(0, stats_type, &request);
342 dump_stats_transaction(vconn_name, request);
346 do_show(int argc OVS_UNUSED, char *argv[])
348 dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
349 dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
353 do_status(int argc, char *argv[])
355 struct nicira_header *request, *reply;
359 request = make_openflow(sizeof *request, OFPT_VENDOR, &b);
360 request->vendor = htonl(NX_VENDOR_ID);
361 request->subtype = htonl(NXT_STATUS_REQUEST);
363 ofpbuf_put(b, argv[2], strlen(argv[2]));
364 update_openflow_length(b);
366 open_vconn(argv[1], &vconn);
367 run(vconn_transact(vconn, b, &b), "talking to %s", argv[1]);
370 if (b->size < sizeof *reply) {
371 ovs_fatal(0, "short reply (%zu bytes)", b->size);
374 if (reply->header.type != OFPT_VENDOR
375 || reply->vendor != ntohl(NX_VENDOR_ID)
376 || reply->subtype != ntohl(NXT_STATUS_REPLY)) {
377 ofp_print(stderr, b->data, b->size, 2);
378 ovs_fatal(0, "bad reply");
381 fwrite(reply + 1, b->size - sizeof *reply, 1, stdout);
385 do_dump_desc(int argc OVS_UNUSED, char *argv[])
387 dump_trivial_stats_transaction(argv[1], OFPST_DESC);
391 do_dump_tables(int argc OVS_UNUSED, char *argv[])
393 dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
397 str_to_port_no(const char *vconn_name, const char *str)
399 struct ofpbuf *request, *reply;
400 struct ofp_switch_features *osf;
404 unsigned int port_no;
407 /* Check if the argument is a port index. Otherwise, treat it as
409 if (str_to_uint(str, 10, &port_no)) {
413 /* Send a "Features Request" to resolve the name into a number. */
414 make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
415 open_vconn(vconn_name, &vconn);
416 run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
419 n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
421 for (port_idx = 0; port_idx < n_ports; port_idx++) {
422 /* Check argument as an interface name */
423 if (!strncmp((char *)osf->ports[port_idx].name, str,
424 sizeof osf->ports[0].name)) {
428 if (port_idx == n_ports) {
429 ovs_fatal(0, "couldn't find monitored port: %s", str);
432 ofpbuf_delete(reply);
439 do_dump_flows(int argc, char *argv[])
441 struct ofp_flow_stats_request *req;
443 struct ofpbuf *request;
445 req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
446 parse_ofp_str(argc > 2 ? argv[2] : "", &req->match, NULL,
447 &req->table_id, &out_port, NULL, NULL, NULL, NULL);
448 memset(&req->pad, 0, sizeof req->pad);
449 req->out_port = htons(out_port);
451 dump_stats_transaction(argv[1], request);
455 do_dump_aggregate(int argc, char *argv[])
457 struct ofp_aggregate_stats_request *req;
458 struct ofpbuf *request;
461 req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
462 parse_ofp_str(argc > 2 ? argv[2] : "", &req->match, NULL,
463 &req->table_id, &out_port, NULL, NULL, NULL, NULL);
464 memset(&req->pad, 0, sizeof req->pad);
465 req->out_port = htons(out_port);
467 dump_stats_transaction(argv[1], request);
471 enable_flow_mod_table_id_ext(struct vconn *vconn, bool enable)
473 send_openflow_buffer(vconn, make_nxt_flow_mod_table_id(enable));
477 do_queue_stats(int argc, char *argv[])
479 struct ofp_queue_stats_request *req;
480 struct ofpbuf *request;
482 req = alloc_stats_request(sizeof *req, OFPST_QUEUE, &request);
484 if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) {
485 req->port_no = htons(str_to_port_no(argv[1], argv[2]));
487 req->port_no = htons(OFPP_ALL);
489 if (argc > 3 && argv[3][0] && strcasecmp(argv[3], "all")) {
490 req->queue_id = htonl(atoi(argv[3]));
492 req->queue_id = htonl(OFPQ_ALL);
495 memset(req->pad, 0, sizeof req->pad);
497 dump_stats_transaction(argv[1], request);
501 do_add_flow(int argc OVS_UNUSED, char *argv[])
504 struct ofpbuf *buffer;
505 struct ofp_flow_mod *ofm;
506 uint16_t priority, idle_timeout, hard_timeout;
508 struct ofp_match match;
511 /* Parse and send. parse_ofp_str() will expand and reallocate the
512 * data in 'buffer', so we can't keep pointers to across the
513 * parse_ofp_str() call. */
514 make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
515 parse_ofp_str(argv[2], &match, buffer,
516 &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
520 ofm->command = htons(OFPFC_ADD);
521 ofm->cookie = htonll(cookie);
522 ofm->idle_timeout = htons(idle_timeout);
523 ofm->hard_timeout = htons(hard_timeout);
524 ofm->buffer_id = htonl(UINT32_MAX);
525 ofm->priority = htons(priority);
527 open_vconn(argv[1], &vconn);
528 if (table_idx != 0xff) {
529 enable_flow_mod_table_id_ext(vconn, 1);
530 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
532 send_openflow_buffer(vconn, buffer);
537 do_add_flows(int argc OVS_UNUSED, char *argv[])
542 bool table_id_enabled = false;
545 file = fopen(argv[2], "r");
547 ovs_fatal(errno, "%s: open", argv[2]);
550 open_vconn(argv[1], &vconn);
551 while ((b = parse_ofp_add_flow_file(file, &table_idx)) != NULL) {
552 if ((table_idx != 0xff) != table_id_enabled) {
553 table_id_enabled = table_idx != 0xff;
554 enable_flow_mod_table_id_ext(vconn, table_id_enabled);
556 send_openflow_buffer(vconn, b);
563 do_mod_flows(int argc OVS_UNUSED, char *argv[])
565 uint16_t priority, idle_timeout, hard_timeout;
568 struct ofpbuf *buffer;
569 struct ofp_flow_mod *ofm;
570 struct ofp_match match;
573 /* Parse and send. parse_ofp_str() will expand and reallocate the
574 * data in 'buffer', so we can't keep pointers to across the
575 * parse_ofp_str() call. */
576 make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
577 parse_ofp_str(argv[2], &match, buffer,
578 &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
583 ofm->command = htons(OFPFC_MODIFY_STRICT);
585 ofm->command = htons(OFPFC_MODIFY);
587 ofm->idle_timeout = htons(idle_timeout);
588 ofm->hard_timeout = htons(hard_timeout);
589 ofm->cookie = htonll(cookie);
590 ofm->buffer_id = htonl(UINT32_MAX);
591 ofm->priority = htons(priority);
593 open_vconn(argv[1], &vconn);
594 if (table_idx != 0xff) {
595 enable_flow_mod_table_id_ext(vconn, 1);
596 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
598 send_openflow_buffer(vconn, buffer);
602 static void do_del_flows(int argc, char *argv[])
607 struct ofpbuf *buffer;
608 struct ofp_flow_mod *ofm;
611 /* Parse and send. */
612 ofm = make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
613 parse_ofp_str(argc > 2 ? argv[2] : "", &ofm->match, NULL, &table_idx,
614 &out_port, &priority, NULL, NULL, NULL);
616 ofm->command = htons(OFPFC_DELETE_STRICT);
618 ofm->command = htons(OFPFC_DELETE);
620 ofm->idle_timeout = htons(0);
621 ofm->hard_timeout = htons(0);
622 ofm->buffer_id = htonl(UINT32_MAX);
623 ofm->out_port = htons(out_port);
624 ofm->priority = htons(priority);
626 open_vconn(argv[1], &vconn);
627 if (table_idx != 0xff) {
628 enable_flow_mod_table_id_ext(vconn, 1);
629 ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
631 send_openflow_buffer(vconn, buffer);
636 do_tun_cookie(int argc OVS_UNUSED, char *argv[])
638 struct nxt_tun_id_cookie *tun_id_cookie;
639 struct ofpbuf *buffer;
642 tun_id_cookie = make_openflow(sizeof *tun_id_cookie, OFPT_VENDOR, &buffer);
644 tun_id_cookie->vendor = htonl(NX_VENDOR_ID);
645 tun_id_cookie->subtype = htonl(NXT_TUN_ID_FROM_COOKIE);
646 tun_id_cookie->set = !strcmp(argv[2], "true");
648 open_vconn(argv[1], &vconn);
649 send_openflow_buffer(vconn, buffer);
654 monitor_vconn(struct vconn *vconn)
658 run(vconn_recv_block(vconn, &b), "vconn_recv");
659 ofp_print(stderr, b->data, b->size, 2);
665 do_monitor(int argc, char *argv[])
669 open_vconn(argv[1], &vconn);
671 int miss_send_len = atoi(argv[2]);
672 struct ofp_switch_config *osc;
675 osc = make_openflow(sizeof *osc, OFPT_SET_CONFIG, &buf);
676 osc->miss_send_len = htons(miss_send_len);
677 send_openflow_buffer(vconn, buf);
679 monitor_vconn(vconn);
683 do_snoop(int argc OVS_UNUSED, char *argv[])
687 open_vconn__(argv[1], "snoop", &vconn);
688 monitor_vconn(vconn);
692 do_dump_ports(int argc, char *argv[])
694 struct ofp_port_stats_request *req;
695 struct ofpbuf *request;
698 req = alloc_stats_request(sizeof *req, OFPST_PORT, &request);
699 port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_NONE;
700 req->port_no = htons(port);
701 dump_stats_transaction(argv[1], request);
705 do_probe(int argc OVS_UNUSED, char *argv[])
707 struct ofpbuf *request;
709 struct ofpbuf *reply;
711 make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
712 open_vconn(argv[1], &vconn);
713 run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
714 if (reply->size != sizeof(struct ofp_header)) {
715 ovs_fatal(0, "reply does not match request");
717 ofpbuf_delete(reply);
722 do_mod_port(int argc OVS_UNUSED, char *argv[])
724 struct ofpbuf *request, *reply;
725 struct ofp_switch_features *osf;
726 struct ofp_port_mod *opm;
734 /* Check if the argument is a port index. Otherwise, treat it as
736 port_no = strtol(argv[2], &endptr, 10);
737 if (port_no == 0 && endptr == argv[2]) {
741 /* Send a "Features Request" to get the information we need in order
742 * to modify the port. */
743 make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
744 open_vconn(argv[1], &vconn);
745 run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
748 n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
750 for (port_idx = 0; port_idx < n_ports; port_idx++) {
752 /* Check argument as a port index */
753 if (osf->ports[port_idx].port_no == htons(port_no)) {
757 /* Check argument as an interface name */
758 if (!strncmp((char *)osf->ports[port_idx].name, argv[2],
759 sizeof osf->ports[0].name)) {
765 if (port_idx == n_ports) {
766 ovs_fatal(0, "couldn't find monitored port: %s", argv[2]);
769 opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
770 opm->port_no = osf->ports[port_idx].port_no;
771 memcpy(opm->hw_addr, osf->ports[port_idx].hw_addr, sizeof opm->hw_addr);
772 opm->config = htonl(0);
773 opm->mask = htonl(0);
774 opm->advertise = htonl(0);
776 printf("modifying port: %s\n", osf->ports[port_idx].name);
778 if (!strncasecmp(argv[3], MOD_PORT_CMD_UP, sizeof MOD_PORT_CMD_UP)) {
779 opm->mask |= htonl(OFPPC_PORT_DOWN);
780 } else if (!strncasecmp(argv[3], MOD_PORT_CMD_DOWN,
781 sizeof MOD_PORT_CMD_DOWN)) {
782 opm->mask |= htonl(OFPPC_PORT_DOWN);
783 opm->config |= htonl(OFPPC_PORT_DOWN);
784 } else if (!strncasecmp(argv[3], MOD_PORT_CMD_FLOOD,
785 sizeof MOD_PORT_CMD_FLOOD)) {
786 opm->mask |= htonl(OFPPC_NO_FLOOD);
787 } else if (!strncasecmp(argv[3], MOD_PORT_CMD_NOFLOOD,
788 sizeof MOD_PORT_CMD_NOFLOOD)) {
789 opm->mask |= htonl(OFPPC_NO_FLOOD);
790 opm->config |= htonl(OFPPC_NO_FLOOD);
792 ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
795 send_openflow_buffer(vconn, request);
797 ofpbuf_delete(reply);
802 do_ping(int argc, char *argv[])
804 size_t max_payload = 65535 - sizeof(struct ofp_header);
805 unsigned int payload;
809 payload = argc > 2 ? atoi(argv[2]) : 64;
810 if (payload > max_payload) {
811 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
814 open_vconn(argv[1], &vconn);
815 for (i = 0; i < 10; i++) {
816 struct timeval start, end;
817 struct ofpbuf *request, *reply;
818 struct ofp_header *rq_hdr, *rpy_hdr;
820 rq_hdr = make_openflow(sizeof(struct ofp_header) + payload,
821 OFPT_ECHO_REQUEST, &request);
822 random_bytes(rq_hdr + 1, payload);
824 gettimeofday(&start, NULL);
825 run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
826 gettimeofday(&end, NULL);
828 rpy_hdr = reply->data;
829 if (reply->size != request->size
830 || memcmp(rpy_hdr + 1, rq_hdr + 1, payload)
831 || rpy_hdr->xid != rq_hdr->xid
832 || rpy_hdr->type != OFPT_ECHO_REPLY) {
833 printf("Reply does not match request. Request:\n");
834 ofp_print(stdout, request, request->size, 2);
836 ofp_print(stdout, reply, reply->size, 2);
838 printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
839 reply->size - sizeof *rpy_hdr, argv[1], rpy_hdr->xid,
840 (1000*(double)(end.tv_sec - start.tv_sec))
841 + (.001*(end.tv_usec - start.tv_usec)));
842 ofpbuf_delete(request);
843 ofpbuf_delete(reply);
849 do_benchmark(int argc OVS_UNUSED, char *argv[])
851 size_t max_payload = 65535 - sizeof(struct ofp_header);
852 struct timeval start, end;
853 unsigned int payload_size, message_size;
859 payload_size = atoi(argv[2]);
860 if (payload_size > max_payload) {
861 ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
863 message_size = sizeof(struct ofp_header) + payload_size;
865 count = atoi(argv[3]);
867 printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
868 count, message_size, count * message_size);
870 open_vconn(argv[1], &vconn);
871 gettimeofday(&start, NULL);
872 for (i = 0; i < count; i++) {
873 struct ofpbuf *request, *reply;
874 struct ofp_header *rq_hdr;
876 rq_hdr = make_openflow(message_size, OFPT_ECHO_REQUEST, &request);
877 memset(rq_hdr + 1, 0, payload_size);
878 run(vconn_transact(vconn, request, &reply), "transact");
879 ofpbuf_delete(reply);
881 gettimeofday(&end, NULL);
884 duration = ((1000*(double)(end.tv_sec - start.tv_sec))
885 + (.001*(end.tv_usec - start.tv_usec)));
886 printf("Finished in %.1f ms (%.0f packets/s) (%.0f bytes/s)\n",
887 duration, count / (duration / 1000.0),
888 count * message_size / (duration / 1000.0));
891 /* This command is really only useful for testing the flow parser (ofp_parse),
892 * so it is undocumented. */
894 do_parse_flows(int argc OVS_UNUSED, char *argv[])
900 file = fopen(argv[1], "r");
902 ovs_fatal(errno, "%s: open", argv[2]);
905 while ((b = parse_ofp_add_flow_file(file, &table_idx)) != NULL) {
906 ofp_print(stdout, b->data, b->size, 0);
913 do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
918 static const struct command all_commands[] = {
919 { "show", 1, 1, do_show },
920 { "status", 1, 2, do_status },
921 { "monitor", 1, 2, do_monitor },
922 { "snoop", 1, 1, do_snoop },
923 { "dump-desc", 1, 1, do_dump_desc },
924 { "dump-tables", 1, 1, do_dump_tables },
925 { "dump-flows", 1, 2, do_dump_flows },
926 { "dump-aggregate", 1, 2, do_dump_aggregate },
927 { "queue-stats", 1, 3, do_queue_stats },
928 { "add-flow", 2, 2, do_add_flow },
929 { "add-flows", 2, 2, do_add_flows },
930 { "mod-flows", 2, 2, do_mod_flows },
931 { "del-flows", 1, 2, do_del_flows },
932 { "tun-cookie", 2, 2, do_tun_cookie },
933 { "dump-ports", 1, 2, do_dump_ports },
934 { "mod-port", 3, 3, do_mod_port },
935 { "probe", 1, 1, do_probe },
936 { "ping", 1, 2, do_ping },
937 { "benchmark", 3, 3, do_benchmark },
938 { "parse-flows", 1, 1, do_parse_flows },
939 { "help", 0, INT_MAX, do_help },
940 { NULL, 0, 0, NULL },