Old Copy
diff --git a/nlsr_adl.c b/nlsr_adl.c
index de6ad07..7ebc8af 100644
--- a/nlsr_adl.c
+++ b/nlsr_adl.c
@@ -23,46 +23,75 @@
 #include "nlsr_adl.h"
 
 void
-add_adjacent_to_adl(struct ndn_neighbor *nbr)
+add_adjacent_to_adl(struct name_prefix *np, int face)
 {
 	printf("\nadd_adjacent_to_adl called\n");
-	printf("Neighbor: %s Length: %d Face: %d Status: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status);
-
-	struct ndn_neighbor *hnbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor*));
+	printf("Neighbor: %s Length: %d Face:%d\n",np->name,np->length,face);
 	
+	struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor));
+
 	struct hashtb_enumerator ee;
     	struct hashtb_enumerator *e = ⅇ 	
     	int res;
 
    	hashtb_start(nlsr->adl, e);
-    	res = hashtb_seek(e, nbr->neighbor->buf , nbr->neighbor->length, 0);
+    	res = hashtb_seek(e, np->name, np->length, 0);
 
 	if(res == HT_NEW_ENTRY )
 	{
    
-		hnbr = e->data;
-		hnbr->neighbor=ccn_charbuf_create();
-		ccn_charbuf_append_string(hnbr->neighbor,ccn_charbuf_as_string(nbr->neighbor));
+		nbr = e->data;
 
-		hnbr->face=nbr->face;
-		hnbr->status=nbr->status;
-		hnbr->last_lsdb_version=0;
-		hnbr->info_interest_timed_out=0;
+		nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix ));
+		nbr->neighbor->name=(char *)malloc(np->length);
+		memcpy(nbr->neighbor->name,np->name,np->length);
+		nbr->neighbor->length=np->length;
+		nbr->face=face;
+		nbr->status=NBR_DOWN;
+		nbr->info_interest_timed_out=0;
+		nbr->lsdb_synch_interval=300;
+		nbr->metric=10;
+		nbr->is_lsdb_send_interest_scheduled=0;
+		
+		
 
-		struct hashtb_param param_luq = {0};
-		hnbr->lsa_update_queue=hashtb_create(200, &param_luq);
+		char *time_stamp=get_current_timestamp_micro();
+		nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1);
+		memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
+		memset(nbr->last_lsdb_version,'0',strlen(time_stamp));
+
+		nbr->last_lsdb_requested=0;
+
+		//nbr->last_lsdb_requested=(char *)malloc(strlen(time_stamp)+1);
+		//memcpy(nbr->last_lsdb_requested,time_stamp,strlen(time_stamp)+1);
+		//memset(nbr->last_lsdb_requested,'0',strlen(time_stamp));
+
 	}
-	
+
     	hashtb_end(e);
+}
 
-	printf("\n");
-
+void 
+print_adjacent(struct ndn_neighbor *nbr)
+{
+	printf("\nprint_adjacent called\n");
+	printf("--------Neighbor---------------------------\n");
+	printf("	Neighbor: %s \n",nbr->neighbor->name);
+	printf("	Length  : %d \n",nbr->neighbor->length);
+	printf("	Face    : %d \n",nbr->face);
+	printf("	Metric    : %d \n",nbr->metric);
+	printf("	Status  : %d \n",nbr->status);
+	printf("	LSDB Version: %s \n",nbr->last_lsdb_version);
+	printf("	Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
+	printf("	LSDB Synch Interval     : %ld \n",nbr->lsdb_synch_interval);
+	printf("	Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
 
 }
 
 void
 print_adjacent_from_adl(void)
 {
+
 	printf("print_adjacent_from_adl called \n");	
 	int i, adl_element;
 	struct ndn_neighbor *nbr;
@@ -76,20 +105,19 @@
 	for(i=0;i<adl_element;i++)
 	{
 		nbr=e->data;
-		printf("Neighbor: %s Length: %d Face: %d Status: %d LSDB Version: %ld Interest Timed Out: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status, nbr->last_lsdb_version,nbr->info_interest_timed_out);	
+		print_adjacent(nbr);	
 		hashtb_next(e);		
 	}
 
 	hashtb_end(e);
 
-	printf("\n");
 }
 
 void 
-update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status)
+update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
 {
 	printf("update_adjacent_status_to_adl called \n");
-
+	//int ret;
 	int res;
 	struct ndn_neighbor *nnbr;
 
@@ -97,8 +125,8 @@
     	struct hashtb_enumerator *e = &ee;
 
 	hashtb_start(nlsr->adl, e);
-   	res = hashtb_seek(e, nbr->buf, nbr->length, 0);
-	
+   	res = hashtb_seek(e, nbr->name, nbr->length, 0);
+
 
 	if (res == HT_OLD_ENTRY)
 	{
@@ -113,15 +141,14 @@
 	{
 		hashtb_delete(e);
 	}
-	
+
 	hashtb_end(e);
 }
 
-
 void 
-update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, long int version)
+update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
 {
-	printf("update_adjacent_status_to_adl called \n");
+	printf("uupdate_lsdb_synch_interval_to_adl called \n");
 
 	int res;
 	struct ndn_neighbor *nnbr;
@@ -130,24 +157,31 @@
     	struct hashtb_enumerator *e = &ee;
 
 	hashtb_start(nlsr->adl, e);
-	res = hashtb_seek(e, nbr->buf, nbr->length, 0);
+   	res = hashtb_seek(e, nbr->name, nbr->length, 0);
 
-	if( res == HT_OLD_ENTRY )
+
+	if (res == HT_OLD_ENTRY)
 	{
 		nnbr=e->data;
-		nnbr->last_lsdb_version = version;
-		//memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
+		if ( nnbr->lsdb_synch_interval!= interval )
+		{
+			nnbr->lsdb_synch_interval=interval;
+			
+		}
 	}
 	else if(res == HT_NEW_ENTRY)
 	{
 		hashtb_delete(e);
 	}
-	
+
 	hashtb_end(e);
+	
+	
 }
 
+
 void 
-update_adjacent_timed_out_to_adl(struct ccn_charbuf *nbr, int increment)
+update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
 {
 	printf("update_adjacent_timed_out_to_adl called \n");
 
@@ -158,7 +192,7 @@
     	struct hashtb_enumerator *e = &ee;
 
 	hashtb_start(nlsr->adl, e);
-	res = hashtb_seek(e, nbr->buf, nbr->length, 0);
+	res = hashtb_seek(e, nbr->name, nbr->length, 0);
 
 	if( res == HT_OLD_ENTRY )
 	{
@@ -169,14 +203,13 @@
 	{
 		hashtb_delete(e);
 	}
-	
+
 	hashtb_end(e);
 }
 
 void 
-update_adjacent_timed_out_zero_to_adl(struct ccn_charbuf *nbr)
+update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
 {
-
 	printf("update_adjacent_timed_out_zero_to_adl called \n");
 	int time_out_number=get_timed_out_number(nbr);
 	update_adjacent_timed_out_to_adl(nbr,-time_out_number);
@@ -184,10 +217,40 @@
 }
 
 
-int 
-get_timed_out_number(struct ccn_charbuf *nbr)
+void 
+update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
 {
+	printf("update_adjacent_timed_out_to_adl called \n");
 
+	int res;
+	struct ndn_neighbor *nnbr;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	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);
+
+}
+
+int 
+get_timed_out_number(struct name_prefix *nbr)
+{
 	printf("get_timed_out_number called \n");
 
 	int res,ret=-1;
@@ -197,7 +260,7 @@
     	struct hashtb_enumerator *e = &ee;
 
 	hashtb_start(nlsr->adl, e);
-	res = hashtb_seek(e, nbr->buf, nbr->length, 0);
+	res = hashtb_seek(e, nbr->name, nbr->length, 0);
 
 	if( res == HT_OLD_ENTRY )
 	{
@@ -208,9 +271,423 @@
 	{
 		hashtb_delete(e);
 	}
-	
+
 	hashtb_end(e);
 
 	return ret;
-	
+
+	return 0;	
 }
+
+int
+is_adj_lsa_build(void)
+{
+	int ret=0;
+
+	int nbr_count=0;	
+
+	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 )
+		{
+			nbr_count++;
+		}
+		else if (nbr->info_interest_timed_out >= nlsr->interest_retry)
+		{
+			nbr_count++;
+		}
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	if(nbr_count == adl_element)
+		ret=1;
+	
+	return ret;
+}
+
+int 
+no_active_nbr(void)
+{
+	int i, adl_element;
+	int no_link=0;
+	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 )
+			no_link++;
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+	return no_link;
+
+}
+
+long int 
+len_active_nbr_data(void)
+{
+	int i, adl_element;
+	int no_link=0;
+	long int len=0;
+	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 )
+		{
+			char *temp_face=(char *)malloc(20);
+			char *temp_metric=(char *)malloc(20);
+			char *temp_length=(char *)malloc(20);
+			
+			len+=strlen(nbr->neighbor->name);
+
+			memset(	temp_face,0,20);
+			sprintf(temp_face,"%d",nbr->face);
+			len+=strlen(temp_face);	
+
+			memset(	temp_metric,0,20);
+			sprintf(temp_face,"%d",nbr->metric);
+			len+=strlen(temp_metric);
+
+			memset(	temp_length,0,20);
+			sprintf(temp_length,"%d",nbr->neighbor->length);
+			len+=strlen(temp_length);
+		
+			no_link++;
+
+			free(temp_face);
+			free(temp_metric);
+			free(temp_length);
+
+		}
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+	len=len+ no_link*4+1;
+
+	return len;
+
+}
+
+void 
+get_active_nbr_adj_data(struct ccn_charbuf *c)
+{
+
+	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 )
+		{
+			ccn_charbuf_append_string(c,nbr->neighbor->name);
+			ccn_charbuf_append_string(c,"|");
+			
+			char *temp_length=(char *)malloc(20);
+			memset(temp_length,0,20);
+			sprintf(temp_length,"%d",nbr->neighbor->length);
+			ccn_charbuf_append_string(c,temp_length);
+			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);
+			ccn_charbuf_append_string(c,temp_metric);
+			free(temp_metric);
+			ccn_charbuf_append_string(c,"|");
+
+		}
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+}
+
+char *
+get_nbr_lsdb_version(char *nbr)
+{
+	printf("get_timed_out_number called \n");
+
+	char *version=NULL;
+
+	int res;
+	struct ndn_neighbor *nnbr;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	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)
+{
+	printf("update_adjacent_last_lsdb_requested_to_adl called \n");
+
+	int res;
+	struct ndn_neighbor *nnbr;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	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 
+adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
+{
+	printf("update_adjacent_last_lsdb_requested_to_adl called \n");
+
+	int res;
+	struct ndn_neighbor *nnbr;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	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);
+
+}
+
+
+long int 
+get_nbr_last_lsdb_requested(char *nbr)
+{
+	printf("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 = &ee;
+
+	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;
+}
+
+long int
+get_nbr_time_diff_lsdb_req(char *nbr)
+{
+	printf("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 = &ee;
+
+	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_lsdb_synch_interval(char *nbr)
+{
+	printf("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 = &ee;
+
+	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;
+
+}
+
+void 
+set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
+{
+	printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
+
+	int res;
+	struct ndn_neighbor *nnbr;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	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);
+
+}
+
+
+int 
+get_adjacent_status(struct name_prefix *nbr)
+{
+	printf("get_adjacent_status called \n");
+
+	int res;
+	int status=-1;
+	struct ndn_neighbor *nnbr;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	hashtb_start(nlsr->adl, e);
+	res = hashtb_seek(e, nbr->name, nbr->length, 0);
+
+	if (res == HT_OLD_ENTRY)
+	{
+		nnbr=e->data;
+		status=nnbr->status;
+	}
+	else if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+
+	hashtb_end(e);
+
+	return status;
+
+}
+