c0f40587eab0447a0bf2a6ce8edd825eed683075
[openvswitch] / 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               set maximum verbosity level\n"
183            "  -h, --help                  display this help message\n"
184            "  -V, --version               display version information\n");
185     exit(EXIT_SUCCESS);
186 }
187
188 static void run(int retval, const char *message, ...)
189     PRINTF_FORMAT(2, 3);
190
191 static void run(int retval, const char *message, ...)
192 {
193     if (retval) {
194         va_list args;
195
196         fprintf(stderr, "%s: ", program_name);
197         va_start(args, message);
198         vfprintf(stderr, message, args);
199         va_end(args);
200         if (retval == EOF) {
201             fputs(": unexpected end of file\n", stderr);
202         } else {
203             fprintf(stderr, ": %s\n", strerror(retval));
204         }
205
206         exit(EXIT_FAILURE);
207     }
208 }
209 \f
210 #ifdef HAVE_NETLINK
211 /* Netlink-only commands. */
212
213 static int  if_up(const char* intf)
214 {
215     char command[256];
216     snprintf(command, sizeof command, "%s %s up &> /dev/null",
217             ifconfigbin, intf);
218     return system(command);
219 }
220
221 static void open_nl_vconn(const char *name, bool subscribe, struct dpif *dpif)
222 {
223     if (strncmp(name, "nl:", 3)
224         || strlen(name) < 4
225         || name[strspn(name + 3, "0123456789") + 3]) {
226         fatal(0, "%s: argument is not of the form \"nl:DP_ID\"", name);
227     }
228     run(dpif_open(atoi(name + 3), subscribe, dpif), "opening datapath");
229 }
230
231 static void do_add_dp(int argc UNUSED, char *argv[])
232 {
233     struct dpif dp;
234     open_nl_vconn(argv[1], false, &dp);
235     run(dpif_add_dp(&dp), "add_dp");
236     dpif_close(&dp);
237 }
238
239 static void do_del_dp(int argc UNUSED, char *argv[])
240 {
241     struct dpif dp;
242     open_nl_vconn(argv[1], false, &dp);
243     run(dpif_del_dp(&dp), "del_dp");
244     dpif_close(&dp);
245 }
246
247 static void do_add_port(int argc UNUSED, char *argv[])
248 {
249     struct dpif dp;
250     if_up(argv[2]);
251     open_nl_vconn(argv[1], false, &dp);
252     run(dpif_add_port(&dp, argv[2]), "add_port");
253     dpif_close(&dp);
254 }
255
256 static void do_del_port(int argc UNUSED, char *argv[])
257 {
258     struct dpif dp;
259     open_nl_vconn(argv[1], false, &dp);
260     run(dpif_del_port(&dp, argv[2]), "del_port");
261     dpif_close(&dp);
262 }
263
264 static void do_monitor(int argc UNUSED, char *argv[])
265 {
266     struct dpif dp;
267     open_nl_vconn(argv[1], true, &dp);
268     for (;;) {
269         struct buffer *b;
270         run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
271         ofp_print(stderr, b->data, b->size, 2);
272         buffer_delete(b);
273     }
274 }
275
276 #define BENCHMARK_INCR   100
277
278 static void do_benchmark_nl(int argc UNUSED, char *argv[])
279 {
280     struct dpif dp;
281     uint32_t num_packets, i, milestone;
282     struct timeval start, end;
283
284     open_nl_vconn(argv[1], false, &dp);
285     num_packets = atoi(argv[2]);
286     milestone = BENCHMARK_INCR;
287     run(dpif_benchmark_nl(&dp, num_packets, atoi(argv[3])), "benchmark_nl");
288     if (gettimeofday(&start, NULL) == -1) {
289         run(errno, "gettimeofday");
290     }
291     for (i = 0; i < num_packets;i++) {
292         struct buffer *b;
293         run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
294         if (i == milestone) {
295             gettimeofday(&end, NULL);
296             printf("%u packets received in %f ms\n",
297                    BENCHMARK_INCR,
298                    (1000*(double)(end.tv_sec - start.tv_sec))
299                    + (.001*(end.tv_usec - start.tv_usec)));
300             milestone += BENCHMARK_INCR;
301             start = end;
302         }
303         buffer_delete(b);
304     }
305     gettimeofday(&end, NULL);
306     printf("%u packets received in %f ms\n",
307            i - (milestone - BENCHMARK_INCR),
308            (1000*(double)(end.tv_sec - start.tv_sec))
309            + (.001*(end.tv_usec - start.tv_usec)));
310
311     dpif_close(&dp);
312 }
313 #endif /* HAVE_NETLINK */
314 \f
315 /* Generic commands. */
316
317 static uint32_t
318 random_xid(void)
319 {
320     static bool inited = false;
321     if (!inited) {
322         struct timeval tv;
323         inited = true;
324         if (gettimeofday(&tv, NULL) < 0) {
325             fatal(errno, "gettimeofday");
326         }
327         srand(tv.tv_sec ^ tv.tv_usec);
328     }
329     return rand();
330 }
331
332 static void *
333 alloc_openflow_buffer(size_t openflow_len, uint8_t type,
334                       struct buffer **bufferp)
335 {
336         struct buffer *buffer;
337         struct ofp_header *oh;
338
339         buffer = *bufferp = buffer_new(openflow_len);
340         oh = buffer_put_uninit(buffer, openflow_len);
341     memset(oh, 0, openflow_len);
342         oh->version = OFP_VERSION;
343         oh->type = type;
344         oh->length = 0;
345         oh->xid = random_xid();
346         return oh;
347 }
348
349 static void *
350 alloc_stats_request(size_t body_len, uint16_t type, struct buffer **bufferp)
351 {
352     struct ofp_stats_request *rq;
353     rq = alloc_openflow_buffer((offsetof(struct ofp_stats_request, body)
354                                 + body_len), OFPT_STATS_REQUEST, bufferp);
355     rq->type = htons(type);
356     rq->flags = htons(0);
357     return rq->body;
358 }
359
360 static void
361 send_openflow_buffer(struct vconn *vconn, struct buffer *buffer)
362 {
363     struct ofp_header *oh;
364
365     oh = buffer_at_assert(buffer, 0, sizeof *oh);
366     oh->length = htons(buffer->size);
367
368     run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
369 }
370
371 static struct buffer *
372 transact_openflow(struct vconn *vconn, struct buffer *request)
373 {
374     uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
375
376     send_openflow_buffer(vconn, request);
377     for (;;) {
378         uint32_t recv_xid;
379         struct buffer *reply;
380
381         run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
382         recv_xid = ((struct ofp_header *) reply->data)->xid;
383         if (send_xid == recv_xid) {
384             return reply;
385         }
386
387         VLOG_DBG("received reply with xid %08"PRIx32" != expected %08"PRIx32,
388                  recv_xid, send_xid);
389         buffer_delete(reply);
390     }
391 }
392
393 static void
394 dump_transaction(const char *vconn_name, struct buffer *request)
395 {
396     struct vconn *vconn;
397     struct buffer *reply;
398
399     run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
400     reply = transact_openflow(vconn, request);
401     ofp_print(stdout, reply->data, reply->size, 1);
402     vconn_close(vconn);
403 }
404
405 static void
406 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
407 {
408     struct buffer *request;
409     alloc_openflow_buffer(sizeof(struct ofp_header), request_type, &request);
410     dump_transaction(vconn_name, request);
411 }
412
413 static void
414 dump_stats_transaction(const char *vconn_name, struct buffer *request)
415 {
416     uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
417     struct vconn *vconn;
418     bool done = false;
419
420     run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
421     send_openflow_buffer(vconn, request);
422     while (!done) {
423         uint32_t recv_xid;
424         struct buffer *reply;
425
426         run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
427         recv_xid = ((struct ofp_header *) reply->data)->xid;
428         if (send_xid == recv_xid) {
429             struct ofp_stats_reply *osr;
430
431             ofp_print(stdout, reply->data, reply->size, 1);
432
433             osr = buffer_at(reply, 0, sizeof *osr);
434             done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
435         } else {
436             VLOG_DBG("received reply with xid %08"PRIx32" "
437                      "!= expected %08"PRIx32, recv_xid, send_xid);
438         }
439         buffer_delete(reply);
440     }
441     vconn_close(vconn);
442 }
443
444 static void
445 dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
446 {
447     struct buffer *request;
448     alloc_stats_request(0, stats_type, &request);
449     dump_stats_transaction(vconn_name, request);
450 }
451
452 static void
453 do_show(int argc UNUSED, char *argv[])
454 {
455     dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
456     dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
457 }
458
459
460 static void
461 do_dump_tables(int argc, char *argv[])
462 {
463     dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
464 }
465
466
467 static uint32_t
468 str_to_int(const char *str) 
469 {
470     uint32_t value;
471     if (sscanf(str, "%"SCNu32, &value) != 1) {
472         fatal(0, "invalid numeric format %s", str);
473     }
474     return value;
475 }
476
477 static void
478 str_to_mac(const char *str, uint8_t mac[6]) 
479 {
480     if (sscanf(str, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
481                &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6) {
482         fatal(0, "invalid mac address %s", str);
483     }
484 }
485
486 static void
487 str_to_ip(const char *str, uint32_t *ip) 
488 {
489     struct in_addr in_addr;
490     int retval;
491
492     retval = lookup_ip(str, &in_addr);
493     if (retval) {
494         fatal(0, "%s: could not convert to IP address", str);
495     }
496     *ip = in_addr.s_addr;
497 }
498
499 static void
500 str_to_action(const char *str, struct ofp_action *action) 
501 {
502     uint16_t port;
503
504     if (!strcasecmp(str, "normal")) {
505         port = OFPP_NORMAL;
506     } else if (!strcasecmp(str, "flood")) {
507         port = OFPP_FLOOD;
508     } else if (!strcasecmp(str, "all")) {
509         port = OFPP_ALL;
510     } else if (!strcasecmp(str, "controller")) {
511         port = OFPP_CONTROLLER;
512     } else if (!strcasecmp(str, "local")) {
513         port = OFPP_LOCAL;
514     } else {
515         port = str_to_int(str);
516     }
517
518     memset(action, 0, sizeof *action);
519     action->type = OFPAT_OUTPUT;
520     action->arg.output.port = htons(port);
521 }
522
523 static void
524 str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
525             uint8_t *table_idx, uint16_t *priority)
526 {
527     struct field {
528         const char *name;
529         uint32_t wildcard;
530         enum { F_U8, F_U16, F_MAC, F_IP } type;
531         size_t offset;
532     };
533
534 #define F_OFS(MEMBER) offsetof(struct ofp_match, MEMBER)
535     static const struct field fields[] = { 
536         { "in_port", OFPFW_IN_PORT, F_U16, F_OFS(in_port) },
537         { "dl_vlan", OFPFW_DL_VLAN, F_U16, F_OFS(dl_vlan) },
538         { "dl_src", OFPFW_DL_SRC, F_MAC, F_OFS(dl_src) },
539         { "dl_dst", OFPFW_DL_DST, F_MAC, F_OFS(dl_dst) },
540         { "dl_type", OFPFW_DL_TYPE, F_U16, F_OFS(dl_type) },
541         { "nw_src", OFPFW_NW_SRC, F_IP, F_OFS(nw_src) },
542         { "nw_dst", OFPFW_NW_DST, F_IP, F_OFS(nw_dst) },
543         { "nw_proto", OFPFW_NW_PROTO, F_U8, F_OFS(nw_proto) },
544         { "tp_src", OFPFW_TP_SRC, F_U16, F_OFS(tp_src) },
545         { "tp_dst", OFPFW_TP_DST, F_U16, F_OFS(tp_dst) },
546     };
547
548     char *name, *value;
549     uint32_t wildcards;
550     bool got_action = false;
551
552     if (table_idx) {
553         *table_idx = 0xff;
554     }
555     if (priority) {
556         *priority = OFP_DEFAULT_PRIORITY;
557     }
558     memset(match, 0, sizeof *match);
559     wildcards = OFPFW_ALL;
560     for (name = strtok(string, "="), value = strtok(NULL, ", \t\r\n");
561          name && value;
562          name = strtok(NULL, "="), value = strtok(NULL, ", \t\r\n"))
563     {
564         const struct field *f;
565         void *data;
566
567         if (action && !strcmp(name, "action")) {
568             got_action = true;
569             str_to_action(value, action);
570             continue;
571         }
572
573         if (table_idx && !strcmp(name, "table")) {
574             *table_idx = atoi(value);
575             continue;
576         }
577
578         if (priority && !strcmp(name, "priority")) {
579             *priority = atoi(value);
580             continue;
581         }
582
583         for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
584             if (!strcmp(f->name, name)) {
585                 goto found;
586             }
587         }
588         fprintf(stderr, "%s: unknown field %s (fields are",
589                 program_name, name);
590         for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
591             if (f != fields) {
592                 putc(',', stderr);
593             }
594             fprintf(stderr, " %s", f->name);
595         }
596         fprintf(stderr, ")\n");
597         exit(1);
598
599     found:
600         data = (char *) match + f->offset;
601         if (!strcmp(value, "*") || !strcmp(value, "ANY")) {
602             wildcards |= f->wildcard;
603         } else {
604             wildcards &= ~f->wildcard;
605             if (f->type == F_U8) {
606                 *(uint8_t *) data = str_to_int(value);
607             } else if (f->type == F_U16) {
608                 *(uint16_t *) data = htons(str_to_int(value));
609             } else if (f->type == F_MAC) {
610                 str_to_mac(value, data);
611             } else if (f->type == F_IP) {
612                 str_to_ip(value, data);
613             } else {
614                 NOT_REACHED();
615             }
616         }
617     }
618     if (name && !value) {
619         fatal(0, "field %s missing value", name);
620     }
621     if (action && !got_action) {
622         fatal(0, "must specify an action");
623     }
624     match->wildcards = htons(wildcards);
625 }
626
627 static void do_dump_flows(int argc, char *argv[])
628 {
629     struct ofp_flow_stats_request *req;
630     struct buffer *request;
631
632     req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
633     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id, 
634             NULL);
635     memset(req->pad, 0, sizeof req->pad);
636
637     dump_stats_transaction(argv[1], request);
638 }
639
640 static void do_dump_aggregate(int argc, char *argv[])
641 {
642     struct ofp_aggregate_stats_request *req;
643     struct buffer *request;
644
645     req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
646     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id,
647                 NULL);
648     memset(req->pad, 0, sizeof req->pad);
649
650     dump_stats_transaction(argv[1], request);
651 }
652
653 static void do_add_flows(int argc, char *argv[])
654 {
655     struct vconn *vconn;
656
657     FILE *file;
658     char line[1024];
659
660     file = fopen(argv[2], "r");
661     if (file == NULL) {
662         fatal(errno, "%s: open", argv[2]);
663     }
664
665     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
666     while (fgets(line, sizeof line, file)) {
667         struct buffer *buffer;
668         struct ofp_flow_mod *ofm;
669         uint16_t priority;
670         size_t size;
671
672         char *comment;
673
674         /* Delete comments. */
675         comment = strchr(line, '#');
676         if (comment) {
677             *comment = '\0';
678         }
679
680         /* Drop empty lines. */
681         if (line[strspn(line, " \t\n")] == '\0') {
682             continue;
683         }
684
685         /* Parse and send. */
686         size = sizeof *ofm + sizeof ofm->actions[0];
687         ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
688         str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority);
689         ofm->command = htons(OFPFC_ADD);
690         ofm->max_idle = htons(50);
691         ofm->buffer_id = htonl(UINT32_MAX);
692         ofm->priority = htons(priority);
693         ofm->reserved = htonl(0);
694
695         send_openflow_buffer(vconn, buffer);
696     }
697     vconn_close(vconn);
698     fclose(file);
699 }
700
701 static void do_del_flows(int argc, char *argv[])
702 {
703     struct vconn *vconn;
704     uint16_t priority;
705
706     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
707     struct buffer *buffer;
708     struct ofp_flow_mod *ofm;
709     size_t size;
710
711
712     /* Parse and send. */
713     size = sizeof *ofm;
714     ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
715     str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, &priority);
716     ofm->command = htons(OFPFC_DELETE);
717     ofm->max_idle = htons(0);
718     ofm->buffer_id = htonl(UINT32_MAX);
719     ofm->priority = htons(priority);
720     ofm->reserved = htonl(0);
721
722     send_openflow_buffer(vconn, buffer);
723
724     vconn_close(vconn);
725 }
726
727 static void
728 do_dump_ports(int argc, char *argv[])
729 {
730     dump_trivial_stats_transaction(argv[1], OFPST_PORT);
731 }
732
733 static void do_help(int argc UNUSED, char *argv[] UNUSED)
734 {
735     usage();
736 }
737
738 static struct command all_commands[] = {
739 #ifdef HAVE_NETLINK
740     { "adddp", 1, 1, do_add_dp },
741     { "deldp", 1, 1, do_del_dp },
742     { "addif", 2, 2, do_add_port },
743     { "delif", 2, 2, do_del_port },
744     { "benchmark-nl", 3, 3, do_benchmark_nl },
745 #endif
746
747     { "show", 1, 1, do_show },
748
749     { "help", 0, INT_MAX, do_help },
750     { "monitor", 1, 1, do_monitor },
751     { "dump-tables", 1, 1, do_dump_tables },
752     { "dump-flows", 1, 2, do_dump_flows },
753     { "dump-aggregate", 1, 2, do_dump_aggregate },
754     { "add-flows", 2, 2, do_add_flows },
755     { "del-flows", 1, 2, do_del_flows },
756     { "dump-ports", 1, 1, do_dump_ports },
757     { NULL, 0, 0, NULL },
758 };