[ovs-dev] [PATCH 2/3] netdev: New functions for interpreting "enum ofp_port_features" bitmaps.
Ben Pfaff
blp at nicira.com
Tue Dec 22 00:29:24 UTC 2009
---
lib/netdev.c | 30 ++++++++++++++++++++++++++++++
lib/netdev.h | 2 ++
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/lib/netdev.c b/lib/netdev.c
index fb0f98e..d14b909 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -31,6 +31,7 @@
#include "list.h"
#include "netdev-provider.h"
#include "ofpbuf.h"
+#include "openflow/openflow.h"
#include "packets.h"
#include "poll-loop.h"
#include "shash.h"
@@ -525,6 +526,35 @@ netdev_get_features(struct netdev *netdev,
return error;
}
+/* Returns the maximum speed of a network connection that has the "enum
+ * ofp_port_features" bits in 'features', in bits per second. If no bits that
+ * indicate a speed are set in 'features', assumes 100Mbps. */
+uint64_t
+netdev_features_to_bps(uint32_t features)
+{
+ enum {
+ F_10000MB = OFPPF_10GB_FD,
+ F_1000MB = OFPPF_1GB_HD | OFPPF_1GB_FD,
+ F_100MB = OFPPF_100MB_HD | OFPPF_100MB_FD,
+ F_10MB = OFPPF_10MB_HD | OFPPF_10MB_FD
+ };
+
+ return ( features & F_10000MB ? UINT64_C(10000000000)
+ : features & F_1000MB ? UINT64_C(1000000000)
+ : features & F_100MB ? UINT64_C(100000000)
+ : features & F_10MB ? UINT64_C(10000000)
+ : UINT64_C(100000000));
+}
+
+/* Returns true if any of the "enum ofp_port_features" bits that indicate a
+ * full-duplex link are set in 'features', otherwise false. */
+bool
+netdev_features_is_full_duplex(uint32_t features)
+{
+ return (features & (OFPPF_10MB_FD | OFPPF_100MB_FD | OFPPF_1GB_FD
+ | OFPPF_10GB_FD)) != 0;
+}
+
/* Set the features advertised by 'netdev' to 'advertise'. Returns 0 if
* successful, otherwise a positive errno value. */
int
diff --git a/lib/netdev.h b/lib/netdev.h
index b8c7dfb..8060ddb 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -112,6 +112,8 @@ int netdev_get_carrier(const struct netdev *, bool *carrier);
int netdev_get_features(struct netdev *,
uint32_t *current, uint32_t *advertised,
uint32_t *supported, uint32_t *peer);
+uint64_t netdev_features_to_bps(uint32_t features);
+bool netdev_features_is_full_duplex(uint32_t features);
int netdev_set_advertisements(struct netdev *, uint32_t advertise);
int netdev_get_in4(const struct netdev *, struct in_addr *address,
--
1.6.3.3
More information about the dev
mailing list