2009-07-08 13:19:16 -07:00
|
|
|
/*
|
2014-05-20 11:37:02 -07:00
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <inttypes.h>
|
2010-05-26 10:05:19 -07:00
|
|
|
#include <sys/socket.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include "command-line.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "dirs.h"
|
2014-07-17 17:26:00 -07:00
|
|
|
#include "dpctl.h"
|
2014-02-26 10:44:46 -08:00
|
|
|
#include "fatal-signal.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "odp-util.h"
|
2013-10-13 12:44:20 -07:00
|
|
|
#include "ofp-parse.h"
|
2011-11-17 10:24:05 -08:00
|
|
|
#include "packets.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "timeval.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "vlog.h"
|
2010-07-16 11:02:49 -07:00
|
|
|
|
2014-07-17 17:26:00 -07:00
|
|
|
static struct dpctl_params dpctl_p;
|
2011-04-28 13:02:15 -07:00
|
|
|
|
2014-09-15 12:58:09 -07:00
|
|
|
NO_RETURN static void usage(void *userdata OVS_UNUSED);
|
2009-07-08 13:19:16 -07:00
|
|
|
static void parse_options(int argc, char *argv[]);
|
|
|
|
|
2014-07-17 17:26:00 -07:00
|
|
|
static void
|
|
|
|
dpctl_print(void *userdata OVS_UNUSED, bool error, const char *msg)
|
|
|
|
{
|
|
|
|
FILE *outfile = error ? stderr : stdout;
|
|
|
|
fputs(msg, outfile);
|
|
|
|
}
|
|
|
|
|
2009-10-23 11:49:39 -07:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2014-07-17 17:26:00 -07:00
|
|
|
int error;
|
2009-07-08 13:19:16 -07:00
|
|
|
set_program_name(argv[0]);
|
|
|
|
parse_options(argc, argv);
|
2014-02-26 10:44:46 -08:00
|
|
|
fatal_ignore_sigpipe();
|
2014-07-17 17:26:00 -07:00
|
|
|
|
|
|
|
dpctl_p.output = dpctl_print;
|
|
|
|
dpctl_p.usage = usage;
|
|
|
|
|
|
|
|
error = dpctl_run_command(argc - optind, (const char **) argv + optind,
|
|
|
|
&dpctl_p);
|
|
|
|
return error ? EXIT_FAILURE : EXIT_SUCCESS;
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_options(int argc, char *argv[])
|
|
|
|
{
|
2010-01-04 18:55:00 -08:00
|
|
|
enum {
|
2013-03-15 13:47:53 -07:00
|
|
|
OPT_CLEAR = UCHAR_MAX + 1,
|
|
|
|
OPT_MAY_CREATE,
|
2010-01-04 18:55:00 -08:00
|
|
|
VLOG_OPTION_ENUMS
|
|
|
|
};
|
2013-04-23 16:40:56 -07:00
|
|
|
static const struct option long_options[] = {
|
2011-05-04 13:49:42 -07:00
|
|
|
{"statistics", no_argument, NULL, 's'},
|
2013-03-15 13:47:53 -07:00
|
|
|
{"clear", no_argument, NULL, OPT_CLEAR},
|
|
|
|
{"may-create", no_argument, NULL, OPT_MAY_CREATE},
|
2011-11-17 10:24:05 -08:00
|
|
|
{"more", no_argument, NULL, 'm'},
|
2011-05-04 13:49:42 -07:00
|
|
|
{"timeout", required_argument, NULL, 't'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
2014-09-11 17:24:35 -07:00
|
|
|
{"option", no_argument, NULL, 'o'},
|
2011-05-04 13:49:42 -07:00
|
|
|
{"version", no_argument, NULL, 'V'},
|
2010-01-04 18:55:00 -08:00
|
|
|
VLOG_LONG_OPTIONS,
|
2011-05-04 13:49:42 -07:00
|
|
|
{NULL, 0, NULL, 0},
|
2009-07-08 13:19:16 -07:00
|
|
|
};
|
|
|
|
char *short_options = long_options_to_short_options(long_options);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
unsigned long int timeout;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, short_options, long_options, NULL);
|
|
|
|
if (c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
2011-04-28 13:02:15 -07:00
|
|
|
case 's':
|
2014-07-17 17:26:00 -07:00
|
|
|
dpctl_p.print_statistics = true;
|
2011-04-28 13:02:15 -07:00
|
|
|
break;
|
|
|
|
|
2013-03-15 13:47:53 -07:00
|
|
|
case OPT_CLEAR:
|
2014-07-17 17:26:00 -07:00
|
|
|
dpctl_p.zero_statistics = true;
|
2013-03-15 13:47:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_MAY_CREATE:
|
2014-07-17 17:26:00 -07:00
|
|
|
dpctl_p.may_create = true;
|
2013-03-15 13:47:53 -07:00
|
|
|
break;
|
|
|
|
|
2011-11-17 10:24:05 -08:00
|
|
|
case 'm':
|
2014-07-17 17:26:00 -07:00
|
|
|
dpctl_p.verbosity++;
|
2011-11-17 10:24:05 -08:00
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case 't':
|
|
|
|
timeout = strtoul(optarg, NULL, 10);
|
|
|
|
if (timeout <= 0) {
|
|
|
|
ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
|
|
|
|
optarg);
|
|
|
|
} else {
|
|
|
|
time_alarm(timeout);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
2014-07-17 17:26:00 -07:00
|
|
|
usage(NULL);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2014-09-11 17:24:35 -07:00
|
|
|
case 'o':
|
|
|
|
print_options(long_options);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case 'V':
|
2011-08-02 12:16:44 -07:00
|
|
|
ovs_print_version(0, 0);
|
2009-07-08 13:19:16 -07:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
2010-01-04 18:55:00 -08:00
|
|
|
VLOG_OPTION_HANDLERS
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(short_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-07-17 17:26:00 -07:00
|
|
|
usage(void *userdata OVS_UNUSED)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
|
|
|
printf("%s: Open vSwitch datapath management utility\n"
|
|
|
|
"usage: %s [OPTIONS] COMMAND [ARG...]\n"
|
|
|
|
" add-dp DP [IFACE...] add new datapath DP (with IFACEs)\n"
|
|
|
|
" del-dp DP delete local datapath DP\n"
|
|
|
|
" add-if DP IFACE... add each IFACE as a port on DP\n"
|
2011-10-17 11:24:37 -07:00
|
|
|
" set-if DP IFACE... reconfigure each IFACE within DP\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
" del-if DP IFACE... delete each IFACE from DP\n"
|
2009-08-04 15:13:40 -07:00
|
|
|
" dump-dps display names of all datapaths\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
" show show basic info on all datapaths\n"
|
|
|
|
" show DP... show basic info on each DP\n"
|
2013-09-24 10:23:49 -07:00
|
|
|
" dump-flows [DP] display flows in DP\n"
|
|
|
|
" add-flow [DP] FLOW ACTIONS add FLOW with ACTIONS to DP\n"
|
|
|
|
" mod-flow [DP] FLOW ACTIONS change FLOW actions to ACTIONS in DP\n"
|
|
|
|
" del-flow [DP] FLOW delete FLOW from DP\n"
|
|
|
|
" del-flows [DP] delete all flows from DP\n"
|
2011-10-17 11:24:37 -07:00
|
|
|
"Each IFACE on add-dp, add-if, and set-if may be followed by\n"
|
|
|
|
"comma-separated options. See ovs-dpctl(8) for syntax, or the\n"
|
2013-09-24 10:23:49 -07:00
|
|
|
"Interface table in ovs-vswitchd.conf.db(5) for an options list.\n"
|
|
|
|
"For COMMAND dump-flows, add-flow, mod-flow, del-flow and\n"
|
|
|
|
"del-flows, DP is optional if there is only one datapath.\n",
|
2009-07-08 13:19:16 -07:00
|
|
|
program_name, program_name);
|
|
|
|
vlog_usage();
|
2013-03-15 13:47:53 -07:00
|
|
|
printf("\nOptions for show and mod-flow:\n"
|
|
|
|
" -s, --statistics print statistics for port or flow\n"
|
2013-08-03 12:23:14 -07:00
|
|
|
"\nOptions for dump-flows:\n"
|
|
|
|
" -m, --more increase verbosity of output\n"
|
2013-03-15 13:47:53 -07:00
|
|
|
"\nOptions for mod-flow:\n"
|
|
|
|
" --may-create create flow if it doesn't exist\n"
|
|
|
|
" --clear reset existing stats to zero\n"
|
2012-11-29 16:14:53 -08:00
|
|
|
"\nOther options:\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
" -t, --timeout=SECS give up after SECS seconds\n"
|
|
|
|
" -h, --help display this help message\n"
|
|
|
|
" -V, --version display version information\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|