Fixed Bug for Link Failure
diff --git a/macbook.conf b/macbook.conf
index 0e61f98..402a0ad 100644
--- a/macbook.conf
+++ b/macbook.conf
@@ -7,7 +7,7 @@
 ccnname /ndn/memphis.edu/houston/
 #------lsdb-synch-interval-----
 lsdb-synch-interval 350
-interest-retry 4
+interest-retry 2 
 interest-resend-time 5
 lsa-refresh-time 600
 router-dead-interval 900
diff --git a/nlsr_adl.c b/nlsr_adl.c
index ec78eb8..087f9c4 100644
--- a/nlsr_adl.c
+++ b/nlsr_adl.c
@@ -248,7 +248,7 @@
 void 
 update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
 {
-	printf("update_adjacent_timed_out_to_adl called \n");
+	printf("update_lsdb_interest_timed_out_to_adl called \n");
 
 	int res;
 	struct ndn_neighbor *nnbr;
@@ -257,18 +257,24 @@
     	struct hashtb_enumerator *e = ⅇ
 
 	hashtb_start(nlsr->adl, e);
+
+	//printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length);
+
 	res = hashtb_seek(e, nbr->name, nbr->length, 0);
 
 	if( res == HT_OLD_ENTRY )
 	{
+		//printf("Old Neighbor\n");
 		nnbr=e->data;
 		nnbr->lsdb_interest_timed_out += increment;
+		//printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out);
 	}
 	else if(res == HT_NEW_ENTRY)
 	{
 		hashtb_delete(e);
 	}
 
+	//print_adjacent_from_adl();		
 	hashtb_end(e);
 }
 
@@ -375,6 +381,7 @@
 int
 is_adj_lsa_build(void)
 {
+	//print_adjacent_from_adl();
 	int ret=0;
 
 	int nbr_count=0;	
@@ -395,8 +402,9 @@
 		{
 			nbr_count++;
 		}
-		else if (nbr->info_interest_timed_out >= nlsr->interest_retry)
+		else if ( (nbr->status == 0) && (nbr->info_interest_timed_out >= nlsr->interest_retry || nbr->lsdb_interest_timed_out >= nlsr->interest_retry))
 		{
+			//printf(" In Status: 0  info_interest_timed_out= %d and lsdb_interest_timed_out= %d\n",nbr->info_interest_timed_out,nbr->lsdb_interest_timed_out);
 			nbr_count++;
 		}
 		hashtb_next(e);		
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index 16a7f30..cb24794 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -587,34 +587,40 @@
 
 
 
-		if(res == HT_NEW_ENTRY )
+		if(res == HT_NEW_ENTRY)
 		{
-			printf("New ADJ LSA... Adding to LSDB\n");
-			new_adj_lsa = e->data;
+			if ( adj_lsa->no_link > 0)
+			{
+				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=(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->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->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);
+				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);
+			
+				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 
+			{
+				hashtb_delete(e);
+			}
 
 			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)
 		{
@@ -625,24 +631,30 @@
 			}
 			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);
+				if ( adj_lsa->no_link > 0)
+				{				
+					new_adj_lsa = e->data;
 
-				new_adj_lsa->no_link=adj_lsa->no_link;
+					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);
+					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);
 
+					add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
+				}
+				else
+				{
+					hashtb_delete(e);
+				}
 				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);
-
 			}
 	
 		}
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index 006692f..6c95460 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -712,6 +712,7 @@
 		update_adjacent_lsdb_version_to_adl(nbr,lsdb_version);
 		printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
 
+		update_lsdb_interest_timed_out_zero_to_adl(nbr);
 
 		free(lsdb_version);
 		free(nbr);	
@@ -723,12 +724,15 @@
 		long int interval=get_lsdb_synch_interval(nbr->name);
 		adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2);
 
-
+		update_lsdb_interest_timed_out_zero_to_adl(nbr);
 		free(nbr);
 	}
 	else 
 	{
 		printf("NACK Content Received\n");
+		struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+		get_nbr(nbr,selfp,info);
+		update_lsdb_interest_timed_out_zero_to_adl(nbr);
 	}
 }
 
@@ -898,15 +902,14 @@
 
 	printf("LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
 
+	update_lsdb_interest_timed_out_to_adl(nbr,1);
+
 	int interst_timed_out_num=get_lsdb_interest_timed_out_number(nbr);
 
-	if( interst_timed_out_num < nlsr->interest_retry )
+	printf("Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry);
+
+	if( interst_timed_out_num >= nlsr->interest_retry )
 	{
-		update_lsdb_interest_timed_out_to_adl(nbr,1);
-	}
-	else
-	{
-		update_lsdb_interest_timed_out_zero_to_adl(nbr);
 		update_adjacent_status_to_adl(nbr,NBR_DOWN);
 		if(!nlsr->is_build_adj_lsa_sheduled)
 		{