serialized LQ data is not always 4 bytes long, so we need a function to precalculate...
authorHenning Rogge <hrogge@googlemail.com>
Sun, 5 Jul 2009 11:13:03 +0000 (13:13 +0200)
committerHenning Rogge <hrogge@googlemail.com>
Sun, 5 Jul 2009 11:13:03 +0000 (13:13 +0200)
lib/lq_etx_ff/src/lq_plugin_etx_ff.c
lib/lq_etx_float/src/lq_plugin_etx_float.c
lib/lq_etx_fpm/src/lq_plugin_etx_fpm.c
lib/lq_rfc/src/lq_plugin_rfc.c
src/lq_packet.c
src/lq_plugin.c
src/lq_plugin.h

index b3c197d..aeeb899 100644 (file)
@@ -135,7 +135,9 @@ struct lq_handler lq_etxff_handler = {
   sizeof(struct lq_etxff_link_entry),
 
   LQ_HELLO_MESSAGE,
-  LQ_TC_MESSAGE
+  LQ_TC_MESSAGE,
+
+  4,4
 };
 
 static int lq_etxff_post_init(void) {
index 4dbca77..a8c0e02 100644 (file)
@@ -123,7 +123,9 @@ struct lq_handler lq_etxfloat_handler = {
   sizeof(struct lq_etxfloat_link_entry),
 
   LQ_HELLO_MESSAGE,
-  LQ_TC_MESSAGE
+  LQ_TC_MESSAGE,
+
+  4,4
 };
 
 static float lq_aging = LQ_FLOAT_DEFAULT_AGING;
index a913d08..23cb2f0 100644 (file)
@@ -123,7 +123,9 @@ struct lq_handler lq_etxfpm_handler = {
   sizeof(struct lq_etxfpm_link_entry),
 
   LQ_HELLO_MESSAGE,
-  LQ_TC_MESSAGE
+  LQ_TC_MESSAGE,
+
+  4,4
 };
 
 static uint32_t aging_factor_new = LQ_FPM_DEFAULT_AGING;
index eb8dbb8..d421d06 100644 (file)
@@ -124,7 +124,9 @@ struct lq_handler lq_rfc_handler = {
   sizeof(struct lq_rfc_link_entry),
 
   HELLO_MESSAGE,
-  TC_MESSAGE
+  TC_MESSAGE,
+
+  0,0
 };
 
 static bool use_hysteresis = DEF_USE_HYST;
index 7d8aec6..5352c94 100644 (file)
@@ -369,7 +369,7 @@ serialize_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
         is_first = true;
         for (neigh = lq_hello->neigh; neigh != NULL; neigh = neigh->next) {
           if (0 == i && 0 == j)
-            expected_size += olsr_cnf->ipsize + 4;
+            expected_size += olsr_cnf->ipsize + olsr_sizeof_TCLQ();
           if (neigh->neigh_type == i && neigh->link_type == LINK_ORDER[j]) {
             if (is_first) {
               expected_size += sizeof(struct lq_hello_info_header);
@@ -555,8 +555,7 @@ serialize_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
    */
   if (0 < net_output_pending(outif)) {
     for (neigh = lq_tc->neigh; neigh != NULL; neigh = neigh->next) {
-      // TODO sizeof_tc_lq function required
-      expected_size += olsr_cnf->ipsize + 4;
+      expected_size += olsr_cnf->ipsize + olsr_sizeof_TCLQ();
     }
   }
 
index c35f94b..a7fd656 100644 (file)
@@ -498,6 +498,26 @@ olsr_get_TC_MessageId(void)
   return active_lq_handler->messageid_tc;
 }
 
+/**
+ * olsr_sizeof_HelloLQ
+ *
+ * @return number of bytes necessary to store HelloLQ data
+ */
+size_t
+olsr_sizeof_HelloLQ(void) {
+  return active_lq_handler->serialized_lqhello_size;
+}
+
+/**
+ * olsr_sizeof_TCLQ
+ *
+ * @return number of bytes necessary to store TCLQ data
+ */
+size_t
+olsr_sizeof_TCLQ(void) {
+  return active_lq_handler->serialized_lqtc_size;
+}
+
 /*
  * Local Variables:
  * c-basic-offset: 2
index d6e4aec..cdfbac9 100644 (file)
@@ -100,6 +100,9 @@ struct lq_handler {
 
   uint8_t messageid_hello;
   uint8_t messageid_tc;
+
+  size_t serialized_lqhello_size;
+  size_t serialized_lqtc_size;
 };
 
 void init_lq_handler(void);
@@ -140,6 +143,9 @@ void olsr_free_tc_mpr_addr(struct tc_mpr_addr *);
 uint8_t olsr_get_Hello_MessageId(void);
 uint8_t olsr_get_TC_MessageId(void);
 
+size_t olsr_sizeof_HelloLQ(void);
+size_t olsr_sizeof_TCLQ(void);
+
 /* Externals. */
 extern struct lq_handler *EXPORT(active_lq_handler);