Bring manpages and usage messages up-to-date.
[sliver-openvswitch.git] / utilities / dpctl.c
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  * 
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  * 
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  * 
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #include <errno.h>
35 #include <getopt.h>
36 #include <inttypes.h>
37 #include <netinet/in.h>
38 #include <stdarg.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
42 #include <sys/time.h>
43
44 #include "command-line.h"
45 #include "compiler.h"
46 #include "buffer.h"
47 #include "dpif.h"
48 #ifdef HAVE_NETLINK
49 #include "netlink.h"
50 #include "openflow-netlink.h"
51 #endif
52 #include "util.h"
53 #include "socket-util.h"
54 #include "openflow.h"
55 #include "ofp-print.h"
56 #include "vconn.h"
57 #include "vconn-ssl.h"
58
59 #include "vlog.h"
60 #define THIS_MODULE VLM_dpctl
61
62 static const char* ifconfigbin = "/sbin/ifconfig";
63
64 struct command {
65     const char *name;
66     int min_args;
67     int max_args;
68     void (*handler)(int argc, char *argv[]);
69 };
70
71 static struct command all_commands[];
72
73 static void usage(void) NO_RETURN;
74 static void parse_options(int argc, char *argv[]);
75
76 int main(int argc, char *argv[])
77 {
78     struct command *p;
79
80     set_program_name(argv[0]);
81     vlog_init();
82     parse_options(argc, argv);
83
84     argc -= optind;
85     argv += optind;
86     if (argc < 1)
87         fatal(0, "missing command name; use --help for help");
88
89     for (p = all_commands; p->name != NULL; p++) {
90         if (!strcmp(p->name, argv[0])) {
91             int n_arg = argc - 1;
92             if (n_arg < p->min_args)
93                 fatal(0, "'%s' command requires at least %d arguments",
94                       p->name, p->min_args);
95             else if (n_arg > p->max_args)
96                 fatal(0, "'%s' command takes at most %d arguments",
97                       p->name, p->max_args);
98             else {
99                 p->handler(argc, argv);
100                 exit(0);
101             }
102         }
103     }
104     fatal(0, "unknown command '%s'; use --help for help", argv[0]);
105
106     return 0;
107 }
108
109 static void
110 parse_options(int argc, char *argv[])
111 {
112     static struct option long_options[] = {
113         {"verbose", optional_argument, 0, 'v'},
114         {"help", no_argument, 0, 'h'},
115         {"version", no_argument, 0, 'V'},
116         VCONN_SSL_LONG_OPTIONS
117         {0, 0, 0, 0},
118     };
119     char *short_options = long_options_to_short_options(long_options);
120
121     for (;;) {
122         int indexptr;
123         int c;
124
125         c = getopt_long(argc, argv, short_options, long_options, &indexptr);
126         if (c == -1) {
127             break;
128         }
129
130         switch (c) {
131         case 'h':
132             usage();
133
134         case 'V':
135             printf("%s "VERSION" compiled "__DATE__" "__TIME__"\n", argv[0]);
136             exit(EXIT_SUCCESS);
137
138         case 'v':
139             vlog_set_verbosity(optarg);
140             break;
141
142         VCONN_SSL_OPTION_HANDLERS
143
144         case '?':
145             exit(EXIT_FAILURE);
146
147         default:
148             abort();
149         }
150     }
151     free(short_options);
152 }
153
154 static void
155 usage(void)
156 {
157     printf("%s: OpenFlow switch management utility\n"
158            "usage: %s [OPTIONS] COMMAND [ARG...]\n"
159 #ifdef HAVE_NETLINK
160            "\nCommands that apply to local datapaths only:\n"
161            "  adddp nl:DP_ID              add a new local datapath DP_ID\n"
162            "  deldp nl:DP_ID              delete local datapath DP_ID\n"
163            "  addif nl:DP_ID IFACE        add IFACE as a port on DP_ID\n"
164            "  delif nl:DP_ID IFACE        delete IFACE as a port on DP_ID\n"
165            "  monitor nl:DP_ID            print packets received\n"
166            "  benchmark-nl nl:DP_ID N SIZE   send N packets of SIZE bytes\n"
167 #endif
168            "\nCommands that apply to local datapaths and remote switches:\n"
169            "  show SWITCH                 show information\n"
170            "  dump-tables SWITCH          print table stats\n"
171            "  dump-ports SWITCH           print port statistics\n"
172            "  dump-flows SWITCH           print all flow entries\n"
173            "  dump-flows SWITCH FLOW      print matching FLOWs\n"
174            "  dump-aggregate SWITCH       print aggregate flow statistics\n"
175            "  dump-aggregate SWITCH FLOW  print aggregate stats for FLOWs\n"
176            "  add-flows SWITCH FILE       add flows from FILE\n"
177            "  del-flows SWITCH FLOW       delete matching FLOWs\n"
178            "where each SWITCH is an active OpenFlow connection method.\n",
179            program_name, program_name);
180     vconn_usage(true, false);
181     printf("\nOptions:\n"
182            "  -v, --verbose=MODULE:FACILITY:LEVEL  configure logging levels\n"
183            "  -v, --verbose               set maximum verbosity level\n"
184            "  -h, --help                  display this help message\n"
185            "  -V, --version               display version information\n");
186     exit(EXIT_SUCCESS);
187 }
188
189 static void run(int retval, const char *message, ...)
190     PRINTF_FORMAT(2, 3);
191
192 static void run(int retval, const char *message, ...)
193 {
194     if (retval) {
195         va_list args;
196
197         fprintf(stderr, "%s: ", program_name);
198         va_start(args, message);
199         vfprintf(stderr, message, args);
200         va_end(args);
201         if (retval == EOF) {
202             fputs(": unexpected end of file\n", stderr);
203         } else {
204             fprintf(stderr, ": %s\n", strerror(retval));
205         }
206
207         exit(EXIT_FAILURE);
208     }
209 }
210 \f
211 #ifdef HAVE_NETLINK
212 /* Netlink-only commands. */
213
214 static int  if_up(const char* intf)
215 {
216     char command[256];
217     snprintf(command, sizeof command, "%s %s up &> /dev/null",
218             ifconfigbin, intf);
219     return system(command);
220 }
221
222 static void open_nl_vconn(const char *name, bool subscribe, struct dpif *dpif)
223 {
224     if (strncmp(name, "nl:", 3)
225         || strlen(name) < 4
226         || name[strspn(name + 3, "0123456789") + 3]) {
227         fatal(0, "%s: argument is not of the form \"nl:DP_ID\"", name);
228     }
229     run(dpif_open(atoi(name + 3), subscribe, dpif), "opening datapath");
230 }
231
232 static void do_add_dp(int argc UNUSED, char *argv[])
233 {
234     struct dpif dp;
235     open_nl_vconn(argv[1], false, &dp);
236     run(dpif_add_dp(&dp), "add_dp");
237     dpif_close(&dp);
238 }
239
240 static void do_del_dp(int argc UNUSED, char *argv[])
241 {
242     struct dpif dp;
243     open_nl_vconn(argv[1], false, &dp);
244     run(dpif_del_dp(&dp), "del_dp");
245     dpif_close(&dp);
246 }
247
248 static void do_add_port(int argc UNUSED, char *argv[])
249 {
250     struct dpif dp;
251     if_up(argv[2]);
252     open_nl_vconn(argv[1], false, &dp);
253     run(dpif_add_port(&dp, argv[2]), "add_port");
254     dpif_close(&dp);
255 }
256
257 static void do_del_port(int argc UNUSED, char *argv[])
258 {
259     struct dpif dp;
260     open_nl_vconn(argv[1], false, &dp);
261     run(dpif_del_port(&dp, argv[2]), "del_port");
262     dpif_close(&dp);
263 }
264
265 static void do_monitor(int argc UNUSED, char *argv[])
266 {
267     struct dpif dp;
268     open_nl_vconn(argv[1], true, &dp);
269     for (;;) {
270         struct buffer *b;
271         run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
272         ofp_print(stderr, b->data, b->size, 2);
273         buffer_delete(b);
274     }
275 }
276
277 #define BENCHMARK_INCR   100
278
279 static void do_benchmark_nl(int argc UNUSED, char *argv[])
280 {
281     struct dpif dp;
282     uint32_t num_packets, i, milestone;
283     struct timeval start, end;
284
285     open_nl_vconn(argv[1], false, &dp);
286     num_packets = atoi(argv[2]);
287     milestone = BENCHMARK_INCR;
288     run(dpif_benchmark_nl(&dp, num_packets, atoi(argv[3])), "benchmark_nl");
289     if (gettimeofday(&start, NULL) == -1) {
290         run(errno, "gettimeofday");
291     }
292     for (i = 0; i < num_packets;i++) {
293         struct buffer *b;
294         run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
295         if (i == milestone) {
296             gettimeofday(&end, NULL);
297             printf("%u packets received in %f ms\n",
298                    BENCHMARK_INCR,
299                    (1000*(double)(end.tv_sec - start.tv_sec))
300                    + (.001*(end.tv_usec - start.tv_usec)));
301             milestone += BENCHMARK_INCR;
302             start = end;
303         }
304         buffer_delete(b);
305     }
306     gettimeofday(&end, NULL);
307     printf("%u packets received in %f ms\n",
308            i - (milestone - BENCHMARK_INCR),
309            (1000*(double)(end.tv_sec - start.tv_sec))
310            + (.001*(end.tv_usec - start.tv_usec)));
311
312     dpif_close(&dp);
313 }
314 #endif /* HAVE_NETLINK */
315 \f
316 /* Generic commands. */
317
318 static uint32_t
319 random_xid(void)
320 {
321     static bool inited = false;
322     if (!inited) {
323         struct timeval tv;
324         inited = true;
325         if (gettimeofday(&tv, NULL) < 0) {
326             fatal(errno, "gettimeofday");
327         }
328         srand(tv.tv_sec ^ tv.tv_usec);
329     }
330     return rand();
331 }
332
333 static void *
334 alloc_openflow_buffer(size_t openflow_len, uint8_t type,
335                       struct buffer **bufferp)
336 {
337         struct buffer *buffer;
338         struct ofp_header *oh;
339
340         buffer = *bufferp = buffer_new(openflow_len);
341         oh = buffer_put_uninit(buffer, openflow_len);
342     memset(oh, 0, openflow_len);
343         oh->version = OFP_VERSION;
344         oh->type = type;
345         oh->length = 0;
346         oh->xid = random_xid();
347         return oh;
348 }
349
350 static void *
351 alloc_stats_request(size_t body_len, uint16_t type, struct buffer **bufferp)
352 {
353     struct ofp_stats_request *rq;
354     rq = alloc_openflow_buffer((offsetof(struct ofp_stats_request, body)
355                                 + body_len), OFPT_STATS_REQUEST, bufferp);
356     rq->type = htons(type);
357     rq->flags = htons(0);
358     return rq->body;
359 }
360
361 static void
362 send_openflow_buffer(struct vconn *vconn, struct buffer *buffer)
363 {
364     struct ofp_header *oh;
365
366     oh = buffer_at_assert(buffer, 0, sizeof *oh);
367     oh->length = htons(buffer->size);
368
369     run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
370 }
371
372 static struct buffer *
373 transact_openflow(struct vconn *vconn, struct buffer *request)
374 {
375     uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
376
377     send_openflow_buffer(vconn, request);
378     for (;;) {
379         uint32_t recv_xid;
380         struct buffer *reply;
381
382         run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
383         recv_xid = ((struct ofp_header *) reply->data)->xid;
384         if (send_xid == recv_xid) {
385             return reply;
386         }
387
388         VLOG_DBG("received reply with xid %08"PRIx32" != expected %08"PRIx32,
389                  recv_xid, send_xid);
390         buffer_delete(reply);
391     }
392 }
393
394 static void
395 dump_transaction(const char *vconn_name, struct buffer *request)
396 {
397     struct vconn *vconn;
398     struct buffer *reply;
399
400     run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
401     reply = transact_openflow(vconn, request);
402     ofp_print(stdout, reply->data, reply->size, 1);
403     vconn_close(vconn);
404 }
405
406 static void
407 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
408 {
409     struct buffer *request;
410     alloc_openflow_buffer(sizeof(struct ofp_header), request_type, &request);
411     dump_transaction(vconn_name, request);
412 }
413
414 static void
415 dump_stats_transaction(const char *vconn_name, struct buffer *request)
416 {
417     uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
418     struct vconn *vconn;
419     bool done = false;
420
421     run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
422     send_openflow_buffer(vconn, request);
423     while (!done) {
424         uint32_t recv_xid;
425         struct buffer *reply;
426
427         run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
428         recv_xid = ((struct ofp_header *) reply->data)->xid;
429         if (send_xid == recv_xid) {
430             struct ofp_stats_reply *osr;
431
432             ofp_print(stdout, reply->data, reply->size, 1);
433
434             osr = buffer_at(reply, 0, sizeof *osr);
435             done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
436         } else {
437             VLOG_DBG("received reply with xid %08"PRIx32" "
438                      "!= expected %08"PRIx32, recv_xid, send_xid);
439         }
440         buffer_delete(reply);
441     }
442     vconn_close(vconn);
443 }
444
445 static void
446 dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
447 {
448     struct buffer *request;
449     alloc_stats_request(0, stats_type, &request);
450     dump_stats_transaction(vconn_name, request);
451 }
452
453 static void
454 do_show(int argc UNUSED, char *argv[])
455 {
456     dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
457     dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
458 }
459
460
461 static void
462 do_dump_tables(int argc, char *argv[])
463 {
464     dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
465 }
466
467
468 static uint32_t
469 str_to_int(const char *str) 
470 {
471     uint32_t value;
472     if (sscanf(str, "%"SCNu32, &value) != 1) {
473         fatal(0, "invalid numeric format %s", str);
474     }
475     return value;
476 }
477
478 static void
479 str_to_mac(const char *str, uint8_t mac[6]) 
480 {
481     if (sscanf(str, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
482                &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6) {
483         fatal(0, "invalid mac address %s", str);
484     }
485 }
486
487 static void
488 str_to_ip(const char *str, uint32_t *ip) 
489 {
490     struct in_addr in_addr;
491     int retval;
492
493     retval = lookup_ip(str, &in_addr);
494     if (retval) {
495         fatal(0, "%s: could not convert to IP address", str);
496     }
497     *ip = in_addr.s_addr;
498 }
499
500 static void
501 str_to_action(const char *str, struct ofp_action *action) 
502 {
503     uint16_t port;
504
505     if (!strcasecmp(str, "normal")) {
506         port = OFPP_NORMAL;
507     } else if (!strcasecmp(str, "flood")) {
508         port = OFPP_FLOOD;
509     } else if (!strcasecmp(str, "all")) {
510         port = OFPP_ALL;
511     } else if (!strcasecmp(str, "controller")) {
512         port = OFPP_CONTROLLER;
513     } else if (!strcasecmp(str, "local")) {
514         port = OFPP_LOCAL;
515     } else {
516         port = str_to_int(str);
517     }
518
519     memset(action, 0, sizeof *action);
520     action->type = OFPAT_OUTPUT;
521     action->arg.output.port = htons(port);
522 }
523
524 static void
525 str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
526             uint8_t *table_idx, uint16_t *priority)
527 {
528     struct field {
529         const char *name;
530         uint32_t wildcard;
531         enum { F_U8, F_U16, F_MAC, F_IP } type;
532         size_t offset;
533     };
534
535 #define F_OFS(MEMBER) offsetof(struct ofp_match, MEMBER)
536     static const struct field fields[] = { 
537         { "in_port", OFPFW_IN_PORT, F_U16, F_OFS(in_port) },
538         { "dl_vlan", OFPFW_DL_VLAN, F_U16, F_OFS(dl_vlan) },
539         { "dl_src", OFPFW_DL_SRC, F_MAC, F_OFS(dl_src) },
540         { "dl_dst", OFPFW_DL_DST, F_MAC, F_OFS(dl_dst) },
541         { "dl_type", OFPFW_DL_TYPE, F_U16, F_OFS(dl_type) },
542         { "nw_src", OFPFW_NW_SRC, F_IP, F_OFS(nw_src) },
543         { "nw_dst", OFPFW_NW_DST, F_IP, F_OFS(nw_dst) },
544         { "nw_proto", OFPFW_NW_PROTO, F_U8, F_OFS(nw_proto) },
545         { "tp_src", OFPFW_TP_SRC, F_U16, F_OFS(tp_src) },
546         { "tp_dst", OFPFW_TP_DST, F_U16, F_OFS(tp_dst) },
547     };
548
549     char *name, *value;
550     uint32_t wildcards;
551     bool got_action = false;
552
553     if (table_idx) {
554         *table_idx = 0xff;
555     }
556     if (priority) {
557         *priority = OFP_DEFAULT_PRIORITY;
558     }
559     memset(match, 0, sizeof *match);
560     wildcards = OFPFW_ALL;
561     for (name = strtok(string, "="), value = strtok(NULL, ", \t\r\n");
562          name && value;
563          name = strtok(NULL, "="), value = strtok(NULL, ", \t\r\n"))
564     {
565         const struct field *f;
566         void *data;
567
568         if (action && !strcmp(name, "action")) {
569             got_action = true;
570             str_to_action(value, action);
571             continue;
572         }
573
574         if (table_idx && !strcmp(name, "table")) {
575             *table_idx = atoi(value);
576             continue;
577         }
578
579         if (priority && !strcmp(name, "priority")) {
580             *priority = atoi(value);
581             continue;
582         }
583
584         for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
585             if (!strcmp(f->name, name)) {
586                 goto found;
587             }
588         }
589         fprintf(stderr, "%s: unknown field %s (fields are",
590                 program_name, name);
591         for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
592             if (f != fields) {
593                 putc(',', stderr);
594             }
595             fprintf(stderr, " %s", f->name);
596         }
597         fprintf(stderr, ")\n");
598         exit(1);
599
600     found:
601         data = (char *) match + f->offset;
602         if (!strcmp(value, "*") || !strcmp(value, "ANY")) {
603             wildcards |= f->wildcard;
604         } else {
605             wildcards &= ~f->wildcard;
606             if (f->type == F_U8) {
607                 *(uint8_t *) data = str_to_int(value);
608             } else if (f->type == F_U16) {
609                 *(uint16_t *) data = htons(str_to_int(value));
610             } else if (f->type == F_MAC) {
611                 str_to_mac(value, data);
612             } else if (f->type == F_IP) {
613                 str_to_ip(value, data);
614             } else {
615                 NOT_REACHED();
616             }
617         }
618     }
619     if (name && !value) {
620         fatal(0, "field %s missing value", name);
621     }
622     if (action && !got_action) {
623         fatal(0, "must specify an action");
624     }
625     match->wildcards = htons(wildcards);
626 }
627
628 static void do_dump_flows(int argc, char *argv[])
629 {
630     struct ofp_flow_stats_request *req;
631     struct buffer *request;
632
633     req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
634     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id, 
635             NULL);
636     memset(req->pad, 0, sizeof req->pad);
637
638     dump_stats_transaction(argv[1], request);
639 }
640
641 static void do_dump_aggregate(int argc, char *argv[])
642 {
643     struct ofp_aggregate_stats_request *req;
644     struct buffer *request;
645
646     req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
647     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id,
648                 NULL);
649     memset(req->pad, 0, sizeof req->pad);
650
651     dump_stats_transaction(argv[1], request);
652 }
653
654 static void do_add_flows(int argc, char *argv[])
655 {
656     struct vconn *vconn;
657
658     FILE *file;
659     char line[1024];
660
661     file = fopen(argv[2], "r");
662     if (file == NULL) {
663         fatal(errno, "%s: open", argv[2]);
664     }
665
666     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
667     while (fgets(line, sizeof line, file)) {
668         struct buffer *buffer;
669         struct ofp_flow_mod *ofm;
670         uint16_t priority;
671         size_t size;
672
673         char *comment;
674
675         /* Delete comments. */
676         comment = strchr(line, '#');
677         if (comment) {
678             *comment = '\0';
679         }
680
681         /* Drop empty lines. */
682         if (line[strspn(line, " \t\n")] == '\0') {
683             continue;
684         }
685
686         /* Parse and send. */
687         size = sizeof *ofm + sizeof ofm->actions[0];
688         ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
689         str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority);
690         ofm->command = htons(OFPFC_ADD);
691         ofm->max_idle = htons(50);
692         ofm->buffer_id = htonl(UINT32_MAX);
693         ofm->priority = htons(priority);
694         ofm->reserved = htonl(0);
695
696         send_openflow_buffer(vconn, buffer);
697     }
698     vconn_close(vconn);
699     fclose(file);
700 }
701
702 static void do_del_flows(int argc, char *argv[])
703 {
704     struct vconn *vconn;
705     uint16_t priority;
706
707     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
708     struct buffer *buffer;
709     struct ofp_flow_mod *ofm;
710     size_t size;
711
712
713     /* Parse and send. */
714     size = sizeof *ofm;
715     ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
716     str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, &priority);
717     ofm->command = htons(OFPFC_DELETE);
718     ofm->max_idle = htons(0);
719     ofm->buffer_id = htonl(UINT32_MAX);
720     ofm->priority = htons(priority);
721     ofm->reserved = htonl(0);
722
723     send_openflow_buffer(vconn, buffer);
724
725     vconn_close(vconn);
726 }
727
728 static void
729 do_dump_ports(int argc, char *argv[])
730 {
731     dump_trivial_stats_transaction(argv[1], OFPST_PORT);
732 }
733
734 static void do_help(int argc UNUSED, char *argv[] UNUSED)
735 {
736     usage();
737 }
738
739 static struct command all_commands[] = {
740 #ifdef HAVE_NETLINK
741     { "adddp", 1, 1, do_add_dp },
742     { "deldp", 1, 1, do_del_dp },
743     { "addif", 2, 2, do_add_port },
744     { "delif", 2, 2, do_del_port },
745     { "benchmark-nl", 3, 3, do_benchmark_nl },
746 #endif
747
748     { "show", 1, 1, do_show },
749
750     { "help", 0, INT_MAX, do_help },
751     { "monitor", 1, 1, do_monitor },
752     { "dump-tables", 1, 1, do_dump_tables },
753     { "dump-flows", 1, 2, do_dump_flows },
754     { "dump-aggregate", 1, 2, do_dump_aggregate },
755     { "add-flows", 2, 2, do_add_flows },
756     { "del-flows", 1, 2, do_del_flows },
757     { "dump-ports", 1, 1, do_dump_ports },
758     { NULL, 0, 0, NULL },
759 };