Small bugfixes in linkset code
authorHenning Rogge <rogge@fgan.de>
Wed, 26 Mar 2008 12:21:28 +0000 (13:21 +0100)
committerHenning Rogge <rogge@fgan.de>
Wed, 26 Mar 2008 12:21:28 +0000 (13:21 +0100)
added FPM-based routing plugin

19 files changed:
lib/Makefile
lib/bmf/src/NetworkInterfaces.c
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/nameservice/src/mapwrite.c
lib/nameservice/src/nameservice.c
lib/tas/src/plugin.c
lib/txtinfo/src/olsrd_txtinfo.c
src/duplicate_set.c
src/link_set.c
src/lq_packet.c
src/lq_plugin.c
src/lq_plugin.h
src/lq_plugin_default.c
src/lq_plugin_default.h
src/lq_route.c
src/routing_table.c
src/tc_set.c
src/two_hop_neighbor_table.c

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 3a458b2..7045dec 100644 (file)
@@ -852,6 +852,7 @@ void FindNeighbors(
 #ifndef NODEBUG
           struct interface* bestIntf = if_ifwithaddr(&bestLinkToNeighbor->local_iface_addr);
           struct ipaddr_str buf;
+          struct lqtextbuffer lqbuffer;
 #endif
           OLSR_PRINTF(
             9,
@@ -859,7 +860,7 @@ void FindNeighbors(
             PLUGIN_NAME_SHORT,
             olsr_ip_to_string(&buf, &walker->neighbor_iface_addr),
             bestIntf->int_name,
-            get_linkcost_text(bestLinkToNeighbor->linkcost, OLSR_FALSE));
+            get_linkcost_text(bestLinkToNeighbor->linkcost, OLSR_FALSE, &lqbuffer));
         }
 
         continue; /* for */
@@ -869,6 +870,7 @@ void FindNeighbors(
       {
 #ifndef NODEBUG
         struct ipaddr_str forwardedByBuf, niaBuf;
+        struct lqtextbuffer lqbuffer;
 #endif
         OLSR_PRINTF(
           9,
@@ -876,7 +878,7 @@ void FindNeighbors(
           PLUGIN_NAME_SHORT,
           olsr_ip_to_string(&forwardedByBuf, forwardedBy),
           olsr_ip_to_string(&niaBuf, &walker->neighbor_iface_addr),
-          get_linkcost_text(previousLinkEtx + currEtx, OLSR_TRUE));
+          get_linkcost_text(previousLinkEtx + currEtx, OLSR_TRUE, &lqbuffer));
       }
 
       /* Check the topology table whether the 'forwardedBy' node is itself a direct
@@ -903,6 +905,7 @@ void FindNeighbors(
             {
 #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(
@@ -912,7 +915,7 @@ void FindNeighbors(
                 neighbor_iface_buf.buf,
                 olsr_ip_to_string(&forw_buf, forwardedBy),
                 neighbor_iface_buf.buf,
-                get_linkcost_text(tcEtx, OLSR_FALSE));
+                get_linkcost_text(tcEtx, OLSR_FALSE, &lqbuffer));
 
               continue; /* for */
             } /* if */
index 4811be8..a2b1b1e 100644 (file)
@@ -159,7 +159,8 @@ ipc_print_neigh_link(const struct neighbor_entry *neighbor)
   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 {   
@@ -173,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),
-               get_linkcost_text(etx, OLSR_FALSE),
+               get_linkcost_text(etx, OLSR_FALSE, &lqbuffer),
                style);
   
   if (neighbor->is_mpr) {
@@ -337,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),
-               get_linkcost_text(dst_entry->cost, OLSR_FALSE));
+               get_linkcost_text(dst_entry->cost, OLSR_FALSE, &lqbuffer));
 }
 
 
index 87cf489..3235478 100644 (file)
@@ -751,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,
@@ -765,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>",
-                   get_linkcost_text(rt->rt_best->rtp_metric.cost, OLSR_TRUE));
+                   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));
@@ -987,10 +988,11 @@ static int build_neigh_body(char *buf, olsr_u32_t bufsize)
     size += build_ipaddr_with_link(&buf[size], bufsize, &link->neighbor_iface_addr, -1);
     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) %s</td>",
-                       get_link_entry_text(link),
-                       get_linkcost_text(link->linkcost, OLSR_FALSE));
+                       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);
@@ -1055,10 +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) %s</td>\n",
-                               get_tc_edge_entry_text(tc_edge),
-                               get_linkcost_text(tc_edge->cost, OLSR_FALSE));
+                               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");
 
index 1c15ed1..a339104 100644 (file)
@@ -176,13 +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);\n", 
             olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
             olsr_ip_to_string(&strbuf2, &tc->addr), 
-            get_linkcost_text(tc_edge->cost, OLSR_FALSE),
+            get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer),
             lla, llb))
       {
         return;
@@ -190,13 +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);\n", 
             olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
             olsr_ip_to_string(&strbuf2, &tc->addr), 
-            get_linkcost_text(tc_edge->cost, OLSR_FALSE)))
+            get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer)))
       {
         return;
       }
index 2ded8f3..37eb749 100644 (file)
@@ -1227,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, cost %s\n",
                                                olsr_ip_to_string(&strbuf, &rt1->rt_dst.prefix),
-                                               get_linkcost_text(rt1->rt_best->rtp_metric.cost, OLSR_TRUE));
+                                               get_linkcost_text(rt1->rt_best->rtp_metric.cost, OLSR_TRUE, &lqbuffer));
 
                        rt[nameserver_idx] = rt2;
                        rt[nameserver_idx+1] = rt1;
@@ -1274,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);
 
@@ -1288,7 +1290,7 @@ write_resolv_file(void)
                                *nameserver_routes = route;
                                OLSR_PRINTF(6, "NAME PLUGIN: found nameserver %s, cost %s",
                                                        olsr_ip_to_string(&strbuf, &name->ip),
-                                                       get_linkcost_text(route->rt_best->rtp_metric.cost, OLSR_TRUE));
+                                                       get_linkcost_text(route->rt_best->rtp_metric.cost, OLSR_TRUE, &lqbuffer));
 
                                /* find the closet one */
                                select_best_nameserver(nameserver_routes);
index a16c98e..d3bb0b3 100644 (file)
@@ -107,7 +107,8 @@ static void __attribute__((constructor)) banner(void)
 int iterLinkTabNext(char *buff, int len)
 {
   struct list_node *link_node;
-
+  struct lqtextbuffer lqbuffer;
+  
   if (iterLinkTab == NULL)
     return -1;
 
@@ -116,7 +117,7 @@ int iterLinkTabNext(char *buff, int len)
            rawIpAddrToString(&iterLinkTab->neighbor_iface_addr, ipAddrLen),
            rawIpAddrToString(&iterLinkTab->neighbor->neighbor_main_addr, ipAddrLen),
            iterLinkTab->L_link_quality,
-           get_linkcost_text(iterLinkTab->linkcost, OLSR_FALSE));
+           get_linkcost_text(iterLinkTab->linkcost, OLSR_FALSE, &lqbuffer));
 
 
   link_node = iterLinkTab->link_list.next;
@@ -277,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;
@@ -295,7 +297,7 @@ int iterTcTabNext(char *buff, int len)
 
     res = snprintf(buff, len, "[~%d~address~%s~cost~%s~]~", i,
                    rawIpAddrToString(&tc_edge->T_dest_addr, ipAddrLen),
-                   get_linkcost_text(tc_edge->cost, OLSR_FALSE));
+                   get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer));
 
     if (res < len)
       buff += res;
index e5ccf75..979bf6f 100644 (file)
@@ -348,6 +348,8 @@ 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\tLinkcost\n");
@@ -358,8 +360,8 @@ static void ipc_print_link(void)
                    olsr_ip_to_string(&buf1, &link->local_iface_addr),
                    olsr_ip_to_string(&buf2, &link->neighbor_iface_addr),
                    link->L_link_quality, 
-                   get_link_entry_text(link),
-                   get_linkcost_text(link->linkcost, OLSR_FALSE));
+                   get_link_entry_text(link, &lqbuffer1),
+                   get_linkcost_text(link->linkcost, OLSR_FALSE, &lqbuffer2));
     } OLSR_FOR_ALL_LINK_ENTRIES_END(link);
 
     ipc_sendf("\n");
@@ -370,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 */
@@ -385,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,
-                   get_linkcost_text(rt->rt_best->rtp_metric.cost, OLSR_TRUE),
+                   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");
@@ -403,11 +406,12 @@ static void ipc_print_topology(void)
         struct tc_edge_entry *tc_edge;
         OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
             struct ipaddr_str dstbuf, addrbuf;
+            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), 
-                       get_tc_edge_entry_text(tc_edge),
-                       get_linkcost_text(tc_edge->cost, OLSR_FALSE));
+                       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 f41db9f..a425ddc 100644 (file)
@@ -26,7 +26,9 @@ 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) {
@@ -59,6 +61,7 @@ int olsr_shall_process_message(void *ip, olsr_u16_t seqnr) {
       entry->array = 1;
       return 1;
     }
+    OLSR_PRINTF(9, "blocked %x from %s\n", seqnr, olsr_ip_to_string(&buf, mainIp));
     return 0;
   }
   
@@ -67,11 +70,11 @@ int olsr_shall_process_message(void *ip, olsr_u16_t seqnr) {
     olsr_u32_t bitmask = 1 << ((olsr_u32_t) (-diff));
     
     if ((entry->array & bitmask) != 0) {
-//      printf("blocked\n");
+      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;
-//    printf("processed\n");
+    OLSR_PRINTF(9, "processed %x from %s\n", seqnr, olsr_ip_to_string(&buf, mainIp));
     return 1;
   }
   else if (diff < 32) {
@@ -82,7 +85,7 @@ int olsr_shall_process_message(void *ip, olsr_u16_t seqnr) {
   }
   entry->array |= 1;
   entry->seqnr = seqnr;
-//  printf("processed\n");
+  OLSR_PRINTF(9, "processed %x from %s\n", seqnr, olsr_ip_to_string(&buf, mainIp));
   return 1;
 }
 
index 7705554..5854b51 100644 (file)
@@ -839,11 +839,12 @@ void olsr_print_link_set(void)
   OLSR_FOR_ALL_LINK_ENTRIES(walker) {
 
     struct ipaddr_str buf;
+    struct lqtextbuffer lqbuffer1, lqbuffer2;
     OLSR_PRINTF(1, "%-*s  %5.3f  %-13s %s\n",
                 addrsize, olsr_ip_to_string(&buf, &walker->neighbor_iface_addr),
                 walker->L_link_quality,
-                get_link_entry_text(walker),
-                get_linkcost_text(walker->linkcost, OLSR_FALSE));
+                get_link_entry_text(walker, &lqbuffer1),
+                get_linkcost_text(walker->linkcost, OLSR_FALSE, &lqbuffer2));
   } OLSR_FOR_ALL_LINK_ENTRIES_END(walker);
 #endif
 }
index 499b628..de69cf1 100644 (file)
@@ -222,15 +222,22 @@ 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_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) {
       olsr_copylq_link_entry_2_tc_mpr_addr(neigh, lnk);
     }
index af89ffd..336c379 100644 (file)
@@ -44,6 +44,7 @@
 #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"
@@ -85,7 +86,7 @@ struct lq_handler *active_lq_handler = &default_lq_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, char *name) {
+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;
@@ -236,10 +237,11 @@ void olsr_memorize_foreign_hello_lq(struct link_entry *local, struct hello_neigh
  * 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
  */
-char *get_link_entry_text(struct link_entry *entry) {
-  return active_lq_handler->print_hello_lq(entry->linkquality);
+const char *get_link_entry_text(struct link_entry *entry, struct lqtextbuffer *buffer) {
+  return active_lq_handler->print_hello_lq(entry->linkquality, buffer);
 }
 
 /*
@@ -252,11 +254,11 @@ char *get_link_entry_text(struct link_entry *entry) {
  * @param pointer to tc_edge_entry
  * @return pointer to a buffer with the text representation
  */
-char *get_tc_edge_entry_text(struct tc_edge_entry *entry) {
-  return active_lq_handler->print_tc_lq(entry->linkquality);
+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);
 }
 
-const char *get_linkcost_text(olsr_linkcost cost, olsr_bool route) {
+const char *get_linkcost_text(olsr_linkcost cost, olsr_bool route, struct lqtextbuffer *buffer) {
   static const char *infinite = "INFINITE";
   
   if (route) {
@@ -269,7 +271,7 @@ const char *get_linkcost_text(olsr_linkcost cost, olsr_bool route) {
       return infinite;
     }
   }
-  return active_lq_handler->print_cost(cost);
+  return active_lq_handler->print_cost(cost, buffer);
 }
 
 /*
index 3988919..e90f3f0 100644 (file)
 #include "lq_packet.h"
 #include "packet.h"
 
-#define LINK_COST_BROKEN 65535
+#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);
@@ -69,15 +73,15 @@ struct lq_handler {
   void (*deserialize_hello_lq)(const olsr_u8_t **curr, void *lq);
   void (*deserialize_tc_lq)(const olsr_u8_t **curr, void *lq);
   
-  char *(*print_hello_lq)(void *ptr);
-  char *(*print_tc_lq)(void *ptr);
-  char *(*print_cost)(olsr_linkcost cost);
+  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, char *name);
+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);
@@ -90,9 +94,9 @@ void olsr_deserialize_tc_lq_pair(const olsr_u8_t **curr, struct tc_edge_entry *e
 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);
 
-char *get_link_entry_text(struct link_entry *entry);
-char *get_tc_edge_entry_text(struct tc_edge_entry *entry);
-const char *get_linkcost_text(olsr_linkcost cost, olsr_bool route);
+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);
index 36f6811..2a41439 100644 (file)
@@ -139,16 +139,14 @@ void default_olsr_clear_lq(void *target) {
   memset(target, 0, sizeof(struct default_lq));
 }
 
-char *default_olsr_print_lq(void *ptr) {
-  static char output_buffer[16];
+const char *default_olsr_print_lq(void *ptr, struct lqtextbuffer *buffer) {
   struct default_lq *lq = ptr;
   
-  sprintf(output_buffer, "%2.3f/%2.3f", lq->lq, lq->nlq);
-  return output_buffer;
+  sprintf(buffer->buf, "%2.3f/%2.3f", lq->lq, lq->nlq);
+  return buffer->buf;
 }
 
-char *default_olsr_print_cost(olsr_linkcost cost) {
-  static char output_buffer[16];
-  sprintf(output_buffer, "%2.3f", ((float)cost)/LQ_PLUGIN_LC_MULTIPLIER);
-  return output_buffer;
+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;
 }
index ca0539b..c665fef 100644 (file)
 #define LQ_PLUGIN_DEFAULT_H_
 
 #include "olsr_types.h"
+#include "lq_plugin.h"
 
 #define LQ_PLUGIN_LC_MULTIPLIER 1024
-#define LQ_PLUGIN_RELEVANT_COSTCHANGE 16
+#define LQ_PLUGIN_RELEVANT_COSTCHANGE 8
 
 struct default_lq {
        float lq, nlq;
@@ -65,7 +66,7 @@ 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);
 
-char *default_olsr_print_lq(void *ptr);
-char *default_olsr_print_cost(olsr_linkcost cost);
+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 b0d6847..90a9804 100644 (file)
@@ -102,6 +102,7 @@ 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_cost;
   tc->cand_tree_node.data = tc;
@@ -109,7 +110,7 @@ olsr_spf_add_cand_tree (struct avl_tree *tree,
 #ifdef DEBUG
   OLSR_PRINTF(2, "SPF: insert candidate %s, cost %s\n",
               olsr_ip_to_string(&buf, &tc->addr),
-              get_linkcost_text(tc->path_cost, OLSR_FALSE));
+              get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer));
 #endif
 
   avl_insert(tree, &tc->cand_tree_node, AVL_DUP);
@@ -128,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(2, "SPF: delete candidate %s, cost %s\n",
               olsr_ip_to_string(&buf, &tc->addr),
-              get_linkcost_text(tc->path_cost, OLSR_FALSE));
+              get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer));
 #endif
 
   avl_delete(tree, &tc->cand_tree_node);
@@ -148,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(2, "SPF: append path %s, cost %s, via %s\n",
               olsr_ip_to_string(&pathbuf, &tc->addr),
-              get_linkcost_text(tc->path_cost, OLSR_FALSE),
+              get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer),
               tc->next_hop ? olsr_ip_to_string(
                 &nbuf, &tc->next_hop->neighbor_iface_addr) : "-");
 #endif
@@ -193,10 +196,11 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
 #ifdef DEBUG
 #ifndef NODEBUG
   struct ipaddr_str buf, nbuf;
+  struct lqtextbuffer lqbuffer;
 #endif
   OLSR_PRINTF(2, "SPF: exploring node %s, cost %s\n",
               olsr_ip_to_string(&buf, &tc->addr),
-              get_linkcost_text(tc->path_cost, OLSR_FALSE));
+              get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer));
 #endif
 
   /*
@@ -235,7 +239,7 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
 #ifdef DEBUG
       OLSR_PRINTF(2, "SPF:   exploring edge %s, cost %s\n",
                   olsr_ip_to_string(&buf, &tc_edge->T_dest_addr),
-                  get_linkcost_text(new_cost, OLSR_TRUE));
+                  get_linkcost_text(new_cost, OLSR_TRUE, &lqbuffer));
 #endif
 
       /* 
@@ -264,7 +268,7 @@ olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
 #ifdef DEBUG
       OLSR_PRINTF(2, "SPF:   better path to %s, cost %s, via %s, hops %u\n",
                   olsr_ip_to_string(&buf, &new_tc->addr),
-                  get_linkcost_text(new_cost, OLSR_TRUE),
+                  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);
index e720d09..ee75e14 100644 (file)
@@ -644,7 +644,8 @@ 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, "
            "cost %s, metric %u, v %u",
@@ -652,7 +653,7 @@ olsr_rtp_to_string(const struct rt_path *rtp)
            rt->rt_dst.prefix_len,
            olsr_ip_to_string(&origstr, &rtp->rtp_originator),
            olsr_ip_to_string(&gwstr, &rtp->rtp_nexthop.gateway),
-           get_linkcost_text(rtp->rtp_metric.cost, OLSR_TRUE),
+           get_linkcost_text(rtp->rtp_metric.cost, OLSR_TRUE, &lqbuffer),
            rtp->rtp_metric.hops,
            rtp->rtp_version);
 
@@ -669,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);
@@ -693,7 +695,7 @@ olsr_print_routing_table(const struct avl_tree *tree)
       const struct rt_path * const rtp = rtp_tree_node->data;
       OLSR_PRINTF(6, "\tfrom %s, cost %s, metric %u, via %s, %s, v %u\n",
              olsr_ip_to_string(&origstr, &rtp->rtp_originator),
-             get_linkcost_text(rtp->rtp_metric.cost, OLSR_TRUE),
+             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 f21d5cf..6cd8b47 100644 (file)
@@ -285,13 +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, cost (%6s) %s",
            olsr_ip_to_string(&addrbuf, &tc->addr),
            olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr),
-           get_tc_edge_entry_text(tc_edge),
-           get_linkcost_text(tc_edge->cost, OLSR_FALSE));
+           get_tc_edge_entry_text(tc_edge, &lqbuffer1),
+           get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer2));
 
   return buf;
 }
@@ -641,11 +642,12 @@ 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;
+      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),
-                  get_tc_edge_entry_text(tc_edge),
-                  get_linkcost_text(tc_edge->cost, OLSR_FALSE));
+                  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
index 3554295..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),
-                    get_linkcost_text(entry->path_linkcost, OLSR_FALSE));
+                    get_linkcost_text(entry->path_linkcost, OLSR_FALSE, &lqbuffer));
       }
     }
   }