Timestamp New Function Used in nlsr_lsdb
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index a2eb400..9eb5b98 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -120,22 +120,80 @@
*/
void
-destroy_name_lsa(struct nlsa * name_lsa)
+destroy_name_lsa_component(struct nlsa * name_lsa)
{
if ( name_lsa->header->orig_router->name )
free(name_lsa->header->orig_router->name);
if ( name_lsa->header->orig_router )
free(name_lsa->header->orig_router);
+ if ( name_lsa->header->orig_time )
+ free(name_lsa->header->orig_time);
if ( name_lsa->header )
free(name_lsa->header);
+
if ( name_lsa->name_prefix->name )
free(name_lsa->name_prefix->name);
if ( name_lsa->name_prefix )
free(name_lsa->name_prefix);
+}
+
+void
+destroy_name_lsa(struct nlsa * name_lsa)
+{
+ destroy_name_lsa_component(name_lsa);
if ( name_lsa )
free(name_lsa);
}
+void
+destroy_adj_lsa_component(struct alsa * adj_lsa)
+{
+ if ( adj_lsa->header->orig_router->name )
+ free(adj_lsa->header->orig_router->name);
+ if ( adj_lsa->header->orig_router )
+ free(adj_lsa->header->orig_router);
+ if ( adj_lsa->header->orig_time )
+ free(adj_lsa->header->orig_time);
+ if ( adj_lsa->header )
+ free(adj_lsa->header);
+
+ if ( adj_lsa->body )
+ free(adj_lsa->body);
+}
+
+void
+destroy_adj_lsa(struct alsa * adj_lsa)
+{
+
+ destroy_adj_lsa_component(adj_lsa);
+ if ( adj_lsa )
+ free(adj_lsa);
+}
+
+void
+destroy_cor_lsa_component(struct clsa * cor_lsa)
+{
+ if ( cor_lsa->header->orig_router->name )
+ free(cor_lsa->header->orig_router->name);
+ if ( cor_lsa->header->orig_router )
+ free(cor_lsa->header->orig_router);
+ if ( cor_lsa->header->orig_time )
+ free(cor_lsa->header->orig_time);
+ if ( cor_lsa->header )
+ free(cor_lsa->header);
+}
+
+void
+destroy_cor_lsa(struct clsa * cor_lsa)
+{
+
+ destroy_cor_lsa_component(cor_lsa);
+ if ( cor_lsa )
+ free(cor_lsa);
+}
+
+
+
void
build_and_install_name_lsas(void)
{
@@ -198,10 +256,6 @@
{
name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
name_lsa->header->ls_type=LS_TYPE_NAME;
-
- //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();
name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
@@ -213,7 +267,6 @@
name_lsa->header->ls_id=++nlsr->nlsa_id;
name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
name_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
- //memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
name_lsa->header->isValid=1;
@@ -230,11 +283,6 @@
install_name_lsa(struct nlsa *name_lsa)
{
- /*char *time_stamp=(char *)malloc(20);
- memset(time_stamp,0,20);
- get_current_timestamp_micro(time_stamp);*/
-
-
char lst[2];
memset(lst,0,2);
sprintf(lst,"%d",name_lsa->header->ls_type);
@@ -252,7 +300,7 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key));
- struct nlsa *new_name_lsa; //=(struct nlsa*)malloc(sizeof(struct nlsa ));
+ struct nlsa *new_name_lsa;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -264,6 +312,8 @@
if(res == HT_NEW_ENTRY )
{
+ if ( name_lsa->header->isValid == 1 )
+ {
if ( nlsr->debugging )
printf("New Name LSA... Adding to LSDB\n");
if ( nlsr->detailed_logging )
@@ -271,7 +321,6 @@
new_name_lsa = e->data;
- //memcpy(e->data, name_lsa, sizeof(name_lsa));
new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
@@ -360,10 +409,15 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
- //write_log_for_name_lsa(new_name_lsa);
+ write_log_for_name_lsa(new_name_lsa);
writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
//free(time_stamp);
+ }
+ else
+ {
+ hashtb_delete(e);
+ }
}
else if(res == HT_OLD_ENTRY)
@@ -529,7 +583,7 @@
hashtb_end(e);
- //free(key);
+ free(key);
}
void
@@ -617,12 +671,7 @@
print_name_lsdb();
print_npt();
- free(name_lsa->header->orig_router->name);
- free(name_lsa->header->orig_router);
- free(name_lsa->header);
- free(name_lsa->name_prefix->name);
- free(name_lsa->name_prefix);
- free(name_lsa);
+ destroy_name_lsa(name_lsa);
}
@@ -634,25 +683,22 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
- name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
+ name_lsa->header=(struct nlsa_header *)calloc(1,sizeof(struct nlsa_header ));
name_lsa->header->ls_type=LS_TYPE_NAME;
- name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
- memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
- memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time));
+ name_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
+ memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
name_lsa->header->ls_id=ls_id;
- name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
- memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
- memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router));
+ name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
+ name_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
+ memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
name_lsa->header->orig_router->length=strlen(orig_router)+1;
name_lsa->header->isValid=isValid;
- name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
- memset(name_lsa->name_prefix->name,0,strlen(np)+1);
- memcpy(name_lsa->name_prefix->name,np,strlen(np));
+ name_lsa->name_prefix=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
+ name_lsa->name_prefix->name=(char *)calloc(strlen(np)+1,sizeof(char));
+ memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
name_lsa->name_prefix->length=strlen(np)+1;
}
@@ -717,41 +763,32 @@
memset(lst,0,2);
sprintf(lst,"%d",LS_TYPE_ADJ);
- char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15);
- memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15);
- make_adj_lsa_prefix_for_repo(repo_key, adj_lsa->header->orig_router->name,LS_TYPE_ADJ,adj_lsa->header->orig_time,nlsr->slice_prefix);
+ char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15,sizeof(char));
+ make_adj_lsa_prefix_for_repo(repo_key, adj_lsa->header->orig_router->name,LS_TYPE_ADJ,adj_lsa->header->orig_time,nlsr->slice_prefix);
if ( nlsr->debugging )
printf("Adj LSA Repo Key: %s \n",repo_key);
- char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
- memset(key,0,adj_lsa->header->orig_router->length+2+2);
+ char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,sizeof(char));
make_adj_lsa_key(key,adj_lsa);
if ( nlsr->debugging )
printf("Adj LSA: %s \n",key);
- struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
- lsaid->name=(char *)malloc(strlen(key)+1);
- memset(lsaid->name, 0, strlen(key)+1);
- memcpy(lsaid->name,key,strlen(key));
+ struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
+ lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
+ memcpy(lsaid->name,key,strlen(key)+1);
lsaid->length=strlen(key)+1;
write_adj_lsa_to_repo(repo_key, lsaid);
- //free(key);
+ free(key);
free(repo_key);
free(lsaid->name);
free(lsaid);
+ destroy_adj_lsa(adj_lsa);
-
- free(adj_lsa->header->orig_router->name);
- free(adj_lsa->header->orig_router);
- free(adj_lsa->header->orig_time);
- free(adj_lsa->header);
- free(adj_lsa->body);
- free(adj_lsa);
nlsr->adj_build_flag=0;
print_adj_lsdb();
}
@@ -790,10 +827,8 @@
adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
- 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();
adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
@@ -806,9 +841,10 @@
get_active_nbr_adj_data(c);
char *data=ccn_charbuf_as_string(c);
- adj_lsa->body=(char *)malloc(strlen(data)+1);
- memset(adj_lsa->body,0,strlen(data)+1);
+ adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
+ //memset(adj_lsa->body,0,strlen(data)+1);
memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
+ data[strlen(data)]='\0';
ccn_charbuf_destroy(&c);
nlsr->adj_build_count++;
@@ -827,13 +863,9 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
- char *time_stamp=(char *)malloc(20);
- memset(time_stamp,0,20);
- get_current_timestamp_micro(time_stamp);
- char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
- memset(key,0,adj_lsa->header->orig_router->length+2);
+ char *key=(char *)calloc(adj_lsa->header->orig_router->length+4,sizeof(char));
make_adj_lsa_key(key,adj_lsa);
struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
@@ -857,20 +889,20 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
new_adj_lsa = e->data;
- new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+ new_adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
- new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
+ new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
- new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
+ new_adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
+ new_adj_lsa->header->orig_router->name=(char *)calloc(adj_lsa->header->orig_router->length,sizeof(char));
memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
new_adj_lsa->no_link=adj_lsa->no_link;
- new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
- memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
+ new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
+ //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
add_next_hop_router(new_adj_lsa->header->orig_router->name);
@@ -920,13 +952,13 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
free(new_adj_lsa->header->orig_time);
- new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
+ new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
new_adj_lsa->no_link=adj_lsa->no_link;
- new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
- memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
+ new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
+ //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
@@ -969,17 +1001,17 @@
}
- //free(key);
+ free(key);
- free(time_stamp);
+ //free(time_stamp);
}
void
write_log_for_adj_lsa_body(const char *body, int no_link)
{
int i=0;
- char *lsa_data=(char *)malloc(strlen(body)+1);
- memset( lsa_data,0,strlen(body)+1);
+ char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
+ //memset( lsa_data,0,strlen(body)+1);
memcpy(lsa_data,body,strlen(body)+1);
char *sep="|";
char *rem;
@@ -1017,7 +1049,8 @@
}
}
- free(lsa_data);
+ if(lsa_data)
+ free(lsa_data);
}
@@ -1042,8 +1075,8 @@
print_adj_lsa_body(const char *body, int no_link)
{
int i=0;
- char *lsa_data=(char *)malloc(strlen(body)+1);
- memset( lsa_data,0,strlen(body)+1);
+ char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
+ //memset( lsa_data,0,strlen(body)+1);
memcpy(lsa_data,body,strlen(body)+1);
char *sep="|";
char *rem;
@@ -1082,7 +1115,8 @@
}
}
- free(lsa_data);
+ if( lsa_data )
+ free(lsa_data);
}
void
@@ -1146,13 +1180,7 @@
build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
install_adj_lsa(adj_lsa);
-
- free(adj_lsa->header->orig_router->name);
- free(adj_lsa->header->orig_router);
- free(adj_lsa->header->orig_time);
- free(adj_lsa->header);
- free(adj_lsa->body);
- free(adj_lsa);
+ destroy_adj_lsa(adj_lsa);
print_adj_lsdb();
@@ -1168,10 +1196,9 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
/*Filling Up Header Data */
- adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
- adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
- memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
+ adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
+ adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
+ adj_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
adj_lsa->header->orig_router->length=strlen(orig_router)+1;
@@ -1179,14 +1206,12 @@
adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
- adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
- memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
+ adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
adj_lsa->no_link=no_link;
- adj_lsa->body=(char *)malloc(strlen(data)+1);
- memset(adj_lsa->body,0,strlen(data)+1);
+ adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
}
@@ -1562,8 +1587,7 @@
}
-//int
-//delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+
int
delete_name_lsa(char *orig_router, char *name_prefix)
{
@@ -1572,50 +1596,9 @@
printf("delete_name_lsa called \n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
- /*
- if(flags == CCN_SCHEDULE_CANCEL)
- {
- return -1;
- }
-
-
- nlsr_lock();
-
- if ( nlsr->debugging )
- printf("LSA Key: %s \n",(char *)ev->evdata);
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
-
- struct nlsa *nlsa;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- int res;
-
- hashtb_start(nlsr->lsdb->name_lsdb, e);
- res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
-
- if( res == HT_OLD_ENTRY )
- {
- nlsa=e->data;
- */
delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
- /*
- writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
- writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
- write_log_for_name_lsa(nlsa);
- writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
-
- hashtb_delete(e);
- }
- else if( res == HT_NEW_ENTRY )
- {
- hashtb_delete(e);
- }
- hashtb_end(e);
- */
+
if ( nlsr->debugging )
printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
@@ -1629,13 +1612,11 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
- //nlsr_unlock();
return 0;
}
-//int
-//delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+
int delete_adj_lsa()
{
@@ -1644,43 +1625,6 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
- /*
- if(flags == CCN_SCHEDULE_CANCEL)
- {
- return -1;
- }
- nlsr_lock();
-
- if ( nlsr->debugging )
- printf("LSA Key: %s \n",(char *)ev->evdata);
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
-
- struct alsa *alsa;
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
- int res;
-
- hashtb_start(nlsr->lsdb->adj_lsdb, e);
- res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
-
- if( res == HT_OLD_ENTRY )
- {
- alsa=e->data;
- writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
- writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
- write_log_for_adj_lsa(alsa);
- writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
-
- hashtb_delete(e);
- }
- else if( res == HT_OLD_ENTRY )
- {
- hashtb_delete(e);
- }
- hashtb_end(e);
- */
-
if ( nlsr->debugging )
printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
if ( nlsr->detailed_logging )
@@ -1700,8 +1644,6 @@
nlsr->is_route_calculation_scheduled=1;
}
- //nlsr_unlock();
-
return 0;
}
@@ -1713,9 +1655,7 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
- 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();
long int lsa_life_time;
@@ -1754,14 +1694,10 @@
write_log_for_name_lsa(name_lsa);
writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
-
- char *current_time_stamp=(char *)malloc(20);
- memset(current_time_stamp,0,20);
- get_current_timestamp_micro(current_time_stamp);
+ char *current_time_stamp=get_current_timestamp_micro_v2();
free(name_lsa->header->orig_time);
- name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
- memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
+ name_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
@@ -1774,29 +1710,15 @@
hashtb_next(e);
}
else
- { /*
- char lst[2];
- memset(lst,0,2);
- sprintf(lst,"%d",name_lsa->header->ls_type);
-
- char lsid[10];
- memset(lsid,0,10);
- sprintf(lsid,"%ld",name_lsa->header->ls_id);
-
-
- char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
- memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
-
-
- make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
-
- nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
- */
+ {
delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
write_log_for_name_lsa(name_lsa);
writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
+
+ destroy_name_lsa_component(name_lsa);
+
hashtb_delete(e);
i++;
}
@@ -1831,28 +1753,13 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
- /*char lst[2];
- memset(lst,0,2);
- sprintf(lst,"%d",name_lsa->header->ls_type);
-
- char lsid[10];
- memset(lsid,0,10);
- sprintf(lsid,"%ld",name_lsa->header->ls_id);
-
-
- char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
- memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
-
-
- make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
-
- nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
- */
delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
write_log_for_name_lsa(name_lsa);
writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
+
+ destroy_name_lsa_component(name_lsa);
hashtb_delete(e);
i++;
}
@@ -1861,10 +1768,6 @@
hashtb_next(e);
}
}
- /*else
- {
- hashtb_next(e);
- }*/
}
hashtb_end(e);
@@ -1882,11 +1785,9 @@
printf("refresh_adj_lsdb called \n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
-
- 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();
+
long int lsa_life_time;
int i, adj_lsdb_element;
@@ -1923,13 +1824,10 @@
write_log_for_adj_lsa(adj_lsa);
writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
- char *current_time_stamp=(char *)malloc(20);
- memset(current_time_stamp,0,20);
- get_current_timestamp_micro(current_time_stamp);
+ char *current_time_stamp=get_current_timestamp_micro_v2();
free(adj_lsa->header->orig_time);
- adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
- memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
+ adj_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
free(current_time_stamp);
@@ -1967,19 +1865,13 @@
printf("Others Adj LSA need to be deleted\n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
- /*
- char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
- memset(key,0,adj_lsa->header->orig_router->length+2);
- make_adj_lsa_key(key,adj_lsa);
-
- nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
- */
-
writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
write_log_for_adj_lsa(adj_lsa);
writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
delete_adj_lsa();
+
+ destroy_adj_lsa_component(adj_lsa);
hashtb_delete(e);
i++;
@@ -1989,10 +1881,7 @@
hashtb_next(e);
}
}
-
-
-
- //hashtb_next(e);
+
}
hashtb_end(e);
@@ -2010,10 +1899,8 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
- 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();
+
long int lsa_life_time;
int i, cor_lsdb_element;
@@ -2045,14 +1932,7 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
- //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
- //writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
- //write_log_for_adj_lsa(adj_lsa);
- //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
-
- char *current_time_stamp=(char *)malloc(20);
- memset(current_time_stamp,0,20);
- get_current_timestamp_micro(current_time_stamp);
+ char *current_time_stamp=get_current_timestamp_micro_v2();
free(cor_lsa->header->orig_time);
cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
@@ -2061,11 +1941,6 @@
free(current_time_stamp);
- //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
- //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
- //write_log_for_adj_lsa(adj_lsa);
- //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
-
if ( nlsr->debugging )
printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
if ( nlsr->detailed_logging )
@@ -2092,7 +1967,8 @@
printf("Others Adj LSA need to be deleted\n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
-
+
+ destroy_cor_lsa_component(cor_lsa);
hashtb_delete(e);
i++;
}
@@ -2128,7 +2004,6 @@
refresh_name_lsdb();
refresh_adj_lsdb();
- //refresh_cor_lsdb();
nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
@@ -2149,7 +2024,11 @@
if ( nlsr->debugging )
printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
- write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
+ char *data=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
+ data=ccn_charbuf_as_string(lsa_data);
+ data[strlen(data)]='\0';
+
+ write_data_to_repo(data, repo_content_prefix);
ccn_charbuf_destroy(&lsa_data);
@@ -2169,9 +2048,11 @@
if ( nlsr->debugging )
printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
-
+ char *data=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
+ data=ccn_charbuf_as_string(lsa_data);
+ data[strlen(data)]='\0';
- write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
+ write_data_to_repo(data, repo_content_prefix);
ccn_charbuf_destroy(&lsa_data);
}
@@ -2212,17 +2093,15 @@
printf("Name LSA Key: %s \n",key);
- char *repo_key=(char *)malloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15);
- memset(repo_key,0,strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15);
+ char *repo_key=(char *)calloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+16,sizeof(char));
make_name_lsa_prefix_for_repo(repo_key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id,name_lsa->header->orig_time,slice_prefix);
if ( nlsr->debugging )
printf("Name LSA Repo Key: %s \n",repo_key);
- struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
- lsaid->name=(char *)malloc(strlen(key)+1);
- memset(lsaid->name, 0, strlen(key)+1);
- memcpy(lsaid->name,key,strlen(key));
+ struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
+ lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
+ memcpy(lsaid->name,key,strlen(key)+1);
lsaid->length=strlen(key)+1;
@@ -2346,7 +2225,7 @@
}
hashtb_end(e);
- //free(key);
+ free(key);
}
@@ -2356,17 +2235,14 @@
cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
cor_lsa->header->ls_type=LS_TYPE_COR;
- 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();
cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
free(time_stamp);
- cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- cor_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
+ cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
+ cor_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
@@ -2406,12 +2282,7 @@
print_cor_lsdb();
- free(cor_lsa->header->orig_router->name);
- free(cor_lsa->header->orig_router);
- free(cor_lsa->header->orig_time);
- free(cor_lsa->header);
- free(cor_lsa);
-
+ destroy_cor_lsa(cor_lsa);
}
@@ -2427,13 +2298,9 @@
install_cor_lsa(cor_lsa);
write_cor_lsa_to_repo(cor_lsa);
+ destroy_cor_lsa(cor_lsa);
print_cor_lsdb();
-
- free(cor_lsa->header->orig_router);
- free(cor_lsa->header->orig_time);
- free(cor_lsa->header);
- free(cor_lsa);
}
@@ -2515,8 +2382,7 @@
printf("write_cor_lsa_to_repo called\n");
- char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2);
- memset(key,0,cor_lsa->header->orig_router->length+2+2);
+ char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char));
make_cor_lsa_key(key,cor_lsa);
struct ccn_charbuf *lsa_data=ccn_charbuf_create();
@@ -2528,14 +2394,17 @@
char *lst=(char *)malloc(20);
memset(lst,0,20);
sprintf(lst,"%d",cor_lsa->header->ls_type);
- char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15);
- memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15);
+ char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 20,sizeof(char));
make_cor_lsa_prefix_for_repo(repo_key, cor_lsa->header->orig_router->name,LS_TYPE_COR,cor_lsa->header->orig_time,nlsr->slice_prefix);
if ( nlsr->debugging )
printf("Cor LSA Repo Key: %s \n",repo_key);
- write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
+ char *data=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
+ data=ccn_charbuf_as_string(lsa_data);
+ data[strlen(data)]='\0';
+
+ write_data_to_repo(data, repo_key);
@@ -2593,7 +2462,7 @@
double
get_hyperbolic_theta(char *router)
{
- double ret=-1.0;
+ double ret=-1.0;
char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
make_cor_lsa_key_by_router_name(cor_lsa_key,router);