summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2017-04-28 08:09:55 -0700
committerBen Pfaff <blp@ovn.org>2017-05-03 16:18:44 -0700
commitc2f4c39be4e288e7a08974aea53b18627a1ef9ef (patch)
treeb08299b10b19ba35b85e220cbdc520e29d684142 /lib
parentbed7aef90248573307020b545711b72b4d868011 (diff)
downloadopenvswitch-c2f4c39be4e288e7a08974aea53b18627a1ef9ef.tar.gz
ovn-sbctl: Add --ovs option to "lflow-list", for listing OpenFlow flows.
This is like the --ovs option to ovn-trace, but it applies to every flow dumped, so it has different applications. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/db-ctl-base.c19
-rw-r--r--lib/db-ctl-base.h11
-rw-r--r--lib/ofp-print.c2
3 files changed, 18 insertions, 14 deletions
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 52e06293e..78393895c 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -1637,11 +1637,11 @@ parse_command(int argc, char *argv[], struct shash *local_options,
const char *s = strstr(p->options, node->name);
int end = s ? s[strlen(node->name)] : EOF;
- if (end != '=' && end != ',' && end != ' ' && end != '\0') {
+ if (!strchr("=,? ", end)) {
ctl_fatal("'%s' command has no '%s' option",
argv[i], node->name);
}
- if ((end == '=') != (node->data != NULL)) {
+ if (end != '?' && (end == '=') != (node->data != NULL)) {
if (end == '=') {
ctl_fatal("missing argument to '%s' option on '%s' "
"command", node->name, argv[i]);
@@ -1913,19 +1913,14 @@ ctl_add_cmd_options(struct option **options_p, size_t *n_options_p,
s = xstrdup(p->options);
for (name = strtok_r(s, ",", &save_ptr); name != NULL;
name = strtok_r(NULL, ",", &save_ptr)) {
- char *equals;
- int has_arg;
-
ovs_assert(name[0] == '-' && name[1] == '-' && name[2]);
name += 2;
- equals = strchr(name, '=');
- if (equals) {
- has_arg = required_argument;
- *equals = '\0';
- } else {
- has_arg = no_argument;
- }
+ size_t n = strcspn(name, "=?");
+ int has_arg = (name[n] == '\0' ? no_argument
+ : name[n] == '=' ? required_argument
+ : optional_argument);
+ name[n] = '\0';
o = find_option(name, *options_p, *n_options_p);
if (o) {
diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h
index e4568a2cf..81f0d0b27 100644
--- a/lib/db-ctl-base.h
+++ b/lib/db-ctl-base.h
@@ -128,7 +128,16 @@ struct ctl_command_syntax {
void (*postprocess)(struct ctl_context *ctx);
/* A comma-separated list of supported options, e.g. "--a,--b", or the
- * empty string if the command does not support any options. */
+ * empty string if the command does not support any options.
+ *
+ * Arguments are determined by appending special characters to option
+ * names:
+ *
+ * - Append "=" (e.g. "--id=") for a required argument.
+ *
+ * - Append "?" (e.g. "--ovs?") for an optional argument.
+ *
+ * - Otherwise an option does not accept an argument. */
const char *options;
enum { RO, RW } mode; /* Does this command modify the database? */
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 10ac053ae..ab07434d0 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -1659,7 +1659,7 @@ ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
}
void
-ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
+ofp_print_flow_stats(struct ds *string, const struct ofputil_flow_stats *fs)
{
ds_put_format(string, " %scookie=%s0x%"PRIx64", %sduration=%s",
colors.param, colors.end, ntohll(fs->cookie),