/* Provider interface, which provide a virtual connection to an OpenFlow
* device. */
+#include <assert.h>
#include "vconn.h"
-/* Virtual connection to an OpenFlow device. */
+/* Virtual connection to an OpenFlow device.
+ *
+ * This structure should be treated as opaque by vconn implementations. */
struct vconn {
struct vconn_class *class;
int connect_status;
void vconn_init(struct vconn *, struct vconn_class *, int connect_status,
uint32_t ip, const char *name);
+static inline void vconn_assert_class(const struct vconn *vconn,
+ const struct vconn_class *class)
+{
+ assert(vconn->class == class);
+}
struct vconn_class {
/* Prefix for connection names, e.g. "nl", "tcp". */
static struct netlink_vconn *
netlink_vconn_cast(struct vconn *vconn)
{
- assert(vconn->class == &netlink_vconn_class);
+ vconn_assert_class(vconn, &netlink_vconn_class);
return CONTAINER_OF(vconn, struct netlink_vconn, vconn);
}
static struct ssl_vconn *
ssl_vconn_cast(struct vconn *vconn)
{
- assert(vconn->class == &ssl_vconn_class);
+ vconn_assert_class(vconn, &ssl_vconn_class);
return CONTAINER_OF(vconn, struct ssl_vconn, vconn);
}
static struct pssl_vconn *
pssl_vconn_cast(struct vconn *vconn)
{
- assert(vconn->class == &pssl_vconn_class);
+ vconn_assert_class(vconn, &pssl_vconn_class);
return CONTAINER_OF(vconn, struct pssl_vconn, vconn);
}
static struct stream_vconn *
stream_vconn_cast(struct vconn *vconn)
{
- assert(vconn->class == &stream_vconn_class);
+ vconn_assert_class(vconn, &stream_vconn_class);
return CONTAINER_OF(vconn, struct stream_vconn, vconn);
}
static struct pstream_vconn *
pstream_vconn_cast(struct vconn *vconn)
{
- assert(vconn->class == &pstream_vconn_class);
+ vconn_assert_class(vconn, &pstream_vconn_class);
return CONTAINER_OF(vconn, struct pstream_vconn, vconn);
}