Adding, disseminating and Gathering Cor LSA
diff --git a/nlsr-sync-0.0/macbook.conf b/nlsr-sync-0.0/macbook.conf
index c64b1da..73c7014 100755
--- a/nlsr-sync-0.0/macbook.conf
+++ b/nlsr-sync-0.0/macbook.conf
@@ -1,6 +1,7 @@
 #----configuration file for macbook----------
 #
 router-name /ndn/memphis.edu/netlab/macbook
+hyperbolic-cordinate 1234.0 0.875
 ccnneighbor /ndn/memphis.edu/cs/maia
 ccnneighbor /ndn/memphis.edu/cs/mira
 ccnneighbor /ndn/memphis.edu/cs/castor
diff --git a/nlsr-sync-0.0/nlsr.c b/nlsr-sync-0.0/nlsr.c
index 5266d2a..c65eccd 100755
--- a/nlsr-sync-0.0/nlsr.c
+++ b/nlsr-sync-0.0/nlsr.c
@@ -552,13 +552,10 @@
 			topo_prefix[strlen(topo_prefix)-1]='\0';
 
 		nlsr->topo_prefix=(char *)malloc(strlen(topo_prefix)+1);
-		//nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1, sizeof(char));
 		memset(nlsr->topo_prefix,0,strlen(topo_prefix)+1);
 		puts(topo_prefix);
 		memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix));
 
-		//printf(" Topo Prefix: %s \n",nlsr->topo_prefix);
-
 	}
 }
 
@@ -591,8 +588,6 @@
 		nlsr->slice_prefix=(char *)malloc(strlen(slice_prefix)+1);
 		memset(nlsr->slice_prefix,0,strlen(slice_prefix)+1);
 		memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix));
-
-		//printf(" Slice Prefix: %s \n",nlsr->slice_prefix);
 	}
 }
 
@@ -621,6 +616,39 @@
 	}
 }
 
+void
+process_command_hyperbolic_cordinate(char *command)
+{
+	if(command==NULL)
+	{
+		printf(" Wrong Command Format ( hyperbolic r 0 )\n");
+		return;
+	}
+
+	char *rem;
+	const char *sep=" \t\n\r";
+	char *radious;
+	char *theta;
+
+	radious=strtok_r(command,sep,&rem);
+	if (radious == NULL )
+	{
+		printf(" Wrong Command Format ( hyperbolic r 0 )\n");
+		return;
+	}
+
+	theta=strtok_r(NULL,sep,&rem);
+	if (theta == NULL )
+	{
+		printf(" Wrong Command Format ( hyperbolic r 0 )\n");
+		return;
+	}
+
+	nlsr->cor_r=strtof(radious,NULL);
+	nlsr->cor_theta=strtof(theta,NULL);
+
+}
+
 void 
 process_conf_command(char *command)
 {
@@ -689,6 +717,10 @@
 	{
 			process_command_slice_prefix(remainder);
 	}
+	else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
+	{
+		process_command_hyperbolic_cordinate(remainder);
+	}
 	else 
 	{
 		printf("Wrong configuration Command %s \n",cmd_type);
@@ -744,7 +776,6 @@
 		int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name, (const char *)nbr->ip_address, 9695);
 		update_face_to_adl_for_nbr(nbr->neighbor->name, face_id);		
 		add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id);
-		//add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_REG, face_id);
 		hashtb_next(e);		
 	}
 
@@ -766,9 +797,12 @@
 
 	for(i=0;i<adl_element;i++)
 	{
-		nbr=e->data;	
-		add_delete_ccn_face_by_face_id(nlsr->ccn,(const char *)nbr->neighbor->name,OP_UNREG,nbr->face);	
-		add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face);
+		nbr=e->data;
+		if ( nbr->face > 0 )
+		{	
+			add_delete_ccn_face_by_face_id(nlsr->ccn,(const char *)nbr->neighbor->name,OP_UNREG,nbr->face);	
+			add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face);
+		}
 		hashtb_next(e);		
 	}
 
@@ -992,7 +1026,7 @@
 	hashtb_destroy(&nlsr->lsdb->adj_lsdb);
 	hashtb_destroy(&nlsr->pit_alsa);
 
-	//To Do: has to destroy the face_list one by one 	
+		
 
 	hashtb_destroy(&nlsr->routing_table);
 
@@ -1058,7 +1092,6 @@
        	}
 
 	server_address.sin_family = AF_INET;
-	//server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
 	server_address.sin_addr.s_addr = INADDR_ANY;
 	server_address.sin_port = htons(nlsr->api_port);
 
@@ -1113,13 +1146,15 @@
 	memset(time_stamp,0,20);
 	get_current_timestamp_micro(time_stamp);
 	nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
-	memset(nlsr->lsdb->lsdb_version,'0',strlen(time_stamp));
+	memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp));
 	free(time_stamp);
 	
 	struct hashtb_param param_adj_lsdb = {0};
 	nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), &param_adj_lsdb);
 	struct hashtb_param param_name_lsdb = {0};
 	nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), &param_name_lsdb);
+	struct hashtb_param param_cor_lsdb = {0};
+	nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), &param_cor_lsdb);
 	
 	
 
@@ -1154,6 +1189,8 @@
 	memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA"));
 
 	nlsr->is_hyperbolic_calc=0;
+	nlsr->cor_r=-1.0;
+	nlsr->cor_theta=-1.0;
 
 	return 0;
 }
@@ -1196,6 +1233,11 @@
 
 	readConfigFile(config_file);
 
+	if ( nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0 ) 	
+	{
+		fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
+		ON_ERROR_DESTROY(-1);
+	}
 	print_adjacent_from_adl();
 
 	if ( daemon_mode == 1 )
@@ -1256,7 +1298,10 @@
 	print_name_prefix_from_npl();
 	print_adjacent_from_adl();
 	build_and_install_name_lsas();
-	print_name_lsdb();	
+	print_name_lsdb();
+
+	build_and_install_cor_lsa();
+	//print_cor_lsdb();	
 
 	sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
 
diff --git a/nlsr-sync-0.0/nlsr.h b/nlsr-sync-0.0/nlsr.h
index e9d83d0..1155688 100755
--- a/nlsr-sync-0.0/nlsr.h
+++ b/nlsr-sync-0.0/nlsr.h
@@ -29,6 +29,8 @@
 {
 	struct hashtb *name_lsdb;
 	struct hashtb *adj_lsdb;
+	struct hashtb *cor_lsdb;
+	
 	char *lsdb_version;
 };
 
@@ -101,6 +103,9 @@
 	char *slice_prefix;
 
 	int is_hyperbolic_calc;
+	double cor_r;
+	double cor_theta;
+	
 	
 };
 
diff --git a/nlsr-sync-0.0/nlsr_lsdb.c b/nlsr-sync-0.0/nlsr_lsdb.c
index d7a3068..f018675 100755
--- a/nlsr-sync-0.0/nlsr_lsdb.c
+++ b/nlsr-sync-0.0/nlsr_lsdb.c
@@ -86,6 +86,16 @@
 }
 
 void 
+make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type, char *orig_time,char *slice_prefix)
+{
+		
+	sprintf(key,"%s/%d/%s%s",slice_prefix,ls_type, orig_time, orig_router);	
+
+	if ( nlsr->debugging )
+		printf("Cor LSA prefix for repo content:%s\n",key);	
+}
+
+void 
 build_and_install_name_lsas(void)
 {
 	if ( nlsr->debugging )
@@ -611,6 +621,16 @@
 }
 
 
+void 
+make_cor_lsa_key(char *key,struct clsa *cor_lsa)
+{
+	memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
+	memcpy(key+strlen(key),"/",1);
+	char ls_type[2];
+	sprintf(ls_type,"%d",cor_lsa->header->ls_type);
+	memcpy(key+strlen(key),ls_type,strlen(ls_type));
+	key[strlen(key)]='\0';
+}
 
 
 void 
@@ -1168,133 +1188,6 @@
 	return num_element; 
 }
 
-/*
-void 
-get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
-{
-	if ( nlsr->debugging )
-		printf("get_name_lsdb_summary called  \n");	
-	if ( nlsr->detailed_logging )
-		writeLogg(__FILE__,__FUNCTION__,__LINE__,"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)
-{
-	if ( nlsr->debugging )
-		printf("get_adj_lsdb_summary called  \n");	
-	if ( nlsr->detailed_logging )
-		writeLogg(__FILE__,__FUNCTION__,__LINE__,"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)
@@ -1378,6 +1271,46 @@
 	return ret;
 }
 
+int 
+check_is_new_cor_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 clsa *cor_lsa;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+
+	hashtb_start(nlsr->lsdb->cor_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)
+	{
+		cor_lsa=e->data;
+		if( strcmp ( orig_time , cor_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)
 {
@@ -2102,3 +2035,304 @@
 	
 
 }
+
+void
+print_cor_lsa(struct clsa *cor_lsa)
+{
+	if ( nlsr->debugging )
+	{
+		printf("-----------Cor LSA Content---------------\n");
+		printf("	Origination Router       :	%s\n",cor_lsa->header->orig_router->name);
+		printf("	Origination Router Length:	%d\n",cor_lsa->header->orig_router->length);
+		printf("	LS Type			 :	%d\n",cor_lsa->header->ls_type);
+		printf("	Origination Time	 :	%s\n",cor_lsa->header->orig_time);
+		printf("	LSA Data			\n");
+		printf("		Cor R:	 	:	%f\n",cor_lsa->cor_r);
+		printf("		Cor Theta	:	%f\n",cor_lsa->cor_theta);
+
+		printf("\n");	
+	}
+}
+
+void 
+print_cor_lsdb()
+{
+	
+	if ( nlsr->debugging )
+		printf("print_cor_lsdb called \n");	
+	
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+	int i=1;
+
+	for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e)) 
+	{
+		if ( nlsr->debugging )
+			printf("-----------Cor LSA (%d)---------------\n",i);	
+		struct clsa *cor_lsa=e->data;
+		print_cor_lsa(cor_lsa);
+		i++;
+  	}
+	hashtb_end(e);
+
+	if ( nlsr->debugging )
+		printf("\n");
+	if ( nlsr->detailed_logging )
+		writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
+}
+
+void
+install_cor_lsa(struct clsa *cor_lsa)
+{
+	if ( nlsr->debugging )
+		printf("install_cor_lsa called \n");
+	if ( nlsr->detailed_logging )
+		writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called  \n");
+	
+
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+
+
+	char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2);
+	memset(key,0,cor_lsa->header->orig_router->length+2);
+	make_cor_lsa_key(key,cor_lsa);
+
+	if ( nlsr->debugging )
+		printf("Cor LSA key: %s \n",key);
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    	int res;
+
+   	hashtb_start(nlsr->lsdb->cor_lsdb, e);
+    	res = hashtb_seek(e, key, strlen(key), 0);
+
+	if ( res == HT_NEW_ENTRY )
+	{
+		if ( nlsr->debugging )
+			printf("New Cor LSA... \n");
+		
+		struct clsa *new_cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
+		new_cor_lsa=e->data;
+		new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+
+		new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+		new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
+		memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
+		memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
+		new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
+
+		new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free 
+		memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
+		memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
+
+		new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
+
+		new_cor_lsa->cor_r=cor_lsa->cor_r;
+		new_cor_lsa->cor_theta=cor_lsa->cor_theta;
+	}
+	else if ( res == HT_OLD_ENTRY )
+	{	
+		if ( nlsr->debugging )
+			printf("Cor LSA exists (Old)... \n");
+	}
+	hashtb_end(e);
+
+	free(key);
+
+}
+
+void 
+build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
+{
+	cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+	cor_lsa->header->ls_type=LS_TYPE_COR;
+
+	char *time_stamp=(char *)malloc(20);
+	memset(time_stamp,0,20);
+	get_current_timestamp_micro(time_stamp);
+
+	cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free 
+	memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
+	memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
+	free(time_stamp);
+
+	cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	cor_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
+	memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
+	memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
+	cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
+
+	cor_lsa->cor_r=cor_r;	
+	cor_lsa->cor_theta=cor_theta;
+
+}
+
+void 
+build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
+{
+	cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+	cor_lsa->header->ls_type=ls_type;
+
+	cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); 
+	memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
+	memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
+
+	cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+	cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
+	memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
+	memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
+	cor_lsa->header->orig_router->length=strlen(orig_router)+1;
+
+	cor_lsa->cor_r=cor_r;	
+	cor_lsa->cor_theta=cor_theta;
+
+}
+
+void
+build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
+{
+	struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
+	build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
+	install_cor_lsa(cor_lsa);
+
+	print_cor_lsdb();
+
+	free(cor_lsa->header->orig_router);
+	free(cor_lsa->header->orig_time);
+	free(cor_lsa->header);
+	free(cor_lsa);
+
+}
+
+
+void 
+build_and_install_cor_lsa()
+{
+
+	struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
+	
+	build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
+	install_cor_lsa(cor_lsa);
+
+	write_cor_lsa_to_repo(cor_lsa);
+
+	print_cor_lsdb();	
+
+	free(cor_lsa->header->orig_router);
+	free(cor_lsa->header->orig_time);
+	free(cor_lsa->header);
+	free(cor_lsa);
+	
+}
+
+void 
+get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
+{
+	if ( nlsr->debugging )
+		printf("get_cor_lsa_data called  \n");	
+	if ( nlsr->detailed_logging )
+		writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called  \n");
+
+	struct clsa *cor_lsa=(struct clsa*)malloc(sizeof(struct clsa ));
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    	int res;
+
+   	hashtb_start(nlsr->lsdb->cor_lsdb, e);
+    	res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
+
+	if( res == HT_OLD_ENTRY )
+	{
+		cor_lsa=e->data;
+
+		if ( nlsr->debugging )
+			printf("Cor LSA found  \n");	
+		if ( nlsr->detailed_logging )
+			writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found  \n");
+
+		ccn_charbuf_append_string(lsa_data,cor_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",cor_lsa->header->orig_router->length);
+		ccn_charbuf_append_string(lsa_data,temp_length);
+		ccn_charbuf_append_string(lsa_data,"|");
+		free(temp_length);
+
+		char *temp_ltype=(char *)malloc(20);
+		memset(temp_ltype,0,20);
+		sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
+		ccn_charbuf_append_string(lsa_data,temp_ltype);
+		ccn_charbuf_append_string(lsa_data,"|");
+		free(temp_ltype);
+
+		ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
+		ccn_charbuf_append_string(lsa_data,"|");
+
+		char *cor_r=(char *)malloc(20);
+		memset(cor_r,0,20);
+		sprintf(cor_r,"%f",cor_lsa->cor_r);
+		ccn_charbuf_append_string(lsa_data,cor_r);
+		ccn_charbuf_append_string(lsa_data,"|");
+		free(cor_r);
+
+		char *cor_theta=(char *)malloc(20);
+		memset(cor_theta,0,20);
+		sprintf(cor_theta,"%f",cor_lsa->cor_theta);
+		ccn_charbuf_append_string(lsa_data,cor_theta);
+		ccn_charbuf_append_string(lsa_data,"|");
+		free(cor_theta);
+
+	}
+	else if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+
+	hashtb_end(e);
+}
+
+void
+write_cor_lsa_to_repo(struct clsa *cor_lsa)
+{
+	
+
+	if ( nlsr->debugging )
+		printf("write_cor_lsa_to_repo called\n");
+	
+	
+	char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2);
+	memset(key,0,cor_lsa->header->orig_router->length+2);
+	make_cor_lsa_key(key,cor_lsa);
+	
+	struct ccn_charbuf *lsa_data=ccn_charbuf_create();
+	get_cor_lsa_data(lsa_data,key);
+	
+	if ( nlsr->debugging )
+		printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));	
+	char *lst=(char *)malloc(20);
+	memset(lst,0,20);
+	sprintf(lst,"%d",cor_lsa->header->ls_type);
+	char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5);
+	memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5);	
+	make_cor_lsa_prefix_for_repo(repo_key, cor_lsa->header->orig_router->name,LS_TYPE_COR,cor_lsa->header->orig_time,nlsr->slice_prefix);
+		
+	if ( nlsr->debugging )
+		printf("Cor LSA Repo Key: %s \n",repo_key);	
+
+	write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
+
+	
+		
+	free(lst);
+	free(key);
+	free(repo_key);
+	ccn_charbuf_destroy(&lsa_data);
+}
+
diff --git a/nlsr-sync-0.0/nlsr_lsdb.h b/nlsr-sync-0.0/nlsr_lsdb.h
index 8944802..420e178 100755
--- a/nlsr-sync-0.0/nlsr_lsdb.h
+++ b/nlsr-sync-0.0/nlsr_lsdb.h
@@ -3,6 +3,7 @@
 
 #define LS_TYPE_ADJ 1
 #define LS_TYPE_NAME 2
+#define LS_TYPE_COR 3
 
 struct link
 {
@@ -44,6 +45,13 @@
 	struct name_prefix *name_prefix;
 };
 
+struct clsa
+{
+	struct alsa_header *header;
+	double cor_r;
+	double cor_theta;
+};
+
 
 void set_new_lsdb_version(void);
 void build_and_install_name_lsas(void);
@@ -74,15 +82,22 @@
 
 int check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time);
 int check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time);
+int check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time);
 
 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);
 
 void make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id);
 
+void build_and_install_cor_lsa();
+void print_cor_lsdb();
+
 void write_name_lsdb_to_repo(char *slice_prefix);
 void write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id);
 void make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type, long int ls_id,char *orig_time,char *slice_prefix);
 void write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id);
 
+void write_cor_lsa_to_repo(struct clsa *cor_lsa);
+void build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta);
+
 #endif
diff --git a/nlsr-sync-0.0/nlsr_ndn.c b/nlsr-sync-0.0/nlsr_ndn.c
index a98c0aa..6ad79d5 100755
--- a/nlsr-sync-0.0/nlsr_ndn.c
+++ b/nlsr-sync-0.0/nlsr_ndn.c
@@ -694,17 +694,20 @@
 		ccn_charbuf_append_closer(templ); /* </Name> */
 		ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
 		ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
+		/* Adding InterestLifeTime and InterestScope filter done */		
 		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);
+		unsigned int face_id=get_next_hop_face_from_adl(nbr->name);
+		ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id);
 		ccn_charbuf_append_closer(templ); /* </Interest> */
-		/* Adding InterestLifeTime and InterestScope filter done */
+		
 	
 		if ( nlsr->debugging )
-			printf("Sending info interest on name prefix : %s \n",int_name);
+			printf("Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id);
 		if ( nlsr->detailed_logging )
-			writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s \n",int_name);
+			writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id);
 
 		res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
 
diff --git a/nlsr-sync-0.0/nlsr_sync.c b/nlsr-sync-0.0/nlsr_sync.c
index c63df07..289cf39 100644
--- a/nlsr-sync-0.0/nlsr_sync.c
+++ b/nlsr-sync-0.0/nlsr_sync.c
@@ -226,7 +226,7 @@
 }
 
 
-//char *
+
 void 
 get_content_by_content_name(char *content_name, unsigned char **content_data)
 {
@@ -312,9 +312,7 @@
 
 
 	if ( nlsr->debugging )
-		printf("process_incoming_sync_content_lsa called \n");
-	//if ( nlsr->detailed_logging )
-		//writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_lsa called \n");	
+		printf("process_incoming_sync_content_lsa called \n");	
 
 	char *sep="|";
 	char *rem;
@@ -391,11 +389,31 @@
 
 			if ( nlsr->debugging )
 			{
+				printf("	Orig Time   : %s\n",orig_time);
 				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);
 		}
+		else if ( ls_type == LS_TYPE_COR )
+		{
+			orig_time=strtok_r(NULL,sep,&rem);
+			char *cor_r=strtok_r(NULL,sep,&rem);
+			char *cor_theta=strtok_r(NULL,sep,&rem);
+
+			double r, theta;
+			r=strtof(cor_r,NULL);
+			theta=strtof(cor_theta,NULL);
+
+			if ( nlsr->debugging )
+			{
+				printf("	Orig Time   : %s\n",orig_time);
+				printf("	Cor R	    : %f\n",r);
+				printf("	Cor Theta   : %f\n",theta);
+			}
+			build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, (double)r, (double)theta);	
+		}
+		
 	}
 }
 
@@ -423,9 +441,6 @@
 
 	struct name_prefix *orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix));
 	
-	//lsa_position=get_lsa_position(content_name, components);
-
-	//printf("LSA Position: %d \n",lsa_position);
 
 	struct ccn_indexbuf cid={0};
     	struct ccn_indexbuf *temp_components=&cid;
@@ -433,13 +448,11 @@
 	ccn_name_from_uri(name,nlsr->slice_prefix);
     	ccn_name_split (name, temp_components);
 	lsa_position=temp_components->n-2;
-	//printf("LSA Position from Slice Prefix Component: %d \n",(int)temp_components->n-2);
     	ccn_charbuf_destroy(&name);
 
 
 	res=ccn_name_comp_get(content_name->buf, components,lsa_position+1,&lst, &comp_size);
 	
-	//printf("Ls Type: %s\n",lst);
 	ls_type=atoi((char *)lst);
 	if(ls_type == LS_TYPE_NAME)
 	{
@@ -451,8 +464,6 @@
 
 		int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
 
-		//printf("Ls ID: %s\nOrig Time: %s\nOrig Router: %s\n",lsid,origtime,orig_router->name);
-
 		if ( (strcmp((char *)orig_router,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time) || (strcmp((char *)orig_router,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) )
 		{
 			int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,(char *)lst,(char *)lsid,(char *)origtime);
@@ -460,7 +471,6 @@
 			{
 				if ( nlsr->debugging )
 					printf("New NAME LSA.....\n");	
-				//content_data=get_content_by_content_name(ccn_charbuf_as_string(uri));
 				get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
 				if ( nlsr->debugging )
 					printf("Content Data: %s \n",content_data);
@@ -470,7 +480,6 @@
 			{
 				if ( nlsr->debugging )
 					printf("Name LSA / Newer Name LSA already xists in LSDB\n");
-				//content_data=get_content_by_content_name(ccn_charbuf_as_string(uri));
 				get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
 				
 				if ( nlsr->debugging )
@@ -492,9 +501,6 @@
 			printf("Orig Time: %s\nOrig Router: %s\n",origtime,orig_router->name);
 
 		int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
-
-		//printf("Ls ID: %s\nOrig Time: %s\nOrig Router: %s\n",lsid,origtime,orig_router->name);
-
 		if ( (strcmp((char *)orig_router,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time) || (strcmp((char *)orig_router,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) )	
 		{
 			int is_new_adj_lsa=check_is_new_adj_lsa(orig_router->name,(char *)lst,(char *)origtime);
@@ -502,7 +508,6 @@
 			{
 				if ( nlsr->debugging )
 					printf("New Adj LSA.....\n");	
-				//content_data=get_content_by_content_name(ccn_charbuf_as_string(uri));
 				get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
 				
 				if ( nlsr->debugging )
@@ -524,6 +529,44 @@
 				printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
 		}
 	}
+	else if(ls_type == LS_TYPE_COR)
+	{
+		res=ccn_name_comp_get(content_name->buf, components,lsa_position+2,&origtime, &comp_size);
+		get_name_part(orig_router,content_name,components,2);
+		
+		if ( nlsr->debugging )
+			printf("Orig Time: %s\nOrig Router: %s\n",origtime,orig_router->name);
+
+		int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
+		if ( (strcmp((char *)orig_router,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time) || (strcmp((char *)orig_router,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) )	
+		{
+			int is_new_cor_lsa=check_is_new_cor_lsa(orig_router->name,(char *)lst,(char *)origtime);
+			if ( is_new_cor_lsa == 1 )
+			{
+				if ( nlsr->debugging )
+					printf("New Cor LSA.....\n");	
+				get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
+				
+				if ( nlsr->debugging )
+					printf("Content Data: %s \n",content_data);
+				process_incoming_sync_content_lsa(content_data);			
+			}
+			else
+			{
+				if ( nlsr->debugging )
+					printf("Cor LSA / Newer Cor LSA already exists in LSDB\n");
+				get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
+				if ( nlsr->debugging )
+					printf("Content Data: %s \n",content_data);
+			}
+		}
+		else 
+		{
+			if ( nlsr->debugging )
+				printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
+		}
+
+	}
 
 	if (content_data != NULL)
 		free(content_data);
@@ -691,7 +734,6 @@
     if (prefix == NULL || topo == NULL || clause == NULL ||
         slice_name == NULL || slice_uri == NULL) {
         fprintf(stderr, "Unable to allocate required memory.\n");
-        //exit(1);
 	return -1;
     }