Deserialization of new LQ packet types compiles. Not tested at all, yet.
authorThomas Lopatic <thomas@lopatic.de>
Tue, 2 Nov 2004 22:55:43 +0000 (22:55 +0000)
committerThomas Lopatic <thomas@lopatic.de>
Tue, 2 Nov 2004 22:55:43 +0000 (22:55 +0000)
src/packet.c
src/packet.h
src/process_package.c
src/process_package.h
src/rebuild_packet.c
src/rebuild_packet.h

index 7f72695..a18c623 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: packet.c,v 1.8 2004/11/01 19:27:11 tlopatic Exp $
+ * $Id: packet.c,v 1.9 2004/11/02 22:55:42 tlopatic Exp $
  *
  */
 
@@ -532,7 +532,7 @@ olsr_build_lq_hello_packet(struct lq_hello_message *msg,
       else if (walker->neighbor->status == NOT_SYM)
         neigh->neigh_type = NOT_NEIGH;
   
-      COPY_IP(&neigh->main, &walker->neighbor->neighbor_main_addr);
+      // COPY_IP(&neigh->main, &walker->neighbor->neighbor_main_addr);
       COPY_IP(&neigh->addr, &walker->neighbor_iface_addr);
       
       olsr_printf(5, "%s - ", olsr_ip_to_string(&neigh->addr));
index 886b13f..e7fc599 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: packet.h,v 1.6 2004/11/01 19:27:11 tlopatic Exp $
+ * $Id: packet.h,v 1.7 2004/11/02 22:55:42 tlopatic Exp $
  *
  */
 
@@ -67,7 +67,6 @@ struct lq_hello_neighbor
   olsr_u8_t                link_type;
   olsr_u8_t                neigh_type;
   double                   link_quality;
-  union olsr_ip_addr       main;
   union olsr_ip_addr       addr;
   struct lq_hello_neighbor *next;
 };
index ef25fec..bf23cdb 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: process_package.c,v 1.7 2004/10/20 17:11:33 tlopatic Exp $
+ * $Id: process_package.c,v 1.8 2004/11/02 22:55:43 tlopatic Exp $
  *
  */
 
 void
 olsr_init_package_process()
 {
-
+#if !defined USE_LINK_QUALITY
   olsr_parser_add_function(&olsr_process_received_hello, HELLO_MESSAGE, 1);
   olsr_parser_add_function(&olsr_process_received_tc, TC_MESSAGE, 1);
+#else
+  olsr_parser_add_function(&olsr_process_received_lq_hello,
+                           LQ_HELLO_MESSAGE, 1);
+  olsr_parser_add_function(&olsr_process_received_lq_tc,
+                           LQ_TC_MESSAGE, 1);
+#endif
   olsr_parser_add_function(&olsr_process_received_mid, MID_MESSAGE, 1);
   olsr_parser_add_function(&olsr_process_received_hna, HNA_MESSAGE, 1);
 }
@@ -98,13 +104,6 @@ olsr_process_received_hello(union olsr_message *m, struct interface *in_if, unio
       olsr_update_hysteresis_hello(link, message.htime);
     }
 
-#if defined USE_LINK_QUALITY
-  if (1)
-    {
-      olsr_update_packet_loss_hello_int(link, message.htime);
-    }
-#endif
-
   /* Check if we are chosen as MPR */
   if(olsr_lookup_mpr_status(&message, in_if))
     /* source_addr is always the main addr of a node! */
@@ -645,3 +644,23 @@ olsr_lookup_mpr_status(struct hello_message *message, struct interface *in_if)
   return 0;
 }
 
+#if defined USE_LINK_QUALITY
+void
+olsr_process_received_lq_hello(union olsr_message *ser,
+                               struct interface *inif,
+                               union olsr_ip_addr *from)
+{
+  struct lq_hello_message deser;
+
+  lq_hello_chgestruct(&deser, ser);
+}
+
+void
+olsr_process_received_lq_tc(union olsr_message *ser, struct interface *inif,
+                            union olsr_ip_addr *from)
+{
+  struct lq_tc_message deser;
+
+  lq_tc_chgestruct(&deser, ser, from);
+}
+#endif
index 29e503c..203cb52 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: process_package.h,v 1.6 2004/10/09 22:32:47 kattemat Exp $
+ * $Id: process_package.h,v 1.7 2004/11/02 22:55:43 tlopatic Exp $
  *
  */
 
@@ -57,4 +57,15 @@ olsr_linking_this_2_entries(struct neighbor_entry *,struct neighbor_2_entry *, f
 int
 olsr_lookup_mpr_status(struct hello_message *, struct interface *);
 
+#if defined USE_LINK_QUALITY
+void
+olsr_process_received_lq_hello(union olsr_message *ser,
+                               struct interface *inif,
+                               union olsr_ip_addr *from);
+
+void
+olsr_process_received_lq_tc(union olsr_message *ser, struct interface *inif,
+                            union olsr_ip_addr *from);
+#endif
+
 #endif
index e82168b..945418d 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: rebuild_packet.c,v 1.8 2004/10/18 13:13:37 kattemat Exp $
+ * $Id: rebuild_packet.c,v 1.9 2004/11/02 22:55:43 tlopatic Exp $
  *
  */
 
@@ -563,3 +563,143 @@ tc_chgestruct(struct tc_message *tmsg, union olsr_message *m, union olsr_ip_addr
     }
 
 }
+
+#if defined USE_LINK_QUALITY
+void
+lq_hello_chgestruct(struct lq_hello_message *deser, union olsr_message *ser)
+{
+  struct lq_hello_header *head;
+  struct lq_hello_info_header *info_head;
+  unsigned char *curr, *limit, *limit2;
+  struct lq_hello_neighbor *neigh;
+  
+  deser->neigh = NULL;
+
+  if (ser == NULL || ser->v4.olsr_msgtype != LQ_HELLO_MESSAGE)
+    return;
+
+  deser->vtime = me_to_double(ser->v4.olsr_vtime);
+
+  if (olsr_cnf->ip_version == AF_INET)
+    {
+      COPY_IP(&deser->main, &ser->v4.originator);
+
+      deser->seqno = ntohs(ser->v4.seqno);
+
+      head = &ser->v4.message.lq_hello;
+    }
+
+  else
+    {
+      COPY_IP(&deser->main, &ser->v6.originator);
+
+      deser->seqno = ntohs(ser->v6.seqno);
+
+      head = &ser->v6.message.lq_hello;
+    }
+
+  deser->htime = me_to_double(head->htime);
+  deser->will = head->will;
+
+  // XXX - deserialize TTL and hop count?
+
+  curr = (unsigned char *)(head + 1);
+
+  limit = ((unsigned char *)ser) + ntohs(ser->v4.olsr_msgsize);
+
+  while (curr < limit)
+    {
+      info_head = (struct lq_hello_info_header *)curr;
+
+      limit2 = curr + ntohs(info_head->size);
+
+      curr = (unsigned char *)(info_head + 1);
+      
+      while (curr < limit2)
+        {
+          neigh = olsr_malloc(sizeof (struct lq_tc_neighbor),
+                              "LQ HELLO deserialization");
+
+          COPY_IP(&neigh->addr, curr);
+          curr += ipsize;
+
+          neigh->link_quality = (double)*curr / 256.0;
+          curr += 4;
+
+          neigh->link_type = EXTRACT_LINK(info_head->link_code);
+          neigh->neigh_type = EXTRACT_STATUS(info_head->link_code);
+
+          neigh->next = deser->neigh;
+          deser->neigh = neigh;
+        }
+    }
+}
+
+void
+lq_tc_chgestruct(struct lq_tc_message *deser, union olsr_message *ser,
+                 union olsr_ip_addr *from)
+{
+  struct lq_tc_header *head;
+  union olsr_ip_addr *addr;
+  unsigned char *curr, *limit;
+  struct lq_tc_neighbor *neigh;
+
+  deser->neigh = NULL;
+
+  if (ser == NULL || ser->v4.olsr_msgtype != LQ_TC_MESSAGE)
+    return;
+
+  deser->vtime = me_to_double(ser->v4.olsr_vtime);
+
+  addr = mid_lookup_main_addr(from);
+
+  if (addr == 0)
+    COPY_IP(&deser->main, from);
+
+  else
+    COPY_IP(&deser->main, addr);
+
+  if (olsr_cnf->ip_version == AF_INET)
+    {
+      COPY_IP(&deser->orig, &ser->v4.originator);
+
+      deser->seqno = ntohs(ser->v4.seqno);
+      deser->hops =  ser->v4.hopcnt;
+
+      head = &ser->v4.message.lq_tc;
+    }
+
+  else
+    {
+      COPY_IP(&deser->orig, &ser->v6.originator);
+
+      deser->seqno = ntohs(ser->v6.seqno);
+      deser->hops =  ser->v6.hopcnt;
+
+      head = &ser->v6.message.lq_tc;
+    }
+
+  deser->ansn =  ntohs(head->ansn);
+
+  // XXX - deserialize TTL?
+
+  curr = (unsigned char *)(head + 1);
+
+  limit = ((unsigned char *)ser) + ntohs(ser->v4.olsr_msgsize);
+
+  while (curr < limit)
+    {
+      neigh = olsr_malloc(sizeof (struct lq_tc_neighbor),
+                          "LQ TC deserialization");
+
+      COPY_IP(&neigh->main, curr);
+      curr += ipsize;
+
+      neigh->link_quality = (double)*curr / 256.0;
+      curr += 4;
+
+      neigh->next = deser->neigh;
+      deser->neigh = neigh;
+    }
+}
+#endif
index 9add76c..dc7a1b8 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: rebuild_packet.h,v 1.5 2004/09/21 19:08:58 kattemat Exp $
+ * $Id: rebuild_packet.h,v 1.6 2004/11/02 22:55:43 tlopatic Exp $
  *
  */
 
@@ -47,5 +47,13 @@ hello_chgestruct(struct hello_message *, union olsr_message *);
 void
 tc_chgestruct(struct tc_message *, union olsr_message *, union olsr_ip_addr *);
 
+#if defined USE_LINK_QUALITY
+void
+lq_hello_chgestruct(struct lq_hello_message *deser, union olsr_message *ser);
+
+void
+lq_tc_chgestruct(struct lq_tc_message *deser, union olsr_message *ser,
+                 union olsr_ip_addr *from);
+#endif
 
 #endif