Old Copy
diff --git a/Makefile b/Makefile
index 94d2529..de1f4c7 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,8 @@
 
 all: $(PROGRAMS)
 
-nlsr: nlsr.c nlsr_adl.c nlsr_lsdb.c nlsr_ndn.c utility.c
-	$(CC) $(CFLAGS) nlsr.c nlsr_adl.c nlsr_lsdb.c nlsr_ndn.c utility.c -o nlsr $(LIBS)
+nlsr: nlsr.c nlsr_ndn.c nlsr_lsdb.c nlsr_adl.c utility.c
+	$(CC) $(CFLAGS) nlsr.c nlsr_ndn.c nlsr_lsdb.c nlsr_adl.c utility.c -o nlsr $(LIBS)
 
 clean:
 	rm -f *.o
diff --git a/nlsr.c b/nlsr.c
index 1576bc4..9d7438e 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -19,9 +19,9 @@
 
 #include "nlsr.h"
 #include "nlsr_ndn.h"
-#include "utility.h"
-#include "nlsr_adl.h"
 #include "nlsr_lsdb.h"
+#include "nlsr_adl.h"
+#include "utility.h"
 
 
 struct option longopts[] =
@@ -90,9 +90,11 @@
 		printf(" Wrong Command Format ( router-name /router/name )\n");
 		return;
 	}
-	nlsr->router_name=(char *)malloc(strlen(rtr_name)+1);
-	memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1);	
-	printf("Router Name: %s\n",nlsr->router_name);
+	
+	nlsr->router_name->name=(char *)malloc(strlen(rtr_name)+1);
+	memcpy(nlsr->router_name->name,rtr_name,strlen(rtr_name)+1);
+	nlsr->router_name->length=strlen(rtr_name)+1;
+
 }
 
 void 
@@ -106,28 +108,25 @@
 	}
 	char *rem;
 	const char *sep=" \t\n";
-	char *name_prefix;
-	name_prefix=strtok_r(command,sep,&rem);
-	if(name_prefix==NULL)
+	char *name;
+	name=strtok_r(command,sep,&rem);
+	if(name==NULL)
 	{
 		printf(" Wrong Command Format ( ccnname /name/prefix/ )\n");
 		return;
 	}
 
-	printf("Name Prefix: %s \n",name_prefix);
+	printf("Name Prefix: %s \n",name);
 
-	struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
-	np->name=(char *)malloc(strlen(name_prefix)+1);
-	memcpy(np->name,name_prefix,strlen(name_prefix)+1);
-	np->length=strlen(name_prefix)+1;
-
+	struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	np->name=(char *)malloc(strlen(name)+1);
+	memcpy(np->name,name,strlen(name)+1);
+	np->length=strlen(name)+1;
+	
 	add_name_prefix_to_npl(np);
-	/* Debugging Purpose */
-	print_name_prefix_from_npl();
 
-	free(np->name);
 	free(np);
-
+	
 		
 }
 
@@ -168,22 +167,14 @@
 		return;
 	}
 
-	struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor*));
-	nbr->neighbor=ccn_charbuf_create();
-	ccn_charbuf_append_string(nbr->neighbor,rtr_name);
-	nbr->face=face_id;
-	nbr->status=NBR_DOWN;	
+	struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	np->name=(char *)malloc(strlen(rtr_name)+1);
+	memcpy(np->name,rtr_name,strlen(rtr_name)+1);
+	np->length=strlen(rtr_name)+1;
 
-	
+	add_adjacent_to_adl(np,face_id);
 
-	add_adjacent_to_adl(nbr);
-	print_adjacent_from_adl();
-
-	//free(nbr->neighbor->name);
-	ccn_charbuf_destroy(&nbr->neighbor);
-	free(nbr->neighbor);
-	free(nbr);
-
+	free(np);
 }
 
 void 
@@ -340,22 +331,22 @@
 	printf("\nadd_name_prefix called\n");
 	printf("Name Prefix: %s and length: %d \n",np->name,np->length);
 
-	struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
+	struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
 
 	struct hashtb_enumerator ee;
     	struct hashtb_enumerator *e = ⅇ 	
     	int res;
 
    	hashtb_start(nlsr->npl, e);
-    	res = hashtb_seek(e, np->name, strlen(np->name), 0);
+    	res = hashtb_seek(e, np->name, np->length, 0);
 
 	if(res == HT_NEW_ENTRY)
 	{   
 
 		hnp = e->data;
-		hnp->name=(char *)malloc(np->length);
-    		memcpy(hnp->name,np->name,np->length);
 		hnp->length=np->length;
+		hnp->name=(char *)malloc(np->length);
+		memcpy(hnp->name,np->name,np->length);
 	}
     	
 	hashtb_end(e);
@@ -395,53 +386,82 @@
 nlsr_destroy( void )
 {
 
+	printf("Freeing Allocated Memory....\n");	
 	/* Destroying every hash table attached to each neighbor in ADL before destorying ADL */	
 
 	int i, element;
-	struct ndn_neighbor *nbr;
-
 	struct hashtb_enumerator ee;
     	struct hashtb_enumerator *e = ⅇ
     	
-    	hashtb_start(nlsr->adl, e);
+	/*destroying NAME LSDB */
+	struct nlsr *name_lsa;
+	hashtb_start(nlsr->lsdb->name_lsdb, e);
+	element=hashtb_n(nlsr->lsdb->name_lsdb);
+
+	for(i=0;i<element;i++)
+	{
+		name_lsa=e->data;
+		free(name_lsa);	
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);    	
+	hashtb_destroy(&nlsr->lsdb->name_lsdb);
+
+
+	/*destroying ADJ LSDB */
+	struct alsr *adj_lsa;
+	hashtb_start(nlsr->lsdb->adj_lsdb, e);
+	element=hashtb_n(nlsr->lsdb->adj_lsdb);
+
+	for(i=0;i<element;i++)
+	{
+		adj_lsa=e->data;
+		free(adj_lsa);	
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	
+
+	hashtb_destroy(&nlsr->lsdb->adj_lsdb);
+
+	/* Destroying NPL */
+	struct ccn_charbuf *np;
+	hashtb_start(nlsr->npl, e);
+	element=hashtb_n(nlsr->npl);
+
+	for(i=0;i<element;i++)
+	{
+		np=e->data;	
+		free(np);
+		hashtb_next(e);		
+	}
+	hashtb_end(e);
+	hashtb_destroy(&nlsr->npl);
+
+	/* Destroying ADL */
+	struct ndn_neighbor *nbr;
+	hashtb_start(nlsr->adl, e);
 	element=hashtb_n(nlsr->adl);
 
 	for(i=0;i<element;i++)
 	{
 		nbr=e->data;
-		hashtb_destroy(&nbr->lsa_update_queue);	
-		ccn_charbuf_destroy(&nbr->neighbor);
+		free(nbr);	
 		hashtb_next(e);		
 	}
 	hashtb_end(e);
 	hashtb_destroy(&nlsr->adl);
 
-	/* Destroying every element in Name LSDB Hash Table */
-	hashtb_start(nlsr->adl, e);
-	element=hashtb_n(nlsr->lsdb->name_lsdb);
 
-	struct nlsa *name_lsa;
-
-	for(i=0;i<element;i++)
-	{
-		name_lsa=e->data;	
-		ccn_charbuf_destroy(&name_lsa->name_prefix);
-		ccn_charbuf_destroy(&name_lsa->header->orig_router);
-		free(name_lsa->header);
-		free(name_lsa);
-		hashtb_next(e);		
-	}
-	hashtb_end(e);
-
-	hashtb_destroy(&nlsr->lsdb->name_lsdb);
-
-	hashtb_destroy(&nlsr->lsdb->adj_lsdb);
-
-	hashtb_destroy(&nlsr->npl);
+	
 	ccn_schedule_destroy(&nlsr->sched);
 	ccn_destroy(&nlsr->ccn);
 	free(nlsr);
 
+	printf("Finished freeing allocated memory\n");
+
 }
 
 void
@@ -456,20 +476,29 @@
 	nlsr=(struct nlsr *)malloc(sizeof(struct nlsr));
 
 	nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), &param_adl);
-	nlsr->npl = hashtb_create(sizeof(struct name_prefix), &param_npl);
+	nlsr->npl = hashtb_create(sizeof(struct name_prefix ), &param_npl);
+	
 	nlsr->in_interest.p = &incoming_interest;
 	nlsr->in_content.p = &incoming_content;
 
-	nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase *));
-	nlsr->lsdb->version=0;
+	nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase ));
+	char *time_stamp=get_current_timestamp_micro();
+	nlsr->lsdb->version=(char *)malloc(strlen(time_stamp)+1);
+	memcpy(nlsr->lsdb->version,time_stamp,strlen(time_stamp)+1);
+	memset(nlsr->lsdb->version,'0',strlen(time_stamp));
+	
 
 	nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), &param_adj_lsdb);
 	nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), &param_name_lsdb);
 
+	nlsr->router_name=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+
 	nlsr->is_synch_init=1;
 	nlsr->nlsa_id=0;
 	nlsr->adj_build_flag=0;
-	nlsr->adj_build_count=0;	
+	nlsr->adj_build_count=0;
+	nlsr->is_build_adj_lsa_sheduled=0;
+	nlsr->is_send_lsdb_interest_scheduled=0;	
 
 	nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL;
 	nlsr->interest_retry = INTEREST_RETRY;
@@ -486,7 +515,7 @@
     	int res;
     	char *config_file;
 	//int daemon_mode;
-	struct ccn_charbuf *router_prefix;	
+		
 
 	init_nlsr();
     	
@@ -513,17 +542,18 @@
 		{
 			fprintf(stderr,"Could not connect to ccnd\n");
 			exit(1);
-		}	
-	router_prefix=ccn_charbuf_create();	
-	res=ccn_name_from_uri(router_prefix,nlsr->router_name);		
+		}
+	struct ccn_charbuf *router_prefix;	
+	router_prefix=ccn_charbuf_create();
+	res=ccn_name_from_uri(router_prefix,nlsr->router_name->name);		
 	if(res<0)
 		{
-			fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
+			fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name->name);
 			exit(1);
 		}
 
 	ccn_name_append_str(router_prefix,"nlsr");
-	nlsr->in_interest.data=nlsr->router_name;
+	nlsr->in_interest.data=nlsr->router_name->name;
 	res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
 	if ( res < 0 )
 		{
@@ -531,16 +561,28 @@
 			exit(1);
 		}
 
-	nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
-
-	nlsr->event_build_name_lsa = ccn_schedule_event(nlsr->sched, 100, &initial_build_name_lsa, NULL, 0);
-	nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1000000, &send_info_interest, NULL, 0);
+	/* Debugging purpose */	
+	print_name_prefix_from_npl();
+	print_adjacent_from_adl();
 	
+	printf("\n");
+	printf("Router Name: %s\n",nlsr->router_name->name);
+	printf("Time in MicroSec: %s \n",get_current_timestamp_micro());
+	printf("LSDB Version: %s\n",nlsr->lsdb->version);
+	printf("\n");
+
+	build_and_install_name_lsas();
+	print_name_lsdb();	
+
+	nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
+	nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 500, &send_info_interest, NULL, 0);	
+
+
 
 	while(1)
 	{
-		if(nlsr->semaphor !=1)
-		{
+		if(nlsr->semaphor == 0)
+		{	
 			ccn_schedule_run(nlsr->sched);
         		res = ccn_run(nlsr->ccn, 500);
 		}
diff --git a/nlsr.conf b/nlsr.conf
index dbbaf9c..ced844f 100644
--- a/nlsr.conf
+++ b/nlsr.conf
@@ -1,11 +1,10 @@
 router-name /ndn/memphis.edu/netlab/macbook
-ccnneighbor /ndn/memphis.edu/netlab/maia face2 10
+ccnneighbor /ndn/memphis.edu/netlab/pollux face2 10
 ccnneighbor /ndn/memphis.edu/netlab/castor face3 8
-ccnneighbor /ndn/memphis.edu/netlab/pollux face4 15
 ccnname /ndn/memphis.edu/netlab/macbook/name1
 ccnname /ndn/memphis.edu/netlab/macbook/test
-lsdb-synch-interval 300
-interest-retry 2
-interest-resend-time 15
+lsdb-synch-interval 310
+interest-retry 4
+interest-resend-time 5
 
 
diff --git a/nlsr.h b/nlsr.h
index 144742c..fdde154 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -7,6 +7,9 @@
 #define INTEREST_RETRY 3
 #define INTEREST_RESEND_TIME 15
 
+#define NBR_DOWN 0
+#define NBR_ACTIVE 1
+
 struct name_prefix
 {
 	char *name;
@@ -15,17 +18,20 @@
 
 struct ndn_neighbor
 {
-	struct ccn_charbuf *neighbor;
+	struct name_prefix *neighbor;
 	int face;
 	int status;
-	long int last_lsdb_version;
+	char * last_lsdb_version;
 	int info_interest_timed_out;
-	struct hashtb *lsa_update_queue;
+	long int lsdb_synch_interval;
+	long int last_lsdb_requested;
+	int is_lsdb_send_interest_scheduled;
+	int metric;
 };
 
 struct linkStateDatabase
 {
-	long int version;
+	char  * version;
 	struct hashtb *adj_lsdb;
 	struct hashtb *name_lsdb;
 };
@@ -46,7 +52,7 @@
 	struct hashtb *npl;
 
 	struct ccn *ccn;
-	char *router_name;
+	struct name_prefix *router_name;
 
 	struct linkStateDatabase *lsdb;
 
@@ -54,6 +60,8 @@
 	long int nlsa_id;
 	int adj_build_flag;
 	long int adj_build_count;
+	int is_build_adj_lsa_sheduled;
+	int is_send_lsdb_interest_scheduled;
 
 	long int lsdb_synch_interval;
 	int interest_retry;
@@ -77,7 +85,7 @@
 void process_conf_command(char *command);
 int readConfigFile(const char *filename);
 
-void add_name_prefix_to_npl(struct name_prefix *name_prefix);
+void add_name_prefix_to_npl(struct name_prefix *np);
 void print_name_prefix_from_npl(void);
 
 void my_lock(void);
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 = &ee; 	
     	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;
+
+}
+
diff --git a/nlsr_adl.h b/nlsr_adl.h
index 1bcb381..7879aa8 100644
--- a/nlsr_adl.h
+++ b/nlsr_adl.h
@@ -4,13 +4,31 @@
 #define NBR_ACTIVE 1
 #define NBR_DOWN 0
 
-void add_adjacent_to_adl(struct ndn_neighbor *nbr);
+void add_adjacent_to_adl(struct name_prefix *np, int face);
+void print_adjacent(struct ndn_neighbor *nbr);
 void print_adjacent_from_adl(void);
-void update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status);
-void update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, long int version);
+void update_adjacent_status_to_adl(struct name_prefix *nbr, int status);
+int get_adjacent_status(struct name_prefix *nbr);
+void update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char * version);
+void update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval);
 
-int get_timed_out_number(struct ccn_charbuf *nbr);
-void update_adjacent_timed_out_to_adl(struct ccn_charbuf *nbr, int increment);
-void update_adjacent_timed_out_zero_to_adl(struct ccn_charbuf *nbr);
+int get_timed_out_number(struct name_prefix *nbr);
+void update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment);
+void update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr);
+
+int is_adj_lsa_build(void);
+int no_active_nbr(void);
+long int len_active_nbr_data(void);
+void get_active_nbr_adj_data(struct ccn_charbuf *c);
+char * get_nbr_lsdb_version(char *nbr);
+void update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp);
+long int get_nbr_last_lsdb_requested(char *nbr);
+long int get_nbr_time_diff_lsdb_req(char *nbr);
+long int get_lsdb_synch_interval(char *nbr);
+void set_is_lsdb_send_interest_scheduled_to_zero(char *nbr);
+
+void adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec);
+//long int get_lsdb_synch_interval(char *nbr);
+
 
 #endif
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index b6b115e..39a0322 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -21,110 +21,27 @@
 #include "nlsr_lsdb.h"
 #include "utility.h"
 #include "nlsr_ndn.h"
+#include "nlsr_adl.h"
 
 void
-make_name_lsa_key(struct ccn_charbuf *key, struct ccn_charbuf *orig_router, unsigned int ls_type, long int nlsa_id, long int orig_time)
+set_new_lsdb_version(void)
 {
-	printf("make_name_lsa_key called \n");	
-	ccn_charbuf_append_string(key,ccn_charbuf_as_string(orig_router));
-
-	struct ccn_charbuf *c=ccn_charbuf_create();
-	ccn_charbuf_reset(c);
-	ccn_charbuf_putf(c, "%d", ls_type);
-	ccn_charbuf_append_string(key,ccn_charbuf_as_string(c));
 	
-	ccn_charbuf_reset(c);
-	ccn_charbuf_putf(c, "%ld", nlsa_id);
-	ccn_charbuf_append_string(key,ccn_charbuf_as_string(c));
+	char *time_stamp=get_current_timestamp_micro();
 	
-	ccn_charbuf_reset(c);
-	ccn_charbuf_putf(c, "%ld", orig_time);
-	ccn_charbuf_append_string(key,ccn_charbuf_as_string(c));
-	//ccn_charbuf_append_string(key,orig_time);	
-
-	ccn_charbuf_destroy(&c);
-
-	printf("Key: %s length: %d\n",ccn_charbuf_as_string(key),(int)key->length);
-
+	free(nlsr->lsdb->version);
+	nlsr->lsdb->version=(char *)malloc(strlen(time_stamp)+1);
+	memset(nlsr->lsdb->version,0,strlen(time_stamp)+1);
+	memcpy(nlsr->lsdb->version,time_stamp,strlen(time_stamp)+1);
+	
 }
 
+
 void 
-install_name_lsa(struct nlsa *new_name_lsa)
+build_and_install_name_lsas(void)
 {
-	printf("install_name_lsa called \n");
-	struct ccn_charbuf *key=ccn_charbuf_create();
-	make_name_lsa_key(key,new_name_lsa->header->orig_router,new_name_lsa->header->ls_type,new_name_lsa->header->ls_id,new_name_lsa->header->orig_time);
+	printf("build_and_install_name_lsas called \n");
 
-	struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa *));
-	
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee; 	
-    	int res;
-
-   	hashtb_start(nlsr->lsdb->name_lsdb, e);
-    	res = hashtb_seek(e, key->buf , key->length, 0);
-
-	if(res == HT_NEW_ENTRY )
-	{
-   		printf("New Name LSA. Added...\n");
-		name_lsa = e->data;
-
-		name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header *));
-	
-	
-		name_lsa->header->ls_type=new_name_lsa->header->ls_type;
-		name_lsa->header->orig_time=new_name_lsa->header->orig_time;
-		name_lsa->header->ls_id=new_name_lsa->header->ls_id;
-		
-		name_lsa->header->orig_router=ccn_charbuf_create();
-		ccn_charbuf_append_string(name_lsa->header->orig_router,ccn_charbuf_as_string(new_name_lsa->header->orig_router));	
-		name_lsa->header->isValid=new_name_lsa->header->isValid;
-
-		name_lsa->name_prefix=ccn_charbuf_create();	
-		ccn_charbuf_append_string(name_lsa->name_prefix,ccn_charbuf_as_string(new_name_lsa->name_prefix));
-		//ccn_charbuf_append_charbuf(name_lsa->name_prefix,new_name_lsa->name_prefix);
-	}
-	else if(res == HT_OLD_ENTRY)
-	{
-		printf("Duplicate Name LSA. Discarded...\n");
-	
-	}
-	
-    	hashtb_end(e);
-
-	ccn_charbuf_destroy(&key);
-	
-}
-
-void 
-build_name_lsa(struct nlsa *name_lsa, struct ccn_charbuf *name_prefix)
-{
-	printf("build_name_lsa called \n");
-	//struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa *));
-
-	//name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header *));
-	//name_lsa->header->orig_router=ccn_charbuf_create();
-	
-	name_lsa->header->ls_type=LS_TYPE_NAME;
-	name_lsa->header->orig_time=get_current_time_microsec();
-	//name_lsa->header->orig_time=(char *)malloc(strlen(get_current_time_microsec())+1);
-	//memcpy(name_lsa->header->orig_time,get_current_time_microsec(),strlen(get_current_time_microsec())+1);
-	name_lsa->header->ls_id=++nlsr->nlsa_id;
-	ccn_charbuf_append_string(name_lsa->header->orig_router,nlsr->router_name);	
-	name_lsa->header->isValid=1;
-
-	//name_lsa->name_prefix=ccn_charbuf_create();	
-	ccn_charbuf_append_string(name_lsa->name_prefix,ccn_charbuf_as_string(name_prefix));
-	//ccn_charbuf_append_charbuf(name_lsa->name_prefix,name_prefix);
-
-	//return name_lsa;
-}
-
-int 
-initial_build_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
-{
-	my_lock();	
-	printf("initial_build_name_lsa called \n");	
 	int i, npl_element;
 	struct name_prefix *np;
 
@@ -137,92 +54,894 @@
 	for(i=0;i<npl_element;i++)
 	{
 		np=e->data;
-
-		struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa *));
-		name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header *));
-		name_lsa->header->orig_router=ccn_charbuf_create();
-		name_lsa->name_prefix=ccn_charbuf_create();
-
-		struct ccn_charbuf *name;
-		name=ccn_charbuf_create();
-		
-		ccn_charbuf_append_string(name,np->name);
-		build_name_lsa(name_lsa,name);
+		struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
+		build_name_lsa(name_lsa,np);
+		print_name_lsa(name_lsa);
 		install_name_lsa(name_lsa);
-
-		//ccn_charbuf_destroy(&name_lsa->header->orig_router);
-		//free(name_lsa->header);
-		//ccn_charbuf_destroy(&name_lsa->name_prefix);
 		free(name_lsa);
-		ccn_charbuf_destroy(&name);
-	
 		hashtb_next(e);		
 	}
 
-	hashtb_end(e);
+	hashtb_end(e);	
 
-	print_name_lsdb();
-	
-	my_unlock();
-	//nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
-	return 0;
 }
 
+void
+build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,int isValid,char *np)
+{
+	printf("build_and_install_others_name_lsa called \n");
+
+	struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
+	build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,isValid,np);
+	print_name_lsa(name_lsa);
+	install_name_lsa(name_lsa);
+	print_name_lsdb();
+	free(name_lsa);
+}
+
+void
+build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,int isValid,char *np)
+{
+	printf("build_others_name_lsa called \n");
+
+	name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
+	name_lsa->header->ls_type=LS_TYPE_NAME;
+
+	char *time_stamp=get_current_timestamp_micro();
+
+	name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
+	memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
+	memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+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)+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)+1);
+	name_lsa->name_prefix->length=strlen(np)+1;
+	
+	
+}
+
+void 
+build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
+{
+	printf("build_name_lsa called \n");
+
+	name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
+	name_lsa->header->ls_type=LS_TYPE_NAME;
+
+	char *time_stamp=get_current_timestamp_micro();
+
+	name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
+	memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
+	memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
+	name_lsa->header->orig_time[strlen(name_lsa->header->orig_time)]='\0';
+
+	printf("Orig Time: %s\n",name_lsa->header->orig_time);
+
+	name_lsa->header->ls_id=++nlsr->nlsa_id;
+	name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	name_lsa->header->orig_router->name=(char *)malloc(nlsr->router_name->length);
+	memcpy(name_lsa->header->orig_router->name,nlsr->router_name->name,nlsr->router_name->length);
+	name_lsa->header->orig_router->length=nlsr->router_name->length;
+	name_lsa->header->isValid=1;
+
+	
+	name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	name_lsa->name_prefix->name=(char *)malloc(np->length);
+	memcpy(name_lsa->name_prefix->name,np->name,np->length);
+	name_lsa->name_prefix->length=np->length;
+
+}
+
+
 void 
 print_name_lsa(struct nlsa *name_lsa)
 {
 	printf("print_name_lsa called \n");
-	printf("-----------Name LSA---------------\n");
-	printf("	Origination Router       :	%s\n",ccn_charbuf_as_string(name_lsa->header->orig_router));
-	printf("	Origination Router Length:	%d\n",(int)name_lsa->header->orig_router->length);
+	
+	printf("-----------Name LSA Content---------------\n");
+	printf("	Origination Router       :	%s\n",name_lsa->header->orig_router->name);
+	printf("	Origination Router Length:	%d\n",name_lsa->header->orig_router->length);
 	printf("	LS Type			 :	%d\n",name_lsa->header->ls_type);
 	printf("	LS Id			 :	%ld\n",name_lsa->header->ls_id);
-	printf("	Origination Time	 :	%ld\n",name_lsa->header->orig_time);
+	printf("	Origination Time	 :	%s\n",name_lsa->header->orig_time);
 	printf("	Is Valid 		 :	%d\n",name_lsa->header->isValid);
-
 	printf("	LSA Data			\n");
-	printf("		Name Prefix:	 	:	%s\n",ccn_charbuf_as_string(name_lsa->name_prefix));
-	printf("		Name Prefix Length	:	%d\n",(int)name_lsa->name_prefix->length);
+	printf("		Name Prefix:	 	:	%s\n",name_lsa->name_prefix->name);
+	printf("		Name Prefix Length	:	%d\n",name_lsa->name_prefix->length);
 
-	printf("\n");
+	printf("\n");	
+}
 
+void 
+install_name_lsa(struct nlsa *name_lsa)
+{
+	printf("install_name_lsa called \n");
+	
+	print_name_lsa(name_lsa);
+
+	char *key=make_name_lsa_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 ));
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    	int res;
+
+   	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 ));
+		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);
+		memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
+
+		printf("Orig Time: %s\n",new_name_lsa->header->orig_time);
+
+		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 ));
+		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 ));
+		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->version);
+		set_new_lsdb_version();	
+		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);		
+
+	}
+	else if(res == HT_OLD_ENTRY)
+	{
+		printf("Duplicate Name LSA. Discarded...\n");
+
+	}
+
+    	hashtb_end(e);
+}
+
+
+char *
+make_name_lsa_key(char *orig_router, int ls_type, long int ls_id)
+{
+	
+	
+	printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
+
+	char lst[2];
+	memset(lst,0,2);
+	sprintf(lst,"%d",ls_type);	
+
+	char lsid[10];
+	memset(lsid,0,10);
+	sprintf(lsid,"%ld",ls_id);
+	
+	
+	char *key=(char *)malloc(strlen(orig_router)+1+strlen(lst)+1+strlen(lsid)+1);
+	memset(key,0,strlen(orig_router)+1+strlen(lst)+1+strlen(lsid)+1);
+	memcpy(key+strlen(key),orig_router,strlen(orig_router));
+	memcpy(key+strlen(key),"/",1);
+	memcpy(key+strlen(key),lst,strlen(lst));
+	memcpy(key+strlen(key),"/",1);
+	memcpy(key+strlen(key),lsid,strlen(lsid));
+
+	printf("Key: %s\n",key);
+
+	return key;
+	
 }
 
 void
 print_name_lsdb(void)
 {
 	printf("print_name_lsdb called \n");	
-	int i, lsdb_element;
+	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);
-	lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
+	name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
 
-	for(i=0;i<lsdb_element;i++)
+	for(i=0;i<name_lsdb_element;i++)
 	{
+		printf("-----------Name LSA (%d)---------------\n",i+1);
 		name_lsa=e->data;
-		print_name_lsa(name_lsa);		
+		print_name_lsa(name_lsa);	
 		hashtb_next(e);		
 	}
 
 	hashtb_end(e);
 
+	printf("\n");
+}
+
+int
+build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+	printf("build_and_install_adj_lsa called \n");
+	my_lock();
+
+	printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
+
+	if(nlsr->adj_build_flag > 0)
+	{
+		printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
+		if ( is_adj_lsa_build()> 0)
+		{
+			struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
+			build_adj_lsa(adj_lsa);
+			print_adj_lsa(adj_lsa);
+			install_adj_lsa(adj_lsa);
+			free(adj_lsa);
+			nlsr->adj_build_flag=0;	
+			print_adj_lsdb();		
+		}
+		else
+		{
+			printf("Can not build adj LSA now\n");
+		}
+	}
+	nlsr->is_build_adj_lsa_sheduled=0;
+	my_unlock();
+	return 0;
+}
+
+void 
+build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data)
+{
+	printf("build_and_install_others_adj_lsa called \n");	
+	struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
+	build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
+	print_adj_lsa(adj_lsa);
+	install_adj_lsa(adj_lsa);
+	free(adj_lsa);
+	print_adj_lsdb();
+
+}
+
+void 
+build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data)
+{
+	printf("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);
+	memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
+
+	adj_lsa->header->orig_router->length=strlen(orig_router)+1;
+	
+
+	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);
+	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);
+	memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
+	
+}
+
+void
+build_adj_lsa(struct alsa * adj_lsa)
+{
+	printf("build_adj_lsa called \n");
+	
+	int no_link=no_active_nbr();
+	printf("Number of link in Adjacent LSA: %d\n",no_link);
+	
+	/*Filling Up Header Data */
+	adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+	adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;	
+
+	char *time_stamp=get_current_timestamp_micro();
+	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);
+	adj_lsa->header->orig_time[strlen(adj_lsa->header->orig_time)]='\0';
+
+	printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length);
+
+	char *temp_r=(char *)malloc(nlsr->router_name->length);
+	memset(temp_r,0,nlsr->router_name->length);
+	sprintf(temp_r,"%s",nlsr->router_name->name);
+	printf("Router Name: %s Length: %d \n",temp_r,(int)strlen(temp_r)+1);
+	
+	adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	adj_lsa->header->orig_router->name=(char *)malloc(strlen(temp_r)+1);
+	memset(adj_lsa->header->orig_router->name,0,strlen(temp_r)+1);
+	memcpy(adj_lsa->header->orig_router->name,temp_r,strlen(temp_r)+1);
+
+	adj_lsa->header->orig_router->length=strlen(temp_r)+1;
+	printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length);
+
+	/* Filling Up Body Data */
+
+	adj_lsa->no_link=no_link;
+
+
+	struct ccn_charbuf *c=ccn_charbuf_create();
+	get_active_nbr_adj_data(c);
+	char *data=ccn_charbuf_as_string(c);
+	printf("Adjacent data: %s \n",data);
+
+	adj_lsa->body=(char *)malloc(strlen(data)+1);
+	memset(adj_lsa->body,0,strlen(data)+1);
+	memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
+	
+
+	ccn_charbuf_destroy(&c);
+
+	if( !nlsr->is_send_lsdb_interest_scheduled )
+	{	
+		nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
+		nlsr->is_send_lsdb_interest_scheduled=1;
+	}
+	nlsr->adj_build_count++;
+	
+	
+	free(temp_r);
 }
 
 
-int 
-install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+void 
+make_adj_lsa_key(char *key,struct alsa *adj_lsa)
 {
-	my_lock();
-		
+	memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
+	memcpy(key+strlen(key),"/",1);
+	char ls_type[2];
+	sprintf(ls_type,"%d",adj_lsa->header->ls_type);
+	memcpy(key+strlen(key),ls_type,strlen(ls_type));
+	key[strlen(key)]='\0';
+}
+
+void
+install_adj_lsa(struct alsa * adj_lsa)
+{
 	printf("install_adj_lsa called \n");
 
-	ev = ccn_schedule_event(nlsr->sched, 1000000, &install_adj_lsa, NULL, 0);
-
-	my_unlock();
-	return 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->version);
+		set_new_lsdb_version();	
+		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
+		
+
+	}
+	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;
+
+			free(new_adj_lsa->body);
+			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->version);
+			set_new_lsdb_version();	
+			printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
+
+		}
+
+	}
+
+    	hashtb_end(e);
+	
+	free(key);
+}
+
+void 
+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);
+	memcpy(lsa_data,body,strlen(body)+1);
+	char *sep="|";
+	char *rem;
+	char *rtr_id;
+	char *length;
+	char *face;
+	char *metric;
+
+	printf("	Lsa Data:\n");
+	printf("		No of Link	: %d\n",no_link);
+
+	if(no_link >0 )
+	{
+		rtr_id=strtok_r(lsa_data,sep,&rem);
+		length=strtok_r(NULL,sep,&rem);
+		face=strtok_r(NULL,sep,&rem);
+		metric=strtok_r(NULL,sep,&rem);
+
+		printf("		Link %d	 	\n",i+1);
+		printf("		Neighbor		 : %s	\n",rtr_id);
+		printf("		Neighbor Length		 : %s	\n",length);
+		printf("		Connecting Face		 : %s	\n",face);
+		printf("		Metric			 : %s	\n",metric);
+		
+
+		for(i=1;i<no_link;i++)
+		{
+			rtr_id=strtok_r(NULL,sep,&rem);
+			length=strtok_r(NULL,sep,&rem);
+			face=strtok_r(NULL,sep,&rem);
+			metric=strtok_r(NULL,sep,&rem);
+			printf("		Link %d	 	\n",i+1);
+			printf("		Neighbor		 : %s	\n",rtr_id);
+			printf("		Neighbor Length		 : %s	\n",length);
+			printf("		Connecting Face		 : %s	\n",face);
+			printf("		Metric			 : %s	\n",metric);
+
+		}
+	}
+
+	free(lsa_data);
+}
+
+void
+print_adj_lsa(struct alsa * adj_lsa)
+{
+	
+	printf("print_adj_lsa called \n");
+	
+	printf("-----------ADJ LSA Content---------------\n");
+	printf("	Origination Router       :	%s\n",adj_lsa->header->orig_router->name);
+	printf("	Origination Router Length:	%d\n",adj_lsa->header->orig_router->length);
+	printf("	LS Type			 :	%d\n",adj_lsa->header->ls_type);
+	printf("	Origination Time	 :	%s\n",adj_lsa->header->orig_time);
+
+	print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
+	
+
+	printf("\n");
+
+}
+
+void
+print_adj_lsdb(void)
+{
+	printf("print_name_lsdb called \n");	
+	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++)
+	{
+		printf("-----------Adj LSA (%d)---------------\n",i+1);
+		adj_lsa=e->data;
+		print_adj_lsa(adj_lsa);	
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+	printf("\n");
+
+}
+
+char * 
+get_name_lsdb_summary()
+{
+	printf("get_name_lsdb_summary called \n");	
+	int i, name_lsdb_element;
+
+	long int len=0;
+
+	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;
+		
+		//ccn_charbuf_append_string(sum_data,name_lsa->header->orig_router->name);
+		len+=strlen(name_lsa->header->orig_router->name);
+		//ccn_charbuf_append_string(sum_data,"|");
+		len++;
+
+		char *temp=(char *)malloc(20);
+		memset(temp,0,20);
+		sprintf(temp,"%d",name_lsa->header->ls_type);
+		len+=strlen(temp);
+		//ccn_charbuf_append_string(sum_data,temp);
+		free(temp);
+		//ccn_charbuf_append_string(sum_data,"|");
+		len++;
+
+		char *temp1=(char *)malloc(20);
+		memset(temp1,0,20);
+		sprintf(temp1,"%ld",name_lsa->header->ls_id);
+		//ccn_charbuf_append_string(sum_data,temp1);
+		len+=strlen(temp1);
+		free(temp1);
+		//ccn_charbuf_append_string(sum_data,"|");
+		len++;
+			
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+	len++;
+
+	char *sum_data=malloc(len);
+	memset(sum_data,0,len);
+
+	hashtb_start(nlsr->lsdb->name_lsdb, e);
+	for(i=0;i<name_lsdb_element;i++)
+	{
+		name_lsa=e->data;
+		
+		//ccn_charbuf_append_string(sum_data,name_lsa->header->orig_router->name);
+		memcpy(sum_data+strlen(sum_data),name_lsa->header->orig_router->name,strlen(name_lsa->header->orig_router->name));
+		//len+=strlen(name_lsa->header->orig_router->name);
+		//ccn_charbuf_append_string(sum_data,"|");
+		memcpy(sum_data+strlen(sum_data),"|",1);
+		//len++;
+
+		char *tempstr=(char *)malloc(20);
+		memset(tempstr,0,20);
+		sprintf(tempstr,"%d",name_lsa->header->ls_type);
+		//len+=strlen(tempstr);
+		//ccn_charbuf_append_string(sum_data,temp);
+		memcpy(sum_data+strlen(sum_data),tempstr,strlen(tempstr));
+		free(tempstr);
+		//ccn_charbuf_append_string(sum_data,"|");
+		memcpy(sum_data+strlen(sum_data),"|",1);
+		//len++;
+
+		char *temp1str=(char *)malloc(20);
+		memset(temp1str,0,20);
+		sprintf(temp1str,"%ld",name_lsa->header->ls_id);
+		//ccn_charbuf_append_string(sum_data,temp1);
+		memcpy(sum_data+strlen(sum_data),temp1str,strlen(temp1str));
+		//len+=strlen(temp1str);
+		free(temp1str);
+		//ccn_charbuf_append_string(sum_data,"|");
+		memcpy(sum_data+strlen(sum_data),"|",1);
+		//len++;
+			
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+	printf("Summary Name LSDB: %s\n",sum_data);
+	
+	return sum_data;
+}
+
+char * 
+get_adj_lsdb_summary(void)
+{
+	printf("get_adj_lsdb_summary called \n");	
+	int i, adj_lsdb_element;
+	struct alsa *adj_lsa;
+
+	long int len=0;
+
+	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;
+		
+		//ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_router->name);
+		len+=strlen(adj_lsa->header->orig_router->name);
+		//ccn_charbuf_append_string(sum_data,"|");
+		len++;
+
+		char *temp=(char *)malloc(20);
+		memset(temp,0,20);
+		sprintf(temp,"%d",adj_lsa->header->ls_type);
+		len+=strlen(temp);
+		//ccn_charbuf_append_string(sum_data,temp);
+		free(temp);
+		//ccn_charbuf_append_string(sum_data,"|");
+		len++;
+
+		//ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_time);
+		len+=strlen(adj_lsa->header->orig_time);
+		//ccn_charbuf_append_string(sum_data,"|");
+		len++;
+			
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	len++;	
+
+	char *sum_data=(char *)malloc(len);
+	memset(sum_data,0,len);
+
+	hashtb_start(nlsr->lsdb->adj_lsdb, e);
+	for(i=0;i<adj_lsdb_element;i++)
+	{
+		adj_lsa=e->data;
+		
+		//ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_router->name);
+		memcpy(sum_data+strlen(sum_data),adj_lsa->header->orig_router->name,strlen(adj_lsa->header->orig_router->name));
+		//len+=strlen(adj_lsa->header->orig_router->name);
+		//ccn_charbuf_append_string(sum_data,"|");
+		memcpy(sum_data+strlen(sum_data),"|",1);
+		//len++;
+
+		char *temp1=(char *)malloc(20);
+		memset(temp1,0,20);
+		sprintf(temp1,"%d",adj_lsa->header->ls_type);
+		//len+=strlen(temp);
+		//ccn_charbuf_append_string(sum_data,temp);
+		memcpy(sum_data+strlen(sum_data),temp1,strlen(temp1));
+		free(temp1);
+		//ccn_charbuf_append_string(sum_data,"|");
+		memcpy(sum_data+strlen(sum_data),"|",1);
+		//len++;
+
+		//ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_time);
+		memcpy(sum_data+strlen(sum_data),adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time));
+		//len+=strlen(adj_lsa->header->orig_time);
+		//ccn_charbuf_append_string(sum_data,"|");
+		memcpy(sum_data+strlen(sum_data),"|",1);
+		//len++;
+			
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	
+	printf("Summary ADJ LSDB: %s\n",sum_data);
+
+	return sum_data;
+}
+
+void 
+get_name_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
+{
+	printf("get_name_lsa_data called \n");
+
+	struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    	int res;
+
+   	hashtb_start(nlsr->lsdb->name_lsdb, e);
+    	res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
+
+	if( res == HT_OLD_ENTRY )
+	{
+		name_lsa=e->data;
+		printf("NAME LSA found\n");
+		
+		ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_length=(char *)malloc(20);
+		memset(temp_length,0,20);
+		sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
+		ccn_charbuf_append_string(lsa_data,temp_length);
+		free(temp_length);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_ltype=(char *)malloc(20);
+		memset(temp_ltype,0,20);
+		sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
+		ccn_charbuf_append_string(lsa_data,temp_ltype);
+		free(temp_ltype);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_lsid=(char *)malloc(20);
+		memset(temp_lsid,0,20);
+		sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
+		ccn_charbuf_append_string(lsa_data,temp_lsid);
+		free(temp_lsid);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_valid=(char *)malloc(20);
+		memset(temp_valid,0,20);
+		sprintf(temp_valid,"%d",name_lsa->header->isValid);
+		ccn_charbuf_append_string(lsa_data,temp_valid);
+		free(temp_valid);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_npl=(char *)malloc(20);
+		memset(temp_npl,0,20);
+		sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
+		ccn_charbuf_append_string(lsa_data,temp_npl);
+		free(temp_npl);
+		ccn_charbuf_append_string(lsa_data,"|");
+		
+	}
+	else if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+
+	hashtb_end(e);
+}
+
+void 
+get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
+{
+	printf("get_adj_lsa_data called \n");
+
+	struct alsa *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, lsaId->name, lsaId->length-1, 0);
+
+	if( res == HT_OLD_ENTRY )
+	{
+		adj_lsa=e->data;
+		printf("NAME LSA found\n");
+		
+		ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_length=(char *)malloc(20);
+		memset(temp_length,0,20);
+		sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
+		ccn_charbuf_append_string(lsa_data,temp_length);
+		free(temp_length);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_ltype=(char *)malloc(20);
+		memset(temp_ltype,0,20);
+		sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
+		ccn_charbuf_append_string(lsa_data,temp_ltype);
+		free(temp_ltype);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *temp_nl=(char *)malloc(20);
+		memset(temp_nl,0,20);
+		sprintf(temp_nl,"%d",adj_lsa->no_link);
+		ccn_charbuf_append_string(lsa_data,temp_nl);
+		free(temp_nl);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		ccn_charbuf_append_string(lsa_data,adj_lsa->body);
+
+		
+	}
+	else if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+
+	hashtb_end(e);
+}
+
+long int
+get_name_lsdb_num_element(void)
+{
+	long int num_element;
+
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+    	hashtb_start(nlsr->lsdb->name_lsdb, e);
+	num_element=hashtb_n(nlsr->lsdb->name_lsdb);
+	hashtb_end(e);
+
+	return num_element; 
+}
+
+long int
+get_adj_lsdb_num_element(void)
+{
+	long int num_element;
+
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+    	hashtb_start(nlsr->lsdb->adj_lsdb, e);
+	num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
+	hashtb_end(e);
+
+	return num_element; 
 }
diff --git a/nlsr_lsdb.h b/nlsr_lsdb.h
index c71a84d..5b37c60 100644
--- a/nlsr_lsdb.h
+++ b/nlsr_lsdb.h
@@ -7,7 +7,7 @@
 
 struct link
 {
-	struct ccn_charbuf *nbr;
+	struct name_prefix *nbr;
 	int face;
 	int metric;
 };
@@ -16,23 +16,24 @@
 struct alsa_header 
 {
 	unsigned int ls_type;
-	long int orig_time;
-	struct ccn_charbuf *orig_router;
+	char *orig_time;
+	struct name_prefix *orig_router;
+	
 };
 
 struct alsa
 {
 	struct alsa_header *header;	
 	int no_link;
-	struct link *links;
+	char *body;
 };
 
 struct nlsa_header
 {
 	unsigned int ls_type;
-	long int orig_time;
+	char *orig_time;
 	long int ls_id;
-	struct ccn_charbuf *orig_router;
+	struct name_prefix *orig_router;
 	unsigned int isValid;
 
 };
@@ -40,18 +41,36 @@
 struct nlsa
 {
 	struct nlsa_header *header;
-	struct ccn_charbuf *name_prefix;
+	struct name_prefix *name_prefix;
 };
 
+void set_new_lsdb_version(void);
 
-int initial_build_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
-void build_name_lsa(struct nlsa *name_lsa, struct ccn_charbuf *name_prefix);
-void install_name_lsa(struct nlsa *new_name_lsa);
-void make_name_lsa_key(struct ccn_charbuf *key, struct ccn_charbuf *orig_router, unsigned int ls_type, long int nlsa_id, long int orig_time);
-void print_name_lsdb(void);
+void build_and_install_name_lsas(void);
+void build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,int isValid,char *np);
+void build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np);
+void build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,int isValid,char *np);
 void print_name_lsa(struct nlsa *name_lsa);
+void install_name_lsa(struct nlsa *name_lsa);
+char * make_name_lsa_key(char *orig_router, int ls_type, long int ls_id);
+void print_name_lsdb(void);
 
+int build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
+void build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data);
+void build_adj_lsa(struct alsa * adj_lsa);
+void build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data);
+void install_adj_lsa(struct alsa * adj_lsa);
+void make_adj_lsa_key(char *key,struct alsa *adj_lsa);
+void print_adj_lsa_body(const char *body, int no_link);
+void print_adj_lsa(struct alsa * adj_lsa);
+void print_adj_lsdb(void);
 
-int install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
+char * get_name_lsdb_summary(void);
+char * get_adj_lsdb_summary(void);
+void get_name_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId);
+void get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId);
+
+long int get_name_lsdb_num_element(void);
+long int get_adj_lsdb_num_element(void);
 
 #endif
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index af79e3a..d67cd1d 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -20,9 +20,10 @@
 
 #include "nlsr.h"
 #include "nlsr_ndn.h"
-#include "utility.h"
 #include "nlsr_adl.h"
 #include "nlsr_lsdb.h"
+#include "utility.h"
+
 
 int
 appendLifetime(struct ccn_charbuf *cb, int lifetime) 
@@ -41,399 +42,152 @@
 	return res;
 }
 
+
+void 
+get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info)
+{
+
+	printf("get_nbr called\n");
+	int res,i;
+	int nlsr_position=0;
+	int name_comps=(int)info->interest_comps->n;
+	int len=0;
+
+	for(i=0;i<name_comps;i++)
+	{
+		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
+		if( res == 0)
+		{
+			nlsr_position=i;
+			break;
+		}	
+	}
+
+
+	const unsigned char *comp_ptr1;
+	size_t comp_size;
+	for(i=0;i<nlsr_position;i++)
+	{
+		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
+		len+=1;
+		len+=(int)comp_size;	
+	}
+	len++;
+
+	char *neighbor=(char *)malloc(len);
+	memset(neighbor,0,len);
+
+	for(i=0; i<nlsr_position;i++)
+	{
+		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
+		memcpy(neighbor+strlen(neighbor),"/",1);
+		memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
+
+	}
+	
+	//neighbor[strlen(neighbor)]='\0';
+
+	nbr->name=(char *)malloc(strlen(neighbor)+1);
+	memcpy(nbr->name,neighbor,strlen(neighbor)+1);
+	nbr->length=strlen(neighbor)+1;
+
+	printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length);
+	
+
+}
+
+void 
+get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info)
+{
+
+	printf("get_nbr called\n");
+	int res,i;
+	int nlsr_position=0;
+	int name_comps=(int)info->interest_comps->n;
+	int len=0;
+
+	for(i=0;i<name_comps;i++)
+	{
+		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
+		if( res == 0)
+		{
+			nlsr_position=i;
+			break;
+		}	
+	}
+
+
+	const unsigned char *comp_ptr1;
+	size_t comp_size;
+	for(i=nlsr_position+2;i<info->interest_comps->n-2;i++)
+	{
+		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
+		len+=1;
+		len+=(int)comp_size;	
+	}
+	len++;
+
+	char *neighbor=(char *)malloc(len);
+	memset(neighbor,0,len);
+
+	for(i=nlsr_position+2; i<info->interest_comps->n-2;i++)
+	{
+		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
+		memcpy(neighbor+strlen(neighbor),"/",1);
+		memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
+
+	}
+	
+	//neighbor[strlen(neighbor)]='\0';
+
+	lsaId->name=(char *)malloc(strlen(neighbor)+1);
+	memset(lsaId->name,0,strlen(neighbor)+1);
+	memcpy(lsaId->name,neighbor,strlen(neighbor)+1);
+	lsaId->length=strlen(neighbor)+1;
+
+	printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
+	
+
+}
+
 enum ccn_upcall_res 
 incoming_interest(struct ccn_closure *selfp,
         enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
 {
-	my_lock();
-    
+    	my_lock();
     switch (kind) {
         case CCN_UPCALL_FINAL:
             break;
         case CCN_UPCALL_INTEREST:
-		// printing the name prefix for which it received interest
-            	printf("Interest Received for name: "); 
-	    	struct ccn_charbuf*c;
-		c=ccn_charbuf_create();
-		ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
-		ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
-		//ccn_name_chop(c,NULL,-1);
-		printf("%s\n",ccn_charbuf_as_string(c));
-		ccn_charbuf_destroy(&c);
-
+            	printf("Interest Received \n"); 
 		process_incoming_interest(selfp, info);
-		
-		/* 
-	    	struct ccn_charbuf *data=ccn_charbuf_create();
-	    	struct ccn_charbuf *name=ccn_charbuf_create();
-	    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
-	   
-		 ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],
-            info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
-
-		sp.template_ccnb=ccn_charbuf_create();
-		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
-		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010);
-                sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
-        	ccn_charbuf_append_closer(sp.template_ccnb);		   
-
-		res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello")); 
-	    	res=ccn_put(ospfndn->ccn,data->buf,data->length);
-            	ccn_charbuf_destroy(&data);  
-
-		*/
 		break;
-
         default:
             break;
     }
-
 	my_unlock();
     return CCN_UPCALL_RESULT_OK;
 }
 
 
-enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
-        enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
-{
-
-	my_lock();
-
-    switch(kind) {
-        case CCN_UPCALL_FINAL:
-            break;
-        case CCN_UPCALL_CONTENT:
-            	printf("Content Received for name: ");  
-		struct ccn_charbuf*c;
-		c=ccn_charbuf_create();
-		ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
-		printf("%s\n",ccn_charbuf_as_string(c));
-		ccn_charbuf_destroy(&c);
-	
-		process_incoming_content(selfp, info);
-
-	    break;
-        case CCN_UPCALL_INTEREST_TIMED_OUT:
-          	printf("Interest timed out \n"); 
-		struct ccn_charbuf*ic;
-		ic=ccn_charbuf_create();
-		ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
-		printf("%s\n",ccn_charbuf_as_string(ic));
-		ccn_charbuf_destroy(&ic);	    
-		process_incoming_timed_out_interest(selfp,info);
-
-	    break;
-        default:
-            fprintf(stderr, "Unexpected response of kind %d\n", kind);
-            return CCN_UPCALL_RESULT_ERR;
-    }
-
-	my_unlock();
-    return CCN_UPCALL_RESULT_OK;
-}
-
-
-void 
-process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info)
-{
-	printf("process_incoming_content called \n");
-
-	struct ccn_charbuf*c;
-	c=ccn_charbuf_create();
-	//ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
-	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
-	printf("%s\n",ccn_charbuf_as_string(c));
-	ccn_charbuf_destroy(&c);
-
-	const unsigned char *comp_ptr1;
-	size_t comp_size;
-	int res,i;
-	int nlsr_position=0;
-	int name_comps=(int)info->interest_comps->n;
-	
-	for(i=0;i<name_comps;i++)
-	{
-		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
-		if( res == 0)
-		{
-			nlsr_position=i;
-			break;
-		}	
-	}
-
-	res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
-
-
-	printf("Det= %s \n",comp_ptr1);
-
-	if(!strcmp((char *)comp_ptr1,"lsdb"))
-	{
-		process_incoming_content_lsdb(selfp,info);
-	}
-	if(!strcmp((char *)comp_ptr1,"info"))
-	{
-		process_incoming_content_info(selfp,info);
-	}
-
-}
-
-
-void 
-process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
-{
-	printf("process_incoming_content_lsdb called \n");
-
-	const unsigned char *content_data;
-	size_t length;
-	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);
-
-
-	if ( !strcmp((char *)content_data,"NACK"))
-	{
-		printf("NACK received for LSDB request. Do nothing \n");
-	}
-	else
-	{
-		// Do the LSDB processing here 
-
-		const unsigned char *comp_ptr1;
-		size_t comp_size;
-		int res;
-
-		res=ccn_name_comp_get(info->content_ccnb, info->content_comps,info->interest_comps->n-1,&comp_ptr1, &comp_size);
-		if ( res >=0)
-		printf("Received Database Version: %s \n",(char *)comp_ptr1);
-
-	}
-
-	
-
-}
-
-
-
-void 
-process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
-{
-	printf("process_incoming_content_info called \n");
-
-	const unsigned char *content_data;
-	size_t length;
-	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);
-
-	printf("Info Value: %s \n",(char *)content_data);
-
-
-	int res,i;
-	int nlsr_position=0;
-	int name_comps=(int)info->interest_comps->n;
-
-	for(i=0;i<name_comps;i++)
-	{
-		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
-		if( res == 0)
-		{
-			nlsr_position=i;
-			break;
-		}	
-	}
-	
-	struct ccn_charbuf *nbr;
-	nbr=ccn_charbuf_create();
-
-	
-	const unsigned char *comp_ptr1;
-	size_t comp_size;
-	for(i=0;i<nlsr_position;i++)
-	{
-		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
-		//printf("%s \n",comp_ptr1);
-		ccn_charbuf_append_string(nbr,"/");
-		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
-	}
-
-	ccn_charbuf_append_string(nbr,"\0");	
-	printf("Info Content received for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
-	
-	update_adjacent_timed_out_zero_to_adl(nbr);
-	update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
-
-	print_adjacent_from_adl();
-
-	nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
-
-	ccn_charbuf_destroy(&nbr);	
-	
-
-}
-
-void 
-process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
-{
-	printf("process_incoming_timed_out_interest called \n");
-
-	struct ccn_charbuf*c;
-	c=ccn_charbuf_create();
-	//ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
-	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
-	printf("%s\n",ccn_charbuf_as_string(c));
-	ccn_charbuf_destroy(&c);
-
-	//const unsigned char *comp_ptr1;
-	//size_t comp_size;
-	int res,i;
-	int nlsr_position=0;
-	int name_comps=(int)info->interest_comps->n;
-	
-	for(i=0;i<name_comps;i++)
-	{
-		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
-		if( res == 0)
-		{
-			nlsr_position=i;
-			break;
-		}	
-	}
-
-	//res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
-
-
-	//printf("Det= %s \n",comp_ptr1);
-
-	//if(!strcmp((char *)comp_ptr1,"lsdb"))
-	if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
-	{
-		process_incoming_timed_out_interest_lsdb(selfp,info);
-	}
-	else if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
-	{
-		process_incoming_timed_out_interest_info(selfp,info);
-	}
-}
-
-
-void 
-process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
-{
-	printf("process_incoming_timed_out_interest_lsdb called \n");
-
-		
-	int res,i;
-	int nlsr_position=0;
-	int name_comps=(int)info->interest_comps->n;
-
-	//const unsigned char *comp_ptr1;
-	//size_t comp_size;
-	
-	for(i=0;i<name_comps;i++)
-	{
-		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
-		if( res == 0)
-		{
-			nlsr_position=i;
-			break;
-		}	
-	}	
-
-
-	struct ccn_charbuf *nbr;
-	nbr=ccn_charbuf_create();
-
-	
-	const unsigned char *comp_ptr1;
-	size_t comp_size;
-	for(i=0;i<nlsr_position;i++)
-	{
-		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
-		//printf("%s \n",comp_ptr1);
-		ccn_charbuf_append_string(nbr,"/");
-		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
-	}
-
-	ccn_charbuf_append_string(nbr,"\0");	
-	printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
-
-	//update_adjacent_status_to_adl(nbr,1);
-
-	ccn_charbuf_destroy(&nbr);	
-}
-
-void 
-process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
-{
-
-	printf("process_incoming_timed_out_interest_info called \n");
-
-	int res,i;
-	int nlsr_position=0;
-	int name_comps=(int)info->interest_comps->n;
-
-	for(i=0;i<name_comps;i++)
-	{
-		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
-		if( res == 0)
-		{
-			nlsr_position=i;
-			break;
-		}	
-	}
-	
-	struct ccn_charbuf *nbr;
-	nbr=ccn_charbuf_create();
-
-	
-	const unsigned char *comp_ptr1;
-	size_t comp_size;
-	for(i=0;i<nlsr_position;i++)
-	{
-		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
-		//printf("%s \n",comp_ptr1);
-		ccn_charbuf_append_string(nbr,"/");
-		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
-	}
-
-	ccn_charbuf_append_string(nbr,"\0");	
-	printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
-
-	update_adjacent_timed_out_to_adl(nbr,1);
-
-	print_adjacent_from_adl();	
-
-	int timed_out=get_timed_out_number(nbr);
-	if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables 
-	{
-		printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
-		send_info_interest_to_neighbor(nbr);
-	}
-	else
-	{
-		printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
-		nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
-	}
-
-	ccn_charbuf_destroy(&nbr);
-}
-
-
 void 
 process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
 {
 	printf("process_incoming_interest called \n");
 
-
+	/*
 	struct ccn_charbuf*c;
 	c=ccn_charbuf_create();
-	//ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
-	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
+	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);	
 	printf("%s\n",ccn_charbuf_as_string(c));
 	ccn_charbuf_destroy(&c);
-
+	*/
 	const unsigned char *comp_ptr1;
 	size_t comp_size;
 	int res,i;
 	int nlsr_position=0;
 	int name_comps=(int)info->interest_comps->n;
-	
+
 	for(i=0;i<name_comps;i++)
 	{
 		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
@@ -445,17 +199,82 @@
 	}
 
 	res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
-	
+
 	printf("Det= %s \n",comp_ptr1);
 
-	if(!strcmp((char *)comp_ptr1,"lsdb"))
-	{
-		process_incoming_interest_lsdb(selfp,info);
-	}
 	if(!strcmp((char *)comp_ptr1,"info"))
 	{
 		process_incoming_interest_info(selfp,info);
 	}
+	if(!strcmp((char *)comp_ptr1,"lsdb"))
+	{
+		process_incoming_interest_lsdb(selfp,info);
+	}
+	if(!strcmp((char *)comp_ptr1,"lsa"))
+	{
+		process_incoming_interest_lsa(selfp,info);
+	}
+	
+}
+
+void 
+process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
+{
+	printf("process_incoming_interest_info called \n");
+	
+
+	printf("Sending info Content Back ...\n");
+	int res;
+	struct ccn_charbuf *data=ccn_charbuf_create();
+    	struct ccn_charbuf *name=ccn_charbuf_create();
+    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
+	
+	res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);
+	if (res >= 0)
+	{
+		sp.template_ccnb=ccn_charbuf_create();
+		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
+		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
+       	 	sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
+		ccn_charbuf_append_closer(sp.template_ccnb);
+
+
+		char *raw_data=(char *)malloc(16);
+		memset(raw_data,0,16);
+		sprintf(raw_data,"%ld", nlsr->lsdb_synch_interval);	
+
+		res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data)); 
+		if(res >= 0)
+			printf("Signing Content is successful \n");
+
+    		res=ccn_put(nlsr->ccn,data->buf,data->length);		
+		if(res >= 0)
+		printf("Sending Info Content is successful \n");
+
+		printf("Info Content sending done....\n");
+
+
+		struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *));
+		get_lsa_identifier(nbr,selfp,info);
+		printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
+	
+
+		if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry )
+		{
+			send_info_interest_to_neighbor(nbr);
+		}
+
+		free(nbr);
+		free(raw_data);
+		ccn_charbuf_destroy(&sp.template_ccnb);
+	}
+	
+	ccn_charbuf_destroy(&data);
+	ccn_charbuf_destroy(&name);	
+
+	
+
+		
 }
 
 
@@ -463,14 +282,14 @@
 process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
 {
 	printf("process_incoming_interest_lsdb called \n");
-	
-	int l, res;
+
+	int l,res;
 	const unsigned char *exclbase;
 	size_t size;
 	struct ccn_buf_decoder decoder;
 	struct ccn_buf_decoder *d;
-	const unsigned char *comp;	
-
+	const unsigned char *comp;
+	int dbcmp=0;
 
 	l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
 	if (l > 0) 
@@ -489,345 +308,930 @@
 				ccn_buf_advance(d);
 				ccn_buf_match_blob(d, &comp, &size);
 				ccn_buf_check_close(d);			
-				
-				
+
+
 			}
 			ccn_buf_check_close(d);
 		}
-		//if (d->decoder.state < 0)
-			//printf("Parse Failed\n");
 		if (comp != NULL)
-			printf("Number in Exclusion Filter is %s\n",comp);
-			
+		{
+			printf("LSDB Version in Exclusion Filter is %s\n",comp);
+			dbcmp=strcmp(nlsr->lsdb->version,(char *)comp);
+		}
 		/* Now comp points to the start of your potential number, and size is its length */
 	}
-
-	int excl_db_version=atoi((char *)comp);
-	int dbcmp=nlsr->lsdb->version-excl_db_version;
-	//int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16);
-
-	
-
-	printf (" dbcmp = %d \n",dbcmp);	
-
-	if(dbcmp > 0)
+	else
 	{
-		printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
-	}
-	else 
-	{
-		printf("Data base is not updated than the older one (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
-		printf("Sending NACK Content back.....\n");
-
-		struct ccn_charbuf *data=ccn_charbuf_create();
-	    	struct ccn_charbuf *name=ccn_charbuf_create();
-	    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
-
-		ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
-		
-		sp.template_ccnb=ccn_charbuf_create();
-		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
-		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
-                sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
-        	ccn_charbuf_append_closer(sp.template_ccnb);		   
-
-		res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); 
-		if(res >= 0)
-			printf("Signing Content is successful \n");
-
-	    	res=ccn_put(nlsr->ccn,data->buf,data->length);
-		
-		if(res >= 0)
-			printf("Sending NACK Content is successful \n");
-
-            	ccn_charbuf_destroy(&data);
-		ccn_charbuf_destroy(&name);
-		ccn_charbuf_destroy(&sp.template_ccnb);		
+		printf("LSDB Version in Exclusion Filter is: None Added\n");
+		dbcmp=1;		
 
 	}
 
-}
-
-
-void 
-process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
-{
-	printf("process_incoming_interest_info called \n");
-	int res;
-
-	printf("Sending Info Content back.....\n");
-
 	struct ccn_charbuf *data=ccn_charbuf_create();
-    	struct ccn_charbuf *name=ccn_charbuf_create();
-    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
-
-	ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);	
+	struct ccn_charbuf *name=ccn_charbuf_create();
+	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
+	
+	ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
 
 	sp.template_ccnb=ccn_charbuf_create();
 	ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
 	ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
-	sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
-	ccn_charbuf_append_closer(sp.template_ccnb);	
+        sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
+        ccn_charbuf_append_closer(sp.template_ccnb);
 
-	res= ccn_sign_content(nlsr->ccn, data, name, &sp,"info",strlen("info") ); 
-	if(res >= 0)
-		printf("Signing Content is successful \n");
 
-    	res=ccn_put(nlsr->ccn,data->buf,data->length);		
-	if(res >= 0)
-		printf("Sending Info Content is successful \n");
+	if(dbcmp>0)
+	{
+		printf("Has Updated Database than Neighbor\n");
+		printf("Sending LSDB Summary of Updated LSDB Content...\n");	
+		/*
+		ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
+
+		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
+		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
+                sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
+        	ccn_charbuf_append_closer(sp.template_ccnb);
+		*/	
+
+		//ccn_charbuf_append_string(name,nlsr->lsdb->version);
+
+
+		
+		long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element();
+		char *num_element=(char *)malloc(15);
+		memset(num_element,0,15);
+		sprintf(num_element,"%ld|",num_lsa);
+
+		char *name_lsdb_summary=get_name_lsdb_summary();
+		char *adj_lsdb_summary=get_adj_lsdb_summary();
+
+		char *raw_data=(char *)malloc(strlen(num_element) + strlen(name_lsdb_summary)+strlen(adj_lsdb_summary)+1);
+		memset(raw_data,0,strlen(num_element) + strlen(name_lsdb_summary)+strlen(adj_lsdb_summary)+1);
+
+		memcpy(raw_data+strlen(raw_data),num_element,strlen(num_element)+1);
+
+		if( strlen(name_lsdb_summary) >0 )
+		{
+			memcpy(raw_data+strlen(raw_data),name_lsdb_summary,strlen(name_lsdb_summary)+1);
+		}
+		if( strlen(adj_lsdb_summary) >0 )
+		{
+			memcpy(raw_data+strlen(raw_data),adj_lsdb_summary,strlen(adj_lsdb_summary)+1);
+		}
+
+		printf("Content Data to be sent: %s \n",raw_data);		
+
+		if(nlsr->adj_build_count == 0 && nlsr->is_build_adj_lsa_sheduled == 1)
+		{
+			 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT"));
+		}
+		else
+		{
+			res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
+		}
+		if(res >= 0)
+			printf("Signing LSDB Summary of Updated LSDB Content is successful \n");
+
+	    	res=ccn_put(nlsr->ccn,data->buf,data->length);
+
+		if(res >= 0)
+			printf("Sending LSDB Summary of Updated LSDB Content is successful \n");
+
+		//ccn_charbuf_destroy(&nlsd);
+		//ccn_charbuf_destroy(&alsd);
+		free(num_element);
+	}
+	else
+	{
+		printf("Does not have Updated Database than Neighbor\n");
+		
+		printf("Sending NACK Content.....\n");	
+		//ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
+
+		/*
+		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
+		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
+                sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
+        	ccn_charbuf_append_closer(sp.template_ccnb);		   
+		*/
+		res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); 
+		if(res >= 0)
+			printf("Signing NACK Content is successful \n");
+
+	    	res=ccn_put(nlsr->ccn,data->buf,data->length);
+
+		if(res >= 0)
+			printf("Sending NACK Content is successful \n");
+
+		
+	}
 
 	ccn_charbuf_destroy(&data);
 	ccn_charbuf_destroy(&name);
-	//ccn_charbuf_destroy(&c);
 	ccn_charbuf_destroy(&sp.template_ccnb);
 
 }
 
-int
-send_lsdb_interest(struct ccn_schedule *sched, void *clienth,
-        struct ccn_scheduled_event *ev, int flags)
+void 
+process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info)
 {
-	my_lock();
-	struct ccn_charbuf *name;
-	long int rnum;
-	char rnumstr[20];
-	char lsdb_str[5];
-	char nlsr_str[5];
+	printf("process_incoming_interest_lsa called \n");
 
-	int res,i;
-	int adl_element;
+	/*
+	struct ccn_charbuf*c;
+	c=ccn_charbuf_create();
+	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);	
+	printf("%s\n",ccn_charbuf_as_string(c));
+	ccn_charbuf_destroy(&c);
+	*/
+	int res;
 
-	rnum=random();
-	memset(&rnumstr,0,20);
-	sprintf(rnumstr,"%ld",rnum);
-	memset(&nlsr_str,0,5);
-	sprintf(nlsr_str,"nlsr");
-	memset(&lsdb_str,0,5);
-	sprintf(lsdb_str,"lsdb");
-	
+	struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	get_lsa_identifier(lsaId,selfp,info);
 
-	struct ndn_neighbor *nbr;
+	printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
+	printf("Router Name   : %s Length: %d\n",nlsr->router_name->name,nlsr->router_name->length);		
 
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee;
-    	
-    	hashtb_start(nlsr->adl, e);
-	adl_element=hashtb_n(nlsr->adl);
-	//int mynumber=15;
+	char lsa_type=lsaId->name[nlsr->router_name->length];
+	printf("LSA Type: %c\n",lsa_type);
+	int ls_type=atoi(&lsa_type);
 
-	for(i=0;i<adl_element;i++)
+	struct ccn_charbuf *lsa_data=ccn_charbuf_create();
+
+	if ( ls_type == LSA_NAME_TYPE )
 	{
-		nbr=e->data;
-		printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,lsdb_str);	
-		name=ccn_charbuf_create();
-		res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
-		ccn_name_append_str(name,nlsr_str);
-		ccn_name_append_str(name,lsdb_str);
-		//ccn_name_append_str(name,rnumstr);
-
-		/* adding Exclusion filter */
-		
-		struct ccn_charbuf *templ;
-		templ = ccn_charbuf_create();
-
-		struct ccn_charbuf *c;
-		c = ccn_charbuf_create();
-
-
-		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
-		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
-		ccn_charbuf_append_closer(templ); /* </Name> */
-		ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
-		ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
-		ccn_charbuf_reset(c);
-		//ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
-		//ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
-		ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
-		ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
-		ccn_charbuf_append_closer(templ); /* </Exclude> */
-		ccn_charbuf_append_closer(templ); /* </Interest> */
-
-	
-		/* Adding Exclusion filter done */
-				
-		res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
-			
-		if ( res >= 0 )
-			printf("Interest sending Successfull .... \n");	
-		ccn_charbuf_destroy(&c);
-		ccn_charbuf_destroy(&templ);
-		ccn_charbuf_destroy(&name);
-	
-		hashtb_next(e);		
+		printf("Interest Received for NAME LSA\n");
+		get_name_lsa_data(lsa_data,lsaId);
+	}
+	else if ( ls_type == LSA_ADJ_TYPE )
+	{
+		printf("Interest Received for ADJ LSA\n");
+		get_adj_lsa_data(lsa_data,lsaId);
 	}
 
-	hashtb_end(e);
+	char *rdata=ccn_charbuf_as_string(lsa_data);
+	char *raw_data=(char *)malloc(strlen(rdata)+1);
+	memset(raw_data,0,strlen(rdata)+1);
+	memcpy(raw_data,(char *)rdata,strlen(rdata)+1);
+	printf("Content Data to be sent: %s\n",raw_data);
 
-	nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0);
+	struct ccn_charbuf *data=ccn_charbuf_create();
+	struct ccn_charbuf *name=ccn_charbuf_create();
+	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
+	
+	ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
 
-	my_unlock();
-	return 0;
+	sp.template_ccnb=ccn_charbuf_create();
+	ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
+	ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
+        sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
+        ccn_charbuf_append_closer(sp.template_ccnb);
 
+	res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); 
+	if(res >= 0)
+		printf("Signing LSA Content is successful \n");
+
+	res=ccn_put(nlsr->ccn,data->buf,data->length);
+	if(res >= 0)
+		printf("Sending LSA Content is successful \n");
+
+	
+	
+	ccn_charbuf_destroy(&data);
+	ccn_charbuf_destroy(&name);
+	ccn_charbuf_destroy(&sp.template_ccnb);
+	ccn_charbuf_destroy(&lsa_data);
+
+	free(raw_data);
+	free(lsaId);
 }
 
-
-int
-send_info_interest(struct ccn_schedule *sched, void *clienth,
-        struct ccn_scheduled_event *ev, int flags)
+enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
+        enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
 {
 
 	my_lock();
-	struct ccn_charbuf *name;
-	long int rnum;
-	char rnumstr[20];
-	char info_str[5];
-	char nlsr_str[5];
-
-	int res,i;
-	int adl_element;
-	int scope = 2;  //no further than the next host
-
-	rnum=random();
-	memset(&rnumstr,0,20);
-	sprintf(rnumstr,"%ld",rnum);
-	memset(&nlsr_str,0,5);
-	sprintf(nlsr_str,"nlsr");
-	memset(&info_str,0,5);
-	sprintf(info_str,"info");
-	
-
-	struct ndn_neighbor *nbr;
-
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee;
-    	
-    	hashtb_start(nlsr->adl, e);
-	adl_element=hashtb_n(nlsr->adl);
-	//int mynumber=15;
-
-	for(i=0;i<adl_element;i++)
-	{
-		nbr=e->data;
-		printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,info_str);	
-		name=ccn_charbuf_create();
-		res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
-		ccn_name_append_str(name,nlsr_str);
-		ccn_name_append_str(name,info_str);
-		//ccn_name_append_str(name,rnumstr);
-
-		/* adding Exclusion filter */
+    switch(kind) {
+        case CCN_UPCALL_FINAL:
+            break;
+        case CCN_UPCALL_CONTENT:
+            	printf("Content Received \n");  
 		
-		struct ccn_charbuf *templ;
-		templ = ccn_charbuf_create();
+		process_incoming_content(selfp, info);
 
-//		struct ccn_charbuf *c;
-//		c = ccn_charbuf_create();
+	    break;
+        case CCN_UPCALL_INTEREST_TIMED_OUT:
+          	printf("Interest timed out \n"); 	    
+		process_incoming_timed_out_interest(selfp,info);
 
-
-		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
-		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
-		ccn_charbuf_append_closer(templ); /* </Name> */
-//		ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
-//		ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
-//		ccn_charbuf_reset(c);
-//		//ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
-//		//ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
-//		ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
-//		ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
-//		ccn_charbuf_append_closer(templ); /* </Exclude> */
-		ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
-		appendLifetime(templ,nlsr->interest_resend_time);
-		ccn_charbuf_append_closer(templ); /* </Interest> */
-
-
-		/* Adding Exclusion filter done */
-				
-		res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
-			
-		if ( res >= 0 )
-			printf("Interest sending Successfull .... \n");	
-//		ccn_charbuf_destroy(&c);
-		ccn_charbuf_destroy(&templ);
-		ccn_charbuf_destroy(&name);
-	
-		hashtb_next(e);		
-	}
-
-	hashtb_end(e);
-
-	//nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0);
+	    break;
+        default:
+            fprintf(stderr, "Unexpected response of kind %d\n", kind);
+            //return CCN_UPCALL_RESULT_ERR;
+    }
 
 	my_unlock();
-	return 0;
-
+    return CCN_UPCALL_RESULT_OK;
 }
 
-
 void 
-send_info_interest_to_neighbor(struct ccn_charbuf *nbr)
+process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info)
 {
+	printf("process_incoming_content called \n");
+	
+	/*	
+	struct ccn_charbuf*c;
+	c=ccn_charbuf_create();
+	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);	
+	printf("%s\n",ccn_charbuf_as_string(c));
+	ccn_charbuf_destroy(&c);
+	*/
+
+	const unsigned char *comp_ptr1;
+	size_t comp_size;
+	int res,i;
+	int nlsr_position=0;
+	int name_comps=(int)info->interest_comps->n;
+
+	for(i=0;i<name_comps;i++)
+	{
+		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
+		if( res == 0)
+		{
+			nlsr_position=i;
+			break;
+		}	
+	}
+
+	res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
+
+	printf("Det= %s \n",comp_ptr1);
+
+	if(!strcmp((char *)comp_ptr1,"info"))
+	{
+		process_incoming_content_info(selfp,info);
+	}
+	if(!strcmp((char *)comp_ptr1,"lsdb"))
+	{
+		process_incoming_content_lsdb(selfp,info);
+	}
+	if(!strcmp((char *)comp_ptr1,"lsa"))
+	{
+		process_incoming_content_lsa(selfp,info);
+	}
+	
+}
+
+void 
+process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info)
+{
+	printf("process_incoming_content_info called \n");
+	
+	struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	get_nbr(nbr,selfp,info);
+	
+	printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
+		
+
+	const unsigned char *ptr;
+	size_t length;
+	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length);
+	printf("Content data: %s\n",ptr);
+
+	long int interval=atoi((char *)ptr);
+
+
+	update_adjacent_timed_out_zero_to_adl(nbr);	
+	update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
+	update_lsdb_synch_interval_to_adl(nbr,interval);
+	print_adjacent_from_adl();
+
+	if(!nlsr->is_build_adj_lsa_sheduled)
+	{
+		printf("Scheduling Build and Install Adj LSA...\n");
+		nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0);
+		nlsr->is_build_adj_lsa_sheduled=1;		
+	}
+	else
+	{
+		printf("Build and Install Adj LSA already scheduled\n");
+	}
+
+	free(nbr);
+	
+
+}
+
+void 
+process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info)
+{
+	printf("process_incoming_content_lsdb called \n");
+
+	
+	const unsigned char *ptr;
+	size_t length;
+	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length);
+	printf("Content data: %s\n",ptr);
+
+	if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) )
+	{
+		struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+		get_nbr(nbr,selfp,info);
+
+		char *nl;
+		int num_element;
+		int i;
+		char *rem;
+		const char *sep="|";
+		char *orig_router;
+		char *lst;
+		int ls_type;
+		char *lsid;
+		long int ls_id;
+
+		nl=strtok_r((char *)ptr,sep,&rem);
+		num_element=atoi(nl);		
+
+		for(i = 0 ; i < num_element ; i++)
+		{
+			orig_router=strtok_r(NULL,sep,&rem);
+			lst=strtok_r(NULL,sep,&rem);
+			ls_type=atoi(lst);
+			printf("Orig Router: %s ls Type: %d",orig_router,ls_type);			
+
+			if(ls_type == LS_TYPE_NAME)
+			{
+				lsid=strtok_r(NULL,sep,&rem);
+				ls_id=atoi(lsid);
+				printf(" LS Id: %ld\n",ls_id);
+				send_interest_for_name_lsa(nbr,orig_router,lst,lsid);	
+			}
+			else
+			{
+				printf("\n");
+				send_interest_for_adj_lsa(nbr,orig_router,lst);
+			}
+				
+		}
+				
+
+		
+		char *version=get_current_timestamp_micro();
+		printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));		
+		update_adjacent_lsdb_version_to_adl(nbr,version);
+		printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
+		
+		
+
+		free(nbr);	
+	}
+	else if (strcmp("WAIT",(char *)ptr) == 0)
+	{
+		struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+		get_nbr(nbr,selfp,info);
+		long int interval=get_lsdb_synch_interval(nbr->name);
+		adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2);
+		
+
+		free(nbr);
+	}
+	else 
+	{
+		printf("NACK Content Received\n");
+	}
+	
+	
+}
+
+void 
+process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info)
+{
+	printf("process_incoming_content_lsa called \n");
+
+	char *sep="|";
+	char *rem;
+	char *orig_router;
+	char *orl;
+	int orig_router_length;
+	char *lst;
+	int ls_type;
+	char *lsid;
+	long int ls_id;
+	char *isvld;
+	int isValid;
+	char *num_link;
+	int no_link;
+	char *np;
+	char *np_length;
+	int name_length;
+	char *data;
+	char *orig_time;
+
+	const unsigned char *ptr;
+	size_t length;
+	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length);
+	printf("Content data Received: %s\n",ptr);
+
+	printf("LSA Data\n");
+
+	if( strlen((char *) ptr ) > 0 )
+	{
+
+		orig_router=strtok_r((char *)ptr,sep,&rem);
+		orl=strtok_r(NULL,sep,&rem);
+		orig_router_length=atoi(orl);
+
+		printf("	Orig Router Name  : %s\n",orig_router);
+		printf("	Orig Router Length: %d\n",orig_router_length);
+
+		lst=strtok_r(NULL,sep,&rem);		
+		ls_type=atoi(lst);
+
+		printf("	LS Type  : %d\n",ls_type);
+
+		if ( ls_type == LSA_NAME_TYPE )
+		{
+			lsid=strtok_r(NULL,sep,&rem);
+			ls_id=atoi(lsid);
+			isvld=strtok_r(NULL,sep,&rem);
+			isValid=atoi(isvld);
+			np=strtok_r(NULL,sep,&rem);
+			np_length=strtok_r(NULL,sep,&rem);
+			name_length=atoi(np_length);
+
+			printf("	LS ID  : %ld\n",ls_id);
+			printf("	isValid  : %d\n",isValid);
+			printf("	Name Prefix : %s\n",np);
+			printf("	Name Prefix length: %d\n",name_length);
+
+			build_and_install_others_name_lsa(orig_router,ls_type,ls_id,isValid,np);
+				
+		}
+		else if ( ls_type == LSA_ADJ_TYPE )
+		{
+			orig_time=strtok_r(NULL,sep,&rem);
+			num_link=strtok_r(NULL,sep,&rem);
+			no_link=atoi(num_link);
+			data=rem;
+
+			printf("	No Link  : %d\n",no_link);
+			printf("	Data  : %s\n",data);
+
+			build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data);
+		}
+	
+
+	}
+
+}
+
+void
+process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
+{
+	printf("process_incoming_timed_out_interest called \n");
+
+	/*
+	struct ccn_charbuf*c;
+	c=ccn_charbuf_create();
+	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
+	printf("%s\n",ccn_charbuf_as_string(c));
+	ccn_charbuf_destroy(&c);
+	*/
+
+	int res,i;
+	int nlsr_position=0;
+	int name_comps=(int)info->interest_comps->n;
+
+	for(i=0;i<name_comps;i++)
+	{
+		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
+		if( res == 0)
+		{
+			nlsr_position=i;
+			break;
+		}	
+	}
+
+	if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
+	{
+		process_incoming_timed_out_interest_info(selfp,info);
+	}
+}
+
+void
+process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
+{
+	printf("process_incoming_timed_out_interest_info called \n");
+
+	struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	get_nbr(nbr,selfp,info);
+
+	printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
+		
+	
+	update_adjacent_timed_out_to_adl(nbr,1);
+	print_adjacent_from_adl();	
+	int timed_out=get_timed_out_number(nbr);
+	
+
+	if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables 
+	{
+		printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
+		send_info_interest_to_neighbor(nbr);
+	}
+	else
+	{
+		printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);		
+		update_adjacent_status_to_adl(nbr,NBR_DOWN);
+		if(!nlsr->is_build_adj_lsa_sheduled)
+		{
+			nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
+			nlsr->is_build_adj_lsa_sheduled=1;		
+		}
+	}
+
+	free(nbr);
+		
+
+}
+
+int 
+send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+	printf("send_info_interest called \n");
+	printf("\n");
 
 	my_lock();
-	struct ccn_charbuf *name;
-	long int rnum;
-	char rnumstr[20];
-	char info_str[5];
-	char nlsr_str[5];
+
+	int adl_element,i;
+
+	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;
+		send_info_interest_to_neighbor(nbr->neighbor);
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+	my_unlock();
+
+	return 0;
+}
+
+void 
+send_info_interest_to_neighbor(struct name_prefix *nbr)
+{
+	printf("send_info_interest_to_neighbor called \n");
 
 	int res;
-	int scope = 2;  //no further than the next host
+	//int scope = 2;  //no further than the next host
+	
+	char info_str[5];
+	char nlsr_str[5];
+	long int rnum;
+	char rnumstr[20];
 
 	rnum=random();
 	memset(&rnumstr,0,20);
 	sprintf(rnumstr,"%ld",rnum);
+	
 	memset(&nlsr_str,0,5);
 	sprintf(nlsr_str,"nlsr");
 	memset(&info_str,0,5);
 	sprintf(info_str,"info");
 	
-	printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr),nlsr_str,info_str);	
+	
+	struct ccn_charbuf *name;	
 	name=ccn_charbuf_create();
-	res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr));
-	ccn_name_append_str(name,nlsr_str);
-	ccn_name_append_str(name,info_str);
-	//ccn_name_append_str(name,rnumstr);
 
-	/* adding Exclusion filter */
+	char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name->name)+1);
+	memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name->name)+1);
+	memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
+	memcpy(int_name+strlen(int_name),"/",1);
+	memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
+	memcpy(int_name+strlen(int_name),"/",1);
+	memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
+	memcpy(int_name+strlen(int_name),nlsr->router_name->name,strlen(nlsr->router_name->name));
+	
+
+	res=ccn_name_from_uri(name,int_name);
+	if ( res >=0 )
+	{
+		ccn_name_append_str(name,rnumstr);
+
+		/* adding InterestLifeTime and InterestScope filter */
+
+		struct ccn_charbuf *templ;
+		templ = ccn_charbuf_create();
+
+		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
+		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
+		ccn_charbuf_append_closer(templ); /* </Name> */
+		//ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
+		//ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
+		//ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
+		//ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
+		//ccn_charbuf_append_closer(templ); /* </Scope> */
+
+		appendLifetime(templ,nlsr->interest_resend_time);
+		ccn_charbuf_append_closer(templ); /* </Interest> */
+		/* Adding InterestLifeTime and InterestScope filter done */
+	
+		printf("Sending info interest on name prefix : %s \n",int_name);
+
+		res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
+
+		if ( res >= 0 )
+			printf("Info interest sending Successfull .... \n");	
+		ccn_charbuf_destroy(&templ);
+	}
+	ccn_charbuf_destroy(&name);
+	free(int_name);
+
+}
+
+
+int 
+send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+	printf("send_lsdb_interest called \n");	
+
+	my_lock();
+
+	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 == NBR_ACTIVE)
+		{	
+			if(nbr->is_lsdb_send_interest_scheduled == 0)
+			{
+				long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name);	
+				printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);		
+
+				if(time_diff>=get_lsdb_synch_interval(nbr->neighbor->name))
+				{
+					nbr->is_lsdb_send_interest_scheduled=1;
+					send_lsdb_interest_to_nbr(nbr->neighbor);
+				}
+			}
+		}
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+	nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0);
+
+	my_unlock();
+	return 0;
+}
+
+void 
+send_lsdb_interest_to_nbr(struct name_prefix *nbr)
+{
+	printf("send_lsdb_interest_to_nbr called \n");	
+	
+	char *last_lsdb_version=get_nbr_lsdb_version(nbr->name);
+
+	if(last_lsdb_version !=NULL)
+	{
+		printf("Last LSDB Version: %s \n",last_lsdb_version);
+
+
+		struct ccn_charbuf *name;
+		int res;
+		long int rnum;
+		char rnumstr[20];
+		char lsdb_str[5];
+		char nlsr_str[5];
+						
+		rnum=random();
+		memset(&rnumstr,0,20);
+		sprintf(rnumstr,"%ld",rnum);
+		memset(&nlsr_str,0,5);
+		sprintf(nlsr_str,"nlsr");
+		memset(&lsdb_str,0,5);
+		sprintf(lsdb_str,"lsdb");		
+		//make and send interest with exclusion filter as last_lsdb_version
+		printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);	
+		name=ccn_charbuf_create();
+		res=ccn_name_from_uri(name,nbr->name);
+
+		if( res >= 0)
+		{
+			ccn_name_append_str(name,nlsr_str);
+			ccn_name_append_str(name,lsdb_str);
+			ccn_name_append_str(name,rnumstr);
+	
+			/* adding Exclusion filter */
+
+			struct ccn_charbuf *templ;
+			templ = ccn_charbuf_create();
+	
+			struct ccn_charbuf *c;
+			c = ccn_charbuf_create();
+	
+
+			ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
+			ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
+			ccn_charbuf_append_closer(templ); /* </Name> */
+			ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
+			ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
+			ccn_charbuf_reset(c);
+			ccn_charbuf_putf(c, "%s", last_lsdb_version);
+			//ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
+			ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
+			ccn_charbuf_append_closer(templ); /* </Exclude> */
+			ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
+			ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
+			ccn_charbuf_append(templ, "2", 1);
+			ccn_charbuf_append_closer(templ); /* </Scope> */
+	
+			appendLifetime(templ,nlsr->interest_resend_time);
+	
+			ccn_charbuf_append_closer(templ); /* </Interest> */
+	
 		
+			/* Adding Exclusion filter done */
+	
+			res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
+
+			if ( res >= 0 )
+			{
+				printf("Interest sending Successfull .... \n");	
+				update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec());
+
+			}
+			ccn_charbuf_destroy(&c);
+			ccn_charbuf_destroy(&templ);
+		}
+		ccn_charbuf_destroy(&name);
+	}	
+	set_is_lsdb_send_interest_scheduled_to_zero(nbr->name);
+
+}
+
+void 
+send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id)
+{
+	printf("send_interest_for_name_lsa called\n");
+
+	int res;
+	long int rnum;
+	char rnumstr[20];
+	char lsa_str[5];
+	char nlsr_str[5];
+
+						
+	rnum=random();
+	memset(&rnumstr,0,20);
+	sprintf(rnumstr,"%ld",rnum);
+	memset(&nlsr_str,0,5);
+	sprintf(nlsr_str,"nlsr");
+	memset(&lsa_str,0,5);
+	sprintf(lsa_str,"lsa");
+
+	char *int_name=(char *)malloc(nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
+	memset(int_name,0,nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
+
+	memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
+	memcpy(int_name+strlen(int_name),"/",1);
+	memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
+	memcpy(int_name+strlen(int_name),"/",1);
+	memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
+	memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));	
+
+	
+	struct ccn_charbuf *name;	
+	name=ccn_charbuf_create();
+
+
+	res=ccn_name_from_uri(name,int_name);
+	ccn_name_append_str(name,ls_type);
+	ccn_name_append_str(name,ls_id);
+	ccn_name_append_str(name,rnumstr);
+
+
+	/* adding InterestLifeTime and InterestScope filter */
+
 	struct ccn_charbuf *templ;
 	templ = ccn_charbuf_create();
 
-//	struct ccn_charbuf *c;
-//	c = ccn_charbuf_create();
-
-
 	ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
 	ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
 	ccn_charbuf_append_closer(templ); /* </Name> */
-//	ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
-//	ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
-//	ccn_charbuf_reset(c);
-//	//ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
-//	//ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
-//	ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
-//	ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
-//	ccn_charbuf_append_closer(templ); /* </Exclude> */
-	ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
-	appendLifetime(templ,15);
+	//ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
+	ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
+	ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
+	ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
+	ccn_charbuf_append_closer(templ); /* </Scope> */
+
+	appendLifetime(templ,nlsr->interest_resend_time);
 	ccn_charbuf_append_closer(templ); /* </Interest> */
+	/* Adding InterestLifeTime and InterestScope filter done */
+	
+	printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id);
 
-
-	/* Adding Exclusion filter done */
-				
 	res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
-			
+
 	if ( res >= 0 )
-		printf("Interest sending Successfull .... \n");	
-//	ccn_charbuf_destroy(&c);
+		printf("NAME LSA interest sending Successfull .... \n");	
+	
+	//free(lsa_orig_router);	
 	ccn_charbuf_destroy(&templ);
 	ccn_charbuf_destroy(&name);
-
-	my_unlock();
-
+	free(int_name);
+	
+	
 }
+
+void 
+send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type)
+{
+	printf("send_interest_for_adj_lsa called\n");
+
+	int res;
+	long int rnum;
+	char rnumstr[20];
+	char lsa_str[5];
+	char nlsr_str[5];
+
+						
+	rnum=random();
+	memset(&rnumstr,0,20);
+	sprintf(rnumstr,"%ld",rnum);
+	memset(&nlsr_str,0,5);
+	sprintf(nlsr_str,"nlsr");
+	memset(&lsa_str,0,5);
+	sprintf(lsa_str,"lsa");
+
+	char *int_name=(char *)malloc(nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
+	memset(int_name,0,nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
+
+	memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
+	memcpy(int_name+strlen(int_name),"/",1);
+	memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
+	memcpy(int_name+strlen(int_name),"/",1);
+	memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
+	memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
+
+	
+	struct ccn_charbuf *name;	
+	name=ccn_charbuf_create();
+	
+
+	ccn_name_from_uri(name,int_name);
+	ccn_name_append_str(name,ls_type);
+	ccn_name_append_str(name,rnumstr);
+
+	/* adding InterestLifeTime and InterestScope filter */
+
+	struct ccn_charbuf *templ;
+	templ = ccn_charbuf_create();
+
+	ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
+	ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
+	ccn_charbuf_append_closer(templ); /* </Name> */
+	//ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
+	ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
+	ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
+	ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
+	ccn_charbuf_append_closer(templ); /* </Scope> */
+
+	appendLifetime(templ,nlsr->interest_resend_time);
+	ccn_charbuf_append_closer(templ); /* </Interest> */
+	/* Adding InterestLifeTime and InterestScope filter done */
+	
+	printf("Sending ADJ LSA interest on name prefix : %s/%s/%s%s/%s/\n",nbr->name,nlsr_str,lsa_str,orig_router,ls_type);
+
+	res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
+
+	if ( res >= 0 )
+		printf("ADJ LSA interest sending Successfull .... \n");	
+	
+	//free(lsa_orig_router);	
+	ccn_charbuf_destroy(&templ);
+	ccn_charbuf_destroy(&name);
+	free(int_name);
+
+	
+}
+
diff --git a/nlsr_ndn.h b/nlsr_ndn.h
index 4c2a79c..0b6b14c 100644
--- a/nlsr_ndn.h
+++ b/nlsr_ndn.h
@@ -2,27 +2,33 @@
 #define _NLSR_NDN_H_
 
 int appendLifetime(struct ccn_charbuf *cb, int lifetime);
-
-int send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
-
+void get_nbr(struct name_prefix * nbr, struct ccn_closure *selfp, struct ccn_upcall_info *info);
+void get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info);
 enum ccn_upcall_res incoming_interest(struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info);
 void process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info);
-void process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info);
 void process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info);
+void process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info);
+void process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info);
+
+enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info* info);
+
+void process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info);
+void process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info);
+void process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info);
+void process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info);
 
 void process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info);
-void process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info);
 void process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info);
 
 
-enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info* info);
-void process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info);
-void process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info);
-void process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info);
-
-
 int send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
-void send_info_interest_to_neighbor(struct ccn_charbuf *nbr);
+void send_info_interest_to_neighbor(struct name_prefix *nbr);
+
+int send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
+void send_lsdb_interest_to_nbr(struct name_prefix *nbr);
+
+void send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id);
+void send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type);
 
 #endif
 
diff --git a/utility.c b/utility.c
index 283376d..7ebc72d 100644
--- a/utility.c
+++ b/utility.c
@@ -10,6 +10,13 @@
 #include <config.h>
 #endif
 
+#include <ccn/ccn.h>
+#include <ccn/uri.h>
+#include <ccn/keystore.h>
+#include <ccn/signing.h>
+#include <ccn/schedule.h>
+#include <ccn/hashtb.h>
+
 #include "utility.h"
 
 
@@ -81,3 +88,18 @@
 	return microSec;
 
 }
+
+char *
+get_current_timestamp_micro(void)
+{
+	struct timeval now; 
+	gettimeofday(&now, NULL);
+
+	char *microSec=(char *)malloc(20);
+	sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec);
+	microSec[strlen(microSec)]='\0';
+
+	return microSec;
+
+}
+
diff --git a/utility.h b/utility.h
index b068d1a..4b67bbd 100644
--- a/utility.h
+++ b/utility.h
@@ -7,4 +7,6 @@
 long int get_current_time_sec(void);
 long int get_current_time_microsec(void);
 
+char * get_current_timestamp_micro(void);
+
 #endif