Add missing <stdint.h> includes.
[openvswitch] / lib / netdev.c
index f5089c1de0cf4f2f937615af4beb7b1e3be95577..82a490419778edcd8601f60569d55f46a6d38059 100644 (file)
@@ -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.
@@ -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"
@@ -234,6 +235,7 @@ netdev_open(const char *name, int ethertype, struct netdev **netdevp)
 
     netdev_obj = shash_find_data(&netdev_obj_shash, name);
     if (netdev_obj) {
+        netdev_obj->ref_cnt++;
         error = netdev_obj->netdev_class->open(name, ethertype, &netdev);
     } else {
         /* Default to "system". */
@@ -248,16 +250,14 @@ netdev_open(const char *name, int ethertype, struct netdev **netdevp)
                  * closes its handle. */
                 error = class->create(name, "system", &empty_args, false);
                 if (!error) {
-                    error = class->open(name, ethertype, &netdev);
                     netdev_obj = shash_find_data(&netdev_obj_shash, name);
+                    netdev_obj->ref_cnt++;
+                    error = class->open(name, ethertype, &netdev);
                 }
                 break;
             }
         }
     }
-    if (!error) {
-        netdev_obj->ref_cnt++;
-    }
 
     *netdevp = error ? NULL : netdev;
     return error;
@@ -525,6 +525,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
@@ -1025,7 +1054,7 @@ restore_flags(struct netdev *netdev)
 /* Retores all the flags on all network devices that we modified.  Called from
  * a signal handler, so it does not attempt to report error conditions. */
 static void
-restore_all_flags(void *aux UNUSED)
+restore_all_flags(void *aux OVS_UNUSED)
 {
     struct netdev *netdev;
     LIST_FOR_EACH (netdev, struct netdev, node, &netdev_list) {