X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-dpctl.c;h=ee545a61ac5273e611929ffe4a47f1682afbde27;hb=149f577a25508779b756515be1f1bdcefa3710fa;hp=5a0da820c2fbe8a06c8f3b091fa23550ea542d32;hpb=00908dc27a4d93bd1c5bda3bcdc84ec351e9a09a;p=sliver-openvswitch.git diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 5a0da820c..ee545a61a 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,56 +43,20 @@ #include "vlog.h" #define THIS_MODULE VLM_dpctl -struct command { - const char *name; - int min_args; - int max_args; - void (*handler)(int argc, char *argv[]); -}; - -static struct command all_commands[]; +static const struct command all_commands[]; static void usage(void) NO_RETURN; static void parse_options(int argc, char *argv[]); -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - struct command *p; - set_program_name(argv[0]); time_init(); vlog_init(); parse_options(argc, argv); signal(SIGPIPE, SIG_IGN); - - argc -= optind; - argv += optind; - if (argc < 1) - ovs_fatal(0, "missing command name; use --help for help"); - - for (p = all_commands; p->name != NULL; p++) { - if (!strcmp(p->name, argv[0])) { - int n_arg = argc - 1; - if (n_arg < p->min_args) - ovs_fatal(0, "'%s' command requires at least %d arguments", - p->name, p->min_args); - else if (n_arg > p->max_args) - ovs_fatal(0, "'%s' command takes at most %d arguments", - p->name, p->max_args); - else { - p->handler(argc, argv); - if (ferror(stdout)) { - ovs_fatal(0, "write to stdout failed"); - } - if (ferror(stderr)) { - ovs_fatal(0, "write to stderr failed"); - } - exit(0); - } - } - } - ovs_fatal(0, "unknown command '%s'; use --help for help", argv[0]); - + run_command(argc - optind, argv + optind, all_commands); return 0; } @@ -202,7 +166,7 @@ static int if_up(const char *netdev_name) struct netdev *netdev; int retval; - retval = netdev_open(netdev_name, NETDEV_ETH_TYPE_NONE, &netdev); + retval = netdev_open_default(netdev_name, &netdev); if (!retval) { retval = netdev_turn_flags_on(netdev, NETDEV_UP, true); netdev_close(netdev); @@ -371,9 +335,11 @@ show_dpif(struct dpif *dpif) printf("\tports: cur:%"PRIu32", max:%"PRIu32"\n", stats.n_ports, stats.max_ports); printf("\tgroups: max:%"PRIu16"\n", stats.max_groups); - printf("\tlookups: frags:%"PRIu64", hit:%"PRIu64", missed:%"PRIu64", " - "lost:%"PRIu64"\n", - stats.n_frags, stats.n_hit, stats.n_missed, stats.n_lost); + printf("\tlookups: frags:%llu, hit:%llu, missed:%llu, lost:%llu\n", + (unsigned long long int) stats.n_frags, + (unsigned long long int) stats.n_hit, + (unsigned long long int) stats.n_missed, + (unsigned long long int) stats.n_lost); printf("\tqueues: max-miss:%"PRIu16", max-action:%"PRIu16"\n", stats.max_miss_queue, stats.max_action_queue); } @@ -527,7 +493,7 @@ do_help(int argc UNUSED, char *argv[] UNUSED) usage(); } -static struct command all_commands[] = { +static const struct command all_commands[] = { { "add-dp", 1, INT_MAX, do_add_dp }, { "del-dp", 1, 1, do_del_dp }, { "add-if", 2, INT_MAX, do_add_if },