#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <assert.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>

#ifdef HAVE_CONFIG_H
#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 <ccn/sync.h>
#include <ccn/seqwriter.h>
#include <ccn/ccn_private.h>

#include "nlsr.h"
#include "nlsr_ndn.h"
#include "nlsr_lsdb.h"
#include "utility.h"
#include "nlsr_npl.h"
#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) \
{           \
	if ((resval) < 0) { \
		nlsr_destroy(); \
		exit(1);\
	} \
}


#define ON_ERROR_EXIT(resval) \
{           \
	if ((resval) < 0) { \
		exit(1); \
	} \
}

struct option longopts[] =
{
	{ "daemon",      no_argument,       NULL, 'd'},
	{ "config_file", required_argument, NULL, 'f'},
	{ "api_port",    required_argument, NULL, 'p'},
	{ "help",        no_argument,       NULL, 'h'},
	{ 0 }
};

	static int 
usage(char *progname)
{

	printf("Usage: %s [OPTIONS...]\n\
			NDN routing....\n\
			-d, --daemon        Run in daemon mode\n\
			-f, --config_file   Specify configuration file name\n\
			-p, --api_port      port where api client will connect\n\
			-h, --help          Display this help message\n", progname);

	exit(1);
}

void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result)
{
	struct timeval now = {0};
	gettimeofday(&now, 0);
	result->s = now.tv_sec;
	result->micros = now.tv_usec;
}

static struct ccn_gettime ndn_rtr_ticker = {
	"timer",
	&ndn_rtr_gettime,
	1000000,
	NULL
};

	void
nlsr_lock(void)
{
	nlsr->semaphor=NLSR_LOCKED;
}

	void
nlsr_unlock(void)
{
	nlsr->semaphor=NLSR_UNLOCKED;
}

	void 
nlsr_stop_signal_handler(int sig)
{
	signal(sig, SIG_IGN);
	nlsr_destroy();
	exit(0);	
}

	void  
daemonize_nlsr(void)
{
	//int ret;
	pid_t process_id = 0;
	pid_t sid = 0;
	process_id = fork();
	if (process_id < 0)
	{
		printf("Daemonization failed!\n");
		ON_ERROR_DESTROY(process_id);
	}
	if (process_id > 0)
	{
		printf("Process daemonized. Process id: %d \n", process_id);
		//ret=process_id;
		exit(0);
	}

	umask(0);
	sid = setsid();
	if(sid < 0)
	{
		ON_ERROR_DESTROY(sid);		
	}

	chdir("/");	
	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);
}

	void 
process_command_ccnneighbor(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *rtr_name;
	char *nbr_ip_addr;
	int is_ip_configured=0;
	char *ip_addr=(char *)calloc(20,sizeof(char));

	rtr_name=strtok_r(command,sep,&rem);
	if(rtr_name==NULL)
	{
		printf(" Wrong Command Format ( ccnneighbor router_name faceX)\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);
		if ( nbr_ip_addr != NULL)
			is_ip_configured=1;
	}
	struct name_prefix *nbr=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
	nbr->name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
	memcpy(nbr->name,rtr_name,strlen(rtr_name)+1);
	nbr->length=strlen(rtr_name)+1;


	if ( !is_ip_configured )
	{
		struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
		get_host_name_from_command_string(nbr_name,nbr->name,0);
		if ( nlsr->debugging)
			printf("Hostname of neighbor: %s ",nbr_name->name);
		get_ip_from_hostname_02(nbr_name->name,ip_addr);
		if ( nlsr->debugging)
			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)+1);
		if (nlsr->debugging)
		{
			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);
}

	void 
process_command_ccnname(char *command)
{

	if(command==NULL)
	{
		printf(" Wrong Command Format ( ccnname /name/prefix)\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	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);

	if ( name[strlen(name)-1] == '/' )
		name[strlen(name)-1]='\0';

	struct name_prefix *np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
	np->name=(char *)calloc(strlen(name)+1,sizeof(char));
	//memset(np->name,0,strlen(name)+1);
	memcpy(np->name,name,strlen(name)+1);
	np->length=strlen(name)+1;

	add_name_to_npl(np);

	free(np->name);
	free(np);
}


	void 
process_command_router_name(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( router-name /router/name )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *rtr_name;

	rtr_name=strtok_r(command,sep,&rem);
	if(rtr_name==NULL)
	{
		printf(" Wrong Command Format ( router-name /router/name )\n");
		return;
	}


	if ( rtr_name[strlen(rtr_name)-1] == '/' )
		rtr_name[strlen(rtr_name)-1]='\0';

	nlsr->router_name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
	//memset(nlsr->router_name,0,strlen(rtr_name)+1);
	memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1);


}

/*
   void 
   process_command_lsdb_synch_interval(char *command)
   {
   if(command==NULL)
   {
   printf(" Wrong Command Format ( lsdb-synch-interval secs )\n");
   return;
   }
   char *rem;
   const char *sep=" \t\n";
   char *secs;
   long int seconds;

   secs=strtok_r(command,sep,&rem);
   if(secs==NULL)
   {
   printf(" Wrong Command Format ( lsdb-synch-interval secs)\n");
   return;
   }

   seconds=atoi(secs);
   if ( seconds >= 120 && seconds <= 3600 )
   {
   nlsr->lsdb_synch_interval=seconds;
   }

   }
 */

	void 
process_command_interest_retry(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( interest-retry number )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *retry;
	long int retry_number;

	retry=strtok_r(command,sep,&rem);
	if(retry==NULL)
	{
		printf(" Wrong Command Format ( interest-retry number)\n");
		return;
	}

	retry_number=atoi(retry);
	if ( retry_number >= 1 && retry_number<=10 )
	{
		nlsr->interest_retry=retry_number;
	}

}

	void 
process_command_interest_resend_time(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( interest-resend-time secs )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *secs;
	long int seconds;

	secs=strtok_r(command,sep,&rem);
	if(secs==NULL)
	{
		printf(" Wrong Command Format ( interest-resend-time secs)\n");
		return;
	}

	seconds=atoi(secs);
	if ( seconds <= 60 && seconds >= 1 )
	{
		nlsr->interest_resend_time=seconds;
	}
}


	void 
process_command_lsa_refresh_time(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( lsa-refresh-time secs )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *secs;
	long int seconds;

	secs=strtok_r(command,sep,&rem);
	if(secs==NULL)
	{
		printf(" Wrong Command Format ( lsa-refresh-time secs)\n");
		return;
	}

	seconds=atoi(secs);
	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;
		}
	}

}

	void 
process_command_router_dead_interval(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( router-dead-interval secs )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *secs;
	long int seconds;

	secs=strtok_r(command,sep,&rem);
	if(secs==NULL)
	{
		printf(" Wrong Command Format ( router-dead-interval secs)\n");
		return;
	}

	seconds=atoi(secs);
	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_max_faces_per_prefix(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( max-faces-per-prefix n )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *num;
	long int number;

	num=strtok_r(command,sep,&rem);
	if(num==NULL)
	{
		printf(" Wrong Command Format ( max-faces-per-prefix n)\n");
		return;
	}

	number=atoi(num);
	if ( number >= 0 && number <= 60 )
	{
		nlsr->max_faces_per_prefix=number;
	}

}

	void 
process_command_logdir(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( logdir /path/to/logdir )\n");
		return;
	}
	char *rem;
	const char *sep=" \t\n";
	char *dir;

	dir=strtok_r(command,sep,&rem);
	if(dir==NULL)
	{
		printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n");
		return;
	}

	nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char));
	memcpy(nlsr->logDir,dir,strlen(dir)+1);
}

	void 
process_command_detailed_log(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( detailed-log on/off )\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 ( detailed-log on/off )\n");
		return;
	}

	if ( strcmp(on_off,"ON") == 0  || strcmp(on_off,"on") == 0)
	{
		nlsr->detailed_logging=1;
	}
}

	void 
process_command_debug(char *command)
{
	if(command==NULL)
	{
		printf(" Wrong Command Format ( debug on/off )\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 ( debug on/off )\n");
		return;
	}

	if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
	{
		nlsr->debugging=1;
	}
}


	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 *)calloc(strlen(topo_prefix)+1,sizeof(char));
		memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
		printf ("Topo prefix is: %s", nlsr->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 *)calloc(strlen(slice_prefix)+1,sizeof(char));
		memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
	}
}

	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)
{
	const char *separators=" \t\n";
	char *remainder=NULL;
	char *cmd_type=NULL;

	if(command==NULL || strlen(command)==0 || command[0]=='!')
		return;	

	cmd_type=strtok_r(command,separators,&remainder);

	if(!strcmp(cmd_type,"router-name") )
	{
		process_command_router_name(remainder);
	}
	else if(!strcmp(cmd_type,"ccnneighbor") )
	{
		process_command_ccnneighbor(remainder);
	} 
	else if(!strcmp(cmd_type,"ccnname") )
	{
		process_command_ccnname(remainder);
	}
	else if(!strcmp(cmd_type,"interest-retry") )
	{
		process_command_interest_retry(remainder);
	}
	else if(!strcmp(cmd_type,"interest-resend-time") )
	{
		process_command_interest_resend_time(remainder);
	}
	else if(!strcmp(cmd_type,"lsa-refresh-time") )
	{
		process_command_lsa_refresh_time(remainder);
	}
	else if(!strcmp(cmd_type,"router-dead-interval") )
	{
		process_command_router_dead_interval(remainder);
	}
	else if(!strcmp(cmd_type,"max-faces-per-prefix") )
	{
		process_command_max_faces_per_prefix(remainder);
	}
	else if(!strcmp(cmd_type,"logdir") )
	{
		process_command_logdir(remainder);
	}
	else if(!strcmp(cmd_type,"detailed-log") )
	{
		process_command_detailed_log(remainder);
	}
	else if(!strcmp(cmd_type,"debug") )
	{
		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);
	}
}


	int 
readConfigFile(const char *filename)
{
	FILE *cfg;
	char buf[1024];
	int len;

	cfg=fopen(filename, "r");

	if(cfg == NULL)
	{
		printf("\nConfiguration File does not exists\n");
		return -1;	
	}

	while(fgets((char *)buf, sizeof(buf), cfg))
	{
		len=strlen(buf);
		if(buf[len-1] == '\n')
			buf[len-1]='\0';
		if ( buf[0] != '#' && buf[0] != '!') 
			process_conf_command(buf);	
	}

	fclose(cfg);

	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,0,100);

	const char *sep=" \t\n";
	char *rem=NULL;
	char *cmd_type=NULL;
	char *op_type=NULL;
	char *name=NULL;
	char *face=NULL;
	int face_id;
	int res;

	op_type=strtok_r(command,sep,&rem);
	cmd_type=strtok_r(NULL,sep,&rem);
	name=strtok_r(NULL,sep,&rem);
	if ( name[strlen(name)-1] == '/' )
		name[strlen(name)-1]='\0';

	struct name_prefix *np=(struct name_prefix *) calloc (1, 
			sizeof(struct name_prefix ));
	np->name = (char *) calloc (strlen(name)+1,sizeof(char));
	memcpy(np->name,name,strlen(name)+1);
	np->length=strlen(name)+1;

	if ( strcmp(cmd_type,"name")!= 0 )
	{
		face=strtok_r(NULL,sep,&rem);
		sscanf(face,"face%d",&face_id);
	}

	if ( strcmp(cmd_type,"name")== 0 )
	{
		if ( strcmp(op_type,"del") == 0 ) 
		{
			res=does_name_exist_in_npl(np);
			if ( res == 0)
			{
				sprintf(msg,"Name %s does not exist !!",name);
			}
			else
			{
				long int ls_id=get_lsa_id_from_npl(np);
				if ( ls_id != 0 )
				{
					make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id);
					sprintf(msg,"Name %s has been deleted and Advertised.",name);
				}
				else 
				{
					sprintf(msg,"Name %s does not have an Name LSA yet !!",name);
				}
			}			
		}
		else if ( strcmp(op_type,"add") == 0 )
		{
			res=does_name_exist_in_npl(np);
			if ( res == 0)
			{
				add_name_to_npl(np);
				build_and_install_single_name_lsa(np);
				sprintf(msg,"Name %s has been added to advertise.",name);
			}
			else
			{
				sprintf(msg,"Name %s has already been advertised from this router !!",name);
			}
		} 
	}
	else if ( strcmp(cmd_type,"neighbor") == 0 )
	{
		if ( strcmp(op_type,"del") == 0 ) 
		{
			res=is_neighbor(np->name);
			if ( res == 0)
			{
				sprintf(msg,"Neighbor %s does not exist !!",name);
			}
			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)
				{
					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;		
				}
				sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name);	
			}
		}
		else if ( strcmp(op_type,"add") == 0 )
		{
			res=is_neighbor(np->name);
			if ( res == 0 )
			{
				struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,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 *)calloc(20,sizeof(char));
				//memset(ip_addr,0,20);
				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);
				free(ip_addr);

			}
			else
			{
				sprintf(msg,"Neighbor %s already exists in adjacency list.",name);
			}
		}
	}


	return msg;
}

	int
nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd)
{
	struct timeval timeout;
	if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 )
	{
		timeout.tv_sec=0;
		timeout.tv_usec=time_out_micro_sec;
	}
	else 
	{
		timeout.tv_sec = 0;
		timeout.tv_usec = 500000;
	}

	int fd;
	int nread;
	int result;
	fd_set testfds;
	unsigned int client_len;
	int client_sockfd;
	char recv_buffer[1024];
	bzero(recv_buffer,1024);
	struct sockaddr_in client_address;

	testfds=nlsr->readfds;
	result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout);

	for(fd = 0; fd < FD_SETSIZE && result > 0; fd++) 
	{
		if(FD_ISSET(fd,&testfds)) 
		{
			if ( fd == ccn_fd )
			{
				return 0;
			}			
			else if(fd == nlsr->nlsr_api_server_sock_fd)
			{
				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
			{   

				ioctl(fd, FIONREAD, &nread);
				if(nread == 0) 
				{
					close(fd);
					FD_CLR(fd, &nlsr->readfds);
				}
				else 
				{
					recv(fd, recv_buffer, 1024, 0);
					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);
					close(fd);
					FD_CLR(fd, &nlsr->readfds);
				}
			}
		}
	}

	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 )
{
	if ( nlsr->debugging )
	{
		printf("Freeing Allocated Memory....\n");
	}	
	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->adl);
	hashtb_destroy(&nlsr->npl);	
	hashtb_destroy(&nlsr->pit_alsa);
	hashtb_destroy(&nlsr->lsdb->name_lsdb);
	hashtb_destroy(&nlsr->lsdb->adj_lsdb);
	hashtb_destroy(&nlsr->lsdb->cor_lsdb);

	int i, npt_element,rt_element;
	struct npt_entry *ne;
	struct hashtb_enumerator ee;
	struct hashtb_enumerator *e = &ee;
	hashtb_start(nlsr->npt, e);
	npt_element=hashtb_n(nlsr->npt);
	for(i=0;i<npt_element;i++)
	{
		ne=e->data;
		hashtb_destroy(&ne->name_list);
		hashtb_destroy(&ne->face_list);	
		hashtb_next(e);		
	}

	hashtb_end(e);
	hashtb_destroy(&nlsr->npt);

	struct routing_table_entry *rte;
	hashtb_start(nlsr->routing_table, e);
	rt_element=hashtb_n(nlsr->routing_table);
	for(i=0;i<rt_element;i++)
	{
		rte=e->data;
		hashtb_destroy(&rte->face_list);	
		hashtb_next(e);		
	}	
	hashtb_end(e);
	hashtb_destroy(&nlsr->routing_table);

	if ( nlsr->ccns != NULL )
		ccns_close(&nlsr->ccns, NULL, NULL);
	if ( nlsr->slice != NULL ) 
		ccns_slice_destroy(&nlsr->slice);

	close(nlsr->nlsr_api_server_sock_fd);

	ccn_destroy(&nlsr->ccn);
	free(nlsr->lsdb->lsdb_version);
	free(nlsr->lsdb);
	free(nlsr->router_name);
	if ( nlsr->debugging )
	{
		printf("Finished freeing allocated memory\n");
	}
	writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n");

	free(nlsr);

}



	void
init_api_server(int ccn_fd)
{
	int server_sockfd;
	int server_len;
	struct sockaddr_in server_address;
	unsigned int yes=1;	

	server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

	int flags = fcntl(server_sockfd, F_GETFL, 0);
	fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags);

	if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) 
	{
		ON_ERROR_DESTROY(-1);
	}

	server_address.sin_family = AF_INET;
	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);
	listen(server_sockfd, 100);
	FD_ZERO(&nlsr->readfds);
	FD_SET(server_sockfd, &nlsr->readfds);
	FD_SET(ccn_fd, &nlsr->readfds);
	nlsr->nlsr_api_server_sock_fd=server_sockfd;
}

	int 
init_nlsr(void)
{
	if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR) 
	{
		perror("SIGQUIT install error\n");
		return -1;
	}
	if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR) 
	{
		perror("SIGTERM install error\n");
		return -1;
	}
	if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
	{
		perror("SIGTERM install error\n");
		return -1;
	}

	nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr));

	nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), NULL);
	nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL);
	nlsr->pit_alsa = hashtb_create(sizeof(struct pending_interest), NULL);
	nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
	nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);

	nlsr->in_interest.p = &incoming_interest;
	nlsr->in_content.p = &incoming_content;

	nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));

	char *time_stamp=(char *) calloc (20,sizeof(char));
	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));
	free(time_stamp);

	nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
	nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
	nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);

	nlsr->is_synch_init=1;
	nlsr->nlsa_id=0;
	nlsr->adj_build_flag=0;
	nlsr->adj_build_count=0;
	nlsr->is_build_adj_lsa_sheduled=0;
	nlsr->is_send_lsdb_interest_scheduled=0;
	nlsr->is_route_calculation_scheduled=0;	

	nlsr->detailed_logging=0;
	nlsr->debugging=0;

	//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->max_faces_per_prefix=MAX_FACES_PER_PREFIX;
	nlsr->semaphor=NLSR_UNLOCKED;

	nlsr->api_port=API_PORT;

	nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char));
	memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));

	nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char));
	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;
}

	int 
main(int argc, char *argv[])
{
	int res, ret;
	char *config_file;
	int daemon_mode=0;
	int port=0;

	while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1) 
	{
		switch (res) 
		{
			case 'd':
				daemon_mode = 1;
				break;
			case 'f':
				config_file = optarg;
				break;
			case 'p':
				port = atoi(optarg);
				break;
			case 'h':
			default:
				usage(argv[0]);
		}
	}

	ret = init_nlsr();	
	ON_ERROR_EXIT(ret);

	if ( port !=0 )
		nlsr->api_port=port;

	ON_ERROR_DESTROY(readConfigFile(config_file));

	ON_ERROR_DESTROY(check_config_validity());

	print_adjacent_from_adl();

	if ( daemon_mode == 1 )
	{
		nlsr->debugging=0;
		daemonize_nlsr();
	}

	startLogging(nlsr->logDir);

	nlsr->ccn=ccn_create();
	int ccn_fd=ccn_connect(nlsr->ccn, NULL);

	if(ccn_fd == -1)
	{
		fprintf(stderr,"Could not connect to ccnd\n");
		writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n");
		ON_ERROR_DESTROY(-1);
	}

	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);		
	if(res<0)
	{
		fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
		writeLogg(__FILE__,__FUNCTION__,__LINE__,
				"Bad ccn URI: %s\n", nlsr->router_name);
		ON_ERROR_DESTROY(res);
	}

	ccn_name_append_str(router_prefix,"nlsr");
	nlsr->in_interest.data=nlsr->router_name;
	res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
	if ( res < 0 )
	{
		fprintf(stderr,"Failed to register interest for router\n");
		writeLogg(__FILE__,__FUNCTION__,__LINE__,
				"Failed to register interest for router\n");
		ON_ERROR_DESTROY(res);
	}
	ccn_charbuf_destroy(&router_prefix);

	if ( nlsr->debugging )
		printf("Router Name : %s\n",nlsr->router_name);
	writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name);
	if ( nlsr->debugging )
		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();
	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);
	ccn_set_schedule(nlsr->ccn,nlsr->sched);
	nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
	nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);

	res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
	ON_ERROR_DESTROY(res);

	while(1)
	{	
		if ( nlsr->semaphor == NLSR_UNLOCKED  )
		{
			if( nlsr->sched != NULL )
			{
				long int micro_sec=ccn_schedule_run(nlsr->sched);
				res=nlsr_api_server_poll(micro_sec,ccn_fd);
				ON_ERROR_DESTROY(res);
			}
			if(nlsr->ccn != NULL)
			{
				res = ccn_run(nlsr->ccn, 1);
			}
			if (!(nlsr->sched && nlsr->ccn))
			{	      
				break;
			}
		}

	}
	return 0;
}

