Updated net-output handling and packet generation
authorAndreas Tonnesen <andreto@olsr.org>
Wed, 22 Sep 2004 17:00:29 +0000 (17:00 +0000)
committerAndreas Tonnesen <andreto@olsr.org>
Wed, 22 Sep 2004 17:00:29 +0000 (17:00 +0000)
bin/olsrd
src/build_msg.c
src/defs.h
src/generate_msg.c
src/net.c
src/net.h
src/olsr.c
src/scheduler.c

index a16dc5b..eebe8dc 100755 (executable)
Binary files a/bin/olsrd and b/bin/olsrd differ
index 4fea33f..b70f25f 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: build_msg.c,v 1.10 2004/09/21 19:51:11 kattemat Exp $
+ * $Id: build_msg.c,v 1.11 2004/09/22 17:00:28 kattemat Exp $
  *
  */
 
@@ -315,25 +315,30 @@ hello_build4(struct hello_message *message, struct interface *ifp)
                       */
                      if((curr_size + 4 + ipsize) > remainsize)
                        {
-                         /* Complete the headers */
-                         m->v4.seqno = htons(get_msg_seqno());
-                         m->v4.olsr_msgsize = htons(curr_size);
-
-                         hinfo->size = (char *)haddr - (char *)hinfo;
-                         hinfo->size = ntohs(hinfo->size);
-                         
-                         /* Send partial packet */
-                         net_outbuffer_push(msg_buffer, curr_size);
-                         net_output(ifp);
-                         
+                         /* Only send partial HELLO if it contains data */
+                         if(curr_size > (12 + 4))
+                           {
+                             /* Complete the headers */
+                             m->v4.seqno = htons(get_msg_seqno());
+                             m->v4.olsr_msgsize = htons(curr_size);
+                             
+                             hinfo->size = (char *)haddr - (char *)hinfo;
+                             hinfo->size = ntohs(hinfo->size);
+                             
+                             /* Send partial packet */
+                             net_outbuffer_push(msg_buffer, curr_size);
+
+                             curr_size = 12; /* OLSR message header */
+                             curr_size += 4; /* Hello header */
+                             
+                             h = &m->v4.message.hello;
+                             hinfo = h->hell_info;
+                             haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
+                           }
+
+                         net_output(ifp);                        
                          /* Reset size and pointers */
                          remainsize = net_outbuffer_bytes_left();
-                         curr_size = 12; /* OLSR message header */
-                         curr_size += 4; /* Hello header */
-
-                         h = &m->v4.message.hello;
-                         hinfo = h->hell_info;
-                         haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
                        }
                      memset(&hinfo->reserved, 0, sizeof(olsr_u8_t));
                      /* Set link and status for this group of neighbors (this is the first) */
@@ -356,6 +361,9 @@ hello_build4(struct hello_message *message, struct interface *ifp)
                   */
                  if((curr_size + ipsize) > remainsize)
                    {
+                     /* If we get here the message contains data
+                      * - no need to check 
+                      */
                      /* Complete the headers */
                      m->v4.seqno = htons(get_msg_seqno());
                      m->v4.olsr_msgsize = htons(curr_size);
@@ -532,27 +540,31 @@ hello_build6(struct hello_message *message, struct interface *ifp)
                  sametype++;
                  if (sametype == 1)
                    {
+                     /* Check if there is room for header + one address */
                      if((curr_size + 4 + ipsize) > remainsize)
                        {
-                         /* Complete the headers */
-                         m->v6.seqno = htons(get_msg_seqno());
-                         m->v6.olsr_msgsize = htons(curr_size);
-
-                         hinfo6->size = (char *)haddr - (char *)hinfo6;
-                         hinfo6->size = ntohs(hinfo6->size);
-                         
-                         /* Send partial packet */
-                         net_outbuffer_push(msg_buffer, curr_size);
+                         /* Only send partial HELLO if it contains data */
+                         if(curr_size > (24 + 4))
+                           {
+                             /* Complete the headers */
+                             m->v6.seqno = htons(get_msg_seqno());
+                             m->v6.olsr_msgsize = htons(curr_size);
+                             
+                             hinfo6->size = (char *)haddr - (char *)hinfo6;
+                             hinfo6->size = ntohs(hinfo6->size);
+                             
+                             /* Send partial packet */
+                             net_outbuffer_push(msg_buffer, curr_size);
+                             curr_size = 24; /* OLSR message header */
+                             curr_size += 4; /* Hello header */
+                             
+                             h6 = &m->v6.message.hello;
+                             hinfo6 = h6->hell_info;
+                             haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
+                           }
                          net_output(ifp);
-                         
                          /* Reset size and pointers */
                          remainsize = net_outbuffer_bytes_left();
-                         curr_size = 24; /* OLSR message header */
-                         curr_size += 4; /* Hello header */
-                         
-                         h6 = &m->v6.message.hello;
-                         hinfo6 = h6->hell_info;
-                         haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
                        }
                      memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));
                      /* Set link and status for this group of neighbors (this is the first) */
@@ -568,13 +580,16 @@ hello_build6(struct hello_message *message, struct interface *ifp)
 
                  /*
                   * If there is not enough room left 
-                  * for the data in tho outputbuffer
+                  * for the data in the outputbuffer
                   * we must send a partial HELLO and
                   * continue building the rest of the
                   * data in a new HELLO message
                   */
                  if((curr_size + ipsize) > remainsize)
                    {
+                     /* If we get here the message contains data
+                      * - no need to check 
+                      */
                      /* Complete the headers */
                      m->v6.seqno = htons(get_msg_seqno());
                      m->v6.olsr_msgsize = htons(curr_size);
@@ -583,11 +598,7 @@ hello_build6(struct hello_message *message, struct interface *ifp)
                      hinfo6->size = ntohs(hinfo6->size);
                      
                      /* Send partial packet */
-                     net_outbuffer_push(msg_buffer, curr_size);
-                     net_output(ifp);
-                     
-                     /* Reset size and pointers */
-                     remainsize = net_outbuffer_bytes_left();
+                         net_outbuffer_push(msg_buffer, curr_size);
                      curr_size = 24; /* OLSR message header */
                      curr_size += 4; /* Hello header */
                      
@@ -601,6 +612,10 @@ hello_build6(struct hello_message *message, struct interface *ifp)
                      hinfo6->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
                      //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
                      curr_size += 4; /* HELLO type section header */
+
+                     net_output(ifp);                
+                     /* Reset size */
+                     remainsize = net_outbuffer_bytes_left();
                      
                    }
 
@@ -676,7 +691,7 @@ tc_build4(struct tc_message *message, struct interface *ifp)
   union olsr_message *m;
   struct tcmsg *tc;
   struct neigh_info *mprsaddr; 
-  int found = 0;
+  int found = 0, partial_sent = 0;
 
   if((!message) || (!ifp) || (ipversion != AF_INET))
     return;
@@ -718,21 +733,25 @@ tc_build4(struct tc_message *message, struct interface *ifp)
       if((curr_size + ipsize) > remainsize)
        {
 
-         olsr_printf(1, "Chomping TC!\n");
+         /* Only add TC message if it contains data */
+         if(curr_size > (12 + 4 ))
+           {
+             m->v4.olsr_msgsize = htons(curr_size);
+             m->v4.seqno = htons(get_msg_seqno());
 
-         m->v4.olsr_msgsize = htons(curr_size);
-         m->v4.seqno = htons(get_msg_seqno());
+             net_outbuffer_push(msg_buffer, curr_size);
+             
+             /* Reset stuff */
+             mprsaddr = tc->neigh;
+             curr_size = 12; /* OLSR message header */
+             curr_size += 4; /* TC header */
+             found = 0;
+             partial_sent = 1;
+           }
 
-         net_outbuffer_push(msg_buffer, curr_size);
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left();
 
-         /* Reset stuff */
-         mprsaddr = tc->neigh;
-         curr_size = 12; /* OLSR message header */
-         curr_size += 4; /* TC header */
-
-         found = 0;
        }
       found = 1;
       
@@ -753,7 +772,7 @@ tc_build4(struct tc_message *message, struct interface *ifp)
     }
   else
     {
-      if(!TIMED_OUT(&send_empty_tc))
+      if((!partial_sent) && (!TIMED_OUT(&send_empty_tc)))
        {
          olsr_printf(1, "TC: Sending empty package\n");
 
@@ -804,7 +823,7 @@ tc_build6(struct tc_message *message, struct interface *ifp)
   union olsr_message *m;
   struct tcmsg6 *tc6;
   struct neigh_info6 *mprsaddr6; 
-  int found = 0;
+  int found = 0, partial_sent = 0;
 
   if ((!message) || (!ifp) || (ipversion != AF_INET6))
     return;
@@ -845,19 +864,23 @@ tc_build6(struct tc_message *message, struct interface *ifp)
       /*If packet is to be chomped */
       if((curr_size + ipsize) > remainsize)
        {
-         m->v6.olsr_msgsize = htons(curr_size);
-         m->v6.seqno = htons(get_msg_seqno());
+         /* Only add TC message if it contains data */
+         if(curr_size > (24 + 4 ))
+           {
+             m->v6.olsr_msgsize = htons(curr_size);
+             m->v6.seqno = htons(get_msg_seqno());
 
-         net_outbuffer_push(msg_buffer, curr_size);
+             net_outbuffer_push(msg_buffer, curr_size);
+             mprsaddr6 = tc6->neigh;
+             curr_size = 24; /* OLSR message header */
+             curr_size += 4; /* TC header */
+             found = 0;
+             partial_sent = 1;
+           }
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left();
-
-         mprsaddr6 = tc6->neigh;
-         curr_size = 24; /* OLSR message header */
-         curr_size += 4; /* TC header */
                
 
-         found = 0;
        }
       found = 1;
 
@@ -878,7 +901,7 @@ tc_build6(struct tc_message *message, struct interface *ifp)
     }
   else
     {
-      if(!TIMED_OUT(&send_empty_tc))
+      if((!partial_sent) && (!TIMED_OUT(&send_empty_tc)))
        {
          olsr_printf(1, "TC: Sending empty package\n");
            
@@ -960,15 +983,19 @@ mid_build4(struct interface *ifp)
 
          if((curr_size + ipsize) > remainsize)
            {
-             /* set size */
-             m->v4.olsr_msgsize = htons(curr_size);
-             m->v4.seqno = htons(get_msg_seqno());/* seqnumber */
-             
-             net_outbuffer_push(msg_buffer, curr_size);
+             /* Only add MID message if it contains data */
+             if(curr_size > 12)
+               {
+                 /* set size */
+                 m->v4.olsr_msgsize = htons(curr_size);
+                 m->v4.seqno = htons(get_msg_seqno());/* seqnumber */
+                 
+                 net_outbuffer_push(msg_buffer, curr_size);
+                 curr_size = 12; /* OLSR message header */
+                 addrs = m->v4.message.mid.mid_addr;
+               }
              net_output(ifp);
              remainsize = net_outbuffer_bytes_left();
-             curr_size = 12; /* OLSR message header */
-             addrs = m->v4.message.mid.mid_addr;
            }
          
          COPY_IP(&addrs->addr, &ifs->ip_addr);
@@ -1044,15 +1071,19 @@ mid_build6(struct interface *ifp)
        {
          if((curr_size + ipsize) > remainsize)
            {
-             /* set size */
-             m->v6.olsr_msgsize = htons(curr_size);
-             m->v6.seqno = htons(get_msg_seqno());/* seqnumber */
-             
-             net_outbuffer_push(msg_buffer, curr_size);
+             /* Only add MID message if it contains data */
+             if(curr_size > 24)
+               {
+                 /* set size */
+                 m->v6.olsr_msgsize = htons(curr_size);
+                 m->v6.seqno = htons(get_msg_seqno());/* seqnumber */
+                 
+                 net_outbuffer_push(msg_buffer, curr_size);
+                 curr_size = 24; /* OLSR message header */
+                 addrs6 = m->v6.message.mid.mid_addr;
+               }
              net_output(ifp);
              remainsize = net_outbuffer_bytes_left();
-             curr_size = 24; /* OLSR message header */
-             addrs6 = m->v6.message.mid.mid_addr;
            }
 
          COPY_IP(&addrs6->addr, &ifs->ip_addr);
@@ -1122,14 +1153,17 @@ hna_build4(struct interface *ifp)
     {
       if((curr_size + (2 * ipsize)) > remainsize)
        {
-         m->v4.seqno = htons(get_msg_seqno());
-         m->v4.olsr_msgsize = htons(curr_size);
-
-         net_outbuffer_push(msg_buffer, curr_size);
+         /* Only add HNA message if it contains data */
+         if(curr_size > 12)
+           {
+             m->v4.seqno = htons(get_msg_seqno());
+             m->v4.olsr_msgsize = htons(curr_size);
+             net_outbuffer_push(msg_buffer, curr_size);
+             curr_size = 12; /* OLSR message header */
+             pair = m->v4.message.hna.hna_net;
+           }
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left();
-         curr_size = 12; /* OLSR message header */
-         pair = m->v4.message.hna.hna_net;
        }
       COPY_IP(&pair->addr, &h->A_network_addr);
       COPY_IP(&pair->netmask, &h->A_netmask);
@@ -1200,14 +1234,17 @@ hna_build6(struct interface *ifp)
     {
       if((curr_size + (2 * ipsize)) > remainsize)
        {
-         m->v6.seqno = htons(get_msg_seqno());
-         m->v6.olsr_msgsize = htons(curr_size);
-
-         net_outbuffer_push(msg_buffer, curr_size);
+         /* Only add HNA message if it contains data */
+         if(curr_size > 24)
+           {
+             m->v6.seqno = htons(get_msg_seqno());
+             m->v6.olsr_msgsize = htons(curr_size);
+             net_outbuffer_push(msg_buffer, curr_size);
+             curr_size = 24; /* OLSR message header */
+             pair6 = m->v6.message.hna.hna_net;
+           }
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left();
-         curr_size = 24; /* OLSR message header */
-         pair6 = m->v6.message.hna.hna_net;
        }
 
       //printf("Adding %s\n", olsr_ip_to_string(&h->hna_net.addr));
index 33089f1..6e24a8b 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: defs.h,v 1.10 2004/09/21 19:08:57 kattemat Exp $
+ * $Id: defs.h,v 1.11 2004/09/22 17:00:28 kattemat Exp $
  *
  */
 
@@ -223,13 +223,6 @@ extern struct hna_entry *hna_old;
 extern struct ip_tunnel_parm ipt;
 extern union olsr_ip_addr tnl_addr; /* The gateway address if inet_tnl_added==1 */
 
-extern char                  packet[MAXMESSAGESIZE+1];
-extern int                    outputsize;
-extern union olsr_packet      *msg;
-extern char                  fwd_packet[MAXMESSAGESIZE+1];
-extern int                    fwdsize;
-extern union olsr_packet      *fwdmsg;
-
 olsr_u8_t changes;                /* is set if changes occur in MPRS set */ 
 
 extern float                  topology_hold_time, neighbor_hold_time;
index 9b5f726..1415f4f 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: generate_msg.c,v 1.5 2004/09/21 19:08:57 kattemat Exp $
+ * $Id: generate_msg.c,v 1.6 2004/09/22 17:00:28 kattemat Exp $
  *
  */
 
@@ -261,7 +261,7 @@ generate_hello()
       olsr_build_hello_packet(&hellopacket, ifn);
       hello_build(&hellopacket, ifn);
       
-      if(outputsize)
+      if(net_output_pending())
        net_output(ifn);
       
     }
@@ -281,10 +281,10 @@ generate_hello_nw()
       
       olsr_build_hello_packet(&hellopacket, ifn);
       hello_build(&hellopacket, ifn);
-      
-      if(outputsize)
+
+      if(net_output_pending())
        net_output(ifn);
-      
+
     }
   return;
 }
@@ -303,7 +303,7 @@ generate_tc()
       olsr_build_tc_packet(&tcpacket);
       tc_build(&tcpacket, ifn);
 
-      if(outputsize)
+      if(net_output_pending())
        net_output(ifn);
     }
 }
@@ -319,7 +319,7 @@ generate_mid()
     {
       //printf("\nSending MID seq: %i\n", ifn->seqnums.mid_seqnum);
       mid_build(ifn);
-      if(outputsize)
+      if(net_output_pending())
        net_output(ifn);
     }
 
@@ -338,7 +338,7 @@ generate_hna()
     { 
       hna_build(ifn);
       
-      if(outputsize)
+      if(net_output_pending())
        net_output(ifn);
     }
   return;
index 7cbedc7..b5396d7 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -20,7 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: net.c,v 1.10 2004/09/21 19:08:57 kattemat Exp $
+ * $Id: net.c,v 1.11 2004/09/22 17:00:28 kattemat Exp $
  *
  */
 
@@ -87,6 +87,13 @@ net_fwd_pending()
   return fwdsize;
 }
 
+
+inline olsr_u16_t
+net_output_pending()
+{
+  return outputsize;
+}
+
 /**
  * Add data to the buffer that is to be transmitted
  *
index 620669e..86e2e01 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -20,7 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: net.h,v 1.6 2004/09/21 19:08:57 kattemat Exp $
+ * $Id: net.h,v 1.7 2004/09/22 17:00:28 kattemat Exp $
  *
  */
 
@@ -50,6 +50,12 @@ init_net();
 inline int
 net_outbuffer_bytes_left();
 
+inline olsr_u16_t
+net_fwd_pending();
+
+inline olsr_u16_t
+net_output_pending();
+
 int
 net_set_maxmsgsize(olsr_u16_t);
 
index 5c564e0..f16d299 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: olsr.c,v 1.10 2004/09/21 19:06:56 kattemat Exp $
+ * $Id: olsr.c,v 1.11 2004/09/22 17:00:28 kattemat Exp $
  *
  */
 
@@ -347,9 +347,9 @@ olsr_forward_message(union olsr_message *m,
       /*
        * Check if message is to big to be piggybacked
        */
-      if(net_fwdbuffer_push(m, msgsize) != msgsize)
+      if(net_fwdbuffer_push((olsr_u8_t *)m, msgsize) != msgsize)
        {
-         olsr_printf(1, "Forwardbuffer full(%d + %d) - flushing!\n", fwdsize, msgsize);
+         olsr_printf(1, "Forwardbuffer full(%d + %d) - flushing!\n", net_fwd_pending(), msgsize);
          
          /* Send */
          net_forward();
@@ -360,7 +360,7 @@ olsr_forward_message(union olsr_message *m,
       else
        {
 #ifdef DEBUG
-         olsr_printf(3, "Piggybacking message - buffer: %d msg: %d\n", fwdsize, msgsize);
+         olsr_printf(3, "Piggybacking message - buffer: %d msg: %d\n", net_fwd_pending(), msgsize);
 #endif
          /* piggyback message to outputbuffer */
        }
@@ -398,7 +398,7 @@ buffer_forward(union olsr_message *m, olsr_u16_t msgsize)
 #endif
 
   /* Copy message to outputbuffer */
-  if(net_fwdbuffer_push(m, msgsize) != msgsize)
+  if(net_fwdbuffer_push((olsr_u8_t *)m, msgsize) != msgsize)
     {
       olsr_printf(1, "Received message to big to be forwarded(%d bytes)!", msgsize);
       olsr_syslog(OLSR_LOG_ERR, "Received message to big to be forwarded(%d bytes)!", msgsize);
index 53ce0cb..3b01999 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * 
- * $Id: scheduler.c,v 1.7 2004/09/21 19:08:58 kattemat Exp $
+ * $Id: scheduler.c,v 1.8 2004/09/22 17:00:29 kattemat Exp $
  *
  */
 
@@ -197,13 +197,12 @@ scheduler()
 
 
       /* Forward message(s) OUTSIDE INTERFACE LOOP */
-      if(fwdsize && TIMED_OUT(&fwdtimer)) 
+      if(net_fwd_pending() && TIMED_OUT(&fwdtimer)) 
        { 
 #ifdef DEBUG
          olsr_printf(3, "Forwarding message - size %d\n", fwdsize);
 #endif   
          net_forward();
-         fwdsize = 0;
          
        }