X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-dpctl.c;h=8e9ed3dea8f21df1b74bcff3a9eefabc10f45e16;hb=67a78abeeae1a726d46ae475c5834513c7fe291e;hp=92d1d2d6a8fd939bb2663f59450a0991ec6389be;hpb=c228a3649af653a1b2109871b7b1f6ab76a841b7;p=openvswitch diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 92d1d2d6..8e9ed3de 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -36,6 +36,7 @@ #include "dynamic-string.h" #include "netdev.h" #include "odp-util.h" +#include "svec.h" #include "timeval.h" #include "util.h" @@ -157,6 +158,7 @@ usage(void) " del-dp DP delete local datapath DP\n" " add-if DP IFACE... add each IFACE as a port on DP\n" " del-if DP IFACE... delete each IFACE from DP\n" + " dump-dps display names of all datapaths\n" " show show basic info on all datapaths\n" " show DP... show basic info on each DP\n" " dump-flows DP display flows in DP\n" @@ -243,29 +245,6 @@ query_ports(struct dpif *dpif, struct odp_port **ports, size_t *n_ports) qsort(*ports, *n_ports, sizeof **ports, compare_ports); } -static uint16_t -get_free_port(struct dpif *dpif) -{ - struct odp_port *ports; - size_t n_ports; - int port_no; - - query_ports(dpif, &ports, &n_ports); - for (port_no = 0; port_no <= UINT16_MAX; port_no++) { - size_t i; - for (i = 0; i < n_ports; i++) { - if (ports[i].port == port_no) { - goto next_portno; - } - } - free(ports); - return port_no; - - next_portno: ; - } - ovs_fatal(0, "no free datapath ports"); -} - static void do_add_if(int argc UNUSED, char *argv[]) { @@ -277,7 +256,6 @@ do_add_if(int argc UNUSED, char *argv[]) for (i = 2; i < argc; i++) { char *save_ptr = NULL; char *devname, *suboptions; - int port = -1; int flags = 0; int error; @@ -290,11 +268,9 @@ do_add_if(int argc UNUSED, char *argv[]) suboptions = strtok_r(NULL, "", &save_ptr); if (suboptions) { enum { - AP_PORT, AP_INTERNAL }; static char *options[] = { - "port", "internal" }; @@ -302,13 +278,6 @@ do_add_if(int argc UNUSED, char *argv[]) char *value; switch (getsubopt(&suboptions, options, &value)) { - case AP_PORT: - if (!value) { - ovs_error(0, "'port' suboption requires a value"); - } - port = atoi(value); - break; - case AP_INTERNAL: flags |= ODP_PORT_INTERNAL; break; @@ -319,14 +288,10 @@ do_add_if(int argc UNUSED, char *argv[]) } } } - if (port < 0) { - port = get_free_port(dpif); - } - error = dpif_port_add(dpif, devname, port, flags); + error = dpif_port_add(dpif, devname, flags, NULL); if (error) { - ovs_error(error, "adding %s as port %"PRIu16" of %s failed", - devname, port, argv[1]); + ovs_error(error, "adding %s to %s failed", devname, argv[1]); failure = true; } else if (if_up(devname)) { failure = true; @@ -406,9 +371,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); } @@ -425,7 +392,7 @@ show_dpif(struct dpif *dpif) } static void -do_show(int argc UNUSED, char *argv[]) +do_show(int argc, char *argv[]) { bool failure = false; if (argc > 1) { @@ -465,6 +432,30 @@ do_show(int argc UNUSED, char *argv[]) } } +static void +do_dump_dps(int argc UNUSED, char *argv[] UNUSED) +{ + struct svec all_dps; + unsigned int i; + int error; + + svec_init(&all_dps); + error = dp_enumerate(&all_dps); + + for (i = 0; i < all_dps.n; i++) { + struct dpif *dpif; + if (!dpif_open(all_dps.names[i], &dpif)) { + printf("%s\n", dpif_name(dpif)); + dpif_close(dpif); + } + } + + svec_destroy(&all_dps); + if (error) { + exit(EXIT_FAILURE); + } +} + static void do_dump_flows(int argc UNUSED, char *argv[]) { @@ -515,11 +506,10 @@ do_dump_groups(int argc UNUSED, char *argv[]) run(dpif_open(argv[1], &dpif), "opening datapath"); run(dpif_get_dp_stats(dpif, &stats), "get datapath stats"); for (i = 0; i < stats.max_groups; i++) { - uint16_t ports[UINT16_MAX]; + uint16_t *ports; size_t n_ports; - if (!dpif_port_group_get(dpif, i, ports, - ARRAY_SIZE(ports), &n_ports) && n_ports) { + if (!dpif_port_group_get(dpif, i, &ports, &n_ports) && n_ports) { size_t j; printf("group %u:", i); @@ -528,6 +518,7 @@ do_dump_groups(int argc UNUSED, char *argv[]) } printf("\n"); } + free(ports); } dpif_close(dpif); } @@ -543,6 +534,7 @@ static struct command all_commands[] = { { "del-dp", 1, 1, do_del_dp }, { "add-if", 2, INT_MAX, do_add_if }, { "del-if", 2, INT_MAX, do_del_if }, + { "dump-dps", 0, 0, do_dump_dps }, { "show", 0, INT_MAX, do_show }, { "dump-flows", 1, 1, do_dump_flows }, { "del-flows", 1, 1, do_del_flows },