The following commit has been merged in the master branch: commit e88ef3b214b068da7385fd00db6420ffbe85e9ef Author: Axel Neumann neumann@cgws.de Date: Tue Jan 23 17:17:32 2007 +0100
some debug messages and questions
diff --git a/Makefile b/Makefile index 405e283..de2aa1e 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ OS_OBJ= posix-specific.o posix.o bsd.o allocate.o bitarray.o endif
LINUX_SRC_C= batman.c posix-specific.c posix.c linux-specific.c linux.c allocate.c bitarray.c +LINUX_SRC_H= batman.h batman-specific.h list.h os.h allocate.h
all: batmand
@@ -55,11 +56,11 @@ mips: batmand-mips-static batmand-mips-dynamic batmand: batman.o $(OS_OBJ) Makefile $(CC) -o $@ batman.o $(OS_OBJ) $(LDFLAGS)
-batmand-mips-static: $(LINUX_SRC_C) Makefile +batmand-mips-static: $(LINUX_SRC_C) $(LINUX_SRC_H) Makefile $(CC_MIPS) $(CFLAGS_MIPS) -o $@ $(LINUX_SRC_C) $(LDFLAGS_MIPS) -static $(STRIP_MIPS) $@
-batmand-mips-dynamic: $(LINUX_SRC_C) Makefile +batmand-mips-dynamic: $(LINUX_SRC_C) $(LINUX_SRC_H) Makefile $(CC_MIPS) $(CFLAGS_MIPS) -o $@ $(LINUX_SRC_C) $(LDFLAGS_MIPS) $(STRIP_MIPS) $@
diff --git a/batman.c b/batman.c index 0638adf..78aee3f 100644 --- a/batman.c +++ b/batman.c @@ -526,7 +526,7 @@ void debug() {
debug_output( 4, "------------------ DEBUG ------------------\n" ); debug_output( 4, "Forward list\n" ); - + list_for_each( forw_pos, &forw_list ) { forw_node = list_entry( forw_pos, struct forw_node, list ); addr_to_string( ((struct packet *)forw_node->pack_buff)->orig, str, sizeof (str) ); @@ -549,6 +549,7 @@ void debug() { addr_to_string( orig_node->router->addr, str2, sizeof (str2) );
debug_output( 1, "%s, GW: %s(%i) via:", str, str2, orig_node->router->packet_count ); + //printf( "%s, GW: %s(%i) via:", str, str2, orig_node->router->packet_count ); debug_output( 4, "%s, GW: %s(%i), last_aware:%u via:\n", str, str2, orig_node->router->packet_count, orig_node->last_aware );
list_for_each(neigh_pos, &orig_node->neigh_list) { @@ -557,11 +558,13 @@ void debug() { addr_to_string(neigh_node->addr, str, sizeof (str));
debug_output( 1, " %s(%i)", str, neigh_node->packet_count ); + //printf(" %s(%i)", str, neigh_node->packet_count ); debug_output( 4, "\t\t%s (%d)\n", str, neigh_node->packet_count );
}
debug_output( 1, "\n" ); + //printf( "\n" );
}
@@ -627,7 +630,7 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned struct list_head *neigh_pos; struct neigh_node *neigh_node = NULL, *tmp_neigh_node, *best_neigh_node; int max_packet_count = 0; - + char is_new_seqno = 0;
debug_output( 4, "update_originator(): Searching and updating originator entry of received packet, \n" );
@@ -675,7 +678,7 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned }
- bit_get_packet( neigh_node->seq_bits, in->seqno - orig_node->last_seqno, 1 ); + is_new_seqno = bit_get_packet( neigh_node->seq_bits, in->seqno - orig_node->last_seqno, 1 ); neigh_node->packet_count = bit_packet_count( neigh_node->seq_bits );
if ( neigh_node->packet_count > max_packet_count ) { @@ -686,11 +689,13 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned }
- neigh_node->last_ttl = in->ttl; + neigh_node->last_ttl = in->ttl; //TBD: This may be applied only if new_seqno is true ??!! neigh_node->last_aware = get_time();
- orig_node->last_seqno = in->seqno; - + if( is_new_seqno ) { + debug_output( 4, "updating last_seqno: old %d, new %d \n", orig_node->last_seqno, in->seqno ); + orig_node->last_seqno = in->seqno; + }
/* update routing table and check for changed hna announcements */ update_routes( orig_node, best_neigh_node, hna_recv_buff, hna_buff_len ); @@ -939,6 +944,7 @@ void purge( unsigned int curr_time ) { list_for_each_safe(orig_pos, orig_temp, &orig_list) { orig_node = list_entry(orig_pos, struct orig_node, list);
+//TBD: (axel) during purge() the orig_node is purged after TIMEOUT while the neigh_nodes later on are purged after 2*TIMEOUT if ( (int)( ( orig_node->last_aware + TIMEOUT ) < curr_time ) ) {
addr_to_string(orig_node->orig, orig_str, ADDR_STR_LEN); @@ -1231,9 +1237,11 @@ int batman() is_bidirectional = isBidirectionalNeigh( orig_neigh_node, if_incoming );
/* update ranking */ - if ( ( is_bidirectional ) && ( !is_duplicate ) ) + if ( ( is_bidirectional ) && ( !is_duplicate ) ) { +//TBD: (axel) here the real originator should be updated but the orig_neigh_node ist provided to update_originator() update_originator( orig_neigh_node, (struct packet *)&in, neigh, if_incoming, hna_recv_buff, hna_buff_len ); - + } + /* is single hop (direct) neighbour */ if ( ((struct packet *)&in)->orig == neigh ) {
diff --git a/batman.h b/batman.h index a00a017..a067e0b 100644 --- a/batman.h +++ b/batman.h @@ -50,9 +50,9 @@
-#define TYPE_OF_WORD unsigned int /* you should choose something big, if you don't want to waste cpu */ +#define TYPE_OF_WORD unsigned long /* you should choose something big, if you don't want to waste cpu */ #define NUM_WORDS ( SEQ_RANGE / ( sizeof(TYPE_OF_WORD) * 8 ) ) -#define WORD_SIZE ( sizeof(TYPE_OF_WORD) * 8 ) +#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
@@ -204,7 +204,7 @@ void bit_init( TYPE_OF_WORD *seq_bits ); int bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned short curr_seqno ); void bit_mark( TYPE_OF_WORD *seq_bits, int n ); void bit_shift( TYPE_OF_WORD *seq_bits, int n ); -void bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ); +char bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ); int bit_packet_count( TYPE_OF_WORD *seq_bits );
#endif diff --git a/bitarray.c b/bitarray.c index e060fe0..3e1a592 100644 --- a/bitarray.c +++ b/bitarray.c @@ -22,6 +22,7 @@ #include <stdio.h> /* printf() */
#include "batman-specific.h" +#include "os.h"
@@ -46,8 +47,8 @@ int bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned shor
} else {
- word_offset= ( last_seqno - curr_seqno ) % WORD_SIZE; /* which position in the selected word */ - word_num = ( last_seqno - curr_seqno ) / WORD_SIZE; /* which word */ + word_offset= ( last_seqno - curr_seqno ) % WORD_BIT_SIZE; /* which position in the selected word */ + word_num = ( last_seqno - curr_seqno ) / WORD_BIT_SIZE; /* which word */
if ( seq_bits[word_num] & 1<<word_offset ) /* get position status */ return 1; @@ -58,6 +59,20 @@ int bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned shor
}
+/* print the packet array, for debugging purposes */ +void bit_print( TYPE_OF_WORD *seq_bits ) { + int i,j; + +// printf("the last %d packets, we got %d:\n", SEQ_RANGE, bit_packet_count(seq_bits)); + for ( i=0; i<NUM_WORDS; i++ ) { + for ( j=0; j<WORD_BIT_SIZE; j++) { + printf("%ld", (seq_bits[i]>>j)%2 ); /* print the j position */ + } + printf(" "); + } + printf("\n\n"); +} + /* turn on bit on, so we can remember that we got the packet */ void bit_mark( TYPE_OF_WORD *seq_bits, int n ) { int word_offset,word_num; @@ -69,8 +84,8 @@ void bit_mark( TYPE_OF_WORD *seq_bits, int n ) {
// printf("mark bit %d\n", n);
- word_offset= n%WORD_SIZE; /* which position in the selected word */ - word_num = n/WORD_SIZE; /* which word */ + word_offset= n%WORD_BIT_SIZE; /* which position in the selected word */ + word_num = n/WORD_BIT_SIZE; /* which word */
seq_bits[word_num]|= 1<<word_offset; /* turn the position on */ } @@ -80,9 +95,12 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int n ) { int word_offset, word_num; int i;
+ printf("bit_shift(): to shift %d bits \n", n); + bit_print( seq_bits ); + if( n<=0 ) return;
- word_offset= n%WORD_SIZE; /* shift how much inside each word */ - word_num = n/WORD_SIZE; /* shift over how much (full) words */ + word_offset= n%WORD_BIT_SIZE; /* shift how much inside each word */ + word_num = n/WORD_BIT_SIZE; /* shift over how much (full) words */
for ( i=NUM_WORDS-1; i>word_num; i-- ) { /* going from old to new, so we can't overwrite the data we copy from. * @@ -90,7 +108,7 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int n ) { * ^^ ^^ * vvvv * ^^^^ = from, vvvvv =to, we'd have word_num==1 and - * word_offset==WORD_SIZE/2 in this example. + * word_offset==WORD_BIT_SIZE/2 ????? in this example. (=24 bits) * * our desired output would be: 9876 5432 1000 0000 * */ @@ -98,7 +116,7 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int n ) { seq_bits[i]= (seq_bits[i - word_num] << word_offset) + /* take the lower port from the left half, shift it left to its final position */ - (seq_bits[i - word_num - 1] >> (WORD_SIZE-word_offset)); + (seq_bits[i - word_num - 1] >> (WORD_BIT_SIZE-word_offset)); /* and the upper part of the right half and shift it left to it's position */ /* for our example that would be: word[0] = 9800 + 0076 = 9876 */ } @@ -113,37 +131,28 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int n ) { for (; i>=0; i--) { seq_bits[i]= 0; } + bit_print( seq_bits ); }
-/* print the packet array, for debugging purposes */ -void bit_print( TYPE_OF_WORD *seq_bits ) { - int i,j;
-// printf("the last %d packets, we got %d:\n", SEQ_RANGE, bit_packet_count(seq_bits)); - for ( i=0; i<NUM_WORDS; i++ ) { - for ( j=0; j<WORD_SIZE; j++) { - printf("%d", (seq_bits[i]>>j)%2 ); /* print the j position */ - } - printf(" "); - } - printf("\n\n"); -} - -/* receive and process one packet */ -void bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ) { +/* receive and process one packet, returns 1 if received seq_num is considered new, 0 if old */ +char bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ) {
int i; + debug_output(4, "bit_get_packet( seq_num_diff: %d, set_mark: %d ):", seq_num_diff, set_mark);
- if ( ( seq_num_diff < 0 ) && ( -seq_num_diff <= SEQ_RANGE ) ) { /* we already got a sequence number higher than this one, so we just mark it. this should wrap around the integer just fine */ + if ( ( seq_num_diff < 0 ) && ( seq_num_diff >= -SEQ_RANGE ) ) { /* we already got a sequence number higher than this one, so we just mark it. this should wrap around the integer just fine */ + printf(" we already got a sequence number higher than this one, so we just mark it. \n");
if ( set_mark ) bit_mark( seq_bits, -seq_num_diff );
- return; + return 0;
}
- if ( ( seq_num_diff > SEQ_RANGE ) || ( -seq_num_diff > SEQ_RANGE ) ) { /* it seems we missed a lot of packets or the other host restarted */ + if ( ( seq_num_diff > SEQ_RANGE ) || ( seq_num_diff < -SEQ_RANGE ) ) { /* it seems we missed a lot of packets or the other host restarted */ + debug_output(4, " it seems we missed a lot of packets or the other host restarted \n");
/* if ( seq_num_diff > SEQ_RANGE ) printf("d'oh, BIG loss (missed %d packets)!!\n", seq_num_diff-1); @@ -158,6 +167,7 @@ void bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ) { seq_bits[0] = 1; /* we only have the latest packet */
} else { + debug_output(4," new seq_no \n");
bit_shift(seq_bits, seq_num_diff);
@@ -166,6 +176,8 @@ void bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ) {
}
+ return 1; + }
/* count the hamming weight, how many good packets did we receive? just count the 1's ... */ @@ -186,8 +198,8 @@ int bit_packet_count( TYPE_OF_WORD *seq_bits ) { }
} - - /* printf( "packets counted: %i\n", hamming ); */ +// bit_print( seq_bits ); +// printf( "packets counted: %i\n", hamming ); return(hamming);
}