The following commit has been merged in the master branch: commit e7b3ebda883bcd73ba9573ca64c60ce468a3a232 Author: Axel Neumann neumann@cgws.de Date: Wed Jan 24 11:34:35 2007 +0100
allowing SEQ_RANGE to be any number
diff --git a/batman.c b/batman.c index e375bb0..5865a0f 100644 --- a/batman.c +++ b/batman.c @@ -549,7 +549,6 @@ 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,14 +556,12 @@ 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, " %s(%i) %s", str, neigh_node->packet_count, bit_print( neigh_node->seq_bits ) ); + debug_output( 4, "\t\t%s (%d) %s\n", str, neigh_node->packet_count , bit_print( neigh_node->seq_bits ) );
}
debug_output( 1, "\n" ); - //printf( "\n" );
}
@@ -597,7 +594,7 @@ int isDuplicate( unsigned int orig, unsigned short seqno ) { list_for_each(neigh_pos, &orig_node->neigh_list) { neigh_node = list_entry(neigh_pos, struct neigh_node, list);
- if ( bit_status( neigh_node->seq_bits, orig_node->last_seqno, seqno ) ) + if ( get_bit_status( neigh_node->seq_bits, orig_node->last_seqno, seqno ) ) return 1;
} @@ -703,6 +700,7 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned
/* update routing table and check for changed hna announcements */ update_routes( orig_node, best_neigh_node, hna_recv_buff, hna_buff_len ); +debug_output( 4, "update_routes complete \n" );
if ( orig_node->gwflags != in->gwflags ) update_gw_list( orig_node, in->gwflags ); diff --git a/batman.h b/batman.h index a067e0b..d60c084 100644 --- a/batman.h +++ b/batman.h @@ -46,12 +46,16 @@ #define JITTER 50 #define TTL 50 /* Time To Live of broadcast messages */ #define TIMEOUT 60000 /* sliding window size of received orginator messages in ms */ -#define SEQ_RANGE 64 /* sliding packet range of received orginator messages in squence numbers (should be a multiple of our word size) */ +#define SEQ_RANGE 60 /* sliding packet range of received orginator messages in squence numbers (should be a multiple of our word size) */
#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 ) ) + +//TBD: this shall be evaluated only once during initialization, macros are called tooo often, waste of processtime +#define MIN_NUM_WORDS ( SEQ_RANGE / ( sizeof(TYPE_OF_WORD) * 8 ) ) +#define RST_NUM_WORDS ( SEQ_RANGE % ( sizeof(TYPE_OF_WORD) * 8 ) ) +#define NUM_WORDS ( RST_NUM_WORDS ? ( MIN_NUM_WORDS + 1) : MIN_NUM_WORDS ) #define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
@@ -201,7 +205,8 @@ void del_default_route(); int add_default_route();
void bit_init( TYPE_OF_WORD *seq_bits ); -int bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned short curr_seqno ); +int get_bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned short curr_seqno ); +char* bit_print( TYPE_OF_WORD *seq_bits ); void bit_mark( TYPE_OF_WORD *seq_bits, int n ); void bit_shift( TYPE_OF_WORD *seq_bits, int n ); char bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ); diff --git a/bitarray.c b/bitarray.c index e02c9e3..72e390b 100644 --- a/bitarray.c +++ b/bitarray.c @@ -36,11 +36,11 @@ void bit_init( TYPE_OF_WORD *seq_bits ) {
};
-/* turn on bit on, so we can remember that we got the packet */ -int bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned short curr_seqno ) { +/* returns true if corresponding bit in given seq_bits indicates so and curr_seqno is within range of last_seqno */ +int get_bit_status( TYPE_OF_WORD *seq_bits, unsigned short last_seqno, unsigned short curr_seqno ) {
int word_offset,word_num; - +//TBD: not shure for wrap arounds, what about: if ( curr_seqno - last_seqno > 0 || curr_seqno - last_seqno < if ( curr_seqno > last_seqno || curr_seqno < last_seqno - SEQ_RANGE ) {
return 0; @@ -60,24 +60,31 @@ 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; +static char bit_string[130]; +char* bit_print( TYPE_OF_WORD *seq_bits ) { + int i,j,k=0,b=0;
// 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 */ + bit_string[k++] = ((seq_bits[i]>>j)%2 ? '1':'0'); /* print the j position */ + if( ++b == SEQ_RANGE ) { + bit_string[k++]='|'; + } } - printf(" "); + bit_string[k++]=' '; } - printf("\n\n"); + bit_string[k++]='\0'; +// debug_output( 4, "%s\n", bit_string); +// printf("\n\n"); + return bit_string; }
-/* turn on bit on, so we can remember that we got the packet */ +/* turn corresponding 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;
- if ( n >= SEQ_RANGE ) { /* if too old, just drop it */ + if ( n<0 || n >= SEQ_RANGE ) { /* if too old, just drop it */ // printf("got old packet, dropping\n"); return; } @@ -138,6 +145,9 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int n ) { char bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ) {
int i; + +// if ( n<0 || n >= SEQ_RANGE) return 0; + 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 */ @@ -183,11 +193,15 @@ 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 ) {
int i, hamming = 0; - TYPE_OF_WORD word; + TYPE_OF_WORD word, pattern=~0;
for (i=0; i<NUM_WORDS; i++) {
- word= seq_bits[i]; +// if( i == NUM_WORDS - 1 ) { +// pattern = pattern >> ( WORD_BIT_SIZE - RST_NUM_WORDS ); +// } + + word= seq_bits[i] & ( ( i < NUM_WORDS - 1 ) ? ~0 : pattern >> ( WORD_BIT_SIZE - RST_NUM_WORDS ) );
while (word) {
@@ -197,8 +211,7 @@ int bit_packet_count( TYPE_OF_WORD *seq_bits ) { }
} -// bit_print( seq_bits ); -// printf( "packets counted: %i\n", hamming ); + return(hamming);
}