nlsr_adl clean, timestamp function
diff --git a/macbook.conf b/macbook.conf
index fbff79a..7310e35 100644
--- a/macbook.conf
+++ b/macbook.conf
@@ -1,9 +1,8 @@
#----configuration file for macbook----------
#
router-name /ndn/memphis.edu/netlab/macbook
-ccnneighbor /ndn/memphis.edu/cs/maia
-#ccnneighbor /ndn/memphis.edu/cs/mira
-#ccnneighbor /ndn/memphis.edu/cs/castor
+ccnneighbor /ndn/memphis.edu/cs/gemeni
+ccnneighbor /ndn/memphis.edu/cs/altair
ccnneighbor /ndn/memphis.edu/cs/pollux 141.225.11.132
ccnname /ndn/memphis.edu/macbook/patterson
ccnname /ndn/memphis.edu/macbook/houston/
diff --git a/nlsr.c b/nlsr.c
index 4f50669..b3816b5 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -162,9 +162,7 @@
char *rtr_name;
char *nbr_ip_addr;
int is_ip_configured=0;
- //char *face;
char *ip_addr=(char *)calloc(20,sizeof(char));
- //memset(ip_addr,0,12);
rtr_name=strtok_r(command,sep,&rem);
if(rtr_name==NULL)
@@ -185,7 +183,6 @@
}
struct name_prefix *nbr=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
nbr->name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
- //memset(nbr->name,0,strlen(rtr_name)+1);
memcpy(nbr->name,rtr_name,strlen(rtr_name)+1);
nbr->length=strlen(rtr_name)+1;
@@ -204,7 +201,7 @@
}
else
{
- memcpy(ip_addr,nbr_ip_addr,strlen(nbr_ip_addr));
+ memcpy(ip_addr,nbr_ip_addr,strlen(nbr_ip_addr)+1);
if (nlsr->debugging)
{
printf("Name of neighbor: %s ",nbr->name);
@@ -483,8 +480,7 @@
}
nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char));
- //memset(nlsr->logDir,0,strlen(dir)+1);
- memcpy(nlsr->logDir,dir,strlen(dir));
+ memcpy(nlsr->logDir,dir,strlen(dir)+1);
}
void
@@ -564,7 +560,7 @@
topo_prefix[strlen(topo_prefix)-1]='\0';
nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char));
- memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix));
+ memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
printf ("Topo prefix is: %s", nlsr->topo_prefix);;
}
}
@@ -596,7 +592,7 @@
slice_prefix[strlen(slice_prefix)-1]='\0';
nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
- memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix));
+ memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
}
}
@@ -1211,7 +1207,6 @@
nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
char *time_stamp=(char *) calloc (20,sizeof(char));
- //memset(time_stamp,0,20);
get_current_timestamp_micro(time_stamp);
nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp));
diff --git a/nlsr_adl.c b/nlsr_adl.c
index 947d5ac..6076f89 100644
--- a/nlsr_adl.c
+++ b/nlsr_adl.c
@@ -31,7 +31,7 @@
void
add_nbr_to_adl(struct name_prefix *new_nbr,int face,char *ip)
{
- struct ndn_neighbor *nbr;//=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free
+ struct ndn_neighbor *nbr;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -45,7 +45,7 @@
nbr = e->data;
- nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free
+ nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix ));
nbr->neighbor->name=(char *)malloc(new_nbr->length);
memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length);
nbr->neighbor->length=new_nbr->length;
@@ -58,18 +58,17 @@
nbr->metric=LINK_METRIC;
nbr->is_lsdb_send_interest_scheduled=0;
- nbr->ip_address=(char *)malloc(strlen(ip)+1);
- memset(nbr->ip_address,0,strlen(ip)+1);
- memcpy(nbr->ip_address,ip,strlen(ip));
+ nbr->ip_address=(char *)calloc(strlen(ip)+1,sizeof(char));
+ memcpy(nbr->ip_address,ip,strlen(ip)+1);
char *time_stamp=(char *)malloc(20);
get_current_timestamp_micro(time_stamp);
- nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free
+ nbr->last_lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
- memset(nbr->last_lsdb_version,'0',strlen(time_stamp));
- nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free
+ memset(nbr->last_lsdb_version,'0',strlen(time_stamp)+1);
+ nbr->last_info_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1);
- memset(nbr->last_info_version,'0',strlen(time_stamp));
+ memset(nbr->last_info_version,'0',strlen(time_stamp)+1);
free(time_stamp);
nbr->last_lsdb_requested=0;
@@ -399,7 +398,14 @@
if (res == HT_OLD_ENTRY)
{
- hashtb_delete(e);
+ struct ndn_neighbor *nbr=e->data;
+ free(nbr->neighbor->name);
+ free(nbr->neighbor);
+ free(nbr->last_lsdb_version);
+ free(nbr->last_info_version);
+ free(nbr->ip_address);
+ hashtb_delete(e);
+
}
else if(res == HT_NEW_ENTRY)
{
@@ -535,14 +541,6 @@
free(temp_length);
ccn_charbuf_append_string(c,"|");
- /*char *temp_face=(char *)malloc(20);
- memset(temp_face,0,20);
- sprintf(temp_face,"%d",nbr->face);
- ccn_charbuf_append_string(c,temp_face);
- free(temp_face);
- ccn_charbuf_append_string(c,"|");
- */
-
char *temp_metric=(char *)malloc(20);
memset(temp_metric,0,20);
sprintf(temp_metric,"%d",nbr->metric);
@@ -557,314 +555,6 @@
hashtb_end(e);
}
-long int
-get_nbr_time_diff_lsdb_req(char *nbr)
-{
- if ( nlsr->debugging )
- printf("get_nbr_time_diff_lsdb_req called\n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n");
-
- long int time_diff=get_lsdb_synch_interval(nbr)+1;
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
-
- if (nnbr->last_lsdb_requested == 0)
- time_diff=get_lsdb_synch_interval(nbr)+1;
- else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
-
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return time_diff;
-}
-
-long int
-get_nbr_last_lsdb_requested(char *nbr)
-{
- if ( nlsr->debugging )
- printf("get_timed_out_number called\n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n");
-
- long int last_lsdb_requested=0;
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- last_lsdb_requested=nnbr->last_lsdb_requested;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return last_lsdb_requested;
-}
-
-
-int
-get_nbr_random_time_component(char *nbr)
-{
- if ( nlsr->debugging )
- printf("get_nbr_random_time_component called\n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n");
-
- int time=0;
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- time=nnbr->lsdb_random_time_component * (int)pow(-1,nnbr->lsdb_interest_timed_out+1);
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return time;
-}
-
-long int
-get_lsdb_synch_interval(char *nbr)
-{
- if ( nlsr->debugging )
- printf("get_lsdb_synch_interval called \n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n");
-
- long int lsdb_synch_interval=300;
-
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- lsdb_synch_interval=nnbr->lsdb_synch_interval;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return lsdb_synch_interval;
-
-}
-
-char *
-get_nbr_lsdb_version(char *nbr)
-{
- if ( nlsr->debugging )
- printf("get_nbr_lsdb_version called \n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n");
-
- char *version=NULL;
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1);
- memset(version,0,strlen(nnbr->last_lsdb_version)+1);
- memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1);
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return version;
-}
-
-void
-update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp)
-{
- if ( nlsr->debugging )
- printf("update_adjacent_last_lsdb_requested_to_adl called \n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n");
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if( res == HT_OLD_ENTRY )
- {
- nnbr=e->data;
- nnbr->last_lsdb_requested=timestamp;
-
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-}
-
-void
-set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
-{
- if ( nlsr->debugging )
- printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n");
-
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- nnbr->is_lsdb_send_interest_scheduled=0;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-}
-
-void
-update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
-{
- if ( nlsr->debugging )
- printf("update_adjacent_timed_out_to_adl called \n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n");
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr->name, nbr->length, 0);
-
- if( res == HT_OLD_ENTRY )
- {
- nnbr=e->data;
- free(nnbr->last_lsdb_version);
- nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
- memset(nnbr->last_lsdb_version,0,strlen(version)+1);
- memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
-}
-
-void
-adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
-{
- printf("update_adjacent_last_lsdb_requested_to_adl called \n");
-
- if ( nlsr->debugging )
- printf("update_adjacent_last_lsdb_requested_to_adl called \n");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n");
-
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if( res == HT_OLD_ENTRY )
- {
- nnbr=e->data;
- nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
-
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
-}
int
get_next_hop_face_from_adl(char *nbr)
@@ -1024,8 +714,7 @@
}
- name_part->name=(char *)malloc(strlen(neighbor)+1);
- memset(name_part->name,0,strlen(neighbor)+1);
+ name_part->name=(char *)calloc(strlen(neighbor)+1,sizeof(char));
memcpy(name_part->name,neighbor,strlen(neighbor)+1);
name_part->length=strlen(neighbor)+1;
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index 46a9428..6c18921 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -34,16 +34,18 @@
void
set_new_lsdb_version(void)
{
- char *time_stamp=(char *)malloc(20);
- memset(time_stamp,0,20);
- get_current_timestamp_micro(time_stamp);
+ //char *time_stamp=(char *)malloc(20);
+ //memset(time_stamp,0,20);
+ //get_current_timestamp_micro(time_stamp);
+ char *time_stamp=get_current_timestamp_micro_v2();
free(nlsr->lsdb->lsdb_version);
- nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
- memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
+ nlsr->lsdb->lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
-
free(time_stamp);
+ //memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
+
+ //free(time_stamp);
}
diff --git a/utility.c b/utility.c
index 0c0be75..6a7cb0c 100644
--- a/utility.c
+++ b/utility.c
@@ -62,7 +62,17 @@
}
-
+int
+get_width_of_number(long int number)
+{
+ int i=0;
+ while(number>0)
+ {
+ i++;
+ number/=10;
+ }
+ return i;
+}
long int
get_current_time_sec(void)
@@ -81,6 +91,18 @@
sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec);
}
+char *
+get_current_timestamp_micro_v2()
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ //sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec);
+ char *microSec=(char *)calloc(get_width_of_number(now.tv_sec)+7,sizeof(char));
+ sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec);
+ microSec[strlen(microSec)]='\0';
+
+ return microSec;
+}
long int
get_time_diff(const char *time1, const char *time2)
@@ -268,9 +290,10 @@
for(i = 0; addr_list[i] != NULL; i++)
{
strcpy(ip , inet_ntoa(*addr_list[i]) );
+ ip[strlen(ip)]='\0';
return 0;
}
- return 1;
+ return -1;
}
diff --git a/utility.h b/utility.h
index f90c281..bbca9f6 100644
--- a/utility.h
+++ b/utility.h
@@ -11,4 +11,5 @@
void writeLogg(const char *source_file, const char *function, const int line, const char *format, ...);
struct sockaddr_in * get_ip_from_hostname(char *hostname);
int get_ip_from_hostname_02(char * hostname , char* ip);
+char * get_current_timestamp_micro_v2();
#endif