Fresh Rewritten Copy
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index 39a0322..29c7440 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -18,24 +18,53 @@
 #include <ccn/hashtb.h>
 
 #include "nlsr.h"
+#include "nlsr_ndn.h"
 #include "nlsr_lsdb.h"
 #include "utility.h"
-#include "nlsr_ndn.h"
+#include "nlsr_npl.h"
 #include "nlsr_adl.h"
 
 void
 set_new_lsdb_version(void)
 {
 	
-	char *time_stamp=get_current_timestamp_micro();
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
 	
-	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);
+	free(nlsr->lsdb->lsdb_version);
+	nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
+	memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
+	memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
+
+	free(time_stamp);
 	
 }
 
+void 
+make_name_lsa_key(char *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);
+	
+	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);
+	
+}
 
 void 
 build_and_install_name_lsas(void)
@@ -56,8 +85,13 @@
 		np=e->data;
 		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);
+		free(name_lsa->header->orig_router->name);
+		free(name_lsa->header->orig_router);
+		free(name_lsa->header);
+		free(name_lsa->name_prefix->name);
+		free(name_lsa->name_prefix);
 		free(name_lsa);
 		hashtb_next(e);		
 	}
@@ -66,72 +100,28 @@
 
 }
 
-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();
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
 
-	name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
+	name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free 
 	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);
+	
+	free(time_stamp);
 
 	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->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
+	memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
+	memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
+	name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
 	name_lsa->header->isValid=1;
 
 	
@@ -142,37 +132,27 @@
 
 }
 
-
-void 
-print_name_lsa(struct nlsa *name_lsa)
-{
-	printf("print_name_lsa called \n");
-	
-	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	 :	%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",name_lsa->name_prefix->name);
-	printf("		Name Prefix Length	:	%d\n",name_lsa->name_prefix->length);
-
-	printf("\n");	
-}
-
 void 
 install_name_lsa(struct nlsa *name_lsa)
 {
-	printf("install_name_lsa called \n");
 	
-	print_name_lsa(name_lsa);
+	char lst[2];
+	memset(lst,0,2);
+	sprintf(lst,"%d",name_lsa->header->ls_type);	
 
-	char *key=make_name_lsa_key(name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);	
+	char lsid[10];
+	memset(lsid,0,10);
+	sprintf(lsid,"%ld",name_lsa->header->ls_id);
+	
+	
+	char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
+	memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
+
+
+	make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);	
 	printf("Key:%s Length:%d\n",key,(int)strlen(key));
 
-	struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
+	struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
 
 	struct hashtb_enumerator ee;
     	struct hashtb_enumerator *e = &ee; 	
@@ -186,32 +166,31 @@
 		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=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
 		new_name_lsa->header->ls_type=name_lsa->header->ls_type;
 
 		new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
+		memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
 		memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
 
-		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=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
 		new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
 		memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
 		new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
 		new_name_lsa->header->isValid=name_lsa->header->isValid;
 
 	
-		new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+		new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
 		new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
 		memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
 		new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
 
 		printf("New Name LSA Added....\n");	
 
-		printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version);
+		printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
 		set_new_lsdb_version();	
-		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);		
+		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);		
 
 	}
 	else if(res == HT_OLD_ENTRY)
@@ -221,37 +200,27 @@
 	}
 
     	hashtb_end(e);
+
+	free(key);
 }
 
 
-char *
-make_name_lsa_key(char *orig_router, int ls_type, long int ls_id)
+void 
+print_name_lsa(struct nlsa *name_lsa)
 {
 	
-	
-	printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
+	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	 :	%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",name_lsa->name_prefix->name);
+	printf("		Name Prefix Length	:	%d\n",name_lsa->name_prefix->length);
 
-	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;
-	
+	printf("\n");	
 }
 
 void
@@ -280,138 +249,53 @@
 	printf("\n");
 }
 
-int
-build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+
+void
+build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
 {
-	printf("build_and_install_adj_lsa called \n");
-	my_lock();
+	printf("build_and_install_others_name_lsa called \n");
 
-	printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
+	struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
+	build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
+	print_name_lsa(name_lsa);
+	install_name_lsa(name_lsa);
+	print_name_lsdb();
 
-	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);
+	free(name_lsa->header->orig_router->name);
+	free(name_lsa->header->orig_router);
+	free(name_lsa->header);
+	free(name_lsa->name_prefix->name);
+	free(name_lsa->name_prefix);
+	free(name_lsa);
 	
 }
 
 void
-build_adj_lsa(struct alsa * adj_lsa)
+build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
 {
-	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;	
+	printf("build_others_name_lsa called \n");
 
-	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';
+	name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
+	name_lsa->header->ls_type=LS_TYPE_NAME;
 
-	printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length);
+	name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
+	memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
+	memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
 
-	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);
+	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;
 
-	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);
+	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;
 }
 
 
@@ -426,6 +310,131 @@
 	key[strlen(key)]='\0';
 }
 
+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");
+
+	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);
+			install_adj_lsa(adj_lsa);
+
+			free(adj_lsa->header->orig_router->name);
+			free(adj_lsa->header->orig_router);
+			free(adj_lsa->header->orig_time);
+			free(adj_lsa->header);
+			free(adj_lsa->body);
+			free(adj_lsa);
+			nlsr->adj_build_flag=0;	
+			print_adj_lsdb();		
+		}
+		else
+		{
+			printf("Can not build adj LSA now\n");
+		}
+	}
+	nlsr->is_build_adj_lsa_sheduled=0;
+	return 0;
+}
+
+
+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->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
+	memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
+	memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
+	adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
+
+	adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;	
+
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+
+	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);	
+	free(time_stamp);
+
+
+	/* Filling Up Body Data */
+
+	adj_lsa->no_link=no_link;
+/*
+	struct link *templ=(struct link *)malloc(2*sizeof(struct link));
+	adj_lsa->links=templ;
+
+	int i, adl_element;
+	struct ndn_neighbor *nbr;
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	hashtb_start(nlsr->adl, e);
+	adl_element=hashtb_n(nlsr->adl);
+
+	for(i=0;i<adl_element;i++)
+	{
+		nbr=e->data;
+		if( nbr->status	== 1 )
+		{
+			struct link *temp=(struct link *)malloc(sizeof(struct link));
+			temp->nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix));
+			temp->nbr->name=(char *)malloc(nbr->neighbor->length);
+			memset(temp->nbr->name,0,nbr->neighbor->length);		
+			memcpy(temp->nbr->name,nbr->neighbor->name,nbr->neighbor->length);
+
+			temp->nbr->length=nbr->neighbor->length;
+			temp->face=nbr->face;
+			temp->metric=nbr->metric;
+
+			templ=temp;
+			templ++;
+		}	
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+*/
+
+
+	struct ccn_charbuf *c=ccn_charbuf_create();
+	get_active_nbr_adj_data(c);
+	char *data=ccn_charbuf_as_string(c);
+
+	adj_lsa->body=(char *)malloc(strlen(data)+1);
+	memset(adj_lsa->body,0,strlen(data)+1);
+	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++;
+
+
+}
+
+
 void
 install_adj_lsa(struct alsa * adj_lsa)
 {
@@ -435,7 +444,7 @@
 	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;
@@ -445,7 +454,7 @@
    	hashtb_start(nlsr->lsdb->adj_lsdb, e);
     	res = hashtb_seek(e, key, strlen(key), 0);
 
-	
+
 
 	if(res == HT_NEW_ENTRY )
 	{
@@ -461,17 +470,17 @@
 		new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
 		memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
 		new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
-	
-		new_adj_lsa->no_link=adj_lsa->no_link;
 
+		new_adj_lsa->no_link=adj_lsa->no_link;
+		
 		new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
 		memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
 		memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
 
-		printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version);
+		printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
 		set_new_lsdb_version();	
-		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
-		
+		printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+
 
 	}
 	else if(res == HT_OLD_ENTRY)
@@ -488,24 +497,23 @@
 			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->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);
+			printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
 			set_new_lsdb_version();	
-			printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
+			printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
 
 		}
 
 	}
 
     	hashtb_end(e);
-	
+
 	free(key);
 }
 
@@ -523,9 +531,6 @@
 	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);
@@ -538,7 +543,7 @@
 		printf("		Neighbor Length		 : %s	\n",length);
 		printf("		Connecting Face		 : %s	\n",face);
 		printf("		Metric			 : %s	\n",metric);
-		
+
 
 		for(i=1;i<no_link;i++)
 		{
@@ -561,18 +566,34 @@
 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);
+	printf("	Lsa Data:\n");
+	printf("		No of Link	: %d\n",adj_lsa->no_link);
 
 	print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
-	
 
+/*
+	struct link *templ=adj_lsa->links;
+	int i;
+	
+	for(i=0 ; i< adj_lsa->no_link ; i++)
+	{
+		printf("		Link %d	 	\n",i+1);
+		printf("		Neighbor		 : %s	\n",templ->nbr->name);
+		printf("		Neighbor Length		 : %d	\n",templ->nbr->length);
+		printf("		Connecting Face		 : %d	\n",templ->face);
+		printf("		Metric			 : %d	\n",templ->metric);		
+
+		templ++;
+	}
+*/
 	printf("\n");
 
 }
@@ -601,319 +622,60 @@
 	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)
+build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data)
 {
-	printf("get_name_lsa_data called \n");
+	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);
+	
 
-	struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
+	free(adj_lsa->header->orig_router->name);
+	free(adj_lsa->header->orig_router);
+	free(adj_lsa->header->orig_time);
+	free(adj_lsa->header);
+	free(adj_lsa->body);
+	free(adj_lsa);
 
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee; 	
-    	int res;
+	print_adj_lsdb();
 
-   	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)
+build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data)
 {
-	printf("get_adj_lsa_data called \n");
+	printf("build_others_adj_lsa called \n");
 
-	struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
+	/*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);
 
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee; 	
-    	int res;
+	adj_lsa->header->orig_router->length=strlen(orig_router)+1;
 
-   	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,"|");
+	adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;	
 
-		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,"|");
+	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);
 
-		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,"|");
+	adj_lsa->no_link=no_link;
 
-		ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
-		ccn_charbuf_append_string(lsa_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);
 
-		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)
 {
@@ -945,3 +707,332 @@
 
 	return num_element; 
 }
+
+void 
+get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
+{
+	printf("get_name_lsdb_summary called \n");	
+	int i, name_lsdb_element;
+
+	struct nlsa *name_lsa;
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+    	hashtb_start(nlsr->lsdb->name_lsdb, e);
+	name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
+
+	for(i=0;i<name_lsdb_element;i++)
+	{
+		name_lsa=e->data;
+
+		ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name);
+		ccn_charbuf_append_string(name_lsdb_data,"|");
+
+		char *lst=(char *)malloc(20);
+		memset(lst,0,20);
+		sprintf(lst,"%d",name_lsa->header->ls_type);
+		ccn_charbuf_append_string(name_lsdb_data,lst);
+		free(lst);
+		ccn_charbuf_append_string(name_lsdb_data,"|");
+
+		char *lsid=(char *)malloc(20);
+		memset(lsid,0,20);
+		sprintf(lsid,"%ld",name_lsa->header->ls_id);
+		ccn_charbuf_append_string(name_lsdb_data,lsid);
+		free(lsid);
+		ccn_charbuf_append_string(name_lsdb_data,"|");
+
+		ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time);
+		ccn_charbuf_append_string(name_lsdb_data,"|");
+
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+}
+
+
+void 
+get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data)
+{
+	printf("get_adj_lsdb_summary 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++)
+	{
+		adj_lsa=e->data;
+
+		ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name);
+		ccn_charbuf_append_string(adj_lsdb_data,"|");
+		
+		char *lst=(char *)malloc(20);
+		memset(lst,0,20);
+		sprintf(lst,"%d",adj_lsa->header->ls_type);
+		ccn_charbuf_append_string(adj_lsdb_data,lst);
+		free(lst);
+		ccn_charbuf_append_string(adj_lsdb_data,"|");
+
+		ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time);
+		ccn_charbuf_append_string(adj_lsdb_data,"|");
+
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+}
+
+
+void 
+get_lsdb_summary(struct ccn_charbuf *lsdb_data)
+{
+	struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create();
+	struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create();
+
+	get_name_lsdb_summary(name_lsdb_data);
+	get_adj_lsdb_summary(adj_lsdb_data);
+
+	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);
+
+	if( num_lsa > 0)
+	{
+		ccn_charbuf_append_string(lsdb_data,num_element);
+		ccn_charbuf_append_string(lsdb_data,"|");
+	}
+	if(name_lsdb_data->length>0)
+	{
+		char *data1=ccn_charbuf_as_string(name_lsdb_data);
+		ccn_charbuf_append_string(lsdb_data,(char *)data1);
+	}
+	if(adj_lsdb_data->length>0)
+	{
+		char *data2=ccn_charbuf_as_string(adj_lsdb_data);
+		ccn_charbuf_append_string(lsdb_data,(char *)data2);
+	}
+	ccn_charbuf_destroy(&name_lsdb_data);
+	ccn_charbuf_destroy(&adj_lsdb_data);
+	free(num_element);
+
+}
+
+int 
+check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
+{
+	int ret=0;
+	struct ccn_charbuf *key=ccn_charbuf_create();
+	ccn_charbuf_append_string(key,orig_router);
+	ccn_charbuf_append_string(key,"/");
+	ccn_charbuf_append_string(key,lst);
+	ccn_charbuf_append_string(key,"/");
+	ccn_charbuf_append_string(key,lsid);
+
+	int res;
+	struct nlsa *name_lsa;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	hashtb_start(nlsr->lsdb->name_lsdb, e);
+	res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
+
+	if( res == HT_NEW_ENTRY )
+	{
+		hashtb_delete(e);
+		ret=1;
+
+	}
+	else if(res == HT_OLD_ENTRY)
+	{
+		name_lsa=e->data;
+		if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
+		{
+			ret=1;
+		}
+	}
+
+	hashtb_end(e);
+
+	ccn_charbuf_destroy(&key);
+	
+	return ret;
+}
+
+int 
+check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
+{
+	int ret=0;
+	struct ccn_charbuf *key=ccn_charbuf_create();
+	ccn_charbuf_append_string(key,orig_router);
+	ccn_charbuf_append_string(key,"/");
+	ccn_charbuf_append_string(key,lst);
+
+	int res;
+	struct alsa *adj_lsa;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	hashtb_start(nlsr->lsdb->adj_lsdb, e);
+	res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
+
+	if( res == HT_NEW_ENTRY )
+	{
+		hashtb_delete(e);
+		ret=1;
+
+	}
+	else if(res == HT_OLD_ENTRY)
+	{
+		adj_lsa=e->data;
+		if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
+		{
+			ret=1;
+		}
+	}
+
+	hashtb_end(e);
+	
+	ccn_charbuf_destroy(&key);
+
+	return ret;
+}
+
+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,"|");
+
+		ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
+		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);
+}