[Olsr-dev] [PATCH v1 05/23] gateway: simplify by using the new costs interface

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


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
Reviewed-by: Henning Rogge <(spam-protected)>
---
 src/gateway_default_handler.c | 45 +++++++++++--------------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)

diff --git a/src/gateway_default_handler.c b/src/gateway_default_handler.c
index 558bf12..4bb360d 100644
--- a/src/gateway_default_handler.c
+++ b/src/gateway_default_handler.c
@@ -166,54 +166,31 @@ static void gw_default_choose_gateway(void) {
   uint64_t cost_ipv4 = UINT64_MAX;
   uint64_t cost_ipv6 = UINT64_MAX;
   struct gateway_entry *gw;
-  struct tc_entry *tc;
   bool dual;
 
   if (olsr_cnf->smart_gw_thresh) {
     /* determine the path cost thresholds */
 
-    gw = olsr_get_inet_gateway(false);
-    if (gw) {
-      tc = olsr_lookup_tc_entry(&gw->originator);
-      if (tc) {
-        uint64_t cost = gw_default_weigh_costs(tc->path_cost, gw->uplink, gw->downlink);
-        cost_ipv4_threshold = gw_default_calc_threshold(cost);
-        eval_cost_ipv4_threshold = true;
-      }
+    uint64_t cost = gw_default_getcosts(olsr_get_inet_gateway(false));
+    if (cost != UINT64_MAX) {
+      cost_ipv4_threshold = gw_default_calc_threshold(cost);
+      eval_cost_ipv4_threshold = true;
     }
-    gw = olsr_get_inet_gateway(true);
-    if (gw) {
-      tc = olsr_lookup_tc_entry(&gw->originator);
-      if (tc) {
-        uint64_t cost = gw_default_weigh_costs(tc->path_cost, gw->uplink, gw->downlink);
-        cost_ipv6_threshold = gw_default_calc_threshold(cost);
-        eval_cost_ipv6_threshold = true;
-      }
+
+    cost = gw_default_getcosts(olsr_get_inet_gateway(true));
+    if (cost != UINT64_MAX) {
+      cost_ipv6_threshold = gw_default_calc_threshold(cost);
+      eval_cost_ipv6_threshold = true;
     }
   }
 
   OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
-    uint64_t path_cost;
-    tc = olsr_lookup_tc_entry(&gw->originator);
-
-    if (!tc) {
-      /* gateways should not exist without tc entry */
-      continue;
-    }
+    uint64_t path_cost = gw_default_getcosts(gw);
 
-    if (tc->path_cost == ROUTE_COST_BROKEN) {
-      /* do not consider nodes with an infinite ETX */
+    if (path_cost == UINT64_MAX) {
       continue;
     }
 
-    if (!gw->uplink || !gw->downlink) {
-      /* do not consider nodes without bandwidth or with a uni-directional link */
-      continue;
-    }
-
-    /* determine the path cost */
-    path_cost = gw_default_weigh_costs(tc->path_cost, gw->uplink, gw->downlink);
-
     if (!gw_def_finished_ipv4 && gw->ipv4 && gw->ipv4nat == olsr_cnf->smart_gw_allow_nat && path_cost < cost_ipv4
         && (!eval_cost_ipv4_threshold || (path_cost < cost_ipv4_threshold))) {
       inet_ipv4 = gw;
-- 
1.7.11.7





More information about the Olsr-dev mailing list