[ovs-dev] [PATCH 39/47] ofp-util: Pass vconn to fetch_port_by_features()

Simon Horman horms at verge.net.au
Wed Aug 1 07:02:22 UTC 2012


Pass vconn to fetch_port_by_features() and callers.
In some cases this will reduce the number of connections
that ovs-ofputil sets up.

It should not alter the behaviour of ovs-ofputil.

Signed-off-by: Simon Horman <horms at verge.net.au>

---

v9
* Manual rebase

v8
* Omitted

v7
* Omitted

v6
* No change

v5
* Initial post
---
 utilities/ovs-ofctl.c | 46 ++++++++++++++++++++++------------------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 4f4b149..606a3f2 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -591,29 +591,28 @@ ofctl_dump_tables(int argc OVS_UNUSED, char *argv[])
 }
 
 static bool
-fetch_port_by_features(const char *vconn_name,
-                       const char *port_name, unsigned int port_no,
-                       struct ofputil_phy_port *pp, bool *trunc)
+fetch_port_by_features(struct vconn *vconn, const char *port_name,
+                       unsigned int port_no, struct ofputil_phy_port *pp,
+                       bool *trunc)
 {
     struct ofputil_switch_features features;
     const struct ofp_header *oh;
     struct ofpbuf *request, *reply;
-    struct vconn *vconn;
     enum ofperr error;
     enum ofptype type;
     struct ofpbuf b;
     bool found = false;
 
     /* Fetch the switch's ofp_switch_features. */
-    request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST, OFP10_VERSION, 0);
-    open_vconn(vconn_name, &vconn);
-    run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
-    vconn_close(vconn);
+    request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST,
+                           vconn_get_version(vconn), 0);
+    run(vconn_transact(vconn, request, &reply), "talking to %s",
+        vconn_get_name(vconn));
 
     oh = reply->data;
     if (ofptype_decode(&type, reply->data)
         || type != OFPTYPE_FEATURES_REPLY) {
-        ovs_fatal(0, "%s: received bad features reply", vconn_name);
+        ovs_fatal(0, "%s: received bad features reply", vconn_get_name(vconn));
     }
 
     *trunc = false;
@@ -625,7 +624,7 @@ fetch_port_by_features(const char *vconn_name,
     error = ofputil_decode_switch_features(oh, &features, &b);
     if (error) {
         ovs_fatal(0, "%s: failed to decode features reply (%s)",
-                  vconn_name, ofperr_to_string(error));
+                  vconn_get_name(vconn), ofperr_to_string(error));
     }
 
     while (!ofputil_pull_phy_port(oh->version, &b, pp)) {
@@ -643,20 +642,18 @@ exit:
 }
 
 static bool
-fetch_port_by_stats(const char *vconn_name,
-                    const char *port_name, unsigned int port_no,
-                    struct ofputil_phy_port *pp)
+fetch_port_by_stats(struct vconn* vconn, const char *port_name,
+                    unsigned int port_no, struct ofputil_phy_port *pp)
 {
     struct ofpbuf *request;
-    struct vconn *vconn;
     ovs_be32 send_xid;
     bool done = false;
     bool found = false;
 
-    request = ofpraw_alloc(OFPRAW_OFPST_PORT_DESC_REQUEST, OFP10_VERSION, 0);
+    request = ofpraw_alloc(OFPRAW_OFPST_PORT_DESC_REQUEST,
+                           vconn_get_version(vconn), 0);
     send_xid = ((struct ofp_header *) request->data)->xid;
 
-    open_vconn(vconn_name, &vconn);
     send_openflow_buffer(vconn, request);
     while (!done) {
         ovs_be32 recv_xid;
@@ -700,7 +697,6 @@ fetch_port_by_stats(const char *vconn_name,
         }
         ofpbuf_delete(reply);
     }
-    vconn_close(vconn);
 
     return found;
 }
@@ -710,7 +706,7 @@ fetch_port_by_stats(const char *vconn_name,
  * 'port_name' (which may be a port name or number), and copies it into
  * '*pp'. */
 static void
-fetch_ofputil_phy_port(const char *vconn_name, const char *port_name,
+fetch_ofputil_phy_port(struct vconn *vconn, const char *port_name,
                        struct ofputil_phy_port *pp)
 {
     unsigned int port_no;
@@ -725,14 +721,15 @@ fetch_ofputil_phy_port(const char *vconn_name, const char *port_name,
     /* Try to find the port based on the Features Reply.  If it looks
      * like the results may be truncated, then use the Port Description
      * stats message introduced in OVS 1.7. */
-    found = fetch_port_by_features(vconn_name, port_name, port_no, pp,
+    found = fetch_port_by_features(vconn, port_name, port_no, pp,
                                    &trunc);
     if (trunc) {
-        found = fetch_port_by_stats(vconn_name, port_name, port_no, pp);
+        found = fetch_port_by_stats(vconn, port_name, port_no, pp);
     }
 
     if (!found) {
-        ovs_fatal(0, "%s: couldn't find port `%s'", vconn_name, port_name);
+        ovs_fatal(0, "%s: couldn't find port `%s'",
+                  vconn_get_name(vconn), port_name);
     }
 }
 
@@ -769,7 +766,7 @@ str_to_port_no(struct vconn *vconn, const char *port_name)
     } else {
         struct ofputil_phy_port pp;
 
-        fetch_ofputil_phy_port(vconn_get_name(vconn), port_name, &pp);
+        fetch_ofputil_phy_port(vconn, port_name, &pp);
         return pp.port_no;
     }
 
@@ -1553,7 +1550,9 @@ ofctl_mod_port(int argc OVS_UNUSED, char *argv[])
     const char *command;
     bool not;
 
-    fetch_ofputil_phy_port(argv[1], argv[2], &pp);
+    protocol = open_vconn(argv[1], &vconn);
+
+    fetch_ofputil_phy_port(vconn, argv[2], &pp);
 
     pm.port_no = pp.port_no;
     memcpy(pm.hw_addr, pp.hw_addr, ETH_ADDR_LEN);
@@ -1581,7 +1580,6 @@ ofctl_mod_port(int argc OVS_UNUSED, char *argv[])
     ovs_fatal(0, "unknown mod-port command '%s'", argv[3]);
 
 found:
-    protocol = open_vconn(argv[1], &vconn);
     transact_noreply(vconn, ofputil_encode_port_mod(&pm, protocol));
     vconn_close(vconn);
 }
-- 
1.7.10.2.484.gcd07cc5




More information about the dev mailing list