[ovs-dev] [tests+nxm-ofctl 11/42] Convert stream and vconn interfaces to use ovs_be16, ovs_be32.

Ben Pfaff blp at nicira.com
Tue Nov 23 22:43:43 UTC 2010


---
 lib/netdev-dummy.c    |   42 ++++++++++++++++++++----------------------
 lib/stream-provider.h |   18 +++++++++---------
 lib/stream.c          |   16 ++++++++--------
 lib/stream.h          |    9 +++++----
 lib/vconn-provider.h  |   18 +++++++++---------
 lib/vconn.c           |   22 +++++++++++-----------
 lib/vconn.h           |    8 ++++----
 7 files changed, 66 insertions(+), 67 deletions(-)

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index a29a766..ddcbe36 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -39,6 +39,7 @@ struct netdev_dev_dummy {
     uint8_t hwaddr[ETH_ADDR_LEN];
     int mtu;
     struct netdev_stats stats;
+    enum netdev_flags flags;
 };
 
 struct netdev_dummy {
@@ -90,6 +91,7 @@ netdev_dummy_create(const struct netdev_class *class, const char *name,
     netdev_dev->hwaddr[4] = n >> 8;
     netdev_dev->hwaddr[5] = n;
     netdev_dev->mtu = 1500;
+    netdev_dev->flags = 0;
 
     n++;
 
@@ -183,41 +185,41 @@ netdev_dummy_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
 }
 
 static int
-netdev_dummy_update_flags(struct netdev *netdev OVS_UNUSED,
-                          enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
+netdev_dummy_update_flags(struct netdev *netdev,
+                          enum netdev_flags off, enum netdev_flags on,
                           enum netdev_flags *old_flagsp)
 {
-    if (off & (NETDEV_UP | NETDEV_PROMISC)) {
-        return EOPNOTSUPP;
+    struct netdev_dev_dummy *dev =
+        netdev_dev_dummy_cast(netdev_get_dev(netdev));
+
+    if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
+        return EINVAL;
     }
 
-    *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
+    *old_flagsp = dev->flags;
+    dev->flags |= on;
+    dev->flags &= ~off;
+    if (*old_flagsp != dev->flags) {
+        netdev_dummy_poll_notify(netdev);
+    }
     return 0;
 }
 
-static char *
-make_poll_name(const struct netdev *netdev)
-{
-    return xasprintf("%s:%s",
-                     netdev_get_type(netdev), netdev_get_name(netdev));
-}
-
 static int
 netdev_dummy_poll_add(struct netdev *netdev,
                       void (*cb)(struct netdev_notifier *), void *aux,
                       struct netdev_notifier **notifierp)
 {
-    char *poll_name = make_poll_name(netdev);
+    const char *name = netdev_get_name(netdev);
     struct netdev_dummy_notifier *notifier;
     struct list *list;
     struct shash_node *shash_node;
 
-    shash_node = shash_find_data(&netdev_dummy_notifiers, poll_name);
+    shash_node = shash_find_data(&netdev_dummy_notifiers, name);
     if (!shash_node) {
         list = xmalloc(sizeof *list);
         list_init(list);
-        shash_node = shash_add(&netdev_dummy_notifiers,
-                               netdev_get_name(netdev), list);
+        shash_node = shash_add(&netdev_dummy_notifiers, name, list);
     } else {
         list = shash_node->data;
     }
@@ -228,7 +230,6 @@ netdev_dummy_poll_add(struct netdev *netdev,
     notifier->shash_node = shash_node;
 
     *notifierp = &notifier->notifier;
-    free(poll_name);
 
     return 0;
 }
@@ -255,9 +256,8 @@ netdev_dummy_poll_remove(struct netdev_notifier *notifier_)
 static void
 netdev_dummy_poll_notify(const struct netdev *netdev)
 {
-    char *poll_name = make_poll_name(netdev);
-    struct list *list = shash_find_data(&netdev_dummy_notifiers,
-                                        poll_name);
+    const char *name = netdev_get_name(netdev);
+    struct list *list = shash_find_data(&netdev_dummy_notifiers, name);
 
     if (list) {
         struct netdev_dummy_notifier *notifier;
@@ -267,8 +267,6 @@ netdev_dummy_poll_notify(const struct netdev *netdev)
             n->cb(n);
         }
     }
-
-    free(poll_name);
 }
 
 static const struct netdev_class dummy_class = {
diff --git a/lib/stream-provider.h b/lib/stream-provider.h
index d6bf0a2..2b8ca69 100644
--- a/lib/stream-provider.h
+++ b/lib/stream-provider.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,19 +30,19 @@ struct stream {
     struct stream_class *class;
     int state;
     int error;
-    uint32_t remote_ip;
-    uint16_t remote_port;
-    uint32_t local_ip;
-    uint16_t local_port;
+    ovs_be32 remote_ip;
+    ovs_be16 remote_port;
+    ovs_be32 local_ip;
+    ovs_be16 local_port;
     char *name;
 };
 
 void stream_init(struct stream *, struct stream_class *, int connect_status,
                  const char *name);
-void stream_set_remote_ip(struct stream *, uint32_t remote_ip);
-void stream_set_remote_port(struct stream *, uint16_t remote_port);
-void stream_set_local_ip(struct stream *, uint32_t local_ip);
-void stream_set_local_port(struct stream *, uint16_t local_port);
+void stream_set_remote_ip(struct stream *, ovs_be32 remote_ip);
+void stream_set_remote_port(struct stream *, ovs_be16 remote_port);
+void stream_set_local_ip(struct stream *, ovs_be32 local_ip);
+void stream_set_local_port(struct stream *, ovs_be16 local_port);
 static inline void stream_assert_class(const struct stream *stream,
                                        const struct stream_class *class)
 {
diff --git a/lib/stream.c b/lib/stream.c
index eb75be8..44d94d7 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -280,7 +280,7 @@ stream_get_name(const struct stream *stream)
 
 /* 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. */
-uint32_t
+ovs_be32
 stream_get_remote_ip(const struct stream *stream)
 {
     return stream->remote_ip;
@@ -288,7 +288,7 @@ stream_get_remote_ip(const struct stream *stream)
 
 /* 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. */
-uint16_t
+ovs_be16
 stream_get_remote_port(const struct stream *stream)
 {
     return stream->remote_port;
@@ -296,7 +296,7 @@ stream_get_remote_port(const struct stream *stream)
 
 /* 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. */
-uint32_t
+ovs_be32
 stream_get_local_ip(const struct stream *stream)
 {
     return stream->local_ip;
@@ -304,7 +304,7 @@ stream_get_local_ip(const struct stream *stream)
 
 /* 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. */
-uint16_t
+ovs_be16
 stream_get_local_port(const struct stream *stream)
 {
     return stream->local_port;
@@ -623,25 +623,25 @@ stream_init(struct stream *stream, struct stream_class *class,
 }
 
 void
-stream_set_remote_ip(struct stream *stream, uint32_t ip)
+stream_set_remote_ip(struct stream *stream, ovs_be32 ip)
 {
     stream->remote_ip = ip;
 }
 
 void
-stream_set_remote_port(struct stream *stream, uint16_t port)
+stream_set_remote_port(struct stream *stream, ovs_be16 port)
 {
     stream->remote_port = port;
 }
 
 void
-stream_set_local_ip(struct stream *stream, uint32_t ip)
+stream_set_local_ip(struct stream *stream, ovs_be32 ip)
 {
     stream->local_ip = ip;
 }
 
 void
-stream_set_local_port(struct stream *stream, uint16_t port)
+stream_set_local_port(struct stream *stream, ovs_be16 port)
 {
     stream->local_port = port;
 }
diff --git a/lib/stream.h b/lib/stream.h
index 5c536c6..2482bf2 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -20,6 +20,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
+#include "openvswitch/types.h"
 #include "vlog.h"
 
 struct pstream;
@@ -33,10 +34,10 @@ int stream_open(const char *name, struct stream **);
 int stream_open_block(int error, struct stream **);
 void stream_close(struct stream *);
 const char *stream_get_name(const struct stream *);
-uint32_t stream_get_remote_ip(const struct stream *);
-uint16_t stream_get_remote_port(const struct stream *);
-uint32_t stream_get_local_ip(const struct stream *);
-uint16_t stream_get_local_port(const struct stream *);
+ovs_be32 stream_get_remote_ip(const struct stream *);
+ovs_be16 stream_get_remote_port(const struct stream *);
+ovs_be32 stream_get_local_ip(const struct stream *);
+ovs_be16 stream_get_local_port(const struct stream *);
 int stream_connect(struct stream *);
 int stream_recv(struct stream *, void *buffer, size_t n);
 int stream_send(struct stream *, const void *buffer, size_t n);
diff --git a/lib/vconn-provider.h b/lib/vconn-provider.h
index 1c8b86d..682a593 100644
--- a/lib/vconn-provider.h
+++ b/lib/vconn-provider.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,19 +34,19 @@ struct vconn {
     int error;
     int min_version;
     int version;
-    uint32_t remote_ip;
-    uint16_t remote_port;
-    uint32_t local_ip;
-    uint16_t local_port;
+    ovs_be32 remote_ip;
+    ovs_be16 remote_port;
+    ovs_be32 local_ip;
+    ovs_be16 local_port;
     char *name;
 };
 
 void vconn_init(struct vconn *, struct vconn_class *, int connect_status,
                 const char *name);
-void vconn_set_remote_ip(struct vconn *, uint32_t remote_ip);
-void vconn_set_remote_port(struct vconn *, uint16_t remote_port);
-void vconn_set_local_ip(struct vconn *, uint32_t local_ip);
-void vconn_set_local_port(struct vconn *, uint16_t local_port);
+void vconn_set_remote_ip(struct vconn *, ovs_be32 remote_ip);
+void vconn_set_remote_port(struct vconn *, ovs_be16 remote_port);
+void vconn_set_local_ip(struct vconn *, ovs_be32 local_ip);
+void vconn_set_local_port(struct vconn *, ovs_be16 local_port);
 static inline void vconn_assert_class(const struct vconn *vconn,
                                       const struct vconn_class *class)
 {
diff --git a/lib/vconn.c b/lib/vconn.c
index 380e374..3804061 100644
--- a/lib/vconn.c
+++ b/lib/vconn.c
@@ -317,7 +317,7 @@ vconn_get_name(const struct vconn *vconn)
 
 /* 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. */
-uint32_t
+ovs_be32
 vconn_get_remote_ip(const struct vconn *vconn)
 {
     return vconn->remote_ip;
@@ -325,7 +325,7 @@ vconn_get_remote_ip(const struct vconn *vconn)
 
 /* 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. */
-uint16_t
+ovs_be16
 vconn_get_remote_port(const struct vconn *vconn)
 {
     return vconn->remote_port;
@@ -334,7 +334,7 @@ vconn_get_remote_port(const struct vconn *vconn)
 /* 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. */
-uint32_t
+ovs_be32
 vconn_get_local_ip(const struct vconn *vconn)
 {
     return vconn->local_ip;
@@ -342,7 +342,7 @@ vconn_get_local_ip(const struct vconn *vconn)
 
 /* 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. */
-uint16_t
+ovs_be16
 vconn_get_local_port(const struct vconn *vconn)
 {
     return vconn->local_port;
@@ -648,10 +648,10 @@ vconn_recv_block(struct vconn *vconn, struct ofpbuf **msgp)
  *
  * 'request' is always destroyed, regardless of the return value. */
 int
-vconn_recv_xid(struct vconn *vconn, uint32_t xid, struct ofpbuf **replyp)
+vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp)
 {
     for (;;) {
-        uint32_t recv_xid;
+        ovs_be32 recv_xid;
         struct ofpbuf *reply;
         int error;
 
@@ -683,7 +683,7 @@ int
 vconn_transact(struct vconn *vconn, struct ofpbuf *request,
                struct ofpbuf **replyp)
 {
-    uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
+    ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
     int error;
 
     *replyp = NULL;
@@ -903,25 +903,25 @@ vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
 }
 
 void
-vconn_set_remote_ip(struct vconn *vconn, uint32_t ip)
+vconn_set_remote_ip(struct vconn *vconn, ovs_be32 ip)
 {
     vconn->remote_ip = ip;
 }
 
 void
-vconn_set_remote_port(struct vconn *vconn, uint16_t port)
+vconn_set_remote_port(struct vconn *vconn, ovs_be16 port)
 {
     vconn->remote_port = port;
 }
 
 void
-vconn_set_local_ip(struct vconn *vconn, uint32_t ip)
+vconn_set_local_ip(struct vconn *vconn, ovs_be32 ip)
 {
     vconn->local_ip = ip;
 }
 
 void
-vconn_set_local_port(struct vconn *vconn, uint16_t port)
+vconn_set_local_port(struct vconn *vconn, ovs_be16 port)
 {
     vconn->local_port = port;
 }
diff --git a/lib/vconn.h b/lib/vconn.h
index 80846ff..e341205 100644
--- a/lib/vconn.h
+++ b/lib/vconn.h
@@ -39,10 +39,10 @@ int vconn_verify_name(const char *name);
 int vconn_open(const char *name, int min_version, struct vconn **);
 void vconn_close(struct vconn *);
 const char *vconn_get_name(const struct vconn *);
-uint32_t vconn_get_remote_ip(const struct vconn *);
-uint16_t vconn_get_remote_port(const struct vconn *);
-uint32_t vconn_get_local_ip(const struct vconn *);
-uint16_t vconn_get_local_port(const struct vconn *);
+ovs_be32 vconn_get_remote_ip(const struct vconn *);
+ovs_be16 vconn_get_remote_port(const struct vconn *);
+ovs_be32 vconn_get_local_ip(const struct vconn *);
+ovs_be16 vconn_get_local_port(const struct vconn *);
 int vconn_connect(struct vconn *);
 int vconn_recv(struct vconn *, struct ofpbuf **);
 int vconn_send(struct vconn *, struct ofpbuf *);
-- 
1.7.1





More information about the dev mailing list