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>
|
2017-11-06 14:42:32 -08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#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 <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"
|
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"
|
2014-12-15 14:10:38 +01:00
|
|
|
#include "openvswitch/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-12-15 14:10:38 +01:00
|
|
|
OVS_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
|
|
|
|
2014-10-16 13:26:07 -07:00
|
|
|
dpctl_p.is_appctl = false;
|
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,
|
2016-08-15 18:47:29 +00:00
|
|
|
OPT_READ_ONLY,
|
2017-06-18 09:46:54 +08:00
|
|
|
OPT_NAMES,
|
|
|
|
OPT_NO_NAMES,
|
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},
|
2016-08-15 18:47:29 +00:00
|
|
|
{"read-only", no_argument, NULL, OPT_READ_ONLY},
|
2011-11-17 10:24:05 -08:00
|
|
|
{"more", no_argument, NULL, 'm'},
|
2017-06-18 09:46:54 +08:00
|
|
|
{"names", no_argument, NULL, OPT_NAMES},
|
|
|
|
{"no-names", no_argument, NULL, OPT_NO_NAMES},
|
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
|
|
|
};
|
2015-03-16 12:01:55 -04:00
|
|
|
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2017-06-18 09:46:54 +08:00
|
|
|
bool set_names = false;
|
2018-08-14 10:53:16 +03:00
|
|
|
unsigned int timeout = 0;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
for (;;) {
|
|
|
|
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;
|
|
|
|
|
2016-08-15 18:47:29 +00:00
|
|
|
case OPT_READ_ONLY:
|
|
|
|
dpctl_p.read_only = true;
|
|
|
|
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;
|
|
|
|
|
2017-06-18 09:46:54 +08:00
|
|
|
case OPT_NAMES:
|
|
|
|
dpctl_p.names = true;
|
|
|
|
set_names = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_NO_NAMES:
|
|
|
|
dpctl_p.names = false;
|
|
|
|
set_names = true;
|
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case 't':
|
2018-08-14 10:53:15 +03:00
|
|
|
if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
|
|
|
|
ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
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':
|
2015-03-16 12:01:55 -04:00
|
|
|
ovs_cmdl_print_options(long_options);
|
2014-09-11 17:24:35 -07:00
|
|
|
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);
|
2017-06-18 09:46:54 +08:00
|
|
|
|
2018-08-14 10:53:16 +03:00
|
|
|
ctl_timeout_setup(timeout);
|
|
|
|
|
2017-06-18 09:46:54 +08:00
|
|
|
if (!set_names) {
|
|
|
|
dpctl_p.names = dpctl_p.verbosity > 0;
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
dpctl: Add add/mod/del-flows command.
When you would like to add, modify, or delete a lot of flows in the
datapath, for example when you want to measure performance, adding
one flow at the time won't scale. This as it takes a decent amount
of time to set up the datapath connection.
This new command is in-line with the same command available in
ovs-ofctl which allows the same thing, with the only difference that
we do not verify all lines before we start execution. This allows for
a continuous add/delete stream. For example with a command like this:
python3 -c 'while True:
for i in range(0, 1000):
print("add in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{}) 1".format(int(i / 256), i % 256))
for i in range(0, 1000):
print("delete in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{})".format(int(i / 256), i % 256))' \
| sudo utilities/ovs-dpctl add-flows -
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Paolo Valerio <pvalerio@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2020-10-13 10:36:48 +02:00
|
|
|
" add-flows [DP] FILE add flows from FILE\n"
|
2013-09-24 10:23:49 -07:00
|
|
|
" mod-flow [DP] FLOW ACTIONS change FLOW actions to ACTIONS in DP\n"
|
dpctl: Add add/mod/del-flows command.
When you would like to add, modify, or delete a lot of flows in the
datapath, for example when you want to measure performance, adding
one flow at the time won't scale. This as it takes a decent amount
of time to set up the datapath connection.
This new command is in-line with the same command available in
ovs-ofctl which allows the same thing, with the only difference that
we do not verify all lines before we start execution. This allows for
a continuous add/delete stream. For example with a command like this:
python3 -c 'while True:
for i in range(0, 1000):
print("add in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{}) 1".format(int(i / 256), i % 256))
for i in range(0, 1000):
print("delete in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{})".format(int(i / 256), i % 256))' \
| sudo utilities/ovs-dpctl add-flows -
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Paolo Valerio <pvalerio@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2020-10-13 10:36:48 +02:00
|
|
|
" mod-flows [DP] FILE change flows from FILE\n"
|
2014-12-05 14:45:51 -08:00
|
|
|
" get-flow [DP] ufid:UFID fetch flow corresponding to UFID\n"
|
2013-09-24 10:23:49 -07:00
|
|
|
" del-flow [DP] FLOW delete FLOW from DP\n"
|
dpctl: Add add/mod/del-flows command.
When you would like to add, modify, or delete a lot of flows in the
datapath, for example when you want to measure performance, adding
one flow at the time won't scale. This as it takes a decent amount
of time to set up the datapath connection.
This new command is in-line with the same command available in
ovs-ofctl which allows the same thing, with the only difference that
we do not verify all lines before we start execution. This allows for
a continuous add/delete stream. For example with a command like this:
python3 -c 'while True:
for i in range(0, 1000):
print("add in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{}) 1".format(int(i / 256), i % 256))
for i in range(0, 1000):
print("delete in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{})".format(int(i / 256), i % 256))' \
| sudo utilities/ovs-dpctl add-flows -
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Paolo Valerio <pvalerio@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2020-10-13 10:36:48 +02:00
|
|
|
" del-flows [DP] [FILE] " \
|
|
|
|
"delete all or specified flows from DP\n"
|
2017-06-23 13:28:20 +01:00
|
|
|
" dump-conntrack [DP] [zone=ZONE] " \
|
|
|
|
"display conntrack entries for ZONE\n"
|
dpctl: Support flush conntrack by conntrack 5-tuple
With this patch, "flush-conntrack" in ovs-dpctl and ovs-appctl accept
a conntrack 5-tuple to delete the conntrack entry specified by the 5-tuple.
For example, user can use the following command to flush a conntrack entry
in zone 5.
$ ovs-dpctl flush-conntrack zone=5 \
'ct_nw_src=10.1.1.2,ct_nw_dst=10.1.1.1,ct_nw_proto=17,ct_tp_src=2,ct_tp_dst=1'
$ ovs-appctl dpctl/flush-conntrack zone=5 \
'ct_nw_src=10.1.1.2,ct_nw_dst=10.1.1.1,ct_nw_proto=17,ct_tp_src=2,ct_tp_dst=1'
VMWare-BZ: #1983178
Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
Signed-off-by: Justin Pettit <jpettit@ovn.org>
2017-12-07 10:40:04 -08:00
|
|
|
" flush-conntrack [DP] [zone=ZONE] [ct-tuple]" \
|
|
|
|
"delete matched conntrack entries in ZONE\n"
|
2017-06-23 13:28:21 +01:00
|
|
|
" ct-stats-show [DP] [zone=ZONE] [verbose] " \
|
|
|
|
"CT connections grouped by protocol\n"
|
2017-08-01 20:12:03 -07:00
|
|
|
" ct-bkts [DP] [gt=N] display connections per CT bucket\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"
|
dpctl: Add add/mod/del-flows command.
When you would like to add, modify, or delete a lot of flows in the
datapath, for example when you want to measure performance, adding
one flow at the time won't scale. This as it takes a decent amount
of time to set up the datapath connection.
This new command is in-line with the same command available in
ovs-ofctl which allows the same thing, with the only difference that
we do not verify all lines before we start execution. This allows for
a continuous add/delete stream. For example with a command like this:
python3 -c 'while True:
for i in range(0, 1000):
print("add in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{}) 1".format(int(i / 256), i % 256))
for i in range(0, 1000):
print("delete in_port(0),eth(),eth_type(0x800),ipv4(src=100.1.{}.{})".format(int(i / 256), i % 256))' \
| sudo utilities/ovs-dpctl add-flows -
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Paolo Valerio <pvalerio@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2020-10-13 10:36:48 +02:00
|
|
|
"For COMMAND dump-flows, add-flow, add-flows, mod-flow,\n"
|
|
|
|
"mod-flows, del-flow and del-flows, DP is optional if there is\n"
|
|
|
|
"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"
|
2017-06-18 09:46:54 +08:00
|
|
|
" --names use port names in 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"
|
2016-08-15 18:47:29 +00:00
|
|
|
" --read-only do not run read/write commands\n"
|
2013-03-15 13:47:53 -07:00
|
|
|
" --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);
|
|
|
|
}
|