#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#include <assert.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 "nlsr.h"
#include "nlsr_lsdb.h"
#include "utility.h"

void
make_name_lsa_key(struct ccn_charbuf *key, struct ccn_charbuf *orig_router, unsigned int ls_type, long int nlsa_id, long int orig_time)
{
	printf("make_name_lsa_key called \n");	
	ccn_charbuf_append_string(key,ccn_charbuf_as_string(orig_router));

	struct ccn_charbuf *c=ccn_charbuf_create();
	ccn_charbuf_reset(c);
	ccn_charbuf_putf(c, "%d", ls_type);
	ccn_charbuf_append_string(key,ccn_charbuf_as_string(c));
	
	ccn_charbuf_reset(c);
	ccn_charbuf_putf(c, "%ld", nlsa_id);
	ccn_charbuf_append_string(key,ccn_charbuf_as_string(c));
	
	ccn_charbuf_reset(c);
	ccn_charbuf_putf(c, "%ld", orig_time);
	ccn_charbuf_append_string(key,ccn_charbuf_as_string(c));
	//ccn_charbuf_append_string(key,orig_time);	

	ccn_charbuf_destroy(&c);

	printf("Key: %s length: %d\n",ccn_charbuf_as_string(key),(int)key->length);

}

void 
install_name_lsa(struct nlsa *new_name_lsa)
{
	printf("install_name_lsa called \n");
	struct ccn_charbuf *key=ccn_charbuf_create();
	make_name_lsa_key(key,new_name_lsa->header->orig_router,new_name_lsa->header->ls_type,new_name_lsa->header->ls_id,new_name_lsa->header->orig_time);

	struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa *));
	
	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee; 	
    	int res;

   	hashtb_start(nlsr->lsdb->name_lsdb, e);
    	res = hashtb_seek(e, key->buf , key->length, 0);

	if(res == HT_NEW_ENTRY )
	{
   		printf("New Name LSA. Added...\n");
		name_lsa = e->data;

		name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header *));
	
	
		name_lsa->header->ls_type=new_name_lsa->header->ls_type;
		name_lsa->header->orig_time=new_name_lsa->header->orig_time;
		name_lsa->header->ls_id=new_name_lsa->header->ls_id;
		
		name_lsa->header->orig_router=ccn_charbuf_create();
		ccn_charbuf_append_string(name_lsa->header->orig_router,ccn_charbuf_as_string(new_name_lsa->header->orig_router));	
		name_lsa->header->isValid=new_name_lsa->header->isValid;

		name_lsa->name_prefix=ccn_charbuf_create();	
		ccn_charbuf_append_string(name_lsa->name_prefix,ccn_charbuf_as_string(new_name_lsa->name_prefix));
		//ccn_charbuf_append_charbuf(name_lsa->name_prefix,new_name_lsa->name_prefix);
	}
	else if(res == HT_OLD_ENTRY)
	{
		printf("Duplicate Name LSA. Discarded...\n");
	
	}
	
    	hashtb_end(e);

	ccn_charbuf_destroy(&key);
	
}

void 
build_name_lsa(struct nlsa *name_lsa, struct ccn_charbuf *name_prefix)
{
	printf("build_name_lsa called \n");
	//struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa *));

	//name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header *));
	//name_lsa->header->orig_router=ccn_charbuf_create();
	
	name_lsa->header->ls_type=LS_TYPE_NAME;
	name_lsa->header->orig_time=get_current_time_microsec();
	//name_lsa->header->orig_time=(char *)malloc(strlen(get_current_time_microsec())+1);
	//memcpy(name_lsa->header->orig_time,get_current_time_microsec(),strlen(get_current_time_microsec())+1);
	name_lsa->header->ls_id=++nlsr->nlsa_id;
	ccn_charbuf_append_string(name_lsa->header->orig_router,nlsr->router_name);	
	name_lsa->header->isValid=1;

	//name_lsa->name_prefix=ccn_charbuf_create();	
	ccn_charbuf_append_string(name_lsa->name_prefix,ccn_charbuf_as_string(name_prefix));
	//ccn_charbuf_append_charbuf(name_lsa->name_prefix,name_prefix);

	//return name_lsa;
}

int 
initial_build_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
{
	printf("initial_build_name_lsa called \n");	
	int i, npl_element;
	struct name_prefix *np;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee;
    	
    	hashtb_start(nlsr->npl, e);
	npl_element=hashtb_n(nlsr->npl);

	for(i=0;i<npl_element;i++)
	{
		np=e->data;

		struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa *));
		name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header *));
		name_lsa->header->orig_router=ccn_charbuf_create();
		name_lsa->name_prefix=ccn_charbuf_create();

		struct ccn_charbuf *name;
		name=ccn_charbuf_create();
		ccn_charbuf_append_string(name,np->name);
		build_name_lsa(name_lsa,name);
		install_name_lsa(name_lsa);

		//ccn_charbuf_destroy(&name_lsa->header->orig_router);
		free(name_lsa->header);
		//ccn_charbuf_destroy(&name_lsa->name_prefix);
		free(name_lsa);
		ccn_charbuf_destroy(&name);
	
		hashtb_next(e);		
	}

	hashtb_end(e);

	print_name_lsdb();

	return 0;
}

void 
print_name_lsa(struct nlsa *name_lsa)
{
	printf("print_name_lsa called \n");
	printf("-----------Name LSA---------------\n");
	printf("	Origination Router       :	%s\n",ccn_charbuf_as_string(name_lsa->header->orig_router));
	printf("	Origination Router Length:	%d\n",(int)name_lsa->header->orig_router->length);
	printf("	LS Type			 :	%d\n",name_lsa->header->ls_type);
	printf("	LS Id			 :	%ld\n",name_lsa->header->ls_id);
	printf("	Origination Time	 :	%ld\n",name_lsa->header->orig_time);
	printf("	Is Valid 		 :	%d\n",name_lsa->header->isValid);

	printf("	LSA Data			\n");
	printf("		Name Prefix:	 	:	%s\n",ccn_charbuf_as_string(name_lsa->name_prefix));
	printf("		Name Prefix Length	:	%d\n",(int)name_lsa->name_prefix->length);

	printf("\n");

}

void
print_name_lsdb(void)
{
	printf("print_name_lsdb called \n");	
	int i, lsdb_element;
	struct nlsa *name_lsa;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee;
    	
    	hashtb_start(nlsr->lsdb->name_lsdb, e);
	lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);

	for(i=0;i<lsdb_element;i++)
	{
		name_lsa=e->data;
		print_name_lsa(name_lsa);		
		hashtb_next(e);		
	}

	hashtb_end(e);

}


int 
install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
{
	printf("install_adj_lsa called \n");

	ev = ccn_schedule_event(nlsr->sched, 1000000, &install_adj_lsa, NULL, 0);

	return 0;
	
}
