gateway: simplify by using the new costs interface
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 8 Nov 2012 14:33:26 +0000 (15:33 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 10 Dec 2012 14:18:24 +0000 (15:18 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Reviewed-by: Henning Rogge <hrogge@googlemail.com>
src/gateway_default_handler.c

index 558bf12..4bb360d 100644 (file)
@@ -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;