Another mayor cleanup for neighbor/neighbor2 data.
authorHenning Rogge <hrogge@googlemail.com>
Sat, 30 May 2009 12:38:14 +0000 (14:38 +0200)
committerHenning Rogge <hrogge@googlemail.com>
Sat, 30 May 2009 12:38:14 +0000 (14:38 +0200)
cleanup of n/n2 database by MIDs must still be tested

21 files changed:
lib/debuginfo/src/olsrd_debuginfo.c
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/httpinfo/src/olsrd_plugin.h
lib/txtinfo/src/olsrd_txtinfo.c
src/duplicate_set.c
src/link_set.c
src/lq_mpr.c
src/lq_packet.c
src/lq_plugin.c
src/mid_set.c
src/mid_set.h
src/mpr.c [deleted file]
src/mpr.h [deleted file]
src/neighbor_table.c
src/neighbor_table.h
src/olsr.c
src/olsr_protocol.h
src/olsr_spf.c
src/process_package.c
src/routing_table.c

index 6dddf5c..fb1e259 100644 (file)
@@ -45,7 +45,6 @@
 #include "olsr.h"
 #include "ipcalc.h"
 #include "neighbor_table.h"
-#include "two_hop_neighbor_table.h"
 #include "mpr_selector_set.h"
 #include "tc_set.h"
 #include "hna_set.h"
index e076051..badcb98 100644 (file)
@@ -149,7 +149,7 @@ ipc_print_neigh_link(int ipc_connection, const struct nbr_entry *neighbor)
   const char *adr = olsr_ip_to_string(&mainaddrstrbuf, &olsr_cnf->router_id);
   struct lqtextbuffer lqbuffer;
 
-  if (neighbor->status == 0) {  /* non SYM */
+  if (neighbor->is_sym == 0) {  /* non SYM */
     style = "dashed";
   } else {
     const struct link_entry *lnk = get_best_link_to_neighbor(&neighbor->nbr_addr);
index 7f6ca7a..61f74e1 100644 (file)
@@ -955,7 +955,7 @@ build_neigh_body(struct autobuf *abuf)
                colspan);
   /* Neighbors */
   OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
-    struct nbr2_list_entry *list_2;
+    struct nbr_con *connector;
     int thop_cnt;
     abuf_puts(abuf, "<tr>");
     build_ipaddr_with_link(abuf, &neigh->nbr_addr, -1);
@@ -964,17 +964,17 @@ build_neigh_body(struct autobuf *abuf)
                  "<td>%s</td>"
                  "<td>%s</td>"
                  "<td>%d</td>",
-                 (neigh->status == SYM) ? "YES" : "NO",
+                 neigh->is_sym ? "YES" : "NO",
                  neigh->is_mpr ? "YES" : "NO", olsr_lookup_mprs_set(&neigh->nbr_addr) ? "YES" : "NO", neigh->willingness);
 
     abuf_puts(abuf, "<td><select>\n" "<option>IP ADDRESS</option>\n");
 
     thop_cnt = 0;
-    OLSR_FOR_ALL_NBR2_LIST_ENTRIES(neigh, list_2) {
+    OLSR_FOR_ALL_NBR_CON_ENTRIES(neigh, connector) {
       struct ipaddr_str strbuf;
-      abuf_appendf(abuf, "<option>%s</option>\n", olsr_ip_to_string(&strbuf, &list_2->nbr2->nbr2_addr));
+      abuf_appendf(abuf, "<option>%s</option>\n", olsr_ip_to_string(&strbuf, &connector->nbr2->nbr2_addr));
       thop_cnt++;
-    } OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(neigh, list_2);
+    } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(neigh, connector);
     abuf_appendf(abuf, "</select> (%d)</td></tr>\n", thop_cnt);
   } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
 
index fd90318..f259f50 100644 (file)
@@ -58,7 +58,6 @@
 #include "olsr_types.h"
 #include "plugin.h"
 #include "neighbor_table.h"
-#include "two_hop_neighbor_table.h"
 #include "tc_set.h"
 #include "hna_set.h"
 #include "mid_set.h"
index 74b8b3d..48caa3b 100644 (file)
@@ -45,7 +45,6 @@
 #include "olsr.h"
 #include "ipcalc.h"
 #include "neighbor_table.h"
-#include "two_hop_neighbor_table.h"
 #include "mpr_selector_set.h"
 #include "tc_set.h"
 #include "hna_set.h"
@@ -189,9 +188,9 @@ txtinfo_neigh(struct comport_connection *con,  char *cmd __attribute__ ((unused)
     struct ipaddr_str buf1;
     if (abuf_appendf(&con->out, !con->is_csv ? "%s\t%s\t%s\t%s\t%d\t%d\n" : "neigh,%s,%s,%s,%s,%d,%d\n",
                        olsr_ip_to_string(&buf1, &neigh->nbr_addr),
-                       neigh->status == SYM ? "YES" : "NO",
+                       neigh->is_sym ? "YES" : "NO",
                        neigh->is_mpr ? "YES" : "NO",
-                       olsr_lookup_mprs_set(&neigh->nbr_addr) ? "YES" : "NO", neigh->willingness, neigh->nbr2_list_tree.count) < 0) {
+                       olsr_lookup_mprs_set(&neigh->nbr_addr) ? "YES" : "NO", neigh->willingness, neigh->con_tree.count) < 0) {
         return ABUF_ERROR;
     }
   } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
index da743b1..ac79e8d 100644 (file)
@@ -76,7 +76,6 @@ olsr_init_duplicate_set(void)
   duplicate_mem_cookie = olsr_alloc_cookie("dup_entry", OLSR_COOKIE_TYPE_MEMORY);
   olsr_cookie_set_memory_size(duplicate_mem_cookie, sizeof(struct dup_entry));
 
-
   olsr_set_timer(&duplicate_cleanup_timer, DUPLICATE_CLEANUP_INTERVAL,
                  DUPLICATE_CLEANUP_JITTER, OLSR_TIMER_PERIODIC, &olsr_cleanup_duplicate_entry, NULL, duplicate_timer_cookie->ci_id);
 }
index a1cf41e..d5c397e 100644 (file)
@@ -46,7 +46,6 @@
 #include "defs.h"
 #include "link_set.h"
 #include "mid_set.h"
-#include "mpr.h"
 #include "neighbor_table.h"
 #include "olsr.h"
 #include "scheduler.h"
@@ -77,7 +76,7 @@ static int check_link_status(const struct lq_hello_message *message, const struc
 static struct link_entry *add_link_entry(const union olsr_ip_addr *,
                                          const union olsr_ip_addr *,
                                          union olsr_ip_addr *, olsr_reltime, olsr_reltime, struct interface *);
-static int get_neighbor_status(const union olsr_ip_addr *);
+static bool get_neighbor_status(const union olsr_ip_addr *);
 
 void
 olsr_init_link_set(void)
@@ -128,9 +127,9 @@ lookup_link_status(const struct link_entry *entry)
  * Find the "best" link status to a neighbor
  *
  * @param address the address to check for
- * @return SYM_LINK if a symmetric link exists 0 if not
+ * @return true if a symmetric link exists false if not
  */
-static int
+static bool
 get_neighbor_status(const union olsr_ip_addr *address)
 {
   const union olsr_ip_addr *main_addr;
@@ -154,7 +153,7 @@ get_neighbor_status(const union olsr_ip_addr *address)
 
     if (lnk != NULL) {
       if (lookup_link_status(lnk) == SYM_LINK)
-        return SYM_LINK;
+        return true;
     }
 
     /* Walk the aliases */
@@ -162,14 +161,14 @@ get_neighbor_status(const union olsr_ip_addr *address)
 
       lnk = lookup_link_entry(&aliases->mid_alias_addr, NULL, ifs);
       if (lnk && (lookup_link_status(lnk) == SYM_LINK)) {
-        return SYM_LINK;
+        return true;
       }
     }
     OLSR_FOR_ALL_TC_MID_ENTRIES_END(tc, aliases);
   }
   OLSR_FOR_ALL_INTERFACES_END(ifs);
 
-  return 0;
+  return false;
 }
 
 /**
@@ -293,7 +292,7 @@ olsr_delete_link_entry(struct link_entry *link)
 
   /* Delete neighbor entry */
   if (link->neighbor->linkcount == 1) {
-    olsr_delete_nbr_entry(&link->neighbor->nbr_addr);
+    olsr_delete_nbr_entry(link->neighbor);
   } else {
     link->neighbor->linkcount--;
   }
@@ -499,7 +498,7 @@ add_link_entry(const union olsr_ip_addr *local,
    */
 
   /* Neighbor MUST exist! */
-  neighbor = olsr_lookup_nbr_entry(remote_main);
+  neighbor = olsr_lookup_nbr_entry(remote_main, true);
   if (!neighbor) {
     OLSR_DEBUG(LOG_LINKS, "ADDING NEW NEIGHBOR ENTRY %s FROM LINK SET\n", olsr_ip_to_string(&rembuf, remote_main));
     neighbor = olsr_add_nbr_entry(remote_main);
index 172e9c8..eab1460 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "defs.h"
 #include "neighbor_table.h"
-#include "two_hop_neighbor_table.h"
 #include "link_set.h"
 #include "lq_mpr.h"
 #include "scheduler.h"
@@ -51,11 +50,12 @@ void
 olsr_calculate_lq_mpr(void)
 {
   struct nbr2_entry *nbr2;
-  struct nbr_list_entry *walker;
+  struct nbr_con *walker;
   int k;
   struct nbr_entry *neigh;
   olsr_linkcost best, best_1hop;
   bool mpr_changes = false;
+  bool found_better_path;
 
   OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
 
@@ -66,7 +66,7 @@ olsr_calculate_lq_mpr(void)
     neigh->is_mpr = false;
 
     /* In this pass we are only interested in WILL_ALWAYS neighbours */
-    if (neigh->status == NOT_SYM || neigh->willingness != WILL_ALWAYS) {
+    if (!neigh->is_sym || neigh->willingness != WILL_ALWAYS) {
       continue;
     }
 
@@ -84,11 +84,9 @@ olsr_calculate_lq_mpr(void)
     best_1hop = LINK_COST_BROKEN;
 
     /* check whether this 2-hop neighbour is also a neighbour */
-    neigh = olsr_lookup_nbr_entry(&nbr2->nbr2_addr);
-
-    /* if it's a neighbour and also symmetric, then examine the link quality */
-    if (neigh != NULL && neigh->status == SYM) {
+    neigh = olsr_lookup_nbr_entry(&nbr2->nbr2_addr, false);
 
+    if (neigh != NULL && neigh->is_sym) {
       /*
        * if the direct link is better than the best route via
        * an MPR, then prefer the direct link and do not select
@@ -102,20 +100,22 @@ olsr_calculate_lq_mpr(void)
       }
 
       best_1hop = lnk->linkcost;
-
+    }
       /* see wether we find a better route via an MPR */
       walker = NULL;
-      OLSR_FOR_ALL_NBR_LIST_ENTRIES(nbr2, walker) {
+      found_better_path = false;
+      OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, walker) {
         if (walker->path_linkcost < best_1hop) {
+          found_better_path = true;
           break;
         }
-      } OLSR_FOR_ALL_NBR_LIST_ENTRIES_END(nbr2, walker);
+      } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr2, walker);
 
       /* we've reached the end of the list, so we haven't found
        * a better route via an MPR - so, skip MPR selection for
        * this 1-hop neighbor */
 
-      if (!walker) {
+      if (!found_better_path) {
         continue;
       }
 
@@ -124,9 +124,9 @@ olsr_calculate_lq_mpr(void)
        */
 
       /* mark all 1-hop neighbours as not selected */
-      OLSR_FOR_ALL_NBR_LIST_ENTRIES(nbr2, walker) {
-        walker->neighbor->skip = false;
-      } OLSR_FOR_ALL_NBR_LIST_ENTRIES_END(nbr2, walker);
+      OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, walker) {
+        walker->nbr->skip = false;
+      } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr2, walker);
 
       for (k = 0; k < olsr_cnf->mpr_coverage; k++) {
 
@@ -134,12 +134,12 @@ olsr_calculate_lq_mpr(void)
         neigh = NULL;
         best = LINK_COST_BROKEN;
 
-        OLSR_FOR_ALL_NBR_LIST_ENTRIES(nbr2, walker) {
-          if (walker->neighbor->status == SYM && !walker->neighbor->skip && walker->path_linkcost < best) {
-            neigh = walker->neighbor;
+        OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, walker) {
+          if (walker->nbr->is_sym && !walker->nbr->skip && walker->path_linkcost < best) {
+            neigh = walker->nbr;
             best = walker->path_linkcost;
           }
-        } OLSR_FOR_ALL_NBR_LIST_ENTRIES_END(nbr2, walker);
+        } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, walker);
 
         /*
          * Found a 1-hop neighbor that we haven't previously selected.
@@ -161,11 +161,10 @@ olsr_calculate_lq_mpr(void)
           break;
         }
       }
-    } OLSR_FOR_ALL_NBR2_ENTRIES_END(NEIGH2);
+  } OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2);
 
-    if (mpr_changes && olsr_cnf->tc_redundancy > 0)
-      signal_link_changes(true);
-  }
+  if (mpr_changes && olsr_cnf->tc_redundancy > 0)
+    signal_link_changes(true);
 }
 
 /*
index f99804c..c81def4 100644 (file)
@@ -50,7 +50,6 @@
 #include "mid_set.h"
 #include "mantissa.h"
 #include "process_package.h"    // XXX - remove
-#include "two_hop_neighbor_table.h"
 #include "olsr.h"
 #include "build_msg.h"
 #include "net_olsr.h"
@@ -67,9 +66,6 @@ static void
 create_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
 {
   struct link_entry *walker;
-#if !defined REMOVE_LOG_WARN
-  struct ipaddr_str buf;
-#endif
 
   // initialize the static fields
 
@@ -111,17 +107,11 @@ create_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
     if (walker->neighbor->is_mpr)
       neigh->neigh_type = MPR_NEIGH;
 
-    else if (walker->neighbor->status == SYM)
+    else if (walker->neighbor->is_sym)
       neigh->neigh_type = SYM_NEIGH;
 
-    else if (walker->neighbor->status == NOT_SYM)
-      neigh->neigh_type = NOT_NEIGH;
-
-    else {
-      OLSR_WARN(LOG_PACKET_CREATION, "Error: neigh_type %d in link %s undefined\n",
-                walker->neighbor->status, olsr_ip_to_string(&buf, &walker->neighbor->nbr_addr));
+    else
       neigh->neigh_type = NOT_NEIGH;
-    }
 
     // set the entry's neighbour interface address
 
@@ -199,7 +189,7 @@ create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
      *
      * Only consider symmetric neighbours.
      */
-    if (walker->status != SYM) {
+    if (!walker->is_sym) {
       continue;
     }
 
index 7a8cb87..da5af68 100644 (file)
@@ -46,7 +46,6 @@
 #include "lq_packet.h"
 #include "olsr.h"
 #include "olsr_cookie.h"
-#include "two_hop_neighbor_table.h"
 #include "common/avl.h"
 #include "common/string.h"
 #include "olsr_logging.h"
index 9ea1681..292f060 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "ipcalc.h"
 #include "defs.h"
-#include "two_hop_neighbor_table.h"
 #include "mid_set.h"
 #include "olsr.h"
 #include "scheduler.h"
@@ -51,6 +50,7 @@
 #include "net_olsr.h"
 #include "olsr_cookie.h"
 #include "olsr_logging.h"
+#include "olsr_protocol.h"
 
 #include <stdlib.h>
 
@@ -128,7 +128,7 @@ olsr_flush_nbr2_duplicates(struct mid_entry *alias)
 
   OLSR_FOR_ALL_TC_MID_ENTRIES(tc, alias) {
     struct nbr_entry *nbr;
-    struct nbr2_entry *nbr2 = olsr_lookup_nbr2_entry_alias(&alias->mid_alias_addr);
+    struct nbr2_entry *nbr2 = olsr_lookup_nbr2_entry(&alias->mid_alias_addr, false);
 
     /* Delete possible 2 hop neighbor */
     if (nbr2) {
@@ -140,9 +140,9 @@ olsr_flush_nbr2_duplicates(struct mid_entry *alias)
     }
 
     /* Delete a possible neighbor entry */
-    nbr = olsr_lookup_nbr_entry_alias(&alias->mid_alias_addr);
+    nbr = olsr_lookup_nbr_entry(&alias->mid_alias_addr, false);
     if (nbr) {
-      struct nbr_entry *real_nbr = olsr_lookup_nbr_entry_alias(&tc->addr);
+      struct nbr_entry *real_nbr = olsr_lookup_nbr_entry(&tc->addr, false);
       if (real_nbr) {
 
         OLSR_DEBUG(LOG_MID, "Delete bogus neighbor entry %s (real %s)\n",
@@ -150,7 +150,7 @@ olsr_flush_nbr2_duplicates(struct mid_entry *alias)
 
         replace_neighbor_link_set(nbr, real_nbr);
 
-        olsr_delete_nbr_entry(&alias->mid_alias_addr);
+        olsr_delete_nbr_entry(nbr);
 
         changes_neighborhood = true;
       }
@@ -167,13 +167,14 @@ olsr_flush_nbr2_duplicates(struct mid_entry *alias)
 static void
 olsr_fixup_mid_main_addr(const union olsr_ip_addr *main_addr, const union olsr_ip_addr *alias_addr)
 {
-  struct nbr_entry *nbr_new, *nbr_old = olsr_lookup_nbr_entry_alias(alias_addr);
+  struct nbr_entry *nbr_new, *nbr_old;
   struct mid_entry *mid_old;
   int ne_ref_rp_count;
 #if !defined REMOVE_LOG_DEBUG
   struct ipaddr_str buf1, buf2;
 #endif
 
+  nbr_old = olsr_lookup_nbr_entry(alias_addr, false);
   if (!nbr_old) {
     return;
   }
@@ -181,7 +182,7 @@ olsr_fixup_mid_main_addr(const union olsr_ip_addr *main_addr, const union olsr_i
   OLSR_DEBUG(LOG_MID, "Main address change %s -> %s detected.\n",
              olsr_ip_to_string(&buf1, alias_addr), olsr_ip_to_string(&buf2, main_addr));
 
-  olsr_delete_nbr_entry(alias_addr);
+  olsr_delete_nbr_entry(nbr_old);
   nbr_new = olsr_add_nbr_entry(main_addr);
 
   /* Adjust pointers to neighbortable-entry in link_set */
index 1a9bf54..e8d52bb 100644 (file)
@@ -42,7 +42,9 @@
 #ifndef _OLSR_MID
 #define _OLSR_MID
 
+#include "defs.h"
 #include "olsr_types.h"
+#include "olsr_protocol.h"
 #include "common/avl.h"
 
 struct mid_entry {
diff --git a/src/mpr.c b/src/mpr.c
deleted file mode 100644 (file)
index 90a37a1..0000000
--- a/src/mpr.c
+++ /dev/null
@@ -1,499 +0,0 @@
-
-/*
- * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in
- *   the documentation and/or other materials provided with the
- *   distribution.
- * * Neither the name of olsr.org, olsrd nor the names of its
- *   contributors may be used to endorse or promote products derived
- *   from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * Visit http://www.olsr.org for more information.
- *
- * If you find this software useful feel free to make a donation
- * to the project. For more information see the website or contact
- * the copyright holders.
- *
- */
-
-#include "ipcalc.h"
-#include "defs.h"
-#include "mpr.h"
-#include "two_hop_neighbor_table.h"
-#include "olsr.h"
-#include "neighbor_table.h"
-#include "scheduler.h"
-#include "net_olsr.h"
-#include "olsr_logging.h"
-
-#include <stdlib.h>
-
-/* Begin:
- * Prototypes for internal functions
- */
-
-static uint16_t add_will_always_nodes(void);
-static void olsr_optimize_mpr_set(void);
-static void olsr_clear_mprs(void);
-static void olsr_clear_two_hop_processed(void);
-static struct nbr_entry *olsr_find_maximum_covered(int);
-static uint16_t olsr_calculate_two_hop_neighbors(void);
-static int olsr_check_mpr_changes(void);
-static int olsr_chosen_mpr(struct nbr_entry *, uint16_t *);
-
-/* End:
- * Prototypes for internal functions
- */
-
-
-/**
- *This function processes the chosen MPRs and updates the counters
- *used in calculations
- */
-static int
-olsr_chosen_mpr(struct nbr_entry *one_hop_neighbor, uint16_t * two_hop_covered_count)
-{
-  struct nbr_list_entry *the_one_hop_list;
-  struct nbr2_list_entry *second_hop_entries;
-  struct nbr_entry *dup_neighbor;
-  uint16_t count;
-#if !defined REMOVE_LOG_DEBUG
-  struct ipaddr_str buf;
-#endif
-  count = *two_hop_covered_count;
-
-  OLSR_DEBUG(LOG_MPR, "Setting %s as MPR\n", olsr_ip_to_string(&buf, &one_hop_neighbor->nbr_addr));
-
-  //printf("PRE COUNT: %d\n\n", count);
-
-  one_hop_neighbor->is_mpr = true;      //NBS_MPR;
-
-  OLSR_FOR_ALL_NBR2_LIST_ENTRIES(one_hop_neighbor, second_hop_entries) {
-
-    dup_neighbor = olsr_lookup_nbr_entry(&second_hop_entries->nbr2->nbr2_addr);
-
-    if ((dup_neighbor != NULL) && (dup_neighbor->status == SYM)) {
-      OLSR_DEBUG(LOG_MPR, "(2)Skipping 2h neighbor %s - already 1hop\n",
-                 olsr_ip_to_string(&buf, &second_hop_entries->nbr2->nbr2_addr));
-      continue;
-    }
-
-    /*
-     * Now the neighbor is covered by this mpr
-     */
-    second_hop_entries->nbr2->mpr_covered_count++;
-
-    OLSR_DEBUG(LOG_MPR, "[%s] has coverage %d\n",
-               olsr_ip_to_string(&buf, &second_hop_entries->nbr2->nbr2_addr),
-               second_hop_entries->nbr2->mpr_covered_count);
-
-    if (second_hop_entries->nbr2->mpr_covered_count >= olsr_cnf->mpr_coverage)
-      count++;
-
-    OLSR_FOR_ALL_NBR_LIST_ENTRIES(second_hop_entries->nbr2, the_one_hop_list) {
-      if ((the_one_hop_list->neighbor->status == SYM)) {
-        if (second_hop_entries->nbr2->mpr_covered_count >= olsr_cnf->mpr_coverage) {
-          the_one_hop_list->neighbor->nbr2_nocov--;
-        }
-      }
-    } OLSR_FOR_ALL_NBR_LIST_ENTRIES_END(second_hop_entries->nbr2, the_one_hop_list);
-  } OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(one_hop_neighbor, second_hop_entries);
-
-  *two_hop_covered_count = count;
-  return count;
-
-}
-
-
-/**
- *Find the neighbor that covers the most 2 hop neighbors
- *with a given willingness
- *
- *@param willingness the willingness of the neighbor
- *
- *@return a pointer to the nbr_entry struct
- */
-static struct nbr_entry *
-olsr_find_maximum_covered(int willingness)
-{
-  uint16_t maximum;
-  struct nbr_entry *a_neighbor;
-  struct nbr_entry *mpr_candidate = NULL;
-#if !defined REMOVE_LOG_DEBUG
-  struct ipaddr_str buf;
-#endif
-  maximum = 0;
-
-  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-
-    OLSR_DEBUG(LOG_MPR, "[%s] nocov: %d mpr: %d will: %d max: %d\n\n",
-               olsr_ip_to_string(&buf, &a_neighbor->nbr_addr),
-               a_neighbor->nbr2_nocov, a_neighbor->is_mpr, a_neighbor->willingness, maximum);
-
-    if ((!a_neighbor->is_mpr) && (a_neighbor->willingness == willingness) && (maximum < a_neighbor->nbr2_nocov)) {
-
-      maximum = a_neighbor->nbr2_nocov;
-      mpr_candidate = a_neighbor;
-    }
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-
-  return mpr_candidate;
-}
-
-
-/**
- *Remove all MPR registrations
- */
-static void
-olsr_clear_mprs(void)
-{
-  struct nbr_entry *a_neighbor;
-  struct nbr2_list_entry *two_hop_list;
-
-  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-
-    /* Clear MPR selection. */
-    if (a_neighbor->is_mpr) {
-      a_neighbor->was_mpr = true;
-      a_neighbor->is_mpr = false;
-    }
-
-    /* Clear two hop neighbors coverage count/ */
-    OLSR_FOR_ALL_NBR2_LIST_ENTRIES(a_neighbor, two_hop_list) {
-      two_hop_list->nbr2->mpr_covered_count = 0;
-    } OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(a_neighbor, two_hop_list);
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-}
-
-
-/**
- *Check for changes in the MPR set
- *
- *@return 1 if changes occured 0 if not
- */
-static int
-olsr_check_mpr_changes(void)
-{
-  struct nbr_entry *a_neighbor;
-  int retval;
-
-  retval = 0;
-
-  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-
-    if (a_neighbor->was_mpr) {
-      a_neighbor->was_mpr = false;
-
-      if (!a_neighbor->is_mpr) {
-        retval = 1;
-      }
-    }
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-
-  return retval;
-}
-
-
-/**
- * Clears out proccess registration on two hop neighbors
- */
-static void
-olsr_clear_two_hop_processed(void)
-{
-  struct nbr2_entry *nbr2;
-
-  OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) {
-
-      /* Clear */
-      nbr2->processed = 0;
-  } OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2);
-}
-
-
-/**
- *This function calculates the number of two hop neighbors
- */
-static uint16_t
-olsr_calculate_two_hop_neighbors(void)
-{
-  struct nbr_entry *a_neighbor, *dup_neighbor;
-  struct nbr2_list_entry *twohop_neighbors;
-  uint16_t count = 0;
-  uint16_t n_count = 0;
-  uint16_t sum = 0;
-
-  /* Clear 2 hop neighs */
-  olsr_clear_two_hop_processed();
-
-  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-
-    if (a_neighbor->status == NOT_SYM) {
-      a_neighbor->nbr2_nocov = count;
-      continue;
-    }
-
-    OLSR_FOR_ALL_NBR2_LIST_ENTRIES(a_neighbor, twohop_neighbors) {
-      dup_neighbor = olsr_lookup_nbr_entry(&twohop_neighbors->nbr2->nbr2_addr);
-
-      if ((dup_neighbor == NULL) || (dup_neighbor->status != SYM)) {
-        n_count++;
-        if (!twohop_neighbors->nbr2->processed) {
-          count++;
-          twohop_neighbors->nbr2->processed = 1;
-        }
-      }
-    } OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(a_neighbor, twohop_neighbors);
-    a_neighbor->nbr2_nocov = n_count;
-
-    /* Add the two hop count */
-    sum += count;
-
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-
-  OLSR_DEBUG(LOG_MPR, "Two hop neighbors: %d\n", sum);
-  return sum;
-}
-
-
-
-
-/**
- * Adds all nodes with willingness set to WILL_ALWAYS
- */
-static uint16_t
-add_will_always_nodes(void)
-{
-  struct nbr_entry *a_neighbor;
-  uint16_t count = 0;
-#if !defined REMOVE_LOG_DEBUG
-  struct ipaddr_str buf;
-#endif
-  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-    if ((a_neighbor->status == NOT_SYM) || (a_neighbor->willingness != WILL_ALWAYS)) {
-      continue;
-    }
-    olsr_chosen_mpr(a_neighbor, &count);
-
-    OLSR_DEBUG(LOG_MPR, "Adding WILL_ALWAYS: %s\n", olsr_ip_to_string(&buf, &a_neighbor->nbr_addr));
-
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-
-  return count;
-}
-
-/**
- *This function calculates the mpr neighbors
- *@return nada
- */
-void
-olsr_calculate_mpr(void)
-{
-#if !defined REMOVE_LOG_DEBUG
-  struct ipaddr_str buf;
-#endif
-
-  struct nbr2_entry *nbr2;
-  struct nbr_entry *nbr;
-  struct nbr_entry *mprs;
-  uint16_t two_hop_covered_count;
-  uint16_t two_hop_count;
-  int willingness;
-
-  olsr_clear_mprs();
-  two_hop_count = olsr_calculate_two_hop_neighbors();
-  two_hop_covered_count = add_will_always_nodes();
-
-  /*
-   * Calculate MPRs based on WILLINGNESS.
-   */
-  for (willingness = WILL_ALWAYS - 1; willingness > WILL_NEVER; willingness--) {
-
-    /*
-     * Find all 2 hop neighbors with 1 link
-     * connecting them to us trough neighbors
-     * with a given willingness.
-     */
-    OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) {
-
-      /*
-       * Eliminate 2 hop neighbors which already are in our 1 hop neighborhood.
-       */
-      nbr = olsr_lookup_nbr_entry(&nbr2->nbr2_addr);
-      if (nbr && (nbr->status != NOT_SYM)) {
-        OLSR_DEBUG(LOG_MPR, "Skipping 2-hop neighbor2 %s - already 1hop\n",
-                   olsr_ip_to_string(&buf, &nbr2->nbr2_addr));
-        continue;
-      }
-
-      /*
-       * Eliminate 2 hop neighbors which are not single link.
-       */
-      if (nbr2->nbr2_refcount != 1) {
-        OLSR_DEBUG(LOG_MPR, "Skipping 2-hop neighbor %s - not single link\n",
-                   olsr_ip_to_string(&buf, &nbr2->nbr2_addr));
-        continue;
-      }
-
-      nbr = nbr_list_node_to_nbr_list(avl_walk_first(&nbr2->nbr2_nbr_list_tree))->neighbor;
-
-      /* Already an elected MPR ? */
-      if (nbr->is_mpr) {
-        OLSR_DEBUG(LOG_MPR, "Skipping 2-hop neighbor %s - already MPR\n",
-                   olsr_ip_to_string(&buf, &nbr2->nbr2_addr));
-        continue;
-      }
-
-      /* Match willingness */
-      if (nbr->willingness != willingness) {
-        continue;
-      }
-
-      /* Only symmetric neighbors */
-      if (nbr->status != SYM) {
-        continue;
-      }
-
-      /*
-       * This 2 hop neighbor is good enough.
-       */
-      OLSR_DEBUG(LOG_MPR, "One link adding %s\n", olsr_ip_to_string(&buf, &nbr2->nbr2_addr));
-      olsr_chosen_mpr(nbr, &two_hop_covered_count);
-
-    } OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2);
-
-    if (two_hop_covered_count >= two_hop_count) {
-      willingness = WILL_NEVER;
-      break;
-    }
-
-    while ((mprs = olsr_find_maximum_covered(willingness)) != NULL) {
-      olsr_chosen_mpr(mprs, &two_hop_covered_count);
-
-      if (two_hop_covered_count >= two_hop_count) {
-        willingness = WILL_NEVER;
-        break;
-      }
-    }
-  }
-
-  /*
-   * Increment the MPR sequence number.
-   */
-
-  /* Optimize selection */
-  olsr_optimize_mpr_set();
-
-  if (olsr_check_mpr_changes()) {
-    OLSR_DEBUG(LOG_MPR, "CHANGES IN MPR SET\n");
-    if (olsr_cnf->tc_redundancy > 0)
-      signal_link_changes(true);
-  }
-}
-
-/**
- *Optimize MPR set by removing all entries
- *where all 2 hop neighbors actually is
- *covered by enough MPRs already
- *Described in RFC3626 section 8.3.1
- *point 5
- *
- *@return nada
- */
-static void
-olsr_optimize_mpr_set(void)
-{
-  int i;
-#if !defined REMOVE_LOG_DEBUG
-  struct ipaddr_str buf;
-#endif
-  OLSR_DEBUG(LOG_MPR, "\n**MPR OPTIMIZING**\n\n");
-
-  for (i = WILL_NEVER + 1; i < WILL_ALWAYS; i++) {
-    struct nbr_entry *a_neighbor;
-
-    OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-
-      if (a_neighbor->willingness != i) {
-        continue;
-      }
-
-      if (a_neighbor->is_mpr) {
-        struct nbr2_list_entry *two_hop_list;
-        int remove_it = 1;
-
-        OLSR_FOR_ALL_NBR2_LIST_ENTRIES(a_neighbor, two_hop_list) {
-          const struct nbr_entry *dup_neighbor = olsr_lookup_nbr_entry(&two_hop_list->nbr2->nbr2_addr);
-
-          if ((dup_neighbor != NULL) && (dup_neighbor->status != NOT_SYM)) {
-            continue;
-          }
-
-          OLSR_DEBUG(LOG_MPR, "\t[%s] coverage %d\n", olsr_ip_to_string(&buf, &two_hop_list->nbr2->nbr2_addr),
-                     two_hop_list->nbr2->mpr_covered_count);
-          /* Do not remove if we find a entry which need this MPR */
-          if (two_hop_list->nbr2->mpr_covered_count <= olsr_cnf->mpr_coverage) {
-            remove_it = 0;
-            break;
-          }
-        } OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(a_neighbor, two_hop_list_list);
-
-        if (remove_it) {
-          OLSR_DEBUG(LOG_MPR, "MPR OPTIMIZE: removiong mpr %s\n\n", olsr_ip_to_string(&buf, &a_neighbor->nbr_addr));
-          a_neighbor->is_mpr = false;
-        }
-      }
-    } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-  }
-}
-
-void
-olsr_print_mpr_set(void)
-{
-#if !defined REMOVE_LOG_INFO
-  /* The whole function makes no sense without it. */
-  struct nbr_entry *a_neighbor;
-
-  OLSR_INFO(LOG_MPR, "MPR SET: ");
-
-  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
-
-    /*
-     * Remove MPR settings
-     */
-    if (a_neighbor->is_mpr) {
-      struct ipaddr_str buf;
-      OLSR_INFO_NH(LOG_MPR, "\t[%s]\n", olsr_ip_to_string(&buf, &a_neighbor->nbr_addr));
-    }
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
-#endif
-}
-
-/*
- * Local Variables:
- * c-basic-offset: 2
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/src/mpr.h b/src/mpr.h
deleted file mode 100644 (file)
index 7cf7841..0000000
--- a/src/mpr.h
+++ /dev/null
@@ -1,60 +0,0 @@
-
-/*
- * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in
- *   the documentation and/or other materials provided with the
- *   distribution.
- * * Neither the name of olsr.org, olsrd nor the names of its
- *   contributors may be used to endorse or promote products derived
- *   from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * Visit http://www.olsr.org for more information.
- *
- * If you find this software useful feel free to make a donation
- * to the project. For more information see the website or contact
- * the copyright holders.
- *
- */
-
-
-#ifndef _OLSR_MPR
-#define _OLSR_MPR
-
-#include "defs.h"
-
-void
-  olsr_calculate_mpr(void);
-
-void olsr_print_mpr_set(void);
-
-#endif
-
-/*
- * Local Variables:
- * c-basic-offset: 2
- * indent-tabs-mode: nil
- * End:
- */
index 7d3729b..2e62460 100644 (file)
@@ -41,9 +41,7 @@
 
 #include "ipcalc.h"
 #include "defs.h"
-#include "two_hop_neighbor_table.h"
 #include "mid_set.h"
-#include "mpr.h"
 #include "neighbor_table.h"
 #include "olsr.h"
 #include "scheduler.h"
 
 /* Root of the one hop neighbor database */
 struct avl_tree nbr_tree;
+struct avl_tree nbr2_tree;
 
 /* Some cookies for stats keeping */
-struct olsr_cookie_info *nbr2_list_timer_cookie = NULL;
-struct olsr_cookie_info *nbr2_list_mem_cookie = NULL;
+struct olsr_cookie_info *nbr2_mem_cookie = NULL;
 struct olsr_cookie_info *nbr_mem_cookie = NULL;
 
+struct olsr_cookie_info *nbr_connector_mem_cookie = NULL;
+struct olsr_cookie_info *nbr_connector_timer_cookie = NULL;
+
+static void olsr_expire_nbr_con(void *);
+
 /*
  * Init neighbor tables.
  */
@@ -70,161 +73,19 @@ olsr_init_neighbor_table(void)
 {
   OLSR_INFO(LOG_NEIGHTABLE, "Initializing neighbor tree.\n");
   avl_init(&nbr_tree, avl_comp_default);
+  avl_init(&nbr2_tree, avl_comp_default);
 
-  nbr2_list_timer_cookie = olsr_alloc_cookie("2-Hop Neighbor List", OLSR_COOKIE_TYPE_TIMER);
-
-  nbr2_list_mem_cookie = olsr_alloc_cookie("2-Hop Neighbor List", OLSR_COOKIE_TYPE_MEMORY);
-  olsr_cookie_set_memory_size(nbr2_list_mem_cookie, sizeof(struct nbr2_list_entry));
+  nbr_connector_timer_cookie = olsr_alloc_cookie("Neighbor connector", OLSR_COOKIE_TYPE_TIMER);
+  nbr_connector_mem_cookie = olsr_alloc_cookie("Neighbor connector", OLSR_COOKIE_TYPE_MEMORY);
+  olsr_cookie_set_memory_size(nbr_connector_mem_cookie, sizeof(struct nbr_con));
 
   nbr_mem_cookie = olsr_alloc_cookie("1-Hop Neighbor", OLSR_COOKIE_TYPE_MEMORY);
   olsr_cookie_set_memory_size(nbr_mem_cookie, sizeof(struct nbr_entry));
-}
-
-
-/**
- * Add a neighbor 2 reference to a neighbor.
- */
-struct nbr2_list_entry *
-olsr_add_nbr2_list_entry(struct nbr_entry *nbr, struct nbr2_entry *nbr2, float vtime)
-{
-  struct nbr2_list_entry *nbr2_list;
-
-  /*
-   * check first if the entry exists.
-   */
-  nbr2_list = olsr_lookup_nbr2_list_entry(nbr, &nbr2->nbr2_addr);
-  if (nbr2_list) {
-
-    /* 
-     * Refresh timer.
-     */
-    olsr_change_timer(nbr2_list->nbr2_list_timer, vtime, OLSR_NBR2_LIST_JITTER, OLSR_TIMER_ONESHOT);
-    return nbr2_list;
-  }
-
-  /*
-   * Reference not found, allocate and init a fresh one.
-   */
-  nbr2_list = olsr_cookie_malloc(nbr2_list_mem_cookie);
-
-  nbr2_list->nbr2 = nbr2;
-  olsr_lock_nbr2(nbr2);
-
-  nbr2_list->nbr2_nbr = nbr;    /* XXX nbr refcount protection */
-
-  /*
-   * Start the timer.
-   */
-  olsr_start_timer(vtime, OLSR_NBR2_LIST_JITTER, OLSR_TIMER_ONESHOT,
-                   &olsr_expire_nbr2_list, nbr2_list, nbr2_list_timer_cookie->ci_id);
-
-  /* Add to the nbr2 reference subtree */
-  nbr2_list->nbr2_list_node.key = &nbr2->nbr2_addr;
-  avl_insert(&nbr->nbr2_list_tree, &nbr2_list->nbr2_list_node, AVL_DUP_NO);
-
-  return nbr2_list;
-}
-
-
-/**
- * Unlink, delete and free a nbr2_list entry.
- */
-void
-olsr_delete_nbr2_list_entry(struct nbr2_list_entry *nbr2_list)
-{
-  struct nbr2_entry *nbr2;
-  struct nbr_entry *nbr;
-
-  nbr2 = nbr2_list->nbr2;
-  nbr = nbr2_list->nbr2_nbr;
-
-  /*
-   * Kill running timers.
-   */
-  olsr_stop_timer(nbr2_list->nbr2_list_timer);
-  nbr2_list->nbr2_list_timer = NULL;
-
-  /* Remove from neighbor2 reference subtree */
-  avl_delete(&nbr->nbr2_list_tree, &nbr2_list->nbr2_list_node);
-
-  /* Remove reference to a two-hop neighbor, unlock */
-  nbr2_list->nbr2 = NULL;
-  olsr_unlock_nbr2(nbr2);
-
-  olsr_cookie_free(nbr2_list_mem_cookie, nbr2_list);
-
-  /* Set flags to recalculate the MPR set and the routing table */
-  changes_neighborhood = true;
-  changes_topology = true;
-}
-
-/**
- * Check if a two hop neighbor is reachable via a given
- * neighbor.
- *
- * @param nbr neighbor-entry to check via
- * @param addr the addres of the two hop neighbor to find.
- *
- * @return a pointer to the nbr2_list_entry struct
- * representing the two hop neighbor if found. NULL if not found.
- */
-struct nbr2_list_entry *
-olsr_lookup_nbr2_list_entry(struct nbr_entry *nbr, const union olsr_ip_addr *addr)
-{
-  struct avl_node *node;
-
-  node = avl_find(&nbr->nbr2_list_tree, addr);
-  if (node) {
-    return nbr2_list_node_to_nbr2_list(node);
-  }
-  return NULL;
-}
-
-
-/**
- * Delete a neighbor table entry.
- *
- * Remember: Deleting a neighbor entry results the deletion of its 2 hop neighbors list!!!
- * @param addr the neighbor entry to delete
- *
- * @return TRUE on success, FALSE otherwise.
- */
-bool
-olsr_delete_nbr_entry(const union olsr_ip_addr * addr)
-{
-  struct nbr2_list_entry *nbr2_list;
-  struct nbr_entry *nbr;
-
-#if !defined REMOVE_LOG_DEBUG
-  struct ipaddr_str buf;
-#endif
-
-  /*
-   * Find neighbor entry
-   */
-  nbr = olsr_lookup_nbr_entry(addr);
-  if (!nbr) {
-    return false;
-  }
-
-  OLSR_DEBUG(LOG_NEIGHTABLE, "Delete 1-hop neighbor: %s\n", olsr_ip_to_string(&buf, addr));
-
-  OLSR_FOR_ALL_NBR2_LIST_ENTRIES(nbr, nbr2_list) {
-    olsr_delete_nbr_list_by_addr(nbr2_list->nbr2, &nbr->nbr_addr);
-    olsr_delete_nbr2_list_entry(nbr2_list);
-  } OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(nbr, nbr2_list);
-
-  /* Remove from global neighbor tree */
-  avl_delete(&nbr_tree, &nbr->nbr_node);
-
-  olsr_cookie_free(nbr_mem_cookie, nbr);
 
-  changes_neighborhood = true;
-
-  return true;
+  nbr2_mem_cookie = olsr_alloc_cookie("2-Hop Neighbor", OLSR_COOKIE_TYPE_MEMORY);
+  olsr_cookie_set_memory_size(nbr2_mem_cookie, sizeof(struct nbr2_entry));
 }
 
-
 /**
  * Insert a neighbor entry in the neighbor table.
  *
@@ -242,7 +103,7 @@ olsr_add_nbr_entry(const union olsr_ip_addr *addr)
   /*
    * Check if neighbor entry exists.
    */
-  nbr = olsr_lookup_nbr_entry(addr);
+  nbr = olsr_lookup_nbr_entry(addr, true);
   if (nbr) {
     return nbr;
   }
@@ -254,10 +115,10 @@ olsr_add_nbr_entry(const union olsr_ip_addr *addr)
   /* Set address, willingness and status */
   nbr->nbr_addr = *addr;
   nbr->willingness = WILL_NEVER;
-  nbr->status = NOT_SYM;
+  nbr->is_sym = false;
 
   /* Init subtree for nbr2 pointers */
-  avl_init(&nbr->nbr2_list_tree, avl_comp_default);
+  avl_init(&nbr->con_tree, avl_comp_default);
 
   nbr->linkcount = 0;
   nbr->is_mpr = false;
@@ -270,47 +131,66 @@ olsr_add_nbr_entry(const union olsr_ip_addr *addr)
   return nbr;
 }
 
-
-
 /**
- * Lookup a neighbor entry in the neighbortable based on an address.
- * Unalias the passed in address before.
- * 
- * @param addr the IP address of the neighbor to look up
+ * Delete a neighbor table entry.
  *
- * @return a pointer to the neighbor struct registered on the given
- * address. NULL if not found.
+ * Remember: Deleting a neighbor entry results the deletion of its 2 hop neighbors list!!!
+ * @param addr the neighbor entry to delete
  */
-struct nbr_entry *
-olsr_lookup_nbr_entry(const union olsr_ip_addr *addr)
+void
+olsr_delete_nbr_entry(struct nbr_entry *nbr)
 {
-  const union olsr_ip_addr *main_addr;
+  struct nbr_con *connector;
+  struct nbr2_entry *nbr2;
 
-  /*
-   * Find main address of node
-   */
-  main_addr = olsr_lookup_main_addr_by_alias(addr);
-  if (!main_addr) {
-    main_addr = addr;
-  }
+#if !defined REMOVE_LOG_DEBUG
+  struct ipaddr_str buf;
+#endif
 
-  return olsr_lookup_nbr_entry_alias(main_addr);
-}
+  OLSR_DEBUG(LOG_NEIGHTABLE, "Delete 1-hop neighbor: %s\n", olsr_ip_to_string(&buf, &nbr->nbr_addr));
+
+  OLSR_FOR_ALL_NBR_CON_ENTRIES(nbr, connector) {
+    nbr2 = connector->nbr2;
+
+    olsr_delete_nbr_con(connector);
+    if (nbr2->con_tree.count == 0) {
+      olsr_delete_nbr2_entry(nbr2);
+    }
+  } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr, connector);
+
+  /* Remove from global neighbor tree */
+  avl_delete(&nbr_tree, &nbr->nbr_node);
+
+  olsr_cookie_free(nbr_mem_cookie, nbr);
 
+  changes_neighborhood = true;
+}
 
 /**
  * Lookup a neighbor entry in the neighbortable based on an address.
+ * Unalias the passed in address before.
  *
  * @param addr the IP address of the neighbor to look up
  *
  * @return a pointer to the neighbor struct registered on the given
- *  address. NULL if not found.
+ * address. NULL if not found.
  */
 struct nbr_entry *
-olsr_lookup_nbr_entry_alias(const union olsr_ip_addr *addr)
+olsr_lookup_nbr_entry(const union olsr_ip_addr *addr, bool lookupalias)
 {
+  const union olsr_ip_addr *main_addr = NULL;
   struct avl_node *node;
 
+  /*
+   * Find main address of node
+   */
+  if (lookupalias) {
+    main_addr = olsr_lookup_main_addr_by_alias(addr);
+  }
+  if (main_addr == NULL) {
+    main_addr = addr;
+  }
+
   node = avl_find(&nbr_tree, addr);
   if (node) {
     return nbr_node_to_nbr(node);
@@ -318,21 +198,21 @@ olsr_lookup_nbr_entry_alias(const union olsr_ip_addr *addr)
   return NULL;
 }
 
-
-int
-olsr_update_nbr_status(struct nbr_entry *entry, int lnk)
-{
+int olsr_update_nbr_status(struct nbr_entry *entry, bool sym) {
+#if !defined REMOVE_LOG_DEBUG
+  struct ipaddr_str buf;
+#endif
   /*
    * Update neighbor entry
    */
 
-  if (lnk == SYM_LINK) {
+  if (sym) {
     /* N_status is set to SYM */
-    if (entry->status == NOT_SYM) {
+    if (!entry->is_sym) {
       struct nbr2_entry *two_hop_neighbor;
 
       /* Delete posible 2 hop entry on this neighbor */
-      if ((two_hop_neighbor = olsr_lookup_nbr2_entry(&entry->nbr_addr)) != NULL) {
+      if ((two_hop_neighbor = olsr_lookup_nbr2_entry(&entry->nbr_addr, true)) != NULL) {
         olsr_delete_nbr2_entry(two_hop_neighbor);
       }
 
@@ -341,40 +221,202 @@ olsr_update_nbr_status(struct nbr_entry *entry, int lnk)
       if (olsr_cnf->tc_redundancy > 1)
         signal_link_changes(true);
     }
-    entry->status = SYM;
+    entry->is_sym = true;
+    OLSR_DEBUG(LOG_NEIGHTABLE, "Neighbor %s is now symmetric\n", olsr_ip_to_string(&buf, &entry->nbr_addr));
   } else {
-    if (entry->status == SYM) {
+    if (entry->is_sym) {
       changes_neighborhood = true;
       changes_topology = true;
       if (olsr_cnf->tc_redundancy > 1)
         signal_link_changes(true);
     }
     /* else N_status is set to NOT_SYM */
-    entry->status = NOT_SYM;
-    /* remove neighbor from routing list */
+    entry->is_sym = false;
+
+    OLSR_DEBUG(LOG_NEIGHTABLE, "Neighbor %s is now non-symmetric\n", olsr_ip_to_string(&buf, &entry->nbr_addr));
   }
 
-  return entry->status;
+  return entry->is_sym;
 }
 
+/**
+ * Insert a new entry to the two hop neighbor table.
+ *
+ * @param addr the entry to insert
+ * @return nada
+ */
+struct nbr2_entry *olsr_add_nbr2_entry(const union olsr_ip_addr *addr) {
+#if !defined REMOVE_LOG_DEBUG
+  struct ipaddr_str buf;
+#endif
+  struct nbr2_entry *nbr2;
+
+  /*
+   * Check first if the entry exists.
+   */
+  nbr2 = olsr_lookup_nbr2_entry(addr, true);
+  if (nbr2) {
+    return nbr2;
+  }
+
+  OLSR_DEBUG(LOG_2NEIGH, "Adding 2 hop neighbor %s\n", olsr_ip_to_string(&buf, addr));
+
+  nbr2 = olsr_cookie_malloc(nbr2_mem_cookie);
+
+  /* Init neighbor reference subtree */
+  avl_init(&nbr2->con_tree, avl_comp_default);
+
+  nbr2->nbr2_addr = *addr;
+
+  /* Add to global neighbor 2 tree */
+  nbr2->nbr2_node.key = &nbr2->nbr2_addr;
+  avl_insert(&nbr2_tree, &nbr2->nbr2_node, AVL_DUP_NO);
+
+  return nbr2;
+}
 
 /**
- * Callback for the nbr2_list timer.
+ * Delete an entry from the two hop neighbor table.
+ *
+ * @param nbr2 the two hop neighbor to delete.
  */
-void
-olsr_expire_nbr2_list(void *context)
-{
-  struct nbr2_list_entry *nbr2_list;
-  struct nbr_entry *nbr;
+void olsr_delete_nbr2_entry(struct nbr2_entry *nbr2) {
+  struct nbr_con *connector;
+
+#if !defined REMOVE_LOG_DEBUG
+  struct ipaddr_str buf;
+#endif
+
+  OLSR_DEBUG(LOG_NEIGHTABLE, "Delete 2-hop neighbor: %s\n", olsr_ip_to_string(&buf, &nbr2->nbr2_addr));
+
+  OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, connector) {
+    olsr_delete_nbr_con(connector);
+  } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, connector);
+
+  /* Remove from global neighbor tree */
+  avl_delete(&nbr2_tree, &nbr2->nbr2_node);
+
+  olsr_cookie_free(nbr2_mem_cookie, nbr2);
+  changes_neighborhood = true;
+}
+
+struct nbr2_entry *olsr_lookup_nbr2_entry(const union olsr_ip_addr *addr, bool lookupalias) {
+  const union olsr_ip_addr *main_addr = NULL;
+  struct avl_node *node;
+
+  /*
+   * Find main address of node
+   */
+  if (lookupalias) {
+    main_addr = olsr_lookup_main_addr_by_alias(addr);
+  }
+  if (main_addr == NULL) {
+    main_addr = addr;
+  }
+
+  node = avl_find(&nbr2_tree, addr);
+  if (node) {
+    return nbr2_node_to_nbr2(node);
+  }
+  return NULL;
+}
+
+/**
+ * Links a one-hop neighbor with a 2-hop neighbor.
+ *
+ * @param nbr  the 1-hop neighbor
+ * @param nbr2 the 2-hop neighbor
+ * @param vtime validity time of the 2hop neighbor
+ */
+struct nbr_con *olsr_link_nbr_nbr2(struct nbr_entry *nbr, const union olsr_ip_addr *nbr2_addr, olsr_reltime vtime) {
+  struct nbr_con *connector;
   struct nbr2_entry *nbr2;
 
-  nbr2_list = (struct nbr2_list_entry *)context;
+  connector = olsr_lookup_nbr_con_entry(nbr, nbr2_addr);
+  if (connector) {
+    olsr_change_timer(connector->nbr2_list_timer, vtime, OLSR_NBR2_LIST_JITTER, OLSR_TIMER_ONESHOT);
+    return connector;
+  }
+
+  nbr2 = olsr_add_nbr2_entry(nbr2_addr);
+
+  connector = olsr_cookie_malloc(nbr_connector_mem_cookie);
+
+  connector->nbr = nbr;
+  connector->nbr2 = nbr2;
+  connector->nbr_tree_node.key = &nbr2->nbr2_addr;
+  connector->nbr2_tree_node.key = &nbr->nbr_addr;
+
+  avl_insert(&nbr->con_tree, &connector->nbr_tree_node, AVL_DUP_NO);
+  avl_insert(&nbr2->con_tree, &connector->nbr2_tree_node, AVL_DUP_NO);
+
+  connector->path_linkcost = LINK_COST_BROKEN;
+
+  connector->nbr2_list_timer = olsr_start_timer(vtime, OLSR_NBR2_LIST_JITTER,
+      OLSR_TIMER_ONESHOT, &olsr_expire_nbr_con, connector, nbr_connector_timer_cookie->ci_id);
+
+  return connector;
+}
+
+/**
+ * Unlinks an one-hop and a 2-hop neighbor.
+ * Does NOT free the two-hop neighbor
+ *
+ * @param connector the connector between the neighbors
+ */
+void olsr_delete_nbr_con(struct nbr_con *connector) {
+  olsr_stop_timer(connector->nbr2_list_timer);
+  connector->nbr2_list_timer = NULL;
+
+  avl_delete(&connector->nbr->con_tree, &connector->nbr_tree_node);
+  avl_delete(&connector->nbr2->con_tree, &connector->nbr2_tree_node);
 
-  nbr = nbr2_list->nbr2_nbr;
-  nbr2 = nbr2_list->nbr2;
+  olsr_cookie_free(nbr_connector_mem_cookie, connector);
+}
+
+/**
+ * Looks up the connection object of an one-hop neighbor to a
+ * 2-hop neighbor ip address.
+ *
+ * @param nbr the one-hop neighbor
+ * @param nbr2_addr the ip of the 2-hop neighbor
+ * @return nbr_con, or NULL if not found
+ */
+struct nbr_con *olsr_lookup_nbr_con_entry(struct nbr_entry *nbr, const union olsr_ip_addr *nbr2_addr) {
+  struct avl_node *node;
+
+  node = avl_find(&nbr->con_tree, nbr2_addr);
+  if (node) {
+    return nbr_con_node_to_connector(node);
+  }
+  return NULL;
+}
+
+/**
+ * Looks up the connection object of an 2-hop neighbor to an
+ * one-hop neighbor ip address.
+ *
+ * @param nbr2 the 2-hop neighbor
+ * @param nbr_addr the ip of the one-hop neighbor
+ * @return nbr_con, or NULL if not found
+ */
+struct nbr_con *olsr_lookup_nbr2_con_entry(struct nbr2_entry *nbr2, const union olsr_ip_addr *nbr_addr) {
+  struct avl_node *node;
+
+  node = avl_find(&nbr2->con_tree, nbr_addr);
+  if (node) {
+    return nbr2_con_node_to_connector(node);
+  }
+  return NULL;
+}
 
-  olsr_delete_nbr_list_by_addr(nbr2, &nbr->nbr_addr);
-  olsr_delete_nbr2_list_entry(nbr2_list);
+static void olsr_expire_nbr_con(void *context) {
+  struct nbr_con *connector;
+
+  connector = context;
+  connector->nbr2_list_timer = NULL;
+
+  olsr_delete_nbr_con(connector);
 }
 
 
@@ -389,13 +431,17 @@ olsr_print_neighbor_table(void)
 #if !defined REMOVE_LOG_INFO
   /* The whole function doesn't do anything else. */
 
-  const int ipwidth = olsr_cnf->ip_version == AF_INET ? 15 : 39;
+  const int ipwidth = olsr_cnf->ip_version == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN;
   struct nbr_entry *nbr;
   struct link_entry *lnk;
   struct ipaddr_str buf;
+  struct nbr2_entry *nbr2;
+  struct nbr_con *connector;
+  struct lqtextbuffer lqbuffer;
+  bool first;
 
   OLSR_INFO(LOG_NEIGHTABLE, "\n--- %s ------------------------------------------------ NEIGHBORS\n\n"
-            "%*s  LQ    SYM   MPR   MPRS  will\n", olsr_wallclock_string(), ipwidth, "IP address");
+            "%-*s\tSYM\tMPR\tMPRS\twill\n", olsr_wallclock_string(), ipwidth, "IP address");
 
   OLSR_FOR_ALL_NBR_ENTRIES(nbr) {
 
@@ -404,12 +450,28 @@ olsr_print_neighbor_table(void)
       continue;
     }
 
-    OLSR_INFO_NH(LOG_NEIGHTABLE, "%-*s  %s  %s  %s  %d\n",
+    OLSR_INFO_NH(LOG_NEIGHTABLE, "%-*s\t%s\t%s\t%s\t%d\n",
                  ipwidth, olsr_ip_to_string(&buf, &nbr->nbr_addr),
-                 nbr->status == SYM ? "YES " : "NO  ",
-                 nbr->is_mpr ? "YES " : "NO  ",
+                 nbr->is_sym ? "YES" : "NO",
+                 nbr->is_mpr ? "YES" : "NO",
                  olsr_lookup_mprs_set(&nbr->nbr_addr) == NULL ? "NO  " : "YES ", nbr->willingness);
   } OLSR_FOR_ALL_NBR_ENTRIES_END(nbr);
+
+  OLSR_INFO(LOG_2NEIGH, "\n--- %s ----------------------- TWO-HOP NEIGHBORS\n\n"
+            "IP addr (2-hop)  IP addr (1-hop)  Total cost\n", olsr_wallclock_string());
+
+  OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) {
+    first = true;
+    OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, connector) {
+      OLSR_INFO_NH(LOG_2NEIGH, "%-*s  %-*s  %s\n",
+                   ipwidth, first ? olsr_ip_to_string(&buf, &nbr2->nbr2_addr) : "",
+                   ipwidth, olsr_ip_to_string(&buf, &connector->nbr->nbr_addr),
+                   get_linkcost_text(connector->path_linkcost, false, &lqbuffer));
+
+      first = false;
+    } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, connector);
+  } OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2);
+
 #endif
 }
 
index fb9379f..75c4e8a 100644 (file)
 #define _OLSR_NEIGH_TBL
 
 #include "defs.h"
+#include "mantissa.h"
 #include "olsr_types.h"
 #include "common/avl.h"
 
+#define NB2S_COVERED  0x1     /* node has been covered by a MPR */
+
 /*
- * This is a neighbor2 list entry.
- * It is used to describe a set of references to two-hop neighbors.
- * This AVL tree node is hanging off an nbr_entry.
+ * This is a connector between a neighbor and a two-hop neighbor
  */
-struct nbr2_list_entry {
-  struct avl_node nbr2_list_node;
-  struct nbr_entry *nbr2_nbr;          /* backpointer to owning nbr entry */
+struct nbr_con {
+  struct avl_node nbr_tree_node;
+  struct avl_node nbr2_tree_node;
+
+  struct nbr_entry *nbr;
   struct nbr2_entry *nbr2;
+
   struct timer_entry *nbr2_list_timer;
+
+  olsr_linkcost second_hop_linkcost;
+  olsr_linkcost path_linkcost;
+  olsr_linkcost saved_path_linkcost;
 };
 
-AVLNODE2STRUCT(nbr2_list_node_to_nbr2_list, struct nbr2_list_entry, nbr2_list_node);
+AVLNODE2STRUCT(nbr_con_node_to_connector, struct nbr_con, nbr_tree_node);
+AVLNODE2STRUCT(nbr2_con_node_to_connector, struct nbr_con, nbr2_tree_node);
 
 #define OLSR_NBR2_LIST_JITTER 5 /* percent */
 
 struct nbr_entry {
   struct avl_node nbr_node;            /* nbr keyed by ip address */
   union olsr_ip_addr nbr_addr;
-  unsigned int status:3;
   unsigned int willingness:3;
+  unsigned int is_sym:1;
   unsigned int is_mpr:1;
   unsigned int was_mpr:1;              /* Used to detect changes in MPR */
   unsigned int skip:1;
   int nbr2_nocov;
   unsigned int linkcount;
-  struct avl_tree nbr2_list_tree;      /* subtree for nbr2 pointers */
-} __attribute__ ((packed));
+  struct avl_tree con_tree;      /* subtree for connectors to nbr2 */
+};
 
 AVLNODE2STRUCT(nbr_node_to_nbr, struct nbr_entry, nbr_node);
 
+struct nbr2_entry {
+  struct avl_node nbr2_node;
+  union olsr_ip_addr nbr2_addr;
+  unsigned int mpr_covered_count;      /* Used in mpr calculation */
+  unsigned int processed:1;            /* Used in mpr calculation */
+  struct avl_tree con_tree;  /* subtree for connectors to nbr */
+};
+
+AVLNODE2STRUCT(nbr2_node_to_nbr2, struct nbr2_entry, nbr2_node);
+
 /*
  * macros for traversing neighbors and neighbor2 ref lists.
  * it is recommended to use this because it hides all the internal
@@ -95,34 +114,69 @@ AVLNODE2STRUCT(nbr_node_to_nbr, struct nbr_entry, nbr_node);
     nbr = nbr_node_to_nbr(nbr_tree_node);
 #define OLSR_FOR_ALL_NBR_ENTRIES_END(nbr) }}
 
-#define OLSR_FOR_ALL_NBR2_LIST_ENTRIES(nbr, nbr2_list) \
+#define OLSR_FOR_ALL_NBR_CON_ENTRIES(nbr, nbr_con) \
+{ \
+  struct avl_node *nbr_con_node, *next_nbr_con_node; \
+  for (nbr_con_node = avl_walk_first(&nbr->con_tree); \
+    nbr_con_node; nbr_con_node = next_nbr_con_node) { \
+    next_nbr_con_node = avl_walk_next(nbr_con_node); \
+    nbr_con = nbr_con_node_to_connector(nbr_con_node);
+#define OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr, nbr_con) }}
+
+/*
+ * macros for traversing two-hop neighbors and neighbor ref lists.
+ * it is recommended to use this because it hides all the internal
+ * datastructure from the callers.
+ *
+ * the loop prefetches the next node in order to not loose context if
+ * for example the caller wants to delete the current entry.
+ */
+#define OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) \
+{ \
+  struct avl_node *nbr2_tree_node, *next_nbr2_tree_node; \
+  for (nbr2_tree_node = avl_walk_first(&nbr2_tree); \
+    nbr2_tree_node; nbr2_tree_node = next_nbr2_tree_node) { \
+    next_nbr2_tree_node = avl_walk_next(nbr2_tree_node); \
+    nbr2 = nbr2_node_to_nbr2(nbr2_tree_node);
+#define OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2) }}
+
+#define OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, nbr_con) \
 { \
-  struct avl_node *nbr2_list_node, *next_nbr2_list_node; \
-  for (nbr2_list_node = avl_walk_first(&nbr->nbr2_list_tree); \
-    nbr2_list_node; nbr2_list_node = next_nbr2_list_node) { \
-    next_nbr2_list_node = avl_walk_next(nbr2_list_node); \
-    nbr2_list = nbr2_list_node_to_nbr2_list(nbr2_list_node);
-#define OLSR_FOR_ALL_NBR2_LIST_ENTRIES_END(nbr, nbr2_list) }}
+  struct avl_node *nbr_con_node, *next_nbr_con_node; \
+  for (nbr_con_node = avl_walk_first(&nbr2->con_tree); \
+    nbr_con_node; nbr_con_node = next_nbr_con_node) { \
+    next_nbr_con_node = avl_walk_next(nbr_con_node); \
+    nbr_con = nbr2_con_node_to_connector(nbr_con_node);
+#define OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, nbr_con) }}
 
 /*
  * The one hop neighbor tree
  */
 extern struct avl_tree EXPORT(nbr_tree);
+extern struct avl_tree EXPORT(nbr2_tree);
 extern struct olsr_cookie_info *nbr2_list_timer_cookie;
 
 void olsr_init_neighbor_table(void);
-struct nbr2_list_entry *olsr_lookup_nbr2_list_entry(struct nbr_entry *, const union olsr_ip_addr *);
-struct nbr2_list_entry *olsr_add_nbr2_list_entry(struct nbr_entry *, struct nbr2_entry *, float);
-void olsr_delete_nbr2_list_entry(struct nbr2_list_entry *);
-bool olsr_delete_nbr_entry(const union olsr_ip_addr *);
-void olsr_link_nbr_nbr2(struct nbr_entry *, struct nbr2_entry *, float);
+
+/* work with 1-hop neighbors */
 struct nbr_entry *olsr_add_nbr_entry(const union olsr_ip_addr *);
-struct nbr_entry *olsr_lookup_nbr_entry(const union olsr_ip_addr *);
-struct nbr_entry *olsr_lookup_nbr_entry_alias(const union olsr_ip_addr *);
-void olsr_time_out_two_hop_neighbors(struct nbr_entry *);
-void olsr_expire_nbr2_list(void *);
+void olsr_delete_nbr_entry(struct nbr_entry *);
+struct nbr_entry *EXPORT(olsr_lookup_nbr_entry) (const union olsr_ip_addr *, bool aliaslookup);
+
+int olsr_update_nbr_status(struct nbr_entry *, bool);
+
+/* work with 2-hop neighbors */
+struct nbr2_entry *olsr_add_nbr2_entry(const union olsr_ip_addr *);
+void olsr_delete_nbr2_entry(struct nbr2_entry *);
+struct nbr2_entry *EXPORT(olsr_lookup_nbr2_entry)(const union olsr_ip_addr *, bool aliaslookup);
+
+/* work with connectors */
+struct nbr_con *olsr_link_nbr_nbr2(struct nbr_entry *, const union olsr_ip_addr *, olsr_reltime);
+void olsr_delete_nbr_con(struct nbr_con *);
+struct nbr_con *EXPORT(olsr_lookup_nbr_con_entry)(struct nbr_entry *, const union olsr_ip_addr *);
+struct nbr_con *EXPORT(olsr_lookup_nbr2_con_entry)(struct nbr2_entry *, const union olsr_ip_addr *);
+
 void olsr_print_neighbor_table(void);
-int olsr_update_nbr_status(struct nbr_entry *, int);
 
 #endif /* OLSR_NEIGH_TBL */
 
index c500c00..c2f97c7 100644 (file)
 #include "defs.h"
 #include "olsr.h"
 #include "link_set.h"
-#include "two_hop_neighbor_table.h"
 #include "tc_set.h"
 #include "duplicate_set.h"
 #include "mpr_selector_set.h"
 #include "mid_set.h"
-#include "mpr.h"
 #include "lq_mpr.h"
 #include "olsr_spf.h"
 #include "scheduler.h"
@@ -169,7 +167,6 @@ olsr_process_changes(void)
 
   olsr_print_link_set();
   olsr_print_neighbor_table();
-  olsr_print_two_hop_neighbor_table();
   olsr_print_tc_table();
   olsr_print_mid_set();
   olsr_print_duplicate_table();
@@ -227,9 +224,6 @@ olsr_init_tables(void)
   /* Initialize routing table */
   olsr_init_routing_table();
 
-  /* Initialize two hop table */
-  olsr_init_two_hop_table();
-
   /* Initialize topology */
   olsr_init_tc();
 
@@ -265,6 +259,9 @@ olsr_forward_message(union olsr_message *m, struct interface *in_if, union olsr_
   struct nbr_entry *neighbor;
   int msgsize;
   struct interface *ifn;
+#if !defined REMOVE_LOG_DEBUG
+  struct ipaddr_str buf;
+#endif
 
   /*
    * Sven-Ola: We should not flood the mesh with overdue messages. Because
@@ -284,21 +281,30 @@ olsr_forward_message(union olsr_message *m, struct interface *in_if, union olsr_
   if (!src)
     src = from_addr;
 
-  neighbor = olsr_lookup_nbr_entry(src);
-  if (!neighbor)
+  neighbor = olsr_lookup_nbr_entry(src, true);
+  if (!neighbor) {
+    OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because no nbr entry found for %s\n",
+        m->v4.olsr_msgtype, olsr_ip_to_string(&buf, src));
     return 0;
-
-  if (neighbor->status != SYM)
+  }
+  if (!neighbor->is_sym) {
+    OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because received by non-symmetric neighbor %s\n",
+        m->v4.olsr_msgtype, olsr_ip_to_string(&buf, src));
     return 0;
+  }
 
   /* Check MPR */
   if (olsr_lookup_mprs_set(src) == NULL) {
+    OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because we are no MPR for %s\n",
+        m->v4.olsr_msgtype, olsr_ip_to_string(&buf, src));
     /* don't forward packages if not a MPR */
     return 0;
   }
 
   /* check if we already forwarded this message */
   if (olsr_message_is_duplicate(m, true)) {
+    OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d from %s because we already forwarded it.\n",
+        m->v4.olsr_msgtype, olsr_ip_to_string(&buf, src));
     return 0;                   /* it's a duplicate, forget about it */
   }
 
@@ -316,6 +322,9 @@ olsr_forward_message(union olsr_message *m, struct interface *in_if, union olsr_
   /* Update packet data */
   msgsize = ntohs(m->v4.olsr_msgsize);
 
+  OLSR_DEBUG(LOG_PACKET_PARSING, "Forwarding message type %d from %s.\n",
+      m->v4.olsr_msgtype, olsr_ip_to_string(&buf, src));
+
   /* looping trough interfaces */
   OLSR_FOR_ALL_INTERFACES(ifn) {
     if (net_output_pending(ifn)) {
index 315990e..b7adf0e 100644 (file)
 #define MAX_NEIGH             2
 
 /*
- *Neighbor status
- */
-
-#define NOT_SYM               0
-#define SYM                   1
-
-/*
  *Willingness
  */
 
index e0649c0..7baf89f 100644 (file)
@@ -342,7 +342,7 @@ olsr_calculate_routing_table(void)
     neigh = link->neighbor;
     tc_edge = link->link_tc_edge;
 
-    if (neigh->status == SYM) {
+    if (neigh->is_sym) {
       if (tc_edge->edge_inv) {
         tc_edge->edge_inv->tc->next_hop = link;
       }
index 6997d70..2bc0da7 100644 (file)
@@ -42,7 +42,6 @@
 #include "process_package.h"
 #include "link_set.h"
 #include "hna_set.h"
-#include "two_hop_neighbor_table.h"
 #include "neighbor_table.h"
 #include "mpr_selector_set.h"
 #include "mid_set.h"
@@ -72,8 +71,7 @@ process_message_neighbors(struct nbr_entry *neighbor, const struct lq_hello_mess
   olsr_linkcost first_hop_pathcost;
   struct link_entry *lnk;
   union olsr_ip_addr *neigh_addr;
-  struct nbr_list_entry *nbr_list;
-  struct nbr2_list_entry *nbr2_list;
+  struct nbr_con *connector;
 
   /*
    * Walk our 2-hop neighbors.
@@ -101,43 +99,7 @@ process_message_neighbors(struct nbr_entry *neighbor, const struct lq_hello_mess
       continue;
     }
 
-    nbr2_list = olsr_lookup_nbr2_list_entry(neighbor, &message_neighbors->addr);
-    if (nbr2_list != NULL) {
-
-      /* Updating the holding time for this neighbor */
-      olsr_set_timer(&nbr2_list->nbr2_list_timer, message->comm.vtime, OLSR_NBR2_LIST_JITTER,
-                     OLSR_TIMER_ONESHOT, &olsr_expire_nbr2_list, nbr2_list, nbr2_list_timer_cookie->ci_id);
-
-      /*
-       * reset the path link quality here.
-       * The path link quality will be calculated in the second pass, below.
-       * Keep the saved_path_link_quality for reference.
-       */
-
-      /*
-       * loop through the one-hop neighbors that see this
-       * 'two_hop_neighbor'
-       */
-      OLSR_FOR_ALL_NBR_LIST_ENTRIES(nbr2_list->nbr2, nbr_list) {
-
-        /*
-         * have we found the one-hop neighbor that sent the
-         * HELLO message that we're current processing?
-         */
-        if (nbr_list->neighbor == neighbor) {
-          nbr_list->path_linkcost = LINK_COST_BROKEN;
-        }
-      } OLSR_FOR_ALL_NBR_LIST_ENTRIES_END(nbr2_list->nbr2, nbr_list);
-    } else {
-      struct nbr2_entry *two_hop_neighbor = olsr_add_nbr2_entry(&message_neighbors->addr);
-
-      /*
-       * linking to this two_hop_neighbor entry
-       */
-      changes_neighborhood = true;
-      changes_topology = true;
-      olsr_link_nbr_nbr2(neighbor, two_hop_neighbor, message->comm.vtime);
-    }
+    olsr_link_nbr_nbr2(neighbor, &message_neighbors->addr, message->comm.vtime);
   }
 
   /* Second pass */
@@ -161,47 +123,35 @@ process_message_neighbors(struct nbr_entry *neighbor, const struct lq_hello_mess
       continue;
     }
     if (message_neighbors->neigh_type == SYM_NEIGH || message_neighbors->neigh_type == MPR_NEIGH) {
-      nbr2_list = olsr_lookup_nbr2_list_entry(neighbor, &message_neighbors->addr);
+      olsr_linkcost new_second_hop_linkcost;
+      olsr_linkcost new_path_linkcost;
+      connector = olsr_lookup_nbr_con_entry(neighbor, &message_neighbors->addr);
 
-      if (!nbr2_list) {
+      if (!connector) {
         continue;
       }
 
-      /*
-       * Loop through the one-hop neighbors that see this 'nbr2_list->nbr2'
-       */
-      OLSR_FOR_ALL_NBR_LIST_ENTRIES(nbr2_list->nbr2, nbr_list) {
-
-        /*
-         * have we found the one-hop neighbor that sent the
-         * HELLO message that we're current processing?
-         */
-        if (nbr_list->neighbor == neighbor) {
-          // the link cost between the 1-hop neighbour and the
-          // 2-hop neighbour
-          olsr_linkcost new_second_hop_linkcost = message_neighbors->cost;
-
-          // the total cost for the route
-          // "us --- 1-hop --- 2-hop"
-          olsr_linkcost new_path_linkcost = first_hop_pathcost + new_second_hop_linkcost;
-
-          // Only copy the link quality if it is better than what we have
-          // for this 2-hop neighbor
-          if (new_path_linkcost < nbr_list->path_linkcost) {
-            nbr_list->second_hop_linkcost = new_second_hop_linkcost;
-            nbr_list->path_linkcost = new_path_linkcost;
-
-            if (olsr_is_relevant_costchange(new_path_linkcost, nbr_list->saved_path_linkcost)) {
-              nbr_list->saved_path_linkcost = new_path_linkcost;
-
-              if (olsr_cnf->lq_dlimit > 0) {
-                changes_neighborhood = true;
-                changes_topology = true;
-              }
-            }
+      new_second_hop_linkcost = message_neighbors->cost;
+
+      // the total cost for the route
+      // "us --- 1-hop --- 2-hop"
+      new_path_linkcost = first_hop_pathcost + new_second_hop_linkcost;
+
+      // Only copy the link quality if it is better than what we have
+      // for this 2-hop neighbor
+      if (new_path_linkcost < connector->path_linkcost) {
+        connector->second_hop_linkcost = new_second_hop_linkcost;
+        connector->path_linkcost = new_path_linkcost;
+
+        if (olsr_is_relevant_costchange(new_path_linkcost, connector->saved_path_linkcost)) {
+          connector->saved_path_linkcost = new_path_linkcost;
+
+          if (olsr_cnf->lq_dlimit > 0) {
+            changes_neighborhood = true;
+            changes_topology = true;
           }
         }
-      } OLSR_FOR_ALL_NBR_LIST_ENTRIES_END(nbr2_list->nbr2, nbr_list);
+      }
     }
   }
 }
index 599b61f..b6243b8 100644 (file)
@@ -42,7 +42,6 @@
 #include "routing_table.h"
 #include "ipcalc.h"
 #include "defs.h"
-#include "two_hop_neighbor_table.h"
 #include "tc_set.h"
 #include "mid_set.h"
 #include "neighbor_table.h"