Some minor and trivial cleanup: Added two functions to calculate the ETX
authorBernd Petrovitsch <bernd@firmix.at>
Fri, 2 Nov 2007 20:58:07 +0000 (20:58 +0000)
committerBernd Petrovitsch <bernd@firmix.at>
Fri, 2 Nov 2007 20:58:07 +0000 (20:58 +0000)
value from a struct tc_edge_entry and a struct link_entry, respectively.
And use them everywhere.

CHANGELOG
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/nameservice/src/nameservice.c
lib/pgraph/src/olsrd_pgraph.c
lib/tas/src/plugin.c
lib/txtinfo/src/olsrd_txtinfo.c
src/link_set.c
src/link_set.h
src/tc_set.c
src/tc_set.h

index bd16059..410e1b9 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,5 @@
 This file states changes as of version 0.2.4:
-$Id: CHANGELOG,v 1.106 2007/11/02 15:51:46 bernd67 Exp $
+$Id: CHANGELOG,v 1.107 2007/11/02 20:58:06 bernd67 Exp $
 
 0.5.5 ---------------------------------------------------------------------
 
@@ -32,6 +32,9 @@ PATCHES and CLEANUPS by Bernd Petrovitsch <bernd@firmix.at>
     their use to allow gcc to inline if only used once.
   It remains ugly - God knows why there are that so many useless
   type-casts.
+- Some minor and trivial cleanup: Added two functions to calculate the ETX
+  value from a struct tc_edge_entry and a struct link_entry, respectively.
+  And use them everywhere.
 
 0.5.4 ---------------------------------------------------------------------
 
index e84f805..6a94d23 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsrd_dot_draw.c,v 1.27 2007/09/13 15:31:58 bernd67 Exp $
+ * $Id: olsrd_dot_draw.c,v 1.28 2007/11/02 20:58:07 bernd67 Exp $
  */
 
 /*
@@ -113,9 +113,6 @@ ipc_send(const char *, int);
 static int
 ipc_send_str(const char *);
 
-static double 
-calc_etx(double, double);
-
 
 /**
  *Do initialization here
@@ -172,7 +169,7 @@ ipc_print_neigh_link(struct neighbor_entry *neighbor)
   else {   
       link = get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
       if (link) {
-        etx = calc_etx( link->loss_link_quality, link->neigh_link_quality);
+        etx = olsr_calc_link_etx(link);
       }
   }
     
@@ -365,30 +362,15 @@ pcf_event(int changes_neighborhood,
 }
 
 
-#define MIN_LINK_QUALITY 0.01
-static double 
-calc_etx(double loss, double neigh_loss) 
-{
-  if (loss < MIN_LINK_QUALITY || neigh_loss < MIN_LINK_QUALITY)
-    return 0.0;
-  else
-    return 1.0 / (loss * neigh_loss);
-}
-
-
 static void
 ipc_print_tc_link(struct tc_entry *entry, struct tc_edge_entry *dst_entry)
 {
   char buf[256];
-  const char* adr;
-  double etx = calc_etx( dst_entry->link_quality, dst_entry->inverse_link_quality );
 
-  adr = olsr_ip_to_string(&entry->addr);
-  sprintf( buf, "\"%s\" -> ", adr );
+  sprintf( buf, "\"%s\" -> ", olsr_ip_to_string(&entry->addr));
   ipc_send_str(buf);
   
-  adr = olsr_ip_to_string(&dst_entry->T_dest_addr);
-  sprintf( buf, "\"%s\"[label=\"%.2f\"];\n", adr, etx );
+  sprintf( buf, "\"%s\"[label=\"%.2f\"];\n", olsr_ip_to_string(&dst_entry->T_dest_addr), olsr_calc_tc_etx(dst_entry));
   ipc_send_str(buf);
 }
 
index 7ebe984..75a75e1 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsrd_httpinfo.c,v 1.80 2007/10/14 22:46:03 bernd67 Exp $
+ * $Id: olsrd_httpinfo.c,v 1.81 2007/11/02 20:58:07 bernd67 Exp $
  */
 
 /*
@@ -980,16 +980,16 @@ static int build_neigh_body(char *buf, olsr_u32_t bufsize)
        size += snprintf(&buf[size], bufsize-size, "<td align=\"right\">%0.2f</td>", link->L_link_quality);
         if (olsr_cnf->lq_level > 0) {
            size += snprintf(&buf[size], bufsize-size,
-                           "<td align=\"right\">%0.2f</td>"
-                           "<td>%d</td>"
-                           "<td>%d</td>"
-                           "<td align=\"right\">%0.2f</td>"
-                           "<td align=\"right\">%0.2f</td></tr>\n",
-                           link->loss_link_quality,
-                           link->lost_packets, 
-                           link->total_packets,
-                           link->neigh_link_quality, 
-                           (link->loss_link_quality * link->neigh_link_quality) ? 1.0 / (link->loss_link_quality * link->neigh_link_quality) : 0.0);
+                             "<td align=\"right\">%0.2f</td>"
+                             "<td>%d</td>"
+                             "<td>%d</td>"
+                             "<td align=\"right\">%0.2f</td>"
+                             "<td align=\"right\">%0.2f</td></tr>\n",
+                             link->loss_link_quality,
+                             link->lost_packets, 
+                             link->total_packets,
+                             link->neigh_link_quality, 
+                             olsr_calc_link_etx(link));
         }
        size += snprintf(&buf[size], bufsize-size, "</tr>\n");
 
@@ -1061,14 +1061,13 @@ 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) {
-              const double d = tc_edge->link_quality * tc_edge->inverse_link_quality;
               size += snprintf(&buf[size], bufsize-size,
                                "<td align=\"right\">%0.2f</td>"
                                "<td align=\"right\">%0.2f</td>"
                                "<td align=\"right\">%0.2f</td>\n",
                                tc_edge->link_quality,
                                tc_edge->inverse_link_quality,
-                               d ? 1.0 / d : 0.0);
+                               olsr_calc_tc_etx(tc_edge));
           }
           size += snprintf(&buf[size], bufsize-size, "</tr>\n");
 
index a2f0e29..f10eeb3 100644 (file)
@@ -31,7 +31,7 @@
  *
  */
 
-/* $Id: nameservice.c,v 1.32 2007/10/05 20:24:47 bernd67 Exp $ */
+/* $Id: nameservice.c,v 1.33 2007/11/02 20:58:07 bernd67 Exp $ */
 
 /*
  * Dynamic linked library for UniK OLSRd
@@ -1539,9 +1539,7 @@ write_latlon_file(void)
                                        olsr_ip_to_string(&tc->addr), 
                                        tc_edge->link_quality,
                                        tc_edge->inverse_link_quality,
-                                       (tc_edge->link_quality * tc_edge->inverse_link_quality) ?
-                    1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality) :
-                    0.0);
+                    olsr_calc_tc_etx(tc_edge));
 
         } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
     } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
index b56730f..fb17284 100755 (executable)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsrd_pgraph.c,v 1.8 2007/09/13 15:31:59 bernd67 Exp $
+ * $Id: olsrd_pgraph.c,v 1.9 2007/11/02 20:58:07 bernd67 Exp $
  */
 
 /*
@@ -184,7 +184,7 @@ static void ipc_print_neigh_link(struct neighbor_entry *neighbor)
 //      link_set = link; // for olsr_neighbor_best_link    
 //      link = olsr_neighbor_best_link(&neighbor->neighbor_main_addr);
 //      if (link) {
-//        etx = calc_etx( link->loss_link_quality, link->neigh_link_quality);
+//        etx = olsr_calc_etx(link);
 //      }
 //    }
 //  }
@@ -405,7 +405,7 @@ static void ipc_print_tc_link(struct tc_entry *entry, struct tc_edge_entry *dst_
   int len;
   const char* main_adr;
   const char* adr;
-//  double etx = calc_etx( dst_entry->link_quality, dst_entry->inverse_link_quality );
+//  double etx = olsr_calc_tc_etx(dst_entry);
 
   main_adr = olsr_ip_to_string(&entry->addr);
   adr = olsr_ip_to_string(&dst_entry->T_dest_addr);
index efda292..e72b6a0 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: plugin.c,v 1.13 2007/09/17 22:24:22 bernd67 Exp $
+ * $Id: plugin.c,v 1.14 2007/11/02 20:58:07 bernd67 Exp $
  */
 
 #include <string.h>
@@ -103,15 +103,6 @@ static void __attribute__((constructor)) banner(void)
   printf("Tiny Application Server 0.1 by olsr.org\n");
 }
 
-static double lqToEtx(double lq, double nlq)
-{
-  if (lq < MIN_LINK_QUALITY || nlq < MIN_LINK_QUALITY)
-    return 0.0;
-
-  else
-    return 1.0 / (lq * nlq);
-}
-
 int iterLinkTabNext(char *buff, int len)
 {
   double etx;
@@ -119,8 +110,7 @@ int iterLinkTabNext(char *buff, int len)
   if (iterLinkTab == NULL)
     return -1;
 
-  etx = lqToEtx(iterLinkTab->loss_link_quality,
-                iterLinkTab->neigh_link_quality);
+  etx = olsr_calc_link_etx(iterLinkTab);
 
   snprintf(buff, len, "local~%s~remote~%s~main~%s~hysteresis~%f~lq~%f~nlq~%f~etx~%f~",
            rawIpAddrToString(&iterLinkTab->local_iface_addr, ipAddrLen),
@@ -275,7 +265,7 @@ int iterTcTabNext(char *buff, int len)
 
     res = snprintf(buff, len, "[~%d~address~%s~etx~%f~]~", i,
                    rawIpAddrToString(&tc_edge->T_dest_addr, ipAddrLen),
-                   lqToEtx(tc_edge->link_quality, tc_edge->inverse_link_quality));
+                   olsr_calc_tc_etx(tc_edge));
 
     if (res < len)
       buff += res;
index f57dda6..da853d0 100644 (file)
@@ -40,7 +40,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsrd_txtinfo.c,v 1.12 2007/10/14 14:11:11 bernd67 Exp $
+ * $Id: olsrd_txtinfo.c,v 1.13 2007/11/02 20:58:07 bernd67 Exp $
  */
 
 /*
@@ -314,7 +314,7 @@ static void ipc_print_neigh_link(void)
                    link->lost_packets, 
                    link->total_packets,
                    link->neigh_link_quality, 
-                   (link->loss_link_quality * link->neigh_link_quality) ? 1.0 / (link->loss_link_quality * link->neigh_link_quality) : 0.0);
+                   olsr_calc_link_etx(link));
         link = link->next;
     }
     ipc_sendf("\nTable: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWillingness\t2 Hop Neighbors\n");
@@ -387,7 +387,7 @@ static void ipc_print_topology(void)
                        olsr_ip_to_string(&tc->addr), 
                        tc_edge->link_quality,
                        tc_edge->inverse_link_quality,
-                       (tc_edge->link_quality * tc_edge->inverse_link_quality) ? 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality) : 0.0);
+                       olsr_calc_tc_etx(tc_edge));
 
         } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
     } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
index 9b0d4d2..15fca85 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: link_set.c,v 1.75 2007/10/21 20:09:09 bernd67 Exp $
+ * $Id: link_set.c,v 1.76 2007/11/02 20:58:06 bernd67 Exp $
  */
 
 
@@ -1184,3 +1184,10 @@ void olsr_update_dijkstra_link_qualities(void)
   }
 }
 
+float olsr_calc_link_etx(const struct link_entry *link)
+{
+  return link->loss_link_quality < MIN_LINK_QUALITY ||
+         link->neigh_link_quality < MIN_LINK_QUALITY
+             ? 0.0
+             : 1.0 / (link->loss_link_quality * link->neigh_link_quality);
+}
index 727ab91..a7ae80f 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: link_set.h,v 1.32 2007/10/05 20:10:24 bernd67 Exp $
+ * $Id: link_set.h,v 1.33 2007/11/02 20:58:06 bernd67 Exp $
  */
 
 
@@ -150,4 +150,6 @@ olsr_print_link_set(void);
 void
 olsr_update_dijkstra_link_qualities(void);
 
+float olsr_calc_link_etx(const struct link_entry *);
+
 #endif
index e6efa45..3bcaefe 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: tc_set.c,v 1.33 2007/11/02 09:38:55 bernd67 Exp $
+ * $Id: tc_set.c,v 1.34 2007/11/02 20:58:06 bernd67 Exp $
  */
 
 #include "tc_set.h"
@@ -252,12 +252,11 @@ olsr_set_tc_edge_timer(struct tc_edge_entry *tc_edge, unsigned int timer)
 void
 olsr_calc_tc_edge_entry_etx(struct tc_edge_entry *tc_edge)
 {
-  if (tc_edge->link_quality >= MIN_LINK_QUALITY &&
-      tc_edge->inverse_link_quality >= MIN_LINK_QUALITY) {
-        
-    tc_edge->etx = 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);
-  } else {
+  if (tc_edge->link_quality < MIN_LINK_QUALITY &&
+      tc_edge->inverse_link_quality < MIN_LINK_QUALITY) {
     tc_edge->etx = INFINITE_ETX;
+  } else {
+    tc_edge->etx = 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);
   }
 }
 
@@ -616,7 +615,6 @@ olsr_print_tc_table(void)
   struct tc_entry *tc;
   struct tc_edge_entry *tc_edge;
   char *fstr;
-  float etx;
   
   OLSR_PRINTF(1, "\n--- %02d:%02d:%02d.%02d ------------------------------------------------- TOPOLOGY\n\n",
               nowtm->tm_hour,
@@ -637,17 +635,11 @@ olsr_print_tc_table(void)
 
   OLSR_FOR_ALL_TC_ENTRIES(tc) {
     OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
-
-      if (tc_edge->link_quality < MIN_LINK_QUALITY ||
-          tc_edge->inverse_link_quality < MIN_LINK_QUALITY) {
-        etx = 0.0;
-      } else {
-        etx = 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);
-      }
-
       OLSR_PRINTF(1, fstr, olsr_ip_to_string(&tc->addr),
                   olsr_ip_to_string(&tc_edge->T_dest_addr),
-                  tc_edge->link_quality, tc_edge->inverse_link_quality, etx);
+                  tc_edge->link_quality,
+                  tc_edge->inverse_link_quality,
+                  olsr_calc_tc_etx(tc_edge));
 
     } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
   } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
@@ -655,6 +647,14 @@ olsr_print_tc_table(void)
   return 1;
 }
 
+float 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
+             ? 0.0
+             : 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);
+}
+
 /*
  * Local Variables:
  * c-basic-offset: 2
index f1c56d1..fdec2bb 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: tc_set.h,v 1.19 2007/11/02 09:38:55 bernd67 Exp $
+ * $Id: tc_set.h,v 1.20 2007/11/02 20:58:06 bernd67 Exp $
  */
 
 #ifndef _OLSR_TOP_SET
@@ -137,6 +137,7 @@ struct tc_edge_entry *olsr_add_tc_edge_entry(struct tc_entry *,
 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 *);
+float olsr_calc_tc_etx(const struct tc_edge_entry *);
 
 #endif