Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
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 <sys/socket.h>
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"
36 : : #include "dpctl.h"
37 : : #include "fatal-signal.h"
38 : : #include "odp-util.h"
39 : : #include "packets.h"
40 : : #include "timeval.h"
41 : : #include "util.h"
42 : : #include "openvswitch/ofp-parse.h"
43 : : #include "openvswitch/vlog.h"
44 : :
45 : : static struct dpctl_params dpctl_p;
46 : :
47 : : OVS_NO_RETURN static void usage(void *userdata OVS_UNUSED);
48 : : static void parse_options(int argc, char *argv[]);
49 : :
50 : : static void
51 : 978 : dpctl_print(void *userdata OVS_UNUSED, bool error, const char *msg)
52 : : {
53 [ - + ]: 978 : FILE *outfile = error ? stderr : stdout;
54 : 978 : fputs(msg, outfile);
55 : 978 : }
56 : :
57 : : int
58 : 276 : main(int argc, char *argv[])
59 : : {
60 : : int error;
61 : 276 : set_program_name(argv[0]);
62 : 276 : parse_options(argc, argv);
63 : 274 : fatal_ignore_sigpipe();
64 : :
65 : 274 : dpctl_p.is_appctl = false;
66 : 274 : dpctl_p.output = dpctl_print;
67 : 274 : dpctl_p.usage = usage;
68 : :
69 : 274 : error = dpctl_run_command(argc - optind, (const char **) argv + optind,
70 : : &dpctl_p);
71 : 274 : return error ? EXIT_FAILURE : EXIT_SUCCESS;
72 : : }
73 : :
74 : : static void
75 : 276 : parse_options(int argc, char *argv[])
76 : : {
77 : : enum {
78 : : OPT_CLEAR = UCHAR_MAX + 1,
79 : : OPT_MAY_CREATE,
80 : : OPT_READ_ONLY,
81 : : VLOG_OPTION_ENUMS
82 : : };
83 : : static const struct option long_options[] = {
84 : : {"statistics", no_argument, NULL, 's'},
85 : : {"clear", no_argument, NULL, OPT_CLEAR},
86 : : {"may-create", no_argument, NULL, OPT_MAY_CREATE},
87 : : {"read-only", no_argument, NULL, OPT_READ_ONLY},
88 : : {"more", no_argument, NULL, 'm'},
89 : : {"timeout", required_argument, NULL, 't'},
90 : : {"help", no_argument, NULL, 'h'},
91 : : {"option", no_argument, NULL, 'o'},
92 : : {"version", no_argument, NULL, 'V'},
93 : : VLOG_LONG_OPTIONS,
94 : : {NULL, 0, NULL, 0},
95 : : };
96 : 276 : char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
97 : :
98 : : for (;;) {
99 : : unsigned long int timeout;
100 : : int c;
101 : :
102 : 276 : c = getopt_long(argc, argv, short_options, long_options, NULL);
103 [ + + ]: 276 : if (c == -1) {
104 : 274 : break;
105 : : }
106 : :
107 [ - - - - : 2 : switch (c) {
- - - + -
- - - - -
- ]
108 : : case 's':
109 : 0 : dpctl_p.print_statistics = true;
110 : 0 : break;
111 : :
112 : : case OPT_CLEAR:
113 : 0 : dpctl_p.zero_statistics = true;
114 : 0 : break;
115 : :
116 : : case OPT_MAY_CREATE:
117 : 0 : dpctl_p.may_create = true;
118 : 0 : break;
119 : :
120 : : case OPT_READ_ONLY:
121 : 0 : dpctl_p.read_only = true;
122 : 0 : break;
123 : :
124 : : case 'm':
125 : 0 : dpctl_p.verbosity++;
126 : 0 : break;
127 : :
128 : : case 't':
129 : 0 : timeout = strtoul(optarg, NULL, 10);
130 [ # # ]: 0 : if (timeout <= 0) {
131 : 0 : ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
132 : : optarg);
133 : : } else {
134 : 0 : time_alarm(timeout);
135 : : }
136 : 0 : break;
137 : :
138 : : case 'h':
139 : 0 : usage(NULL);
140 : :
141 : : case 'o':
142 : 2 : ovs_cmdl_print_options(long_options);
143 : 2 : exit(EXIT_SUCCESS);
144 : :
145 : : case 'V':
146 : 0 : ovs_print_version(0, 0);
147 : 0 : exit(EXIT_SUCCESS);
148 : :
149 : 0 : VLOG_OPTION_HANDLERS
150 : :
151 : : case '?':
152 : 0 : exit(EXIT_FAILURE);
153 : :
154 : : default:
155 : 0 : abort();
156 : : }
157 : 0 : }
158 : 274 : free(short_options);
159 : 274 : }
160 : :
161 : : static void
162 : 0 : usage(void *userdata OVS_UNUSED)
163 : : {
164 : 0 : printf("%s: Open vSwitch datapath management utility\n"
165 : : "usage: %s [OPTIONS] COMMAND [ARG...]\n"
166 : : " add-dp DP [IFACE...] add new datapath DP (with IFACEs)\n"
167 : : " del-dp DP delete local datapath DP\n"
168 : : " add-if DP IFACE... add each IFACE as a port on DP\n"
169 : : " set-if DP IFACE... reconfigure each IFACE within DP\n"
170 : : " del-if DP IFACE... delete each IFACE from DP\n"
171 : : " dump-dps display names of all datapaths\n"
172 : : " show show basic info on all datapaths\n"
173 : : " show DP... show basic info on each DP\n"
174 : : " dump-flows [DP] display flows in DP\n"
175 : : " add-flow [DP] FLOW ACTIONS add FLOW with ACTIONS to DP\n"
176 : : " mod-flow [DP] FLOW ACTIONS change FLOW actions to ACTIONS in DP\n"
177 : : " get-flow [DP] ufid:UFID fetch flow corresponding to UFID\n"
178 : : " del-flow [DP] FLOW delete FLOW from DP\n"
179 : : " del-flows [DP] delete all flows from DP\n"
180 : : " dump-conntrack [DP] [zone=ZONE] display conntrack entries for ZONE\n"
181 : : " flush-conntrack [DP] [zone=ZONE] delete all conntrack entries in ZONE\n"
182 : : "Each IFACE on add-dp, add-if, and set-if may be followed by\n"
183 : : "comma-separated options. See ovs-dpctl(8) for syntax, or the\n"
184 : : "Interface table in ovs-vswitchd.conf.db(5) for an options list.\n"
185 : : "For COMMAND dump-flows, add-flow, mod-flow, del-flow and\n"
186 : : "del-flows, DP is optional if there is only one datapath.\n",
187 : : program_name, program_name);
188 : 0 : vlog_usage();
189 : 0 : printf("\nOptions for show and mod-flow:\n"
190 : : " -s, --statistics print statistics for port or flow\n"
191 : : "\nOptions for dump-flows:\n"
192 : : " -m, --more increase verbosity of output\n"
193 : : "\nOptions for mod-flow:\n"
194 : : " --may-create create flow if it doesn't exist\n"
195 : : " --read-only do not run read/write commands\n"
196 : : " --clear reset existing stats to zero\n"
197 : : "\nOther options:\n"
198 : : " -t, --timeout=SECS give up after SECS seconds\n"
199 : : " -h, --help display this help message\n"
200 : : " -V, --version display version information\n");
201 : 0 : exit(EXIT_SUCCESS);
202 : : }
|