refactor linkset code
authorHenning Rogge <rogge@fgan.de>
Tue, 15 Apr 2008 15:00:27 +0000 (17:00 +0200)
committerHenning Rogge <rogge@fgan.de>
Tue, 15 Apr 2008 15:00:27 +0000 (17:00 +0200)
50 files changed:
lib/Makefile
lib/bmf/src/NetworkInterfaces.c
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/lq_etx_fpm/Makefile [new file with mode: 0644]
lib/lq_etx_fpm/README_LQ_ETX_FPM [new file with mode: 0644]
lib/lq_etx_fpm/src/lq_etx_fpm.c [new file with mode: 0644]
lib/lq_etx_fpm/src/lq_etx_fpm.h [new file with mode: 0644]
lib/lq_etx_fpm/src/lq_etx_fpm_plugin.c [new file with mode: 0644]
lib/lq_etx_fpm/src/lq_etx_fpm_plugin.h [new file with mode: 0644]
lib/lq_etx_fpm/version-script.txt [new file with mode: 0644]
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/linux/net.c
src/lq_avl.c
src/lq_avl.h
src/lq_mpr.c
src/lq_packet.c
src/lq_packet.h
src/lq_plugin.c [new file with mode: 0644]
src/lq_plugin.h [new file with mode: 0644]
src/lq_plugin_default.c [new file with mode: 0644]
src/lq_plugin_default.h [new file with mode: 0644]
src/lq_route.c
src/mid_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/socket_parser.c
src/socket_parser.h
src/tc_set.c
src/tc_set.h
src/two_hop_neighbor_table.c
src/two_hop_neighbor_table.h

index 0b0dc71..df29c9b 100644 (file)
@@ -3,9 +3,9 @@ ifeq ($(OS),linux)
 SUBDIRS := $(shell find -maxdepth 2 -name Makefile -not -path ./Makefile -printf "%h\n")
 else
 ifeq ($(OS),win32)
-SUBDIRS := bmf dot_draw httpinfo mini pgraph secure txtinfo
+SUBDIRS := bmf dot_draw httpinfo mini pgraph secure txtinfo lq_etx_fpm
 else
-SUBDIRS := bmf dot_draw dyn_gw dyn_gw_plain httpinfo mini nameservice pgraph secure txtinfo
+SUBDIRS := bmf dot_draw dyn_gw dyn_gw_plain httpinfo mini nameservice pgraph secure txtinfo lq_etx_fpm
 endif
 endif
 
index d7ede59..7045dec 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,
@@ -906,21 +852,15 @@ void FindNeighbors(
 #ifndef NODEBUG
           struct interface* bestIntf = if_ifwithaddr(&bestLinkToNeighbor->local_iface_addr);
           struct ipaddr_str buf;
+          struct lqtextbuffer lqbuffer;
 #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, &lqbuffer));
         }
 
         continue; /* for */
@@ -930,14 +870,15 @@ void FindNeighbors(
       {
 #ifndef NODEBUG
         struct ipaddr_str forwardedByBuf, niaBuf;
+        struct lqtextbuffer lqbuffer;
 #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, &lqbuffer));
       }
 
       /* Check the topology table whether the 'forwardedBy' node is itself a direct
@@ -958,29 +899,23 @@ 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)
             {
 #ifndef NODEBUG
               struct ipaddr_str neighbor_iface_buf, forw_buf;
+              struct lqtextbuffer lqbuffer;
               olsr_ip_to_string(&neighbor_iface_buf, &walker->neighbor_iface_addr);
 #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, &lqbuffer));
 
               continue; /* for */
             } /* if */
index 34eaf0b..95c20d5 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,21 +155,18 @@ 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;
-
+  struct lqtextbuffer lqbuffer;
+  
   if (neighbor->status == 0) { // non SYM
     style = "dashed";
   } 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 +174,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, &lqbuffer),
                style);
   
   if (neighbor->is_mpr) {
@@ -269,6 +267,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
 }
 
 
@@ -339,11 +338,12 @@ static void
 ipc_print_tc_link(const struct tc_entry *entry, const struct tc_edge_entry *dst_entry)
 {
   struct ipaddr_str strbuf1, strbuf2;
-
+  struct lqtextbuffer lqbuffer;
+  
   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, &lqbuffer));
 }
 
 
index 96329f2..3235478 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
 
@@ -750,7 +751,8 @@ static int build_ipaddr_link(char *buf, const olsr_u32_t bufsize,
 static int build_route(char *buf, olsr_u32_t bufsize, const struct rt_entry * rt)
 {
   int size = 0;
-
+  struct lqtextbuffer lqbuffer;
+  
   size += snprintf(&buf[size], bufsize-size, "<tr>");
   size += build_ipaddr_with_link(&buf[size], bufsize-size,
                                  &rt->rt_dst.prefix,
@@ -764,7 +766,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, &lqbuffer));
   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 +977,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 +986,13 @@ 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) {
+      struct lqtextbuffer lqbuffer1, lqbuffer2;
       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, &lqbuffer1),
+                       get_linkcost_text(link->linkcost, OLSR_FALSE, &lqbuffer2));
     }
     size += snprintf(&buf[size], bufsize-size, "</tr>\n");
   } OLSR_FOR_ALL_LINK_ENTRIES_END(link);
@@ -1050,7 +1046,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");
 
@@ -1061,13 +1057,11 @@ static int build_topo_body(char *buf, olsr_u32_t bufsize)
           size += build_ipaddr_with_link(&buf[size], bufsize, &tc_edge->T_dest_addr, -1);
           size += build_ipaddr_with_link(&buf[size], bufsize, &tc->addr, -1);
           if (olsr_cnf->lq_level > 0) {
+            struct lqtextbuffer lqbuffer1, lqbuffer2;
               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, &lqbuffer1),
+                               get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer2));
           }
           size += snprintf(&buf[size], bufsize-size, "</tr>\n");
 
diff --git a/lib/lq_etx_fpm/Makefile b/lib/lq_etx_fpm/Makefile
new file mode 100644 (file)
index 0000000..8b456ef
--- /dev/null
@@ -0,0 +1,56 @@
+# 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.
+#
+
+OLSRD_PLUGIN = true
+PLUGIN_NAME =  lq_etx_fpm
+PLUGIN_VER =   0.1
+
+TOPDIR = ../..
+include $(TOPDIR)/Makefile.inc
+
+default_target: $(PLUGIN_FULLNAME)
+
+$(PLUGIN_FULLNAME): $(OBJS) version-script.txt
+               $(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
+
+install:       $(PLUGIN_FULLNAME)
+               $(STRIP) $(PLUGIN_FULLNAME)
+               $(INSTALL_LIB)
+
+clean:
+               rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
diff --git a/lib/lq_etx_fpm/README_LQ_ETX_FPM b/lib/lq_etx_fpm/README_LQ_ETX_FPM
new file mode 100644 (file)
index 0000000..8796b10
--- /dev/null
@@ -0,0 +1,21 @@
+---------------------------------------------------------------------
+ETX-FPM LINKQUALITY PLUGIN FOR OLSRD
+by Henning Rogge <rogge@fgan.de>
+---------------------------------------------------------------------
+
+This plugin is a fpm implementation of the etx metric calculation.
+
+---------------------------------------------------------------------
+SAMPLE CONFIG
+---------------------------------------------------------------------
+
+add in /etc/olsrd.conf:
+
+LoadPlugin "lq_etx_fpm.so.0.1"
+{
+    PlParam "alpha" "0.05"
+}
+
+
+---------------------------------------------------------------------
+EOF / 30.03.2008
diff --git a/lib/lq_etx_fpm/src/lq_etx_fpm.c b/lib/lq_etx_fpm/src/lq_etx_fpm.c
new file mode 100644 (file)
index 0000000..48248a7
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 "tc_set.h"
+#include "link_set.h"
+#include "lq_plugin.h"
+#include "lq_route.h"
+#include "lq_packet.h"
+#include "packet.h"
+#include "olsr.h"
+#include "lq_etx_fpm.h"
+#include "fpm.h"
+
+/* etx lq plugin (fpm version) settings */
+struct lq_handler lq_etx_fpm_handler = {
+    &lq_etx_fpm_calc_cost,
+    &lq_etx_fpm_calc_cost,
+    
+    &lq_etx_fpm_olsr_is_relevant_costchange,
+    
+    &lq_etx_fpm_packet_loss_worker,
+    &lq_etx_fpm_olsr_memorize_foreign_hello_lq,
+    &lq_etx_fpm_olsr_copy_link_lq_into_tc,
+    &lq_etx_fpm_olsr_clear_lq,
+    &lq_etx_fpm_olsr_clear_lq,
+    
+    &lq_etx_fpm_olsr_serialize_hello_lq_pair,
+    &lq_etx_fpm_olsr_serialize_tc_lq_pair,
+    &lq_etx_fpm_olsr_deserialize_hello_lq_pair,
+    &lq_etx_fpm_olsr_deserialize_tc_lq_pair,
+    
+    &lq_etx_fpm_olsr_print_lq,
+    &lq_etx_fpm_olsr_print_lq,
+    &lq_etx_fpm_olsr_print_cost, 
+    
+    sizeof(struct lq_etx_fpm),
+    sizeof(struct lq_etx_fpm)
+};
+
+fpm MINIMAL_LQ;
+fpm aging_factor1, aging_factor2;
+
+void set_lq_etx_fpm_alpha(fpm alpha) {
+  OLSR_PRINTF(3, "lq_etx_fpm: Set alpha to %s\n", fpmtoa(alpha));
+  aging_factor1 = alpha;
+  aging_factor2 = fpmsub(itofpm(1), alpha);
+}
+
+int init_lq_etx_fpm(void) {
+  if (aging_factor1 == 0 && aging_factor2 == 0) {
+    OLSR_PRINTF(1, "Alpha factor for lq_etx_fgm not set !\n");
+    return 0; // error
+  }
+  
+  MINIMAL_LQ = ftofpm(0.1);
+  
+  // activate plugin
+  set_lq_handler(&lq_etx_fpm_handler, LQ_ETX_FPM_HANDLER_NAME);
+  return 1;
+}
+
+olsr_linkcost lq_etx_fpm_calc_cost(const void *ptr) {
+  const struct lq_etx_fpm *lq = ptr;
+  olsr_linkcost cost;
+  
+  if (lq->lq < MINIMAL_LQ || lq->nlq < MINIMAL_LQ) {
+    return LINK_COST_BROKEN;
+  }
+  
+  cost = fpmdiv(itofpm(1), fpmmul(lq->lq, lq->nlq));
+
+  if (cost > LINK_COST_BROKEN)
+    return LINK_COST_BROKEN;
+  if (cost == 0)
+    return 1;
+  return cost;
+}
+
+int lq_etx_fpm_olsr_serialize_hello_lq_pair(unsigned char *buff, void *ptr) {
+  struct lq_etx_fpm *lq = ptr;
+  
+  buff[0] = (unsigned char)fpmtoi(fpmmuli(lq->lq, 255));
+  buff[1] = (unsigned char)fpmtoi(fpmmuli(lq->nlq, 255));
+  buff[2] = (unsigned char)(0);
+  buff[3] = (unsigned char)(0);
+  
+  return 4;
+}
+
+void lq_etx_fpm_olsr_deserialize_hello_lq_pair(const olsr_u8_t **curr, void *ptr) {
+  struct lq_etx_fpm *lq = ptr;
+  olsr_u8_t valueLq, valueNlq;
+  
+  pkt_get_u8(curr, &valueLq);
+  pkt_get_u8(curr, &valueNlq);
+  pkt_ignore_u16(curr);
+  
+  lq->lq = fpmidiv(itofpm((int)valueLq), 255);
+  lq->nlq = fpmidiv(itofpm((int)valueNlq), 255);
+}
+
+olsr_bool lq_etx_fpm_olsr_is_relevant_costchange(olsr_linkcost c1, olsr_linkcost c2) {
+  if (c1 > c2) {
+    return c2 - c1 > LQ_PLUGIN_RELEVANT_COSTCHANGE;
+  }
+  return c1 - c2 > LQ_PLUGIN_RELEVANT_COSTCHANGE;
+}
+
+int lq_etx_fpm_olsr_serialize_tc_lq_pair(unsigned char *buff, void *ptr) {
+  struct lq_etx_fpm *lq = ptr;
+  
+  buff[0] = (unsigned char)fpmtoi(fpmmuli(lq->lq, 255));
+  buff[1] = (unsigned char)fpmtoi(fpmmuli(lq->nlq, 255));
+  buff[2] = (unsigned char)(0);
+  buff[3] = (unsigned char)(0);
+  
+  return 4;
+}
+
+void lq_etx_fpm_olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, void *ptr) {
+  struct lq_etx_fpm *lq = ptr;
+  olsr_u8_t valueLq, valueNlq;
+  
+  pkt_get_u8(curr, &valueLq);
+  pkt_get_u8(curr, &valueNlq);
+  pkt_ignore_u16(curr);
+  
+  lq->lq = fpmidiv(itofpm(valueLq), 255);
+  lq->nlq = fpmidiv(itofpm(valueNlq), 255);
+}
+
+olsr_linkcost lq_etx_fpm_packet_loss_worker(void *ptr, olsr_bool lost) {
+  struct lq_etx_fpm *tlq = ptr;
+  
+  // exponential moving average
+  tlq->lq = fpmmul(tlq->lq, aging_factor2);
+  if (lost == 0) {
+    tlq->lq = fpmadd(tlq->lq, aging_factor1);
+  }
+  return lq_etx_fpm_calc_cost(ptr);
+}
+
+void lq_etx_fpm_olsr_memorize_foreign_hello_lq(void *ptrLocal, void *ptrForeign) {
+  struct lq_etx_fpm *local = ptrLocal;
+  struct lq_etx_fpm *foreign = ptrForeign;
+  
+  if (foreign) {
+    local->nlq = foreign->lq;
+  }
+  else {
+    local->nlq = itofpm(0);
+  }
+}
+
+void lq_etx_fpm_olsr_copy_link_lq_into_tc(void *target, void *source) {
+  memcpy(target, source, sizeof(struct lq_etx_fpm));
+}
+
+void lq_etx_fpm_olsr_clear_lq(void *target) {
+  memset(target, 0, sizeof(struct lq_etx_fpm));
+}
+
+const char *lq_etx_fpm_olsr_print_lq(void *ptr, struct lqtextbuffer *buffer) {
+  struct lq_etx_fpm *lq = ptr;
+  
+  sprintf(buffer->buf, "%s/%s", fpmtoa(lq->lq), fpmtoa(lq->nlq));
+  return buffer->buf;
+}
+
+const char *lq_etx_fpm_olsr_print_cost(olsr_linkcost cost, struct lqtextbuffer *buffer) {
+  sprintf(buffer->buf, "%s", fpmtoa(cost));
+  return buffer->buf;
+}
diff --git a/lib/lq_etx_fpm/src/lq_etx_fpm.h b/lib/lq_etx_fpm/src/lq_etx_fpm.h
new file mode 100644 (file)
index 0000000..97b049c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 LQ_ETX_FPM_
+#define LQ_ETX_FPM_
+
+#include "olsr_types.h"
+#include "fpm.h"
+#include "lq_plugin.h"
+
+#define LQ_PLUGIN_LC_MULTIPLIER 1024
+#define LQ_PLUGIN_RELEVANT_COSTCHANGE 16
+
+#define LQ_ETX_FPM_HANDLER_NAME "ETX metric with FPM"
+struct lq_etx_fpm {
+       fpm lq, nlq;
+};
+
+void set_lq_etx_fpm_alpha(fpm alpha);
+int init_lq_etx_fpm(void);
+
+olsr_linkcost lq_etx_fpm_calc_cost(const void *lq);
+
+olsr_bool lq_etx_fpm_olsr_is_relevant_costchange(olsr_linkcost c1, olsr_linkcost c2);
+
+olsr_linkcost lq_etx_fpm_packet_loss_worker(void *lq, olsr_bool lost);
+void lq_etx_fpm_olsr_memorize_foreign_hello_lq(void *local, void *foreign);
+
+int lq_etx_fpm_olsr_serialize_hello_lq_pair(unsigned char *buff, void *lq);
+void lq_etx_fpm_olsr_deserialize_hello_lq_pair(const olsr_u8_t **curr, void *lq);
+int lq_etx_fpm_olsr_serialize_tc_lq_pair(unsigned char *buff, void *lq);
+void lq_etx_fpm_olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, void *lq);
+
+void lq_etx_fpm_olsr_copy_link_lq_into_tc(void *target, void *source);
+void lq_etx_fpm_olsr_clear_lq(void *target);
+
+const char *lq_etx_fpm_olsr_print_lq(void *ptr, struct lqtextbuffer *buffer);
+const char *lq_etx_fpm_olsr_print_cost(olsr_linkcost cost, struct lqtextbuffer *buffer);
+
+#endif /*LQ_ETX_FPM_*/
diff --git a/lib/lq_etx_fpm/src/lq_etx_fpm_plugin.c b/lib/lq_etx_fpm/src/lq_etx_fpm_plugin.c
new file mode 100644 (file)
index 0000000..19158f2
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 <stdio.h>
+#include <string.h>
+
+#include "../../../src/olsrd_plugin.h"
+
+#include "lq_etx_fpm_plugin.h"
+#include "lq_etx_fpm.h"
+#include "olsr.h"
+#include "fpm.h"
+
+#define PLUGIN_INTERFACE_VERSION 5
+
+/****************************************************************************
+ *                Functions that the plugin MUST provide                    *
+ ****************************************************************************/
+/**
+ * Plugin interface version
+ * Used by main olsrd to check plugin interface version
+ */
+int olsrd_plugin_interface_version(void)
+{
+    return PLUGIN_INTERFACE_VERSION;
+}
+
+
+static int set_alpha(const char *value, void *data __attribute__((unused)), set_plugin_parameter_addon addon __attribute__((unused)))
+{
+    set_lq_etx_fpm_alpha(atofpm(value));
+    return 0;
+}
+
+/**
+ * Register parameters from config file
+ * Called for all plugin parameters
+ */
+static const struct olsrd_plugin_parameters plugin_parameters[] = {
+    { .name = "alpha",   .set_plugin_parameter = &set_alpha,      .data = NULL },
+};
+
+void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
+{
+    *params = plugin_parameters;
+    *size = sizeof(plugin_parameters)/sizeof(*plugin_parameters);
+}
+/**
+ * Initialize plugin
+ * Called after all parameters are passed
+ */
+int
+olsrd_plugin_init(void)
+{
+  return init_lq_etx_fpm();
+}
+
+
+/****************************************************************************
+ *       Optional private constructor and destructor functions              *
+ ****************************************************************************/
+
+/* attention: make static to avoid name clashes */
+
+static void my_init(void) __attribute__ ((constructor));
+static void my_fini(void) __attribute__ ((destructor));
+
+
+/**
+ * Optional Private Constructor
+ */
+static void my_init(void)
+{
+}
+
+
+/**
+ * Optional Private Destructor
+ */
+static void my_fini(void)
+{
+}
diff --git a/lib/lq_etx_fpm/src/lq_etx_fpm_plugin.h b/lib/lq_etx_fpm/src/lq_etx_fpm_plugin.h
new file mode 100644 (file)
index 0000000..2fc2e04
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 LQ_ETX_FPM_PLUGIN_
+#define LQ_ETX_FPM_PLUGIN_
+
+
+/****************************************************************************
+ *                Functions that the plugin MUST provide                    *
+ ****************************************************************************/
+
+
+/* Initialization function */
+int
+olsrd_plugin_init(void);
+
+int 
+olsrd_plugin_interface_version(void);
+
+#endif
diff --git a/lib/lq_etx_fpm/version-script.txt b/lib/lq_etx_fpm/version-script.txt
new file mode 100644 (file)
index 0000000..a145659
--- /dev/null
@@ -0,0 +1,10 @@
+VERS_1.0
+{
+  global:
+    olsrd_plugin_interface_version;
+    olsrd_plugin_init;
+    olsrd_get_plugin_parameters;
+
+  local:
+    *;
+};
index a14c058..a339104 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];
@@ -174,15 +176,15 @@ void mapwrite_work(FILE* fmap)
     char* llb = lookup_position_latlon(&tc_edge->T_dest_addr);
     if (NULL != lla && NULL != llb)
     {
+      struct lqtextbuffer lqbuffer;
+      
       /*
        * 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, &lqbuffer),
             lla, llb))
       {
         return;
@@ -190,15 +192,15 @@ void mapwrite_work(FILE* fmap)
     }
     else
     {
+      struct lqtextbuffer lqbuffer;
+      
       /*
        * 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, &lqbuffer)))
       {
         return;
       }
index 3f526b1..37eb749 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);
 }
 
 /**
@@ -1234,13 +1227,14 @@ select_best_nameserver(struct rt_entry **rt)
                if (!rt2 || olsr_cmp_rt(rt1, rt2)) {
 #ifndef NODEBUG
                        struct ipaddr_str strbuf;
+                       struct lqtextbuffer lqbuffer;
 #endif
                        /*
                         * 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, &lqbuffer));
 
                        rt[nameserver_idx] = rt2;
                        rt[nameserver_idx+1] = rt1;
@@ -1281,6 +1275,7 @@ write_resolv_file(void)
                        for (name = entry->names; name != NULL; name = name->next) {
 #ifndef NODEBUG
                                struct ipaddr_str strbuf;
+                               struct lqtextbuffer lqbuffer;
 #endif
                                route = olsr_lookup_routing_table(&name->ip);
 
@@ -1293,9 +1288,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, &lqbuffer));
 
                                /* find the closet one */
                                select_best_nameserver(nameserver_routes);
index ecb035e..d3bb0b3 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,17 @@ 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
-
+  struct lqtextbuffer lqbuffer;
+  
   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, &lqbuffer));
 
 
   link_node = iterLinkTab->link_list.next;
@@ -285,6 +278,7 @@ int iterTcTabNext(char *buff, int len)
   int res;
   int i;
   struct tc_edge_entry *tc_edge;
+  struct lqtextbuffer lqbuffer;
   
   if (iterTcTab == NULL)
     return -1;
@@ -301,9 +295,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, &lqbuffer));
 
     if (res < len)
       buff += res;
@@ -338,7 +332,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 +351,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 +380,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 7bd3a48..9070eb9 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"
@@ -347,21 +348,20 @@ static void ipc_print_neigh(void)
 static void ipc_print_link(void)
 {
     struct ipaddr_str buf1, buf2;
+    struct lqtextbuffer lqbuffer1, lqbuffer2;
+
     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, &lqbuffer1),
+                   get_linkcost_text(link->linkcost, OLSR_FALSE, &lqbuffer2));
     } OLSR_FOR_ALL_LINK_ENTRIES_END(link);
 
     ipc_sendf("\n");
@@ -372,7 +372,8 @@ static void ipc_print_routes(void)
     struct ipaddr_str buf1, buf2;
     struct rt_entry *rt;
     struct avl_node *rt_tree_node;
-
+    struct lqtextbuffer lqbuffer;
+    
     ipc_sendf("Table: Routes\nDestination\tGateway\tMetric\tETX\tInterface\n");
 
     /* Walk the route table */
@@ -387,7 +388,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, &lqbuffer),
                    if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
     }
     ipc_sendf("\n");
@@ -398,19 +399,19 @@ 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", 
+            struct lqtextbuffer lqbuffer1, lqbuffer2;
+            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, &lqbuffer1),
+                       get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer2));
 
         } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
     } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
index d3d3dd7..f117f2a 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
  * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without 
  *
  */
 
-#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;
-
-  OLSR_PRINTF(3, "Initializing duplicatetable - hashsize %d\n", HASHSIZE);
-
-  for(i = 0; i < HASHSIZE; i++)
-    {
-      dup_set[i].next = &dup_set[i];
-      dup_set[i].prev = &dup_set[i];
-    }
-}
-
-/**
- * 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;
+#include "mid_set.h"
 
-#ifdef DEBUG
-  OLSR_PRINTF(5, "DUP TIMEOUT[%s] s: %d\n", 
-              olsr_ip_to_string(&buf, &dup->addr),
-              dup->seqno);
-#endif
+struct avl_tree duplicate_set;
 
-  olsr_del_dup_entry(dup);
+void olsr_init_duplicate_set(void) {
+  avl_init(&duplicate_set, olsr_cnf->ip_version == AF_INET ? &avl_comp_ipv4 : &avl_comp_ipv6);
 }
 
-
-/**
- *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;
+#ifndef NODEBUG
+  struct ipaddr_str buf;
+#endif  
+  // get main address
+  mainIp = mid_lookup_main_addr(ip);
+  if (mainIp == NULL) {
+    mainIp = ip;
+  }
   
-
-  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);
+  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);
     }
-
-  /* Dequeue */
-  DEQUEUE_ELEM(entry);
-
-  /* Stop timer */
-  if (entry->timer) {
-    olsr_stop_timer(entry->timer);
+    return 1; // okay, we process this package
   }
 
-  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;
-       }
-    }
-
-  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 !! */
+    OLSR_PRINTF(9, "blocked %x from %s\n", seqnr, olsr_ip_to_string(&buf, mainIp));
     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) {
+      OLSR_PRINTF(9, "blocked %x (diff=%d,mask=%08x) from %s\n", seqnr, diff, entry->array, olsr_ip_to_string(&buf, mainIp));
+      return 0;
+    }
+    entry->array |= bitmask;
+    OLSR_PRINTF(9, "processed %x from %s\n", seqnr, olsr_ip_to_string(&buf, mainIp));
+    return 1;
+  }
+  else if (diff < 32) {
+    entry->array <<= (olsr_u32_t)diff;
+  }
+  else {
+    entry->array = 0;
+  }
+  entry->array |= 1;
+  entry->seqnr = seqnr;
+  OLSR_PRINTF(9, "processed %x from %s\n", seqnr, olsr_ip_to_string(&buf, mainIp));
   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) {
+  /* XXX FIXME */
 }
 
 /*
index 4c52879..11ab99a 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas TÃ\83¸nnesen(andreto@olsr.org)
+ * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without 
  *
  */
 
-#ifndef _OLSR_DUP_TABLE
-#define _OLSR_DUP_TABLE
+#ifndef DUPLICATE_SET_H_
+#define DUPLICATE_SET_H_
 
-#include "olsr_types.h"
+#include "lq_avl.h"
+#include "olsr.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 */
-};
-
-#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 */
+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;
 };
 
+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);
 
-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
+#endif /*DUPLICATE_SET_H_*/
 
 /*
  * Local Variables:
index 2a0df61..3a8f58f 100644 (file)
@@ -204,7 +204,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;
@@ -215,9 +215,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
 
   /*
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..5854b51 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,16 @@ 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",
+    struct lqtextbuffer lqbuffer1, lqbuffer2;
+    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, &lqbuffer1),
+                get_linkcost_text(walker->linkcost, OLSR_FALSE, &lqbuffer2));
   } 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 +858,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 +869,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 6c3423b..53586fc 100644 (file)
@@ -358,7 +358,7 @@ restore_settings(int version)
 }
 
 /**
- *Creates a nonblocking broadcast socket.
+ *Creates a blocking tcp socket for communication with switch daemon.
  *@param sa sockaddr struct. Used for bind(2).
  *@return the FD of the socket or -1 on error.
  */
index c2081a8..27011cd 100644 (file)
@@ -66,6 +66,11 @@ int avl_comp_ipv6(const void *ip1, const void *ip2)
   return ip6cmp(ip1, ip2);
 }
 
+int avl_comp_mac(const void *ip1, const void *ip2)
+{
+  return memcmp(ip1, ip2, 6);
+}
+
 void avl_init(struct avl_tree *tree, avl_tree_comp comp)
 {
   tree->root = NULL;
index aa84063..8a870a4 100644 (file)
@@ -42,7 +42,9 @@
 #ifndef _LQ_AVL_H
 #define _LQ_AVL_H
 
-#include "defs.h"
+/* must be declared here because of circular dependency through "defs.h" */
+
+#define INLINE inline __attribute__((always_inline))
 
 struct avl_node
 {
@@ -90,6 +92,7 @@ extern avl_tree_comp avl_comp_default;
 extern avl_tree_comp avl_comp_prefix_default;
 extern int avl_comp_ipv4(const void *, const void *);
 extern int avl_comp_ipv6(const void *, const void *);
+extern int avl_comp_mac(const void *, const void *);
 
 #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..de69cf1 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
 
@@ -224,31 +222,26 @@ create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
       continue;
     }
 
+    /* Set the entry's link quality */
+    lnk = get_best_link_to_neighbor(&walker->neighbor_main_addr);
+    if (!lnk) {
+      continue; // no link ?
+    }
+    
+    if (lnk->linkcost >= LINK_COST_BROKEN) {
+      continue; // don't advertise links with very low LQ
+    }
+    
     /* 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;
 
-    /* Set the entry's link quality */
-    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 +449,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 +557,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);
 
diff --git a/src/lq_plugin.c b/src/lq_plugin.c
new file mode 100644 (file)
index 0000000..8c0da05
--- /dev/null
@@ -0,0 +1,432 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 "tc_set.h"
+#include "link_set.h"
+#include "lq_route.h"
+#include "lq_packet.h"
+#include "packet.h"
+#include "olsr.h"
+#include "two_hop_neighbor_table.h"
+
+#include "lq_plugin_default.h"
+#include "lq_plugin.h"
+
+/* Default lq plugin settings */
+struct lq_handler default_lq_handler = {
+               &default_calc_cost,
+               &default_calc_cost,
+               
+               &default_olsr_is_relevant_costchange,
+               
+               &default_packet_loss_worker,
+               &default_olsr_memorize_foreign_hello_lq,
+               &default_olsr_copy_link_lq_into_tc,
+    &default_olsr_clear_lq,
+    &default_olsr_clear_lq,
+               
+               &default_olsr_serialize_hello_lq_pair,
+               &default_olsr_serialize_tc_lq_pair,
+               &default_olsr_deserialize_hello_lq_pair,
+               &default_olsr_deserialize_tc_lq_pair,
+               
+               &default_olsr_print_lq,
+               &default_olsr_print_lq,
+               &default_olsr_print_cost, 
+               
+               sizeof(struct default_lq),
+               sizeof(struct default_lq)
+};
+
+struct lq_handler *active_lq_handler = &default_lq_handler;
+
+/*
+ * set_lq_handler
+ * 
+ * this function is used by routing metric plugins to activate their link
+ * quality handler
+ * 
+ * @param pointer to lq_handler structure
+ * @param name of the link quality handler for debug output
+ */
+void set_lq_handler(struct lq_handler *handler, const char *name) {
+  if (handler) {
+    OLSR_PRINTF(1, "Activated lq_handler: %s\n", name);
+    active_lq_handler = handler;
+  }
+  else {
+    OLSR_PRINTF(1, "Activated lq_handler: default\n");
+    active_lq_handler = &default_lq_handler;
+  }
+}
+
+/*
+ * olsr_calc_tc_cost
+ * 
+ * this function calculates the linkcost of a tc_edge_entry
+ * 
+ * @param pointer to the tc_edge_entry
+ * @return linkcost
+ */
+olsr_linkcost olsr_calc_tc_cost(const struct tc_edge_entry *tc_edge)
+{
+  return active_lq_handler->calc_tc_cost(tc_edge->linkquality);
+}
+
+/*
+ * olsr_is_relevant_costchange
+ * 
+ * decides if the difference between two costs is relevant
+ * (for changing the route for example)
+ * 
+ * @param first linkcost value
+ * @param second linkcost value
+ * @return boolean
+ */
+olsr_bool olsr_is_relevant_costchange(olsr_linkcost c1, olsr_linkcost c2) {
+  return active_lq_handler->is_relevant_costchange(c1, c2);
+}
+
+/*
+ * olsr_serialize_hello_lq_pair
+ * 
+ * this function converts the lq information of a lq_hello_neighbor into binary package
+ * format
+ * 
+ * @param pointer to binary buffer to write into
+ * @param pointer to lq_hello_neighbor
+ * @return number of bytes that have been written
+ */
+int olsr_serialize_hello_lq_pair(unsigned char *buff, struct lq_hello_neighbor *neigh) {
+       return active_lq_handler->serialize_hello_lq(buff, neigh->linkquality);
+}
+
+/*
+ * olsr_deserialize_hello_lq_pair
+ * 
+ * this function reads the lq information of a binary package into a hello_neighbor
+ * It also initialize the cost variable of the hello_neighbor
+ * 
+ * @param pointer to the current buffer pointer
+ * @param pointer to hello_neighbor
+ */
+void olsr_deserialize_hello_lq_pair(const olsr_u8_t **curr, struct hello_neighbor *neigh) {
+       active_lq_handler->deserialize_hello_lq(curr, neigh->linkquality);
+       neigh->cost = active_lq_handler->calc_hello_cost(neigh->linkquality);
+}
+
+/*
+ * olsr_serialize_tc_lq_pair
+ * 
+ * this function converts the lq information of a olsr_serialize_tc_lq_pair
+ * into binary package format
+ * 
+ * @param pointer to binary buffer to write into
+ * @param pointer to olsr_serialize_tc_lq_pair
+ * @return number of bytes that have been written
+ */
+int olsr_serialize_tc_lq_pair(unsigned char *buff, struct tc_mpr_addr *neigh) {
+       return active_lq_handler->serialize_tc_lq(buff, neigh->linkquality);
+}
+
+/*
+ * olsr_deserialize_tc_lq_pair
+ * 
+ * this function reads the lq information of a binary package into a tc_edge_entry
+ * 
+ * @param pointer to the current buffer pointer
+ * @param pointer to tc_edge_entry
+ */
+void olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, struct tc_edge_entry *edge) {
+       active_lq_handler->deserialize_tc_lq(curr, edge->linkquality);
+}
+
+/*
+ * olsr_update_packet_loss_worker
+ * 
+ * this function is called every times a hello package for a certain link_entry
+ * is lost (timeout) or received. This way the lq-plugin can update the links link
+ * quality value.
+ * 
+ * @param pointer to link_entry
+ * @param OLSR_TRUE if hello package was lost
+ */
+void olsr_update_packet_loss_worker(struct link_entry *entry, olsr_bool lost)
+{
+       olsr_linkcost lq;
+       lq = active_lq_handler->packet_loss_handler(entry->linkquality, lost);
+  
+       if (olsr_is_relevant_costchange(lq, entry->linkcost)) {
+    entry->linkcost = lq;
+    
+    if (olsr_cnf->lq_dlimit > 0) {
+      changes_neighborhood = OLSR_TRUE;
+      changes_topology = OLSR_TRUE;
+    }
+
+    else
+      OLSR_PRINTF(3, "Skipping Dijkstra (1)\n");
+    
+    // XXX - we should check whether we actually
+    // announce this neighbour
+    signal_link_changes(OLSR_TRUE);
+  }
+}
+
+/*
+ * olsr_memorize_foreign_hello_lq
+ * 
+ * this function is called to copy the link quality information from a received
+ * hello package into a link_entry.
+ * 
+ * @param pointer to link_entry
+ * @param pointer to hello_neighbor, if NULL the neighbor link quality information
+ * of the link entry has to be reset to "zero"
+ */
+void olsr_memorize_foreign_hello_lq(struct link_entry *local, struct hello_neighbor *foreign) {
+  if (foreign) {
+    active_lq_handler->memorize_foreign_hello(local->linkquality, foreign->linkquality);
+  }
+  else {
+    active_lq_handler->memorize_foreign_hello(local->linkquality, NULL);
+  }
+}
+
+/*
+ * get_link_entry_text
+ * 
+ * this function returns the text representation of a link_entry cost value.
+ * It's not thread save and should not be called twice with the same println
+ * value in the same context (a single printf command for example).
+ * 
+ * @param pointer to link_entry
+ * @param buffer for output
+ * @return pointer to a buffer with the text representation
+ */
+const char *get_link_entry_text(struct link_entry *entry, struct lqtextbuffer *buffer) {
+  return active_lq_handler->print_hello_lq(entry->linkquality, buffer);
+}
+
+/*
+ * get_tc_edge_entry_text
+ * 
+ * this function returns the text representation of a tc_edge_entry cost value.
+ * It's not thread save and should not be called twice with the same println
+ * value in the same context (a single printf command for example).
+ * 
+ * @param pointer to tc_edge_entry
+ * @param pointer to buffer
+ * @return pointer to the buffer with the text representation
+ */
+const char *get_tc_edge_entry_text(struct tc_edge_entry *entry, struct lqtextbuffer *buffer) {
+  return active_lq_handler->print_tc_lq(entry->linkquality, buffer);
+}
+
+/*
+ * get_linkcost_text
+ * 
+ * This function transforms an olsr_linkcost value into it's text representation and copies
+ * the result into a buffer.
+ * 
+ * @param linkcost value
+ * @param true to transform the cost of a route, false for a link
+ * @param pointer to buffer
+ * @return pointer to buffer filled with text
+ */
+const char *get_linkcost_text(olsr_linkcost cost, olsr_bool route, struct lqtextbuffer *buffer) {
+  static const char *infinite = "INFINITE";
+  
+  if (route) {
+    if (cost == ROUTE_COST_BROKEN) {
+      return infinite;
+    }
+  }
+  else {
+    if (cost >= LINK_COST_BROKEN) {
+      return infinite;
+    }
+  }
+  return active_lq_handler->print_cost(cost, buffer);
+}
+
+/*
+ * olsr_copy_hello_lq
+ * 
+ * this function copies the link quality information from a link_entry to a
+ * lq_hello_neighbor.
+ * 
+ * @param pointer to target lq_hello_neighbor
+ * @param pointer to source link_entry
+ */
+void olsr_copy_hello_lq(struct lq_hello_neighbor *target, struct link_entry *source) {
+  memcpy(target->linkquality, source->linkquality, active_lq_handler->hello_lq_size);
+}
+
+/*
+ * olsr_copylq_link_entry_2_tc_mpr_addr
+ * 
+ * this function copies the link quality information from a link_entry to a
+ * tc_mpr_addr.
+ * 
+ * @param pointer to tc_mpr_addr
+ * @param pointer to link_entry
+ */
+void olsr_copylq_link_entry_2_tc_mpr_addr(struct tc_mpr_addr *target, struct link_entry *source) {
+  active_lq_handler->copy_link_lq_into_tc(target->linkquality, source->linkquality);
+}
+
+/*
+ * olsr_copylq_link_entry_2_tc_edge_entry
+ * 
+ * this function copies the link quality information from a link_entry to a
+ * tc_edge_entry.
+ * 
+ * @param pointer to tc_edge_entry
+ * @param pointer to link_entry
+ */
+void olsr_copylq_link_entry_2_tc_edge_entry(struct tc_edge_entry *target, struct link_entry *source) {
+  active_lq_handler->copy_link_lq_into_tc(target->linkquality, source->linkquality);
+}
+
+/*
+ * olsr_clear_tc_lq
+ * 
+ * this function resets the linkquality value of a tc_mpr_addr
+ * 
+ * @param pointer to tc_mpr_addr
+ */
+void olsr_clear_tc_lq(struct tc_mpr_addr *target) {
+  active_lq_handler->clear_tc(target->linkquality);
+}
+
+/*
+ * olsr_malloc_hello_neighbor
+ * 
+ * this function allocates memory for an hello_neighbor inclusive
+ * linkquality data.
+ * 
+ * @param id string for memory debugging
+ * 
+ * @return pointer to hello_neighbor
+ */
+struct hello_neighbor *olsr_malloc_hello_neighbor(const char *id) {
+       struct hello_neighbor *h;
+       
+       h = olsr_malloc(sizeof(struct hello_neighbor) + active_lq_handler->hello_lq_size, id);
+       
+       active_lq_handler->clear_hello(h->linkquality);
+       return h;
+}
+
+/*
+ * olsr_malloc_tc_mpr_addr
+ * 
+ * this function allocates memory for an tc_mpr_addr inclusive
+ * linkquality data.
+ * 
+ * @param id string for memory debugging
+ * 
+ * @return pointer to tc_mpr_addr
+ */
+struct tc_mpr_addr *olsr_malloc_tc_mpr_addr(const char *id) {
+  struct tc_mpr_addr *t;
+  
+   t = olsr_malloc(sizeof(struct tc_mpr_addr) + active_lq_handler->tc_lq_size, id);
+  
+  active_lq_handler->clear_tc(t->linkquality);
+  return t;
+}
+
+/*
+ * olsr_malloc_lq_hello_neighbor
+ * 
+ * this function allocates memory for an lq_hello_neighbor inclusive
+ * linkquality data.
+ * 
+ * @param id string for memory debugging
+ * 
+ * @return pointer to lq_hello_neighbor
+ */
+struct lq_hello_neighbor *olsr_malloc_lq_hello_neighbor(const char *id) {
+  struct lq_hello_neighbor *h;
+  
+  h = olsr_malloc(sizeof(struct lq_hello_neighbor) + active_lq_handler->hello_lq_size, id);
+  
+  active_lq_handler->clear_hello(h->linkquality);
+  return h;
+}
+
+/*
+ * olsr_malloc_link_entry
+ * 
+ * this function allocates memory for an link_entry inclusive
+ * linkquality data.
+ * 
+ * @param id string for memory debugging
+ * 
+ * @return pointer to link_entry
+ */
+struct link_entry *olsr_malloc_link_entry(const char *id) {
+  struct link_entry *h;
+  
+  h =  olsr_malloc(sizeof(struct link_entry) + active_lq_handler->hello_lq_size, id);
+  
+  active_lq_handler->clear_hello(h->linkquality);
+  return h;
+}
+
+/*
+ * olsr_malloc_tc_edge_entry
+ * 
+ * this function allocates memory for an tc_edge_entry inclusive
+ * linkquality data.
+ * 
+ * @param id string for memory debugging
+ * 
+ * @return pointer to tc_edge_entry
+ */
+struct tc_edge_entry *olsr_malloc_tc_edge_entry(const char *id) {
+  struct tc_edge_entry *t;
+  
+  t = olsr_malloc(sizeof(struct tc_edge_entry) + active_lq_handler->tc_lq_size, id);
+  
+  active_lq_handler->clear_tc(t);
+  return t;
+}
diff --git a/src/lq_plugin.h b/src/lq_plugin.h
new file mode 100644 (file)
index 0000000..bf987b9
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 LQPLUGIN_H_
+#define LQPLUGIN_H_
+
+#include "tc_set.h"
+#include "link_set.h"
+#include "lq_route.h"
+#include "lq_packet.h"
+#include "packet.h"
+
+#define LINK_COST_BROKEN (1<<22)
+#define ROUTE_COST_BROKEN (0xffffffff)
+#define ZERO_ROUTE_COST 0
+
+struct lqtextbuffer {
+  char buf[16];
+};
+
+struct lq_handler {
+  olsr_linkcost (*calc_hello_cost)(const void *lq);
+  olsr_linkcost (*calc_tc_cost)(const void *lq);
+  
+  olsr_bool (*is_relevant_costchange)(olsr_linkcost c1, olsr_linkcost c2);
+  
+  olsr_linkcost (*packet_loss_handler)(void *lq, olsr_bool lost);
+  
+  void (*memorize_foreign_hello)(void *local, void *foreign);
+  void (*copy_link_lq_into_tc)(void *target, void *source);
+  void (*clear_hello)(void *target);
+  void (*clear_tc)(void *target);
+  
+  int (*serialize_hello_lq)(unsigned char *buff, void *lq);
+  int (*serialize_tc_lq)(unsigned char *buff, void *lq);
+  void (*deserialize_hello_lq)(const olsr_u8_t **curr, void *lq);
+  void (*deserialize_tc_lq)(const olsr_u8_t **curr, void *lq);
+  
+  const char *(*print_hello_lq)(void *ptr, struct lqtextbuffer *buffer);
+  const char *(*print_tc_lq)(void *ptr, struct lqtextbuffer *buffer);
+  const char *(*print_cost)(olsr_linkcost cost, struct lqtextbuffer *buffer);
+  
+  size_t hello_lq_size;
+  size_t tc_lq_size;
+};
+
+void set_lq_handler(struct lq_handler *handler, const char *name);
+
+olsr_linkcost olsr_calc_tc_cost(const struct tc_edge_entry *);
+olsr_bool olsr_is_relevant_costchange(olsr_linkcost c1, olsr_linkcost c2);
+
+int olsr_serialize_hello_lq_pair(unsigned char *buff, struct lq_hello_neighbor *neigh);
+void olsr_deserialize_hello_lq_pair(const olsr_u8_t **curr, struct hello_neighbor *neigh);
+int olsr_serialize_tc_lq_pair(unsigned char *buff, struct tc_mpr_addr *neigh);
+void olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, struct tc_edge_entry *edge);
+
+void olsr_update_packet_loss_worker(struct link_entry *entry, olsr_bool lost);
+void olsr_memorize_foreign_hello_lq(struct link_entry *local, struct hello_neighbor *foreign);
+
+const char *get_link_entry_text(struct link_entry *entry, struct lqtextbuffer *buffer);
+const char *get_tc_edge_entry_text(struct tc_edge_entry *entry, struct lqtextbuffer *buffer);
+const char *get_linkcost_text(olsr_linkcost cost, olsr_bool route, struct lqtextbuffer *buffer);
+
+void olsr_copy_hello_lq(struct lq_hello_neighbor *target, struct link_entry *source);
+void olsr_copylq_link_entry_2_tc_mpr_addr(struct tc_mpr_addr *target, struct link_entry *source);
+void olsr_copylq_link_entry_2_tc_edge_entry(struct tc_edge_entry *target, struct link_entry *source);
+void olsr_clear_tc_lq(struct tc_mpr_addr *target);
+
+struct hello_neighbor *olsr_malloc_hello_neighbor(const char *id);
+struct tc_mpr_addr *olsr_malloc_tc_mpr_addr(const char *id);
+struct lq_hello_neighbor *olsr_malloc_lq_hello_neighbor(const char *id);
+struct link_entry *olsr_malloc_link_entry(const char *id);
+struct tc_edge_entry *olsr_malloc_tc_edge_entry(const char *id);
+
+#endif /*LQPLUGIN_H_*/
diff --git a/src/lq_plugin_default.c b/src/lq_plugin_default.c
new file mode 100644 (file)
index 0000000..b1445cd
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 "tc_set.h"
+#include "link_set.h"
+#include "lq_route.h"
+#include "lq_packet.h"
+#include "packet.h"
+#include "olsr.h"
+#include "lq_plugin_default.h"
+
+olsr_linkcost default_calc_cost(const void *ptr) {
+  const struct default_lq *lq = ptr;
+  
+  float etx = (lq->lq < 0.1 || lq->nlq < 0.1 ? LINK_COST_BROKEN : 1.0/(lq->lq * lq->nlq));
+  olsr_linkcost cost = (olsr_linkcost)(etx  * LQ_PLUGIN_LC_MULTIPLIER);
+  
+  if (cost > LINK_COST_BROKEN)
+    return LINK_COST_BROKEN;
+  if (cost == 0)
+    return 1;
+  return cost;
+}
+
+int default_olsr_serialize_hello_lq_pair(unsigned char *buff, void *ptr) {
+  struct default_lq *lq = ptr;
+  
+  buff[0] = (unsigned char)(lq->lq * 255);
+  buff[1] = (unsigned char)(lq->nlq * 255);
+  buff[2] = (unsigned char)(0);
+  buff[3] = (unsigned char)(0);
+  
+  return 4;
+}
+
+void default_olsr_deserialize_hello_lq_pair(const olsr_u8_t **curr, void *ptr) {
+  struct default_lq *lq = ptr;
+  
+  pkt_get_lq(curr, &lq->lq);
+  pkt_get_lq(curr, &lq->nlq);
+  pkt_ignore_u16(curr);
+}
+
+olsr_bool default_olsr_is_relevant_costchange(olsr_linkcost c1, olsr_linkcost c2) {
+  if (c1 > c2) {
+    return c2 - c1 > LQ_PLUGIN_RELEVANT_COSTCHANGE;
+  }
+  return c1 - c2 > LQ_PLUGIN_RELEVANT_COSTCHANGE;
+}
+
+int default_olsr_serialize_tc_lq_pair(unsigned char *buff, void *ptr) {
+  struct default_lq *lq = ptr;
+  
+  buff[0] = (unsigned char)(lq->lq * 255);
+  buff[1] = (unsigned char)(lq->nlq * 255);
+  buff[2] = (unsigned char)(0);
+  buff[3] = (unsigned char)(0);
+  
+  return 4;
+}
+
+void default_olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, void *ptr) {
+  struct default_lq *lq = ptr;
+  
+  pkt_get_lq(curr, &lq->lq);
+  pkt_get_lq(curr, &lq->nlq);
+  pkt_ignore_u16(curr);
+}
+
+olsr_linkcost default_packet_loss_worker(void *ptr, olsr_bool lost) {
+  struct default_lq *tlq = ptr;
+  float alpha;
+  
+  // calculate exponental factor for the new link quality, could be directly done in configuration !
+  alpha = 1 / (float)(olsr_cnf->lq_wsize);
+  
+  // exponential moving average
+  tlq->lq *= (1 - alpha);
+  if (lost == 0) {
+    tlq->lq += alpha;
+  }
+  return default_calc_cost(ptr);
+}
+
+void default_olsr_memorize_foreign_hello_lq(void *ptrLocal, void *ptrForeign) {
+  struct default_lq *local = ptrLocal;
+  struct default_lq *foreign = ptrForeign;
+  
+  if (foreign) {
+    local->nlq = foreign->lq;
+  }
+  else {
+    local->nlq = 0;
+  }
+}
+
+void default_olsr_copy_link_lq_into_tc(void *target, void *source) {
+  memcpy(target, source, sizeof(struct default_lq));
+}
+
+void default_olsr_clear_lq(void *target) {
+  memset(target, 0, sizeof(struct default_lq));
+}
+
+const char *default_olsr_print_lq(void *ptr, struct lqtextbuffer *buffer) {
+  struct default_lq *lq = ptr;
+  
+  sprintf(buffer->buf, "%2.3f/%2.3f", lq->lq, lq->nlq);
+  return buffer->buf;
+}
+
+const char *default_olsr_print_cost(olsr_linkcost cost, struct lqtextbuffer *buffer) {
+  sprintf(buffer->buf, "%2.3f", ((float)cost)/LQ_PLUGIN_LC_MULTIPLIER);
+  return buffer->buf;
+}
diff --git a/src/lq_plugin_default.h b/src/lq_plugin_default.h
new file mode 100644 (file)
index 0000000..aec7def
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2008 Henning Rogge <rogge@fgan.de>
+ * 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 LQ_PLUGIN_DEFAULT_H_
+#define LQ_PLUGIN_DEFAULT_H_
+
+#include "olsr_types.h"
+#include "lq_plugin.h"
+
+#define LQ_PLUGIN_LC_MULTIPLIER 1024
+#define LQ_PLUGIN_RELEVANT_COSTCHANGE 8
+
+struct default_lq {
+       float lq, nlq;
+};
+
+olsr_linkcost default_calc_cost(const void *lq);
+
+olsr_bool default_olsr_is_relevant_costchange(olsr_linkcost c1, olsr_linkcost c2);
+
+olsr_linkcost default_packet_loss_worker(void *lq, olsr_bool lost);
+void default_olsr_memorize_foreign_hello_lq(void *local, void *foreign);
+
+int default_olsr_serialize_hello_lq_pair(unsigned char *buff, void *lq);
+void default_olsr_deserialize_hello_lq_pair(const olsr_u8_t **curr, void *lq);
+int default_olsr_serialize_tc_lq_pair(unsigned char *buff, void *lq);
+void default_olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, void *lq);
+
+void default_olsr_copy_link_lq_into_tc(void *target, void *source);
+void default_olsr_clear_lq(void *target);
+
+const char *default_olsr_print_lq(void *ptr, struct lqtextbuffer *buffer);
+const char *default_olsr_print_cost(olsr_linkcost cost, struct lqtextbuffer *buffer);
+
+#endif /*LQ_PLUGIN_DEFAULT_H_*/
index b30d252..90a9804 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;
 }
@@ -111,14 +102,15 @@ olsr_spf_add_cand_tree (struct avl_tree *tree,
 {
 #if !defined(NODEBUG) && defined(DEBUG)
   struct ipaddr_str buf;
+  struct lqtextbuffer lqbuffer;
 #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, &lqbuffer));
 #endif
 
   avl_insert(tree, &tc->cand_tree_node, AVL_DUP);
@@ -137,10 +129,11 @@ olsr_spf_del_cand_tree (struct avl_tree *tree,
 #ifdef DEBUG
 #ifndef NODEBUG
   struct ipaddr_str buf;
+  struct lqtextbuffer lqbuffer;
 #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, &lqbuffer));
 #endif
 
   avl_delete(tree, &tc->cand_tree_node);
@@ -157,13 +150,14 @@ olsr_spf_add_path_list (struct list_node *head, int *path_count,
 {
 #if !defined(NODEBUG) && defined(DEBUG)
   struct ipaddr_str pathbuf, nbuf;
+  struct lqtextbuffer lqbuffer;
 #endif
   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, &lqbuffer),
               tc->next_hop ? olsr_ip_to_string(
                 &nbuf, &tc->next_hop->neighbor_iface_addr) : "-");
 #endif
@@ -197,19 +191,16 @@ 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;
+  struct lqtextbuffer lqbuffer;
 #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, &lqbuffer));
 #endif
 
   /*
@@ -227,13 +218,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 +234,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, &lqbuffer));
 #endif
 
       /* 
@@ -262,15 +248,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 +266,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, &lqbuffer),
                   tc->next_hop ? olsr_ip_to_string(
                     &nbuf, &tc->next_hop->neighbor_iface_addr) : "<none>",
                   new_tc->hops);
@@ -376,7 +361,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 +369,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 +405,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 +454,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 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 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..cebfcc8 100644 (file)
@@ -240,7 +240,7 @@ olsr_init_tables(void)
   olsr_init_link_set();
 
   /* Initialize duplicate table */
-  olsr_init_duplicate_table();
+  olsr_init_duplicate_set();
 
   /* Initialize neighbor table */
   olsr_init_neighbor_table();
@@ -282,9 +282,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 +303,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 +315,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 +341,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..ff9f7d8 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;
            
@@ -341,7 +342,7 @@ olsr_build_tc_packet(struct tc_message *message)
     {
       /* 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");
+      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..4a359ee 100644 (file)
@@ -67,7 +67,7 @@
  * recv() loop never ends. This is a small hack to end
  * the loop in this cases
  */
+
 unsigned int cpu_overload_exit = 0;
 
 struct parse_function_entry *parse_functions;
@@ -77,9 +77,7 @@ static char inbuf[MAXMESSAGESIZE+1];
 
 static olsr_bool disp_pack_in = OLSR_FALSE;
 
-void
-parser_set_disp_pack_in(olsr_bool val)
-{
+void parser_set_disp_pack_in(olsr_bool val) {
   disp_pack_in = val;
 }
 
@@ -88,127 +86,98 @@ parser_set_disp_pack_in(olsr_bool val)
  *
  *@return nada
  */
-void
-olsr_init_parser(void)
-{
+void olsr_init_parser(void) {
   OLSR_PRINTF(3, "Initializing parser...\n");
-
+  
   /* Initialize the packet functions */
   olsr_init_package_process();
-
+  
 }
 
-void
-olsr_parser_add_function(parse_function *function, olsr_u32_t type, int forwarding)
-{
+void olsr_parser_add_function(parse_function *function, olsr_u32_t type, int forwarding) {
   struct parse_function_entry *new_entry;
-
+  
   OLSR_PRINTF(3, "Parser: registering event for type %d\n", type);
-
+  
   new_entry = olsr_malloc(sizeof(struct parse_function_entry), "Register parse function");
-
+  
   new_entry->function = function;
   new_entry->type = type;
   new_entry->caller_forwarding = forwarding;
-
+  
   /* Queue */
   new_entry->next = parse_functions;
   parse_functions = new_entry;
-
+  
   OLSR_PRINTF(3, "Register parse function: Added function for type %d\n", type);
-
+  
 }
 
-
-
-int
-olsr_parser_remove_function(parse_function *function, olsr_u32_t type, int forwarding)
-{
+int olsr_parser_remove_function(parse_function *function, olsr_u32_t type, int forwarding) {
   struct parse_function_entry *entry, *prev;
-
+  
   entry = parse_functions;
   prev = NULL;
-
-  while(entry)
-    {
-      if((entry->function == function) &&
-        (entry->type == type) &&
-        (entry->caller_forwarding == forwarding))
-       {
-         if(entry == parse_functions)
-           {
-             parse_functions = entry->next;
-           }
-         else
-           {
-             prev->next = entry->next;
-           }
-         free(entry);
-         return 1;
-       }
-
-      prev = entry;
-      entry = entry->next;
+  
+  while (entry) {
+    if ((entry->function == function) && (entry->type == type) && (entry->caller_forwarding == forwarding)) {
+      if (entry == parse_functions) {
+        parse_functions = entry->next;
+      } else {
+        prev->next = entry->next;
+      }
+      free(entry);
+      return 1;
     }
-
+    
+    prev = entry;
+    entry = entry->next;
+  }
+  
   return 0;
 }
 
-void
-olsr_preprocessor_add_function(preprocessor_function *function)
-{
+void olsr_preprocessor_add_function(preprocessor_function *function) {
   struct preprocessor_function_entry *new_entry;
-
+  
   OLSR_PRINTF(3, "Parser: registering preprocessor\n");
-
+  
   new_entry = olsr_malloc(sizeof(struct preprocessor_function_entry), "Register preprocessor function");
-
+  
   new_entry->function = function;
-
+  
   /* Queue */
   new_entry->next = preprocessor_functions;
   preprocessor_functions = new_entry;
-
+  
   OLSR_PRINTF(3, "Registered preprocessor function\n");
-
+  
 }
 
-
-
-int
-olsr_preprocessor_remove_function(preprocessor_function *function)
-{
+int olsr_preprocessor_remove_function(preprocessor_function *function) {
   struct preprocessor_function_entry *entry, *prev;
-
+  
   entry = preprocessor_functions;
   prev = NULL;
-
-  while(entry)
-    {
-      if(entry->function == function)
-       {
-         if(entry == preprocessor_functions)
-           {
-                 preprocessor_functions = entry->next;
-           }
-         else
-           {
-             prev->next = entry->next;
-           }
-         free(entry);
-         return 1;
-       }
-
-      prev = entry;
-      entry = entry->next;
+  
+  while (entry) {
+    if (entry->function == function) {
+      if (entry == preprocessor_functions) {
+        preprocessor_functions = entry->next;
+      } else {
+        prev->next = entry->next;
+      }
+      free(entry);
+      return 1;
     }
-
+    
+    prev = entry;
+    entry = entry->next;
+  }
+  
   return 0;
 }
 
-
 /**
  *Process a newly received OLSR packet. Checks the type
  *and to the neccessary convertions and call the
@@ -219,214 +188,192 @@ olsr_preprocessor_remove_function(preprocessor_function *function)
  *@return nada
  */
 
-void
-parse_packet(struct olsr *olsr, int size, struct interface *in_if, union olsr_ip_addr *from_addr)
-{
+void parse_packet(struct olsr *olsr, int size, struct interface *in_if, union olsr_ip_addr *from_addr) {
   union olsr_message *m = (union olsr_message *)olsr->olsr_msg;
   struct unknown_message unkpacket;
   int count;
   int msgsize;
   int processed;
   struct parse_function_entry *entry;
-
+  
   count = size - ((char *)m - (char *)olsr);
-
+  
   if (count < MIN_PACKET_SIZE(olsr_cnf->ip_version))
     return;
-
-  if (ntohs(olsr->olsr_packlen) != size)
-    {
-      struct ipaddr_str buf;
-      OLSR_PRINTF(1, "Size error detected in received packet.\nRecieved %d, in packet %d\n", size, ntohs(olsr->olsr_packlen));
-           
-      olsr_syslog(OLSR_LOG_ERR, " packet length error in  packet received from %s!",
-            olsr_ip_to_string(&buf, from_addr));
-      return;
-    }
-
+  
+  if (ntohs(olsr->olsr_packlen) != size) {
+    struct ipaddr_str buf;
+    OLSR_PRINTF(1, "Size error detected in received packet.\nRecieved %d, in packet %d\n", size, ntohs(olsr->olsr_packlen));
+    
+    olsr_syslog(OLSR_LOG_ERR, " packet length error in  packet received from %s!",
+    olsr_ip_to_string(&buf, from_addr));
+    return;
+  }
+  
   //printf("Message from %s\n\n", olsr_ip_to_string(&buf, from_addr)); 
-      
+
   /* Display packet */
-  if(disp_pack_in)
+  if (disp_pack_in)
     print_olsr_serialized_packet(stdout, (union olsr_packet *)olsr, size, from_addr);
-
-  if(olsr_cnf->ip_version == AF_INET)
+  
+  if (olsr_cnf->ip_version == AF_INET)
     msgsize = ntohs(m->v4.olsr_msgsize);
   else
     msgsize = ntohs(m->v6.olsr_msgsize);
-
-
+  
   /*
    * Hysteresis update - for every OLSR package
    */
-  if(olsr_cnf->use_hysteresis)
-    {
-      if(olsr_cnf->ip_version == AF_INET)
-       {
-         /* IPv4 */
-         update_hysteresis_incoming(from_addr, 
-                                    in_if,
-                                    ntohs(olsr->olsr_seqno));
-       }
-      else
-       {
-         /* IPv6 */
-         update_hysteresis_incoming(from_addr, 
-                                    in_if, 
-                                    ntohs(olsr->olsr_seqno));
-       }
-    }
-
-  if (olsr_cnf->lq_level > 0)
-    {
-      olsr_update_packet_loss(from_addr, in_if,
-                              ntohs(olsr->olsr_seqno));
+  if (olsr_cnf->use_hysteresis) {
+    if (olsr_cnf->ip_version == AF_INET) {
+      /* IPv4 */
+      update_hysteresis_incoming(from_addr, in_if, ntohs(olsr->olsr_seqno));
+    } else {
+      /* IPv6 */
+      update_hysteresis_incoming(from_addr, in_if, ntohs(olsr->olsr_seqno));
     }
+  }
   
-  for ( ; count > 0; m = (union olsr_message *)((char *)m + (msgsize)))
-    {
-
-      processed = 0;      
-      if (count < MIN_PACKET_SIZE(olsr_cnf->ip_version))
-       break;
-      
-      if(olsr_cnf->ip_version == AF_INET)
-       msgsize = ntohs(m->v4.olsr_msgsize);
-      else
-       msgsize = ntohs(m->v6.olsr_msgsize);
+  for (; count > 0; m = (union olsr_message *)((char *)m + (msgsize))) {
+    
+    processed = 0;
+    if (count < MIN_PACKET_SIZE(olsr_cnf->ip_version))
+      break;
+    
+    if (olsr_cnf->ip_version == AF_INET)
+      msgsize = ntohs(m->v4.olsr_msgsize);
+    else
+      msgsize = ntohs(m->v6.olsr_msgsize);
+    
+    count -= msgsize;
+    
+    /* Check size of message */
+    if (count < 0) {
+      struct ipaddr_str buf;
+      OLSR_PRINTF(1, "packet length error in  packet received from %s!",
+          olsr_ip_to_string(&buf, from_addr));
       
-      count -= msgsize;
-
-      /* Check size of message */
-      if(count < 0)
-       {
-          struct ipaddr_str buf;
-         OLSR_PRINTF(1, "packet length error in  packet received from %s!",
-                     olsr_ip_to_string(&buf, from_addr));
-
-         olsr_syslog(OLSR_LOG_ERR, " packet length error in  packet received from %s!",
-                olsr_ip_to_string(&buf, from_addr));
-         break;
-       }
-
-
+      olsr_syslog(OLSR_LOG_ERR, " packet length error in  packet received from %s!",
+      olsr_ip_to_string(&buf, from_addr));
+      break;
+    }
+    
 #if 0
-      /*
-       * Sven-Ola: This code leads to flooding our meshes with invalid /
-       * overdue messages if lq_fish is enabled (which is true since 2005)
-       * because there was no "do not forward"-check in olsr.c. If a message
-       * (yes: ttl=0 is invalid) is received, we should say: Welcome message,
-       * let us evaluate! But: if TTL < 2 or TTL + hopcount is higher than
-       * plausible, we should not forward. See olsr.c:olsr_forward_message()
-       */
-       
-      /* Treat TTL hopcnt */
-      if(olsr_cnf->ip_version == AF_INET)
-       {
-         /* IPv4 */
-         if (m->v4.ttl <= 0 && olsr_cnf->lq_fish == 0)
-           {
+    /*
+     * Sven-Ola: This code leads to flooding our meshes with invalid /
+     * overdue messages if lq_fish is enabled (which is true since 2005)
+     * because there was no "do not forward"-check in olsr.c. If a message
+     * (yes: ttl=0 is invalid) is received, we should say: Welcome message,
+     * let us evaluate! But: if TTL < 2 or TTL + hopcount is higher than
+     * plausible, we should not forward. See olsr.c:olsr_forward_message()
+     */
+
+    /* Treat TTL hopcnt */
+    if(olsr_cnf->ip_version == AF_INET)
+    {
+      /* IPv4 */
+      if (m->v4.ttl <= 0 && olsr_cnf->lq_fish == 0)
+      {
 #ifndef NODEBUG
-              struct ipaddr_str buf;
+        struct ipaddr_str buf;
 #endif
-             OLSR_PRINTF(2, "Dropping packet type %d from neigh %s with TTL 0\n", 
-                         m->v4.olsr_msgtype,
-                         olsr_ip_to_string(&buf, from_addr));
-             continue;
-           }
-       }
-      else
-       {
-         /* IPv6 */
-         if (m->v6.ttl <= 0 && olsr_cnf->lq_fish == 0) 
-           {
+        OLSR_PRINTF(2, "Dropping packet type %d from neigh %s with TTL 0\n",
+            m->v4.olsr_msgtype,
+            olsr_ip_to_string(&buf, from_addr));
+        continue;
+      }
+    }
+    else
+    {
+      /* IPv6 */
+      if (m->v6.ttl <= 0 && olsr_cnf->lq_fish == 0)
+      {
 #ifndef NODEBUG
-              struct ipaddr_str buf;
+        struct ipaddr_str buf;
 #endif
-             OLSR_PRINTF(2, "Dropping packet type %d from %s with TTL 0\n", 
-                         m->v4.olsr_msgtype,
-                         olsr_ip_to_string(&buf, from_addr));
-             continue;
-           }
-       }
+        OLSR_PRINTF(2, "Dropping packet type %d from %s with TTL 0\n",
+            m->v4.olsr_msgtype,
+            olsr_ip_to_string(&buf, from_addr));
+        continue;
+      }
+    }
 #endif
-
-      /*RFC 3626 section 3.4:
-       *  2    If the time to live of the message is less than or equal to
-       *  '0' (zero), or if the message was sent by the receiving node
-       *  (i.e., the Originator Address of the message is the main
-       *  address of the receiving node): the message MUST silently be
-       *  dropped.
-       */
-
-      /* Should be the same for IPv4 and IPv6 */
-      if(ipequal((union olsr_ip_addr *)&m->v4.originator, &olsr_cnf->main_addr) || !olsr_validate_address((union olsr_ip_addr *)&m->v4.originator))
-        {
+    
+    /*RFC 3626 section 3.4:
+     *  2    If the time to live of the message is less than or equal to
+     *  '0' (zero), or if the message was sent by the receiving node
+     *  (i.e., the Originator Address of the message is the main
+     *  address of the receiving node): the message MUST silently be
+     *  dropped.
+     */
+
+    /* Should be the same for IPv4 and IPv6 */
+    if (ipequal((union olsr_ip_addr *)&m->v4.originator, &olsr_cnf->main_addr)
+        || !olsr_validate_address((union olsr_ip_addr *)&m->v4.originator)) {
 #if !defined(NODEBUG) && defined(DEBUG)
-         struct ipaddr_str buf;
+      struct ipaddr_str buf;
 #endif
 #ifdef DEBUG
-         OLSR_PRINTF(3, "Not processing message originating from %s!\n",
-           olsr_ip_to_string(&buf,(union olsr_ip_addr *)&m->v4.originator));
+      OLSR_PRINTF(3, "Not processing message originating from %s!\n",
+          olsr_ip_to_string(&buf,(union olsr_ip_addr *)&m->v4.originator));
 #endif
-          continue;
-        }
-
-
-      //printf("MESSAGETYPE: %d\n", m->v4.olsr_msgtype);
-
-      entry = parse_functions;
-
-      while(entry)
-       {
-         /* Should be the same for IPv4 and IPv6 */
-
-         /* Promiscuous or exact match */
-         if((entry->type == PROMISCUOUS) || 
-            (entry->type == m->v4.olsr_msgtype))
-           {
-             entry->function(m, in_if, from_addr);
-             if(entry->caller_forwarding)
-               processed = 1;
-           }
-         entry = entry->next;
-       }
+      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);
 
+    entry = parse_functions;
+    
+    while (entry) {
+      /* Should be the same for IPv4 and IPv6 */
 
-      /* UNKNOWN PACKETTYPE */
-      if(processed == 0)
-       {
+      /* Promiscuous or exact match */
+      if ((entry->type == PROMISCUOUS) || (entry->type == m->v4.olsr_msgtype)) {
+        entry->function(m, in_if, from_addr);
+        if (entry->caller_forwarding)
+          processed = 1;
+      }
+      entry = entry->next;
+    }
+    
+    /* UNKNOWN PACKETTYPE */
+    if (processed == 0) {
 #ifndef NODEBUG
-          struct ipaddr_str buf;
+      struct ipaddr_str buf;
 #endif
-         unk_chgestruct(&unkpacket, m);
-         
-         OLSR_PRINTF(3, "Unknown type: %d, size %d, from %s\n",
-                     m->v4.olsr_msgtype,
-                     size,
-                     olsr_ip_to_string(&buf, &unkpacket.originator));
-
-         /* Forward message */
-         if(!ipequal(&unkpacket.originator, &olsr_cnf->main_addr))
-           {         
-             /* Forward */
-             olsr_forward_message(m, 
-                                  &unkpacket.originator, 
-                                  unkpacket.seqno, 
-                                  in_if,
-                                  from_addr);
-           }
-
-          /* Cancel loop here, otherwise olsrd just hangs forever at this point */
-          break;
-       }
-
-    } /* for olsr_msg */ 
+      unk_chgestruct(&unkpacket, m);
+      
+      OLSR_PRINTF(3, "Unknown type: %d, size %d, from %s\n",
+          m->v4.olsr_msgtype,
+          size,
+          olsr_ip_to_string(&buf, &unkpacket.originator));
+      
+      /* Forward message */
+      if (!ipequal(&unkpacket.originator, &olsr_cnf->main_addr)) {
+        /* Forward */
+        olsr_forward_message(m, from_addr);
+      }
+      
+      /* Cancel loop here, otherwise olsrd just hangs forever at this point */
+      break;
+    }
+    
+  } /* for olsr_msg */
 }
 
-
-
-
 /**
  *Processing OLSR data from socket. Reading data, setting 
  *wich interface recieved the message, Sends IPC(if used) 
@@ -435,9 +382,7 @@ parse_packet(struct olsr *olsr, int size, struct interface *in_if, union olsr_ip
  *@param fd the filedescriptor that data should be read from.
  *@return nada
  */
-void
-olsr_input(int fd)
-{
+void olsr_input(int fd) {
   struct interface *olsr_in_if;
   union olsr_ip_addr from_addr;
   struct preprocessor_function_entry *entry;
@@ -445,103 +390,85 @@ olsr_input(int fd)
   
   cpu_overload_exit = 0;
   
-  for (;;) 
-    {
+  for (;;) {
 #if !defined(NODEBUG) && defined(DEBUG)
-      struct ipaddr_str buf;
+    struct ipaddr_str buf;
 #endif
-      /* sockaddr_in6 is bigger than sockaddr !!!! */
-      struct sockaddr_storage from;
-      socklen_t fromlen;
-      int cc;
-
-      if (32 < ++cpu_overload_exit)
-      {
-        OLSR_PRINTF(1, "CPU overload detected, ending olsr_input() loop\n");
-       break;
+    /* sockaddr_in6 is bigger than sockaddr !!!! */
+    struct sockaddr_storage from;
+    socklen_t fromlen;
+    int cc;
+    
+    if (32 < ++cpu_overload_exit) {
+      OLSR_PRINTF(1, "CPU overload detected, ending olsr_input() loop\n");
+      break;
+    }
+    
+    fromlen = sizeof(struct sockaddr_storage);
+    cc = olsr_recvfrom(fd, inbuf, sizeof (inbuf), 0, (struct sockaddr *)&from, &fromlen);
+    
+    if (cc <= 0) {
+      if (cc < 0 && errno != EWOULDBLOCK) {
+        OLSR_PRINTF(1, "error recvfrom: %s", strerror(errno));
+        olsr_syslog(OLSR_LOG_ERR, "error recvfrom: %m");
       }
-      
-      fromlen = sizeof(struct sockaddr_storage);
-      cc = olsr_recvfrom(fd, 
-                        inbuf, 
-                        sizeof (inbuf), 
-                        0, 
-                        (struct sockaddr *)&from, 
-                        &fromlen);
-
-      if (cc <= 0) 
-       {
-         if (cc < 0 && errno != EWOULDBLOCK)
-           {
-             OLSR_PRINTF(1, "error recvfrom: %s", strerror(errno));
-             olsr_syslog(OLSR_LOG_ERR, "error recvfrom: %m");
-           }
-         break;
-       }
-      if(olsr_cnf->ip_version == AF_INET)
-       {
-         /* IPv4 sender address */
-         from_addr.v4 = ((struct sockaddr_in *)&from)->sin_addr;
-       }
-      else
-       {
-         /* IPv6 sender address */
-         from_addr.v6 = ((struct sockaddr_in6 *)&from)->sin6_addr;
-       }
-      
-      
+      break;
+    }
+    if (olsr_cnf->ip_version == AF_INET) {
+      /* IPv4 sender address */
+      from_addr.v4 = ((struct sockaddr_in *)&from)->sin_addr;
+    } else {
+      /* IPv6 sender address */
+      from_addr.v6 = ((struct sockaddr_in6 *)&from)->sin6_addr;
+    }
+    
 #ifdef DEBUG
-      OLSR_PRINTF(5, "Recieved a packet from %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr));
+    OLSR_PRINTF(5, "Recieved a packet from %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr));
 #endif
-       
-       if ((olsr_cnf->ip_version == AF_INET) && (fromlen != sizeof (struct sockaddr_in)))
-         break;
-       else if ((olsr_cnf->ip_version == AF_INET6) && (fromlen != sizeof (struct sockaddr_in6)))
-         break;
-      
-      /* are we talking to ourselves? */
-      if(if_ifwithaddr(&from_addr) != NULL)
-       return;
-      
-      if((olsr_in_if = if_ifwithsock(fd)) == NULL)
-       {
-          struct ipaddr_str buf;
-         OLSR_PRINTF(1, "Could not find input interface for message from %s size %d\n",
-                     olsr_ip_to_string(&buf, &from_addr),
-                     cc);
-         olsr_syslog(OLSR_LOG_ERR, "Could not find input interface for message from %s size %d\n",
-                olsr_ip_to_string(&buf, &from_addr),
-                cc);
-         return ;
-       }
-
-      // call preprocessors
-      entry = preprocessor_functions;
-      packet = &inbuf[0];
-      
-      while(entry)
-        {
-             packet = entry->function(packet, olsr_in_if, &from_addr, &cc);
-             // discard package ?
-             if (packet == NULL) {
-               return;
-             }
-             entry = entry->next;
-        }
-      
-      /*
-       * &from - sender
-       * &inbuf.olsr 
-       * cc - bytes read
-       */
-      parse_packet((struct olsr *)packet, cc, olsr_in_if, &from_addr);
     
+    if ((olsr_cnf->ip_version == AF_INET) && (fromlen != sizeof(struct sockaddr_in)))
+      break;
+    else if ((olsr_cnf->ip_version == AF_INET6) && (fromlen != sizeof(struct sockaddr_in6)))
+      break;
+    
+    /* are we talking to ourselves? */
+    if (if_ifwithaddr(&from_addr) != NULL)
+      return;
+    
+    if ((olsr_in_if = if_ifwithsock(fd)) == NULL) {
+      struct ipaddr_str buf;
+      OLSR_PRINTF(1, "Could not find input interface for message from %s size %d\n",
+          olsr_ip_to_string(&buf, &from_addr),
+          cc);
+      olsr_syslog(OLSR_LOG_ERR, "Could not find input interface for message from %s size %d\n",
+      olsr_ip_to_string(&buf, &from_addr),
+      cc);
+      return;
+    }
+    
+    // call preprocessors
+    entry = preprocessor_functions;
+    packet = &inbuf[0];
+    
+    while (entry) {
+      packet = entry->function(packet, olsr_in_if, &from_addr, &cc);
+      // discard package ?
+      if (packet == NULL) {
+        return;
+      }
+      entry = entry->next;
     }
+    
+    /*
+     * &from - sender
+     * &inbuf.olsr 
+     * cc - bytes read
+     */
+    parse_packet((struct olsr *)packet, cc, olsr_in_if, &from_addr);
+    
+  }
 }
 
-
-
-
 /**
  *Processing OLSR data from socket. Reading data, setting 
  *wich interface recieved the message, Sends IPC(if used) 
@@ -550,9 +477,7 @@ olsr_input(int fd)
  *@param fd the filedescriptor that data should be read from.
  *@return nada
  */
-void
-olsr_input_hostemu(int fd)
-{
+void olsr_input_hostemu(int fd) {
   /* sockaddr_in6 is bigger than sockaddr !!!! */
   struct sockaddr_storage from;
   socklen_t fromlen;
@@ -561,88 +486,74 @@ olsr_input_hostemu(int fd)
   olsr_u16_t pcklen;
   struct preprocessor_function_entry *entry;
   char *packet;
-
+  
   /* Host emulator receives IP address first to emulate
-     direct link */
+   direct link */
 
   int cc = recv(fd, from_addr.v6.s6_addr, olsr_cnf->ipsize, 0);
-  if(cc != (int)olsr_cnf->ipsize)
-    {
-      fprintf(stderr, "Error receiving host-client IP hook(%d) %s!\n", cc, strerror(errno));
-      memcpy(&from_addr, &((struct olsr *)inbuf)->olsr_msg->originator, olsr_cnf->ipsize);
-    }
-
+  if (cc != (int)olsr_cnf->ipsize) {
+    fprintf(stderr, "Error receiving host-client IP hook(%d) %s!\n", cc, strerror(errno));
+    memcpy(&from_addr, &((struct olsr *)inbuf)->olsr_msg->originator, olsr_cnf->ipsize);
+  }
+  
   /* are we talking to ourselves? */
-  if(if_ifwithaddr(&from_addr) != NULL)
+  if (if_ifwithaddr(&from_addr) != NULL)
     return;
-      
+  
   /* Extract size */
-  if((cc = recv(fd, (void *)&pcklen, 2, MSG_PEEK)) != 2) /* Win needs a cast */
-    {
-      if(cc <= 0)
-       {
-         fprintf(stderr, "Lost olsr_switch connection - exit!\n");
-         olsr_exit(__func__, EXIT_FAILURE);
-       }
-      fprintf(stderr, "[hust-emu] error extracting size(%d) %s!\n", cc, strerror(errno));
-      return;
+  if ((cc = recv(fd, (void *)&pcklen, 2, MSG_PEEK)) != 2) /* Win needs a cast */
+  {
+    if (cc <= 0) {
+      fprintf(stderr, "Lost olsr_switch connection - exit!\n");
+      olsr_exit(__func__, EXIT_FAILURE);
     }
-  else
-    {
-      pcklen = ntohs(pcklen);
-    }
-
+    fprintf(stderr, "[hust-emu] error extracting size(%d) %s!\n", cc, strerror(errno));
+    return;
+  } else {
+    pcklen = ntohs(pcklen);
+  }
+  
   fromlen = sizeof(struct sockaddr_storage);
   
-  cc = olsr_recvfrom(fd, 
-                    inbuf, 
-                    pcklen, 
-                    0, 
-                    (struct sockaddr *)&from, 
-                    &fromlen);
-
-  if (cc <= 0) 
-    {
-      if (cc < 0 && errno != EWOULDBLOCK)
-       {
-          const char * const err_msg = strerror(errno);
-         OLSR_PRINTF(1, "error recvfrom: %s", err_msg);
-          olsr_syslog(OLSR_LOG_ERR, "error recvfrom: %s", err_msg);
-       }
-      return;
-    }
+  cc = olsr_recvfrom(fd, inbuf, pcklen, 0, (struct sockaddr *)&from, &fromlen);
   
-  if(cc != pcklen)
-    {
-      printf("Could not read whole packet(size %d, read %d)\n", pcklen, cc);
-      return;
-    }
-
-  if((olsr_in_if = if_ifwithsock(fd)) == NULL)
-    {
-      struct ipaddr_str buf;
-      OLSR_PRINTF(1, "Could not find input interface for message from %s size %d\n",
-                 olsr_ip_to_string(&buf, &from_addr),
-                 cc);
-      olsr_syslog(OLSR_LOG_ERR, "Could not find input interface for message from %s size %d\n",
-                  olsr_ip_to_string(&buf, &from_addr),
-                  cc);
-      return;
+  if (cc <= 0) {
+    if (cc < 0 && errno != EWOULDBLOCK) {
+      const char * const err_msg = strerror(errno);
+      OLSR_PRINTF(1, "error recvfrom: %s", err_msg);
+      olsr_syslog(OLSR_LOG_ERR, "error recvfrom: %s", err_msg);
     }
+    return;
+  }
+  
+  if (cc != pcklen) {
+    printf("Could not read whole packet(size %d, read %d)\n", pcklen, cc);
+    return;
+  }
+  
+  if ((olsr_in_if = if_ifwithsock(fd)) == NULL) {
+    struct ipaddr_str buf;
+    OLSR_PRINTF(1, "Could not find input interface for message from %s size %d\n",
+        olsr_ip_to_string(&buf, &from_addr),
+        cc);
+    olsr_syslog(OLSR_LOG_ERR, "Could not find input interface for message from %s size %d\n",
+    olsr_ip_to_string(&buf, &from_addr),
+    cc);
+    return;
+  }
   
   // call preprocessors
   entry = preprocessor_functions;
   packet = &inbuf[0];
   
-  while(entry)
-    {
-      packet = entry->function(packet, olsr_in_if, &from_addr, &cc);
-      // discard package ?
-      if (packet == NULL) {
-        return;
-      }
-      entry = entry->next;
+  while (entry) {
+    packet = entry->function(packet, olsr_in_if, &from_addr, &cc);
+    // discard package ?
+    if (packet == NULL) {
+      return;
     }
+    entry = entry->next;
+  }
   
   /*
    * &from - sender
@@ -653,4 +564,3 @@ olsr_input_hostemu(int fd)
   
 }
 
-
index c66818e..1e0a2cf 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;
@@ -689,7 +527,7 @@ olsr_hello_tap(struct hello_message *message,
 
 void
 olsr_process_received_mid(union olsr_message *m,
-                          struct interface *in_if,
+                          struct interface *in_if __attribute__((unused)),
                           union olsr_ip_addr *from_addr)
 {
 #if !defined(NODEBUG) && defined(DEBUG)
@@ -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);
 }
 
@@ -766,7 +596,7 @@ olsr_process_received_mid(union olsr_message *m,
 
 void
 olsr_process_received_hna(union olsr_message *m,
-                          struct interface *in_if,
+                          struct interface *in_if __attribute__((unused)),
                           union olsr_ip_addr *from_addr)
 {
 
@@ -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..ee75e14 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) {
@@ -651,15 +644,16 @@ olsr_rtp_to_string(const struct rt_path *rtp)
   static char buff[128];
   struct ipaddr_str prefixstr, origstr, gwstr;
   struct rt_entry *rt = rtp->rtp_rt;
-
+  struct lqtextbuffer lqbuffer;
+  
   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, &lqbuffer),
            rtp->rtp_metric.hops,
            rtp->rtp_version);
 
@@ -676,7 +670,8 @@ olsr_print_routing_table(const struct avl_tree *tree)
 #ifndef NODEBUG
   /* The whole function makes no sense without it. */
   const struct avl_node *rt_tree_node;
-
+  struct lqtextbuffer lqbuffer;
+  
   OLSR_PRINTF(6, "ROUTING TABLE\n");
 
   for (rt_tree_node = avl_walk_first_c(tree);
@@ -698,9 +693,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, &lqbuffer),
              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 ec12b85..9ec58b4 100644 (file)
@@ -68,7 +68,7 @@ static int hfd = 0;
  *@param pf the processing function
  */
 void
-add_olsr_socket(int fd, void(*pf)(int))
+add_olsr_socket(int fd, void(*pf)(int fd))
 {
   struct olsr_socket_entry *new_entry;
 
index 6ea4b49..b63e35f 100644 (file)
@@ -46,7 +46,8 @@
 struct olsr_socket_entry
 {
   int fd;
-  void(*process_function)(int);
+  int arp_type;
+  void(*process_function)(int fd);
   struct olsr_socket_entry *next;
 };
 
index c15cc1a..cb964f6 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>
 
@@ -284,14 +285,14 @@ olsr_tc_edge_to_string(struct tc_edge_entry *tc_edge)
   static char buf[128];
   struct ipaddr_str addrbuf, dstbuf;
   struct tc_entry *tc = tc_edge->tc;
-
+  struct lqtextbuffer lqbuffer1, lqbuffer2;
+  
   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, &lqbuffer1),
+           get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer2));
 
   return buf;
 }
@@ -327,28 +328,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 +356,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 +364,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 +375,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 +515,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 +526,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 +536,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 +552,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 +570,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 +642,17 @@ 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",
+      struct lqtextbuffer lqbuffer1, lqbuffer2;
+      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, &lqbuffer1),
+                  get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer2));
     } 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.
  *
@@ -796,7 +664,8 @@ olsr_calc_tc_etx(const struct tc_edge_entry *tc_edge)
  * hence the spot we are looking at.
  */
 void
-olsr_input_tc(union olsr_message *msg, struct interface *input_if,
+olsr_input_tc(union olsr_message *msg,
+              struct interface *input_if __attribute__((unused)),
               union olsr_ip_addr *from_addr)
 {
 #ifndef NODEBUG 
@@ -918,7 +787,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 +803,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..13a0d65 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,22 +143,10 @@ 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);
 
 #endif
index 4d62c3d..0621b6f 100644 (file)
@@ -253,6 +253,7 @@ olsr_print_two_hop_neighbor_table(void)
            entry != &neigh2->neighbor_2_nblist;
            entry = entry->next) {
         struct ipaddr_str buf;
+        struct lqtextbuffer lqbuffer;
         if (first) {
           OLSR_PRINTF(1, "%-15s  ",
                       olsr_ip_to_string(&buf, &neigh2->neighbor_2_addr));
@@ -262,7 +263,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, &lqbuffer));
       }
     }
   }
index 04e8c2e..c8d920f 100644 (file)
@@ -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;
 };