[Olsr-dev] [PATCH v1 04/23] gateway: add interface to get the gateway costs

Ferry Huberts (spam-protected)
Tue Dec 4 16:17:11 CET 2012


From: Ferry Huberts <(spam-protected)>

We need it when we are going to keep the active gateway(s) in a list

Signed-off-by: Ferry Huberts <(spam-protected)>
Reviewed-by: Henning Rogge <(spam-protected)>
---
 src/gateway.h                 |  8 ++++++++
 src/gateway_default_handler.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/src/gateway.h b/src/gateway.h
index 5643884..8ac6eab 100644
--- a/src/gateway.h
+++ b/src/gateway.h
@@ -103,6 +103,14 @@ struct olsr_gw_handler {
     void (*startup)(void);
 
     /**
+     * Called when the costs of a gateway must be determined.
+     *
+     * @param gw the gateway
+     * @return the costs
+     */
+    uint64_t (*getcosts)(struct gateway_entry *gw);
+
+    /**
      * Called when a new gateway must be chosen.
      *
      * @param ipv4 true when an IPv4 gateway must be chosen
diff --git a/src/gateway_default_handler.c b/src/gateway_default_handler.c
index 1d683f4..558bf12 100644
--- a/src/gateway_default_handler.c
+++ b/src/gateway_default_handler.c
@@ -22,6 +22,7 @@ static struct timer_entry *gw_def_timer;
 static void gw_default_init(void);
 static void gw_default_cleanup(void);
 static void gw_default_startup_handler(void);
+static uint64_t gw_default_getcosts(struct gateway_entry *gw);
 static void gw_default_choosegw_handler(bool ipv4, bool ipv6);
 static void gw_default_update_handler(struct gateway_entry *);
 static void gw_default_delete_handler(struct gateway_entry *);
@@ -33,6 +34,7 @@ struct olsr_gw_handler gw_def_handler = {
     &gw_default_init,
     &gw_default_cleanup,
     &gw_default_startup_handler,
+    &gw_default_getcosts,
     &gw_default_choosegw_handler,
     &gw_default_update_handler,
     &gw_default_delete_handler
@@ -343,6 +345,32 @@ static void gw_default_startup_handler(void) {
 }
 
 /**
+ * Called when the costs of a gateway must be determined.
+ *
+ * @param gw the gateway
+ * @return the costs, or UINT64_MAX in case the gateway has inifinite costs
+ */
+static uint64_t gw_default_getcosts(struct gateway_entry *gw) {
+  struct tc_entry* tc;
+
+  if (!gw) {
+    return UINT64_MAX;
+  }
+
+  tc = olsr_lookup_tc_entry(&gw->originator);
+
+  if (!tc || (tc->path_cost == ROUTE_COST_BROKEN) || (!gw->uplink || !gw->downlink)) {
+    /* gateways should not exist without tc entry */
+    /* do not consider nodes with an infinite ETX */
+    /* do not consider nodes without bandwidth or with a uni-directional link */
+    return UINT64_MAX;
+  }
+
+  /* determine the path cost */
+  return gw_default_weigh_costs(tc->path_cost, gw->uplink, gw->downlink);
+}
+
+/**
  * Choose a new gateway
  *
  * @param ipv4 lookup new v4 gateway
-- 
1.7.11.7





More information about the Olsr-dev mailing list