ovs-dpctl: Reimplement get_port_number() using dpif_port_query_by_name().
authorBen Pfaff <blp@nicira.com>
Mon, 27 Dec 2010 20:46:48 +0000 (12:46 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 29 Dec 2010 06:40:34 +0000 (22:40 -0800)
Presumably this function was written to iterate all of the ports because
at some point we didn't have a direct way to do this, but now
dpif_port_query_by_name() is the obvious way to do it.

Acked-by: Jesse Gross <jesse@nicira.com>
utilities/ovs-dpctl.c

index b12ceb7586cc5f8c7452b424b357a35c2af9651e..ff31fb8ec6338ecf23a85a5771ee352c416c246a 100644 (file)
@@ -300,21 +300,15 @@ do_add_if(int argc OVS_UNUSED, char *argv[])
 static bool
 get_port_number(struct dpif *dpif, const char *name, uint16_t *port)
 {
-    struct odp_port *ports;
-    size_t n_ports;
-    size_t i;
+    struct odp_port odp_port;
 
-    query_ports(dpif, &ports, &n_ports);
-    for (i = 0; i < n_ports; i++) {
-        if (!strcmp(name, ports[i].devname)) {
-            *port = ports[i].port;
-            free(ports);
-            return true;
-        }
+    if (!dpif_port_query_by_name(dpif, name, &odp_port)) {
+        *port = odp_port.port;
+        return true;
+    } else {
+        ovs_error(0, "no port named %s", name);
+        return false;
     }
-    free(ports);
-    ovs_error(0, "no port named %s", name);
-    return false;
 }
 
 static void