Expose device IP addresses through netdev.
[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               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, "flood")) {
505         port = OFPP_FLOOD;
506     } else if (!strcasecmp(str, "controller")) {
507         port = OFPP_CONTROLLER;
508     } else {
509         port = str_to_int(str);
510     }
511
512     memset(action, 0, sizeof *action);
513     action->type = OFPAT_OUTPUT;
514     action->arg.output.port = htons(port);
515 }
516
517 static void
518 str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
519             uint8_t *table_idx, uint16_t *priority)
520 {
521     struct field {
522         const char *name;
523         uint32_t wildcard;
524         enum { F_U8, F_U16, F_MAC, F_IP } type;
525         size_t offset;
526     };
527
528 #define F_OFS(MEMBER) offsetof(struct ofp_match, MEMBER)
529     static const struct field fields[] = { 
530         { "in_port", OFPFW_IN_PORT, F_U16, F_OFS(in_port) },
531         { "dl_vlan", OFPFW_DL_VLAN, F_U16, F_OFS(dl_vlan) },
532         { "dl_src", OFPFW_DL_SRC, F_MAC, F_OFS(dl_src) },
533         { "dl_dst", OFPFW_DL_DST, F_MAC, F_OFS(dl_dst) },
534         { "dl_type", OFPFW_DL_TYPE, F_U16, F_OFS(dl_type) },
535         { "nw_src", OFPFW_NW_SRC, F_IP, F_OFS(nw_src) },
536         { "nw_dst", OFPFW_NW_DST, F_IP, F_OFS(nw_dst) },
537         { "nw_proto", OFPFW_NW_PROTO, F_U8, F_OFS(nw_proto) },
538         { "tp_src", OFPFW_TP_SRC, F_U16, F_OFS(tp_src) },
539         { "tp_dst", OFPFW_TP_DST, F_U16, F_OFS(tp_dst) },
540     };
541
542     char *name, *value;
543     uint32_t wildcards;
544     bool got_action = false;
545
546     if (table_idx) {
547         *table_idx = 0xff;
548     }
549     if (priority) {
550         *priority = OFP_DEFAULT_PRIORITY;
551     }
552     memset(match, 0, sizeof *match);
553     wildcards = OFPFW_ALL;
554     for (name = strtok(string, "="), value = strtok(NULL, " \t\n");
555          name && value;
556          name = strtok(NULL, "="), value = strtok(NULL, " \t\n"))
557     {
558         const struct field *f;
559         void *data;
560
561         if (action && !strcmp(name, "action")) {
562             got_action = true;
563             str_to_action(value, action);
564             continue;
565         }
566
567         if (table_idx && !strcmp(name, "table")) {
568             *table_idx = atoi(value);
569             continue;
570         }
571
572         if (priority && !strcmp(name, "priority")) {
573             *priority = atoi(value);
574             continue;
575         }
576
577         for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
578             if (!strcmp(f->name, name)) {
579                 goto found;
580             }
581         }
582         fprintf(stderr, "%s: unknown field %s (fields are",
583                 program_name, name);
584         for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
585             if (f != fields) {
586                 putc(',', stderr);
587             }
588             fprintf(stderr, " %s", f->name);
589         }
590         fprintf(stderr, ")\n");
591         exit(1);
592
593     found:
594         data = (char *) match + f->offset;
595         if (!strcmp(value, "*")) {
596             wildcards |= f->wildcard;
597         } else {
598             wildcards &= ~f->wildcard;
599             if (f->type == F_U8) {
600                 *(uint8_t *) data = str_to_int(value);
601             } else if (f->type == F_U16) {
602                 *(uint16_t *) data = htons(str_to_int(value));
603             } else if (f->type == F_MAC) {
604                 str_to_mac(value, data);
605             } else if (f->type == F_IP) {
606                 str_to_ip(value, data);
607             } else {
608                 NOT_REACHED();
609             }
610         }
611     }
612     if (name && !value) {
613         fatal(0, "field %s missing value", name);
614     }
615     if (action && !got_action) {
616         fatal(0, "must specify an action");
617     }
618     match->wildcards = htons(wildcards);
619 }
620
621 static void do_dump_flows(int argc, char *argv[])
622 {
623     struct ofp_flow_stats_request *req;
624     struct buffer *request;
625
626     req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
627     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id, 
628             NULL);
629     memset(req->pad, 0, sizeof req->pad);
630
631     dump_stats_transaction(argv[1], request);
632 }
633
634 static void do_dump_aggregate(int argc, char *argv[])
635 {
636     struct ofp_aggregate_stats_request *req;
637     struct buffer *request;
638
639     req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
640     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id,
641                 NULL);
642     memset(req->pad, 0, sizeof req->pad);
643
644     dump_stats_transaction(argv[1], request);
645 }
646
647 static void do_add_flows(int argc, char *argv[])
648 {
649     struct vconn *vconn;
650
651     FILE *file;
652     char line[1024];
653
654     file = fopen(argv[2], "r");
655     if (file == NULL) {
656         fatal(errno, "%s: open", argv[2]);
657     }
658
659     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
660     while (fgets(line, sizeof line, file)) {
661         struct buffer *buffer;
662         struct ofp_flow_mod *ofm;
663         uint16_t priority;
664         size_t size;
665
666         char *comment;
667
668         /* Delete comments. */
669         comment = strchr(line, '#');
670         if (comment) {
671             *comment = '\0';
672         }
673
674         /* Drop empty lines. */
675         if (line[strspn(line, " \t\n")] == '\0') {
676             continue;
677         }
678
679         /* Parse and send. */
680         size = sizeof *ofm + sizeof ofm->actions[0];
681         ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
682         str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority);
683         ofm->command = htons(OFPFC_ADD);
684         ofm->max_idle = htons(50);
685         ofm->buffer_id = htonl(UINT32_MAX);
686         ofm->priority = htons(priority);
687         ofm->reserved = htonl(0);
688
689         send_openflow_buffer(vconn, buffer);
690     }
691     vconn_close(vconn);
692     fclose(file);
693 }
694
695 static void do_del_flows(int argc, char *argv[])
696 {
697     struct vconn *vconn;
698
699     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
700     struct buffer *buffer;
701     struct ofp_flow_mod *ofm;
702     size_t size;
703
704
705     /* Parse and send. */
706     size = sizeof *ofm;
707     ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
708     ofm->command = htons(OFPFC_DELETE);
709     ofm->max_idle = htons(0);
710     ofm->buffer_id = htonl(UINT32_MAX);
711     ofm->priority = htons(0);
712     ofm->reserved = htonl(0);
713     str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, NULL);
714
715     send_openflow_buffer(vconn, buffer);
716
717     vconn_close(vconn);
718 }
719
720 static void
721 do_dump_ports(int argc, char *argv[])
722 {
723     dump_trivial_stats_transaction(argv[1], OFPST_PORT);
724 }
725
726 static void do_help(int argc UNUSED, char *argv[] UNUSED)
727 {
728     usage();
729 }
730
731 static struct command all_commands[] = {
732 #ifdef HAVE_NETLINK
733     { "adddp", 1, 1, do_add_dp },
734     { "deldp", 1, 1, do_del_dp },
735     { "addif", 2, 2, do_add_port },
736     { "delif", 2, 2, do_del_port },
737     { "benchmark-nl", 3, 3, do_benchmark_nl },
738 #endif
739
740     { "show", 1, 1, do_show },
741
742     { "help", 0, INT_MAX, do_help },
743     { "monitor", 1, 1, do_monitor },
744     { "dump-tables", 1, 1, do_dump_tables },
745     { "dump-flows", 1, 2, do_dump_flows },
746     { "dump-aggregate", 1, 2, do_dump_aggregate },
747     { "add-flows", 2, 2, do_add_flows },
748     { "del-flows", 1, 2, do_del_flows },
749     { "dump-ports", 1, 1, do_dump_ports },
750     { NULL, 0, 0, NULL },
751 };