* null pointer.
*
* Command-line options should be stripped off, so that a typical invocation
- * looks like "run_command(argc - optind, argv + optind, my_commands);". */
+ * looks like:
+ * struct ovs_cmdl_context ctx = {
+ * .argc = argc - optind,
+ * .argv = argv + optind,
+ * };
+ * ovs_cmdl_run_command(&ctx, my_commands);
+ * */
void
-ovs_cmdl_run_command(int argc, char *argv[], const struct ovs_cmdl_command commands[])
+ovs_cmdl_run_command(struct ovs_cmdl_context *ctx, const struct ovs_cmdl_command commands[])
{
const struct ovs_cmdl_command *p;
- if (argc < 1) {
+ if (ctx->argc < 1) {
ovs_fatal(0, "missing command name; use --help for help");
}
for (p = commands; p->name != NULL; p++) {
- if (!strcmp(p->name, argv[0])) {
- int n_arg = argc - 1;
+ if (!strcmp(p->name, ctx->argv[0])) {
+ int n_arg = ctx->argc - 1;
if (n_arg < p->min_args) {
VLOG_FATAL( "'%s' command requires at least %d arguments",
p->name, p->min_args);
VLOG_FATAL("'%s' command takes at most %d arguments",
p->name, p->max_args);
} else {
- p->handler(argc, argv);
+ p->handler(ctx);
if (ferror(stdout)) {
VLOG_FATAL("write to stdout failed");
}
}
}
- VLOG_FATAL("unknown command '%s'; use --help for help", argv[0]);
+ VLOG_FATAL("unknown command '%s'; use --help for help", ctx->argv[0]);
}
\f
/* Process title. */
struct option;
+/* Command handler context */
+struct ovs_cmdl_context {
+ /* number of command line arguments */
+ int argc;
+ /* array of command line arguments */
+ char **argv;
+ /* private context data defined by the API user */
+ void *pvt;
+};
+
+typedef void (*ovs_cmdl_handler)(struct ovs_cmdl_context *);
+
struct ovs_cmdl_command {
const char *name;
const char *usage;
int min_args;
int max_args;
- void (*handler)(int argc, char *argv[]);
+ ovs_cmdl_handler handler;
};
char *ovs_cmdl_long_options_to_short_options(const struct option *options);
void ovs_cmdl_print_options(const struct option *options);
void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands);
-void ovs_cmdl_run_command(int argc, char *argv[], const struct ovs_cmdl_command[]);
+void ovs_cmdl_run_command(struct ovs_cmdl_context *, const struct ovs_cmdl_command[]);
void ovs_cmdl_proctitle_init(int argc, char **argv);
#if defined(__FreeBSD__) || defined(__NetBSD__)
int
main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = { .argc = 0, };
set_program_name(argv[0]);
parse_options(argc, argv);
fatal_ignore_sigpipe();
- ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
+ ctx.argc = argc - optind;
+ ctx.argv = argv + optind;
+ ovs_cmdl_run_command(&ctx, get_all_commands());
return 0;
}
}
\f
static void
-do_create(int argc, char *argv[])
+do_create(struct ovs_cmdl_context *ctx)
{
- const char *db_file_name = argc >= 2 ? argv[1] : default_db();
- const char *schema_file_name = argc >= 3 ? argv[2] : default_schema();
+ const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
+ const char *schema_file_name = ctx->argc >= 3 ? ctx->argv[2] : default_schema();
struct ovsdb_schema *schema;
struct ovsdb_log *log;
struct json *json;
}
static void
-do_compact(int argc, char *argv[])
+do_compact(struct ovs_cmdl_context *ctx)
{
- const char *db = argc >= 2 ? argv[1] : default_db();
- const char *target = argc >= 3 ? argv[2] : NULL;
+ const char *db = ctx->argc >= 2 ? ctx->argv[1] : default_db();
+ const char *target = ctx->argc >= 3 ? ctx->argv[2] : NULL;
compact_or_convert(db, target, NULL, "compacted by ovsdb-tool "VERSION);
}
static void
-do_convert(int argc, char *argv[])
+do_convert(struct ovs_cmdl_context *ctx)
{
- const char *db = argc >= 2 ? argv[1] : default_db();
- const char *schema = argc >= 3 ? argv[2] : default_schema();
- const char *target = argc >= 4 ? argv[3] : NULL;
+ const char *db = ctx->argc >= 2 ? ctx->argv[1] : default_db();
+ const char *schema = ctx->argc >= 3 ? ctx->argv[2] : default_schema();
+ const char *target = ctx->argc >= 4 ? ctx->argv[3] : NULL;
struct ovsdb_schema *new_schema;
check_ovsdb_error(ovsdb_schema_from_file(schema, &new_schema));
}
static void
-do_needs_conversion(int argc, char *argv[])
+do_needs_conversion(struct ovs_cmdl_context *ctx)
{
- const char *db_file_name = argc >= 2 ? argv[1] : default_db();
- const char *schema_file_name = argc >= 3 ? argv[2] : default_schema();
+ const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
+ const char *schema_file_name = ctx->argc >= 3 ? ctx->argv[2] : default_schema();
struct ovsdb_schema *schema1, *schema2;
check_ovsdb_error(ovsdb_file_read_schema(db_file_name, &schema1));
}
static void
-do_db_version(int argc, char *argv[])
+do_db_version(struct ovs_cmdl_context *ctx)
{
- const char *db_file_name = argc >= 2 ? argv[1] : default_db();
+ const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
struct ovsdb_schema *schema;
check_ovsdb_error(ovsdb_file_read_schema(db_file_name, &schema));
}
static void
-do_db_cksum(int argc OVS_UNUSED, char *argv[])
+do_db_cksum(struct ovs_cmdl_context *ctx)
{
- const char *db_file_name = argc >= 2 ? argv[1] : default_db();
+ const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
struct ovsdb_schema *schema;
check_ovsdb_error(ovsdb_file_read_schema(db_file_name, &schema));
}
static void
-do_schema_version(int argc, char *argv[])
+do_schema_version(struct ovs_cmdl_context *ctx)
{
- const char *schema_file_name = argc >= 2 ? argv[1] : default_schema();
+ const char *schema_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_schema();
struct ovsdb_schema *schema;
check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, &schema));
}
static void
-do_schema_cksum(int argc, char *argv[])
+do_schema_cksum(struct ovs_cmdl_context *ctx)
{
- const char *schema_file_name = argc >= 2 ? argv[1] : default_schema();
+ const char *schema_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_schema();
struct ovsdb_schema *schema;
check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, &schema));
}
static void
-do_query(int argc, char *argv[])
+do_query(struct ovs_cmdl_context *ctx)
{
- transact(true, argc, argv);
+ transact(true, ctx->argc, ctx->argv);
}
static void
-do_transact(int argc, char *argv[])
+do_transact(struct ovs_cmdl_context *ctx)
{
- transact(false, argc, argv);
+ transact(false, ctx->argc, ctx->argv);
}
static void
}
static void
-do_show_log(int argc, char *argv[])
+do_show_log(struct ovs_cmdl_context *ctx)
{
- const char *db_file_name = argc >= 2 ? argv[1] : default_db();
+ const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
struct shash names;
struct ovsdb_log *log;
struct ovsdb_schema *schema;
}
static void
-do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
usage();
}
static void
-do_list_commands(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_list_commands(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
ovs_cmdl_print_commands(get_all_commands());
}
}
static void
-help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+help(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
const struct ovs_cmdl_command *p;
struct ds test_names = DS_EMPTY_INITIALIZER;
}
void
-ovstest_register(const char *test_name, ovstest_func f)
+ovstest_register(const char *test_name, ovs_cmdl_handler f)
{
struct ovs_cmdl_command test_cmd;
add_top_level_commands();
if (argc > 1) {
- ovs_cmdl_run_command(argc - 1, argv + 1, commands);
+ struct ovs_cmdl_context ctx = {
+ .argc = argc - 1,
+ .argv = argv + 1,
+ };
+ ovs_cmdl_run_command(&ctx, commands);
}
cleanup();
#include "compiler.h"
+#include "command-line.h"
+
/* Overview
* ========
*
*/
typedef void (*ovstest_func)(int argc, char *argv[]);
-void ovstest_register(const char *test_name, ovstest_func f);
+
+void ovstest_register(const char *test_name, ovs_cmdl_handler f);
/* Usage
* =====
* OVSTEST_REGISTER("my-test", my_test_main);
*/
#define OVSTEST_REGISTER(name, function) \
+ static void \
+ ovstest_wrapper_##function##__(struct ovs_cmdl_context *ctx) \
+ { \
+ function(ctx->argc, ctx->argv); \
+ } \
OVS_CONSTRUCTOR(register_##function) { \
- ovstest_register(name, function); \
+ ovstest_register(name, ovstest_wrapper_##function##__); \
}
#endif
}
static void
-run_tests(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+run_tests(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
run_test(test_bitmap_equal);
run_test(test_bitmap_scan);
}
static void
-run_benchmarks(int argc OVS_UNUSED, char *argv[])
+run_benchmarks(struct ovs_cmdl_context *ctx)
{
- int n_iter = strtol(argv[1], NULL, 10);
+ int n_iter = strtol(ctx->argv[1], NULL, 10);
struct timeval start;
xgettimeofday(&start);
static void
test_bitmap_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = {
+ .argc = argc - 1,
+ .argv = argv + 1,
+ };
+
set_program_name(argv[0]);
- ovs_cmdl_run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(&ctx, commands);
}
OVSTEST_REGISTER("test-bitmap", test_bitmap_main);
/* Tests an empty classifier. */
static void
-test_empty(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_empty(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct classifier cls;
struct tcls tcls;
/* Destroys a null classifier. */
static void
-test_destroy_null(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_destroy_null(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
classifier_destroy(NULL);
}
/* Tests classification with one rule at a time. */
static void
-test_single_rule(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_single_rule(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned int wc_fields; /* Hilarious. */
/* Tests replacing one rule by another. */
static void
-test_rule_replacement(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_rule_replacement(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned int wc_fields;
/* Tests classification with rules that have the same matching criteria. */
static void
-test_many_rules_in_one_list (int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_many_rules_in_one_list (struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_RULES = 3 };
int n_pris;
/* Tests classification with two rules at a time that fall into the same
* table but different lists. */
static void
-test_many_rules_in_one_table(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_many_rules_in_one_table(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int iteration;
}
static void
-test_many_rules_in_two_tables(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_many_rules_in_two_tables(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
test_many_rules_in_n_tables(2);
}
static void
-test_many_rules_in_five_tables(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_many_rules_in_five_tables(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
test_many_rules_in_n_tables(5);
}
}
static void
-test_miniflow(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_miniflow(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct flow flow;
unsigned int idx;
}
static void
-test_minimask_has_extra(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_minimask_has_extra(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct flow_wildcards catchall;
struct minimask minicatchall;
}
static void
-test_minimask_combine(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_minimask_combine(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct flow_wildcards catchall;
struct minimask minicatchall;
static void
test_classifier_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = {
+ .argc = argc - 1,
+ .argv = argv + 1,
+ };
set_program_name(argv[0]);
init_values();
- ovs_cmdl_run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(&ctx, commands);
}
OVSTEST_REGISTER("test-classifier", test_classifier_main);
}
static void
-run_tests(int argc, char *argv[])
+run_tests(struct ovs_cmdl_context *ctx)
{
int n;
int i;
- n = argc >= 2 ? atoi(argv[1]) : 100;
+ n = ctx->argc >= 2 ? atoi(ctx->argv[1]) : 100;
for (i = 0; i < n; i++) {
run_test(test_cmap_insert_replace_delete);
}
}
static void
-run_benchmarks(int argc, char *argv[] OVS_UNUSED)
+run_benchmarks(struct ovs_cmdl_context *ctx)
{
- n_elems = strtol(argv[1], NULL, 10);
- n_threads = strtol(argv[2], NULL, 10);
- mutation_frac = strtod(argv[3], NULL) / 100.0 * UINT32_MAX;
- n_batch = argc > 4 ? strtol(argv[4], NULL, 10) : 1;
+ n_elems = strtol(ctx->argv[1], NULL, 10);
+ n_threads = strtol(ctx->argv[2], NULL, 10);
+ mutation_frac = strtod(ctx->argv[3], NULL) / 100.0 * UINT32_MAX;
+ n_batch = ctx->argc > 4 ? strtol(ctx->argv[4], NULL, 10) : 1;
if (n_batch > N_BATCH_MAX) {
n_batch = N_BATCH_MAX;
};
static void
-test_cmap_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_cmap_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = {
+ .argc = argc - optind,
+ .argv = argv + optind,
+ };
+
set_program_name(argv[0]);
- ovs_cmdl_run_command(argc - optind, argv + optind, commands);
+ ovs_cmdl_run_command(&ctx, commands);
}
OVSTEST_REGISTER("test-cmap", test_cmap_main);
}
static void
-test_heap_insert_delete_same_order(int argc OVS_UNUSED,
- char *argv[] OVS_UNUSED)
+test_heap_insert_delete_same_order(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_ELEMS = 7 };
}
static void
-test_heap_insert_delete_reverse_order(int argc OVS_UNUSED,
- char *argv[] OVS_UNUSED)
+test_heap_insert_delete_reverse_order(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_ELEMS = 7 };
}
static void
-test_heap_insert_delete_every_order(int argc OVS_UNUSED,
- char *argv[] OVS_UNUSED)
+test_heap_insert_delete_every_order(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_ELEMS = 5 };
}
static void
-test_heap_insert_delete_same_order_with_dups(int argc OVS_UNUSED,
- char *argv[] OVS_UNUSED)
+test_heap_insert_delete_same_order_with_dups(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_ELEMS = 7 };
}
static void
-test_heap_raw_insert(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_heap_raw_insert(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_ELEMS = 7 };
}
static void
-test_heap_raw_delete(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_heap_raw_delete(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
enum { N_ELEMS = 16 };
static void
test_heap_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = {
+ .argc = argc - 1,
+ .argv = argv + 1,
+ };
+
set_program_name(argv[0]);
- ovs_cmdl_run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(&ctx, commands);
}
OVSTEST_REGISTER("test-heap", test_heap_main);
static void
test_jsonrpc_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = { .argc = 0, };
ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
service_start(&argc, &argv);
parse_options(argc, argv);
- ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
+ ctx.argc = argc - optind;
+ ctx.argv = argv + optind;
+ ovs_cmdl_run_command(&ctx, get_all_commands());
}
static void
}
static void
-do_listen(int argc OVS_UNUSED, char *argv[])
+do_listen(struct ovs_cmdl_context *ctx)
{
struct pstream *pstream;
struct jsonrpc **rpcs;
bool done;
int error;
- error = jsonrpc_pstream_open(argv[1], &pstream, DSCP_DEFAULT);
+ error = jsonrpc_pstream_open(ctx->argv[1], &pstream, DSCP_DEFAULT);
if (error) {
- ovs_fatal(error, "could not listen on \"%s\"", argv[1]);
+ ovs_fatal(error, "could not listen on \"%s\"", ctx->argv[1]);
}
daemonize();
}
static void
-do_request(int argc OVS_UNUSED, char *argv[])
+do_request(struct ovs_cmdl_context *ctx)
{
struct jsonrpc_msg *msg;
struct jsonrpc *rpc;
char *string;
int error;
- method = argv[2];
- params = parse_json(argv[3]);
+ method = ctx->argv[2];
+ params = parse_json(ctx->argv[3]);
msg = jsonrpc_create_request(method, params, NULL);
string = jsonrpc_msg_is_valid(msg);
if (string) {
ovs_fatal(0, "not a valid JSON-RPC request: %s", string);
}
- error = stream_open_block(jsonrpc_stream_open(argv[1], &stream,
+ error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream,
DSCP_DEFAULT), &stream);
if (error) {
- ovs_fatal(error, "could not open \"%s\"", argv[1]);
+ ovs_fatal(error, "could not open \"%s\"", ctx->argv[1]);
}
rpc = jsonrpc_open(stream);
}
static void
-do_notify(int argc OVS_UNUSED, char *argv[])
+do_notify(struct ovs_cmdl_context *ctx)
{
struct jsonrpc_msg *msg;
struct jsonrpc *rpc;
char *string;
int error;
- method = argv[2];
- params = parse_json(argv[3]);
+ method = ctx->argv[2];
+ params = parse_json(ctx->argv[3]);
msg = jsonrpc_create_notify(method, params);
string = jsonrpc_msg_is_valid(msg);
if (string) {
ovs_fatal(0, "not a JSON RPC-valid notification: %s", string);
}
- error = stream_open_block(jsonrpc_stream_open(argv[1], &stream,
+ error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream,
DSCP_DEFAULT), &stream);
if (error) {
- ovs_fatal(error, "could not open \"%s\"", argv[1]);
+ ovs_fatal(error, "could not open \"%s\"", ctx->argv[1]);
}
rpc = jsonrpc_open(stream);
}
static void
-do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
usage();
}
int
main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = { .argc = 0, };
set_program_name(argv[0]);
parse_options(argc, argv);
- ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
+ ctx.argc = argc - optind;
+ ctx.argv = argv + optind;
+ ovs_cmdl_run_command(&ctx, get_all_commands());
return 0;
}
/* Command implementations. */
static void
-do_log_io(int argc, char *argv[])
+do_log_io(struct ovs_cmdl_context *ctx)
{
- const char *name = argv[1];
- char *mode_string = argv[2];
+ const char *name = ctx->argv[1];
+ char *mode_string = ctx->argv[2];
struct ovsdb_error *error;
enum ovsdb_log_open_mode mode;
check_ovsdb_error(ovsdb_log_open(name, mode, -1, &log));
printf("%s: open successful\n", name);
- for (i = 3; i < argc; i++) {
- const char *command = argv[i];
+ for (i = 3; i < ctx->argc; i++) {
+ const char *command = ctx->argv[i];
if (!strcmp(command, "read")) {
struct json *json;
}
static void
-do_default_atoms(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_default_atoms(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int type;
}
static void
-do_default_data(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_default_data(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned int n_min;
int key, value;
}
static void
-do_parse_atomic_type(int argc OVS_UNUSED, char *argv[])
+do_parse_atomic_type(struct ovs_cmdl_context *ctx)
{
enum ovsdb_atomic_type type;
struct json *json;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
json_destroy(json);
print_and_free_json(ovsdb_atomic_type_to_json(type));
}
static void
-do_parse_base_type(int argc OVS_UNUSED, char *argv[])
+do_parse_base_type(struct ovs_cmdl_context *ctx)
{
struct ovsdb_base_type base;
struct json *json;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
json_destroy(json);
print_and_free_json(ovsdb_base_type_to_json(&base));
}
static void
-do_parse_type(int argc OVS_UNUSED, char *argv[])
+do_parse_type(struct ovs_cmdl_context *ctx)
{
struct ovsdb_type type;
struct json *json;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_type_from_json(&type, json));
json_destroy(json);
print_and_free_json(ovsdb_type_to_json(&type));
}
static void
-do_parse_atoms(int argc, char *argv[])
+do_parse_atoms(struct ovs_cmdl_context *ctx)
{
struct ovsdb_base_type base;
struct json *json;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
json_destroy(json);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
struct ovsdb_error *error;
union ovsdb_atom atom;
- json = unbox_json(parse_json(argv[i]));
+ json = unbox_json(parse_json(ctx->argv[i]));
error = ovsdb_atom_from_json(&atom, &base, json, NULL);
json_destroy(json);
}
static void
-do_parse_atom_strings(int argc, char *argv[])
+do_parse_atom_strings(struct ovs_cmdl_context *ctx)
{
struct ovsdb_base_type base;
struct json *json;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
json_destroy(json);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
union ovsdb_atom atom;
struct ds out;
- die_if_error(ovsdb_atom_from_string(&atom, &base, argv[i], NULL));
+ die_if_error(ovsdb_atom_from_string(&atom, &base, ctx->argv[i], NULL));
ds_init(&out);
ovsdb_atom_to_string(&atom, base.type, &out);
}
static void
-do_parse_data(int argc, char *argv[])
+do_parse_data(struct ovs_cmdl_context *ctx)
{
- do_parse_data__(argc, argv, ovsdb_datum_from_json);
+ do_parse_data__(ctx->argc, ctx->argv, ovsdb_datum_from_json);
}
static void
-do_parse_data_strings(int argc, char *argv[])
+do_parse_data_strings(struct ovs_cmdl_context *ctx)
{
struct ovsdb_type type;
struct json *json;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_type_from_json(&type, json));
json_destroy(json);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
struct ovsdb_datum datum;
struct ds out;
- die_if_error(ovsdb_datum_from_string(&datum, &type, argv[i], NULL));
+ die_if_error(ovsdb_datum_from_string(&datum, &type, ctx->argv[i], NULL));
ds_init(&out);
ovsdb_datum_to_string(&datum, &type, &out);
}
static void
-do_sort_atoms(int argc OVS_UNUSED, char *argv[])
+do_sort_atoms(struct ovs_cmdl_context *ctx)
{
struct ovsdb_base_type base;
union ovsdb_atom *atoms;
size_t n_atoms;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
json_destroy(json);
- json = unbox_json(parse_json(argv[2]));
+ json = unbox_json(parse_json(ctx->argv[2]));
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "second argument must be array");
}
}
static void
-do_parse_column(int argc OVS_UNUSED, char *argv[])
+do_parse_column(struct ovs_cmdl_context *ctx)
{
struct ovsdb_column *column;
struct json *json;
- json = parse_json(argv[2]);
- check_ovsdb_error(ovsdb_column_from_json(json, argv[1], &column));
+ json = parse_json(ctx->argv[2]);
+ check_ovsdb_error(ovsdb_column_from_json(json, ctx->argv[1], &column));
json_destroy(json);
print_and_free_json(ovsdb_column_to_json(column));
ovsdb_column_destroy(column);
}
static void
-do_parse_table(int argc OVS_UNUSED, char *argv[])
+do_parse_table(struct ovs_cmdl_context *ctx)
{
struct ovsdb_table_schema *ts;
bool default_is_root;
struct json *json;
- default_is_root = argc > 3 && !strcmp(argv[3], "true");
+ default_is_root = ctx->argc > 3 && !strcmp(ctx->argv[3], "true");
- json = parse_json(argv[2]);
- check_ovsdb_error(ovsdb_table_schema_from_json(json, argv[1], &ts));
+ json = parse_json(ctx->argv[2]);
+ check_ovsdb_error(ovsdb_table_schema_from_json(json, ctx->argv[1], &ts));
json_destroy(json);
print_and_free_json(ovsdb_table_schema_to_json(ts, default_is_root));
ovsdb_table_schema_destroy(ts);
}
static void
-do_parse_rows(int argc, char *argv[])
+do_parse_rows(struct ovs_cmdl_context *ctx)
{
struct ovsdb_column_set all_columns;
struct ovsdb_table_schema *ts;
struct json *json;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
ovsdb_column_set_init(&all_columns);
ovsdb_column_set_add_all(&all_columns, table);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
struct ovsdb_column_set columns;
struct ovsdb_row *row;
ovsdb_column_set_init(&columns);
row = ovsdb_row_create(table);
- json = unbox_json(parse_json(argv[i]));
+ json = unbox_json(parse_json(ctx->argv[i]));
check_ovsdb_error(ovsdb_row_from_json(row, json, NULL, &columns));
json_destroy(json);
}
static void
-do_compare_rows(int argc, char *argv[])
+do_compare_rows(struct ovs_cmdl_context *ctx)
{
struct ovsdb_column_set all_columns;
struct ovsdb_table_schema *ts;
int n_rows;
int i, j;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
ovsdb_column_set_init(&all_columns);
ovsdb_column_set_add_all(&all_columns, table);
- n_rows = argc - 2;
+ n_rows = ctx->argc - 2;
rows = xmalloc(sizeof *rows * n_rows);
names = xmalloc(sizeof *names * n_rows);
for (i = 0; i < n_rows; i++) {
rows[i] = ovsdb_row_create(table);
- json = parse_json(argv[i + 2]);
+ json = parse_json(ctx->argv[i + 2]);
if (json->type != JSON_ARRAY || json->u.array.n != 2
|| json->u.array.elems[0]->type != JSON_STRING) {
ovs_fatal(0, "\"%s\" does not have expected form "
- "[\"name\", {data}]", argv[i]);
+ "[\"name\", {data}]", ctx->argv[i]);
}
names[i] = xstrdup(json->u.array.elems[0]->u.string);
check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[1],
}
static void
-do_parse_conditions(int argc, char *argv[])
+do_parse_conditions(struct ovs_cmdl_context *ctx)
{
struct ovsdb_table_schema *ts;
struct json *json;
int exit_code = 0;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
struct ovsdb_condition cnd;
struct ovsdb_error *error;
- json = parse_json(argv[i]);
+ json = parse_json(ctx->argv[i]);
error = ovsdb_condition_from_json(ts, json, NULL, &cnd);
if (!error) {
print_and_free_json(ovsdb_condition_to_json(&cnd));
}
static void
-do_evaluate_conditions(int argc OVS_UNUSED, char *argv[])
+do_evaluate_conditions(struct ovs_cmdl_context *ctx)
{
struct ovsdb_table_schema *ts;
struct ovsdb_table *table;
size_t i, j;
/* Parse table schema, create table. */
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
table = ovsdb_table_create(ts);
/* Parse conditions. */
- json = parse_json(argv[2]);
+ json = parse_json(ctx->argv[2]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "CONDITION argument is not JSON array");
}
json_destroy(json);
/* Parse rows. */
- json = parse_json(argv[3]);
+ json = parse_json(ctx->argv[3]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "ROW argument is not JSON array");
}
}
static void
-do_parse_mutations(int argc, char *argv[])
+do_parse_mutations(struct ovs_cmdl_context *ctx)
{
struct ovsdb_table_schema *ts;
struct json *json;
int exit_code = 0;
int i;
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
struct ovsdb_mutation_set set;
struct ovsdb_error *error;
- json = parse_json(argv[i]);
+ json = parse_json(ctx->argv[i]);
error = ovsdb_mutation_set_from_json(ts, json, NULL, &set);
if (!error) {
print_and_free_json(ovsdb_mutation_set_to_json(&set));
}
static void
-do_execute_mutations(int argc OVS_UNUSED, char *argv[])
+do_execute_mutations(struct ovs_cmdl_context *ctx)
{
struct ovsdb_table_schema *ts;
struct ovsdb_table *table;
size_t i, j;
/* Parse table schema, create table. */
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
table = ovsdb_table_create(ts);
/* Parse mutations. */
- json = parse_json(argv[2]);
+ json = parse_json(ctx->argv[2]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "MUTATION argument is not JSON array");
}
json_destroy(json);
/* Parse rows. */
- json = parse_json(argv[3]);
+ json = parse_json(ctx->argv[3]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "ROW argument is not JSON array");
}
}
static void
-do_query(int argc OVS_UNUSED, char *argv[])
+do_query(struct ovs_cmdl_context *ctx)
{
struct do_query_cbdata cbdata;
struct ovsdb_table_schema *ts;
size_t i;
/* Parse table schema, create table. */
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
table = ovsdb_table_create(ts);
/* Parse rows, add to table. */
- json = parse_json(argv[2]);
+ json = parse_json(ctx->argv[2]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "ROW argument is not JSON array");
}
json_destroy(json);
/* Parse conditions and execute queries. */
- json = parse_json(argv[3]);
+ json = parse_json(ctx->argv[3]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "CONDITION argument is not JSON array");
}
};
static void
-do_query_distinct(int argc OVS_UNUSED, char *argv[])
+do_query_distinct(struct ovs_cmdl_context *ctx)
{
struct ovsdb_column_set columns;
struct ovsdb_table_schema *ts;
size_t i;
/* Parse table schema, create table. */
- json = unbox_json(parse_json(argv[1]));
+ json = unbox_json(parse_json(ctx->argv[1]));
check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
json_destroy(json);
table = ovsdb_table_create(ts);
/* Parse column set. */
- json = parse_json(argv[4]);
+ json = parse_json(ctx->argv[4]);
check_ovsdb_error(ovsdb_column_set_from_json(json, table->schema,
&columns));
json_destroy(json);
/* Parse rows, add to table. */
- json = parse_json(argv[2]);
+ json = parse_json(ctx->argv[2]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "ROW argument is not JSON array");
}
json_destroy(json);
/* Parse conditions and execute queries. */
- json = parse_json(argv[3]);
+ json = parse_json(ctx->argv[3]);
if (json->type != JSON_ARRAY) {
ovs_fatal(0, "CONDITION argument is not JSON array");
}
}
static void
-do_parse_schema(int argc OVS_UNUSED, char *argv[])
+do_parse_schema(struct ovs_cmdl_context *ctx)
{
struct ovsdb_schema *schema;
struct json *json;
- json = parse_json(argv[1]);
+ json = parse_json(ctx->argv[1]);
check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
json_destroy(json);
print_and_free_json(ovsdb_schema_to_json(schema));
}
static void
-do_execute(int argc OVS_UNUSED, char *argv[])
+do_execute(struct ovs_cmdl_context *ctx)
{
struct ovsdb_schema *schema;
struct json *json;
int i;
/* Create database. */
- json = parse_json(argv[1]);
+ json = parse_json(ctx->argv[1]);
check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
json_destroy(json);
db = ovsdb_create(schema);
- for (i = 2; i < argc; i++) {
+ for (i = 2; i < ctx->argc; i++) {
struct json *params, *result;
char *s;
- params = parse_json(argv[i]);
+ params = parse_json(ctx->argv[i]);
result = ovsdb_execute(db, NULL, params, 0, NULL);
s = json_to_string(result, JSSF_SORT);
printf("%s\n", s);
}
static void
-do_trigger(int argc OVS_UNUSED, char *argv[])
+do_trigger(struct ovs_cmdl_context *ctx)
{
struct ovsdb_schema *schema;
struct ovsdb_session session;
int i;
/* Create database. */
- json = parse_json(argv[1]);
+ json = parse_json(ctx->argv[1]);
check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
json_destroy(json);
db = ovsdb_create(schema);
now = 0;
number = 0;
- for (i = 2; i < argc; i++) {
- struct json *params = parse_json(argv[i]);
+ for (i = 2; i < ctx->argc; i++) {
+ struct json *params = parse_json(ctx->argv[i]);
if (params->type == JSON_ARRAY
&& json_array(params)->n == 2
&& json_array(params)->elems[0]->type == JSON_STRING
}
static void
-do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
usage();
}
static struct ovsdb_table *do_transact_table;
static void
-do_transact_commit(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_transact_commit(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
ovsdb_error_destroy(ovsdb_txn_commit(do_transact_txn, false));
do_transact_txn = NULL;
}
static void
-do_transact_abort(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_transact_abort(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
ovsdb_txn_abort(do_transact_txn);
do_transact_txn = NULL;
}
static void
-do_transact_insert(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_transact_insert(struct ovs_cmdl_context *ctx)
{
struct ovsdb_row *row;
struct uuid *uuid;
/* Set UUID. */
uuid = ovsdb_row_get_uuid_rw(row);
- uuid_from_integer(atoi(argv[1]), uuid);
+ uuid_from_integer(atoi(ctx->argv[1]), uuid);
if (ovsdb_table_get_row(do_transact_table, uuid)) {
ovs_fatal(0, "table already contains row with UUID "UUID_FMT,
UUID_ARGS(uuid));
}
- do_transact_set_i_j(row, argv[2], argv[3]);
+ do_transact_set_i_j(row, ctx->argv[2], ctx->argv[3]);
/* Insert row. */
ovsdb_txn_row_insert(do_transact_txn, row);
}
static void
-do_transact_delete(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_transact_delete(struct ovs_cmdl_context *ctx)
{
- const struct ovsdb_row *row = do_transact_find_row(argv[1]);
+ const struct ovsdb_row *row = do_transact_find_row(ctx->argv[1]);
ovsdb_txn_row_delete(do_transact_txn, row);
}
static void
-do_transact_modify(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_transact_modify(struct ovs_cmdl_context *ctx)
{
const struct ovsdb_row *row_ro;
struct ovsdb_row *row_rw;
- row_ro = do_transact_find_row(argv[1]);
+ row_ro = do_transact_find_row(ctx->argv[1]);
row_rw = ovsdb_txn_row_modify(do_transact_txn, row_ro);
- do_transact_set_i_j(row_rw, argv[2], argv[3]);
+ do_transact_set_i_j(row_rw, ctx->argv[2], ctx->argv[3]);
}
static int
}
static void
-do_transact_print(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_transact_print(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
const struct ovsdb_row **rows;
const struct ovsdb_row *row;
}
static void
-do_transact(int argc, char *argv[])
+do_transact(struct ovs_cmdl_context *ctx)
{
static const struct ovs_cmdl_command do_transact_commands[] = {
{ "commit", NULL, 0, 0, do_transact_commit },
do_transact_table = ovsdb_get_table(do_transact_db, "mytable");
assert(do_transact_table != NULL);
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < ctx->argc; i++) {
struct json *command;
size_t n_args;
char **args;
int j;
+ struct ovs_cmdl_context transact_ctx = { .argc = 0, };
- command = parse_json(argv[i]);
+ command = parse_json(ctx->argv[i]);
if (command->type != JSON_ARRAY) {
ovs_fatal(0, "transaction %d must be JSON array "
"with at least 1 element", i);
fputs(args[j], stdout);
}
fputs(":", stdout);
- ovs_cmdl_run_command(n_args, args, do_transact_commands);
+ transact_ctx.argc = n_args;
+ transact_ctx.argv = args;
+ ovs_cmdl_run_command(&transact_ctx, do_transact_commands);
putchar('\n');
for (j = 0; j < n_args; j++) {
}
static void
-do_idl(int argc, char *argv[])
+do_idl(struct ovs_cmdl_context *ctx)
{
struct jsonrpc *rpc;
struct ovsdb_idl *idl;
idltest_init();
- idl = ovsdb_idl_create(argv[1], &idltest_idl_class, true, true);
- if (argc > 2) {
+ idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true);
+ if (ctx->argc > 2) {
struct stream *stream;
- error = stream_open_block(jsonrpc_stream_open(argv[1], &stream,
+ error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream,
DSCP_DEFAULT), &stream);
if (error) {
- ovs_fatal(error, "failed to connect to \"%s\"", argv[1]);
+ ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]);
}
rpc = jsonrpc_open(stream);
} else {
setvbuf(stdout, NULL, _IONBF, 0);
symtab = ovsdb_symbol_table_create();
- for (i = 2; i < argc; i++) {
- char *arg = argv[i];
+ for (i = 2; i < ctx->argc; i++) {
+ char *arg = ctx->argv[i];
struct jsonrpc_msg *request, *reply;
if (*arg == '+') {
svec_parse_words(&args, line);
svec_terminate(&args);
if (!svec_is_empty(&args)) {
- ovs_cmdl_run_command(args.n, args.names, get_all_commands());
+ struct ovs_cmdl_context ctx = {
+ .argc = args.n,
+ .argv = args.names,
+ };
+ ovs_cmdl_run_command(&ctx, get_all_commands());
}
svec_destroy(&args);
}
static void
-do_enable(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_enable(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_enable(reconnect, now);
}
static void
-do_disable(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_disable(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_disable(reconnect, now);
}
static void
-do_force_reconnect(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_force_reconnect(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_force_reconnect(reconnect, now);
}
}
static void
-do_disconnected(int argc OVS_UNUSED, char *argv[])
+do_disconnected(struct ovs_cmdl_context *ctx)
{
- reconnect_disconnected(reconnect, now, error_from_string(argv[1]));
+ reconnect_disconnected(reconnect, now, error_from_string(ctx->argv[1]));
}
static void
-do_connecting(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_connecting(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_connecting(reconnect, now);
}
static void
-do_connect_failed(int argc OVS_UNUSED, char *argv[])
+do_connect_failed(struct ovs_cmdl_context *ctx)
{
- reconnect_connect_failed(reconnect, now, error_from_string(argv[1]));
+ reconnect_connect_failed(reconnect, now, error_from_string(ctx->argv[1]));
}
static void
-do_connected(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_connected(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_connected(reconnect, now);
}
static void
-do_activity(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_activity(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_activity(reconnect, now);
}
static void
-do_run(int argc, char *argv[])
+do_run(struct ovs_cmdl_context *ctx)
{
enum reconnect_action action;
- if (argc > 1) {
- now += atoi(argv[1]);
+ if (ctx->argc > 1) {
+ now += atoi(ctx->argv[1]);
}
action = reconnect_run(reconnect, now);
}
static void
-do_advance(int argc OVS_UNUSED, char *argv[])
+do_advance(struct ovs_cmdl_context *ctx)
{
- now += atoi(argv[1]);
+ now += atoi(ctx->argv[1]);
}
static void
-do_timeout(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_timeout(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int timeout = reconnect_timeout(reconnect, now);
if (timeout >= 0) {
}
static void
-do_set_max_tries(int argc OVS_UNUSED, char *argv[])
+do_set_max_tries(struct ovs_cmdl_context *ctx)
{
- reconnect_set_max_tries(reconnect, atoi(argv[1]));
+ reconnect_set_max_tries(reconnect, atoi(ctx->argv[1]));
}
static void
}
static void
-do_set_passive(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_set_passive(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_set_passive(reconnect, true, now);
}
static void
-do_listening(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+do_listening(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
reconnect_listening(reconnect, now);
}
static void
-do_listen_error(int argc OVS_UNUSED, char *argv[])
+do_listen_error(struct ovs_cmdl_context *ctx)
{
- reconnect_listen_error(reconnect, now, atoi(argv[1]));
+ reconnect_listen_error(reconnect, now, atoi(ctx->argv[1]));
}
static const struct ovs_cmdl_command all_commands[] = {
}
static void
-test_log_2_floor(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_log_2_floor(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int n;
}
static void
-test_ctz(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_ctz(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int n;
}
static void
-test_clz(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_clz(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int n;
}
static void
-test_round_up_pow2(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_round_up_pow2(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int n;
}
static void
-test_round_down_pow2(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_round_down_pow2(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int n;
}
static void
-test_count_1bits(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_count_1bits(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
uint64_t bits[64];
int i;
}
static void
-test_bitwise_copy(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_bitwise_copy(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned int n_loops;
int src_ofs;
}
static void
-test_bitwise_zero(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_bitwise_zero(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned int n_loops;
int dst_ofs;
}
static void
-test_bitwise_one(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_bitwise_one(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned int n_loops;
int dst_ofs;
}
static void
-test_bitwise_is_all_zeros(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_bitwise_is_all_zeros(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
int n_loops;
}
static void
-test_follow_symlinks(int argc, char *argv[])
+test_follow_symlinks(struct ovs_cmdl_context *ctx)
{
int i;
- for (i = 1; i < argc; i++) {
- char *target = follow_symlinks(argv[i]);
+ for (i = 1; i < ctx->argc; i++) {
+ char *target = follow_symlinks(ctx->argv[i]);
puts(target);
free(target);
}
}
static void
-test_assert(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_assert(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
ovs_assert(false);
}
static void
-test_ovs_scan(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_ovs_scan(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
char str[16], str2[16], str3[16];
long double ld, ld2;
}
static void
-test_snprintf(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_snprintf(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
char s[16];
#ifndef _WIN32
static void
-test_file_name(int argc, char *argv[])
+test_file_name(struct ovs_cmdl_context *ctx)
{
int i;
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < ctx->argc; i++) {
char *dir, *base;
- dir = dir_name(argv[i]);
+ dir = dir_name(ctx->argv[i]);
puts(dir);
free(dir);
- base = base_name(argv[i]);
+ base = base_name(ctx->argv[i]);
puts(base);
free(base);
}
static void
test_util_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = { .argc = 0, };
set_program_name(argv[0]);
parse_options(argc, argv);
/* On Windows, stderr is fully buffered if connected to a pipe.
* POSIX doesn't define the circumstances in which stderr is
* fully buffered either. */
setvbuf(stderr, NULL, _IONBF, 0);
- ovs_cmdl_run_command(argc - optind, argv + optind, commands);
+ ctx.argc = argc - optind;
+ ctx.argv = argv + optind;
+ ovs_cmdl_run_command(&ctx, commands);
}
OVSTEST_REGISTER("test-util", test_util_main);
/* Connects to a fake_pvconn with vconn_open(), then closes the listener and
* verifies that vconn_connect() reports 'expected_error'. */
static void
-test_refuse_connection(int argc OVS_UNUSED, char *argv[])
+test_refuse_connection(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct fake_pvconn fpv;
struct vconn *vconn;
int error;
* closes it immediately, and verifies that vconn_connect() reports
* 'expected_error'. */
static void
-test_accept_then_close(int argc OVS_UNUSED, char *argv[])
+test_accept_then_close(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct fake_pvconn fpv;
struct vconn *vconn;
int error;
* reads the hello message from it, then closes the connection and verifies
* that vconn_connect() reports 'expected_error'. */
static void
-test_read_hello(int argc OVS_UNUSED, char *argv[])
+test_read_hello(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct fake_pvconn fpv;
struct vconn *vconn;
struct stream *stream;
/* Try connecting and sending a normal hello, which should succeed. */
static void
-test_send_plain_hello(int argc OVS_UNUSED, char *argv[])
+test_send_plain_hello(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct ofpbuf *hello;
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
* the specification says that implementations must accept and ignore extra
* data). */
static void
-test_send_long_hello(int argc OVS_UNUSED, char *argv[])
+test_send_long_hello(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct ofpbuf *hello;
enum { EXTRA_BYTES = 8 };
/* Try connecting and sending an echo request instead of a hello, which should
* fail with EPROTO. */
static void
-test_send_echo_hello(int argc OVS_UNUSED, char *argv[])
+test_send_echo_hello(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct ofpbuf *echo;
echo = ofpraw_alloc_xid(OFPRAW_OFPT_ECHO_REQUEST, OFP13_VERSION,
/* Try connecting and sending a hello packet that has its length field as 0,
* which should fail with EPROTO. */
static void
-test_send_short_hello(int argc OVS_UNUSED, char *argv[])
+test_send_short_hello(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct ofp_header hello;
memset(&hello, 0, sizeof hello);
/* Try connecting and sending a hello packet that has a bad version, which
* should fail with EPROTO. */
static void
-test_send_invalid_version_hello(int argc OVS_UNUSED, char *argv[])
+test_send_invalid_version_hello(struct ovs_cmdl_context *ctx)
{
- const char *type = argv[1];
+ const char *type = ctx->argv[1];
struct ofpbuf *hello;
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
static void
test_vconn_main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = {
+ .argc = argc - 1,
+ .argv = argv + 1,
+ };
+
set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_EMER);
vlog_set_levels(NULL, VLF_CONSOLE, VLL_DBG);
time_alarm(10);
- ovs_cmdl_run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(&ctx, commands);
}
OVSTEST_REGISTER("test-vconn", test_vconn_main);
int
main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = { .argc = 0, };
set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_EMER);
parse_options(argc, argv);
- ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
+ ctx.argc = argc - optind;
+ ctx.argv = argv + optind;
+ ovs_cmdl_run_command(&ctx, get_all_commands());
return 0;
}
}
static void
-cmd_listen(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+cmd_listen(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct pollfd *fds;
int n_fds;
}
static void
-cmd_rate(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+cmd_rate(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned short int local_port;
unsigned short int remote_port;
}
static void
-cmd_latency(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+cmd_latency(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
unsigned short int local_port;
unsigned short int remote_port;
}
static void
-cmd_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+cmd_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
usage();
}
int
main(int argc, char *argv[])
{
+ struct ovs_cmdl_context ctx = { .argc = 0, };
set_program_name(argv[0]);
service_start(&argc, &argv);
parse_options(argc, argv);
fatal_ignore_sigpipe();
- ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
+ ctx.argc = argc - optind;
+ ctx.argv = argv + optind;
+ ovs_cmdl_run_command(&ctx, get_all_commands());
return 0;
}
}
static void
-ofctl_show(int argc OVS_UNUSED, char *argv[])
+ofctl_show(struct ovs_cmdl_context *ctx)
{
- const char *vconn_name = argv[1];
+ const char *vconn_name = ctx->argv[1];
enum ofp_version version;
struct vconn *vconn;
struct ofpbuf *request;
}
static void
-ofctl_dump_desc(int argc OVS_UNUSED, char *argv[])
+ofctl_dump_desc(struct ovs_cmdl_context *ctx)
{
- dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_DESC_REQUEST);
+ dump_trivial_stats_transaction(ctx->argv[1], OFPRAW_OFPST_DESC_REQUEST);
}
static void
-ofctl_dump_tables(int argc OVS_UNUSED, char *argv[])
+ofctl_dump_tables(struct ovs_cmdl_context *ctx)
{
- dump_trivial_stats_transaction(argv[1], OFPRAW_OFPST_TABLE_REQUEST);
+ dump_trivial_stats_transaction(ctx->argv[1], OFPRAW_OFPST_TABLE_REQUEST);
}
static void
-ofctl_dump_table_features(int argc OVS_UNUSED, char *argv[])
+ofctl_dump_table_features(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
request = ofputil_encode_table_features_request(vconn_get_version(vconn));
if (request) {
dump_stats_transaction(vconn, request);
}
static void
-ofctl_dump_flows(int argc, char *argv[])
+ofctl_dump_flows(struct ovs_cmdl_context *ctx)
{
if (!n_criteria) {
- ofctl_dump_flows__(argc, argv, false);
+ ofctl_dump_flows__(ctx->argc, ctx->argv, false);
return;
} else {
struct ofputil_flow_stats *fses;
struct ds s;
size_t i;
- vconn = prepare_dump_flows(argc, argv, false, &request);
+ vconn = prepare_dump_flows(ctx->argc, ctx->argv, false, &request);
send_xid = ((struct ofp_header *) request->data)->xid;
send_openflow_buffer(vconn, request);
}
static void
-ofctl_dump_aggregate(int argc, char *argv[])
+ofctl_dump_aggregate(struct ovs_cmdl_context *ctx)
{
- ofctl_dump_flows__(argc, argv, true);
+ ofctl_dump_flows__(ctx->argc, ctx->argv, true);
}
static void
-ofctl_queue_stats(int argc, char *argv[])
+ofctl_queue_stats(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
struct ofputil_queue_stats_request oqs;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
- if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) {
- oqs.port_no = str_to_port_no(argv[1], argv[2]);
+ if (ctx->argc > 2 && ctx->argv[2][0] && strcasecmp(ctx->argv[2], "all")) {
+ oqs.port_no = str_to_port_no(ctx->argv[1], ctx->argv[2]);
} else {
oqs.port_no = OFPP_ANY;
}
- if (argc > 3 && argv[3][0] && strcasecmp(argv[3], "all")) {
- oqs.queue_id = atoi(argv[3]);
+ if (ctx->argc > 3 && ctx->argv[3][0] && strcasecmp(ctx->argv[3], "all")) {
+ oqs.queue_id = atoi(ctx->argv[3]);
} else {
oqs.queue_id = OFPQ_ALL;
}
}
static void
-ofctl_queue_get_config(int argc OVS_UNUSED, char *argv[])
+ofctl_queue_get_config(struct ovs_cmdl_context *ctx)
{
- const char *vconn_name = argv[1];
- const char *port_name = argv[2];
+ const char *vconn_name = ctx->argv[1];
+ const char *port_name = ctx->argv[2];
enum ofputil_protocol protocol;
enum ofp_version version;
struct ofpbuf *request;
}
static void
-ofctl_add_flow(int argc, char *argv[])
+ofctl_add_flow(struct ovs_cmdl_context *ctx)
{
- ofctl_flow_mod(argc, argv, OFPFC_ADD);
+ ofctl_flow_mod(ctx->argc, ctx->argv, OFPFC_ADD);
}
static void
-ofctl_add_flows(int argc, char *argv[])
+ofctl_add_flows(struct ovs_cmdl_context *ctx)
{
- ofctl_flow_mod_file(argc, argv, OFPFC_ADD);
+ ofctl_flow_mod_file(ctx->argc, ctx->argv, OFPFC_ADD);
}
static void
-ofctl_mod_flows(int argc, char *argv[])
+ofctl_mod_flows(struct ovs_cmdl_context *ctx)
{
- ofctl_flow_mod(argc, argv, strict ? OFPFC_MODIFY_STRICT : OFPFC_MODIFY);
+ ofctl_flow_mod(ctx->argc, ctx->argv, strict ? OFPFC_MODIFY_STRICT : OFPFC_MODIFY);
}
static void
-ofctl_del_flows(int argc, char *argv[])
+ofctl_del_flows(struct ovs_cmdl_context *ctx)
{
- ofctl_flow_mod(argc, argv, strict ? OFPFC_DELETE_STRICT : OFPFC_DELETE);
+ ofctl_flow_mod(ctx->argc, ctx->argv, strict ? OFPFC_DELETE_STRICT : OFPFC_DELETE);
}
static void
}
static void
-ofctl_monitor(int argc, char *argv[])
+ofctl_monitor(struct ovs_cmdl_context *ctx)
{
struct vconn *vconn;
int i;
enum ofputil_protocol usable_protocols;
- open_vconn(argv[1], &vconn);
- for (i = 2; i < argc; i++) {
- const char *arg = argv[i];
+ open_vconn(ctx->argv[1], &vconn);
+ for (i = 2; i < ctx->argc; i++) {
+ const char *arg = ctx->argv[i];
if (isdigit((unsigned char) *arg)) {
struct ofp_switch_config config;
}
static void
-ofctl_snoop(int argc OVS_UNUSED, char *argv[])
+ofctl_snoop(struct ovs_cmdl_context *ctx)
{
struct vconn *vconn;
- open_vconn__(argv[1], SNOOP, &vconn);
+ open_vconn__(ctx->argv[1], SNOOP, &vconn);
monitor_vconn(vconn, false);
}
static void
-ofctl_dump_ports(int argc, char *argv[])
+ofctl_dump_ports(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
ofp_port_t port;
- open_vconn(argv[1], &vconn);
- port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_ANY;
+ open_vconn(ctx->argv[1], &vconn);
+ port = ctx->argc > 2 ? str_to_port_no(ctx->argv[1], ctx->argv[2]) : OFPP_ANY;
request = ofputil_encode_dump_ports_request(vconn_get_version(vconn), port);
dump_stats_transaction(vconn, request);
vconn_close(vconn);
}
static void
-ofctl_dump_ports_desc(int argc OVS_UNUSED, char *argv[])
+ofctl_dump_ports_desc(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
ofp_port_t port;
- open_vconn(argv[1], &vconn);
- port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_ANY;
+ open_vconn(ctx->argv[1], &vconn);
+ port = ctx->argc > 2 ? str_to_port_no(ctx->argv[1], ctx->argv[2]) : OFPP_ANY;
request = ofputil_encode_port_desc_stats_request(vconn_get_version(vconn),
port);
dump_stats_transaction(vconn, request);
}
static void
-ofctl_probe(int argc OVS_UNUSED, char *argv[])
+ofctl_probe(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
struct ofpbuf *reply;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
request = make_echo_request(vconn_get_version(vconn));
- run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
+ run(vconn_transact(vconn, request, &reply), "talking to %s", ctx->argv[1]);
if (reply->size != sizeof(struct ofp_header)) {
ovs_fatal(0, "reply does not match request");
}
}
static void
-ofctl_packet_out(int argc, char *argv[])
+ofctl_packet_out(struct ovs_cmdl_context *ctx)
{
enum ofputil_protocol protocol;
struct ofputil_packet_out po;
enum ofputil_protocol usable_protocols; /* XXX: Use in proto selection */
ofpbuf_init(&ofpacts, 64);
- error = ofpacts_parse_actions(argv[3], &ofpacts, &usable_protocols);
+ error = ofpacts_parse_actions(ctx->argv[3], &ofpacts, &usable_protocols);
if (error) {
ovs_fatal(0, "%s", error);
}
po.buffer_id = UINT32_MAX;
- po.in_port = str_to_port_no(argv[1], argv[2]);
+ po.in_port = str_to_port_no(ctx->argv[1], ctx->argv[2]);
po.ofpacts = ofpacts.data;
po.ofpacts_len = ofpacts.size;
- protocol = open_vconn(argv[1], &vconn);
- for (i = 4; i < argc; i++) {
+ protocol = open_vconn(ctx->argv[1], &vconn);
+ for (i = 4; i < ctx->argc; i++) {
struct dp_packet *packet;
struct ofpbuf *opo;
const char *error_msg;
- error_msg = eth_from_hex(argv[i], &packet);
+ error_msg = eth_from_hex(ctx->argv[i], &packet);
if (error_msg) {
ovs_fatal(0, "%s", error_msg);
}
}
static void
-ofctl_mod_port(int argc OVS_UNUSED, char *argv[])
+ofctl_mod_port(struct ovs_cmdl_context *ctx)
{
struct ofp_config_flag {
const char *name; /* The flag's name. */
const char *command;
bool not;
- fetch_ofputil_phy_port(argv[1], argv[2], &pp);
+ fetch_ofputil_phy_port(ctx->argv[1], ctx->argv[2], &pp);
pm.port_no = pp.port_no;
memcpy(pm.hw_addr, pp.hw_addr, ETH_ADDR_LEN);
pm.mask = 0;
pm.advertise = 0;
- if (!strncasecmp(argv[3], "no-", 3)) {
- command = argv[3] + 3;
+ if (!strncasecmp(ctx->argv[3], "no-", 3)) {
+ command = ctx->argv[3] + 3;
not = true;
- } else if (!strncasecmp(argv[3], "no", 2)) {
- command = argv[3] + 2;
+ } else if (!strncasecmp(ctx->argv[3], "no", 2)) {
+ command = ctx->argv[3] + 2;
not = true;
} else {
- command = argv[3];
+ command = ctx->argv[3];
not = false;
}
for (flag = flags; flag < &flags[ARRAY_SIZE(flags)]; flag++) {
goto found;
}
}
- ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
+ ovs_fatal(0, "unknown mod-port command '%s'", ctx->argv[3]);
found:
- protocol = open_vconn(argv[1], &vconn);
+ protocol = open_vconn(ctx->argv[1], &vconn);
transact_noreply(vconn, ofputil_encode_port_mod(&pm, protocol));
vconn_close(vconn);
}
static void
-ofctl_mod_table(int argc OVS_UNUSED, char *argv[])
+ofctl_mod_table(struct ovs_cmdl_context *ctx)
{
enum ofputil_protocol protocol, usable_protocols;
struct ofputil_table_mod tm;
char *error;
int i;
- error = parse_ofp_table_mod(&tm, argv[2], argv[3], &usable_protocols);
+ error = parse_ofp_table_mod(&tm, ctx->argv[2], ctx->argv[3], &usable_protocols);
if (error) {
ovs_fatal(0, "%s", error);
}
- protocol = open_vconn(argv[1], &vconn);
+ protocol = open_vconn(ctx->argv[1], &vconn);
if (!(protocol & usable_protocols)) {
for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) {
enum ofputil_protocol f = 1 << i;
}
static void
-ofctl_get_frags(int argc OVS_UNUSED, char *argv[])
+ofctl_get_frags(struct ovs_cmdl_context *ctx)
{
struct ofp_switch_config config;
struct vconn *vconn;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
fetch_switch_config(vconn, &config);
puts(ofputil_frag_handling_to_string(ntohs(config.flags)));
vconn_close(vconn);
}
static void
-ofctl_set_frags(int argc OVS_UNUSED, char *argv[])
+ofctl_set_frags(struct ovs_cmdl_context *ctx)
{
struct ofp_switch_config config;
enum ofp_config_flags mode;
struct vconn *vconn;
ovs_be16 flags;
- if (!ofputil_frag_handling_from_string(argv[2], &mode)) {
- ovs_fatal(0, "%s: unknown fragment handling mode", argv[2]);
+ if (!ofputil_frag_handling_from_string(ctx->argv[2], &mode)) {
+ ovs_fatal(0, "%s: unknown fragment handling mode", ctx->argv[2]);
}
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
fetch_switch_config(vconn, &config);
flags = htons(mode) | (config.flags & htons(~OFPC_FRAG_MASK));
if (flags != config.flags) {
if (flags != config.flags) {
ovs_fatal(0, "%s: setting fragment handling mode failed (this "
"switch probably doesn't support mode \"%s\")",
- argv[1], ofputil_frag_handling_to_string(mode));
+ ctx->argv[1], ofputil_frag_handling_to_string(mode));
}
}
vconn_close(vconn);
}
static void
-ofctl_ofp_parse(int argc OVS_UNUSED, char *argv[])
+ofctl_ofp_parse(struct ovs_cmdl_context *ctx)
{
- const char *filename = argv[1];
+ const char *filename = ctx->argv[1];
struct ofpbuf b;
FILE *file;
}
static void
-ofctl_ofp_parse_pcap(int argc OVS_UNUSED, char *argv[])
+ofctl_ofp_parse_pcap(struct ovs_cmdl_context *ctx)
{
struct tcp_reader *reader;
FILE *file;
int error;
bool first;
- file = ovs_pcap_open(argv[1], "rb");
+ file = ovs_pcap_open(ctx->argv[1], "rb");
if (!file) {
- ovs_fatal(errno, "%s: open failed", argv[1]);
+ ovs_fatal(errno, "%s: open failed", ctx->argv[1]);
}
reader = tcp_reader_open();
flow_extract(packet, &flow);
if (flow.dl_type == htons(ETH_TYPE_IP)
&& flow.nw_proto == IPPROTO_TCP
- && (is_openflow_port(flow.tp_src, argv + 2) ||
- is_openflow_port(flow.tp_dst, argv + 2))) {
+ && (is_openflow_port(flow.tp_src, ctx->argv + 2) ||
+ is_openflow_port(flow.tp_dst, ctx->argv + 2))) {
struct dp_packet *payload = tcp_reader_run(reader, &flow, packet);
if (payload) {
while (dp_packet_size(payload) >= sizeof(struct ofp_header)) {
}
static void
-ofctl_ping(int argc, char *argv[])
+ofctl_ping(struct ovs_cmdl_context *ctx)
{
size_t max_payload = 65535 - sizeof(struct ofp_header);
unsigned int payload;
struct vconn *vconn;
int i;
- payload = argc > 2 ? atoi(argv[2]) : 64;
+ payload = ctx->argc > 2 ? atoi(ctx->argv[2]) : 64;
if (payload > max_payload) {
ovs_fatal(0, "payload must be between 0 and %"PRIuSIZE" bytes", max_payload);
}
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
for (i = 0; i < 10; i++) {
struct timeval start, end;
struct ofpbuf *request, *reply;
ofp_print(stdout, reply, reply->size, verbosity + 2);
}
printf("%"PRIu32" bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
- reply->size, argv[1], ntohl(rpy_hdr->xid),
+ reply->size, ctx->argv[1], ntohl(rpy_hdr->xid),
(1000*(double)(end.tv_sec - start.tv_sec))
+ (.001*(end.tv_usec - start.tv_usec)));
ofpbuf_delete(request);
}
static void
-ofctl_benchmark(int argc OVS_UNUSED, char *argv[])
+ofctl_benchmark(struct ovs_cmdl_context *ctx)
{
size_t max_payload = 65535 - sizeof(struct ofp_header);
struct timeval start, end;
int count;
int i;
- payload_size = atoi(argv[2]);
+ payload_size = atoi(ctx->argv[2]);
if (payload_size > max_payload) {
ovs_fatal(0, "payload must be between 0 and %"PRIuSIZE" bytes", max_payload);
}
message_size = sizeof(struct ofp_header) + payload_size;
- count = atoi(argv[3]);
+ count = atoi(ctx->argv[3]);
printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
count, message_size, count * message_size);
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
xgettimeofday(&start);
for (i = 0; i < count; i++) {
struct ofpbuf *request, *reply;
}
static void
-ofctl_add_group(int argc, char *argv[])
+ofctl_add_group(struct ovs_cmdl_context *ctx)
{
- ofctl_group_mod(argc, argv, OFPGC11_ADD);
+ ofctl_group_mod(ctx->argc, ctx->argv, OFPGC11_ADD);
}
static void
-ofctl_add_groups(int argc, char *argv[])
+ofctl_add_groups(struct ovs_cmdl_context *ctx)
{
- ofctl_group_mod_file(argc, argv, OFPGC11_ADD);
+ ofctl_group_mod_file(ctx->argc, ctx->argv, OFPGC11_ADD);
}
static void
-ofctl_mod_group(int argc, char *argv[])
+ofctl_mod_group(struct ovs_cmdl_context *ctx)
{
- ofctl_group_mod(argc, argv, OFPGC11_MODIFY);
+ ofctl_group_mod(ctx->argc, ctx->argv, OFPGC11_MODIFY);
}
static void
-ofctl_del_groups(int argc, char *argv[])
+ofctl_del_groups(struct ovs_cmdl_context *ctx)
{
- ofctl_group_mod(argc, argv, OFPGC11_DELETE);
+ ofctl_group_mod(ctx->argc, ctx->argv, OFPGC11_DELETE);
}
static void
-ofctl_insert_bucket(int argc, char *argv[])
+ofctl_insert_bucket(struct ovs_cmdl_context *ctx)
{
- ofctl_group_mod(argc, argv, OFPGC15_INSERT_BUCKET);
+ ofctl_group_mod(ctx->argc, ctx->argv, OFPGC15_INSERT_BUCKET);
}
static void
-ofctl_remove_bucket(int argc, char *argv[])
+ofctl_remove_bucket(struct ovs_cmdl_context *ctx)
{
- ofctl_group_mod(argc, argv, OFPGC15_REMOVE_BUCKET);
+ ofctl_group_mod(ctx->argc, ctx->argv, OFPGC15_REMOVE_BUCKET);
}
static void
-ofctl_dump_group_stats(int argc, char *argv[])
+ofctl_dump_group_stats(struct ovs_cmdl_context *ctx)
{
enum ofputil_protocol usable_protocols;
struct ofputil_group_mod gm;
memset(&gm, 0, sizeof gm);
error = parse_ofp_group_mod_str(&gm, OFPGC11_DELETE,
- argc > 2 ? argv[2] : "",
+ ctx->argc > 2 ? ctx->argv[2] : "",
&usable_protocols);
if (error) {
ovs_fatal(0, "%s", error);
group_id = gm.group_id;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
request = ofputil_encode_group_stats_request(vconn_get_version(vconn),
group_id);
if (request) {
}
static void
-ofctl_dump_group_desc(int argc OVS_UNUSED, char *argv[])
+ofctl_dump_group_desc(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
uint32_t group_id;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
- if (argc < 3 || !ofputil_group_from_string(argv[2], &group_id)) {
+ if (ctx->argc < 3 || !ofputil_group_from_string(ctx->argv[2], &group_id)) {
group_id = OFPG11_ALL;
}
}
static void
-ofctl_dump_group_features(int argc OVS_UNUSED, char *argv[])
+ofctl_dump_group_features(struct ovs_cmdl_context *ctx)
{
struct ofpbuf *request;
struct vconn *vconn;
- open_vconn(argv[1], &vconn);
+ open_vconn(ctx->argv[1], &vconn);
request = ofputil_encode_group_features_request(vconn_get_version(vconn));
if (request) {
dump_stats_transaction(vconn, request);
}
static void
-ofctl_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
usage();
}
static void
-ofctl_list_commands(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_list_commands(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
ovs_cmdl_print_commands(get_all_commands());
}
}
static void
-ofctl_replace_flows(int argc OVS_UNUSED, char *argv[])
+ofctl_replace_flows(struct ovs_cmdl_context *ctx)
{
enum { FILE_IDX = 0, SWITCH_IDX = 1 };
enum ofputil_protocol usable_protocols, protocol;
struct fte *fte;
classifier_init(&cls, NULL);
- usable_protocols = read_flows_from_file(argv[2], &cls, FILE_IDX);
+ usable_protocols = read_flows_from_file(ctx->argv[2], &cls, FILE_IDX);
- protocol = open_vconn(argv[1], &vconn);
+ protocol = open_vconn(ctx->argv[1], &vconn);
protocol = set_protocol_for_flow_dump(vconn, protocol, usable_protocols);
read_flows_from_switch(vconn, protocol, &cls, SWITCH_IDX);
}
static void
-ofctl_diff_flows(int argc OVS_UNUSED, char *argv[])
+ofctl_diff_flows(struct ovs_cmdl_context *ctx)
{
bool differences = false;
struct classifier cls;
struct fte *fte;
classifier_init(&cls, NULL);
- read_flows_from_source(argv[1], &cls, 0);
- read_flows_from_source(argv[2], &cls, 1);
+ read_flows_from_source(ctx->argv[1], &cls, 0);
+ read_flows_from_source(ctx->argv[2], &cls, 1);
ds_init(&a_s);
ds_init(&b_s);
static void
-ofctl_add_meter(int argc OVS_UNUSED, char *argv[])
+ofctl_add_meter(struct ovs_cmdl_context *ctx)
{
- ofctl_meter_mod__(argv[1], argv[2], OFPMC13_ADD);
+ ofctl_meter_mod__(ctx->argv[1], ctx->argv[2], OFPMC13_ADD);
}
static void
-ofctl_mod_meter(int argc OVS_UNUSED, char *argv[])
+ofctl_mod_meter(struct ovs_cmdl_context *ctx)
{
- ofctl_meter_mod__(argv[1], argv[2], OFPMC13_MODIFY);
+ ofctl_meter_mod__(ctx->argv[1], ctx->argv[2], OFPMC13_MODIFY);
}
static void
-ofctl_del_meters(int argc, char *argv[])
+ofctl_del_meters(struct ovs_cmdl_context *ctx)
{
- ofctl_meter_mod__(argv[1], argc > 2 ? argv[2] : NULL, OFPMC13_DELETE);
+ ofctl_meter_mod__(ctx->argv[1], ctx->argc > 2 ? ctx->argv[2] : NULL, OFPMC13_DELETE);
}
static void
-ofctl_dump_meters(int argc, char *argv[])
+ofctl_dump_meters(struct ovs_cmdl_context *ctx)
{
- ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
+ ofctl_meter_request__(ctx->argv[1], ctx->argc > 2 ? ctx->argv[2] : NULL,
OFPUTIL_METER_CONFIG);
}
static void
-ofctl_meter_stats(int argc, char *argv[])
+ofctl_meter_stats(struct ovs_cmdl_context *ctx)
{
- ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
+ ofctl_meter_request__(ctx->argv[1], ctx->argc > 2 ? ctx->argv[2] : NULL,
OFPUTIL_METER_STATS);
}
static void
-ofctl_meter_features(int argc OVS_UNUSED, char *argv[])
+ofctl_meter_features(struct ovs_cmdl_context *ctx)
{
- ofctl_meter_request__(argv[1], NULL, OFPUTIL_METER_FEATURES);
+ ofctl_meter_request__(ctx->argv[1], NULL, OFPUTIL_METER_FEATURES);
}
\f
/* "parse-flow FLOW": parses the argument as a flow (like add-flow) and prints
* it back to stdout. */
static void
-ofctl_parse_flow(int argc OVS_UNUSED, char *argv[])
+ofctl_parse_flow(struct ovs_cmdl_context *ctx)
{
enum ofputil_protocol usable_protocols;
struct ofputil_flow_mod fm;
char *error;
- error = parse_ofp_flow_mod_str(&fm, argv[1], OFPFC_ADD, &usable_protocols);
+ error = parse_ofp_flow_mod_str(&fm, ctx->argv[1], OFPFC_ADD, &usable_protocols);
if (error) {
ovs_fatal(0, "%s", error);
}
/* "parse-flows FILENAME": reads the named file as a sequence of flows (like
* add-flows) and prints each of the flows back to stdout. */
static void
-ofctl_parse_flows(int argc OVS_UNUSED, char *argv[])
+ofctl_parse_flows(struct ovs_cmdl_context *ctx)
{
enum ofputil_protocol usable_protocols;
struct ofputil_flow_mod *fms = NULL;
size_t n_fms = 0;
char *error;
- error = parse_ofp_flow_mod_file(argv[1], OFPFC_ADD, &fms, &n_fms,
+ error = parse_ofp_flow_mod_file(ctx->argv[1], OFPFC_ADD, &fms, &n_fms,
&usable_protocols);
if (error) {
ovs_fatal(0, "%s", error);
* stdin, does some internal fussing with them, and then prints them back as
* strings on stdout. */
static void
-ofctl_parse_nxm(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_parse_nxm(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
ofctl_parse_nxm__(false, 0);
}
* them back as strings on stdout. VERSION must specify an OpenFlow version,
* e.g. "OpenFlow12". */
static void
-ofctl_parse_oxm(int argc OVS_UNUSED, char *argv[])
+ofctl_parse_oxm(struct ovs_cmdl_context *ctx)
{
- enum ofp_version version = ofputil_version_from_string(argv[1]);
+ enum ofp_version version = ofputil_version_from_string(ctx->argv[1]);
if (version < OFP12_VERSION) {
- ovs_fatal(0, "%s: not a valid version for OXM", argv[1]);
+ ovs_fatal(0, "%s: not a valid version for OXM", ctx->argv[1]);
}
ofctl_parse_nxm__(true, version);
* prints them as strings on stdout, and then converts them back to hex bytes
* and prints any differences from the input. */
static void
-ofctl_parse_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_parse_actions(struct ovs_cmdl_context *ctx)
{
- ofctl_parse_actions__(argv[1], false);
+ ofctl_parse_actions__(ctx->argv[1], false);
}
/* "parse-actions VERSION": reads a series of instruction specifications for
* ofpacts, prints them as strings on stdout, and then converts them back to
* hex bytes and prints any differences from the input. */
static void
-ofctl_parse_instructions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_parse_instructions(struct ovs_cmdl_context *ctx)
{
- ofctl_parse_actions__(argv[1], true);
+ ofctl_parse_actions__(ctx->argv[1], true);
}
/* "parse-ofp10-match": reads a series of ofp10_match specifications as hex
* them back to hex bytes. ovs-ofctl actually sets "x"s to random bits when
* it does the conversion to hex, to ensure that in fact they are ignored. */
static void
-ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_parse_ofp10_match(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct ds expout;
struct ds in;
* on stdout, and then converts them back to hex bytes and prints any
* differences from the input. */
static void
-ofctl_parse_ofp11_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+ofctl_parse_ofp11_match(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
struct ds in;
/* "parse-pcap PCAP": read packets from PCAP and print their flows. */
static void
-ofctl_parse_pcap(int argc OVS_UNUSED, char *argv[])
+ofctl_parse_pcap(struct ovs_cmdl_context *ctx)
{
FILE *pcap;
- pcap = ovs_pcap_open(argv[1], "rb");
+ pcap = ovs_pcap_open(ctx->argv[1], "rb");
if (!pcap) {
- ovs_fatal(errno, "%s: open failed", argv[1]);
+ ovs_fatal(errno, "%s: open failed", ctx->argv[1]);
}
for (;;) {
if (error == EOF) {
break;
} else if (error) {
- ovs_fatal(error, "%s: read failed", argv[1]);
+ ovs_fatal(error, "%s: read failed", ctx->argv[1]);
}
packet->md = PKT_METADATA_INITIALIZER(ODPP_NONE);
/* "check-vlan VLAN_TCI VLAN_TCI_MASK": converts the specified vlan_tci and
* mask values to and from various formats and prints the results. */
static void
-ofctl_check_vlan(int argc OVS_UNUSED, char *argv[])
+ofctl_check_vlan(struct ovs_cmdl_context *ctx)
{
struct match match;
enum ofputil_protocol usable_protocols; /* Unused for now. */
match_init_catchall(&match);
- match.flow.vlan_tci = htons(strtoul(argv[1], NULL, 16));
- match.wc.masks.vlan_tci = htons(strtoul(argv[2], NULL, 16));
+ match.flow.vlan_tci = htons(strtoul(ctx->argv[1], NULL, 16));
+ match.wc.masks.vlan_tci = htons(strtoul(ctx->argv[2], NULL, 16));
/* Convert to and from string. */
string_s = match_to_string(&match, OFP_DEFAULT_PRIORITY);
/* "print-error ENUM": Prints the type and code of ENUM for every OpenFlow
* version. */
static void
-ofctl_print_error(int argc OVS_UNUSED, char *argv[])
+ofctl_print_error(struct ovs_cmdl_context *ctx)
{
enum ofperr error;
int version;
- error = ofperr_from_name(argv[1]);
+ error = ofperr_from_name(ctx->argv[1]);
if (!error) {
- ovs_fatal(0, "unknown error \"%s\"", argv[1]);
+ ovs_fatal(0, "unknown error \"%s\"", ctx->argv[1]);
}
for (version = 0; version <= UINT8_MAX; version++) {
/* "encode-error-reply ENUM REQUEST": Encodes an error reply to REQUEST for the
* error named ENUM and prints the error reply in hex. */
static void
-ofctl_encode_error_reply(int argc OVS_UNUSED, char *argv[])
+ofctl_encode_error_reply(struct ovs_cmdl_context *ctx)
{
const struct ofp_header *oh;
struct ofpbuf request, *reply;
enum ofperr error;
- error = ofperr_from_name(argv[1]);
+ error = ofperr_from_name(ctx->argv[1]);
if (!error) {
- ovs_fatal(0, "unknown error \"%s\"", argv[1]);
+ ovs_fatal(0, "unknown error \"%s\"", ctx->argv[1]);
}
ofpbuf_init(&request, 0);
- if (ofpbuf_put_hex(&request, argv[2], NULL)[0] != '\0') {
+ if (ofpbuf_put_hex(&request, ctx->argv[2], NULL)[0] != '\0') {
ovs_fatal(0, "Trailing garbage in hex data");
}
if (request.size < sizeof(struct ofp_header)) {
* Alternative usage: "ofp-print [VERBOSITY] - < HEXSTRING_FILE", where
* HEXSTRING_FILE contains the HEXSTRING. */
static void
-ofctl_ofp_print(int argc, char *argv[])
+ofctl_ofp_print(struct ovs_cmdl_context *ctx)
{
struct ofpbuf packet;
char *buffer;
ds_init(&line);
- if (!strcmp(argv[argc-1], "-")) {
+ if (!strcmp(ctx->argv[ctx->argc-1], "-")) {
if (ds_get_line(&line, stdin)) {
VLOG_FATAL("Failed to read stdin");
}
buffer = line.string;
- verbosity = argc > 2 ? atoi(argv[1]) : verbosity;
- } else if (argc > 2) {
- buffer = argv[1];
- verbosity = atoi(argv[2]);
+ verbosity = ctx->argc > 2 ? atoi(ctx->argv[1]) : verbosity;
+ } else if (ctx->argc > 2) {
+ buffer = ctx->argv[1];
+ verbosity = atoi(ctx->argv[2]);
} else {
- buffer = argv[1];
+ buffer = ctx->argv[1];
}
ofpbuf_init(&packet, strlen(buffer) / 2);
/* "encode-hello BITMAP...": Encodes each BITMAP as an OpenFlow hello message
* and dumps each message in hex. */
static void
-ofctl_encode_hello(int argc OVS_UNUSED, char *argv[])
+ofctl_encode_hello(struct ovs_cmdl_context *ctx)
{
- uint32_t bitmap = strtol(argv[1], NULL, 0);
+ uint32_t bitmap = strtol(ctx->argv[1], NULL, 0);
struct ofpbuf *hello;
hello = ofputil_encode_hello(bitmap);