Removing nlsr-sync folder and Adding marker in Content Name
diff --git a/nlsr.c b/nlsr.c
index f71e4ae..df637b7 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -26,6 +26,8 @@
 #include <ccn/signing.h>
 #include <ccn/schedule.h>
 #include <ccn/hashtb.h>
+#include <ccn/sync.h>
+#include <ccn/seqwriter.h>
 
 #include "nlsr.h"
 #include "nlsr_ndn.h"
@@ -35,6 +37,9 @@
 #include "nlsr_adl.h"
 #include "nlsr_npt.h"
 #include "nlsr_route.h"
+#include "nlsr_sync.h"
+#include "nlsr_face.h"
+#include "nlsr_fib.h"
 
 
 #define ON_ERROR_DESTROY(resval) \
@@ -153,7 +158,12 @@
 	}
 	char *rem;
 	const char *sep=" \t\n";
-	char *rtr_name,*face;
+	char *rtr_name;
+	char *nbr_ip_addr;
+	int is_ip_configured=0;
+	//char *face;
+	char *ip_addr=(char *)malloc(13);
+	memset(ip_addr,0,13);
 
 	rtr_name=strtok_r(command,sep,&rem);
 	if(rtr_name==NULL)
@@ -161,35 +171,41 @@
 		printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
 		return;
 	}
-
-	face=strtok_r(NULL,sep,&rem);
-	if(face==NULL)
-	{
-		printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
-		return;
-	}
-
-	printf("Router: %s face: %s\n",rtr_name,face);
-	int face_id;
-	int res;
-	res=sscanf(face,"face%d",&face_id);
-
-	if(res != 1 )
-	{
-		printf(" Wrong Command Format ( ccnneighbor router_name faceX) where X is integer\n");
-		return;
-	}
 	if ( rtr_name[strlen(rtr_name)-1] == '/' )
 	{
 		rtr_name[strlen(rtr_name)-1]='\0';
 	}
+
+	if (rem != NULL )
+	{
+		nbr_ip_addr=strtok_r(NULL,sep,&rem);
+		is_ip_configured=1;
+	}
 	struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
 	nbr->name=(char *)malloc(strlen(rtr_name)+1);
 	memset(nbr->name,0,strlen(rtr_name)+1);
 	memcpy(nbr->name,rtr_name,strlen(rtr_name)+1);
 	nbr->length=strlen(rtr_name)+1;
 
-	add_nbr_to_adl(nbr,face_id);
+	
+	if ( !is_ip_configured )
+	{
+		struct name_prefix *nbr_name=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+		get_host_name_from_command_string(nbr_name,nbr->name,0);
+		printf("Hostname of neighbor: %s ",nbr_name->name);
+		get_ip_from_hostname_02(nbr_name->name,ip_addr);
+		printf("IP Address: %s \n",ip_addr);
+		free(nbr_name->name);
+		free(nbr_name);
+	}
+	else
+	{
+		memcpy(ip_addr,nbr_ip_addr,strlen(nbr_ip_addr));
+		printf("Name of neighbor: %s ",nbr->name);
+		printf("IP Address: %s \n",ip_addr);
+	}
+	add_nbr_to_adl(nbr,0,ip_addr);
+	
 
 	free(nbr->name);
 	free(nbr);
@@ -262,6 +278,7 @@
 
 }
 
+/*
 void 
 process_command_lsdb_synch_interval(char *command)
 {
@@ -289,7 +306,7 @@
 	}
 
 }
-
+*/
 
 void 
 process_command_interest_retry(char *command)
@@ -368,9 +385,13 @@
 	}
 
 	seconds=atoi(secs);
-	if ( seconds >= 240 && seconds <= 3600 )
+	if ( seconds >= 240)
 	{
 		nlsr->lsa_refresh_time=seconds;
+		if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
+		{
+			nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
+		}
 	}
 
 }
@@ -396,19 +417,23 @@
 	}
 
 	seconds=atoi(secs);
-	if ( seconds >= 360 && seconds <= 5400 )
+	if ( seconds >= 480 )
 	{
 		nlsr->router_dead_interval=seconds;
+		if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
+		{
+			nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
+		}
 	}
 
 }
 
 void 
-process_command_multi_path_face_num(char *command)
+process_command_max_faces_per_prefix(char *command)
 {
 	if(command==NULL)
 	{
-		printf(" Wrong Command Format ( multi-path-face-num n )\n");
+		printf(" Wrong Command Format ( max-faces-per-prefix n )\n");
 		return;
 	}
 	char *rem;
@@ -419,14 +444,14 @@
 	num=strtok_r(command,sep,&rem);
 	if(num==NULL)
 	{
-		printf(" Wrong Command Format ( multi-path-face-num n)\n");
+		printf(" Wrong Command Format ( max-faces-per-prefix n)\n");
 		return;
 	}
 
 	number=atoi(num);
 	if ( number >= 0 && number <= 60 )
 	{
-		nlsr->multi_path_face_num=number;
+		nlsr->max_faces_per_prefix=number;
 	}
 
 }
@@ -505,6 +530,159 @@
 	}
 }
 
+
+void 
+process_command_topo_prefix(char *command)
+{
+	if(command==NULL)
+	{
+		printf(" Wrong Command Format ( topo-prefix )\n");
+		return;
+	}
+	char *rem;
+	const char *sep=" \t\n";
+	char *topo_prefix;
+
+	topo_prefix=strtok_r(command,sep,&rem);
+	if(topo_prefix==NULL)
+	{
+		printf(" Wrong Command Format (  topo-prefix /name/prefix  )\n");
+		return;
+	}
+	else
+	{
+		if( nlsr->topo_prefix != NULL)	
+			free(nlsr->topo_prefix);
+		if ( topo_prefix[strlen(topo_prefix)-1] == '/' )
+			topo_prefix[strlen(topo_prefix)-1]='\0';
+
+		nlsr->topo_prefix=(char *)malloc(strlen(topo_prefix)+1);
+		memset(nlsr->topo_prefix,0,strlen(topo_prefix)+1);
+		puts(topo_prefix);
+		memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix));
+
+	}
+}
+
+
+void 
+process_command_slice_prefix(char *command)
+{
+	if(command==NULL)
+	{
+		printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
+		return;
+	}
+	char *rem;
+	const char *sep=" \t\n";
+	char *slice_prefix;
+
+	slice_prefix=strtok_r(command,sep,&rem);
+	if(slice_prefix==NULL)
+	{
+		printf(" Wrong Command Format (  slice-prefix /name/prefix  )\n");
+		return;
+	}
+	else
+	{
+		if ( nlsr->slice_prefix != NULL)
+			free(nlsr->slice_prefix);
+		if ( slice_prefix[strlen(slice_prefix)-1] == '/' )
+			slice_prefix[strlen(slice_prefix)-1]='\0';
+
+		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));
+	}
+}
+
+void 
+process_command_hyperbolic_routing(char *command)
+{
+	if(command==NULL)
+	{
+		printf(" Wrong Command Format ( hyperbolic-routing on)\n");
+		return;
+	}
+	char *rem;
+	const char *sep=" \t\n";
+	char *on_off;
+
+	on_off=strtok_r(command,sep,&rem);
+	if(on_off==NULL)
+	{
+		printf(" Wrong Command Format ( hyperbolic-routing on )\n");
+		return;
+	}
+	
+	if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
+	{
+		nlsr->is_hyperbolic_calc=1;
+	}
+}
+
+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_command_tunnel_type(char *command)
+{
+	if(command==NULL)
+	{
+		printf(" Wrong Command Format ( tunnel-type udp/tcp)\n");
+		return;
+	}
+	char *rem;
+	const char *sep=" \t\n";
+	char *on_off;
+
+	on_off=strtok_r(command,sep,&rem);
+	if(on_off==NULL)
+	{
+		printf(" Wrong Command Format ( tunnel-type udp/tcp )\n");
+		return;
+	}
+	
+	if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 )
+	{
+		nlsr->tunnel_type=IPPROTO_TCP;
+	}
+	else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 )
+	{
+		nlsr->tunnel_type=IPPROTO_UDP;
+	}
+}
+
 void 
 process_conf_command(char *command)
 {
@@ -529,10 +707,10 @@
 	{
 		process_command_ccnname(remainder);
 	}
-	else if(!strcmp(cmd_type,"lsdb-synch-interval") )
+	/*else if(!strcmp(cmd_type,"lsdb-synch-interval") )
 	{
 		process_command_lsdb_synch_interval(remainder);
-	}
+	}*/
 	else if(!strcmp(cmd_type,"interest-retry") )
 	{
 		process_command_interest_retry(remainder);
@@ -549,9 +727,9 @@
 	{
 		process_command_router_dead_interval(remainder);
 	}
-	else if(!strcmp(cmd_type,"multi-path-face-num") )
+	else if(!strcmp(cmd_type,"max-faces-per-prefix") )
 	{
-		process_command_multi_path_face_num(remainder);
+		process_command_max_faces_per_prefix(remainder);
 	}
 	else if(!strcmp(cmd_type,"logdir") )
 	{
@@ -565,6 +743,26 @@
 	{
 			process_command_debug(remainder);
 	}
+	else if(!strcmp(cmd_type,"topo-prefix") )
+	{
+			process_command_topo_prefix(remainder);
+	}
+	else if(!strcmp(cmd_type,"slice-prefix") )
+	{
+			process_command_slice_prefix(remainder);
+	}
+	else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
+	{
+		process_command_hyperbolic_cordinate(remainder);
+	}
+	else if(!strcmp(cmd_type,"hyperbolic-routing") )
+	{
+		process_command_hyperbolic_routing(remainder);
+	}
+	else if(!strcmp(cmd_type,"tunnel-type") )
+	{
+		process_command_tunnel_type(remainder);
+	}
 	else 
 	{
 		printf("Wrong configuration Command %s \n",cmd_type);
@@ -601,14 +799,68 @@
 	return 0;
 }
 
+
+void
+add_faces_for_nbrs(void)
+{	
+	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;
+		int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name, (const char *)nbr->ip_address, 9695,nlsr->tunnel_type);
+		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);		
+	}
+
+	hashtb_end(e);
+
+}
+
+void
+destroy_faces_for_nbrs(void)
+{	
+	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->face > 0 )
+		{	
+			add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face);
+			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->slice_prefix, OP_UNREG, nbr->face);
+		}
+		hashtb_next(e);		
+	}
+
+	hashtb_end(e);
+
+}
+
 char *
 process_api_client_command(char *command)
 {
 	char *msg;
 	msg=(char *)malloc(100);	
-	memset(msg,100,0);
-	//strcpy(msg,"Action Carried Out for NLSR Api Client");
-
+	memset(msg,0,100);
+	
 	const char *sep=" \t\n";
 	char *rem=NULL;
 	char *cmd_type=NULL;
@@ -686,6 +938,10 @@
 			else
 			{
 				update_adjacent_status_to_adl(np,NBR_DOWN);
+				int face_id=get_next_hop_face_from_adl(np->name);
+				add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)np->name, OP_UNREG, face_id);
+				add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, face_id);
+				add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_UNREG, face_id);
 				delete_nbr_from_adl(np);
 				if(!nlsr->is_build_adj_lsa_sheduled)
 				{
@@ -700,8 +956,23 @@
 			res=is_neighbor(np->name);
 			if ( res == 0 )
 			{
-				add_nbr_to_adl(np,face_id);
+				struct name_prefix *nbr_name=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+				get_host_name_from_command_string(nbr_name,np->name,0);
+				printf("Hostname of neighbor: %s ",nbr_name->name);
+
+				char *ip_addr=(char *)malloc(13);
+				memset(ip_addr,0,13);
+				get_ip_from_hostname_02(nbr_name->name,ip_addr);
+				printf("IP Address: %s \n",ip_addr);
+				int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type);
+				update_face_to_adl_for_nbr(nbr_name->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);				
+
+				add_nbr_to_adl(np,face_id,ip_addr);
+
 				sprintf(msg,"Neighbor %s has been added to adjacency list.",name);
+
 			}
 			else
 			{
@@ -718,18 +989,16 @@
 nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd)
 {
 	struct timeval timeout;
-	if ( time_out_micro_sec < 0 )
+	if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 )
 	{
-		timeout.tv_sec=1;
-		timeout.tv_usec=0;
+		timeout.tv_sec=0;
+		timeout.tv_usec=time_out_micro_sec;
 	}
-	else
+	else 
 	{
-		time_out_micro_sec=(long int)time_out_micro_sec*0.4;
-		timeout.tv_sec=time_out_micro_sec / 1000000;
-		timeout.tv_usec=time_out_micro_sec % 1000000;
+		timeout.tv_sec = 0;
+		timeout.tv_usec = 500000;
 	}
-
 	
 	int fd;
 	int nread;
@@ -744,7 +1013,7 @@
 	testfds=nlsr->readfds;
 	result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout);
 	
-	for(fd = 0; fd < FD_SETSIZE; fd++) 
+	for(fd = 0; fd < FD_SETSIZE && result > 0; fd++) 
 	{
 		if(FD_ISSET(fd,&testfds)) 
 		{
@@ -754,14 +1023,13 @@
 			}			
 			else if(fd == nlsr->nlsr_api_server_sock_fd)
 			{
-				printf("Setting up socket....\n");
 				client_len = sizeof(client_address);
 				client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len);
 				FD_SET(client_sockfd, &nlsr->readfds);
 			}
 			else
 			{   
-				printf("Else...\n");		
+					
 				ioctl(fd, FIONREAD, &nread);
 				if(nread == 0) 
 				{
@@ -771,7 +1039,7 @@
 				else 
 				{
 					recv(fd, recv_buffer, 1024, 0);
-					printf("Test Received Data from NLSR API cleint: %s \n",recv_buffer);
+					printf("Received Data from NLSR API cleint: %s \n",recv_buffer);
 					char *msg=process_api_client_command(recv_buffer);
 					send(fd, msg, strlen(msg),0);
 					free(msg);
@@ -785,6 +1053,23 @@
 	return 0;
 }
 
+int
+check_config_validity()
+{
+	if (nlsr->router_name == NULL )
+	{
+		fprintf(stderr,"Router name has not been configured :(\n");
+		return -1;
+	}
+	if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) ) 	
+	{
+		fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
+		return -1;
+	}
+	
+	return 0;
+}
+
 void 
 nlsr_destroy( void )
 {
@@ -795,7 +1080,7 @@
 	writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n");	
 	/* Destroying all face created by nlsr in CCND */
 	destroy_all_face_by_nlsr();	
-
+	destroy_faces_for_nbrs();
 	/* Destroying every hash table attached to each neighbor in ADL before destorying ADL */	
 	hashtb_destroy(&nlsr->npl);
 	hashtb_destroy(&nlsr->adl);	
@@ -803,7 +1088,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);
 
@@ -826,6 +1111,11 @@
 	hashtb_destroy(&nlsr->npt);
 
 
+	ccns_close(&nlsr->ccns, NULL, NULL);
+	ccns_slice_destroy(&nlsr->slice);
+
+
+
 	close(nlsr->nlsr_api_server_sock_fd);	
 
 	ccn_schedule_destroy(&nlsr->sched);
@@ -844,6 +1134,7 @@
 }
 
 
+
 void
 init_api_server(int ccn_fd)
 {
@@ -863,13 +1154,11 @@
        	}
 
 	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);
 
 	server_len = sizeof(server_address);
 	bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
-	//printf("port number %d\n", ntohs(server_address.sin_port));
 	listen(server_sockfd, 100);
 	FD_ZERO(&nlsr->readfds);
 	FD_SET(server_sockfd, &nlsr->readfds);
@@ -919,13 +1208,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);
 	
 	
 
@@ -941,16 +1232,30 @@
 	nlsr->detailed_logging=0;
 	nlsr->debugging=0;
 
-	nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL;
+	//nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL;
 	nlsr->interest_retry = INTEREST_RETRY;
 	nlsr->interest_resend_time = INTEREST_RESEND_TIME;
 	nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
 	nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
-	nlsr->multi_path_face_num=MULTI_PATH_FACE_NUM;
+	nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX;
 	nlsr->semaphor=NLSR_UNLOCKED;
 
 	nlsr->api_port=API_PORT;
 
+	nlsr->topo_prefix=(char *)malloc(strlen("/ndn/routing/nlsr")+1);
+	memset(nlsr->topo_prefix,0,strlen("/ndn/routing/nlsr")+1);
+	memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));
+
+	nlsr->slice_prefix=(char *)malloc(strlen("/ndn/routing/nlsr/LSA")+1);
+	memset(nlsr->slice_prefix, 0, strlen("/ndn/routing/nlsr/LSA")+1);
+	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;
+
+	nlsr->tunnel_type=IPPROTO_UDP;
+
 	return 0;
 }
 
@@ -991,8 +1296,14 @@
 		nlsr->api_port=port;
 
 	readConfigFile(config_file);
+
+	ON_ERROR_DESTROY(check_config_validity());
+
+	print_adjacent_from_adl();
+
 	if ( daemon_mode == 1 )
 	{
+		nlsr->debugging=0;
 		daemonize_nlsr();
 	}
 	
@@ -1008,7 +1319,14 @@
 	}
 
 	init_api_server(ccn_fd);
-	
+
+	res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix);
+	if(res<0)
+	{
+		fprintf(stderr, "Can not create slice for prefix %s\n",nlsr->slice_prefix);
+		writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for prefix %s\n",nlsr->slice_prefix);
+		ON_ERROR_DESTROY(res);
+	}
 	struct ccn_charbuf *router_prefix;	
 	router_prefix=ccn_charbuf_create(); 
 	res=ccn_name_from_uri(router_prefix,nlsr->router_name);		
@@ -1037,10 +1355,20 @@
 		printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
 	writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
 
+	add_faces_for_nbrs();
 	print_name_prefix_from_npl();
 	print_adjacent_from_adl();
-	build_and_install_name_lsas();
-	print_name_lsdb();	
+	build_and_install_name_lsas();	
+
+	sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
+
+
+	print_name_lsdb();
+	if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0)
+	{
+		build_and_install_cor_lsa();
+	}
+	write_name_lsdb_to_repo(nlsr->slice_prefix);
 
 	nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
 	nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
@@ -1059,7 +1387,7 @@
 			}
 			if(nlsr->ccn != NULL)
 			{
-        			res = ccn_run(nlsr->ccn, 0);
+        			res = ccn_run(nlsr->ccn, 1);
 			}
 			if (!(nlsr->sched && nlsr->ccn))
 			{