]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
ac64794a | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. |
064af421 | 3 | * |
a14bc59f BP |
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: | |
064af421 | 7 | * |
a14bc59f BP |
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. | |
064af421 BP |
15 | */ |
16 | ||
17 | #include <config.h> | |
b2befd5b BP |
18 | #include <sys/types.h> |
19 | #include <netinet/in.h> | |
064af421 BP |
20 | #include <arpa/inet.h> |
21 | #include <errno.h> | |
22 | #include <getopt.h> | |
23 | #include <inttypes.h> | |
9d82ec47 | 24 | #include <sys/socket.h> |
064af421 | 25 | #include <net/if.h> |
064af421 BP |
26 | #include <signal.h> |
27 | #include <stdarg.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | #include <unistd.h> | |
31 | #include <sys/stat.h> | |
32 | #include <sys/time.h> | |
33 | ||
34 | #include "command-line.h" | |
35 | #include "compiler.h" | |
36 | #include "dirs.h" | |
fceef209 | 37 | #include "dpctl.h" |
8a777cf6 | 38 | #include "fatal-signal.h" |
064af421 | 39 | #include "odp-util.h" |
becffb86 | 40 | #include "packets.h" |
064af421 BP |
41 | #include "timeval.h" |
42 | #include "util.h" | |
7888d2a6 | 43 | #include "openvswitch/ofp-parse.h" |
e6211adc | 44 | #include "openvswitch/vlog.h" |
5136ce49 | 45 | |
fceef209 | 46 | static struct dpctl_params dpctl_p; |
032aa6a3 | 47 | |
cab50449 | 48 | OVS_NO_RETURN static void usage(void *userdata OVS_UNUSED); |
064af421 BP |
49 | static void parse_options(int argc, char *argv[]); |
50 | ||
fceef209 DDP |
51 | static void |
52 | dpctl_print(void *userdata OVS_UNUSED, bool error, const char *msg) | |
53 | { | |
54 | FILE *outfile = error ? stderr : stdout; | |
55 | fputs(msg, outfile); | |
56 | } | |
57 | ||
675febfa BP |
58 | int |
59 | main(int argc, char *argv[]) | |
064af421 | 60 | { |
fceef209 | 61 | int error; |
064af421 | 62 | set_program_name(argv[0]); |
064af421 | 63 | parse_options(argc, argv); |
8a777cf6 | 64 | fatal_ignore_sigpipe(); |
fceef209 | 65 | |
56cad666 | 66 | dpctl_p.is_appctl = false; |
fceef209 DDP |
67 | dpctl_p.output = dpctl_print; |
68 | dpctl_p.usage = usage; | |
69 | ||
70 | error = dpctl_run_command(argc - optind, (const char **) argv + optind, | |
71 | &dpctl_p); | |
72 | return error ? EXIT_FAILURE : EXIT_SUCCESS; | |
064af421 BP |
73 | } |
74 | ||
75 | static void | |
76 | parse_options(int argc, char *argv[]) | |
77 | { | |
87c84891 | 78 | enum { |
186afbfe BP |
79 | OPT_CLEAR = UCHAR_MAX + 1, |
80 | OPT_MAY_CREATE, | |
1f4a7252 | 81 | OPT_READ_ONLY, |
d1fd1ea9 BP |
82 | OPT_NAMES, |
83 | OPT_NO_NAMES, | |
87c84891 JP |
84 | VLOG_OPTION_ENUMS |
85 | }; | |
07fc4ed3 | 86 | static const struct option long_options[] = { |
e3c17733 | 87 | {"statistics", no_argument, NULL, 's'}, |
186afbfe BP |
88 | {"clear", no_argument, NULL, OPT_CLEAR}, |
89 | {"may-create", no_argument, NULL, OPT_MAY_CREATE}, | |
1f4a7252 | 90 | {"read-only", no_argument, NULL, OPT_READ_ONLY}, |
becffb86 | 91 | {"more", no_argument, NULL, 'm'}, |
d1fd1ea9 BP |
92 | {"names", no_argument, NULL, OPT_NAMES}, |
93 | {"no-names", no_argument, NULL, OPT_NO_NAMES}, | |
e3c17733 BP |
94 | {"timeout", required_argument, NULL, 't'}, |
95 | {"help", no_argument, NULL, 'h'}, | |
66fa2c88 | 96 | {"option", no_argument, NULL, 'o'}, |
e3c17733 | 97 | {"version", no_argument, NULL, 'V'}, |
87c84891 | 98 | VLOG_LONG_OPTIONS, |
e3c17733 | 99 | {NULL, 0, NULL, 0}, |
064af421 | 100 | }; |
5f383751 | 101 | char *short_options = ovs_cmdl_long_options_to_short_options(long_options); |
064af421 | 102 | |
d1fd1ea9 | 103 | bool set_names = false; |
064af421 BP |
104 | for (;;) { |
105 | unsigned long int timeout; | |
106 | int c; | |
107 | ||
108 | c = getopt_long(argc, argv, short_options, long_options, NULL); | |
109 | if (c == -1) { | |
110 | break; | |
111 | } | |
112 | ||
113 | switch (c) { | |
032aa6a3 | 114 | case 's': |
fceef209 | 115 | dpctl_p.print_statistics = true; |
032aa6a3 BP |
116 | break; |
117 | ||
186afbfe | 118 | case OPT_CLEAR: |
fceef209 | 119 | dpctl_p.zero_statistics = true; |
186afbfe BP |
120 | break; |
121 | ||
122 | case OPT_MAY_CREATE: | |
fceef209 | 123 | dpctl_p.may_create = true; |
186afbfe BP |
124 | break; |
125 | ||
1f4a7252 RM |
126 | case OPT_READ_ONLY: |
127 | dpctl_p.read_only = true; | |
128 | break; | |
129 | ||
becffb86 | 130 | case 'm': |
fceef209 | 131 | dpctl_p.verbosity++; |
becffb86 BP |
132 | break; |
133 | ||
d1fd1ea9 BP |
134 | case OPT_NAMES: |
135 | dpctl_p.names = true; | |
136 | set_names = true; | |
137 | break; | |
138 | ||
139 | case OPT_NO_NAMES: | |
140 | dpctl_p.names = false; | |
141 | set_names = true; | |
142 | break; | |
143 | ||
064af421 BP |
144 | case 't': |
145 | timeout = strtoul(optarg, NULL, 10); | |
146 | if (timeout <= 0) { | |
147 | ovs_fatal(0, "value %s on -t or --timeout is not at least 1", | |
148 | optarg); | |
149 | } else { | |
150 | time_alarm(timeout); | |
151 | } | |
152 | break; | |
153 | ||
154 | case 'h': | |
fceef209 | 155 | usage(NULL); |
064af421 | 156 | |
66fa2c88 | 157 | case 'o': |
5f383751 | 158 | ovs_cmdl_print_options(long_options); |
66fa2c88 AW |
159 | exit(EXIT_SUCCESS); |
160 | ||
064af421 | 161 | case 'V': |
55d5bb44 | 162 | ovs_print_version(0, 0); |
064af421 BP |
163 | exit(EXIT_SUCCESS); |
164 | ||
87c84891 | 165 | VLOG_OPTION_HANDLERS |
064af421 BP |
166 | |
167 | case '?': | |
168 | exit(EXIT_FAILURE); | |
169 | ||
170 | default: | |
171 | abort(); | |
172 | } | |
173 | } | |
174 | free(short_options); | |
d1fd1ea9 BP |
175 | |
176 | if (!set_names) { | |
177 | dpctl_p.names = dpctl_p.verbosity > 0; | |
178 | } | |
064af421 BP |
179 | } |
180 | ||
181 | static void | |
fceef209 | 182 | usage(void *userdata OVS_UNUSED) |
064af421 BP |
183 | { |
184 | printf("%s: Open vSwitch datapath management utility\n" | |
185 | "usage: %s [OPTIONS] COMMAND [ARG...]\n" | |
186 | " add-dp DP [IFACE...] add new datapath DP (with IFACEs)\n" | |
187 | " del-dp DP delete local datapath DP\n" | |
188 | " add-if DP IFACE... add each IFACE as a port on DP\n" | |
10500639 | 189 | " set-if DP IFACE... reconfigure each IFACE within DP\n" |
064af421 | 190 | " del-if DP IFACE... delete each IFACE from DP\n" |
b566902b | 191 | " dump-dps display names of all datapaths\n" |
064af421 BP |
192 | " show show basic info on all datapaths\n" |
193 | " show DP... show basic info on each DP\n" | |
2e6d002d GS |
194 | " dump-flows [DP] display flows in DP\n" |
195 | " add-flow [DP] FLOW ACTIONS add FLOW with ACTIONS to DP\n" | |
196 | " mod-flow [DP] FLOW ACTIONS change FLOW actions to ACTIONS in DP\n" | |
818650e6 | 197 | " get-flow [DP] ufid:UFID fetch flow corresponding to UFID\n" |
2e6d002d GS |
198 | " del-flow [DP] FLOW delete FLOW from DP\n" |
199 | " del-flows [DP] delete all flows from DP\n" | |
1401f6de FA |
200 | " dump-conntrack [DP] [zone=ZONE] " \ |
201 | "display conntrack entries for ZONE\n" | |
c43a1331 YHW |
202 | " flush-conntrack [DP] [zone=ZONE] [ct-tuple]" \ |
203 | "delete matched conntrack entries in ZONE\n" | |
8a0d9d85 FA |
204 | " ct-stats-show [DP] [zone=ZONE] [verbose] " \ |
205 | "CT connections grouped by protocol\n" | |
ded30c74 | 206 | " ct-bkts [DP] [gt=N] display connections per CT bucket\n" |
10500639 BP |
207 | "Each IFACE on add-dp, add-if, and set-if may be followed by\n" |
208 | "comma-separated options. See ovs-dpctl(8) for syntax, or the\n" | |
2e6d002d GS |
209 | "Interface table in ovs-vswitchd.conf.db(5) for an options list.\n" |
210 | "For COMMAND dump-flows, add-flow, mod-flow, del-flow and\n" | |
211 | "del-flows, DP is optional if there is only one datapath.\n", | |
064af421 BP |
212 | program_name, program_name); |
213 | vlog_usage(); | |
186afbfe BP |
214 | printf("\nOptions for show and mod-flow:\n" |
215 | " -s, --statistics print statistics for port or flow\n" | |
041e7168 AZ |
216 | "\nOptions for dump-flows:\n" |
217 | " -m, --more increase verbosity of output\n" | |
d1fd1ea9 | 218 | " --names use port names in output\n" |
186afbfe BP |
219 | "\nOptions for mod-flow:\n" |
220 | " --may-create create flow if it doesn't exist\n" | |
1f4a7252 | 221 | " --read-only do not run read/write commands\n" |
186afbfe | 222 | " --clear reset existing stats to zero\n" |
733970eb | 223 | "\nOther options:\n" |
064af421 BP |
224 | " -t, --timeout=SECS give up after SECS seconds\n" |
225 | " -h, --help display this help message\n" | |
226 | " -V, --version display version information\n"); | |
227 | exit(EXIT_SUCCESS); | |
228 | } |