PUD: add helper to determine speed on which to choose a gateway
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 16 Jan 2012 09:47:25 +0000 (10:47 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 16 Jan 2012 09:58:03 +0000 (10:58 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/uplinkGateway.c

index e470079..deba8aa 100644 (file)
 #include <stdbool.h>
 #include <sys/socket.h>
 
+/**
+ * Determine the speed on which a gateway is chosen
+ * @param uplink the uplink speed of the gateway
+ * @param downlink the downlink speed of the gateway
+ * @return the speed
+ */
+static inline unsigned long long gw_speed(struct gateway_entry *gw) {
+       return (gw->uplink + gw->downlink);
+}
+
 /**
  * Determine the best gateway for uplink: this is the cluster leader.
  *
@@ -59,7 +69,7 @@ union olsr_ip_addr * getBestUplinkGateway(void) {
                }
 
                if (eval4 || eval6) {
-                       unsigned long long gw_value = gw->uplink + gw->downlink;
+                       unsigned long long gw_value = gw_speed(gw);
                        if (gw_value > gw_best_value) {
                                gw_best = gw;
                                gw_best_value = gw_value;