lib/netdev-dpdk: increase ring name length for dpdkr ports
[cascardo/ovs.git] / lib / vconn.c
index 6c77d06..d835943 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
 
 #include <config.h>
 #include "vconn-provider.h"
-#include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <netinet/in.h>
@@ -38,7 +37,7 @@
 #include "poll-loop.h"
 #include "random.h"
 #include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 #include "socket-util.h"
 
 VLOG_DEFINE_THIS_MODULE(vconn);
@@ -60,7 +59,7 @@ enum vconn_state {
     VCS_DISCONNECTED            /* Connection failed or connection closed. */
 };
 
-static struct vconn_class *vconn_classes[] = {
+static const struct vconn_class *vconn_classes[] = {
     &tcp_vconn_class,
     &unix_vconn_class,
 #ifdef HAVE_OPENSSL
@@ -68,7 +67,7 @@ static struct vconn_class *vconn_classes[] = {
 #endif
 };
 
-static struct pvconn_class *pvconn_classes[] = {
+static const struct pvconn_class *pvconn_classes[] = {
     &ptcp_pvconn_class,
     &punix_pvconn_class,
 #ifdef HAVE_OPENSSL
@@ -96,28 +95,28 @@ check_vconn_classes(void)
     size_t i;
 
     for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
-        struct vconn_class *class = vconn_classes[i];
-        assert(class->name != NULL);
-        assert(class->open != NULL);
+        const struct vconn_class *class = vconn_classes[i];
+        ovs_assert(class->name != NULL);
+        ovs_assert(class->open != NULL);
         if (class->close || class->recv || class->send
             || class->run || class->run_wait || class->wait) {
-            assert(class->close != NULL);
-            assert(class->recv != NULL);
-            assert(class->send != NULL);
-            assert(class->wait != NULL);
+            ovs_assert(class->close != NULL);
+            ovs_assert(class->recv != NULL);
+            ovs_assert(class->send != NULL);
+            ovs_assert(class->wait != NULL);
         } else {
             /* This class delegates to another one. */
         }
     }
 
     for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
-        struct pvconn_class *class = pvconn_classes[i];
-        assert(class->name != NULL);
-        assert(class->listen != NULL);
+        const struct pvconn_class *class = pvconn_classes[i];
+        ovs_assert(class->name != NULL);
+        ovs_assert(class->listen != NULL);
         if (class->close || class->accept || class->wait) {
-            assert(class->close != NULL);
-            assert(class->accept != NULL);
-            assert(class->wait != NULL);
+            ovs_assert(class->close != NULL);
+            ovs_assert(class->accept != NULL);
+            ovs_assert(class->wait != NULL);
         } else {
             /* This class delegates to another one. */
         }
@@ -139,10 +138,10 @@ vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
     if (active) {
         printf("Active OpenFlow connection methods:\n");
         printf("  tcp:IP[:PORT]           "
-               "PORT (default: %d) at remote IP\n", OFP_TCP_PORT);
+               "PORT (default: %d) at remote IP\n", OFP_PORT);
 #ifdef HAVE_OPENSSL
         printf("  ssl:IP[:PORT]           "
-               "SSL PORT (default: %d) at remote IP\n", OFP_SSL_PORT);
+               "SSL PORT (default: %d) at remote IP\n", OFP_PORT);
 #endif
         printf("  unix:FILE               Unix domain socket named FILE\n");
     }
@@ -151,11 +150,11 @@ vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
         printf("Passive OpenFlow connection methods:\n");
         printf("  ptcp:[PORT][:IP]        "
                "listen to TCP PORT (default: %d) on IP\n",
-               OFP_TCP_PORT);
+               OFP_PORT);
 #ifdef HAVE_OPENSSL
         printf("  pssl:[PORT][:IP]        "
                "listen for SSL on PORT (default: %d) on IP\n",
-               OFP_SSL_PORT);
+               OFP_PORT);
 #endif
         printf("  punix:FILE              "
                "listen on Unix domain socket FILE\n");
@@ -178,7 +177,7 @@ vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
  * a null pointer into '*classp' if 'name' is in the wrong form or if no such
  * class exists. */
 static int
-vconn_lookup_class(const char *name, struct vconn_class **classp)
+vconn_lookup_class(const char *name, const struct vconn_class **classp)
 {
     size_t prefix_len;
 
@@ -187,7 +186,7 @@ vconn_lookup_class(const char *name, struct vconn_class **classp)
         size_t i;
 
         for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
-            struct vconn_class *class = vconn_classes[i];
+            const struct vconn_class *class = vconn_classes[i];
             if (strlen(class->name) == prefix_len
                 && !memcmp(class->name, name, prefix_len)) {
                 *classp = class;
@@ -205,7 +204,7 @@ vconn_lookup_class(const char *name, struct vconn_class **classp)
 int
 vconn_verify_name(const char *name)
 {
-    struct vconn_class *class;
+    const struct vconn_class *class;
     return vconn_lookup_class(name, &class);
 }
 
@@ -223,10 +222,10 @@ vconn_verify_name(const char *name)
  * stores a pointer to the new connection in '*vconnp', otherwise a null
  * pointer.  */
 int
-vconn_open(const char *name, uint32_t allowed_versions,
-           struct vconn **vconnp, uint8_t dscp)
+vconn_open(const char *name, uint32_t allowed_versions, uint8_t dscp,
+           struct vconn **vconnp)
 {
-    struct vconn_class *class;
+    const struct vconn_class *class;
     struct vconn *vconn;
     char *suffix_copy;
     int error;
@@ -253,7 +252,7 @@ vconn_open(const char *name, uint32_t allowed_versions,
     }
 
     /* Success. */
-    assert(vconn->state != VCS_CONNECTING || vconn->class->connect);
+    ovs_assert(vconn->state != VCS_CONNECTING || vconn->vclass->connect);
     *vconnp = vconn;
     return 0;
 
@@ -273,8 +272,8 @@ vconn_run(struct vconn *vconn)
         vconn_connect(vconn);
     }
 
-    if (vconn->class->run) {
-        (vconn->class->run)(vconn);
+    if (vconn->vclass->run) {
+        (vconn->vclass->run)(vconn);
     }
 }
 
@@ -289,13 +288,22 @@ vconn_run_wait(struct vconn *vconn)
         vconn_connect_wait(vconn);
     }
 
-    if (vconn->class->run_wait) {
-        (vconn->class->run_wait)(vconn);
+    if (vconn->vclass->run_wait) {
+        (vconn->vclass->run_wait)(vconn);
     }
 }
 
+/* Returns 0 if 'vconn' is healthy (connecting or connected), a positive errno
+ * value if the connection died abnormally (connection failed or aborted), or
+ * EOF if the connection was closed in a normal way. */
 int
-vconn_open_block(const char *name, uint32_t allowed_versions,
+vconn_get_status(const struct vconn *vconn)
+{
+    return vconn->error == EAGAIN ? 0 : vconn->error;
+}
+
+int
+vconn_open_block(const char *name, uint32_t allowed_versions, uint8_t dscp,
                  struct vconn **vconnp)
 {
     struct vconn *vconn;
@@ -303,7 +311,7 @@ vconn_open_block(const char *name, uint32_t allowed_versions,
 
     fatal_signal_run();
 
-    error = vconn_open(name, allowed_versions, &vconn, DSCP_DEFAULT);
+    error = vconn_open(name, allowed_versions, dscp, &vconn);
     if (!error) {
         error = vconn_connect_block(vconn);
     }
@@ -323,7 +331,7 @@ vconn_close(struct vconn *vconn)
 {
     if (vconn != NULL) {
         char *name = vconn->name;
-        (vconn->class->close)(vconn);
+        (vconn->vclass->close)(vconn);
         free(name);
     }
 }
@@ -343,37 +351,12 @@ vconn_get_allowed_versions(const struct vconn *vconn)
     return vconn->allowed_versions;
 }
 
-/* Returns the IP address of the peer, or 0 if the peer is not connected over
- * an IP-based protocol or if its IP address is not yet known. */
-ovs_be32
-vconn_get_remote_ip(const struct vconn *vconn)
-{
-    return vconn->remote_ip;
-}
-
-/* Returns the transport port of the peer, or 0 if the connection does not
- * contain a port or if the port is not yet known. */
-ovs_be16
-vconn_get_remote_port(const struct vconn *vconn)
-{
-    return vconn->remote_port;
-}
-
-/* Returns the IP address used to connect to the peer, or 0 if the
- * connection is not an IP-based protocol or if its IP address is not
- * yet known. */
-ovs_be32
-vconn_get_local_ip(const struct vconn *vconn)
-{
-    return vconn->local_ip;
-}
-
-/* Returns the transport port used to connect to the peer, or 0 if the
- * connection does not contain a port or if the port is not yet known. */
-ovs_be16
-vconn_get_local_port(const struct vconn *vconn)
+/* Sets the allowed_versions of 'vconn', overriding
+ * the allowed_versions passed to vconn_open(). */
+void
+vconn_set_allowed_versions(struct vconn *vconn, uint32_t allowed_versions)
 {
-    return vconn->local_port;
+    vconn->allowed_versions = allowed_versions;
 }
 
 /* Returns the OpenFlow version negotiated with the peer, or -1 if version
@@ -387,11 +370,32 @@ vconn_get_version(const struct vconn *vconn)
     return vconn->version ? vconn->version : -1;
 }
 
+/* By default, a vconn accepts only OpenFlow messages whose version matches the
+ * one negotiated for the connection.  A message received with a different
+ * version is an error that causes the vconn to drop the connection.
+ *
+ * This functions allows 'vconn' to accept messages with any OpenFlow version.
+ * This is useful in the special case where 'vconn' is used as an rconn
+ * "monitor" connection (see rconn_add_monitor()), that is, where 'vconn' is
+ * used as a target for mirroring OpenFlow messages for debugging and
+ * troubleshooting.
+ *
+ * This function should be called after a successful vconn_open() or
+ * pvconn_accept() but before the connection completes, that is, before
+ * vconn_connect() returns success.  Otherwise, messages that arrive on 'vconn'
+ * beforehand with an unexpected version will the vconn to drop the
+ * connection. */
+void
+vconn_set_recv_any_version(struct vconn *vconn)
+{
+    vconn->recv_any_version = true;
+}
+
 static void
 vcs_connecting(struct vconn *vconn)
 {
-    int retval = (vconn->class->connect)(vconn);
-    assert(retval != EINPROGRESS);
+    int retval = (vconn->vclass->connect)(vconn);
+    ovs_assert(retval != EINPROGRESS);
     if (!retval) {
         vconn->state = VCS_SEND_HELLO;
     } else if (retval != EAGAIN) {
@@ -433,7 +437,7 @@ version_bitmap_to_string(uint32_t bitmap)
     } else if (is_pow2((bitmap >> 1) + 1)) {
         ds_put_cstr(&s, "version ");
         ofputil_format_version(&s, leftmost_1bit_idx(bitmap));
-        ds_put_cstr(&s, "and earlier");
+        ds_put_cstr(&s, " and earlier");
     } else {
         ds_put_cstr(&s, "versions ");
         ofputil_format_version_bitmap(&s, bitmap);
@@ -568,7 +572,7 @@ vconn_connect(struct vconn *vconn)
             return vconn->error;
 
         default:
-            NOT_REACHED();
+            OVS_NOT_REACHED();
         }
     } while (vconn->state != last_state);
 
@@ -593,7 +597,7 @@ vconn_recv(struct vconn *vconn, struct ofpbuf **msgp)
     if (!retval) {
         retval = do_recv(vconn, &msg);
     }
-    if (!retval) {
+    if (!retval && !vconn->recv_any_version) {
         const struct ofp_header *oh = msg->data;
         if (oh->version != vconn->version) {
             enum ofptype type;
@@ -603,11 +607,25 @@ vconn_recv(struct vconn *vconn, struct ofpbuf **msgp)
                     type != OFPTYPE_ERROR &&
                     type != OFPTYPE_ECHO_REQUEST &&
                     type != OFPTYPE_ECHO_REPLY)) {
+                struct ofpbuf *reply;
+
                 VLOG_ERR_RL(&bad_ofmsg_rl, "%s: received OpenFlow version "
                             "0x%02"PRIx8" != expected %02x",
                             vconn->name, oh->version, vconn->version);
+
+                /* Send a "bad version" reply, if we can. */
+                reply = ofperr_encode_reply(OFPERR_OFPBRC_BAD_VERSION, oh);
+                retval = vconn_send(vconn, reply);
+                if (retval) {
+                    VLOG_INFO_RL(&bad_ofmsg_rl,
+                                 "%s: failed to queue error reply (%s)",
+                                 vconn->name, ovs_strerror(retval));
+                    ofpbuf_delete(reply);
+                }
+
+                /* Suppress the received message, as if it had not arrived. */
+                retval = EAGAIN;
                 ofpbuf_delete(msg);
-                retval = EPROTO;
             }
         }
     }
@@ -619,7 +637,7 @@ vconn_recv(struct vconn *vconn, struct ofpbuf **msgp)
 static int
 do_recv(struct vconn *vconn, struct ofpbuf **msgp)
 {
-    int retval = (vconn->class->recv)(vconn, msgp);
+    int retval = (vconn->vclass->recv)(vconn, msgp);
     if (!retval) {
         COVERAGE_INC(vconn_received);
         if (VLOG_IS_DBG_ENABLED()) {
@@ -656,18 +674,18 @@ do_send(struct vconn *vconn, struct ofpbuf *msg)
 {
     int retval;
 
-    assert(msg->size >= sizeof(struct ofp_header));
+    ovs_assert(msg->size >= sizeof(struct ofp_header));
 
     ofpmsg_update_length(msg);
     if (!VLOG_IS_DBG_ENABLED()) {
         COVERAGE_INC(vconn_sent);
-        retval = (vconn->class->send)(vconn, msg);
+        retval = (vconn->vclass->send)(vconn, msg);
     } else {
         char *s = ofp_to_string(msg->data, msg->size, 1);
-        retval = (vconn->class->send)(vconn, msg);
+        retval = (vconn->vclass->send)(vconn, msg);
         if (retval != EAGAIN) {
             VLOG_DBG_RL(&ofmsg_rl, "%s: sent (%s): %s",
-                        vconn->name, strerror(retval), s);
+                        vconn->name, ovs_strerror(retval), s);
         }
         free(s);
     }
@@ -687,7 +705,7 @@ vconn_connect_block(struct vconn *vconn)
         vconn_connect_wait(vconn);
         poll_block();
     }
-    assert(error != EINPROGRESS);
+    ovs_assert(error != EINPROGRESS);
 
     return error;
 }
@@ -726,18 +744,15 @@ vconn_recv_block(struct vconn *vconn, struct ofpbuf **msgp)
     return retval;
 }
 
-/* Waits until a message with a transaction ID matching 'xid' is recived on
- * 'vconn'.  Returns 0 if successful, in which case the reply is stored in
- * '*replyp' for the caller to examine and free.  Otherwise returns a positive
- * errno value, or EOF, and sets '*replyp' to null.
- *
- * 'request' is always destroyed, regardless of the return value. */
-int
-vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp)
+static int
+vconn_recv_xid__(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp,
+                 void (*error_reporter)(const struct ofp_header *))
 {
     for (;;) {
         ovs_be32 recv_xid;
         struct ofpbuf *reply;
+        const struct ofp_header *oh;
+        enum ofptype type;
         int error;
 
         error = vconn_recv_block(vconn, &reply);
@@ -745,19 +760,54 @@ vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp)
             *replyp = NULL;
             return error;
         }
-        recv_xid = ((struct ofp_header *) reply->data)->xid;
+        oh = reply->data;
+        recv_xid = oh->xid;
         if (xid == recv_xid) {
             *replyp = reply;
             return 0;
         }
 
-        VLOG_DBG_RL(&bad_ofmsg_rl, "%s: received reply with xid %08"PRIx32
-                    " != expected %08"PRIx32,
-                    vconn->name, ntohl(recv_xid), ntohl(xid));
+        error = ofptype_decode(&type, oh);
+        if (!error && type == OFPTYPE_ERROR && error_reporter) {
+            error_reporter(oh);
+        } else {
+            VLOG_DBG_RL(&bad_ofmsg_rl, "%s: received reply with xid %08"PRIx32
+                        " != expected %08"PRIx32,
+                        vconn->name, ntohl(recv_xid), ntohl(xid));
+        }
         ofpbuf_delete(reply);
     }
 }
 
+/* Waits until a message with a transaction ID matching 'xid' is received on
+ * 'vconn'.  Returns 0 if successful, in which case the reply is stored in
+ * '*replyp' for the caller to examine and free.  Otherwise returns a positive
+ * errno value, or EOF, and sets '*replyp' to null.
+ *
+ * 'request' is always destroyed, regardless of the return value. */
+int
+vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp)
+{
+    return vconn_recv_xid__(vconn, xid, replyp, NULL);
+}
+
+static int
+vconn_transact__(struct vconn *vconn, struct ofpbuf *request,
+                 struct ofpbuf **replyp,
+                 void (*error_reporter)(const struct ofp_header *))
+{
+    ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
+    int error;
+
+    *replyp = NULL;
+    error = vconn_send_block(vconn, request);
+    if (error) {
+        ofpbuf_delete(request);
+    }
+    return error ? error : vconn_recv_xid__(vconn, send_xid, replyp,
+                                            error_reporter);
+}
+
 /* Sends 'request' to 'vconn' and blocks until it receives a reply with a
  * matching transaction ID.  Returns 0 if successful, in which case the reply
  * is stored in '*replyp' for the caller to examine and free.  Otherwise
@@ -772,15 +822,7 @@ int
 vconn_transact(struct vconn *vconn, struct ofpbuf *request,
                struct ofpbuf **replyp)
 {
-    ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
-    int error;
-
-    *replyp = NULL;
-    error = vconn_send_block(vconn, request);
-    if (error) {
-        ofpbuf_delete(request);
-    }
-    return error ? error : vconn_recv_xid(vconn, send_xid, replyp);
+    return vconn_transact__(vconn, request, replyp, NULL);
 }
 
 /* Sends 'request' followed by a barrier request to 'vconn', then blocks until
@@ -860,16 +902,14 @@ vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request,
  * All of the requests on 'requests' are always destroyed, regardless of the
  * return value. */
 int
-vconn_transact_multiple_noreply(struct vconn *vconn, struct list *requests,
+vconn_transact_multiple_noreply(struct vconn *vconn, struct ovs_list *requests,
                                 struct ofpbuf **replyp)
 {
-    struct ofpbuf *request, *next;
+    struct ofpbuf *request;
 
-    LIST_FOR_EACH_SAFE (request, next, list_node, requests) {
+    LIST_FOR_EACH_POP (request, list_node, requests) {
         int error;
 
-        list_remove(&request->list_node);
-
         error = vconn_transact_noreply(vconn, request, replyp);
         if (error || *replyp) {
             ofpbuf_list_delete(requests);
@@ -881,10 +921,183 @@ vconn_transact_multiple_noreply(struct vconn *vconn, struct list *requests,
     return 0;
 }
 
+static enum ofperr
+vconn_bundle_reply_validate(struct ofpbuf *reply,
+                            struct ofputil_bundle_ctrl_msg *request,
+                            void (*error_reporter)(const struct ofp_header *))
+{
+    const struct ofp_header *oh;
+    enum ofptype type;
+    enum ofperr error;
+    struct ofputil_bundle_ctrl_msg rbc;
+
+    oh = reply->data;
+    error = ofptype_decode(&type, oh);
+    if (error) {
+        return error;
+    }
+
+    if (type == OFPTYPE_ERROR) {
+        error_reporter(oh);
+        return ofperr_decode_msg(oh, NULL);
+    }
+    if (type != OFPTYPE_BUNDLE_CONTROL) {
+        return OFPERR_OFPBRC_BAD_TYPE;
+    }
+
+    error = ofputil_decode_bundle_ctrl(oh, &rbc);
+    if (error) {
+        return error;
+    }
+
+    if (rbc.bundle_id != request->bundle_id) {
+        return OFPERR_OFPBFC_BAD_ID;
+    }
+
+    if (rbc.type != request->type + 1) {
+        return OFPERR_OFPBFC_BAD_TYPE;
+    }
+
+    return 0;
+}
+
+/* Send bundle control message 'bc' of 'type' via 'vconn', and wait for either
+ * an error or the corresponding bundle control message response.
+ *
+ * 'error_reporter' is called for any error responses received, which may be
+ * also regarding earlier OpenFlow messages than this bundle control message.
+ *
+ * Returns errno value, or 0 when successful. */
+static int
+vconn_bundle_control_transact(struct vconn *vconn,
+                              struct ofputil_bundle_ctrl_msg *bc,
+                              uint16_t type,
+                              void (*error_reporter)(const struct ofp_header *))
+{
+    struct ofpbuf *request, *reply;
+    int error;
+    enum ofperr ofperr;
+
+    bc->type = type;
+    request = ofputil_encode_bundle_ctrl_request(vconn->version, bc);
+    ofpmsg_update_length(request);
+    error = vconn_transact__(vconn, request, &reply, error_reporter);
+    if (error) {
+        return error;
+    }
+
+    ofperr = vconn_bundle_reply_validate(reply, bc, error_reporter);
+    if (ofperr) {
+        VLOG_WARN_RL(&bad_ofmsg_rl, "Bundle %s failed (%s).",
+                     type == OFPBCT_OPEN_REQUEST ? "open"
+                     : type == OFPBCT_CLOSE_REQUEST ? "close"
+                     : type == OFPBCT_COMMIT_REQUEST ? "commit"
+                     : type == OFPBCT_DISCARD_REQUEST ? "discard"
+                     : "control message",
+                     ofperr_to_string(ofperr));
+    }
+    ofpbuf_delete(reply);
+
+    return ofperr ? EPROTO : 0;
+}
+
+/* Checks if error responses can be received on 'vconn'. */
+static void
+vconn_recv_error(struct vconn *vconn,
+                 void (*error_reporter)(const struct ofp_header *))
+{
+    int error;
+
+    do {
+        struct ofpbuf *reply;
+
+        error = vconn_recv(vconn, &reply);
+        if (!error) {
+            const struct ofp_header *oh;
+            enum ofptype type;
+            enum ofperr ofperr;
+
+            oh = reply->data;
+            ofperr = ofptype_decode(&type, oh);
+            if (!ofperr && type == OFPTYPE_ERROR) {
+                error_reporter(oh);
+            } else {
+                VLOG_DBG_RL(&bad_ofmsg_rl,
+                            "%s: received unexpected reply with xid %08"PRIx32,
+                            vconn->name, ntohl(oh->xid));
+            }
+            ofpbuf_delete(reply);
+        }
+    } while (!error);
+}
+
+static int
+vconn_bundle_add_msg(struct vconn *vconn, struct ofputil_bundle_ctrl_msg *bc,
+                     struct ofpbuf *msg,
+                     void (*error_reporter)(const struct ofp_header *))
+{
+    struct ofputil_bundle_add_msg bam;
+    struct ofpbuf *request;
+    int error;
+
+    bam.bundle_id = bc->bundle_id;
+    bam.flags = bc->flags;
+    bam.msg = msg->data;
+
+    request = ofputil_encode_bundle_add(vconn->version, &bam);
+    ofpmsg_update_length(request);
+
+    error = vconn_send_block(vconn, request);
+    if (!error) {
+        /* Check for an error return, so that the socket buffer does not become
+         * full of errors. */
+        vconn_recv_error(vconn, error_reporter);
+    }
+    return error;
+}
+
+int
+vconn_bundle_transact(struct vconn *vconn, struct ovs_list *requests,
+                      uint16_t flags,
+                      void (*error_reporter)(const struct ofp_header *))
+{
+    struct ofputil_bundle_ctrl_msg bc;
+    struct ofpbuf *request;
+    int error;
+
+    memset(&bc, 0, sizeof bc);
+    bc.flags = flags;
+    error = vconn_bundle_control_transact(vconn, &bc, OFPBCT_OPEN_REQUEST,
+                                          error_reporter);
+    if (error) {
+        return error;
+    }
+
+    LIST_FOR_EACH (request, list_node, requests) {
+        error = vconn_bundle_add_msg(vconn, &bc, request, error_reporter);
+        if (error) {
+            break;
+        }
+    }
+
+    if (!error) {
+        error = vconn_bundle_control_transact(vconn, &bc,
+                                              OFPBCT_COMMIT_REQUEST,
+                                              error_reporter);
+    } else {
+        /* Do not overwrite the error code from vconn_bundle_add_msg().
+         * Any error in discard should be either reported or logged, so it
+         * should not get lost. */
+        vconn_bundle_control_transact(vconn, &bc, OFPBCT_DISCARD_REQUEST,
+                                      error_reporter);
+    }
+    return error;
+}
+
 void
 vconn_wait(struct vconn *vconn, enum vconn_wait_type wait)
 {
-    assert(wait == WAIT_CONNECT || wait == WAIT_RECV || wait == WAIT_SEND);
+    ovs_assert(wait == WAIT_CONNECT || wait == WAIT_RECV || wait == WAIT_SEND);
 
     switch (vconn->state) {
     case VCS_CONNECTING:
@@ -907,7 +1120,7 @@ vconn_wait(struct vconn *vconn, enum vconn_wait_type wait)
         poll_immediate_wake();
         return;
     }
-    (vconn->class->wait)(vconn, wait);
+    (vconn->vclass->wait)(vconn, wait);
 }
 
 void
@@ -933,7 +1146,7 @@ vconn_send_wait(struct vconn *vconn)
  * a null pointer into '*classp' if 'name' is in the wrong form or if no such
  * class exists. */
 static int
-pvconn_lookup_class(const char *name, struct pvconn_class **classp)
+pvconn_lookup_class(const char *name, const struct pvconn_class **classp)
 {
     size_t prefix_len;
 
@@ -942,7 +1155,7 @@ pvconn_lookup_class(const char *name, struct pvconn_class **classp)
         size_t i;
 
         for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
-            struct pvconn_class *class = pvconn_classes[i];
+            const struct pvconn_class *class = pvconn_classes[i];
             if (strlen(class->name) == prefix_len
                 && !memcmp(class->name, name, prefix_len)) {
                 *classp = class;
@@ -960,7 +1173,7 @@ pvconn_lookup_class(const char *name, struct pvconn_class **classp)
 int
 pvconn_verify_name(const char *name)
 {
-    struct pvconn_class *class;
+    const struct pvconn_class *class;
     return pvconn_lookup_class(name, &class);
 }
 
@@ -978,10 +1191,10 @@ pvconn_verify_name(const char *name)
  * stores a pointer to the new connection in '*pvconnp', otherwise a null
  * pointer.  */
 int
-pvconn_open(const char *name, uint32_t allowed_versions,
-            struct pvconn **pvconnp, uint8_t dscp)
+pvconn_open(const char *name, uint32_t allowed_versions, uint8_t dscp,
+            struct pvconn **pvconnp)
 {
-    struct pvconn_class *class;
+    const struct pvconn_class *class;
     struct pvconn *pvconn;
     char *suffix_copy;
     int error;
@@ -1029,7 +1242,7 @@ pvconn_close(struct pvconn *pvconn)
 {
     if (pvconn != NULL) {
         char *name = pvconn->name;
-        (pvconn->class->close)(pvconn);
+        (pvconn->pvclass->close)(pvconn);
         free(name);
     }
 }
@@ -1047,12 +1260,12 @@ pvconn_close(struct pvconn *pvconn)
 int
 pvconn_accept(struct pvconn *pvconn, struct vconn **new_vconn)
 {
-    int retval = (pvconn->class->accept)(pvconn, new_vconn);
+    int retval = (pvconn->pvclass->accept)(pvconn, new_vconn);
     if (retval) {
         *new_vconn = NULL;
     } else {
-        assert((*new_vconn)->state != VCS_CONNECTING
-               || (*new_vconn)->class->connect);
+        ovs_assert((*new_vconn)->state != VCS_CONNECTING
+                   || (*new_vconn)->vclass->connect);
     }
     return retval;
 }
@@ -1060,7 +1273,7 @@ pvconn_accept(struct pvconn *pvconn, struct vconn **new_vconn)
 void
 pvconn_wait(struct pvconn *pvconn)
 {
-    (pvconn->class->wait)(pvconn);
+    (pvconn->pvclass->wait)(pvconn);
 }
 
 /* Initializes 'vconn' as a new vconn named 'name', implemented via 'class'.
@@ -1081,53 +1294,25 @@ pvconn_wait(struct pvconn *pvconn)
  *
  * The caller retains ownership of 'name'. */
 void
-vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
-           const char *name, uint32_t allowed_versions)
+vconn_init(struct vconn *vconn, const struct vconn_class *class,
+           int connect_status, const char *name, uint32_t allowed_versions)
 {
-    vconn->class = class;
+    memset(vconn, 0, sizeof *vconn);
+    vconn->vclass = class;
     vconn->state = (connect_status == EAGAIN ? VCS_CONNECTING
                     : !connect_status ? VCS_SEND_HELLO
                     : VCS_DISCONNECTED);
     vconn->error = connect_status;
-    vconn->version = 0;
     vconn->allowed_versions = allowed_versions;
-    vconn->remote_ip = 0;
-    vconn->remote_port = 0;
-    vconn->local_ip = 0;
-    vconn->local_port = 0;
     vconn->name = xstrdup(name);
-    assert(vconn->state != VCS_CONNECTING || class->connect);
-}
-
-void
-vconn_set_remote_ip(struct vconn *vconn, ovs_be32 ip)
-{
-    vconn->remote_ip = ip;
-}
-
-void
-vconn_set_remote_port(struct vconn *vconn, ovs_be16 port)
-{
-    vconn->remote_port = port;
-}
-
-void
-vconn_set_local_ip(struct vconn *vconn, ovs_be32 ip)
-{
-    vconn->local_ip = ip;
-}
-
-void
-vconn_set_local_port(struct vconn *vconn, ovs_be16 port)
-{
-    vconn->local_port = port;
+    ovs_assert(vconn->state != VCS_CONNECTING || class->connect);
 }
 
 void
-pvconn_init(struct pvconn *pvconn,  struct pvconn_class *class,
+pvconn_init(struct pvconn *pvconn, const struct pvconn_class *class,
             const char *name, uint32_t allowed_versions)
 {
-    pvconn->class = class;
+    pvconn->pvclass = class;
     pvconn->name = xstrdup(name);
     pvconn->allowed_versions = allowed_versions;
 }