first cut for linkset refactoring
authorHenning Rogge <rogge@fgan.de>
Mon, 17 Mar 2008 18:35:27 +0000 (19:35 +0100)
committerHenning Rogge <rogge@fgan.de>
Mon, 17 Mar 2008 18:35:27 +0000 (19:35 +0100)
38 files changed:
Makefile.inc
lib/bmf/src/NetworkInterfaces.c
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/nameservice/src/mapwrite.c
lib/nameservice/src/nameservice.c
lib/tas/src/plugin.c
lib/txtinfo/src/olsrd_txtinfo.c
src/duplicate_set.c
src/duplicate_set.h
src/hna_set.c
src/hysteresis.c
src/hysteresis.h
src/link_set.c
src/link_set.h
src/lq_mpr.c
src/lq_packet.c
src/lq_packet.h
src/lq_route.c
src/main.c
src/mid_set.c
src/mpr_selector_set.c
src/net_olsr.c
src/olsr.c
src/olsr.h
src/olsr_types.h
src/packet.c
src/packet.h
src/parser.c
src/process_package.c
src/routing_table.c
src/routing_table.h
src/scheduler.c
src/tc_set.c
src/tc_set.h
src/two_hop_neighbor_table.c
src/two_hop_neighbor_table.h
src/unix/ifnet.c

index 5db06bd..9feb874 100644 (file)
@@ -5,13 +5,13 @@
 #
 
 # activate debugging with 1 or deactivate with 0
-DEBUG ?= 0
+DEBUG ?= 1
 
 # compile OLSR_PRINTF out
 NO_DEBUG_MESSAGES ?= 0
 
 # the optimize option to be set for gcc
-OPTIMIZE ?= -O2
+OPTIMIZE ?= 
 
 # enable mudflap with 1 or deactivate with 0
 # you need a recent enough gcc and the libmudflap installed
@@ -178,7 +178,7 @@ OBJS +=             $(SRCS:%.c=%.o)
 # debugging or non-debugging flags
 ifeq ($(DEBUG),1)
 CPPFLAGS +=    -DDEBUG
-CFLAGS +=      -g
+CFLAGS +=      -ggdb
 else
 CPPFLAGS +=    -DNDEBUG
 endif
index d7ede59..3a458b2 100644 (file)
@@ -64,6 +64,7 @@
 #include "lq_route.h" /* MIN_LINK_QUALITY */
 #include "tc_set.h" /* olsr_lookup_tc_entry(), olsr_lookup_tc_edge() */
 #include "net_olsr.h" /* ipequal */
+#include "lq_plugin.h"
 
 /* Plugin includes */
 #include "Packet.h" /* IFHWADDRLEN */
@@ -389,37 +390,6 @@ void RestoreSpoofFilter(void)
   }
 } /* RestoreSpoofFilter */
 
-#ifndef USING_THALES_LINK_COST_ROUTING
-/* -------------------------------------------------------------------------
- * Function   : CalcEtx
- * Description: Calculate the Expected Transmission Count (ETX) value, based on
- *              link loss fraction and inverse link loss fraction
- * Input      : loss - link loss fraction
- *              neigh_loss - inverse link loss fraction 
- * Output     : none
- * Return     : the ETX value
- * Data Used  : none
- * ------------------------------------------------------------------------- */
-static float CalcEtx(float loss, float neigh_loss) 
-{
-#ifdef USE_FPM
-  if (loss < fpmtof(MIN_LINK_QUALITY) || neigh_loss < fpmtof(MIN_LINK_QUALITY))
-  {
-    return fpmtof(INFINITE_ETX);
-  }
-#else
-  if (loss < MIN_LINK_QUALITY || neigh_loss < MIN_LINK_QUALITY)
-  {
-    return INFINITE_ETX;
-  }
-#endif
-  else
-  {
-    return 1.0 / (loss * neigh_loss);
-  }
-} /* CalcEtx */
-#endif /* USING_THALES_LINK_COST_ROUTING */
-
 /* -------------------------------------------------------------------------
  * Function   : FindNeighbors
  * Description: Find the neighbors on a network interface to forward a BMF
@@ -760,13 +730,8 @@ void FindNeighbors(
 #else /* USING_THALES_LINK_COST_ROUTING */
         
     struct link_entry* walker;
-#ifdef USE_FPM
-    float previousLinkEtx = 2 * fpmtof(INFINITE_ETX);
-    float bestEtx = 2 * fpmtof(INFINITE_ETX);
-#else
-    float previousLinkEtx = 2 * INFINITE_ETX;
-    float bestEtx = 2 * INFINITE_ETX;
-#endif
+    olsr_linkcost previousLinkEtx = LINK_COST_BROKEN;
+    olsr_linkcost bestEtx = LINK_COST_BROKEN;
 
     if (forwardedBy != NULL)
     {
@@ -774,15 +739,7 @@ void FindNeighbors(
       struct link_entry* bestLinkFromForwarder = get_best_link_to_neighbor(forwardedBy);
       if (bestLinkFromForwarder != NULL)
       {
-        previousLinkEtx =
-          CalcEtx(
-#ifdef USE_FPM
-            fpmtof(bestLinkFromForwarder->loss_link_quality),
-            fpmtof(bestLinkFromForwarder->neigh_link_quality));
-#else
-            bestLinkFromForwarder->loss_link_quality,
-            bestLinkFromForwarder->neigh_link_quality);
-#endif
+        previousLinkEtx = bestLinkFromForwarder->linkcost;
       }
     }
 
@@ -850,20 +807,9 @@ void FindNeighbors(
       /* Found a candidate neighbor to direct our packet to */
 
       /* Calculate the link quality (ETX) of the link to the found neighbor */
-      currEtx = CalcEtx(
-#ifdef USE_FPM
-        fpmtof(walker->loss_link_quality),
-        fpmtof(walker->neigh_link_quality));
-#else
-        walker->loss_link_quality,
-        walker->neigh_link_quality);
-#endif
+      currEtx = walker->linkcost;
  
-#ifdef USE_FPM
-      if (currEtx >= fpmtof(INFINITE_ETX))
-#else
-      if (currEtx >= INFINITE_ETX)
-#endif
+      if (currEtx < LINK_COST_BROKEN)
       {
         OLSR_PRINTF(
           9,
@@ -909,18 +855,11 @@ void FindNeighbors(
 #endif
           OLSR_PRINTF(
             9,
-            "%s: ----> Not forwarding to %s: \"%s\" gives a better link to this neighbor, costing %5.2f\n",
+            "%s: ----> Not forwarding to %s: \"%s\" gives a better link to this neighbor, costing %s\n",
             PLUGIN_NAME_SHORT,
             olsr_ip_to_string(&buf, &walker->neighbor_iface_addr),
             bestIntf->int_name,
-            CalcEtx(
-#ifdef USE_FPM
-              fpmtof(bestLinkToNeighbor->loss_link_quality),
-              fpmtof(bestLinkToNeighbor->neigh_link_quality)));
-#else
-              bestLinkToNeighbor->loss_link_quality,
-              bestLinkToNeighbor->neigh_link_quality));
-#endif
+            get_linkcost_text(bestLinkToNeighbor->linkcost, OLSR_FALSE));
         }
 
         continue; /* for */
@@ -933,11 +872,11 @@ void FindNeighbors(
 #endif
         OLSR_PRINTF(
           9,
-          "%s: ----> 2-hop path from %s via me to %s will cost ETX %5.2f\n",
+          "%s: ----> 2-hop path from %s via me to %s will cost ETX %s\n",
           PLUGIN_NAME_SHORT,
           olsr_ip_to_string(&forwardedByBuf, forwardedBy),
           olsr_ip_to_string(&niaBuf, &walker->neighbor_iface_addr),
-          previousLinkEtx + currEtx);
+          get_linkcost_text(previousLinkEtx + currEtx, OLSR_TRUE));
       }
 
       /* Check the topology table whether the 'forwardedBy' node is itself a direct
@@ -958,14 +897,7 @@ void FindNeighbors(
           /* We are not interested in dead-end or dying edges. */
           if (tc_edge != NULL && (tc_edge->flags & OLSR_TC_EDGE_DOWN) == 0)
           {
-            float tcEtx = CalcEtx(
-#ifdef USE_FPM
-              fpmtof(tc_edge->link_quality),
-              fpmtof(tc_edge->inverse_link_quality));
-#else
-              tc_edge->link_quality,
-              tc_edge->inverse_link_quality);
-#endif
+            olsr_linkcost tcEtx = tc_edge->cost;
 
             if (previousLinkEtx + currEtx > tcEtx)
             {
@@ -975,12 +907,12 @@ void FindNeighbors(
 #endif
               OLSR_PRINTF(
                 9,
-                "%s: ----> Not forwarding to %s: I am not an MPR between %s and %s, direct link costs %5.2f\n",
+                "%s: ----> Not forwarding to %s: I am not an MPR between %s and %s, direct link costs %s\n",
                 PLUGIN_NAME_SHORT,
                 neighbor_iface_buf.buf,
                 olsr_ip_to_string(&forw_buf, forwardedBy),
                 neighbor_iface_buf.buf,
-                tcEtx);
+                get_linkcost_text(tcEtx, OLSR_FALSE));
 
               continue; /* for */
             } /* if */
index 16cb374..4811be8 100644 (file)
@@ -69,6 +69,7 @@
 #include "link_set.h"
 #include "socket_parser.h"
 #include "net_olsr.h"
+#include "lq_plugin.h"
 
 #include "olsrd_dot_draw.h"
 #include "olsrd_plugin.h"
@@ -154,11 +155,7 @@ static void
 ipc_print_neigh_link(const struct neighbor_entry *neighbor)
 {
   struct ipaddr_str mainaddrstrbuf, strbuf;
-#ifdef USE_FPM
-  fpm etx = itofpm(0);
-#else
-  double etx = 0.0;
-#endif
+  olsr_linkcost etx = 0.0;
   const char *style;
   const char *adr = olsr_ip_to_string(&mainaddrstrbuf, &olsr_cnf->main_addr);
   struct link_entry* link;
@@ -168,7 +165,7 @@ ipc_print_neigh_link(const struct neighbor_entry *neighbor)
   } else {   
     link = get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
     if (link) {
-      etx = olsr_calc_link_etx(link);
+      etx = link->linkcost;
     }
     style = "solid";
   }
@@ -176,7 +173,7 @@ ipc_print_neigh_link(const struct neighbor_entry *neighbor)
   ipc_send_fmt("\"%s\" -> \"%s\"[label=\"%s\", style=%s];\n",
                adr,
                olsr_ip_to_string(&strbuf, &neighbor->neighbor_main_addr),
-               etxtoa(etx),
+               get_linkcost_text(etx, OLSR_FALSE),
                style);
   
   if (neighbor->is_mpr) {
@@ -269,6 +266,7 @@ ipc_action(int fd __attribute__((unused)))
   olsr_printf(1, "(DOT DRAW)IPC: Connection from %s\n", inet_ntoa(pin.sin_addr));
   close(ipc_connection); /* close connection after one output */
   pcf_event(1, 1, 1);
+  close(ipc_connection); // close connection after one output
 }
 
 
@@ -343,7 +341,7 @@ ipc_print_tc_link(const struct tc_entry *entry, const struct tc_edge_entry *dst_
   ipc_send_fmt("\"%s\" -> \"%s\"[label=\"%s\"];\n",
                olsr_ip_to_string(&strbuf1, &entry->addr),
                olsr_ip_to_string(&strbuf2, &dst_entry->T_dest_addr),
-               etxtoa(olsr_calc_tc_etx(dst_entry)));
+               get_linkcost_text(dst_entry->cost, OLSR_FALSE));
 }
 
 
index 96329f2..87cf489 100644 (file)
@@ -62,6 +62,7 @@
 #include "link_set.h"
 #include "socket_parser.h"
 #include "ipcalc.h"
+#include "lq_plugin.h"
 
 #include "olsrd_httpinfo.h"
 #include "admin_interface.h"
@@ -86,7 +87,7 @@
 #define OS "Undefined"
 #endif
 
-static char copyright_string[] __attribute__((unused)) = "olsr.org HTTPINFO plugin Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org) All rights reserved.";
+static char copyright_string[] __attribute__((unused)) = "olsr.org HTTPINFO plugin Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org) All rights reserved.";
 
 #define MAX_CLIENTS 3
 
@@ -764,7 +765,7 @@ static int build_route(char *buf, olsr_u32_t bufsize, const struct rt_entry * rt
                    rt->rt_best->rtp_metric.hops);
   size += snprintf(&buf[size], bufsize-size,
                    "<td align=\"right\">%s</td>",
-                   etxtoa(rt->rt_best->rtp_metric.etx));
+                   get_linkcost_text(rt->rt_best->rtp_metric.cost, OLSR_TRUE));
   size += snprintf(&buf[size], bufsize-size,
                    "<td align=\"center\">%s</td></tr>\n",
                    if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
@@ -975,7 +976,7 @@ static int build_neigh_body(char *buf, olsr_u32_t bufsize)
                    "<tr><th align=\"center\"%s>Local IP</th><th align=\"center\"%s>Remote IP</th><th align=\"right\">Hysteresis</th>", colspan, colspan);
   if (olsr_cnf->lq_level > 0) {
     size += snprintf(&buf[size], bufsize-size,
-                     "<th align=\"right\">LinkQuality</th><th>lost</th><th>total</th><th align=\"right\">NLQ</th><th align=\"right\">ETX</th>");
+                     "<th align=\"right\">LinkCost</th>");
   }
   size += snprintf(&buf[size], bufsize-size, "</tr>\n");
 
@@ -984,19 +985,12 @@ static int build_neigh_body(char *buf, olsr_u32_t bufsize)
     size += snprintf(&buf[size], bufsize-size, "<tr>");
     size += build_ipaddr_with_link(&buf[size], bufsize, &link->local_iface_addr, -1);
     size += build_ipaddr_with_link(&buf[size], bufsize, &link->neighbor_iface_addr, -1);
-    size += snprintf(&buf[size], bufsize-size, "<td align=\"right\">%s</td>", fpmtoa(link->L_link_quality));
+    size += snprintf(&buf[size], bufsize-size, "<td align=\"right\">%0.2f</td>", link->L_link_quality);
     if (olsr_cnf->lq_level > 0) {
       size += snprintf(&buf[size], bufsize-size,
-                       "<td align=\"right\">%s</td>"
-                       "<td>%d</td>"
-                       "<td>%d</td>"
-                       "<td align=\"right\">%s</td>"
-                       "<td align=\"right\">%s</td>\n",
-                       fpmtoa(link->loss_link_quality),
-                       link->lost_packets,
-                       link->total_packets,
-                       fpmtoa(link->neigh_link_quality),
-                       etxtoa(olsr_calc_link_etx(link)));
+                       "<td align=\"right\">(%s) %s</td>",
+                       get_link_entry_text(link),
+                       get_linkcost_text(link->linkcost, OLSR_FALSE));
     }
     size += snprintf(&buf[size], bufsize-size, "</tr>\n");
   } OLSR_FOR_ALL_LINK_ENTRIES_END(link);
@@ -1050,7 +1044,7 @@ static int build_topo_body(char *buf, olsr_u32_t bufsize)
   size += section_title(&buf[size], bufsize-size, "Topology Entries");
   size += snprintf(&buf[size], bufsize-size, "<tr><th align=\"center\"%s>Destination IP</th><th align=\"center\"%s>Last Hop IP</th>", colspan, colspan);
   if (olsr_cnf->lq_level > 0) {
-    size += snprintf(&buf[size], bufsize-size, "<th align=\"right\">LQ</th><th align=\"right\">ILQ</th><th align=\"right\">ETX</th>");
+    size += snprintf(&buf[size], bufsize-size, "<th align=\"right\">Linkcost</th>");
   }
   size += snprintf(&buf[size], bufsize-size, "</tr>\n");
 
@@ -1062,12 +1056,9 @@ static int build_topo_body(char *buf, olsr_u32_t bufsize)
           size += build_ipaddr_with_link(&buf[size], bufsize, &tc->addr, -1);
           if (olsr_cnf->lq_level > 0) {
               size += snprintf(&buf[size], bufsize-size,
-                               "<td align=\"right\">%s</td>"
-                               "<td align=\"right\">%s</td>"
-                               "<td align=\"right\">%s</td>\n",
-                               fpmtoa(tc_edge->link_quality),
-                               fpmtoa(tc_edge->inverse_link_quality),
-                               etxtoa(olsr_calc_tc_etx(tc_edge)));
+                               "<td align=\"right\">(%s) %s</td>\n",
+                               get_tc_edge_entry_text(tc_edge),
+                               get_linkcost_text(tc_edge->cost, OLSR_FALSE));
           }
           size += snprintf(&buf[size], bufsize-size, "</tr>\n");
 
index a14c058..1c15ed1 100644 (file)
@@ -43,6 +43,8 @@
 #include "mid_set.h"
 #include "tc_set.h"
 #include "ipcalc.h"
+#include "lq_plugin.h"
+
 #include "mapwrite.h"
 
 static char my_latlon_str[48];
@@ -177,12 +179,10 @@ void mapwrite_work(FILE* fmap)
       /*
        * To speed up processing, Links with both positions are named PLink()
        */
-      if (0 > fprintf(fmap, "PLink('%s','%s',%s,%s,%s,%s,%s);\n", 
+      if (0 > fprintf(fmap, "PLink('%s','%s',%s,%s,%s);\n", 
             olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
             olsr_ip_to_string(&strbuf2, &tc->addr), 
-            fpmtoa(tc_edge->link_quality),
-            fpmtoa(tc_edge->inverse_link_quality),
-            etxtoa(olsr_calc_tc_etx(tc_edge)),
+            get_linkcost_text(tc_edge->cost, OLSR_FALSE),
             lla, llb))
       {
         return;
@@ -193,12 +193,10 @@ void mapwrite_work(FILE* fmap)
       /*
        * If one link end pos is unkown, only send Link()
        */
-      if (0 > fprintf(fmap, "Link('%s','%s',%s,%s,%s);\n", 
+      if (0 > fprintf(fmap, "Link('%s','%s',%s);\n", 
             olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
             olsr_ip_to_string(&strbuf2, &tc->addr), 
-            fpmtoa(tc_edge->link_quality),
-            fpmtoa(tc_edge->inverse_link_quality),
-            etxtoa(olsr_calc_tc_etx(tc_edge))))
+            get_linkcost_text(tc_edge->cost, OLSR_FALSE)))
       {
         return;
       }
index 3f526b1..2ded8f3 100644 (file)
@@ -666,18 +666,11 @@ olsr_parser(union olsr_message *m, struct interface *in_if, union olsr_ip_addr *
                return;
        }
 
-       /* Check if this message has been processed before
-       * Remeber that this also registeres the message as
-       * processed if nessecary
-       */
-       if(olsr_check_dup_table_proc(&originator, seqno)) {
-               /* If not so - process */
-               update_name_entry(&originator, namemessage, size, vtime);
-       }
+       update_name_entry(&originator, namemessage, size, vtime);
 
        /* Forward the message if nessecary
        * default_fwd does all the work for us! */
-       olsr_forward_message(m, &originator, seqno, in_if, ipaddr);
+       olsr_forward_message(m, ipaddr);
 }
 
 /**
@@ -1238,9 +1231,9 @@ select_best_nameserver(struct rt_entry **rt)
                        /*
                         * first is better, swap the pointers.
                         */
-                       OLSR_PRINTF(6, "NAME PLUGIN: nameserver %s, etx %s\n",
+                       OLSR_PRINTF(6, "NAME PLUGIN: nameserver %s, cost %s\n",
                                                olsr_ip_to_string(&strbuf, &rt1->rt_dst.prefix),
-                                               etxtoa(rt1->rt_best->rtp_metric.etx));
+                                               get_linkcost_text(rt1->rt_best->rtp_metric.cost, OLSR_TRUE));
 
                        rt[nameserver_idx] = rt2;
                        rt[nameserver_idx+1] = rt1;
@@ -1293,9 +1286,9 @@ write_resolv_file(void)
 
                                /* enqueue it on the head of list */
                                *nameserver_routes = route;
-                               OLSR_PRINTF(6, "NAME PLUGIN: found nameserver %s, etx %s",
+                               OLSR_PRINTF(6, "NAME PLUGIN: found nameserver %s, cost %s",
                                                        olsr_ip_to_string(&strbuf, &name->ip),
-                                                       etxtoa(route->rt_best->rtp_metric.etx));
+                                                       get_linkcost_text(route->rt_best->rtp_metric.cost, OLSR_TRUE));
 
                                /* find the closet one */
                                select_best_nameserver(nameserver_routes);
index ecb035e..a16c98e 100644 (file)
@@ -67,6 +67,7 @@
 #include <lq_route.h>
 #include <mpr_selector_set.h>
 #include <duplicate_set.h>
+#include <lq_plugin.h>
 
 #define PLUGIN_INTERFACE_VERSION 5
 
@@ -106,25 +107,16 @@ static void __attribute__((constructor)) banner(void)
 int iterLinkTabNext(char *buff, int len)
 {
   struct list_node *link_node;
-#ifdef USE_FPM
-  fpm etx;
-#else
-  double etx;
- #endif
 
   if (iterLinkTab == NULL)
     return -1;
 
-  etx = olsr_calc_link_etx(iterLinkTab);
-
-  snprintf(buff, len, "local~%s~remote~%s~main~%s~hysteresis~%s~lq~%s~nlq~%s~etx~%s~",
+  snprintf(buff, len, "local~%s~remote~%s~main~%s~hysteresis~%f~cost~%s~",
            rawIpAddrToString(&iterLinkTab->local_iface_addr, ipAddrLen),
            rawIpAddrToString(&iterLinkTab->neighbor_iface_addr, ipAddrLen),
            rawIpAddrToString(&iterLinkTab->neighbor->neighbor_main_addr, ipAddrLen),
-           fpmtoa(iterLinkTab->L_link_quality),
-           fpmtoa(iterLinkTab->loss_link_quality),
-           fpmtoa(iterLinkTab->neigh_link_quality),
-           etxtoa(etx));
+           iterLinkTab->L_link_quality,
+           get_linkcost_text(iterLinkTab->linkcost, OLSR_FALSE));
 
 
   link_node = iterLinkTab->link_list.next;
@@ -301,9 +293,9 @@ int iterTcTabNext(char *buff, int len)
 
   OLSR_FOR_ALL_TC_EDGE_ENTRIES(iterTcTab, tc_edge) {
 
-    res = snprintf(buff, len, "[~%d~address~%s~etx~%s~]~", i,
+    res = snprintf(buff, len, "[~%d~address~%s~cost~%s~]~", i,
                    rawIpAddrToString(&tc_edge->T_dest_addr, ipAddrLen),
-                   etxtoa(olsr_calc_tc_etx(tc_edge)));
+                   get_linkcost_text(tc_edge->cost, OLSR_FALSE));
 
     if (res < len)
       buff += res;
@@ -338,7 +330,6 @@ static void parserFunc(union olsr_message *msg, struct interface *inInt,
 {
   char *mess = (char *)msg;
   union olsr_ip_addr *orig = (union olsr_ip_addr *)(mess + 4);
-  unsigned short seqNo = (mess[ipAddrLen + 6] << 8) | mess[ipAddrLen + 7];
   int len = (mess[2] << 8) | mess[3];
   char *service, *string;
   int i;
@@ -358,8 +349,6 @@ static void parserFunc(union olsr_message *msg, struct interface *inInt,
     return;
   }
 
-  if (olsr_check_dup_table_proc(orig, seqNo) != 0)
-  {
     len -= ipAddrLen + 8;
     service = mess + ipAddrLen + 8;
 
@@ -389,9 +378,8 @@ static void parserFunc(union olsr_message *msg, struct interface *inInt,
     }
 
     httpAddTasMessage(service, string, rawIpAddrToString(orig, ipAddrLen));
-  }
 
-  olsr_forward_message(msg, orig, seqNo, inInt, neighIntAddr);
+  olsr_forward_message(msg, neighIntAddr);
 }
 
 void sendMessage(const char *service, const char *string)
index bc495e2..e5ccf75 100644 (file)
@@ -76,6 +76,7 @@
 #include "link_set.h"
 #include "socket_parser.h"
 #include "net_olsr.h"
+#include "lq_plugin.h"
 
 #include "olsrd_txtinfo.h"
 #include "olsrd_plugin.h"
@@ -349,19 +350,16 @@ static void ipc_print_link(void)
     struct ipaddr_str buf1, buf2;
     struct link_entry *link = NULL;
 
-    ipc_sendf("Table: Links\nLocal IP\tremote IP\tHysteresis\tLinkQuality\tlost\ttotal\tNLQ\tETX\n");
+    ipc_sendf("Table: Links\nLocal IP\tremote IP\tHysteresis\tLinkcost\n");
 
     /* Link set */
     OLSR_FOR_ALL_LINK_ENTRIES(link) {
-       ipc_sendf( "%s\t%s\t%s\t%s\t%d\t%d\t%s\t%s\t\n",
+       ipc_sendf( "%s\t%s\t%0.2f\t%s\t%s\t\n",
                    olsr_ip_to_string(&buf1, &link->local_iface_addr),
                    olsr_ip_to_string(&buf2, &link->neighbor_iface_addr),
-                   fpmtoa(link->L_link_quality), 
-                   fpmtoa(link->loss_link_quality),
-                   link->lost_packets, 
-                   link->total_packets,
-                   fpmtoa(link->neigh_link_quality), 
-                   etxtoa(olsr_calc_link_etx(link)));
+                   link->L_link_quality, 
+                   get_link_entry_text(link),
+                   get_linkcost_text(link->linkcost, OLSR_FALSE));
     } OLSR_FOR_ALL_LINK_ENTRIES_END(link);
 
     ipc_sendf("\n");
@@ -387,7 +385,7 @@ static void ipc_print_routes(void)
                    rt->rt_dst.prefix_len,
                    olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway),
                    rt->rt_best->rtp_metric.hops,
-                   etxtoa(rt->rt_best->rtp_metric.etx),
+                   get_linkcost_text(rt->rt_best->rtp_metric.cost, OLSR_TRUE),
                    if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
     }
     ipc_sendf("\n");
@@ -398,19 +396,18 @@ static void ipc_print_topology(void)
 {
     struct tc_entry *tc;
     
-    ipc_sendf("Table: Topology\nDestination IP\tLast hop IP\tLQ\tILQ\tETX\n");
+    ipc_sendf("Table: Topology\nDestination IP\tLast hop IP\tLinkcost\n");
 
     /* Topology */  
     OLSR_FOR_ALL_TC_ENTRIES(tc) {
         struct tc_edge_entry *tc_edge;
         OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
             struct ipaddr_str dstbuf, addrbuf;
-            ipc_sendf( "%s\t%s\t%s\t%s\t%s\n", 
+            ipc_sendf( "%s\t%s\t%s\t%s\n", 
                        olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr),
                        olsr_ip_to_string(&addrbuf, &tc->addr), 
-                       fpmtoa(tc_edge->link_quality),
-                       fpmtoa(tc_edge->inverse_link_quality),
-                       etxtoa(olsr_calc_tc_etx(tc_edge)));
+                       get_tc_edge_entry_text(tc_edge),
+                       get_linkcost_text(tc_edge->cost, OLSR_FALSE));
 
         } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
     } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
index d3d3dd7..f41db9f 100644 (file)
-/*
- * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
- * 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 "duplicate_set.h"
-#include "scheduler.h"
+#include "ipcalc.h"
+#include "lq_avl.h"
 #include "olsr.h"
-#include "net_olsr.h"
-
-/* The duplicate table */
-static struct dup_entry dup_set[HASHSIZE];
-
-/**
- *Initialize the duplicate table entrys
- *
- *@return nada
- */
-void
-olsr_init_duplicate_table(void)
-{
-  int i;
+#include "mid_set.h"
 
-  OLSR_PRINTF(3, "Initializing duplicatetable - hashsize %d\n", HASHSIZE);
+struct avl_tree duplicate_set;
 
-  for(i = 0; i < HASHSIZE; i++)
-    {
-      dup_set[i].next = &dup_set[i];
-      dup_set[i].prev = &dup_set[i];
-    }
+void olsr_init_duplicate_set(void) {
+  avl_init(&duplicate_set, olsr_cnf->ip_version == AF_INET ? &avl_comp_ipv4 : &avl_comp_ipv6);
 }
 
-/**
- * Callback for the dup_entry timer.
- */
-static void
-olsr_expire_dup_entry(void *context)
-{
-#if !defined(NODEBUG) && defined(DEBUG)
-  struct ipaddr_str buf;
-#endif
-  struct dup_entry *dup;
-
-  dup = context;
-  dup->timer = NULL;
-
-#ifdef DEBUG
-  OLSR_PRINTF(5, "DUP TIMEOUT[%s] s: %d\n", 
-              olsr_ip_to_string(&buf, &dup->addr),
-              dup->seqno);
-#endif
-
-  olsr_del_dup_entry(dup);
-}
-
-
-/**
- *Add an entry to the duplicate set. The set is not checked
- *for duplicate entries.
- *
- *@param originator IP address of the sender of the message
- *@param seqno seqno of the message
- *
- *@return positive on success
- */
-static struct dup_entry *
-olsr_add_dup_entry(const union olsr_ip_addr *originator, const olsr_u16_t seqno)
-{
-  olsr_u32_t hash;
-  struct dup_entry *new_dup_entry;
-
-
-  /* Hash the senders address */
-  hash = HASHMASK & seqno;
-
-  new_dup_entry = olsr_malloc(sizeof(struct dup_entry), "New dup entry");
-
-  /* Address */
-  new_dup_entry->addr = *originator;
-  /* Seqno */
-  new_dup_entry->seqno = seqno;
-  /* Set timer */
-  new_dup_entry->timer =
-    olsr_start_timer(DUP_HOLD_TIME * MSEC_PER_SEC, OLSR_DUP_ENTRY_JITTER,
-                     OLSR_TIMER_ONESHOT, &olsr_expire_dup_entry, new_dup_entry,
-                     0);
-
-  /* Interfaces */
-  new_dup_entry->ifaces = NULL;
-  /* Forwarded */
-  new_dup_entry->forwarded = 0;
-
-  /* Insert into set */
-  QUEUE_ELEM(dup_set[hash], new_dup_entry);
-
-  return new_dup_entry;
-}
-
-
-/**
- * Check wether or not a message should be processed
- *
- */
-int
-olsr_check_dup_table_proc(const union olsr_ip_addr *originator, const olsr_u16_t seqno)
-{
-  olsr_u32_t hash;
-  struct dup_entry *tmp_dup_table;
-
-  /* Hash the senders address */
-  hash = HASHMASK & seqno;
-
-  /* Check for entry */
-  for(tmp_dup_table = dup_set[hash].next;
-      tmp_dup_table != &dup_set[hash];
-      tmp_dup_table = tmp_dup_table->next)
-    {
-      if(ipequal(&tmp_dup_table->addr, originator) &&
-        (tmp_dup_table->seqno == seqno))
-       {
-         return 0;
-       }
-    }
-
-  return 1;
+struct duplicate_entry *olsr_create_duplicate_entry(void *ip, olsr_u16_t seqnr) {
+  struct duplicate_entry *entry;
+  entry = olsr_malloc(sizeof(struct duplicate_entry), "New duplicate entry");
+  if (entry != NULL) {
+    memcpy (&entry->ip, ip, olsr_cnf->ip_version == AF_INET ? sizeof(entry->ip.v4) : sizeof(entry->ip.v6)); 
+    entry->seqnr = seqnr;
+    entry->too_low_counter = 0;
+    entry->avl.key = &entry->ip;
+  }
+  return entry;
 }
 
-
-/**
- * Check wether or not a message should be forwarded
- *
- */
-int
-olsr_check_dup_table_fwd(const union olsr_ip_addr *originator, 
-                         const olsr_u16_t seqno,
-                         const union olsr_ip_addr *int_addr)
-{
-  olsr_u32_t hash;
-  struct dup_entry *tmp_dup_table;
-
-  /* Hash the senders address */
-  hash = HASHMASK & seqno;
-
-  /* Check for entry */
-  for(tmp_dup_table = dup_set[hash].next;
-      tmp_dup_table != &dup_set[hash];
-      tmp_dup_table = tmp_dup_table->next)
-    {
-      if(ipequal(&tmp_dup_table->addr, originator) &&
-        (tmp_dup_table->seqno == seqno))
-       {
-         struct dup_iface *tmp_dup_iface;
-         /* Check retransmitted */
-         if(tmp_dup_table->forwarded)
-           return 0;
-         /* Check for interface */
-         tmp_dup_iface = tmp_dup_table->ifaces;
-         while(tmp_dup_iface)
-           {
-             if(ipequal(&tmp_dup_iface->addr, int_addr))
-               return 0;
-             
-             tmp_dup_iface = tmp_dup_iface->next;
-           }
-       }
-    }
+int olsr_shall_process_message(void *ip, olsr_u16_t seqnr) {
+  struct duplicate_entry *entry;
+  int diff;
+  void *mainIp;
   
-
-  return 1;
-}
-
-
-/**
- *Delete and dequeue a duplicate entry
- *
- *@param entry the entry to delete
- *
- */
-void
-olsr_del_dup_entry(struct dup_entry *entry)
-{
-  struct dup_iface *tmp_iface, *del_iface;
-
-  tmp_iface = entry->ifaces;
-
-  /* Free interfaces */
-  while(tmp_iface)
-    {
-      del_iface = tmp_iface;
-      tmp_iface = tmp_iface->next;
-      free(del_iface);
-    }
-
-  /* Dequeue */
-  DEQUEUE_ELEM(entry);
-
-  /* Stop timer */
-  if (entry->timer) {
-    olsr_stop_timer(entry->timer);
+  // get main address
+  mainIp = mid_lookup_main_addr(ip);
+  if (mainIp == NULL) {
+    mainIp = ip;
   }
-
-  free(entry);
-}
-
-int
-olsr_update_dup_entry(const union olsr_ip_addr *originator, 
-                     const olsr_u16_t seqno, 
-                     const union olsr_ip_addr *iface)
-{
-  olsr_u32_t hash;
-  struct dup_entry *tmp_dup_table;
-  struct dup_iface *new_iface;
-
-  /* Hash the senders address */
-  hash = HASHMASK & seqno;
-
-
-  /* Check for entry */
-  for(tmp_dup_table = dup_set[hash].next;
-      tmp_dup_table != &dup_set[hash];
-      tmp_dup_table = tmp_dup_table->next)
-    {
-      if(ipequal(&tmp_dup_table->addr, originator) &&
-        (tmp_dup_table->seqno == seqno))
-       {
-         break;
-       }
+  
+  entry = (struct duplicate_entry *)avl_find(&duplicate_set, ip);
+  if (entry == NULL) {
+    entry = olsr_create_duplicate_entry(ip, seqnr);
+    if (entry != NULL) {
+      avl_insert(&duplicate_set, &entry->avl, 0);
     }
+    return 1; // okay, we process this package
+  }
 
-  if(tmp_dup_table == &dup_set[hash]) {
-    /* Did not find entry - create it */
-    tmp_dup_table = olsr_add_dup_entry(originator, seqno);
-  } else {
-
-    /* Change timer */
-    olsr_change_timer(tmp_dup_table->timer, DUP_HOLD_TIME * MSEC_PER_SEC,
-                      OLSR_DUP_ENTRY_JITTER, OLSR_TIMER_ONESHOT);
-  }  
-
-  /* 0 for now */
-  tmp_dup_table->forwarded = 0;
+  diff = (int)seqnr - (int)(entry->seqnr);
   
-  new_iface = olsr_malloc(sizeof(struct dup_iface), "New dup iface");
-
-  new_iface->addr = *iface;
-  new_iface->next = tmp_dup_table->ifaces;
-  tmp_dup_table->ifaces = new_iface;
+  // overflow ?
+  if (diff > (1<<15)) {
+    diff -= (1<<16);
+  }
   
-  return 1;
-}
-
-int
-olsr_set_dup_forward(const union olsr_ip_addr *originator, 
-                    const olsr_u16_t seqno)
-{
-#if !defined(NODEBUG) && defined(DEBUG)
-  struct ipaddr_str buf;
-#endif
-  olsr_u32_t hash;
-  struct dup_entry *tmp_dup_table;
-
-  /* Hash the senders address */
-  hash = HASHMASK & seqno;
-
-  /* Check for entry */
-  for(tmp_dup_table = dup_set[hash].next;
-      tmp_dup_table != &dup_set[hash];
-      tmp_dup_table = tmp_dup_table->next)
-    {
-      if(ipequal(&tmp_dup_table->addr, originator) &&
-        (tmp_dup_table->seqno == seqno))
-       {
-         break;
-       }
+  if (diff < -31) {
+    entry->too_low_counter ++;
+    
+    // client did restart with a lower number ?
+    if (entry->too_low_counter > 16) {
+      entry->too_low_counter = 0;
+      entry->seqnr = seqnr;
+      entry->array = 1;
+      return 1;
     }
-
-  if(tmp_dup_table == &dup_set[hash])
-    /* Did not find entry !! */
     return 0;
+  }
   
-#ifdef DEBUG
-  OLSR_PRINTF(3, "Setting DUP %s/%d forwarded\n", olsr_ip_to_string(&buf, &tmp_dup_table->addr), seqno);
-#endif
-
-  /* Set forwarded */
-  tmp_dup_table->forwarded = 1;
-  
-  /* Set timer */
-  olsr_change_timer(tmp_dup_table->timer, DUP_HOLD_TIME * MSEC_PER_SEC,
-                    OLSR_DUP_ENTRY_JITTER, OLSR_TIMER_ONESHOT);
-  
+  entry->too_low_counter = 0;
+  if (diff <= 0) {
+    olsr_u32_t bitmask = 1 << ((olsr_u32_t) (-diff));
+    
+    if ((entry->array & bitmask) != 0) {
+//      printf("blocked\n");
+      return 0;
+    }
+    entry->array |= bitmask;
+//    printf("processed\n");
+    return 1;
+  }
+  else if (diff < 32) {
+    entry->array <<= (olsr_u32_t)diff;
+  }
+  else {
+    entry->array = 0;
+  }
+  entry->array |= 1;
+  entry->seqnr = seqnr;
+//  printf("processed\n");
   return 1;
 }
 
-void
-olsr_print_duplicate_table(void)
-{
-  int i;
-
-  printf("\nDUP TABLE:\n");
-
-  for(i = 0; i < HASHSIZE; i++)
-    {      
-      struct dup_entry *tmp_dup_table = dup_set[i].next;
-      
-      //printf("Timeout %d %d\n", i, j);
-      while(tmp_dup_table != &dup_set[i])
-       {
-          struct ipaddr_str buf;
-          printf("[%s] s: %d\n", 
-                olsr_ip_to_string(&buf, &tmp_dup_table->addr),
-                tmp_dup_table->seqno);
-         tmp_dup_table = tmp_dup_table->next;
-       }
-    }
-  printf("\n");
-
+void olsr_print_duplicate_table(void) {
+  
 }
-
-/*
- * Local Variables:
- * c-basic-offset: 2
- * End:
- */
index 4c52879..2680275 100644 (file)
-/*
- * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas TÃ\83¸nnesen(andreto@olsr.org)
- * 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_DUP_TABLE
-#define _OLSR_DUP_TABLE
-
-#include "olsr_types.h"
-
-#define UNKNOWN_MESSAGE 0
-
-struct dup_entry
-{
-  union olsr_ip_addr     addr;      /* IP address of originator */
-  olsr_u16_t             seqno;     /* Seqno of message */
-  olsr_u8_t              forwarded; /* If this message was forwarded or not */
-  struct timer_entry     *timer; /* Holding time */
-  struct dup_iface       *ifaces;   /* Interfaces this message was recieved on */
-  struct dup_entry       *next;     /* Next entry */
-  struct dup_entry       *prev;     /* Prev entry */
+#ifndef DUPLICATE_SET_2_H_
+#define DUPLICATE_SET_2_H_
+
+#include "lq_avl.h"
+#include "olsr.h"
+
+struct duplicate_entry {
+  struct avl_node avl;
+  union olsr_ip_addr ip;
+  olsr_u16_t seqnr;
+  olsr_u16_t too_low_counter;
+  olsr_u32_t array;
 };
 
-#define OLSR_DUP_ENTRY_JITTER 5 /* percent */
-
-struct dup_iface
-{
-  union olsr_ip_addr     addr;      /* Addess of the interface */
-  struct dup_iface       *next;     /* Next in line */
-};
-
-
-void
-olsr_init_duplicate_table(void);
-
-void
-olsr_time_out_duplicate_table(void *);
-
-int
-olsr_check_dup_table_proc(const union olsr_ip_addr *, const olsr_u16_t);
-
-int
-olsr_check_dup_table_fwd(const union olsr_ip_addr *, const olsr_u16_t, const union olsr_ip_addr *);
-
-void
-olsr_del_dup_entry(struct dup_entry *);
-
-void
-olsr_print_duplicate_table(void);
-
-int
-olsr_update_dup_entry(const union olsr_ip_addr *, const olsr_u16_t, const union olsr_ip_addr *);
-
-int
-olsr_set_dup_forward(const union olsr_ip_addr *, const olsr_u16_t);
-
-int
-olsr_check_dup_forward(union olsr_ip_addr *, olsr_u16_t);
-
-#endif
+void olsr_init_duplicate_set(void);
+struct duplicate_entry *olsr_create_duplicate_entry(void *ip, olsr_u16_t seqnr);
+int olsr_shall_process_message(void *ip, olsr_u16_t seqnr);
+void olsr_print_duplicate_table(void);
 
-/*
- * Local Variables:
- * c-basic-offset: 2
- * End:
- */
+#endif /*DUPLICATE_SET_2_H_*/
index cf8bd49..1dc0041 100644 (file)
@@ -205,7 +205,7 @@ static void
 olsr_expire_hna_net_entry(void *context)
 {
 #if !defined(NODEBUG) && defined(DEBUG)
-  struct ipaddr_str buf;
+  struct ipaddr_str buf1, buf2;
 #endif
   struct hna_net *net_to_delete;
   struct hna_entry *hna_gw;
@@ -216,9 +216,9 @@ olsr_expire_hna_net_entry(void *context)
 
 #ifdef DEBUG
   OLSR_PRINTF(5, "HNA: timeout %s/%u via hna-gw %s\n", 
-              olsr_ip_to_string(&buf, &net_to_delete->A_network_addr),
+              olsr_ip_to_string(&buf1, &net_to_delete->A_network_addr),
               net_to_delete->prefixlen,
-              olsr_ip_to_string(&buf, &hna_gw->A_gateway_addr));
+              olsr_ip_to_string(&buf2, &hna_gw->A_gateway_addr));
 #endif
 
   /*
@@ -234,11 +234,6 @@ olsr_expire_hna_net_entry(void *context)
     DEQUEUE_ELEM(hna_gw);
     free(hna_gw);
   }
-
-  DEQUEUE_ELEM(net_to_delete);
-  free(net_to_delete);
-
-  changes_hna = OLSR_TRUE;
 }
 
 /**
index d505d01..50e0bce 100644 (file)
 #include "ipcalc.h"
 #include "scheduler.h"
 
-#ifdef USE_FPM
-#define hscaling ftofpm(olsr_cnf->hysteresis_param.scaling)
-#define hhigh    ftofpm(olsr_cnf->hysteresis_param.thr_high)
-#define hlow     ftofpm(olsr_cnf->hysteresis_param.thr_low)
-#else
 #define hscaling olsr_cnf->hysteresis_param.scaling
 #define hhigh    olsr_cnf->hysteresis_param.thr_high
 #define hlow     olsr_cnf->hysteresis_param.thr_low
-#endif
 
-#ifdef USE_FPM
-fpm
-olsr_hyst_calc_stability(fpm old_quality)
-{
-  return fpmadd(fpmmul(fpmsub(itofpm(1), hscaling), old_quality), hscaling);
-}
-#else
 float
 olsr_hyst_calc_stability(float old_quality)
 {
   return (((1 - hscaling) * old_quality) + hscaling);
 }
-#endif
 
 
 
-#ifdef USE_FPM
-fpm
-olsr_hyst_calc_instability(fpm old_quality)
-{
-  return fpmmul(fpmsub(itofpm(1), hscaling), old_quality);
-}
-#else
 float
 olsr_hyst_calc_instability(float old_quality)
 {
   return ((1 - hscaling) * old_quality);
 }
-#endif
 
 
 
@@ -198,7 +176,7 @@ update_hysteresis_incoming(union olsr_ip_addr *remote, struct interface *local,
 #endif
       lnk->L_link_quality = olsr_hyst_calc_stability(lnk->L_link_quality);
 #ifdef DEBUG
-      OLSR_PRINTF(3, "HYST[%s]: %s\n", olsr_ip_to_string(&buf, remote), fpmtoa(lnk->L_link_quality));
+      OLSR_PRINTF(3, "HYST[%s]: %f\n", olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
 #endif
 
       /* 
@@ -214,14 +192,10 @@ update_hysteresis_incoming(union olsr_ip_addr *remote, struct interface *local,
            {
              lnk->L_link_quality = olsr_hyst_calc_instability(lnk->L_link_quality);
 #ifdef DEBUG
-             OLSR_PRINTF(5, "HYST[%s] PACKET LOSS! %s\n",
-                         olsr_ip_to_string(&buf, remote), fpmtoa(lnk->L_link_quality));
+             OLSR_PRINTF(5, "HYST[%s] PACKET LOSS! %f\n",
+                         olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
 #endif
-#ifdef USE_FPM
-             if(lnk->L_link_quality < ftofpm(olsr_cnf->hysteresis_param.thr_low))
-#else
              if(lnk->L_link_quality < olsr_cnf->hysteresis_param.thr_low)
-#endif
                break;
 
              lnk->olsr_seqno++;
index 7ce66ab..f4eea6a 100644 (file)
 
 #include "link_set.h"
 
-#ifdef USE_FPM
-fpm
-olsr_hyst_calc_stability(fpm);
-#else
 float
 olsr_hyst_calc_stability
 (float);
-#endif
 
 int
 olsr_process_hysteresis(struct link_entry *);
 
-#ifdef USE_FPM
-fpm
-olsr_hyst_calc_instability(fpm);
-#else
 float
 olsr_hyst_calc_instability(float);
-#endif
 
 void
 olsr_update_hysteresis_hello(struct link_entry *, double);
index 195f865..7705554 100644 (file)
@@ -54,7 +54,7 @@
 #include "lq_route.h"
 #include "net_olsr.h"
 #include "ipcalc.h"
-
+#include "lq_plugin.h"
 
 /* head node for all link sets */
 struct list_node link_entry_head;
@@ -212,11 +212,7 @@ get_best_link_to_neighbor(const union olsr_ip_addr *remote)
   const union olsr_ip_addr *main_addr;
   struct link_entry *walker, *good_link, *backup_link;
   int curr_metric = MAX_IF_METRIC;
-#ifdef USE_FPM
-  fpm curr_lq = itofpm(-1);
-#else
-  float curr_lq = -1.0;
-#endif
+  olsr_linkcost curr_lcost = LINK_COST_BROKEN;
   
   // main address lookup
 
@@ -279,30 +275,21 @@ get_best_link_to_neighbor(const union olsr_ip_addr *remote)
 
     else
     {
-#ifdef USE_FPM
-      fpm tmp_lq;
-#else
-      float tmp_lq;
-#endif
+      olsr_linkcost tmp_lc;
 
-      // calculate the bi-directional link quality - we select the link
-      // with the best link quality
+      // get the link cost
 
-#ifdef USE_FPM
-      tmp_lq = fpmmul(walker->loss_link_quality, walker->neigh_link_quality);
-#else
-      tmp_lq = walker->loss_link_quality * walker->neigh_link_quality;
-#endif
+      tmp_lc = walker->linkcost; 
 
       // is this link better than anything we had before?
              
-      if((tmp_lq > curr_lq) ||
+      if((tmp_lc < curr_lcost) ||
          // use the requested remote interface address as a tie-breaker
-         ((tmp_lq == curr_lq) && ipequal(&walker->local_iface_addr, remote)))
+         ((tmp_lc == curr_lcost) && ipequal(&walker->local_iface_addr, remote)))
       {
         // memorize the link quality
 
-        curr_lq = tmp_lq;
+        curr_lcost = tmp_lc;
 
         // prefer symmetric links over asymmetric links
 
@@ -326,11 +313,7 @@ static void set_loss_link_multiplier(struct link_entry *entry)
   struct interface *inter;
   struct olsr_if *cfg_inter;
   struct olsr_lq_mult *mult;
-#ifdef USE_FPM
-  fpm val = itofpm(-1);
-#else
   float val = -1.0;
-#endif
   union olsr_ip_addr null_addr;
 
   // find the interface for the link
@@ -355,28 +338,15 @@ static void set_loss_link_multiplier(struct link_entry *entry)
     // use the default multiplier only if there isn't any entry that
     // has a matching IP address
 
-#ifdef USE_FPM
-    if ((ipequal(&mult->addr, &null_addr) && val < itofpm(0)) ||
-#else
     if ((ipequal(&mult->addr, &null_addr) && val < 0.0) ||
-#endif
         ipequal(&mult->addr, &entry->neighbor_iface_addr))
-#ifdef USE_FPM
-      val = ftofpm(mult->val);
-#else
       val = mult->val;
-#endif
   }
 
   // if we have not found an entry, then use the default multiplier
 
-#ifdef USE_FPM
-  if (val < itofpm(0))
-    val = itofpm(1);
-#else
   if (val < 0)
     val = 1.0;
-#endif
 
   // store the multiplier
 
@@ -438,18 +408,12 @@ static void
 olsr_expire_link_loss_timer(void *context)
 {
   struct link_entry *link;
-
+  
   link = (struct link_entry *)context;
 
   /* count the lost packet */
   olsr_update_packet_loss_worker(link, OLSR_TRUE);
 
-  /*
-   * memorize that we've counted the packet, so that we do not
-   * count it a second time later.
-   */
-  link->loss_missed_hellos++;
-
   /* next timeout in 1.0 x htime */
   olsr_change_timer(link->link_loss_timer, link->loss_hello_int * MSEC_PER_SEC,
                     OLSR_LINK_LOSS_JITTER, OLSR_TIMER_PERIODIC);
@@ -491,9 +455,9 @@ olsr_expire_link_hello_timer(void *context)
 
   link->L_link_quality = olsr_hyst_calc_instability(link->L_link_quality);
 
-  OLSR_PRINTF(1, "HYST[%s] HELLO timeout %s\n",
+  OLSR_PRINTF(1, "HYST[%s] HELLO timeout %f\n",
               olsr_ip_to_string(&buf, &link->neighbor_iface_addr),
-              etxtoa(link->L_link_quality));
+              link->L_link_quality);
 
   /* Update hello_timeout - NO SLACK THIS TIME */
   olsr_change_timer(link->link_hello_timer, link->last_htime * MSEC_PER_SEC,
@@ -577,9 +541,7 @@ add_link_entry(const union olsr_ip_addr *local,
 
   /* a new tuple is created with... */
 
-  new_link = olsr_malloc(sizeof(struct link_entry), "new link entry");
-
-  memset(new_link, 0 , sizeof(struct link_entry));
+  new_link = olsr_malloc_link_entry("new link entry");
   
   /* copy if_name, if it is defined */
   if (local_if->int_name)
@@ -617,11 +579,7 @@ add_link_entry(const union olsr_ip_addr *local,
       new_link->olsr_seqno_valid = OLSR_FALSE;
     }
 
-#ifdef USE_FPM
-  new_link->L_link_quality = itofpm(0);
-#else
   new_link->L_link_quality = 0.0;
-#endif
 
   if (olsr_cnf->lq_level > 0)
     {
@@ -631,39 +589,10 @@ add_link_entry(const union olsr_ip_addr *local,
                      OLSR_LINK_LOSS_JITTER, OLSR_TIMER_PERIODIC,
                      &olsr_expire_link_loss_timer, new_link, 0);
 
-      new_link->loss_seqno = 0;
-      new_link->loss_seqno_valid = 0;
-      new_link->loss_missed_hellos = 0;
-
-      new_link->lost_packets = 0;
-      new_link->total_packets = 0;
-
-      new_link->loss_index = 0;
-
-      memset(new_link->loss_bitmap, 0, sizeof (new_link->loss_bitmap));
-
       set_loss_link_multiplier(new_link);
     }
 
-#ifdef USE_FPM
-  new_link->loss_link_quality = itofpm(0);
-  new_link->neigh_link_quality = itofpm(0);
-
-  new_link->loss_link_quality2 = itofpm(0);
-  new_link->neigh_link_quality2 = itofpm(0);
-
-  new_link->saved_loss_link_quality = itofpm(0);
-  new_link->saved_neigh_link_quality = itofpm(0);
-#else
-  new_link->loss_link_quality = 0.0;
-  new_link->neigh_link_quality = 0.0;
-
-  new_link->loss_link_quality2 = 0.0;
-  new_link->neigh_link_quality2 = 0.0;
-
-  new_link->saved_loss_link_quality = 0.0;
-  new_link->saved_neigh_link_quality = 0.0;
-#endif
+  new_link->linkcost = LINK_COST_BROKEN;
 
   /* Add to queue */
   list_add_before(&link_entry_head, &new_link->link_list);
@@ -910,156 +839,15 @@ void olsr_print_link_set(void)
   OLSR_FOR_ALL_LINK_ENTRIES(walker) {
 
     struct ipaddr_str buf;
-#ifdef USE_FPM
-    fpm etx;
-
-    if (walker->loss_link_quality < MIN_LINK_QUALITY || walker->neigh_link_quality < MIN_LINK_QUALITY)
-      etx = itofpm(0);
-    else
-      etx = fpmdiv(itofpm(1), fpmmul(walker->loss_link_quality, walker->neigh_link_quality));
-#else
-    float etx;
-
-    if (walker->loss_link_quality < MIN_LINK_QUALITY || walker->neigh_link_quality < MIN_LINK_QUALITY)
-      etx = 0.0;
-    else
-      etx = 1.0 / (walker->loss_link_quality * walker->neigh_link_quality);
-#endif
-
-    OLSR_PRINTF(1, "%-*s  %s  %s  %-3d    %-3d    %s  %s\n",
+    OLSR_PRINTF(1, "%-*s  %5.3f  %-13s %s\n",
                 addrsize, olsr_ip_to_string(&buf, &walker->neighbor_iface_addr),
-                fpmtoa(walker->L_link_quality),
-                fpmtoa(walker->loss_link_quality),
-               walker->lost_packets,
-                walker->total_packets,
-               fpmtoa(walker->neigh_link_quality),
-                etxtoa(etx));
+                walker->L_link_quality,
+                get_link_entry_text(walker),
+                get_linkcost_text(walker->linkcost, OLSR_FALSE));
   } OLSR_FOR_ALL_LINK_ENTRIES_END(walker);
 #endif
 }
 
-void olsr_update_packet_loss_worker(struct link_entry *entry, olsr_bool lost)
-{
-  unsigned char mask = 1 << (entry->loss_index & 7);
-  const int idx = entry->loss_index >> 3;
-#ifdef USE_FPM
-  fpm rel_lq, saved_lq;
-#else
-  double rel_lq, saved_lq;
-#endif
-
-  if (!lost)
-    {
-      // packet not lost
-
-      if ((entry->loss_bitmap[idx] & mask) != 0)
-        {
-          // but the packet that we replace was lost
-          // => decrement packet loss
-
-          entry->loss_bitmap[idx] &= ~mask;
-          entry->lost_packets--;
-        }
-    }
-
-  else
-    {
-      // packet lost
-
-      if ((entry->loss_bitmap[idx] & mask) == 0)
-        {
-          // but the packet that we replace was not lost
-          // => increment packet loss
-
-          entry->loss_bitmap[idx] |= mask;
-          entry->lost_packets++;
-        }
-    }
-
-  // move to the next packet
-
-  entry->loss_index++;
-
-  // wrap around at the end of the packet loss window
-
-  if (entry->loss_index >= olsr_cnf->lq_wsize)
-    entry->loss_index = 0;
-
-  // count the total number of handled packets up to the window size
-
-  if (entry->total_packets < olsr_cnf->lq_wsize)
-    entry->total_packets++;
-
-  // the current reference link quality
-
-  saved_lq = entry->saved_loss_link_quality;
-
-#ifdef USE_FPM
-  if (saved_lq == itofpm(0))
-    saved_lq = itofpm(-1);
-#else
-  if (saved_lq == 0.0)
-    saved_lq = -1.0;
-#endif
-
-  // calculate the new link quality
-  //
-  // start slowly: receive the first packet => link quality = 1 / n
-  //               (n = window size)
-#ifdef USE_FPM
-  entry->loss_link_quality = fpmdiv(
-    itofpm(entry->total_packets - entry->lost_packets),
-    olsr_cnf->lq_wsize < (2 * 4) ? itofpm(olsr_cnf->lq_wsize):
-    fpmidiv(fpmimul(4,fpmadd(fpmmuli(fpmsub(fpmidiv(itofpm(olsr_cnf->lq_wsize),4),
-                                            itofpm(1)),(int)entry->total_packets),
-                             itofpm(olsr_cnf->lq_wsize))),
-            (olsr_32_t)olsr_cnf->lq_wsize));
-#else
-  entry->loss_link_quality =
-    (float)(entry->total_packets - entry->lost_packets) /
-    (float)(olsr_cnf->lq_wsize < (2 * 4) ? olsr_cnf->lq_wsize: 
-    4 * (((float)olsr_cnf->lq_wsize / 4 - 1) * entry->total_packets + olsr_cnf->lq_wsize) / olsr_cnf->lq_wsize);
-#endif
-    
-  // multiply the calculated link quality with the user-specified multiplier
-
-#ifdef USE_FPM
-  entry->loss_link_quality = fpmmul(entry->loss_link_quality, entry->loss_link_multiplier);
-#else
-  entry->loss_link_quality *= entry->loss_link_multiplier;
-#endif
-
-  // if the link quality has changed by more than 10 percent,
-  // print the new link quality table
-
-#ifdef USE_FPM
-  rel_lq = fpmdiv(entry->loss_link_quality, saved_lq);
-#else
-  rel_lq = entry->loss_link_quality / saved_lq;
-#endif
-
-  if (rel_lq > CEIL_LQDIFF || rel_lq < FLOOR_LQDIFF)
-    {
-      entry->saved_loss_link_quality = entry->loss_link_quality;
-
-      if (olsr_cnf->lq_dlimit > 0)
-      {
-        changes_neighborhood = OLSR_TRUE;
-        changes_topology = OLSR_TRUE;
-      }
-
-      else
-        OLSR_PRINTF(3, "Skipping Dijkstra (1)\n");
-
-      // create a new ANSN
-
-      // XXX - we should check whether we actually
-      // announce this neighbour
-
-      signal_link_changes(OLSR_TRUE);
-    }
-}
-
 void olsr_update_packet_loss_hello_int(struct link_entry *entry,
                                        double loss_hello_int)
 {
@@ -1069,61 +857,10 @@ void olsr_update_packet_loss_hello_int(struct link_entry *entry,
   entry->loss_hello_int = loss_hello_int;
 }
 
-void olsr_update_packet_loss(const union olsr_ip_addr *rem,
-                             const struct interface *loc,
-                             olsr_u16_t seqno)
+void olsr_update_packet_loss(struct link_entry *entry)
 {
-  struct link_entry *entry;
-
-  // called for every OLSR packet
-
-  entry = lookup_link_entry(rem, NULL, loc);
-
-  // it's the very first LQ HELLO message - we do not yet have a link
-
-  if (entry == NULL)
-    return;
-    
-  // a) have we seen a packet before, i.e. is the sequence number valid?
-
-  // b) heuristically detect a restart (= sequence number reset)
-  //    of our neighbor
-
-  if (entry->loss_seqno_valid != 0 && 
-      (unsigned short)(seqno - entry->loss_seqno) < 100)
-    {
-      // loop through all lost packets
-
-      while (entry->loss_seqno != seqno)
-        {
-          // have we already considered all lost LQ HELLO messages?
-
-          if (entry->loss_missed_hellos == 0)
-            olsr_update_packet_loss_worker(entry, OLSR_TRUE);
-
-          // if not, then decrement the number of lost LQ HELLOs
-
-          else
-            entry->loss_missed_hellos--;
-
-          entry->loss_seqno++;
-        }
-    }
-
-  // we have received a packet, otherwise this function would not
-  // have been called
-
   olsr_update_packet_loss_worker(entry, OLSR_FALSE);
 
-  // (re-)initialize
-
-  entry->loss_missed_hellos = 0;
-  entry->loss_seqno = seqno + 1;
-
-  // we now have a valid serial number for sure
-
-  entry->loss_seqno_valid = 1;
-
   // timeout for the first lost packet is 1.5 x htime
 
   olsr_set_timer(&entry->link_loss_timer, entry->loss_hello_int * 1500,
@@ -1131,34 +868,6 @@ void olsr_update_packet_loss(const union olsr_ip_addr *rem,
                  &olsr_expire_link_loss_timer, entry, 0);
 }
 
-void olsr_update_dijkstra_link_qualities(void)
-{
-  struct link_entry *walker;
-
-  OLSR_FOR_ALL_LINK_ENTRIES(walker) {
-    walker->loss_link_quality2 = walker->loss_link_quality;
-    walker->neigh_link_quality2 = walker->neigh_link_quality;
-  } OLSR_FOR_ALL_LINK_ENTRIES_END(walker);
-}
-
-#ifdef USE_FPM
-fpm
-#else
-float
-#endif
-olsr_calc_link_etx(const struct link_entry *link)
-{
-  return link->loss_link_quality < MIN_LINK_QUALITY ||
-         link->neigh_link_quality < MIN_LINK_QUALITY
-#ifdef USE_FPM
-             ? itofpm(0)
-             : fpmdiv(itofpm(1), fpmmul(link->loss_link_quality, link->neigh_link_quality));
-#else
-             ? 0.0
-             : 1.0 / (link->loss_link_quality * link->neigh_link_quality);
-#endif
-}
-
 /*
  * Local Variables:
  * c-basic-offset: 2
index 708dd25..a589dbf 100644 (file)
@@ -46,6 +46,7 @@
 #ifndef _LINK_SET_H
 #define _LINK_SET_H
 
+#include "lq_plugin.h"
 #include "packet.h"
 #include "lq_list.h"
 
@@ -67,11 +68,7 @@ struct link_entry
   /*
    *Hysteresis
    */
-#ifdef USE_FPM
-  fpm L_link_quality;
-#else
   float L_link_quality;
-#endif
   int L_link_pending;
   clock_t L_LOST_LINK_time;
   struct timer_entry *link_hello_timer; /* When we should receive a new HELLO */
@@ -82,43 +79,16 @@ struct link_entry
   /*
    * packet loss
    */
-  olsr_u16_t loss_seqno;
-  int loss_seqno_valid;
-  int loss_missed_hellos;
-
   double loss_hello_int;
   struct timer_entry *link_loss_timer;
 
-  unsigned int lost_packets;
-  unsigned int total_packets;
-
-#ifdef USE_FPM
-  fpm loss_link_quality;
-  fpm loss_link_quality2;
-  fpm loss_link_multiplier;
-#else
-  double loss_link_quality;
-  double loss_link_quality2;
-  double loss_link_multiplier;
-#endif
-
-  unsigned int loss_index;
-
-  unsigned char loss_bitmap[16];
-
-#ifdef USE_FPM
-  fpm neigh_link_quality, neigh_link_quality2;
-
-  fpm saved_loss_link_quality;
-  fpm saved_neigh_link_quality;
-#else
-  double neigh_link_quality, neigh_link_quality2;
-
-  double saved_loss_link_quality;
-  double saved_neigh_link_quality;
-#endif
+  float loss_link_multiplier; // user defined multiplies for link quality
+  
+  // cost of this link
+  olsr_linkcost linkcost;
 
   struct list_node link_list; /* double linked list of all link entries */
+  char                  linkquality[0];
 };
 
 /* inline to recast from link_list back to link_entry */
@@ -177,21 +147,11 @@ void
 olsr_update_packet_loss_hello_int(struct link_entry *, double);
 
 void 
-olsr_update_packet_loss(const union olsr_ip_addr *, const struct interface *, olsr_u16_t);
+olsr_update_packet_loss(struct link_entry *entry);
 
 void 
 olsr_print_link_set(void);
 
-void
-olsr_update_dijkstra_link_qualities(void);
-
-#ifdef USE_FPM
-fpm
-#else
-float
-#endif
-olsr_calc_link_etx(const struct link_entry *);
-
 #endif
 
 /*
index b4de652..8423d57 100644 (file)
@@ -44,6 +44,7 @@
 #include "link_set.h"
 #include "lq_mpr.h"
 #include "scheduler.h"
+#include "lq_plugin.h"
 
 void olsr_calculate_lq_mpr(void)
 {
@@ -51,11 +52,7 @@ void olsr_calculate_lq_mpr(void)
   struct neighbor_list_entry *walker;
   int i, k;
   struct neighbor_entry *neigh;
-#ifdef USE_FPM
-  fpm best, best_1hop;
-#else
-  double best, best_1hop;
-#endif
+  olsr_linkcost best, best_1hop;
   olsr_bool mpr_changes = OLSR_FALSE;
 
   OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
@@ -90,11 +87,7 @@ void olsr_calculate_lq_mpr(void)
            neigh2 != &two_hop_neighbortable[i];
            neigh2 = neigh2->next)
         {
-#ifdef USE_FPM
-          best_1hop = itofpm(-1);
-#else
-          best_1hop = -1.0;
-#endif
+          best_1hop = LINK_COST_BROKEN;
 
           // check whether this 2-hop neighbour is also a neighbour
 
@@ -116,18 +109,14 @@ void olsr_calculate_lq_mpr(void)
              if (!lnk)
                continue;
 
-#ifdef USE_FPM
-              best_1hop = fpmmul(lnk->loss_link_quality, lnk->neigh_link_quality);
-#else
-              best_1hop = lnk->loss_link_quality * lnk->neigh_link_quality;
-#endif
+              best_1hop = lnk->linkcost;
 
               // see wether we find a better route via an MPR
 
               for (walker = neigh2->neighbor_2_nblist.next;
                    walker != &neigh2->neighbor_2_nblist;
                    walker = walker->next)
-                if (walker->path_link_quality > best_1hop)
+                if (walker->path_linkcost < best_1hop)
                   break;
 
               // we've reached the end of the list, so we haven't found
@@ -154,27 +143,23 @@ void olsr_calculate_lq_mpr(void)
               // yet selected
 
               neigh = NULL;
-#ifdef USE_FPM
-              best = itofpm(-1);
-#else
-              best = -1.0;
-#endif
+              best = LINK_COST_BROKEN;
 
               for (walker = neigh2->neighbor_2_nblist.next;
                    walker != &neigh2->neighbor_2_nblist;
                    walker = walker->next)
                 if (walker->neighbor->status == SYM &&
                     !walker->neighbor->skip &&
-                    walker->path_link_quality > best)
+                    walker->path_linkcost < best)
                   {
                     neigh = walker->neighbor;
-                    best = walker->path_link_quality;
+                    best = walker->path_linkcost;
                   }
 
               // Found a 1-hop neighbor that we haven't previously selected.
               // Use it as MPR only when the 2-hop path through it is better than
               // any existing 1-hop path.
-              if ((neigh != NULL) && (best > best_1hop))
+              if ((neigh != NULL) && (best < best_1hop))
                 {
                   neigh->is_mpr = OLSR_TRUE;
                   neigh->skip = OLSR_TRUE;
index 148b99d..499b628 100644 (file)
@@ -56,7 +56,7 @@
 #include "olsr.h"
 #include "build_msg.h"
 #include "net_olsr.h"
-
+#include "lq_plugin.h"
 
 olsr_bool lq_tc_pending = OLSR_FALSE;
 
@@ -89,7 +89,7 @@ create_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
   OLSR_FOR_ALL_LINK_ENTRIES(walker) {
 
     // allocate a neighbour entry
-    struct lq_hello_neighbor *neigh = olsr_malloc(sizeof (struct lq_hello_neighbor), "Build LQ_HELLO");
+    struct lq_hello_neighbor *neigh = olsr_malloc_lq_hello_neighbor("Build LQ_HELLO");
 
     // a) this neighbor interface IS NOT visible via the output interface
     if(!ipequal(&walker->local_iface_addr, &outif->ip_addr))
@@ -101,9 +101,7 @@ create_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
       neigh->link_type = lookup_link_status(walker);
 
     // set the entry's link quality
-
-    neigh->link_quality = walker->loss_link_quality;
-    neigh->neigh_link_quality = walker->neigh_link_quality;
+    olsr_copy_hello_lq(neigh, walker);
 
     // set the entry's neighbour type
 
@@ -225,7 +223,7 @@ create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
     }
 
     /* Allocate a neighbour entry. */
-    neigh = olsr_malloc(sizeof (struct tc_mpr_addr), "Build LQ_TC");
+    neigh = olsr_malloc_tc_mpr_addr("Build LQ_TC");
 
     /* Set the entry's main address. */
     neigh->address = walker->neighbor_main_addr;
@@ -234,21 +232,9 @@ create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
     lnk = get_best_link_to_neighbor(&neigh->address);
 
     if (lnk) {
-      neigh->link_quality = lnk->loss_link_quality;
-      neigh->neigh_link_quality = lnk->neigh_link_quality;
+      olsr_copylq_link_entry_2_tc_mpr_addr(neigh, lnk);
     }
 
-    else {
-      OLSR_PRINTF(0, "Error: link_qualtiy undefined");
-#ifdef USE_FPM
-      neigh->link_quality = itofpm(0);
-      neigh->neigh_link_quality = itofpm(0);
-#else
-      neigh->link_quality = 0.0;
-      neigh->neigh_link_quality = 0.0;
-#endif
-    }          
-
     /* Queue the neighbour entry. */
     neigh->next = lq_tc->neigh;
     lq_tc->neigh = neigh;
@@ -456,19 +442,7 @@ serialize_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
               size += olsr_cnf->ipsize;
 
               // add the corresponding link quality
-
-#ifdef USE_FPM
-              buff[size++] = fpmtoi(fpmmuli(neigh->link_quality, 255));
-              buff[size++] = fpmtoi(fpmmuli(neigh->neigh_link_quality, 255));
-#else
-              buff[size++] = (unsigned char)(neigh->link_quality * 255);
-              buff[size++] = (unsigned char)(neigh->neigh_link_quality * 255);
-#endif
-
-              // pad
-
-              buff[size++] = 0;
-              buff[size++] = 0;
+              size += olsr_serialize_hello_lq_pair(&buff[size], neigh);
 
               is_first = OLSR_FALSE;
             }
@@ -576,17 +550,7 @@ serialize_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
       size += olsr_cnf->ipsize;
 
       // add the corresponding link quality
-#ifdef USE_FPM
-      buff[size++] = fpmtoi(fpmmuli(neigh->link_quality, 255));
-      buff[size++] = fpmtoi(fpmmuli(neigh->neigh_link_quality, 255));
-#else
-      buff[size++] = (unsigned char)(neigh->link_quality * 255);
-      buff[size++] = (unsigned char)(neigh->neigh_link_quality * 255);
-#endif
-
-      // pad
-      buff[size++] = 0;
-      buff[size++] = 0;
+      size += olsr_serialize_tc_lq_pair(&buff[size], neigh);
     }
 
   // finalize the OLSR header
index 868c2f3..2b0670f 100644 (file)
@@ -94,15 +94,9 @@ struct lq_hello_neighbor
 {
   olsr_u8_t                link_type;
   olsr_u8_t                neigh_type;
-#ifdef USE_FPM
-  fpm                      link_quality;
-  fpm                      neigh_link_quality;
-#else
-  double                   link_quality;
-  double                   neigh_link_quality;
-#endif
   union olsr_ip_addr       addr;
   struct lq_hello_neighbor *next;
+  char                  linkquality[0];
 };
 
 struct lq_hello_message
@@ -155,11 +149,7 @@ static INLINE void       pkt_get_s32(const olsr_u8_t **p, olsr_32_t *var)
 static INLINE void    pkt_get_double(const olsr_u8_t **p, double *var)             { *var = me_to_double(**p);                       *p += sizeof(olsr_u8_t); }
 static INLINE void pkt_get_ipaddress(const olsr_u8_t **p, union olsr_ip_addr *var) { memcpy(var, *p, olsr_cnf->ipsize);              *p += olsr_cnf->ipsize; }
 static INLINE void pkt_get_prefixlen(const olsr_u8_t **p, olsr_u8_t *var)          { *var = netmask_to_prefix(*p, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
-#ifdef USE_FPM
-static INLINE void        pkt_get_lq(const olsr_u8_t **p, fpm *var)                { *var = fpmidiv(itofpm(**p), 255);               *p += sizeof(olsr_u8_t); }
-#else
-static INLINE void        pkt_get_lq(const olsr_u8_t **p, double *var)             { *var = (const double)**p / 255.0;               *p += sizeof(olsr_u8_t); }
-#endif
+static INLINE void        pkt_get_lq(const olsr_u8_t **p, float *var)              { *var = (const float)**p / 255.0;               *p += sizeof(olsr_u8_t); }
 
 static INLINE void        pkt_ignore_u8(const olsr_u8_t **p) { *p += sizeof(olsr_u8_t); }
 static INLINE void       pkt_ignore_u16(const olsr_u8_t **p) { *p += sizeof(olsr_u16_t); }
@@ -179,7 +169,7 @@ static INLINE void       pkt_put_s32(olsr_u8_t **p, olsr_32_t var)
 static INLINE void    pkt_put_double(olsr_u8_t **p, double var)                    { **p = double_to_me(var);            *p += sizeof(olsr_u8_t); }
 static INLINE void pkt_put_ipaddress(olsr_u8_t **p, const union olsr_ip_addr *var) { memcpy(*p, var, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
 static INLINE void pkt_put_prefixlen(olsr_u8_t **p, olsr_u8_t var)                 { prefix_to_netmask(*p, olsr_cnf->ipsize, var); *p += olsr_cnf->ipsize; }
-static INLINE void        pkt_put_lq(olsr_u8_t **p, double var)                    { **p  = var * 255.0;                 *p += sizeof(olsr_u8_t); }
+static INLINE void        pkt_put_lq(olsr_u8_t **p, float var)                     { **p  = var * 255.0;                 *p += sizeof(olsr_u8_t); }
 
 void olsr_output_lq_hello(void *para);
 
index b30d252..b0d6847 100644 (file)
@@ -64,6 +64,7 @@
 #include "lq_avl.h"
 #include "lq_route.h"
 #include "net_olsr.h"
+#include "lq_plugin.h"
 
 struct timer_entry *spf_backoff_timer = NULL;
 
@@ -79,23 +80,13 @@ struct timer_entry *spf_backoff_timer = NULL;
 static int
 avl_comp_etx (const void *etx1, const void *etx2)
 {       
-#ifdef USE_FPM
-  if (*(const sfpm *)etx1 < *(const sfpm *)etx2) {
+  if (*(const olsr_linkcost *)etx1 < *(const olsr_linkcost *)etx2) {
     return -1;
   }
 
-  if (*(const sfpm *)etx1 > *(const sfpm *)etx2) {
+  if (*(const olsr_linkcost *)etx1 > *(const olsr_linkcost *)etx2) {
     return +1;
   }
-#else
-  if (*(const float *)etx1 < *(const float *)etx2) {
-    return -1;
-  }
-
-  if (*(const float *)etx1 > *(const float *)etx2) {
-    return +1;
-  }
-#endif
 
   return 0;
 }
@@ -112,13 +103,13 @@ olsr_spf_add_cand_tree (struct avl_tree *tree,
 #if !defined(NODEBUG) && defined(DEBUG)
   struct ipaddr_str buf;
 #endif
-  tc->cand_tree_node.key = &tc->path_etx;
+  tc->cand_tree_node.key = &tc->path_cost;
   tc->cand_tree_node.data = tc;
 
 #ifdef DEBUG
-  OLSR_PRINTF(1, "SPF: insert candidate %s, cost %s\n",
+  OLSR_PRINTF(2, "SPF: insert candidate %s, cost %s\n",
               olsr_ip_to_string(&buf, &tc->addr),
-              etxtoa(tc->path_etx));
+              get_linkcost_text(tc->path_cost, OLSR_FALSE));
 #endif
 
   avl_insert(tree, &tc->cand_tree_node, AVL_DUP);
@@ -138,9 +129,9 @@ olsr_spf_del_cand_tree (struct avl_tree *tree,
 #ifndef NODEBUG
   struct ipaddr_str buf;
 #endif
-  OLSR_PRINTF(1, "SPF: delete candidate %s, cost %s\n",
+  OLSR_PRINTF(2, "SPF: delete candidate %s, cost %s\n",
               olsr_ip_to_string(&buf, &tc->addr),
-              etxtoa(tc->path_etx));
+              get_linkcost_text(tc->path_cost, OLSR_FALSE));
 #endif
 
   avl_delete(tree, &tc->cand_tree_node);
@@ -161,9 +152,9 @@ olsr_spf_add_path_list (struct list_node *head, int *path_count,
   tc->path_list_node.data = tc;
 
 #ifdef DEBUG
-  OLSR_PRINTF(1, "SPF: append path %s, cost %s, via %s\n",
+  OLSR_PRINTF(2, "SPF: append path %s, cost %s, via %s\n",
               olsr_ip_to_string(&pathbuf, &tc->addr),
-              etxtoa(tc->path_etx),
+              get_linkcost_text(tc->path_cost, OLSR_FALSE),
               tc->next_hop ? olsr_ip_to_string(
                 &nbuf, &tc->next_hop->neighbor_iface_addr) : "-");
 #endif
@@ -197,19 +188,15 @@ static void
 olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
 {
   struct avl_node *edge_node;
-#ifdef USE_FPM
-  fpm new_etx;
-#else
-  float new_etx;
-#endif
+  olsr_linkcost new_cost;
 
 #ifdef DEBUG
 #ifndef NODEBUG
   struct ipaddr_str buf, nbuf;
 #endif
-  OLSR_PRINTF(1, "SPF: exploring node %s, cost %s\n",
+  OLSR_PRINTF(2, "SPF: exploring node %s, cost %s\n",
               olsr_ip_to_string(&buf, &tc->addr),
-              etxtoa(tc->path_etx));
+              get_linkcost_text(tc->path_cost, OLSR_FALSE));
 #endif
 
   /*
@@ -227,13 +214,13 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
      */
     if (!tc_edge->edge_inv || (tc_edge->flags & OLSR_TC_EDGE_DOWN)) {
 #ifdef DEBUG
-      OLSR_PRINTF(1, "SPF:   ignoring edge %s\n",
+      OLSR_PRINTF(2, "SPF:   ignoring edge %s\n",
                   olsr_ip_to_string(&buf, &tc_edge->T_dest_addr));
       if (tc_edge->flags & OLSR_TC_EDGE_DOWN) {
-        OLSR_PRINTF(1, "SPF:     edge down\n");
+        OLSR_PRINTF(2, "SPF:     edge down\n");
       }
       if (!tc_edge->edge_inv) {
-        OLSR_PRINTF(1, "SPF:     no inverse edge\n");
+        OLSR_PRINTF(2, "SPF:     no inverse edge\n");
       }
 #endif
       continue;
@@ -243,17 +230,12 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
      * total quality of the path through this vertex
      * to the destination of this edge
      */
-#ifdef USE_FPM
-    new_etx = INFINITE_ETX <= tc->path_etx || INFINITE_ETX <= tc_edge->etx
-      ? INFINITE_ETX : fpmadd(tc->path_etx, tc_edge->etx);
-#else
-    new_etx = tc->path_etx + tc_edge->etx;
-#endif
+    new_cost = tc->path_cost + tc_edge->cost;
 
 #ifdef DEBUG
-      OLSR_PRINTF(1, "SPF:   exploring edge %s, cost %s\n",
+      OLSR_PRINTF(2, "SPF:   exploring edge %s, cost %s\n",
                   olsr_ip_to_string(&buf, &tc_edge->T_dest_addr),
-                  etxtoa(new_etx));
+                  get_linkcost_text(new_cost, OLSR_TRUE));
 #endif
 
       /* 
@@ -262,15 +244,15 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
        */
     new_tc = tc_edge->edge_inv->tc;
 
-    if (new_etx < new_tc->path_etx) {
+    if (new_cost < new_tc->path_cost) {
 
       /* if this node has been on the candidate tree delete it */
-      if (new_tc->path_etx != INFINITE_ETX) {
+      if (new_tc->path_cost < ROUTE_COST_BROKEN) {
         olsr_spf_del_cand_tree(cand_tree, new_tc);
       }
 
       /* re-insert on candidate tree with the better metric */
-      new_tc->path_etx = new_etx;
+      new_tc->path_cost = new_cost;
       olsr_spf_add_cand_tree(cand_tree, new_tc);
 
       /* pull-up the next-hop and bump the hop count */
@@ -280,10 +262,9 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
       new_tc->hops = tc->hops + 1;
 
 #ifdef DEBUG
-      OLSR_PRINTF(1, "SPF:   better path to %s, cost %s -> %s, via %s, hops %u\n",
+      OLSR_PRINTF(2, "SPF:   better path to %s, cost %s, via %s, hops %u\n",
                   olsr_ip_to_string(&buf, &new_tc->addr),
-                  etxtoa(new_tc->path_etx),
-                  etxtoa(new_etx),
+                  get_linkcost_text(new_cost, OLSR_TRUE),
                   tc->next_hop ? olsr_ip_to_string(
                     &nbuf, &tc->next_hop->neighbor_iface_addr) : "<none>",
                   new_tc->hops);
@@ -376,7 +357,7 @@ olsr_calculate_routing_table (void *context __attribute__((unused)))
    */
   OLSR_FOR_ALL_TC_ENTRIES(tc) {
     tc->next_hop = NULL;
-    tc->path_etx = INFINITE_ETX;
+    tc->path_cost = ROUTE_COST_BROKEN;
     tc->hops = 0;
   } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 
@@ -384,7 +365,7 @@ olsr_calculate_routing_table (void *context __attribute__((unused)))
    * zero ourselves and add us to the candidate tree.
    */
   olsr_change_myself_tc();
-  tc_myself->path_etx = ZERO_ETX;
+  tc_myself->path_cost = ZERO_ROUTE_COST;
   olsr_spf_add_cand_tree(&cand_tree, tc_myself);
 
   /*
@@ -420,16 +401,12 @@ olsr_calculate_routing_table (void *context __attribute__((unused)))
        */
       if (!tc_edge) {
         tc_edge = olsr_add_tc_edge_entry(tc_myself, &neigh->neighbor_main_addr,
-                                         0, link->vtime,
-                                         link->loss_link_quality2,
-                                         link->neigh_link_quality2);
+                                         0, link->vtime);
       } else {
-
         /*
          * Update LQ and timers, such that the edge does not get deleted.
          */
-        tc_edge->link_quality = link->loss_link_quality2;
-        tc_edge->inverse_link_quality = link->neigh_link_quality2;
+        olsr_copylq_link_entry_2_tc_edge_entry(tc_edge, link);
         olsr_set_tc_edge_timer(tc_edge, link->vtime*1000);
         olsr_calc_tc_edge_entry_etx(tc_edge);
       }
@@ -473,7 +450,7 @@ olsr_calculate_routing_table (void *context __attribute__((unused)))
 #ifndef NODEBUG
         struct ipaddr_str buf;
 #endif
-        OLSR_PRINTF(1, "SPF: %s no next-hop\n", olsr_ip_to_string(&buf, &tc->addr));
+        OLSR_PRINTF(2, "SPF: %s no next-hop\n", olsr_ip_to_string(&buf, &tc->addr));
       }
 #endif
       continue;
index cc3f56f..22377d0 100644 (file)
@@ -404,7 +404,7 @@ main(int argc, char *argv[])
   signal(SIGQUIT, olsr_shutdown);
   signal(SIGILL,  olsr_shutdown);
   signal(SIGABRT, olsr_shutdown);
-  signal(SIGSEGV, olsr_shutdown);
+//  signal(SIGSEGV, olsr_shutdown);
   signal(SIGTERM, olsr_shutdown);
   signal(SIGPIPE, SIG_IGN);
 #endif
index 255145c..9148d35 100644 (file)
@@ -177,7 +177,6 @@ insert_mid_tuple(union olsr_ip_addr *m_addr, struct mid_address *alias, float vt
     {
       /*Create new node*/
       tmp = olsr_malloc(sizeof(struct mid_entry), "MID new alias");
-      memset(tmp, 0, sizeof(struct mid_entry));
 
       tmp->aliases = alias;
       alias->main_entry = tmp;
@@ -274,7 +273,6 @@ insert_mid_alias(union olsr_ip_addr *main_add, const union olsr_ip_addr *alias,
   OLSR_PRINTF(1, "%s\n", olsr_ip_to_string(&buf1, main_add));
 
   adr = olsr_malloc(sizeof(struct mid_address), "Insert MID alias");
-  memset(adr, 0, sizeof(struct mid_address));
 
   adr->alias = *alias;
   adr->next_alias = NULL;
index f62c0ee..7b58fe9 100644 (file)
@@ -154,11 +154,9 @@ olsr_add_mpr_selector(const union olsr_ip_addr *addr, float vtime)
   OLSR_PRINTF(1, "MPRS: adding %s\n", olsr_ip_to_string(&buf, addr));
 
   new_entry = olsr_malloc(sizeof(struct mpr_selector), "Add MPR selector");
-
   /* Fill struct */
   new_entry->MS_main_addr = *addr;
   olsr_set_mpr_sel_timer(new_entry, vtime * MSEC_PER_SEC);
-
   /* Queue */
   QUEUE_ELEM(mprs_list, new_entry);
   /*
index a721020..91b8a52 100644 (file)
@@ -442,7 +442,6 @@ net_output(struct interface *ifp)
   // if we've just transmitted a TC message, let Dijkstra use the current
   // link qualities for the links to our neighbours
 
-  olsr_update_dijkstra_link_qualities();
   lq_tc_pending = OLSR_FALSE;
 
   return retval;
index fb924d5..a8f0967 100644 (file)
@@ -239,9 +239,6 @@ olsr_init_tables(void)
   /* Initialize link set */
   olsr_init_link_set();
 
-  /* Initialize duplicate table */
-  olsr_init_duplicate_table();
-
   /* Initialize neighbor table */
   olsr_init_neighbor_table();
 
@@ -282,9 +279,6 @@ olsr_init_tables(void)
  */
 int
 olsr_forward_message(union olsr_message *m, 
-                    union olsr_ip_addr *originator, 
-                    olsr_u16_t seqno,
-                    struct interface *in_if, 
                     union olsr_ip_addr *from_addr)
 {
   union olsr_ip_addr *src;
@@ -306,14 +300,6 @@ olsr_forward_message(union olsr_message *m,
     if (2 > m->v6.ttl || 255 < (int)m->v6.hopcnt + (int)m->v6.ttl) return 0;
   }
 
-  if(!olsr_check_dup_table_fwd(originator, seqno, &in_if->ip_addr))
-    {
-#ifdef DEBUG
-      OLSR_PRINTF(3, "Message already forwarded!\n");
-#endif
-      return 0;
-    }
-
   /* Lookup sender address */
   src = mid_lookup_main_addr(from_addr);
   if(!src)
@@ -326,10 +312,6 @@ olsr_forward_message(union olsr_message *m,
   if(neighbor->status != SYM)
     return 0;
 
-  /* Update duplicate table interface */
-  olsr_update_dup_entry(originator, seqno, &in_if->ip_addr);
-
-  
   /* Check MPR */
   if(olsr_lookup_mprs_set(src) == NULL)
     {
@@ -356,9 +338,6 @@ olsr_forward_message(union olsr_message *m,
       m->v6.ttl--; 
     }
 
-  /* Update dup forwarded */
-  olsr_set_dup_forward(originator, seqno);
-
   /* Update packet data */
   msgsize = ntohs(m->v4.olsr_msgsize);
 
index 8f50a75..46856d9 100644 (file)
@@ -64,9 +64,6 @@ get_msg_seqno(void);
 
 int
 olsr_forward_message(union olsr_message *, 
-                    union olsr_ip_addr *, 
-                    olsr_u16_t, 
-                    struct interface *, 
                     union olsr_ip_addr *);
 
 void
index f6894fc..691ad70 100644 (file)
@@ -98,4 +98,6 @@ struct olsr_ip_prefix {
   olsr_u8_t prefix_len;
 };
 
+typedef olsr_u32_t olsr_linkcost;
+
 #endif
index 5ac3517..24bb1cb 100644 (file)
@@ -48,6 +48,7 @@
 #include "neighbor_table.h"
 #include "build_msg.h"
 #include "net_olsr.h"
+#include "lq_plugin.h"
 
 static olsr_bool sending_tc = OLSR_FALSE;
 
@@ -128,7 +129,7 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
       continue;
     }
 
-    message_neighbor = olsr_malloc(sizeof(struct hello_neighbor), "Build HELLO");
+    message_neighbor = olsr_malloc_hello_neighbor("Build HELLO");
       
     /* Find the link status */
     message_neighbor->link = lnk;
@@ -219,7 +220,7 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
       continue;
     }
            
-    message_neighbor = olsr_malloc(sizeof(struct hello_neighbor), "Build HELLO 2");
+         message_neighbor = olsr_malloc_hello_neighbor("Build HELLO 2");
            
     message_neighbor->link = UNSPEC_LINK;
            
@@ -339,9 +340,9 @@ olsr_build_tc_packet(struct tc_message *message)
     switch (olsr_cnf->tc_redundancy) {
     case(2):
     {
-      /* 2 = Add all neighbors */
-      //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
-      message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC");
+               /* 2 = Add all neighbors */
+               //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
+                 message_mpr = olsr_malloc_tc_mpr_addr("Build TC");
                
       message_mpr->address = entry->neighbor_main_addr;
       message_mpr->next = message->multipoint_relay_selector_address;
@@ -355,7 +356,7 @@ olsr_build_tc_packet(struct tc_message *message)
       if ((entry->is_mpr) ||
           (olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL)) {
         //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
-        message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC 2");
+        message_mpr = olsr_malloc_tc_mpr_addr("Build TC 2");
                    
         message_mpr->address = entry->neighbor_main_addr;
         message_mpr->next = message->multipoint_relay_selector_address;
@@ -369,7 +370,7 @@ olsr_build_tc_packet(struct tc_message *message)
       /* 0 = Add only MPR selectors(default) */
       if (olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL) {
         //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
-        message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC 3");
+        message_mpr = olsr_malloc_tc_mpr_addr("Build TC 3");
                    
         message_mpr->address = entry->neighbor_main_addr;
         message_mpr->next = message->multipoint_relay_selector_address;
index c8d5cc0..9cce21b 100644 (file)
 
 #include "olsr_protocol.h"
 #include "interfaces.h"
-#include "fpm.h"
 
 struct hello_neighbor
 {
   olsr_u8_t             status;
   olsr_u8_t             link;
-#ifdef USE_FPM
-  fpm                   link_quality;
-  fpm                   neigh_link_quality;
-#else
-  double                link_quality;
-  double                neigh_link_quality;
-#endif
   union olsr_ip_addr    main_address;
   union olsr_ip_addr    address;
   struct hello_neighbor *next;
+  olsr_linkcost         cost;
+  char                  linkquality[0];
 };
 
 struct hello_message
@@ -76,15 +70,9 @@ struct hello_message
 
 struct tc_mpr_addr
 {
-#ifdef USE_FPM
-  fpm                link_quality;
-  fpm                neigh_link_quality;
-#else
-  double             link_quality;
-  double             neigh_link_quality;
-#endif
   union olsr_ip_addr address;
   struct tc_mpr_addr *next;
+  char                  linkquality[0];
 };
 
 struct tc_message
index fdc69ba..16785e8 100644 (file)
@@ -277,12 +277,6 @@ parse_packet(struct olsr *olsr, int size, struct interface *in_if, union olsr_ip
        }
     }
 
-  if (olsr_cnf->lq_level > 0)
-    {
-      olsr_update_packet_loss(from_addr, in_if,
-                              ntohs(olsr->olsr_seqno));
-    }
-  
   for ( ; count > 0; m = (union olsr_message *)((char *)m + (msgsize)))
     {
 
@@ -372,6 +366,19 @@ parse_packet(struct olsr *olsr, int size, struct interface *in_if, union olsr_ip
           continue;
         }
 
+      /* check for message duplicates */
+      if (olsr_cnf->ip_version == AF_INET) {
+        /* IPv4 */
+        if (olsr_shall_process_message(&m->v4.originator, ntohs(m->v4.seqno)) == 0) {
+          continue;
+        }
+      }
+      else {
+        /* IPv6 */
+        if (olsr_shall_process_message(&m->v6.originator, ntohs(m->v6.seqno)) == 0) {
+          continue;
+        }
+      }
 
       //printf("MESSAGETYPE: %d\n", m->v4.olsr_msgtype);
 
@@ -410,11 +417,7 @@ parse_packet(struct olsr *olsr, int size, struct interface *in_if, union olsr_ip
          if(!ipequal(&unkpacket.originator, &olsr_cnf->main_addr))
            {         
              /* Forward */
-             olsr_forward_message(m, 
-                                  &unkpacket.originator, 
-                                  unkpacket.seqno, 
-                                  in_if,
-                                  from_addr);
+             olsr_forward_message(m, from_addr);
            }
 
           /* Cancel loop here, otherwise olsrd just hangs forever at this point */
index c66818e..7c7f860 100644 (file)
@@ -53,6 +53,7 @@
 #include "rebuild_packet.h"
 #include "scheduler.h"
 #include "net_olsr.h"
+#include "lq_plugin.h"
 
 #include <stddef.h>
 
@@ -140,11 +141,7 @@ process_message_neighbors(struct neighbor_entry *neighbor, const struct hello_me
 
                       if (walker->neighbor == neighbor)
                         {
-#ifdef USE_FPM
-                          walker->path_link_quality = itofpm(0);
-#else
-                          walker->path_link_quality = 0.0;
-#endif
+                          walker->path_linkcost = LINK_COST_BROKEN;
                         }
                     }
                 }
@@ -194,16 +191,20 @@ process_message_neighbors(struct neighbor_entry *neighbor, const struct hello_me
         }
     }
 
-  // Separate, second and third pass for link quality OLSR
+  // Separate, second pass for link quality OLSR
 
   if (olsr_cnf->lq_level > 0)
     {
+         olsr_linkcost first_hop_pathcost;
       struct link_entry *lnk =
         get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
 
       if(!lnk)
        return;
 
+      // calculate first hop path quality
+      first_hop_pathcost = lnk->linkcost;
+      
       // Second pass for link quality OLSR: calculate the best 2-hop
       // path costs to all the 2-hop neighbors indicated in the
       // HELLO message. Since the same 2-hop neighbor may be listed
@@ -243,138 +244,39 @@ process_message_neighbors(struct neighbor_entry *neighbor, const struct hello_me
 
                   if (walker->neighbor == neighbor)
                     {
-#ifdef USE_FPM
-                      fpm new_second_hop_link_quality, new_path_link_quality;
-#else
-                      double new_second_hop_link_quality, new_path_link_quality;
-#endif
-
-                      // path link quality = link quality between us
-                      // and our one-hop neighbor x link quality between
-                      // our one-hop neighbor and the two-hop neighbor
-
-                      // let's compare this to ETX:
-
-                      // 1 / LQ1 + 1 / LQ2 < 1 / LQ3 + 1 / LQ4 <=>
-                      // LQ1 * LQ2 > LQ3 * LQ4
+                      olsr_linkcost new_second_hop_linkcost, new_path_linkcost;
 
-                      // so comparing path link quality values with ">" is
-                      // equivalent to comparing ETX values with "<"
-
-                      // the link quality between the 1-hop neighbour and the
+                      // the link cost between the 1-hop neighbour and the
                       // 2-hop neighbour
 
-#ifdef USE_FPM
-                      new_second_hop_link_quality = 
-                        fpmmul(message_neighbors->link_quality,
-                               message_neighbors->neigh_link_quality);
-#else
-                      new_second_hop_link_quality = 
-                        message_neighbors->link_quality *
-                        message_neighbors->neigh_link_quality;
-#endif
+                      new_second_hop_linkcost = message_neighbors->cost;
 
-                      // the total quality for the route
+                      // the total cost for the route
                       // "us --- 1-hop --- 2-hop"
 
-#ifdef USE_FPM
-                      new_path_link_quality =
-                        fpmmul(new_second_hop_link_quality,
-                        fpmmul(lnk->loss_link_quality, lnk->neigh_link_quality));
-#else
-                      new_path_link_quality =
-                        new_second_hop_link_quality *
-                        lnk->loss_link_quality * lnk->neigh_link_quality;
-#endif
+                      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_link_quality > walker->path_link_quality)
-                        {
-                          walker->second_hop_link_quality = new_second_hop_link_quality;
-                          walker->path_link_quality = new_path_link_quality;
-                        }
-                    }
-                }
-            }
-        }
-
-      // Third pass for link quality OLSR: check if the 2-hop path qualities have
-      // actually changed. If so, signal this through the 'changes_neighborhood'
-      // and 'changes_topology' booleans. Keep a 'saved_path_link_quality' for
-      // later reference.
-      for(message_neighbors = message->neighbors;
-          message_neighbors != NULL;
-          message_neighbors = message_neighbors->next)
-        {
-          if(if_ifwithaddr(&message_neighbors->address) != NULL)
-            continue;
-
-          if(((message_neighbors->status == SYM_NEIGH) ||
-              (message_neighbors->status == MPR_NEIGH)))
-            {
-              struct neighbor_list_entry *walker;
-              struct neighbor_2_entry *two_hop_neighbor;
-              struct neighbor_2_list_entry *two_hop_neighbor_yet =
-                olsr_lookup_my_neighbors(neighbor, &message_neighbors->address);
-
-              if(!two_hop_neighbor_yet)
-                continue;
-
-              two_hop_neighbor = two_hop_neighbor_yet->neighbor_2;
-
-              // loop through the one-hop neighbors that see this
-              // 'two_hop_neighbor'
-
-              for (walker = two_hop_neighbor->neighbor_2_nblist.next;
-                   walker != &two_hop_neighbor->neighbor_2_nblist;
-                   walker = walker->next)
-                {
-                  // have we found the one-hop neighbor that sent the
-                  // HELLO message that we're current processing?
-
-                  if (walker->neighbor == neighbor)
-                    {
-#ifdef USE_FPM
-                      fpm saved_lq, rel_lq;
-#else
-                      double saved_lq, rel_lq;
-#endif
-
-                      // saved previous total link quality
-
-                      saved_lq = walker->saved_path_link_quality;
-
-#ifdef USE_FPM
-                      if (saved_lq == itofpm(0))
-                        saved_lq = itofpm(-1);
-#else
-                      if (saved_lq == 0.0)
-                        saved_lq = -1.0;
-#endif
-
-                      // if the link cost has changed by more than 10
-                      // percent, signal
-
-#ifdef USE_FPM
-                      rel_lq = fpmdiv(walker->path_link_quality, saved_lq);
-#else
-                      rel_lq = walker->path_link_quality / saved_lq;
-#endif
-
-                      if (rel_lq > CEIL_LQDIFF || rel_lq < FLOOR_LQDIFF)
+                      if (new_path_linkcost < walker->path_linkcost)
                         {
-                          walker->saved_path_link_quality =
-                            walker->path_link_quality;
-
-                          if (olsr_cnf->lq_dlimit > 0)
-                          {
-                            changes_neighborhood = OLSR_TRUE;
-                            changes_topology = OLSR_TRUE;
-                          }
-
-                          else
-                            OLSR_PRINTF(3, "Skipping Dijkstra (3)\n");
+                          walker->second_hop_linkcost = new_second_hop_linkcost;
+                          walker->path_linkcost = new_path_linkcost;
+                          
+                          if (olsr_is_relevant_costchange(new_path_linkcost, walker->saved_path_linkcost))
+                            {
+                              walker->saved_path_linkcost = new_path_linkcost;
+
+                              if (olsr_cnf->lq_dlimit > 0)
+                              {
+                                changes_neighborhood = OLSR_TRUE;
+                                changes_topology = OLSR_TRUE;
+                              }
+
+                              else
+                                OLSR_PRINTF(3, "Skipping Dijkstra (3)\n");
+                            }
                         }
                     }
                 }
@@ -398,15 +300,9 @@ linking_this_2_entries(struct neighbor_entry *neighbor, struct neighbor_2_entry
 
   list_of_1_neighbors->neighbor = neighbor;
 
-#ifdef USE_FPM
-  list_of_1_neighbors->path_link_quality = itofpm(0);
-  list_of_1_neighbors->saved_path_link_quality = itofpm(0);
-  list_of_1_neighbors->second_hop_link_quality = itofpm(0);
-#else
-  list_of_1_neighbors->path_link_quality = 0.0;
-  list_of_1_neighbors->saved_path_link_quality = 0.0;
-  list_of_1_neighbors->second_hop_link_quality = 0.0;
-#endif
+  list_of_1_neighbors->path_linkcost = LINK_COST_BROKEN;
+  list_of_1_neighbors->saved_path_linkcost = LINK_COST_BROKEN;
+  list_of_1_neighbors->second_hop_linkcost = LINK_COST_BROKEN;
 
   /* Queue */
   two_hop_neighbor->neighbor_2_nblist.next->prev = list_of_1_neighbors;
@@ -490,13 +386,11 @@ static int deserialize_hello(struct hello_message *hello, const void *ser) {
                
                curr = (const unsigned char *)(info_head + 1);
                while (curr < limit2) {
-                       struct hello_neighbor *neigh = olsr_malloc(sizeof(struct hello_neighbor), "HELLO deserialization");
+                       struct hello_neighbor *neigh = olsr_malloc_hello_neighbor("HELLO deserialization");
                        pkt_get_ipaddress(&curr, &neigh->address);
                        
                        if (type == LQ_HELLO_MESSAGE) {
-                               pkt_get_lq(&curr, &neigh->link_quality);
-                               pkt_get_lq(&curr, &neigh->neigh_link_quality);
-                               pkt_ignore_u16(&curr);
+                               olsr_deserialize_hello_lq_pair(&curr, neigh);
                        }
                        neigh->link = EXTRACT_LINK(info_head->link_code);
                        neigh->status = EXTRACT_STATUS(info_head->link_code);
@@ -555,77 +449,21 @@ olsr_hello_tap(struct hello_message *message,
 
   if (olsr_cnf->lq_level > 0)
     {
-#ifdef USE_FPM
-      fpm saved_lq;
-      fpm rel_lq;
-#else
-      double saved_lq;
-      double rel_lq;
-#endif
       struct hello_neighbor *walker;
       // just in case our neighbor has changed its HELLO interval
       olsr_update_packet_loss_hello_int(lnk, message->htime);
 
       // find the input interface in the list of neighbor interfaces
-
       for (walker = message->neighbors; walker != NULL; walker = walker->next)
         if (ipequal(&walker->address, &in_if->ip_addr))
           break;
 
-      // the current reference link quality
-
-      saved_lq = lnk->saved_neigh_link_quality;
-
-#ifdef USE_FPM
-      if (saved_lq == itofpm(0))
-        saved_lq = itofpm(-1);
-#else
-      if (saved_lq == 0.0)
-        saved_lq = -1.0;
-#endif
-
       // memorize our neighbour's idea of the link quality, so that we
       // know the link quality in both directions
+      olsr_memorize_foreign_hello_lq(lnk, walker);
 
-      if (walker != NULL)
-        lnk->neigh_link_quality = walker->link_quality;
-
-      else
-#ifdef USE_FPM
-        lnk->neigh_link_quality = itofpm(0);
-#else
-        lnk->neigh_link_quality = 0.0;
-#endif
-
-      // if the link quality has changed by more than 10 percent,
-      // print the new link quality table
-
-#ifdef USE_FPM
-      rel_lq = fpmdiv(lnk->neigh_link_quality, saved_lq);
-#else
-      rel_lq = lnk->neigh_link_quality / saved_lq;
-#endif
-
-      if (rel_lq > CEIL_LQDIFF || rel_lq < FLOOR_LQDIFF)
-        {
-          lnk->saved_neigh_link_quality = lnk->neigh_link_quality;
-
-          if (olsr_cnf->lq_dlimit > 0)
-          {
-            changes_neighborhood = OLSR_TRUE;
-            changes_topology = OLSR_TRUE;
-          }
-
-          else
-            OLSR_PRINTF(3, "Skipping Dijkstra (2)\n");
-
-          // create a new ANSN
-
-          // XXX - we should check whether we actually
-          // announce this neighbour
-
-         signal_link_changes(OLSR_TRUE);
-        }
+      // update packet loss for link quality calculation
+      olsr_update_packet_loss(lnk);
     }
   
   neighbor = lnk->neighbor;
@@ -705,9 +543,6 @@ olsr_process_received_mid(union olsr_message *m,
     return;
   }
 
-  if (olsr_check_dup_table_proc(&message.mid_origaddr, 
-                                message.mid_seqno)) {
-
 #ifdef DEBUG
     OLSR_PRINTF(5, "Processing MID from %s...\n", olsr_ip_to_string(&buf, &message.mid_origaddr));
 #endif
@@ -744,13 +579,8 @@ olsr_process_received_mid(union olsr_message *m,
     } 
   
     olsr_prune_aliases(&message.mid_origaddr, message.mid_addr);
-  }
 
-  olsr_forward_message(m, 
-                      &message.mid_origaddr, 
-                      message.mid_seqno, 
-                      in_if,
-                      from_addr);
+  olsr_forward_message(m, from_addr);
   olsr_free_mid_packet(&message);
 }
 
@@ -826,7 +656,6 @@ olsr_process_received_hna(union olsr_message *m,
   /* seqno */
   pkt_get_u16(&curr, &packet_seq_number);
 
-  if (olsr_check_dup_table_proc(&originator, packet_seq_number)) {
     /*
      *      If the sender interface (NB: not originator) of this message
      *      is not in the symmetric 1-hop neighborhood of this node, the
@@ -851,20 +680,17 @@ olsr_process_received_hna(union olsr_message *m,
       if (entry == NULL) {
         /* only update if it's not from us */
         olsr_update_hna_entry(&originator, &net, prefixlen, vtime);
+      }
+    }
 #else
     while (hna_tmp) {
       /* Don't add an HNA entry that we are advertising ourselves. */
       if (!ip_prefix_list_find(olsr_cnf->hna_entries, &hna_tmp->net, hna_tmp->prefixlen)) {
         olsr_update_hna_entry(&message.originator, &hna_tmp->net, hna_tmp->prefixlen, message.vtime);
-#endif
       }
     }
-  }
-  olsr_forward_message(m, 
-                       &originator, 
-                       packet_seq_number, 
-                       in_if,
-                       from_addr);
+#endif
+  olsr_forward_message(m, from_addr);
 }
 
 /*
index 86250ab..e720d09 100644 (file)
@@ -207,7 +207,7 @@ olsr_update_rt_path(struct rt_path *rtp, struct tc_entry *tc,
 
   /* metric/etx */
   rtp->rtp_metric.hops = tc->hops;
-  rtp->rtp_metric.etx = tc->path_etx;
+  rtp->rtp_metric.cost = tc->path_cost;
 }
 
 /**
@@ -286,7 +286,7 @@ olsr_insert_rt_path(struct rt_path *rtp, struct tc_entry *tc,
   /*
    * no unreachable routes please.
    */
-  if (tc->path_etx >= INFINITE_ETX) {
+  if (tc->path_cost == ROUTE_COST_BROKEN) {
     return;
   }
 
@@ -426,17 +426,10 @@ olsr_get_nh(const struct rt_entry *rt)
 static olsr_bool
 olsr_cmp_rtp(const struct rt_path *rtp1, const struct rt_path *rtp2, const struct rt_path *inetgw)
 {
-#ifdef USE_FPM
-    fpm etx1 = rtp1->rtp_metric.etx;
-    fpm etx2 = rtp2->rtp_metric.etx;
-    if (inetgw == rtp1) etx1 = fpmmul(etx1, ftofpm(olsr_cnf->lq_nat_thresh));
-    if (inetgw == rtp2) etx2 = fpmmul(etx2, ftofpm(olsr_cnf->lq_nat_thresh));
-#else
-    float etx1 = rtp1->rtp_metric.etx;
-    float etx2 = rtp2->rtp_metric.etx;
+    olsr_linkcost etx1 = rtp1->rtp_metric.cost;
+    olsr_linkcost etx2 = rtp2->rtp_metric.cost;
     if (inetgw == rtp1) etx1 *= olsr_cnf->lq_nat_thresh;
     if (inetgw == rtp2) etx2 *= olsr_cnf->lq_nat_thresh;
-#endif
 
     /* etx comes first */
     if (etx1 < etx2) {
@@ -654,12 +647,12 @@ olsr_rtp_to_string(const struct rt_path *rtp)
 
   snprintf(buff, sizeof(buff),
            "%s/%u from %s via %s, "
-           "etx %s, metric %u, v %u",
+           "cost %s, metric %u, v %u",
            olsr_ip_to_string(&prefixstr, &rt->rt_dst.prefix),
            rt->rt_dst.prefix_len,
            olsr_ip_to_string(&origstr, &rtp->rtp_originator),
            olsr_ip_to_string(&gwstr, &rtp->rtp_nexthop.gateway),
-           etxtoa(rtp->rtp_metric.etx),
+           get_linkcost_text(rtp->rtp_metric.cost, OLSR_TRUE),
            rtp->rtp_metric.hops,
            rtp->rtp_version);
 
@@ -698,9 +691,9 @@ olsr_print_routing_table(const struct avl_tree *tree)
          rtp_tree_node != NULL;
          rtp_tree_node = avl_walk_next_c(rtp_tree_node)) {
       const struct rt_path * const rtp = rtp_tree_node->data;
-      OLSR_PRINTF(6, "\tfrom %s, etx %s, metric %u, via %s, %s, v %u\n",
+      OLSR_PRINTF(6, "\tfrom %s, cost %s, metric %u, via %s, %s, v %u\n",
              olsr_ip_to_string(&origstr, &rtp->rtp_originator),
-             etxtoa(rtp->rtp_metric.etx),
+             get_linkcost_text(rtp->rtp_metric.cost, OLSR_TRUE),
              rtp->rtp_metric.hops,
              olsr_ip_to_string(&gwstr, &rtp->rtp_nexthop.gateway),
              if_ifwithindex_name(rt->rt_nexthop.iif_index),
index 06b7c71..1430ec3 100644 (file)
 /* a composite metric is used for path selection */
 struct rt_metric
 {
-#ifdef USE_FPM
-  fpm                   etx;
-#else
-  float                 etx;
-#endif
+  olsr_linkcost       cost;
   olsr_u32_t           hops;
 };
 
index 98dc415..0359362 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
+ * Copyright (c) 2004, Andreas Tnnesen(andreto@olsr.org)
  * Timer rewrite (c) 2008, Hannes Gredler (hannes@gredler.at)
  * All rights reserved.
  *
@@ -359,7 +359,7 @@ olsr_walk_timers(clock_t *last_run)
       /* Ready to fire ? */
       if (TIMED_OUT(timer->timer_clock)) {
 
-        olsr_printf(3, "TIMER: fire timer %p, ctx %p, "
+        olsr_printf(10, "TIMER: fire timer %p, ctx %p, "
                     "cookie %u at clocktick %u\n",
                     timer, timer->timer_cb_context, timer->timer_cookie,
                     (unsigned int)(*last_run));
@@ -410,7 +410,7 @@ olsr_walk_timers(clock_t *last_run)
   }
 
 #ifdef DEBUG
-  olsr_printf(3, "TIMER: processed %4u/%u clockwheel slots, "
+  olsr_printf(10, "TIMER: processed %4u/%u clockwheel slots, "
               "timers walked %4u/%u, timers fired %u\n",
               wheel_slot_walks, TIMER_WHEEL_SLOTS,
               total_timers_walked, timers_running, total_timers_fired);
@@ -566,7 +566,7 @@ olsr_start_timer(unsigned int rel_time, olsr_u8_t jitter_pct,
   timers_running++;
 
 #ifdef DEBUG
-  OLSR_PRINTF(3, "TIMER: start timer %p firing in %s, ctx %p\n",
+  OLSR_PRINTF(10, "TIMER: start timer %p firing in %s, ctx %p\n",
               timer, olsr_clock_string(timer->timer_clock), context);
 #endif
 
@@ -604,7 +604,7 @@ olsr_stop_timer(struct timer_entry *timer)
   }
 
 #ifdef DEBUG
-  OLSR_PRINTF(3, "TIMER: stop timer %p firing in %s, ctx %p\n",
+  OLSR_PRINTF(10, "TIMER: stop timer %p firing in %s, ctx %p\n",
               timer, olsr_clock_string(timer->timer_clock),
               timer->timer_cb_context);
 #endif
@@ -661,7 +661,7 @@ olsr_change_timer(struct timer_entry *timer, unsigned int rel_time,
                   &timer->timer_list);
 
 #ifdef DEBUG
-  OLSR_PRINTF(3, "TIMER: change timer %p, firing to %s, ctx %p\n",
+  OLSR_PRINTF(10, "TIMER: change timer %p, firing to %s, ctx %p\n",
               timer,
               olsr_clock_string(timer->timer_clock),
               timer->timer_cb_context);
index c15cc1a..f21d5cf 100644 (file)
@@ -49,6 +49,7 @@
 #include "lq_avl.h"
 #include "lq_packet.h"
 #include "net_olsr.h"
+#include "lq_plugin.h"
 
 #include <assert.h>
 
@@ -286,12 +287,11 @@ olsr_tc_edge_to_string(struct tc_edge_entry *tc_edge)
   struct tc_entry *tc = tc_edge->tc;
 
   snprintf(buf, sizeof(buf),
-           "%s > %s, lq %s, inv-lq %s, etx %s",
+           "%s > %s, cost (%6s) %s",
            olsr_ip_to_string(&addrbuf, &tc->addr),
            olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr),
-           fpmtoa(tc_edge->link_quality),
-           fpmtoa(tc_edge->inverse_link_quality),
-           etxtoa(tc_edge->etx));
+           get_tc_edge_entry_text(tc_edge),
+           get_linkcost_text(tc_edge->cost, OLSR_FALSE));
 
   return buf;
 }
@@ -327,28 +327,24 @@ olsr_set_tc_edge_timer(struct tc_edge_entry *tc_edge, unsigned int rel_timer)
  * If the edge does not have a minimum acceptable link quality
  * set the etx cost to infinity such that it gets ignored during
  * SPF calculation.
+ * 
+ * @return 1 if the change of the etx value was relevant
  */
-void
+olsr_bool
 olsr_calc_tc_edge_entry_etx(struct tc_edge_entry *tc_edge)
 {
-
+  olsr_linkcost old;
   /*
    * Some sanity check before recalculating the etx.
    */
   if (olsr_cnf->lq_level < 1) {
-    return;
-  }
-
-  if (tc_edge->link_quality < MIN_LINK_QUALITY ||
-      tc_edge->inverse_link_quality < MIN_LINK_QUALITY) {
-    tc_edge->etx = INFINITE_ETX;
-  } else {
-#ifdef USE_FPM
-    tc_edge->etx = fpmdiv(itofpm(1), fpmmul(tc_edge->link_quality, tc_edge->inverse_link_quality));
-#else
-    tc_edge->etx = 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);
-#endif
+    return 0;
   }
+  
+  old = tc_edge->cost;
+  tc_edge->cost = olsr_calc_tc_cost(tc_edge);
+  
+  return olsr_is_relevant_costchange(old, tc_edge->cost); 
 }
 
 /**
@@ -359,13 +355,7 @@ olsr_calc_tc_edge_entry_etx(struct tc_edge_entry *tc_edge)
  */
 struct tc_edge_entry *
 olsr_add_tc_edge_entry(struct tc_entry *tc, union olsr_ip_addr *addr,
-                       olsr_u16_t ansn, unsigned int vtime,
-#ifdef USE_FPM
-                       fpm link_quality, fpm neigh_link_quality
-#else
-                       float link_quality, float neigh_link_quality
-#endif
-                       )
+                       olsr_u16_t ansn, unsigned int vtime)
 {
 #if !defined(NODEBUG) && defined(DEBUG)
   struct ipaddr_str buf;
@@ -373,11 +363,10 @@ olsr_add_tc_edge_entry(struct tc_entry *tc, union olsr_ip_addr *addr,
   struct tc_entry *tc_neighbor;
   struct tc_edge_entry *tc_edge, *tc_edge_inv;
 
-  tc_edge = olsr_malloc(sizeof(struct tc_edge_entry), "add TC edge");
+  tc_edge = olsr_malloc_tc_edge_entry("add TC edge");
   if (!tc_edge) {
     return NULL;
   }
-  memset(tc_edge, 0, sizeof(struct tc_edge_entry));
 
   /* Fill entry */
   tc_edge->T_dest_addr = *addr;
@@ -385,25 +374,7 @@ olsr_add_tc_edge_entry(struct tc_entry *tc, union olsr_ip_addr *addr,
   tc_edge->T_seq = ansn;
   tc_edge->edge_node.data = tc_edge;
   tc_edge->edge_node.key = &tc_edge->T_dest_addr;
-
-  if (olsr_cnf->lq_level > 0) {
-    tc_edge->link_quality = neigh_link_quality;
-    tc_edge->inverse_link_quality = link_quality;
-  } else {
-
-    /*
-     * Set the link quality to 1.0 to mimikry a hopcount alike
-     * behaviour for nodes not supporting the LQ extensions.
-     */
-#ifdef USE_FPM
-    tc_edge->link_quality = itofpm(1);
-    tc_edge->inverse_link_quality = itofpm(1);
-#else
-    tc_edge->link_quality = 1.0;
-    tc_edge->inverse_link_quality = 1.0;
-#endif
-  }
-
+  
   /*
    * Insert into the edge tree.
    */
@@ -543,48 +514,6 @@ olsr_delete_outdated_tc_edges(struct tc_entry *tc, olsr_u16_t ansn)
   return retval;
 }
 
-/*
- * Determine if a etx change was more than 10%
- * Need to know this for triggering a SPF calculation.
- */
-#ifdef USE_FPM
-static olsr_bool
-olsr_etx_significant_change(fpm etx1, fpm etx2)
-{
-  fpm rel_lq;
-
-  if (etx1 == ZERO_ETX || etx2 == ZERO_ETX) {
-    return OLSR_TRUE;
-  }
-
-  rel_lq = fpmdiv(etx1, etx2);
-
-  if (rel_lq > CEIL_LQDIFF || rel_lq < FLOOR_LQDIFF) {
-    return OLSR_TRUE;
-  }
-
-  return OLSR_FALSE;
-}
-#else
-static olsr_bool
-olsr_etx_significant_change(float etx1, float etx2)
-{
-  float rel_lq;
-
-  if (etx1 == ZERO_ETX || etx2 == ZERO_ETX) {
-    return OLSR_TRUE;
-  }
-
-  rel_lq = etx1 / etx2;
-
-  if (rel_lq > CEIL_LQDIFF || rel_lq < FLOOR_LQDIFF) {
-    return OLSR_TRUE;
-  }
-
-  return OLSR_FALSE;
-}
-#endif
-
 /**
  * Update an edge registered on an entry.
  * Creates new edge-entries if not registered.
@@ -596,14 +525,9 @@ olsr_etx_significant_change(float etx1, float etx2)
  */
 static int
 olsr_tc_update_edge(struct tc_entry *tc, unsigned int vtime_s, olsr_u16_t ansn,
-                    olsr_u8_t type, const unsigned char **curr)
+                    const unsigned char **curr)
 {
   struct tc_edge_entry *tc_edge;
-#ifdef USE_FPM
-  fpm link_quality, neigh_link_quality;
-#else
-  double link_quality, neigh_link_quality;
-#endif
   union olsr_ip_addr neighbor;
   int edge_change;
 
@@ -611,24 +535,9 @@ olsr_tc_update_edge(struct tc_entry *tc, unsigned int vtime_s, olsr_u16_t ansn,
 
   /*
    * Fetch the per-edge data
-   * LQ messages also contain LQ data.
    */
   pkt_get_ipaddress(curr, &neighbor);
 
-  if (type == LQ_TC_MESSAGE) {
-    pkt_get_lq(curr, &link_quality);
-    pkt_get_lq(curr, &neigh_link_quality);
-    pkt_ignore_u16(curr);
-  } else {
-#ifdef USE_FPM
-    link_quality = itofpm(1);
-    neigh_link_quality = itofpm(1);
-#else
-    link_quality = 1.0;
-    neigh_link_quality = 1.0;
-#endif
-  }
-
   /* First check if we know this edge */
   tc_edge = olsr_lookup_tc_edge(tc, &neighbor);
 
@@ -642,12 +551,12 @@ olsr_tc_update_edge(struct tc_entry *tc, unsigned int vtime_s, olsr_u16_t ansn,
       return 0;
     }
 
-    olsr_add_tc_edge_entry(tc, &neighbor, ansn, vtime_s,
-                           link_quality, neigh_link_quality);
+    tc_edge = olsr_add_tc_edge_entry(tc, &neighbor, ansn, vtime_s);
+    
+    olsr_deserialize_tc_lq_pair(curr, tc_edge);
     edge_change = 1;
 
   } else {
-
     /*
      * We know this edge - Update entry.
      */
@@ -660,43 +569,20 @@ olsr_tc_update_edge(struct tc_entry *tc, unsigned int vtime_s, olsr_u16_t ansn,
     tc_edge->flags &= ~OLSR_TC_EDGE_DOWN;
 
     /*
-     * Determine if the etx change is meaningful enough
-     * in order to trigger a SPF calculation.
-     */
-    if (olsr_etx_significant_change(tc_edge->link_quality,
-                                    neigh_link_quality)) {
-
-      if (tc->msg_hops <= olsr_cnf->lq_dlimit)
-        edge_change = 1;
-    }
-
-    /*
-     * Update link quality if configured. For hop-count only mode link quality
-     * remains at 1.0.
-     */
-    if (olsr_cnf->lq_level > 0) {
-      tc_edge->link_quality = neigh_link_quality;
-    }
-
-    if (olsr_etx_significant_change(tc_edge->inverse_link_quality,
-                                    link_quality)) {
-
-      if (tc->msg_hops <= olsr_cnf->lq_dlimit)
-        edge_change = 1;
-    }
-
-    /*
-     * Update inverse link quality if configured. For hop-count only mode
-     * inverse link quality remains at 1.0.
+     * Update link quality if configured.
      */
     if (olsr_cnf->lq_level > 0) {
-      tc_edge->inverse_link_quality = link_quality;
+      olsr_deserialize_tc_lq_pair(curr, tc_edge);
     }
 
     /*
      * Update the etx.
      */
-    olsr_calc_tc_edge_entry_etx(tc_edge);
+    if (olsr_calc_tc_edge_entry_etx(tc_edge)) {
+        if (tc->msg_hops <= olsr_cnf->lq_dlimit) {
+               edge_change = 1;
+        }
+    }
 
 #if DEBUG
     if (edge_change) {          
@@ -755,36 +641,16 @@ olsr_print_tc_table(void)
     struct tc_edge_entry *tc_edge;
     OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
       struct ipaddr_str addrbuf, dstaddrbuf;
-      OLSR_PRINTF(1, "%-*s %-*s  %s  %s  %s  %s\n",
+      OLSR_PRINTF(1, "%-*s %-*s  (%-10s) %s\n",
                   ipwidth, olsr_ip_to_string(&addrbuf, &tc->addr),
                   ipwidth, olsr_ip_to_string(&dstaddrbuf, &tc_edge->T_dest_addr),
-                  fpmtoa(tc_edge->link_quality),
-                  fpmtoa(tc_edge->inverse_link_quality),
-                  etxtoa(olsr_calc_tc_etx(tc_edge)),
-                  tc_edge->flags & OLSR_TC_EDGE_DOWN ? "DOWN" : "UP");
+                  get_tc_edge_entry_text(tc_edge),
+                  get_linkcost_text(tc_edge->cost, OLSR_FALSE));
     } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
   } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 #endif
 }
 
-#ifdef USE_FPM
-fpm
-#else
-float
-#endif
-olsr_calc_tc_etx(const struct tc_edge_entry *tc_edge)
-{
-  return tc_edge->link_quality < MIN_LINK_QUALITY ||
-         tc_edge->inverse_link_quality < MIN_LINK_QUALITY
-#ifdef USE_FPM
-             ? itofpm(0)
-             : fpmdiv(itofpm(1), fpmmul(tc_edge->link_quality, tc_edge->inverse_link_quality));
-#else
-             ? 0.0
-             : 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);
-#endif
-}
-
 /*
  * Process an incoming TC or TC_LQ message.
  *
@@ -918,7 +784,7 @@ olsr_input_tc(union olsr_message *msg, struct interface *input_if,
    */
   limit = (unsigned char *)msg + size;
   while (curr < limit) {
-    if (olsr_tc_update_edge(tc, vtime_s, ansn, type, &curr)) {
+    if (olsr_tc_update_edge(tc, vtime_s, ansn, &curr)) {
       changes_topology = OLSR_TRUE;
     }
   }
@@ -934,7 +800,7 @@ olsr_input_tc(union olsr_message *msg, struct interface *input_if,
   /*
    * Last, flood the message to our other neighbors.
    */
-  olsr_forward_message(msg, &originator, msg_seq, input_if, from_addr);
+  olsr_forward_message(msg, from_addr);
   return;
 }
 
index a97a137..68e56c0 100644 (file)
@@ -64,15 +64,8 @@ struct tc_edge_entry
   struct timer_entry *edge_timer; /* expiration timer */
   olsr_u16_t         T_seq; /* sequence number of the advertised neighbor set */
   olsr_u16_t         flags; /* misc flags */
-#ifdef USE_FPM
-  fpm                etx; /* metric used for SPF calculation */
-  fpm                link_quality;
-  fpm                inverse_link_quality;
-#else
-  float              etx; /* metric used for SPF calculation */
-  float              link_quality;
-  float              inverse_link_quality;
-#endif
+  olsr_linkcost      cost; /* metric used for SPF calculation */
+  char               linkquality[0];
 };
 
 #define OLSR_TC_EDGE_DOWN (1 << 0) /* this edge is down */
@@ -92,11 +85,7 @@ struct tc_entry
   struct avl_tree    edge_tree; /* subtree for edges */
   struct avl_tree    prefix_tree; /* subtree for prefixes */
   struct link_entry  *next_hop; /* SPF calculated link to the 1st hop neighbor */
-#ifdef USE_FPM
-  fpm                path_etx; /* SPF calculated distance, cand_tree_node key */
-#else
-  float              path_etx; /* SPF calculated distance, cand_tree_node key */
-#endif
+  olsr_linkcost      path_cost; /* SPF calculated distance, cand_tree_node key */
   olsr_u16_t         msg_seq; /* sequence number of the tc message */
   olsr_u8_t          msg_hops; /* hopcount as per the tc message */
   olsr_u8_t          hops; /* SPF calculated hopcount */
@@ -154,23 +143,12 @@ struct tc_edge_entry *olsr_lookup_tc_edge(struct tc_entry *,
                                           union olsr_ip_addr *);
 struct tc_edge_entry *olsr_add_tc_edge_entry(struct tc_entry *,
                                              union olsr_ip_addr *, olsr_u16_t,
-                                             unsigned int,
-#ifdef USE_FPM
-                                             fpm, fpm
-#else
-                                             float, float
-#endif
-                                             );
+                                             unsigned int);
 void olsr_delete_tc_entry(struct tc_entry *);
 void olsr_delete_tc_edge_entry(struct tc_edge_entry *);
-void olsr_calc_tc_edge_entry_etx(struct tc_edge_entry *);
-#ifdef USE_FPM
-fpm
-#else
-float
-#endif
-olsr_calc_tc_etx(const struct tc_edge_entry *);
+olsr_bool olsr_calc_tc_edge_entry_etx(struct tc_edge_entry *);
 void olsr_set_tc_edge_timer(struct tc_edge_entry *, unsigned int);
+// static olsr_bool olsr_etx_significant_change(float, float);
 
 #endif
 
index 4d62c3d..3554295 100644 (file)
@@ -262,7 +262,7 @@ olsr_print_two_hop_neighbor_table(void)
         }
         OLSR_PRINTF(1, "%-15s  %s\n",
                     olsr_ip_to_string(&buf, &entry->neighbor->neighbor_main_addr),
-                    fpmtoa(entry->path_link_quality));
+                    get_linkcost_text(entry->path_linkcost, OLSR_FALSE));
       }
     }
   }
index 04e8c2e..7f3cc4e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
+ * Copyright (c) 2004, Andreas Tnnesen(andreto@olsr.org)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without 
@@ -44,7 +44,7 @@
 
 #include "defs.h"
 #include "hashing.h"
-#include "fpm.h"
+#include "lq_plugin.h"
 
 #define        NB2S_COVERED    0x1             /* node has been covered by a MPR */
 
 struct neighbor_list_entry 
 {
   struct       neighbor_entry *neighbor;
-#ifdef USE_FPM
-  fpm           second_hop_link_quality;
-  fpm           path_link_quality;
-  fpm           saved_path_link_quality;
-#else
-  double        second_hop_link_quality;
-  double        path_link_quality;
-  double        saved_path_link_quality;
-#endif
+  olsr_linkcost second_hop_linkcost;
+  olsr_linkcost path_linkcost;
+  olsr_linkcost saved_path_linkcost;
   struct       neighbor_list_entry *next;
   struct       neighbor_list_entry *prev;
 };
index 4ac6a62..f0ca9e2 100644 (file)
@@ -622,6 +622,7 @@ add_hemu_if(struct olsr_if *iface)
   /*
    * Register functions for periodic message generation 
    */
+  
   ifp->hello_gen_timer =
     olsr_start_timer(iface->cnf->hello_params.emission_interval * MSEC_PER_SEC,
                      HELLO_JITTER, OLSR_TIMER_PERIODIC,