initscript: pass complete path to pidfile to status command
[sliver-openvswitch.git] / utilities / ovs-ofctl.c
1 /*
2  * Copyright (c) 2008, 2009 Nicira Networks.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <config.h>
18 #include <arpa/inet.h>
19 #include <errno.h>
20 #include <getopt.h>
21 #include <inttypes.h>
22 #include <net/if.h>
23 #include <netinet/in.h>
24 #include <signal.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <sys/stat.h>
30 #include <sys/time.h>
31
32 #include "command-line.h"
33 #include "compiler.h"
34 #include "dirs.h"
35 #include "dpif.h"
36 #include "dynamic-string.h"
37 #include "netdev.h"
38 #include "netlink.h"
39 #include "odp-util.h"
40 #include "ofp-print.h"
41 #include "ofpbuf.h"
42 #include "openflow/nicira-ext.h"
43 #include "openflow/openflow.h"
44 #include "packets.h"
45 #include "random.h"
46 #include "socket-util.h"
47 #include "timeval.h"
48 #include "util.h"
49 #include "vconn-ssl.h"
50 #include "vconn.h"
51
52 #include "vlog.h"
53 #define THIS_MODULE VLM_ofctl
54
55 #define DEFAULT_IDLE_TIMEOUT 60
56
57 #define MOD_PORT_CMD_UP      "up"
58 #define MOD_PORT_CMD_DOWN    "down"
59 #define MOD_PORT_CMD_FLOOD   "flood"
60 #define MOD_PORT_CMD_NOFLOOD "noflood"
61
62
63 /* Settings that may be configured by the user. */
64 struct settings {
65     bool strict;        /* Use strict matching for flow mod commands */
66 };
67
68 struct command {
69     const char *name;
70     int min_args;
71     int max_args;
72     void (*handler)(const struct settings *, int argc, char *argv[]);
73 };
74
75 static struct command all_commands[];
76
77 static void usage(void) NO_RETURN;
78 static void parse_options(int argc, char *argv[], struct settings *);
79
80 int main(int argc, char *argv[])
81 {
82     struct settings s;
83     struct command *p;
84
85     set_program_name(argv[0]);
86     time_init();
87     vlog_init();
88     parse_options(argc, argv, &s);
89     signal(SIGPIPE, SIG_IGN);
90
91     argc -= optind;
92     argv += optind;
93     if (argc < 1)
94         ovs_fatal(0, "missing command name; use --help for help");
95
96     for (p = all_commands; p->name != NULL; p++) {
97         if (!strcmp(p->name, argv[0])) {
98             int n_arg = argc - 1;
99             if (n_arg < p->min_args)
100                 ovs_fatal(0, "'%s' command requires at least %d arguments",
101                           p->name, p->min_args);
102             else if (n_arg > p->max_args)
103                 ovs_fatal(0, "'%s' command takes at most %d arguments",
104                           p->name, p->max_args);
105             else {
106                 p->handler(&s, argc, argv);
107                 if (ferror(stdout)) {
108                     ovs_fatal(0, "write to stdout failed");
109                 }
110                 if (ferror(stderr)) {
111                     ovs_fatal(0, "write to stderr failed");
112                 }
113                 exit(0);
114             }
115         }
116     }
117     ovs_fatal(0, "unknown command '%s'; use --help for help", argv[0]);
118
119     return 0;
120 }
121
122 static void
123 parse_options(int argc, char *argv[], struct settings *s)
124 {
125     enum {
126         OPT_STRICT = UCHAR_MAX + 1
127     };
128     static struct option long_options[] = {
129         {"timeout", required_argument, 0, 't'},
130         {"verbose", optional_argument, 0, 'v'},
131         {"strict", no_argument, 0, OPT_STRICT},
132         {"help", no_argument, 0, 'h'},
133         {"version", no_argument, 0, 'V'},
134         VCONN_SSL_LONG_OPTIONS
135         {0, 0, 0, 0},
136     };
137     char *short_options = long_options_to_short_options(long_options);
138
139     /* Set defaults that we can figure out before parsing options. */
140     s->strict = false;
141
142     for (;;) {
143         unsigned long int timeout;
144         int c;
145
146         c = getopt_long(argc, argv, short_options, long_options, NULL);
147         if (c == -1) {
148             break;
149         }
150
151         switch (c) {
152         case 't':
153             timeout = strtoul(optarg, NULL, 10);
154             if (timeout <= 0) {
155                 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
156                           optarg);
157             } else {
158                 time_alarm(timeout);
159             }
160             break;
161
162         case 'h':
163             usage();
164
165         case 'V':
166             OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
167             exit(EXIT_SUCCESS);
168
169         case 'v':
170             vlog_set_verbosity(optarg);
171             break;
172
173         case OPT_STRICT:
174             s->strict = true;
175             break;
176
177         VCONN_SSL_OPTION_HANDLERS
178
179         case '?':
180             exit(EXIT_FAILURE);
181
182         default:
183             abort();
184         }
185     }
186     free(short_options);
187 }
188
189 static void
190 usage(void)
191 {
192     printf("%s: OpenFlow switch management utility\n"
193            "usage: %s [OPTIONS] COMMAND [ARG...]\n"
194            "\nFor OpenFlow switches:\n"
195            "  show SWITCH                 show OpenFlow information\n"
196            "  status SWITCH [KEY]         report statistics (about KEY)\n"
197            "  dump-desc SWITCH            print switch description\n"
198            "  dump-tables SWITCH          print table stats\n"
199            "  mod-port SWITCH IFACE ACT   modify port behavior\n"
200            "  dump-ports SWITCH           print port statistics\n"
201            "  dump-flows SWITCH           print all flow entries\n"
202            "  dump-flows SWITCH FLOW      print matching FLOWs\n"
203            "  dump-aggregate SWITCH       print aggregate flow statistics\n"
204            "  dump-aggregate SWITCH FLOW  print aggregate stats for FLOWs\n"
205            "  add-flow SWITCH FLOW        add flow described by FLOW\n"
206            "  add-flows SWITCH FILE       add flows from FILE\n"
207            "  mod-flows SWITCH FLOW       modify actions of matching FLOWs\n"
208            "  del-flows SWITCH [FLOW]     delete matching FLOWs\n"
209            "  monitor SWITCH MISSLEN EXP  print packets received from SWITCH\n"
210            "  execute SWITCH CMD [ARG...] execute CMD with ARGS on SWITCH\n"
211            "\nFor OpenFlow switches and controllers:\n"
212            "  probe VCONN                 probe whether VCONN is up\n"
213            "  ping VCONN [N]              latency of N-byte echos\n"
214            "  benchmark VCONN N COUNT     bandwidth of COUNT N-byte echos\n"
215            "where each SWITCH is an active OpenFlow connection method.\n",
216            program_name, program_name);
217     vconn_usage(true, false, false);
218     vlog_usage();
219     printf("\nOther options:\n"
220            "  --strict                    use strict match for flow commands\n"
221            "  -t, --timeout=SECS          give up after SECS seconds\n"
222            "  -h, --help                  display this help message\n"
223            "  -V, --version               display version information\n");
224     exit(EXIT_SUCCESS);
225 }
226
227 static void run(int retval, const char *message, ...)
228     PRINTF_FORMAT(2, 3);
229
230 static void run(int retval, const char *message, ...)
231 {
232     if (retval) {
233         va_list args;
234
235         fprintf(stderr, "%s: ", program_name);
236         va_start(args, message);
237         vfprintf(stderr, message, args);
238         va_end(args);
239         if (retval == EOF) {
240             fputs(": unexpected end of file\n", stderr);
241         } else {
242             fprintf(stderr, ": %s\n", strerror(retval));
243         }
244
245         exit(EXIT_FAILURE);
246     }
247 }
248 \f
249 /* Generic commands. */
250
251 static void
252 open_vconn(const char *name, struct vconn **vconnp)
253 {
254     struct dpif *dpif;
255     struct stat s;
256
257     if (strstr(name, ":")) {
258         run(vconn_open_block(name, OFP_VERSION, vconnp),
259             "connecting to %s", name);
260     } else if (!stat(name, &s) && S_ISSOCK(s.st_mode)) {
261         char *vconn_name = xasprintf("unix:%s", name);
262         VLOG_INFO("connecting to %s", vconn_name);
263         run(vconn_open_block(vconn_name, OFP_VERSION, vconnp),
264             "connecting to %s", vconn_name);
265         free(vconn_name);
266     } else if (!dpif_open(name, &dpif)) {
267         char dpif_name[IF_NAMESIZE + 1];
268         char *socket_name;
269         char *vconn_name;
270
271         run(dpif_port_get_name(dpif, ODPP_LOCAL, dpif_name, sizeof dpif_name),
272             "obtaining name of %s", dpif_name);
273         dpif_close(dpif);
274         if (strcmp(dpif_name, name)) {
275             VLOG_INFO("datapath %s is named %s", name, dpif_name);
276         }
277
278         socket_name = xasprintf("%s/%s.mgmt", ovs_rundir, dpif_name);
279         if (stat(socket_name, &s)) {
280             ovs_fatal(errno, "cannot connect to %s: stat failed on %s",
281                       name, socket_name);
282         } else if (!S_ISSOCK(s.st_mode)) {
283             ovs_fatal(0, "cannot connect to %s: %s is not a socket",
284                       name, socket_name);
285         }
286
287         vconn_name = xasprintf("unix:%s", socket_name);
288         VLOG_INFO("connecting to %s", vconn_name);
289         run(vconn_open_block(vconn_name, OFP_VERSION, vconnp),
290             "connecting to %s", vconn_name);
291         free(socket_name);
292         free(vconn_name);
293     } else {
294         ovs_fatal(0, "%s is not a valid connection method", name);
295     }
296 }
297
298 static void *
299 alloc_stats_request(size_t body_len, uint16_t type, struct ofpbuf **bufferp)
300 {
301     struct ofp_stats_request *rq;
302     rq = make_openflow((offsetof(struct ofp_stats_request, body)
303                         + body_len), OFPT_STATS_REQUEST, bufferp);
304     rq->type = htons(type);
305     rq->flags = htons(0);
306     return rq->body;
307 }
308
309 static void
310 send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
311 {
312     update_openflow_length(buffer);
313     run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
314 }
315
316 static void
317 dump_transaction(const char *vconn_name, struct ofpbuf *request)
318 {
319     struct vconn *vconn;
320     struct ofpbuf *reply;
321
322     update_openflow_length(request);
323     open_vconn(vconn_name, &vconn);
324     run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
325     ofp_print(stdout, reply->data, reply->size, 1);
326     vconn_close(vconn);
327 }
328
329 static void
330 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
331 {
332     struct ofpbuf *request;
333     make_openflow(sizeof(struct ofp_header), request_type, &request);
334     dump_transaction(vconn_name, request);
335 }
336
337 static void
338 dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
339 {
340     uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
341     struct vconn *vconn;
342     bool done = false;
343
344     open_vconn(vconn_name, &vconn);
345     send_openflow_buffer(vconn, request);
346     while (!done) {
347         uint32_t recv_xid;
348         struct ofpbuf *reply;
349
350         run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
351         recv_xid = ((struct ofp_header *) reply->data)->xid;
352         if (send_xid == recv_xid) {
353             struct ofp_stats_reply *osr;
354
355             ofp_print(stdout, reply->data, reply->size, 1);
356
357             osr = ofpbuf_at(reply, 0, sizeof *osr);
358             done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
359         } else {
360             VLOG_DBG("received reply with xid %08"PRIx32" "
361                      "!= expected %08"PRIx32, recv_xid, send_xid);
362         }
363         ofpbuf_delete(reply);
364     }
365     vconn_close(vconn);
366 }
367
368 static void
369 dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
370 {
371     struct ofpbuf *request;
372     alloc_stats_request(0, stats_type, &request);
373     dump_stats_transaction(vconn_name, request);
374 }
375
376 static void
377 do_show(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
378 {
379     dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
380     dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
381 }
382
383 static void
384 do_status(const struct settings *s UNUSED, int argc, char *argv[])
385 {
386     struct nicira_header *request, *reply;
387     struct vconn *vconn;
388     struct ofpbuf *b;
389
390     request = make_openflow(sizeof *request, OFPT_VENDOR, &b);
391     request->vendor = htonl(NX_VENDOR_ID);
392     request->subtype = htonl(NXT_STATUS_REQUEST);
393     if (argc > 2) {
394         ofpbuf_put(b, argv[2], strlen(argv[2]));
395         update_openflow_length(b);
396     }
397     open_vconn(argv[1], &vconn);
398     run(vconn_transact(vconn, b, &b), "talking to %s", argv[1]);
399     vconn_close(vconn);
400
401     if (b->size < sizeof *reply) {
402         ovs_fatal(0, "short reply (%zu bytes)", b->size);
403     }
404     reply = b->data;
405     if (reply->header.type != OFPT_VENDOR
406         || reply->vendor != ntohl(NX_VENDOR_ID)
407         || reply->subtype != ntohl(NXT_STATUS_REPLY)) {
408         ofp_print(stderr, b->data, b->size, 2);
409         ovs_fatal(0, "bad reply");
410     }
411
412     fwrite(reply + 1, b->size - sizeof *reply, 1, stdout);
413 }
414
415 static void
416 do_dump_desc(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
417 {
418     dump_trivial_stats_transaction(argv[1], OFPST_DESC);
419 }
420
421 static void
422 do_dump_tables(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
423 {
424     dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
425 }
426
427
428 static uint32_t
429 str_to_u32(const char *str) 
430 {
431     char *tail;
432     uint32_t value;
433
434     errno = 0;
435     value = strtoul(str, &tail, 0);
436     if (errno == EINVAL || errno == ERANGE || *tail) {
437         ovs_fatal(0, "invalid numeric format %s", str);
438     }
439     return value;
440 }
441
442 static void
443 str_to_mac(const char *str, uint8_t mac[6]) 
444 {
445     if (sscanf(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
446         != ETH_ADDR_SCAN_COUNT) {
447         ovs_fatal(0, "invalid mac address %s", str);
448     }
449 }
450
451 static uint32_t
452 str_to_ip(const char *str_, uint32_t *ip)
453 {
454     char *str = xstrdup(str_);
455     char *save_ptr = NULL;
456     const char *name, *netmask;
457     struct in_addr in_addr;
458     int n_wild, retval;
459
460     name = strtok_r(str, "/", &save_ptr);
461     retval = name ? lookup_ip(name, &in_addr) : EINVAL;
462     if (retval) {
463         ovs_fatal(0, "%s: could not convert to IP address", str);
464     }
465     *ip = in_addr.s_addr;
466
467     netmask = strtok_r(NULL, "/", &save_ptr);
468     if (netmask) {
469         uint8_t o[4];
470         if (sscanf(netmask, "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8,
471                    &o[0], &o[1], &o[2], &o[3]) == 4) {
472             uint32_t nm = (o[0] << 24) | (o[1] << 16) | (o[2] << 8) | o[3];
473             int i;
474
475             /* Find first 1-bit. */
476             for (i = 0; i < 32; i++) {
477                 if (nm & (1u << i)) {
478                     break;
479                 }
480             }
481             n_wild = i;
482
483             /* Verify that the rest of the bits are 1-bits. */
484             for (; i < 32; i++) {
485                 if (!(nm & (1u << i))) {
486                     ovs_fatal(0, "%s: %s is not a valid netmask",
487                               str, netmask);
488                 }
489             }
490         } else {
491             int prefix = atoi(netmask);
492             if (prefix <= 0 || prefix > 32) {
493                 ovs_fatal(0, "%s: network prefix bits not between 1 and 32",
494                           str);
495             }
496             n_wild = 32 - prefix;
497         }
498     } else {
499         n_wild = 0;
500     }
501
502     free(str);
503     return n_wild;
504 }
505
506 static void *
507 put_action(struct ofpbuf *b, size_t size, uint16_t type)
508 {
509     struct ofp_action_header *ah = ofpbuf_put_zeros(b, size);
510     ah->type = htons(type);
511     ah->len = htons(size);
512     return ah;
513 }
514
515 static struct ofp_action_output *
516 put_output_action(struct ofpbuf *b, uint16_t port)
517 {
518     struct ofp_action_output *oao = put_action(b, sizeof *oao, OFPAT_OUTPUT);
519     oao->port = htons(port);
520     return oao;
521 }
522
523 static void
524 put_dl_addr_action(struct ofpbuf *b, uint16_t type, const char *addr)
525 {
526     struct ofp_action_dl_addr *oada = put_action(b, sizeof *oada, type);
527     str_to_mac(addr, oada->dl_addr);
528 }
529
530
531 static bool
532 parse_port_name(const char *name, uint16_t *port)
533 {
534     struct pair {
535         const char *name;
536         uint16_t value;
537     };
538     static const struct pair pairs[] = {
539 #define DEF_PAIR(NAME) {#NAME, OFPP_##NAME}
540         DEF_PAIR(IN_PORT),
541         DEF_PAIR(TABLE),
542         DEF_PAIR(NORMAL),
543         DEF_PAIR(FLOOD),
544         DEF_PAIR(ALL),
545         DEF_PAIR(CONTROLLER),
546         DEF_PAIR(LOCAL),
547         DEF_PAIR(NONE),
548 #undef DEF_PAIR
549     };
550     static const int n_pairs = ARRAY_SIZE(pairs);
551     size_t i;
552
553     for (i = 0; i < n_pairs; i++) {
554         if (!strcasecmp(name, pairs[i].name)) {
555             *port = pairs[i].value;
556             return true;
557         }
558     }
559     return false;
560 }
561
562 static void
563 str_to_action(char *str, struct ofpbuf *b)
564 {
565     char *act, *arg;
566     char *saveptr = NULL;
567     bool drop = false;
568     int n_actions;
569
570     for (act = strtok_r(str, ", \t\r\n", &saveptr), n_actions = 0; act;
571          act = strtok_r(NULL, ", \t\r\n", &saveptr), n_actions++) 
572     {
573         uint16_t port;
574
575         if (drop) {
576             ovs_fatal(0, "Drop actions must not be followed by other actions");
577         }
578
579         /* Arguments are separated by colons */
580         arg = strchr(act, ':');
581         if (arg) {
582             *arg = '\0';
583             arg++;
584         }
585
586         if (!strcasecmp(act, "mod_vlan_vid")) {
587             struct ofp_action_vlan_vid *va;
588             va = put_action(b, sizeof *va, OFPAT_SET_VLAN_VID);
589             va->vlan_vid = htons(str_to_u32(arg));
590         } else if (!strcasecmp(act, "mod_vlan_pcp")) {
591             struct ofp_action_vlan_pcp *va;
592             va = put_action(b, sizeof *va, OFPAT_SET_VLAN_PCP);
593             va->vlan_pcp = str_to_u32(arg);
594         } else if (!strcasecmp(act, "strip_vlan")) {
595             struct ofp_action_header *ah;
596             ah = put_action(b, sizeof *ah, OFPAT_STRIP_VLAN);
597             ah->type = htons(OFPAT_STRIP_VLAN);
598         } else if (!strcasecmp(act, "mod_dl_src")) {
599             put_dl_addr_action(b, OFPAT_SET_DL_SRC, arg);
600         } else if (!strcasecmp(act, "mod_dl_dst")) {
601             put_dl_addr_action(b, OFPAT_SET_DL_DST, arg);
602         } else if (!strcasecmp(act, "mod_nw_src")) {
603             struct ofp_action_nw_addr *na;
604             na = put_action(b, sizeof *na, OFPAT_SET_NW_SRC);
605             str_to_ip(arg, &na->nw_addr);
606         } else if (!strcasecmp(act, "mod_nw_dst")) {
607             struct ofp_action_nw_addr *na;
608             na = put_action(b, sizeof *na, OFPAT_SET_NW_DST);
609             str_to_ip(arg, &na->nw_addr);
610         } else if (!strcasecmp(act, "mod_tp_src")) {
611             struct ofp_action_tp_port *ta;
612             ta = put_action(b, sizeof *ta, OFPAT_SET_TP_SRC);
613             ta->tp_port = htons(str_to_u32(arg));
614         } else if (!strcasecmp(act, "mod_tp_dst")) {
615             struct ofp_action_tp_port *ta;
616             ta = put_action(b, sizeof *ta, OFPAT_SET_TP_DST);
617             ta->tp_port = htons(str_to_u32(arg));
618         } else if (!strcasecmp(act, "output")) {
619             put_output_action(b, str_to_u32(arg));
620         } else if (!strcasecmp(act, "drop")) {
621             /* A drop action in OpenFlow occurs by just not setting 
622              * an action. */
623             drop = true;
624             if (n_actions) {
625                 ovs_fatal(0, "Drop actions must not be preceded by other "
626                           "actions");
627             }
628         } else if (!strcasecmp(act, "CONTROLLER")) {
629             struct ofp_action_output *oao;
630             oao = put_output_action(b, OFPP_CONTROLLER);
631
632             /* Unless a numeric argument is specified, we send the whole
633              * packet to the controller. */
634             if (arg && (strspn(act, "0123456789") == strlen(act))) {
635                oao->max_len = htons(str_to_u32(arg));
636             } else {
637                 oao->max_len = htons(UINT16_MAX);
638             }
639         } else if (parse_port_name(act, &port)) {
640             put_output_action(b, port);
641         } else if (strspn(act, "0123456789") == strlen(act)) {
642             put_output_action(b, str_to_u32(act));
643         } else {
644             ovs_fatal(0, "Unknown action: %s", act);
645         }
646     }
647 }
648
649 struct protocol {
650     const char *name;
651     uint16_t dl_type;
652     uint8_t nw_proto;
653 };
654
655 static bool
656 parse_protocol(const char *name, const struct protocol **p_out)
657 {
658     static const struct protocol protocols[] = {
659         { "ip", ETH_TYPE_IP, 0 },
660         { "arp", ETH_TYPE_ARP, 0 },
661         { "icmp", ETH_TYPE_IP, IP_TYPE_ICMP },
662         { "tcp", ETH_TYPE_IP, IP_TYPE_TCP },
663         { "udp", ETH_TYPE_IP, IP_TYPE_UDP },
664     };
665     const struct protocol *p;
666
667     for (p = protocols; p < &protocols[ARRAY_SIZE(protocols)]; p++) {
668         if (!strcmp(p->name, name)) {
669             *p_out = p;
670             return true;
671         }
672     }
673     *p_out = NULL;
674     return false;
675 }
676
677 struct field {
678     const char *name;
679     uint32_t wildcard;
680     enum { F_U8, F_U16, F_MAC, F_IP } type;
681     size_t offset, shift;
682 };
683
684 static bool
685 parse_field(const char *name, const struct field **f_out) 
686 {
687 #define F_OFS(MEMBER) offsetof(struct ofp_match, MEMBER)
688     static const struct field fields[] = { 
689         { "in_port", OFPFW_IN_PORT, F_U16, F_OFS(in_port), 0 },
690         { "dl_vlan", OFPFW_DL_VLAN, F_U16, F_OFS(dl_vlan), 0 },
691         { "dl_src", OFPFW_DL_SRC, F_MAC, F_OFS(dl_src), 0 },
692         { "dl_dst", OFPFW_DL_DST, F_MAC, F_OFS(dl_dst), 0 },
693         { "dl_type", OFPFW_DL_TYPE, F_U16, F_OFS(dl_type), 0 },
694         { "nw_src", OFPFW_NW_SRC_MASK, F_IP,
695           F_OFS(nw_src), OFPFW_NW_SRC_SHIFT },
696         { "nw_dst", OFPFW_NW_DST_MASK, F_IP,
697           F_OFS(nw_dst), OFPFW_NW_DST_SHIFT },
698         { "nw_proto", OFPFW_NW_PROTO, F_U8, F_OFS(nw_proto), 0 },
699         { "tp_src", OFPFW_TP_SRC, F_U16, F_OFS(tp_src), 0 },
700         { "tp_dst", OFPFW_TP_DST, F_U16, F_OFS(tp_dst), 0 },
701         { "icmp_type", OFPFW_ICMP_TYPE, F_U16, F_OFS(icmp_type), 0 },
702         { "icmp_code", OFPFW_ICMP_CODE, F_U16, F_OFS(icmp_code), 0 }
703     };
704     const struct field *f;
705
706     for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
707         if (!strcmp(f->name, name)) {
708             *f_out = f;
709             return true;
710         }
711     }
712     *f_out = NULL;
713     return false;
714 }
715
716 static void
717 str_to_flow(char *string, struct ofp_match *match, struct ofpbuf *actions,
718             uint8_t *table_idx, uint16_t *out_port, uint16_t *priority, 
719             uint16_t *idle_timeout, uint16_t *hard_timeout)
720 {
721     char *save_ptr = NULL;
722     char *name;
723     uint32_t wildcards;
724
725     if (table_idx) {
726         *table_idx = 0xff;
727     }
728     if (out_port) {
729         *out_port = OFPP_NONE;
730     }
731     if (priority) {
732         *priority = OFP_DEFAULT_PRIORITY;
733     }
734     if (idle_timeout) {
735         *idle_timeout = DEFAULT_IDLE_TIMEOUT;
736     }
737     if (hard_timeout) {
738         *hard_timeout = OFP_FLOW_PERMANENT;
739     }
740     if (actions) {
741         char *act_str = strstr(string, "action");
742         if (!act_str) {
743             ovs_fatal(0, "must specify an action");
744         }
745         *(act_str-1) = '\0';
746
747         act_str = strchr(act_str, '=');
748         if (!act_str) {
749             ovs_fatal(0, "must specify an action");
750         }
751
752         act_str++;
753
754         str_to_action(act_str, actions);
755     }
756     memset(match, 0, sizeof *match);
757     wildcards = OFPFW_ALL;
758     for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
759          name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
760         const struct protocol *p;
761
762         if (parse_protocol(name, &p)) {
763             wildcards &= ~OFPFW_DL_TYPE;
764             match->dl_type = htons(p->dl_type);
765             if (p->nw_proto) {
766                 wildcards &= ~OFPFW_NW_PROTO;
767                 match->nw_proto = p->nw_proto;
768             }
769         } else {
770             const struct field *f;
771             char *value;
772
773             value = strtok_r(NULL, ", \t\r\n", &save_ptr);
774             if (!value) {
775                 ovs_fatal(0, "field %s missing value", name);
776             }
777         
778             if (table_idx && !strcmp(name, "table")) {
779                 *table_idx = atoi(value);
780             } else if (out_port && !strcmp(name, "out_port")) {
781                 *out_port = atoi(value);
782             } else if (priority && !strcmp(name, "priority")) {
783                 *priority = atoi(value);
784             } else if (idle_timeout && !strcmp(name, "idle_timeout")) {
785                 *idle_timeout = atoi(value);
786             } else if (hard_timeout && !strcmp(name, "hard_timeout")) {
787                 *hard_timeout = atoi(value);
788             } else if (parse_field(name, &f)) {
789                 void *data = (char *) match + f->offset;
790                 if (!strcmp(value, "*") || !strcmp(value, "ANY")) {
791                     wildcards |= f->wildcard;
792                 } else {
793                     wildcards &= ~f->wildcard;
794                     if (f->wildcard == OFPFW_IN_PORT
795                         && parse_port_name(value, (uint16_t *) data)) {
796                         /* Nothing to do. */
797                     } else if (f->type == F_U8) {
798                         *(uint8_t *) data = str_to_u32(value);
799                     } else if (f->type == F_U16) {
800                         *(uint16_t *) data = htons(str_to_u32(value));
801                     } else if (f->type == F_MAC) {
802                         str_to_mac(value, data);
803                     } else if (f->type == F_IP) {
804                         wildcards |= str_to_ip(value, data) << f->shift;
805                     } else {
806                         NOT_REACHED();
807                     }
808                 }
809             } else {
810                 ovs_fatal(0, "unknown keyword %s", name);
811             }
812         }
813     }
814     match->wildcards = htonl(wildcards);
815 }
816
817 static void
818 do_dump_flows(const struct settings *s UNUSED, int argc, char *argv[])
819 {
820     struct ofp_flow_stats_request *req;
821     uint16_t out_port;
822     struct ofpbuf *request;
823
824     req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
825     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL,
826                 &req->table_id, &out_port, NULL, NULL, NULL);
827     memset(&req->pad, 0, sizeof req->pad);
828     req->out_port = htons(out_port);
829
830     dump_stats_transaction(argv[1], request);
831 }
832
833 static void
834 do_dump_aggregate(const struct settings *s UNUSED, int argc, char *argv[])
835 {
836     struct ofp_aggregate_stats_request *req;
837     struct ofpbuf *request;
838     uint16_t out_port;
839
840     req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
841     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL,
842                 &req->table_id, &out_port, NULL, NULL, NULL);
843     memset(&req->pad, 0, sizeof req->pad);
844     req->out_port = htons(out_port);
845
846     dump_stats_transaction(argv[1], request);
847 }
848
849 static void
850 do_add_flow(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
851 {
852     struct vconn *vconn;
853     struct ofpbuf *buffer;
854     struct ofp_flow_mod *ofm;
855     uint16_t priority, idle_timeout, hard_timeout;
856     struct ofp_match match;
857
858     /* Parse and send.  str_to_flow() will expand and reallocate the data in
859      * 'buffer', so we can't keep pointers to across the str_to_flow() call. */
860     make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
861     str_to_flow(argv[2], &match, buffer,
862                 NULL, NULL, &priority, &idle_timeout, &hard_timeout);
863     ofm = buffer->data;
864     ofm->match = match;
865     ofm->command = htons(OFPFC_ADD);
866     ofm->idle_timeout = htons(idle_timeout);
867     ofm->hard_timeout = htons(hard_timeout);
868     ofm->buffer_id = htonl(UINT32_MAX);
869     ofm->priority = htons(priority);
870     ofm->reserved = htonl(0);
871
872     open_vconn(argv[1], &vconn);
873     send_openflow_buffer(vconn, buffer);
874     vconn_close(vconn);
875 }
876
877 static void
878 do_add_flows(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
879 {
880     struct vconn *vconn;
881     FILE *file;
882     char line[1024];
883
884     file = fopen(argv[2], "r");
885     if (file == NULL) {
886         ovs_fatal(errno, "%s: open", argv[2]);
887     }
888
889     open_vconn(argv[1], &vconn);
890     while (fgets(line, sizeof line, file)) {
891         struct ofpbuf *buffer;
892         struct ofp_flow_mod *ofm;
893         uint16_t priority, idle_timeout, hard_timeout;
894         struct ofp_match match;
895
896         char *comment;
897
898         /* Delete comments. */
899         comment = strchr(line, '#');
900         if (comment) {
901             *comment = '\0';
902         }
903
904         /* Drop empty lines. */
905         if (line[strspn(line, " \t\n")] == '\0') {
906             continue;
907         }
908
909         /* Parse and send.  str_to_flow() will expand and reallocate the data
910          * in 'buffer', so we can't keep pointers to across the str_to_flow()
911          * call. */
912         ofm = make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
913         str_to_flow(line, &match, buffer,
914                     NULL, NULL, &priority, &idle_timeout, &hard_timeout);
915         ofm = buffer->data;
916         ofm->match = match;
917         ofm->command = htons(OFPFC_ADD);
918         ofm->idle_timeout = htons(idle_timeout);
919         ofm->hard_timeout = htons(hard_timeout);
920         ofm->buffer_id = htonl(UINT32_MAX);
921         ofm->priority = htons(priority);
922         ofm->reserved = htonl(0);
923
924         send_openflow_buffer(vconn, buffer);
925     }
926     vconn_close(vconn);
927     fclose(file);
928 }
929
930 static void
931 do_mod_flows(const struct settings *s, int argc UNUSED, char *argv[])
932 {
933     uint16_t priority, idle_timeout, hard_timeout;
934     struct vconn *vconn;
935     struct ofpbuf *buffer;
936     struct ofp_flow_mod *ofm;
937     struct ofp_match match;
938
939     /* Parse and send.  str_to_flow() will expand and reallocate the data in
940      * 'buffer', so we can't keep pointers to across the str_to_flow() call. */
941     make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
942     str_to_flow(argv[2], &match, buffer,
943                 NULL, NULL, &priority, &idle_timeout, &hard_timeout);
944     ofm = buffer->data;
945     ofm->match = match;
946     if (s->strict) {
947         ofm->command = htons(OFPFC_MODIFY_STRICT);
948     } else {
949         ofm->command = htons(OFPFC_MODIFY);
950     }
951     ofm->idle_timeout = htons(idle_timeout);
952     ofm->hard_timeout = htons(hard_timeout);
953     ofm->buffer_id = htonl(UINT32_MAX);
954     ofm->priority = htons(priority);
955     ofm->reserved = htonl(0);
956
957     open_vconn(argv[1], &vconn);
958     send_openflow_buffer(vconn, buffer);
959     vconn_close(vconn);
960 }
961
962 static void do_del_flows(const struct settings *s, int argc, char *argv[])
963 {
964     struct vconn *vconn;
965     uint16_t priority;
966     uint16_t out_port;
967     struct ofpbuf *buffer;
968     struct ofp_flow_mod *ofm;
969
970     /* Parse and send. */
971     ofm = make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
972     str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, 
973                 &out_port, &priority, NULL, NULL);
974     if (s->strict) {
975         ofm->command = htons(OFPFC_DELETE_STRICT);
976     } else {
977         ofm->command = htons(OFPFC_DELETE);
978     }
979     ofm->idle_timeout = htons(0);
980     ofm->hard_timeout = htons(0);
981     ofm->buffer_id = htonl(UINT32_MAX);
982     ofm->out_port = htons(out_port);
983     ofm->priority = htons(priority);
984     ofm->reserved = htonl(0);
985
986     open_vconn(argv[1], &vconn);
987     send_openflow_buffer(vconn, buffer);
988     vconn_close(vconn);
989 }
990
991 static void
992 do_monitor(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
993 {
994     struct vconn *vconn;
995
996     open_vconn(argv[1], &vconn);
997     if (argc > 2) {
998         int miss_send_len = atoi(argv[2]);
999         int send_flow_exp = argc > 3 ? atoi(argv[3]) : 0;
1000         struct ofp_switch_config *osc;
1001         struct ofpbuf *buf;
1002
1003         osc = make_openflow(sizeof *osc, OFPT_SET_CONFIG, &buf);
1004         osc->flags = htons(send_flow_exp ? OFPC_SEND_FLOW_EXP : 0);
1005         osc->miss_send_len = htons(miss_send_len);
1006         send_openflow_buffer(vconn, buf);
1007     }
1008     for (;;) {
1009         struct ofpbuf *b;
1010         run(vconn_recv_block(vconn, &b), "vconn_recv");
1011         ofp_print(stderr, b->data, b->size, 2);
1012         ofpbuf_delete(b);
1013     }
1014 }
1015
1016 static void
1017 do_dump_ports(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
1018 {
1019     dump_trivial_stats_transaction(argv[1], OFPST_PORT);
1020 }
1021
1022 static void
1023 do_probe(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
1024 {
1025     struct ofpbuf *request;
1026     struct vconn *vconn;
1027     struct ofpbuf *reply;
1028
1029     make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
1030     open_vconn(argv[1], &vconn);
1031     run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
1032     if (reply->size != sizeof(struct ofp_header)) {
1033         ovs_fatal(0, "reply does not match request");
1034     }
1035     ofpbuf_delete(reply);
1036     vconn_close(vconn);
1037 }
1038
1039 static void
1040 do_mod_port(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
1041 {
1042     struct ofpbuf *request, *reply;
1043     struct ofp_switch_features *osf;
1044     struct ofp_port_mod *opm;
1045     struct vconn *vconn;
1046     char *endptr;
1047     int n_ports;
1048     int port_idx;
1049     int port_no;
1050     
1051
1052     /* Check if the argument is a port index.  Otherwise, treat it as
1053      * the port name. */
1054     port_no = strtol(argv[2], &endptr, 10);
1055     if (port_no == 0 && endptr == argv[2]) {
1056         port_no = -1;
1057     }
1058
1059     /* Send a "Features Request" to get the information we need in order 
1060      * to modify the port. */
1061     make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
1062     open_vconn(argv[1], &vconn);
1063     run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
1064
1065     osf = reply->data;
1066     n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
1067
1068     for (port_idx = 0; port_idx < n_ports; port_idx++) {
1069         if (port_no != -1) {
1070             /* Check argument as a port index */
1071             if (osf->ports[port_idx].port_no == htons(port_no)) {
1072                 break;
1073             }
1074         } else {
1075             /* Check argument as an interface name */
1076             if (!strncmp((char *)osf->ports[port_idx].name, argv[2], 
1077                         sizeof osf->ports[0].name)) {
1078                 break;
1079             }
1080
1081         }
1082     }
1083     if (port_idx == n_ports) {
1084         ovs_fatal(0, "couldn't find monitored port: %s", argv[2]);
1085     }
1086
1087     opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
1088     opm->port_no = osf->ports[port_idx].port_no;
1089     memcpy(opm->hw_addr, osf->ports[port_idx].hw_addr, sizeof opm->hw_addr);
1090     opm->config = htonl(0);
1091     opm->mask = htonl(0);
1092     opm->advertise = htonl(0);
1093
1094     printf("modifying port: %s\n", osf->ports[port_idx].name);
1095
1096     if (!strncasecmp(argv[3], MOD_PORT_CMD_UP, sizeof MOD_PORT_CMD_UP)) {
1097         opm->mask |= htonl(OFPPC_PORT_DOWN);
1098     } else if (!strncasecmp(argv[3], MOD_PORT_CMD_DOWN, 
1099                 sizeof MOD_PORT_CMD_DOWN)) {
1100         opm->mask |= htonl(OFPPC_PORT_DOWN);
1101         opm->config |= htonl(OFPPC_PORT_DOWN);
1102     } else if (!strncasecmp(argv[3], MOD_PORT_CMD_FLOOD, 
1103                 sizeof MOD_PORT_CMD_FLOOD)) {
1104         opm->mask |= htonl(OFPPC_NO_FLOOD);
1105     } else if (!strncasecmp(argv[3], MOD_PORT_CMD_NOFLOOD, 
1106                 sizeof MOD_PORT_CMD_NOFLOOD)) {
1107         opm->mask |= htonl(OFPPC_NO_FLOOD);
1108         opm->config |= htonl(OFPPC_NO_FLOOD);
1109     } else {
1110         ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
1111     }
1112
1113     send_openflow_buffer(vconn, request);
1114
1115     ofpbuf_delete(reply);
1116     vconn_close(vconn);
1117 }
1118
1119 static void
1120 do_ping(const struct settings *s UNUSED, int argc, char *argv[])
1121 {
1122     size_t max_payload = 65535 - sizeof(struct ofp_header);
1123     unsigned int payload;
1124     struct vconn *vconn;
1125     int i;
1126
1127     payload = argc > 2 ? atoi(argv[2]) : 64;
1128     if (payload > max_payload) {
1129         ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
1130     }
1131
1132     open_vconn(argv[1], &vconn);
1133     for (i = 0; i < 10; i++) {
1134         struct timeval start, end;
1135         struct ofpbuf *request, *reply;
1136         struct ofp_header *rq_hdr, *rpy_hdr;
1137
1138         rq_hdr = make_openflow(sizeof(struct ofp_header) + payload,
1139                                OFPT_ECHO_REQUEST, &request);
1140         random_bytes(rq_hdr + 1, payload);
1141
1142         gettimeofday(&start, NULL);
1143         run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
1144         gettimeofday(&end, NULL);
1145
1146         rpy_hdr = reply->data;
1147         if (reply->size != request->size
1148             || memcmp(rpy_hdr + 1, rq_hdr + 1, payload)
1149             || rpy_hdr->xid != rq_hdr->xid
1150             || rpy_hdr->type != OFPT_ECHO_REPLY) {
1151             printf("Reply does not match request.  Request:\n");
1152             ofp_print(stdout, request, request->size, 2);
1153             printf("Reply:\n");
1154             ofp_print(stdout, reply, reply->size, 2);
1155         }
1156         printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
1157                reply->size - sizeof *rpy_hdr, argv[1], rpy_hdr->xid,
1158                    (1000*(double)(end.tv_sec - start.tv_sec))
1159                    + (.001*(end.tv_usec - start.tv_usec)));
1160         ofpbuf_delete(request);
1161         ofpbuf_delete(reply);
1162     }
1163     vconn_close(vconn);
1164 }
1165
1166 static void
1167 do_benchmark(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
1168 {
1169     size_t max_payload = 65535 - sizeof(struct ofp_header);
1170     struct timeval start, end;
1171     unsigned int payload_size, message_size;
1172     struct vconn *vconn;
1173     double duration;
1174     int count;
1175     int i;
1176
1177     payload_size = atoi(argv[2]);
1178     if (payload_size > max_payload) {
1179         ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
1180     }
1181     message_size = sizeof(struct ofp_header) + payload_size;
1182
1183     count = atoi(argv[3]);
1184
1185     printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
1186            count, message_size, count * message_size);
1187
1188     open_vconn(argv[1], &vconn);
1189     gettimeofday(&start, NULL);
1190     for (i = 0; i < count; i++) {
1191         struct ofpbuf *request, *reply;
1192         struct ofp_header *rq_hdr;
1193
1194         rq_hdr = make_openflow(message_size, OFPT_ECHO_REQUEST, &request);
1195         memset(rq_hdr + 1, 0, payload_size);
1196         run(vconn_transact(vconn, request, &reply), "transact");
1197         ofpbuf_delete(reply);
1198     }
1199     gettimeofday(&end, NULL);
1200     vconn_close(vconn);
1201
1202     duration = ((1000*(double)(end.tv_sec - start.tv_sec))
1203                 + (.001*(end.tv_usec - start.tv_usec)));
1204     printf("Finished in %.1f ms (%.0f packets/s) (%.0f bytes/s)\n",
1205            duration, count / (duration / 1000.0),
1206            count * message_size / (duration / 1000.0));
1207 }
1208
1209 static void
1210 do_execute(const struct settings *s UNUSED, int argc, char *argv[])
1211 {
1212     struct vconn *vconn;
1213     struct ofpbuf *request;
1214     struct nicira_header *nicira;
1215     struct nx_command_reply *ncr;
1216     uint32_t xid;
1217     int i;
1218
1219     nicira = make_openflow(sizeof *nicira, OFPT_VENDOR, &request);
1220     xid = nicira->header.xid;
1221     nicira->vendor = htonl(NX_VENDOR_ID);
1222     nicira->subtype = htonl(NXT_COMMAND_REQUEST);
1223     ofpbuf_put(request, argv[2], strlen(argv[2]));
1224     for (i = 3; i < argc; i++) {
1225         ofpbuf_put_zeros(request, 1);
1226         ofpbuf_put(request, argv[i], strlen(argv[i]));
1227     }
1228     update_openflow_length(request);
1229
1230     open_vconn(argv[1], &vconn);
1231     run(vconn_send_block(vconn, request), "send");
1232
1233     for (;;) {
1234         struct ofpbuf *reply;
1235         uint32_t status;
1236
1237         run(vconn_recv_xid(vconn, xid, &reply), "recv_xid");
1238         if (reply->size < sizeof *ncr) {
1239             ovs_fatal(0, "reply is too short (%zu bytes < %zu bytes)",
1240                       reply->size, sizeof *ncr);
1241         }
1242         ncr = reply->data;
1243         if (ncr->nxh.header.type != OFPT_VENDOR
1244             || ncr->nxh.vendor != htonl(NX_VENDOR_ID)
1245             || ncr->nxh.subtype != htonl(NXT_COMMAND_REPLY)) {
1246             ovs_fatal(0, "reply is invalid");
1247         }
1248
1249         status = ntohl(ncr->status);
1250         if (status & NXT_STATUS_STARTED) {
1251             /* Wait for a second reply. */
1252             continue;
1253         } else if (status & NXT_STATUS_EXITED) {
1254             fprintf(stderr, "process terminated normally with exit code %d",
1255                     status & NXT_STATUS_EXITSTATUS);
1256         } else if (status & NXT_STATUS_SIGNALED) {
1257             fprintf(stderr, "process terminated by signal %d",
1258                     status & NXT_STATUS_TERMSIG);
1259         } else if (status & NXT_STATUS_ERROR) {
1260             fprintf(stderr, "error executing command");
1261         } else {
1262             fprintf(stderr, "process terminated for unknown reason");
1263         }
1264         if (status & NXT_STATUS_COREDUMP) {
1265             fprintf(stderr, " (core dumped)");
1266         }
1267         putc('\n', stderr);
1268
1269         fwrite(ncr + 1, reply->size - sizeof *ncr, 1, stdout);
1270         break;
1271     }
1272 }
1273
1274 static void
1275 do_help(const struct settings *s UNUSED, int argc UNUSED, char *argv[] UNUSED)
1276 {
1277     usage();
1278 }
1279
1280 static struct command all_commands[] = {
1281     { "show", 1, 1, do_show },
1282     { "status", 1, 2, do_status },
1283     { "monitor", 1, 3, do_monitor },
1284     { "dump-desc", 1, 1, do_dump_desc },
1285     { "dump-tables", 1, 1, do_dump_tables },
1286     { "dump-flows", 1, 2, do_dump_flows },
1287     { "dump-aggregate", 1, 2, do_dump_aggregate },
1288     { "add-flow", 2, 2, do_add_flow },
1289     { "add-flows", 2, 2, do_add_flows },
1290     { "mod-flows", 2, 2, do_mod_flows },
1291     { "del-flows", 1, 2, do_del_flows },
1292     { "dump-ports", 1, 1, do_dump_ports },
1293     { "mod-port", 3, 3, do_mod_port },
1294     { "probe", 1, 1, do_probe },
1295     { "ping", 1, 2, do_ping },
1296     { "benchmark", 3, 3, do_benchmark },
1297     { "execute", 2, INT_MAX, do_execute },
1298     { "help", 0, INT_MAX, do_help },
1299     { NULL, 0, 0, NULL },
1300 };