Configured Variable Validation and LSDB Refreshing
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index f271e50..f80a2b7 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -137,92 +137,186 @@
 void 
 install_name_lsa(struct nlsa *name_lsa)
 {
-	
-	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 *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+	long int lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
+
+	printf("time difference: %ld \n",lsa_life_time);
+	
+
+		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);
+		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);	
-	printf("Key:%s Length:%d\n",key,(int)strlen(key));
+		make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);	
+		printf("Key:%s Length:%d\n",key,(int)strlen(key));
 
-	struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
+		struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
 
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = ⅇ 	
-    	int res;
+		struct hashtb_enumerator ee;
+    		struct hashtb_enumerator *e = ⅇ 	
+    		int res;
 
-   	hashtb_start(nlsr->lsdb->name_lsdb, e);
-    	res = hashtb_seek(e, key, strlen(key), 0);
+   		hashtb_start(nlsr->lsdb->name_lsdb, e);
+    		res = hashtb_seek(e, key, strlen(key), 0);
 
-	if(res == HT_NEW_ENTRY )
-	{
-		printf("New Name LSA... Adding to LSDB\n");
-		new_name_lsa = e->data;
-
-		new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
-		new_name_lsa->header->ls_type=name_lsa->header->ls_type;
-
-		new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
-		memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
-		memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
-
-		new_name_lsa->header->ls_id=name_lsa->header->ls_id;
-		new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
-		new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
-		memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
-		new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
-		new_name_lsa->header->isValid=name_lsa->header->isValid;
-
-	
-		new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
-		new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
-		memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
-		new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
-
-		printf("New Name LSA Added....\n");	
-
-		printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
-		set_new_lsdb_version();	
-		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);	
-
-		int next_hop=get_next_hop(new_name_lsa->header->orig_router->name);
-		if ( next_hop == NO_NEXT_HOP )
+		if(res == HT_NEW_ENTRY )
 		{
-			int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_FACE);
-			if ( check == HT_NEW_ENTRY )
+				
+	
+		
+		
+			printf("New Name LSA... Adding to LSDB\n");
+			new_name_lsa = e->data;
+
+			new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
+			new_name_lsa->header->ls_type=name_lsa->header->ls_type;
+
+			new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
+			memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
+			memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
+
+			new_name_lsa->header->ls_id=name_lsa->header->ls_id;
+			new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
+			new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
+			memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
+			new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
+			new_name_lsa->header->isValid=name_lsa->header->isValid;
+
+	
+			new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
+			new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
+			memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
+			new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
+
+			printf("New Name LSA Added....\n");	
+
+			printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+			set_new_lsdb_version();	
+			printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);	
+
+			int next_hop=get_next_hop(new_name_lsa->header->orig_router->name);
+			if ( next_hop == NO_NEXT_HOP )
 			{
-				printf("Added in npt \n");
+				int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_FACE);
+				if ( check == HT_NEW_ENTRY )
+				{
+					printf("Added in npt \n");
+				}
 			}
-		}
-		else 
-		{
-			int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop);
-			if ( check == HT_NEW_ENTRY )
+			else 
 			{
-				printf("Added in npt \n");
+				int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop);
+				if ( check == HT_NEW_ENTRY )
+				{
+					printf("Added in npt \n");
+				}
+
 			}
 
+		
+		free(time_stamp);
+
+		}
+		else if(res == HT_OLD_ENTRY)
+		{
+			new_name_lsa=e->data;
+			if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<=0)
+			{
+				printf("Older/Duplicate Adj LSA. Discarded...\n");
+			}
+			else 
+			{
+				if ( name_lsa->header->isValid == 0 )
+				{
+					// have to call to delete npt table entry
+					delete_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
+				
+					if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
+					{
+						hashtb_delete(e);
+						printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
+					}
+					else 
+					{
+						new_name_lsa->header->isValid=name_lsa->header->isValid;
+						free(new_name_lsa->header->orig_time);
+						new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
+						memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
+						memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
+					}
+					printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+					set_new_lsdb_version();	
+					printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+				}
+				else
+				{
+					int is_npt_update=0;
+					if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
+					{
+						is_npt_update=1;
+						delete_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
+					}
+
+					// copying LSA content with header
+
+					free(new_name_lsa->header->orig_time);
+					new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
+					memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
+					memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
+				
+					new_name_lsa->header->isValid=name_lsa->header->isValid;
+
+					free(new_name_lsa->name_prefix->name);
+					free(new_name_lsa->name_prefix);
+					new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+					new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
+					memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
+					new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
+
+					printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+					set_new_lsdb_version();	
+					printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+
+					if( is_npt_update == 1 )
+					{
+						int next_hop=get_next_hop(new_name_lsa->header->orig_router->name);
+						if ( next_hop == NO_NEXT_HOP )
+						{
+							int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_FACE);
+							if ( check == HT_NEW_ENTRY )
+							{
+								printf("Added in npt \n");
+							}
+						}
+						else 
+						{
+							int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop);
+							if ( check == HT_NEW_ENTRY )
+							{
+								printf("Added in npt \n");
+							}
+						}
+					}
+				}
+			}
+		
 		}
 
-	}
-	else if(res == HT_OLD_ENTRY)
-	{
-		printf("Duplicate Name LSA. Discarded...\n");
+    		hashtb_end(e);
 
-	}
-
-    	hashtb_end(e);
-
-	free(key);
+		free(key);
 }
 
 
@@ -320,6 +414,8 @@
 }
 
 
+
+
 void 
 make_adj_lsa_key(char *key,struct alsa *adj_lsa)
 {
@@ -334,6 +430,13 @@
 int
 build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
 {
+	if(flags == CCN_SCHEDULE_CANCEL)
+	{
+ 	 	return -1;
+	}
+
+	nlsr_lock();
+
 	printf("build_and_install_adj_lsa called \n");
 
 	printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
@@ -362,6 +465,9 @@
 		}
 	}
 	nlsr->is_build_adj_lsa_sheduled=0;
+
+	nlsr_unlock();
+
 	return 0;
 }
 
@@ -397,40 +503,6 @@
 	/* Filling Up Body Data */
 
 	adj_lsa->no_link=no_link;
-/*
-	struct link *templ=(struct link *)malloc(2*sizeof(struct link));
-	adj_lsa->links=templ;
-
-	int i, adl_element;
-	struct ndn_neighbor *nbr;
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee;
-    	hashtb_start(nlsr->adl, e);
-	adl_element=hashtb_n(nlsr->adl);
-
-	for(i=0;i<adl_element;i++)
-	{
-		nbr=e->data;
-		if( nbr->status	== 1 )
-		{
-			struct link *temp=(struct link *)malloc(sizeof(struct link));
-			temp->nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix));
-			temp->nbr->name=(char *)malloc(nbr->neighbor->length);
-			memset(temp->nbr->name,0,nbr->neighbor->length);		
-			memcpy(temp->nbr->name,nbr->neighbor->name,nbr->neighbor->length);
-
-			temp->nbr->length=nbr->neighbor->length;
-			temp->face=nbr->face;
-			temp->metric=nbr->metric;
-
-			templ=temp;
-			templ++;
-		}	
-		hashtb_next(e);		
-	}
-
-	hashtb_end(e);
-*/
 
 
 	struct ccn_charbuf *c=ccn_charbuf_create();
@@ -461,68 +533,48 @@
 {
 	printf("install_adj_lsa called \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);
-	printf("Adjacent LSA key: %s \n",key);
 
-	struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+	long int lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
 
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee; 	
-    	int res;
+	printf("time difference: %ld \n",lsa_life_time);
 
-   	hashtb_start(nlsr->lsdb->adj_lsdb, e);
-    	res = hashtb_seek(e, key, strlen(key), 0);
+
+		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);
+		printf("Adjacent LSA key: %s \n",key);
+
+		struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
+
+		struct hashtb_enumerator ee;
+    		struct hashtb_enumerator *e = &ee; 	
+    		int res;
+
+   		hashtb_start(nlsr->lsdb->adj_lsdb, e);
+    		res = hashtb_seek(e, key, strlen(key), 0);
 
 
 
-	if(res == HT_NEW_ENTRY )
-	{
-		printf("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->ls_type=adj_lsa->header->ls_type;
-		new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
-		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);
-		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);
-		memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
-
-		printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
-		set_new_lsdb_version();	
-		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
-
-		add_next_hop_router(new_adj_lsa->header->orig_router->name);
-
-		add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
-	}
-	else if(res == HT_OLD_ENTRY)
-	{
-		new_adj_lsa = e->data;
-		if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
+		if(res == HT_NEW_ENTRY )
 		{
-			printf("Older/Duplicate Adj LSA. Discarded...\n");
-		}
-		else
-		{
+			printf("New ADJ LSA... Adding to LSDB\n");
 			new_adj_lsa = e->data;
 
-			free(new_adj_lsa->header->orig_time);
+			new_adj_lsa->header=(struct alsa_header *)malloc(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);
-			memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
+			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);
+			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);
 			memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
@@ -531,19 +583,52 @@
 			set_new_lsdb_version();	
 			printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
 
-			add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
+			add_next_hop_router(new_adj_lsa->header->orig_router->name);
 
+			add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
+		}
+		else if(res == HT_OLD_ENTRY)
+		{
+			new_adj_lsa = e->data;
+			if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
+			{
+				printf("Older/Duplicate Adj LSA. Discarded...\n");
+			}
+			else
+			{
+				new_adj_lsa = e->data;
+
+				free(new_adj_lsa->header->orig_time);
+				new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
+				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);
+				memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
+
+				printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+				set_new_lsdb_version();	
+				printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+
+				add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
+
+			}
+	
+		}
+	    	hashtb_end(e);
+
+		if ( !nlsr->is_route_calculation_scheduled )
+		{
+			nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
+			nlsr->is_route_calculation_scheduled=1;
 		}
 
-	}
-    	hashtb_end(e);
 
-	if ( !nlsr->is_route_calculation_scheduled )
-	{
-		nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
-		nlsr->is_route_calculation_scheduled=1;
-	}
-	free(key);
+		free(key);
+
+	free(time_stamp);
 }
 
 void 
@@ -1065,3 +1150,101 @@
 
 	hashtb_end(e);
 }
+
+void
+refresh_name_lsdb(void)
+{
+	printf("refresh_name_lsdb called \n");
+
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+	
+	long int lsa_life_time;
+		
+	int i, name_lsdb_element;
+	struct nlsa *name_lsa;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+    	hashtb_start(nlsr->lsdb->name_lsdb, e);
+	name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
+
+	for(i=0;i<name_lsdb_element;i++)
+	{
+		name_lsa=e->data;
+
+		lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
+		printf("LSA Life Time: %ld \n",lsa_life_time);			
+
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	
+	free(time_stamp);
+	
+}
+
+int
+refresh_adj_lsdb(void)
+{
+	printf("refresh_adj_lsdb called \n");
+
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+	
+	long int lsa_life_time;
+		
+	int i, adj_lsdb_element;
+	struct alsa *adj_lsa;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+    	hashtb_start(nlsr->lsdb->adj_lsdb, e);
+	adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
+
+	for(i=0;i<adj_lsdb_element;i++)
+	{
+		adj_lsa=e->data;
+
+		lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
+		printf("LSA Life Time: %ld \n",lsa_life_time);			
+
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	
+	free(time_stamp);
+
+	return 0;
+}
+
+int
+refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+	if(flags == CCN_SCHEDULE_CANCEL)
+	{
+ 	 	return -1;
+	}
+
+	nlsr_lock();
+	printf("refresh_lsdb called \n");
+	
+	refresh_name_lsdb();
+	refresh_adj_lsdb();
+
+	if ( !nlsr->is_route_calculation_scheduled )
+	{
+		nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
+		nlsr->is_route_calculation_scheduled=1;
+	}
+
+	nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
+	nlsr_unlock();
+	return 0;
+}