All interfaces now use a common synchronised tick-clock so that we can

more easily keep track of node reachability.
This commit is contained in:
gardners 2011-08-20 19:06:15 +09:30
parent 28a5214f26
commit 857bf9c11e
5 changed files with 50 additions and 11 deletions

View File

@ -439,7 +439,8 @@ typedef struct overlay_interface {
For ~10K ISM915MHz (nominal range ~3000m) it will probably be about 15000ms.
These figures will be refined over time, and we will allow people to set them per-interface.
*/
int tick_ms;
int tick_ms; /* milliseconds per tick */
/* The time of the last tick on this interface in milli seconds */
long long last_tick_ms;
/* How many times have we abbreviated our address since we last announced it in full? */
@ -470,6 +471,8 @@ typedef struct overlay_interface {
*/
#define OVERLAY_MAX_INTERFACES 16
extern overlay_interface overlay_interfaces[OVERLAY_MAX_INTERFACES];
extern unsigned int overlay_sequence_number;
extern time_t overlay_sequence_start_time;
/* Has someone sent us an abbreviation of an unknown type recently? If so remind them
that we don't accept these.

View File

@ -307,20 +307,20 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
case OA_CODE_PREFIX3: case OA_CODE_PREFIX3_INDEX1: /* 3-byte prefix */
if (in[*inofs]==0x09) bytes=1;
r=overlay_abbreviate_cache_lookup(&in[(*inofs)+1],out,ofs,3,bytes);
(*inofs)+=3+bytes;
(*inofs)+=1+3+bytes;
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
return r;
case OA_CODE_PREFIX7: case OA_CODE_PREFIX7_INDEX1: /* 7-byte prefix */
if (in[*inofs]==OA_CODE_PREFIX7_INDEX1) bytes=1;
r=overlay_abbreviate_cache_lookup(&in[(*inofs)+1],out,ofs,7,bytes);
(*inofs)+=7+bytes;
(*inofs)+=1+7+bytes;
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
return r;
case OA_CODE_PREFIX11: case OA_CODE_PREFIX11_INDEX1: case OA_CODE_PREFIX11_INDEX2: /* 11-byte prefix */
if (in[*inofs]==OA_CODE_PREFIX11_INDEX1) bytes=1;
if (in[*inofs]==OA_CODE_PREFIX11_INDEX2) bytes=2;
r=overlay_abbreviate_cache_lookup(&in[(*inofs)+1],out,ofs,11,bytes);
(*inofs)+=11+bytes;
(*inofs)+=1+11+bytes;
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
return r;
case OA_CODE_BROADCAST: /* broadcast */

View File

@ -19,9 +19,26 @@ struct interface_rules {
struct interface_rules *interface_filter=NULL;
unsigned int overlay_sequence_number=0;
time_t overlay_sequence_start_time;
/* Do we need to repeat our abbreviation policy? */
int overlay_interface_repeat_abbreviation_policy[OVERLAY_MAX_INTERFACES]={1};
int overlay_update_sequence_number()
{
struct timeval nowtv;
if (gettimeofday(&nowtv,NULL))
return WHY("gettimeofday() failed");
/* Get current time in milliseconds */
long long now=(nowtv.tv_sec-overlay_sequence_start_time)*1000LL;
now=now+nowtv.tv_usec/1000;
overlay_sequence_number=now&0xffffffff;
return 0;
}
int overlay_interface_type(char *s)
{
if (!strcasecmp(s,"ethernet")) return OVERLAY_INTERFACE_ETHERNET;
@ -141,6 +158,8 @@ int overlay_interface_init_socket(int interface,struct sockaddr_in src_addr,stru
I(netmask)=netmask;
I(fileP)=0;
overlay_sequence_start_time=time(0);
I(fd)=socket(PF_INET,SOCK_DGRAM,0);
if (I(fd)<0) {
return WHY("Could not create UDP socket for interface");
@ -460,7 +479,6 @@ int overlay_tick_interface(int i, long long now)
}
if (debug&4) fprintf(stderr,"Ticking interface #%d\n",i);
overlay_interfaces[i].sequence_number++;
/* Get a buffer ready, and limit it's size appropriately.
XXX size limit should be reduced from MTU.
@ -529,8 +547,9 @@ int overlay_tick_interface(int i, long long now)
if (debug&4) fprintf(stderr,"Sending %d bytes\n",e->length);
if (!overlay_broadcast_ensemble(i,e->bytes,e->length))
{
overlay_update_sequence_number();
fprintf(stderr,"Successfully transmitted tick frame #%d on interface #%d (%d bytes)\n",
overlay_interfaces[i].sequence_number,i,e->length);
overlay_sequence_number,i,e->length);
/* De-queue the passengers who were aboard. */
int j;
overlay_frame **p=&overlay_tx[OVERLAY_ISOCHRONOUS_VOICE].first;

View File

@ -214,7 +214,7 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
/* Add space for Remaining Frame Size field. This will always be a single byte
for self-announcments as they are always <256 bytes. */
c=1+1+(send_prefix?(1+7):SID_SIZE)+4;
c=1+1+(send_prefix?(1+7):SID_SIZE)+4+4;
if (ob_append_bytes(b,&c,1))
return WHY("ob_append_bytes() could not add RFS for self-announcement frame");
@ -249,9 +249,11 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
overlay_interfaces[interface].ticks_since_sent_full_address++;
}
/* A sequence number, so that others can keep track of their reception of our frames.
These are per-interface */
if (ob_append_int(b,overlay_interfaces[interface].sequence_number))
/* Sequence number range. Based on one tick per milli-second. */
overlay_update_sequence_number();
if (ob_append_int(b,overlay_sequence_number))
return WHY("ob_append_int() could not add sequence number to self-announcement");
if (ob_append_int(b,overlay_sequence_number+overlay_interfaces[interface].tick_ms-1))
return WHY("ob_append_int() could not add sequence number to self-announcement");

View File

@ -287,7 +287,7 @@ int overlay_route_init(int mb_ram)
overlay_bin_size=associativity;
fprintf(stderr,"Node and neighbour tables allocated.\n");
return WHY("Not implemented");
return 0;
}
int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen)
@ -300,6 +300,21 @@ int overlay_route_saw_selfannounce(overlay_frame *f)
{
/* XXX send ack out even if we have no structures setup? */
if (!overlay_neighbours) return 0;
#ifdef NOT_DEFINED
/* Lookup node in node cache */
overlay_node *n=overlay_route_find_node(f->source);
if (!n) return WHY("Could not find node record for observed node");
#endif
/* Update observations of this node, and then insert it into the neighbour list if it is not
already there. */
unsigned int s1,s2;
s1=ntohl(*((int*)&f->payload[0]));
s2=ntohl(*((int*)&f->payload[4]));
fprintf(stderr,"Received self-announcement for sequence range [%08x,%08x]\n",s1,s2);
return WHY("Not implemented");
}