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