#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 <ccn/bloom.h>

#include "nlsr.h"
#include "nlsr_ndn.h"
#include "utility.h"
#include "nlsr_adl.h"
#include "nlsr_lsdb.h"

int
appendLifetime(struct ccn_charbuf *cb, int lifetime) 
{
	unsigned char buf[sizeof(int32_t)];
	int32_t dreck = lifetime << 12;
	int pos = sizeof(int32_t);
	int res = 0;
	while (dreck > 0 && pos > 0) 
	{
		pos--;
		buf[pos] = dreck & 255;
		dreck = dreck >> 8;
	}
	res |= ccnb_append_tagged_blob(cb, CCN_DTAG_InterestLifetime, buf+pos, sizeof(buf)-pos);
	return res;
}

enum ccn_upcall_res 
incoming_interest(struct ccn_closure *selfp,
        enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
{
	my_lock();
    
    switch (kind) {
        case CCN_UPCALL_FINAL:
            break;
        case CCN_UPCALL_INTEREST:
		// printing the name prefix for which it received interest
            	printf("Interest Received for name: "); 
	    	struct ccn_charbuf*c;
		c=ccn_charbuf_create();
		ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
		ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
		//ccn_name_chop(c,NULL,-1);
		printf("%s\n",ccn_charbuf_as_string(c));
		ccn_charbuf_destroy(&c);

		process_incoming_interest(selfp, info);
		
		/* 
	    	struct ccn_charbuf *data=ccn_charbuf_create();
	    	struct ccn_charbuf *name=ccn_charbuf_create();
	    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
	   
		 ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],
            info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 

		sp.template_ccnb=ccn_charbuf_create();
		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010);
                sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
        	ccn_charbuf_append_closer(sp.template_ccnb);		   

		res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello")); 
	    	res=ccn_put(ospfndn->ccn,data->buf,data->length);
            	ccn_charbuf_destroy(&data);  

		*/
		break;

        default:
            break;
    }

	my_unlock();
    return CCN_UPCALL_RESULT_OK;
}


enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
        enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
{

	my_lock();

    switch(kind) {
        case CCN_UPCALL_FINAL:
            break;
        case CCN_UPCALL_CONTENT:
            	printf("Content Received for name: ");  
		struct ccn_charbuf*c;
		c=ccn_charbuf_create();
		ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
		printf("%s\n",ccn_charbuf_as_string(c));
		ccn_charbuf_destroy(&c);
	
		process_incoming_content(selfp, info);

	    break;
        case CCN_UPCALL_INTEREST_TIMED_OUT:
          	printf("Interest timed out \n"); 
		struct ccn_charbuf*ic;
		ic=ccn_charbuf_create();
		ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
		printf("%s\n",ccn_charbuf_as_string(ic));
		ccn_charbuf_destroy(&ic);	    
		process_incoming_timed_out_interest(selfp,info);

	    break;
        default:
            fprintf(stderr, "Unexpected response of kind %d\n", kind);
            return CCN_UPCALL_RESULT_ERR;
    }

	my_unlock();
    return CCN_UPCALL_RESULT_OK;
}


void 
process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info)
{
	printf("process_incoming_content called \n");

	struct ccn_charbuf*c;
	c=ccn_charbuf_create();
	//ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
	printf("%s\n",ccn_charbuf_as_string(c));
	ccn_charbuf_destroy(&c);

	const unsigned char *comp_ptr1;
	size_t comp_size;
	int res,i;
	int nlsr_position=0;
	int name_comps=(int)info->interest_comps->n;
	
	for(i=0;i<name_comps;i++)
	{
		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
		if( res == 0)
		{
			nlsr_position=i;
			break;
		}	
	}

	res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);


	printf("Det= %s \n",comp_ptr1);

	if(!strcmp((char *)comp_ptr1,"lsdb"))
	{
		process_incoming_content_lsdb(selfp,info);
	}
	if(!strcmp((char *)comp_ptr1,"info"))
	{
		process_incoming_content_info(selfp,info);
	}

}


void 
process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
{
	printf("process_incoming_content_lsdb called \n");

	const unsigned char *content_data;
	size_t length;
	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);


	if ( !strcmp((char *)content_data,"NACK"))
	{
		printf("NACK received for LSDB request. Do nothing \n");
	}
	else
	{
		// Do the LSDB processing here 

		const unsigned char *comp_ptr1;
		size_t comp_size;
		int res;

		res=ccn_name_comp_get(info->content_ccnb, info->content_comps,info->interest_comps->n-1,&comp_ptr1, &comp_size);
		if ( res >=0)
		printf("Received Database Version: %s \n",(char *)comp_ptr1);

	}

	

}



void 
process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
{
	printf("process_incoming_content_info called \n");

	const unsigned char *content_data;
	size_t length;
	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);

	printf("Info Value: %s \n",(char *)content_data);


	int res,i;
	int nlsr_position=0;
	int name_comps=(int)info->interest_comps->n;

	for(i=0;i<name_comps;i++)
	{
		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
		if( res == 0)
		{
			nlsr_position=i;
			break;
		}	
	}
	
	struct ccn_charbuf *nbr;
	nbr=ccn_charbuf_create();

	
	const unsigned char *comp_ptr1;
	size_t comp_size;
	for(i=0;i<nlsr_position;i++)
	{
		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
		//printf("%s \n",comp_ptr1);
		ccn_charbuf_append_string(nbr,"/");
		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
	}

	ccn_charbuf_append_string(nbr,"\0");	
	printf("Info Content received for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
	
	update_adjacent_timed_out_zero_to_adl(nbr);
	update_adjacent_status_to_adl(nbr,NBR_ACTIVE);

	print_adjacent_from_adl();

	nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);

	ccn_charbuf_destroy(&nbr);	
	

}

void 
process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
{
	printf("process_incoming_timed_out_interest called \n");

	struct ccn_charbuf*c;
	c=ccn_charbuf_create();
	//ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
	printf("%s\n",ccn_charbuf_as_string(c));
	ccn_charbuf_destroy(&c);

	//const unsigned char *comp_ptr1;
	//size_t comp_size;
	int res,i;
	int nlsr_position=0;
	int name_comps=(int)info->interest_comps->n;
	
	for(i=0;i<name_comps;i++)
	{
		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
		if( res == 0)
		{
			nlsr_position=i;
			break;
		}	
	}

	//res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);


	//printf("Det= %s \n",comp_ptr1);

	//if(!strcmp((char *)comp_ptr1,"lsdb"))
	if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
	{
		process_incoming_timed_out_interest_lsdb(selfp,info);
	}
	else if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
	{
		process_incoming_timed_out_interest_info(selfp,info);
	}
}


void 
process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
{
	printf("process_incoming_timed_out_interest_lsdb called \n");

		
	int res,i;
	int nlsr_position=0;
	int name_comps=(int)info->interest_comps->n;

	//const unsigned char *comp_ptr1;
	//size_t comp_size;
	
	for(i=0;i<name_comps;i++)
	{
		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
		if( res == 0)
		{
			nlsr_position=i;
			break;
		}	
	}	


	struct ccn_charbuf *nbr;
	nbr=ccn_charbuf_create();

	
	const unsigned char *comp_ptr1;
	size_t comp_size;
	for(i=0;i<nlsr_position;i++)
	{
		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
		//printf("%s \n",comp_ptr1);
		ccn_charbuf_append_string(nbr,"/");
		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
	}

	ccn_charbuf_append_string(nbr,"\0");	
	printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));

	//update_adjacent_status_to_adl(nbr,1);

	ccn_charbuf_destroy(&nbr);	
}

void 
process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
{

	printf("process_incoming_timed_out_interest_info called \n");

	int res,i;
	int nlsr_position=0;
	int name_comps=(int)info->interest_comps->n;

	for(i=0;i<name_comps;i++)
	{
		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
		if( res == 0)
		{
			nlsr_position=i;
			break;
		}	
	}
	
	struct ccn_charbuf *nbr;
	nbr=ccn_charbuf_create();

	
	const unsigned char *comp_ptr1;
	size_t comp_size;
	for(i=0;i<nlsr_position;i++)
	{
		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
		//printf("%s \n",comp_ptr1);
		ccn_charbuf_append_string(nbr,"/");
		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
	}

	ccn_charbuf_append_string(nbr,"\0");	
	printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));

	update_adjacent_timed_out_to_adl(nbr,1);

	print_adjacent_from_adl();	

	int timed_out=get_timed_out_number(nbr);
	if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables 
	{
		printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
		send_info_interest_to_neighbor(nbr);
	}
	else
	{
		printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
		nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
	}

	ccn_charbuf_destroy(&nbr);
}


void 
process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
{
	printf("process_incoming_interest called \n");


	struct ccn_charbuf*c;
	c=ccn_charbuf_create();
	//ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
	ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
	printf("%s\n",ccn_charbuf_as_string(c));
	ccn_charbuf_destroy(&c);

	const unsigned char *comp_ptr1;
	size_t comp_size;
	int res,i;
	int nlsr_position=0;
	int name_comps=(int)info->interest_comps->n;
	
	for(i=0;i<name_comps;i++)
	{
		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
		if( res == 0)
		{
			nlsr_position=i;
			break;
		}	
	}

	res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
	
	printf("Det= %s \n",comp_ptr1);

	if(!strcmp((char *)comp_ptr1,"lsdb"))
	{
		process_incoming_interest_lsdb(selfp,info);
	}
	if(!strcmp((char *)comp_ptr1,"info"))
	{
		process_incoming_interest_info(selfp,info);
	}
}


void 
process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
{
	printf("process_incoming_interest_lsdb called \n");
	
	int l, res;
	const unsigned char *exclbase;
	size_t size;
	struct ccn_buf_decoder decoder;
	struct ccn_buf_decoder *d;
	const unsigned char *comp;	


	l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
	if (l > 0) 
	{
		comp = NULL;
		size = 0;
		exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
		d = ccn_buf_decoder_start(&decoder, exclbase, l);
		if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) 
		{
			ccn_buf_advance(d);
			if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
				ccn_buf_advance_past_element(d);
			if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) 
			{
				ccn_buf_advance(d);
				ccn_buf_match_blob(d, &comp, &size);
				ccn_buf_check_close(d);			
				
				
			}
			ccn_buf_check_close(d);
		}
		//if (d->decoder.state < 0)
			//printf("Parse Failed\n");
		if (comp != NULL)
			printf("Number in Exclusion Filter is %s\n",comp);
			
		/* Now comp points to the start of your potential number, and size is its length */
	}

	int excl_db_version=atoi((char *)comp);
	int dbcmp=nlsr->lsdb->version-excl_db_version;
	//int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16);

	

	printf (" dbcmp = %d \n",dbcmp);	

	if(dbcmp > 0)
	{
		printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
	}
	else 
	{
		printf("Data base is not updated than the older one (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
		printf("Sending NACK Content back.....\n");

		struct ccn_charbuf *data=ccn_charbuf_create();
	    	struct ccn_charbuf *name=ccn_charbuf_create();
	    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;

		ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); 
		
		sp.template_ccnb=ccn_charbuf_create();
		ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
                sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
        	ccn_charbuf_append_closer(sp.template_ccnb);		   

		res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); 
		if(res >= 0)
			printf("Signing Content is successful \n");

	    	res=ccn_put(nlsr->ccn,data->buf,data->length);
		
		if(res >= 0)
			printf("Sending NACK Content is successful \n");

            	ccn_charbuf_destroy(&data);
		ccn_charbuf_destroy(&name);
		ccn_charbuf_destroy(&sp.template_ccnb);		

	}

}


void 
process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
{
	printf("process_incoming_interest_info called \n");
	int res;

	printf("Sending Info Content back.....\n");

	struct ccn_charbuf *data=ccn_charbuf_create();
    	struct ccn_charbuf *name=ccn_charbuf_create();
    	struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;

	ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);	

	sp.template_ccnb=ccn_charbuf_create();
	ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
	ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
	sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
	ccn_charbuf_append_closer(sp.template_ccnb);	

	res= ccn_sign_content(nlsr->ccn, data, name, &sp,"info",strlen("info") ); 
	if(res >= 0)
		printf("Signing Content is successful \n");

    	res=ccn_put(nlsr->ccn,data->buf,data->length);		
	if(res >= 0)
		printf("Sending Info Content is successful \n");

	ccn_charbuf_destroy(&data);
	ccn_charbuf_destroy(&name);
	//ccn_charbuf_destroy(&c);
	ccn_charbuf_destroy(&sp.template_ccnb);

}

int
send_lsdb_interest(struct ccn_schedule *sched, void *clienth,
        struct ccn_scheduled_event *ev, int flags)
{
	my_lock();
	struct ccn_charbuf *name;
	long int rnum;
	char rnumstr[20];
	char lsdb_str[5];
	char nlsr_str[5];

	int res,i;
	int adl_element;

	rnum=random();
	memset(&rnumstr,0,20);
	sprintf(rnumstr,"%ld",rnum);
	memset(&nlsr_str,0,5);
	sprintf(nlsr_str,"nlsr");
	memset(&lsdb_str,0,5);
	sprintf(lsdb_str,"lsdb");
	

	struct ndn_neighbor *nbr;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee;
    	
    	hashtb_start(nlsr->adl, e);
	adl_element=hashtb_n(nlsr->adl);
	//int mynumber=15;

	for(i=0;i<adl_element;i++)
	{
		nbr=e->data;
		printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,lsdb_str);	
		name=ccn_charbuf_create();
		res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
		ccn_name_append_str(name,nlsr_str);
		ccn_name_append_str(name,lsdb_str);
		//ccn_name_append_str(name,rnumstr);

		/* adding Exclusion filter */
		
		struct ccn_charbuf *templ;
		templ = ccn_charbuf_create();

		struct ccn_charbuf *c;
		c = ccn_charbuf_create();


		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
		ccn_charbuf_append_closer(templ); /* </Name> */
		ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
		ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
		ccn_charbuf_reset(c);
		//ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
		//ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
		ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
		ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
		ccn_charbuf_append_closer(templ); /* </Exclude> */
		ccn_charbuf_append_closer(templ); /* </Interest> */

	
		/* Adding Exclusion filter done */
				
		res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
			
		if ( res >= 0 )
			printf("Interest sending Successfull .... \n");	
		ccn_charbuf_destroy(&c);
		ccn_charbuf_destroy(&templ);
		ccn_charbuf_destroy(&name);
	
		hashtb_next(e);		
	}

	hashtb_end(e);

	nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0);

	my_unlock();
	return 0;

}


int
send_info_interest(struct ccn_schedule *sched, void *clienth,
        struct ccn_scheduled_event *ev, int flags)
{

	my_lock();
	struct ccn_charbuf *name;
	long int rnum;
	char rnumstr[20];
	char info_str[5];
	char nlsr_str[5];

	int res,i;
	int adl_element;
	int scope = 2;  //no further than the next host

	rnum=random();
	memset(&rnumstr,0,20);
	sprintf(rnumstr,"%ld",rnum);
	memset(&nlsr_str,0,5);
	sprintf(nlsr_str,"nlsr");
	memset(&info_str,0,5);
	sprintf(info_str,"info");
	

	struct ndn_neighbor *nbr;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee;
    	
    	hashtb_start(nlsr->adl, e);
	adl_element=hashtb_n(nlsr->adl);
	//int mynumber=15;

	for(i=0;i<adl_element;i++)
	{
		nbr=e->data;
		printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,info_str);	
		name=ccn_charbuf_create();
		res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
		ccn_name_append_str(name,nlsr_str);
		ccn_name_append_str(name,info_str);
		//ccn_name_append_str(name,rnumstr);

		/* adding Exclusion filter */
		
		struct ccn_charbuf *templ;
		templ = ccn_charbuf_create();

//		struct ccn_charbuf *c;
//		c = ccn_charbuf_create();


		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
		ccn_charbuf_append_closer(templ); /* </Name> */
//		ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
//		ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
//		ccn_charbuf_reset(c);
//		//ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
//		//ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
//		ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
//		ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
//		ccn_charbuf_append_closer(templ); /* </Exclude> */
		ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
		appendLifetime(templ,nlsr->interest_resend_time);
		ccn_charbuf_append_closer(templ); /* </Interest> */


		/* Adding Exclusion filter done */
				
		res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
			
		if ( res >= 0 )
			printf("Interest sending Successfull .... \n");	
//		ccn_charbuf_destroy(&c);
		ccn_charbuf_destroy(&templ);
		ccn_charbuf_destroy(&name);
	
		hashtb_next(e);		
	}

	hashtb_end(e);

	//nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0);

	my_unlock();
	return 0;

}


void 
send_info_interest_to_neighbor(struct ccn_charbuf *nbr)
{

	my_lock();
	struct ccn_charbuf *name;
	long int rnum;
	char rnumstr[20];
	char info_str[5];
	char nlsr_str[5];

	int res;
	int scope = 2;  //no further than the next host

	rnum=random();
	memset(&rnumstr,0,20);
	sprintf(rnumstr,"%ld",rnum);
	memset(&nlsr_str,0,5);
	sprintf(nlsr_str,"nlsr");
	memset(&info_str,0,5);
	sprintf(info_str,"info");
	
	printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr),nlsr_str,info_str);	
	name=ccn_charbuf_create();
	res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr));
	ccn_name_append_str(name,nlsr_str);
	ccn_name_append_str(name,info_str);
	//ccn_name_append_str(name,rnumstr);

	/* adding Exclusion filter */
		
	struct ccn_charbuf *templ;
	templ = ccn_charbuf_create();

//	struct ccn_charbuf *c;
//	c = ccn_charbuf_create();


	ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
	ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
	ccn_charbuf_append_closer(templ); /* </Name> */
//	ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
//	ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
//	ccn_charbuf_reset(c);
//	//ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
//	//ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
//	ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
//	ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
//	ccn_charbuf_append_closer(templ); /* </Exclude> */
	ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
	appendLifetime(templ,15);
	ccn_charbuf_append_closer(templ); /* </Interest> */


	/* Adding Exclusion filter done */
				
	res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
			
	if ( res >= 0 )
		printf("Interest sending Successfull .... \n");	
//	ccn_charbuf_destroy(&c);
	ccn_charbuf_destroy(&templ);
	ccn_charbuf_destroy(&name);

	my_unlock();

}
