Fresh Rewritten Copy
diff --git a/Makefile b/Makefile
index de1f4c7..abfca2b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,14 @@
CC = cc
-CFLAGS = -g -Wall -Wpointer-arith -Wreturn-type -Wstrict-prototypes
+CFLAGS = -g -Wall
+#-Wpointer-arith -Wreturn-type -Wstrict-prototypes
LIBS = -lccn -lcrypto
PROGRAMS = nlsr
all: $(PROGRAMS)
-nlsr: nlsr.c nlsr_ndn.c nlsr_lsdb.c nlsr_adl.c utility.c
- $(CC) $(CFLAGS) nlsr.c nlsr_ndn.c nlsr_lsdb.c nlsr_adl.c utility.c -o nlsr $(LIBS)
+nlsr: nlsr.c nlsr_ndn.c nlsr_npl.c nlsr_adl.c nlsr_lsdb.c utility.c
+ $(CC) $(CFLAGS) nlsr.c nlsr_ndn.c nlsr_npl.c nlsr_adl.c nlsr_lsdb.c utility.c -o nlsr $(LIBS)
clean:
rm -f *.o
diff --git a/macbook.conf b/macbook.conf
index 0bab6de..7dc397b 100644
--- a/macbook.conf
+++ b/macbook.conf
@@ -1,6 +1,7 @@
router-name /ndn/memphis.edu/netlab/macbook
ccnneighbor /ndn/memphis.edu/netlab/pollux face2 10
ccnneighbor /ndn/memphis.edu/netlab/castor face3 8
+ccnneighbor /ndn/memphis.edu/netlab/maia face4 15
ccnname /ndn/memphis.edu/netlab/macbook/name1
ccnname /ndn/memphis.edu/netlab/macbook/test
lsdb-synch-interval 310
diff --git a/nlsr.c b/nlsr.c
index 9d7438e..266a901 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -8,6 +8,9 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <sys/types.h>
+#include <signal.h>
+
#include <ccn/ccn.h>
@@ -20,9 +23,9 @@
#include "nlsr.h"
#include "nlsr_ndn.h"
#include "nlsr_lsdb.h"
-#include "nlsr_adl.h"
#include "utility.h"
-
+#include "nlsr_npl.h"
+#include "nlsr_adl.h"
struct option longopts[] =
{
@@ -60,74 +63,13 @@
NULL
};
-void
-my_lock(void)
-{
- nlsr->semaphor=1;
-}
void
-my_unlock(void)
+nlsr_stop_signal_handler(int sig)
{
- nlsr->semaphor=0;
-}
-
-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;
- }
-
- nlsr->router_name->name=(char *)malloc(strlen(rtr_name)+1);
- memcpy(nlsr->router_name->name,rtr_name,strlen(rtr_name)+1);
- nlsr->router_name->length=strlen(rtr_name)+1;
-
-}
-
-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);
-
- struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- np->name=(char *)malloc(strlen(name)+1);
- memcpy(np->name,name,strlen(name)+1);
- np->length=strlen(name)+1;
-
- add_name_prefix_to_npl(np);
-
- free(np);
-
-
+ signal(sig, SIG_IGN);
+ nlsr_destroy();
+ exit(0);
}
void
@@ -167,16 +109,79 @@
return;
}
+ 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);
+
+ 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);
+
struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- np->name=(char *)malloc(strlen(rtr_name)+1);
- memcpy(np->name,rtr_name,strlen(rtr_name)+1);
- np->length=strlen(rtr_name)+1;
+ np->name=(char *)malloc(strlen(name)+1);
+ memset(np->name,0,strlen(name)+1);
+ memcpy(np->name,name,strlen(name)+1);
+ np->length=strlen(name)+1;
- add_adjacent_to_adl(np,face_id);
+ 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;
+ }
+
+
+ nlsr->router_name=(char *)malloc(strlen(rtr_name)+1);
+ 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)
{
@@ -253,6 +258,8 @@
}
+
+
void
process_conf_command(char *command)
{
@@ -295,6 +302,7 @@
}
}
+
int
readConfigFile(const char *filename)
{
@@ -323,175 +331,74 @@
return 0;
}
-void
-add_name_prefix_to_npl(struct name_prefix *np)
-{
-
-
- printf("\nadd_name_prefix called\n");
- printf("Name Prefix: %s and length: %d \n",np->name,np->length);
-
- struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
- int res;
-
- hashtb_start(nlsr->npl, e);
- res = hashtb_seek(e, np->name, np->length, 0);
-
- if(res == HT_NEW_ENTRY)
- {
-
- hnp = e->data;
- hnp->length=np->length;
- hnp->name=(char *)malloc(np->length);
- memcpy(hnp->name,np->name,np->length);
- }
-
- hashtb_end(e);
-
-
- printf("\n");
-
-}
-
-void
-print_name_prefix_from_npl(void)
-{
- printf("print_name_prefix_from_npl called \n");
- int i, npl_element;
- struct name_prefix *np;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->npl, e);
- npl_element=hashtb_n(nlsr->npl);
-
- for(i=0;i<npl_element;i++)
- {
- np=e->data;
- printf("Name Prefix: %s and Length: %d \n",np->name,np->length);
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
- printf("\n");
-}
-
-
void
nlsr_destroy( void )
{
printf("Freeing Allocated Memory....\n");
/* Destroying every hash table attached to each neighbor in ADL before destorying ADL */
-
- int i, element;
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- /*destroying NAME LSDB */
- struct nlsr *name_lsa;
- hashtb_start(nlsr->lsdb->name_lsdb, e);
- element=hashtb_n(nlsr->lsdb->name_lsdb);
-
- for(i=0;i<element;i++)
- {
- name_lsa=e->data;
- free(name_lsa);
- hashtb_next(e);
- }
-
- hashtb_end(e);
- hashtb_destroy(&nlsr->lsdb->name_lsdb);
-
-
- /*destroying ADJ LSDB */
- struct alsr *adj_lsa;
- hashtb_start(nlsr->lsdb->adj_lsdb, e);
- element=hashtb_n(nlsr->lsdb->adj_lsdb);
-
- for(i=0;i<element;i++)
- {
- adj_lsa=e->data;
- free(adj_lsa);
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
-
- hashtb_destroy(&nlsr->lsdb->adj_lsdb);
-
- /* Destroying NPL */
- struct ccn_charbuf *np;
- hashtb_start(nlsr->npl, e);
- element=hashtb_n(nlsr->npl);
-
- for(i=0;i<element;i++)
- {
- np=e->data;
- free(np);
- hashtb_next(e);
- }
- hashtb_end(e);
hashtb_destroy(&nlsr->npl);
-
- /* Destroying ADL */
- struct ndn_neighbor *nbr;
- hashtb_start(nlsr->adl, e);
- element=hashtb_n(nlsr->adl);
-
- for(i=0;i<element;i++)
- {
- nbr=e->data;
- free(nbr);
- hashtb_next(e);
- }
- hashtb_end(e);
- hashtb_destroy(&nlsr->adl);
-
-
+ hashtb_destroy(&nlsr->adl);
+ hashtb_destroy(&nlsr->lsdb->name_lsdb);
+ hashtb_destroy(&nlsr->lsdb->adj_lsdb);
+
ccn_schedule_destroy(&nlsr->sched);
ccn_destroy(&nlsr->ccn);
+
+ free(nlsr->lsdb->lsdb_version);
+ free(nlsr->lsdb);
+ free(nlsr->router_name);
free(nlsr);
printf("Finished freeing allocated memory\n");
}
+
void
init_nlsr(void)
{
- struct hashtb_param param_adl = {0};
- struct hashtb_param param_npl = {0};
+ if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR)
+ {
+ perror("SIGQUIT install error\n");
+ exit(1);
+ }
+ if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR)
+ {
+ perror("SIGTERM install error\n");
+ exit(1);
+ }
+ if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
+ {
+ perror("SIGTERM install error\n");
+ exit(1);
+ }
- struct hashtb_param param_adj_lsdb = {0};
- struct hashtb_param param_name_lsdb = {0};
-
nlsr=(struct nlsr *)malloc(sizeof(struct nlsr));
-
+
+ struct hashtb_param param_adl = {0};
nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), ¶m_adl);
- nlsr->npl = hashtb_create(sizeof(struct name_prefix ), ¶m_npl);
+ struct hashtb_param param_npl = {0};
+ nlsr->npl = hashtb_create(sizeof(struct name_prefix), ¶m_npl);
nlsr->in_interest.p = &incoming_interest;
nlsr->in_content.p = &incoming_content;
- nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase ));
- char *time_stamp=get_current_timestamp_micro();
- nlsr->lsdb->version=(char *)malloc(strlen(time_stamp)+1);
- memcpy(nlsr->lsdb->version,time_stamp,strlen(time_stamp)+1);
- memset(nlsr->lsdb->version,'0',strlen(time_stamp));
-
+ nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
+ char *time_stamp=(char *)malloc(20);
+ 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));
+ free(time_stamp);
+
+ struct hashtb_param param_adj_lsdb = {0};
nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), ¶m_adj_lsdb);
+ struct hashtb_param param_name_lsdb = {0};
nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), ¶m_name_lsdb);
- nlsr->router_name=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
nlsr->is_synch_init=1;
nlsr->nlsa_id=0;
@@ -505,19 +412,17 @@
nlsr->interest_resend_time = INTEREST_RESEND_TIME;
nlsr->semaphor=0;
-
-
}
+
int
main(int argc, char *argv[])
{
int res;
char *config_file;
//int daemon_mode;
-
- init_nlsr();
+ init_nlsr();
while ((res = getopt_long(argc, argv, "df:h", longopts, 0)) != -1)
{
@@ -539,58 +444,49 @@
nlsr->ccn=ccn_create();
if(ccn_connect(nlsr->ccn, NULL) == -1)
- {
- fprintf(stderr,"Could not connect to ccnd\n");
- exit(1);
- }
+ {
+ fprintf(stderr,"Could not connect to ccnd\n");
+ exit(1);
+ }
struct ccn_charbuf *router_prefix;
- router_prefix=ccn_charbuf_create();
- res=ccn_name_from_uri(router_prefix,nlsr->router_name->name);
+ 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->name);
- exit(1);
- }
+ {
+ fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
+ exit(1);
+ }
ccn_name_append_str(router_prefix,"nlsr");
- nlsr->in_interest.data=nlsr->router_name->name;
+ 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");
- exit(1);
- }
+ {
+ fprintf(stderr,"Failed to register interest for router\n");
+ exit(1);
+ }
+ ccn_charbuf_destroy(&router_prefix);
+
+ printf("Router Name : %s\n",nlsr->router_name);
+ printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
- /* Debugging purpose */
print_name_prefix_from_npl();
print_adjacent_from_adl();
-
- printf("\n");
- printf("Router Name: %s\n",nlsr->router_name->name);
- printf("Time in MicroSec: %s \n",get_current_timestamp_micro());
- printf("LSDB Version: %s\n",nlsr->lsdb->version);
- printf("\n");
-
build_and_install_name_lsas();
print_name_lsdb();
nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
- nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 500, &send_info_interest, NULL, 0);
-
-
+ nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
while(1)
- {
- if(nlsr->semaphor == 0)
- {
- ccn_schedule_run(nlsr->sched);
- res = ccn_run(nlsr->ccn, 500);
- }
+ {
+ ccn_schedule_run(nlsr->sched);
+ res = ccn_run(nlsr->ccn, 500);
}
-
- nlsr_destroy();
+
+ nlsr_destroy();
return 0;
}
diff --git a/nlsr.h b/nlsr.h
index fdde154..27b4adc 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -1,39 +1,22 @@
#ifndef _NLSR_H_
#define _NLSR_H_
-#define LSA_ADJ_TYPE 1
-#define LSA_NAME_TYPE 2
+
#define LSDB_SYNCH_INTERVAL 300
#define INTEREST_RETRY 3
#define INTEREST_RESEND_TIME 15
-#define NBR_DOWN 0
-#define NBR_ACTIVE 1
-
struct name_prefix
{
char *name;
int length;
};
-struct ndn_neighbor
-{
- struct name_prefix *neighbor;
- int face;
- int status;
- char * last_lsdb_version;
- int info_interest_timed_out;
- long int lsdb_synch_interval;
- long int last_lsdb_requested;
- int is_lsdb_send_interest_scheduled;
- int metric;
-};
-
struct linkStateDatabase
{
- char * version;
- struct hashtb *adj_lsdb;
struct hashtb *name_lsdb;
+ struct hashtb *adj_lsdb;
+ char *lsdb_version;
};
struct nlsr
@@ -51,11 +34,13 @@
struct hashtb *adl;
struct hashtb *npl;
- struct ccn *ccn;
- struct name_prefix *router_name;
-
struct linkStateDatabase *lsdb;
+ struct ccn *ccn;
+ char *router_name;
+
+
+
int is_synch_init;
long int nlsa_id;
int adj_build_flag;
@@ -73,26 +58,16 @@
struct nlsr *nlsr;
-void init_nlsr(void);
-
-void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result);
-void process_command_router_name(char *command);
-void process_command_ccnname(char *command);
void process_command_ccnneighbor(char *command);
+void process_command_ccnname(char *command);
void process_command_lsdb_synch_interval(char *command);
void process_command_interest_retry(char *command);
void process_command_interest_resend_time(char *command);
void process_conf_command(char *command);
int readConfigFile(const char *filename);
-void add_name_prefix_to_npl(struct name_prefix *np);
-void print_name_prefix_from_npl(void);
-
-void my_lock(void);
-void my_unlock(void);
-
-
-
+void init_nlsr(void);
void nlsr_destroy( void );
+void nlsr_stop_signal_handler(int sig);
#endif
diff --git a/nlsr_adl.c b/nlsr_adl.c
index 7ebc8af..c04aeda 100644
--- a/nlsr_adl.c
+++ b/nlsr_adl.c
@@ -18,34 +18,31 @@
#include <ccn/hashtb.h>
#include "nlsr.h"
-#include "nlsr_ndn.h"
-#include "utility.h"
+#include "nlsr_npl.h"
#include "nlsr_adl.h"
+#include "utility.h"
-void
-add_adjacent_to_adl(struct name_prefix *np, int face)
+void
+add_nbr_to_adl(struct name_prefix *new_nbr,int face)
{
- printf("\nadd_adjacent_to_adl called\n");
- printf("Neighbor: %s Length: %d Face:%d\n",np->name,np->length,face);
-
- struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor));
+ struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
int res;
hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, np->name, np->length, 0);
+ res = hashtb_seek(e, new_nbr->name, new_nbr->length, 0);
if(res == HT_NEW_ENTRY )
{
nbr = e->data;
- nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix ));
- nbr->neighbor->name=(char *)malloc(np->length);
- memcpy(nbr->neighbor->name,np->name,np->length);
- nbr->neighbor->length=np->length;
+ nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free
+ nbr->neighbor->name=(char *)malloc(new_nbr->length);
+ memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length);
+ nbr->neighbor->length=new_nbr->length;
nbr->face=face;
nbr->status=NBR_DOWN;
nbr->info_interest_timed_out=0;
@@ -53,28 +50,28 @@
nbr->metric=10;
nbr->is_lsdb_send_interest_scheduled=0;
-
- char *time_stamp=get_current_timestamp_micro();
- nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1);
+ char *time_stamp=(char *)malloc(20);
+ get_current_timestamp_micro(time_stamp);
+ nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free
memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
memset(nbr->last_lsdb_version,'0',strlen(time_stamp));
+ nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free
+ memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1);
+ memset(nbr->last_info_version,'0',strlen(time_stamp));
+ free(time_stamp);
nbr->last_lsdb_requested=0;
-
- //nbr->last_lsdb_requested=(char *)malloc(strlen(time_stamp)+1);
- //memcpy(nbr->last_lsdb_requested,time_stamp,strlen(time_stamp)+1);
- //memset(nbr->last_lsdb_requested,'0',strlen(time_stamp));
-
}
hashtb_end(e);
}
+
void
print_adjacent(struct ndn_neighbor *nbr)
{
- printf("\nprint_adjacent called\n");
+ printf("print_adjacent called\n");
printf("--------Neighbor---------------------------\n");
printf(" Neighbor: %s \n",nbr->neighbor->name);
printf(" Length : %d \n",nbr->neighbor->length);
@@ -82,9 +79,13 @@
printf(" Metric : %d \n",nbr->metric);
printf(" Status : %d \n",nbr->status);
printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
+ printf(" Info Version: %s \n",nbr->last_info_version);
printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
+ printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
+
+ printf("\n");
}
@@ -113,11 +114,108 @@
}
+int
+get_adjacent_status(struct name_prefix *nbr)
+{
+ printf("get_adjacent_status called \n");
+
+ int res;
+ int status=-1;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr->name, nbr->length, 0);
+
+ if (res == HT_OLD_ENTRY)
+ {
+ nnbr=e->data;
+ status=nnbr->status;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+
+ return status;
+
+}
+
+int
+get_timed_out_number(struct name_prefix *nbr)
+{
+ printf("get_timed_out_number called \n");
+
+ int res,ret=-1;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr->name, nbr->length, 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ nnbr=e->data;
+ ret=nnbr->info_interest_timed_out;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+
+ return ret;
+}
+
+
+void
+update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
+{
+ printf("update_adjacent_timed_out_to_adl called \n");
+
+ int res;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr->name, nbr->length, 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ nnbr=e->data;
+ nnbr->info_interest_timed_out += increment;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+}
+
+void
+update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
+{
+ printf("update_adjacent_timed_out_zero_to_adl called \n");
+ int time_out_number=get_timed_out_number(nbr);
+ update_adjacent_timed_out_to_adl(nbr,-time_out_number);
+
+}
+
void
update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
{
printf("update_adjacent_status_to_adl called \n");
- //int ret;
+
int res;
struct ndn_neighbor *nnbr;
@@ -166,7 +264,7 @@
if ( nnbr->lsdb_synch_interval!= interval )
{
nnbr->lsdb_synch_interval=interval;
-
+
}
}
else if(res == HT_NEW_ENTRY)
@@ -175,108 +273,32 @@
}
hashtb_end(e);
-
-
}
-void
-update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
-{
- printf("update_adjacent_timed_out_to_adl called \n");
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr->name, nbr->length, 0);
-
- if( res == HT_OLD_ENTRY )
- {
- nnbr=e->data;
- nnbr->info_interest_timed_out += increment;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-}
-
-void
-update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
-{
- printf("update_adjacent_timed_out_zero_to_adl called \n");
- int time_out_number=get_timed_out_number(nbr);
- update_adjacent_timed_out_to_adl(nbr,-time_out_number);
-
-}
-
-
-void
-update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
-{
- printf("update_adjacent_timed_out_to_adl called \n");
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr->name, nbr->length, 0);
-
- if( res == HT_OLD_ENTRY )
- {
- nnbr=e->data;
- free(nnbr->last_lsdb_version);
- nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
- memset(nnbr->last_lsdb_version,0,strlen(version)+1);
- memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
-}
-
int
-get_timed_out_number(struct name_prefix *nbr)
+no_active_nbr(void)
{
- printf("get_timed_out_number called \n");
-
- int res,ret=-1;
- struct ndn_neighbor *nnbr;
-
+ int i, adl_element;
+ int no_link=0;
+ struct ndn_neighbor *nbr;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
+ hashtb_start(nlsr->adl, e);
+ adl_element=hashtb_n(nlsr->adl);
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr->name, nbr->length, 0);
-
- if( res == HT_OLD_ENTRY )
+ for(i=0;i<adl_element;i++)
{
- nnbr=e->data;
- ret=nnbr->info_interest_timed_out;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
+ nbr=e->data;
+ if( nbr->status == 1 )
+ no_link++;
+ hashtb_next(e);
}
hashtb_end(e);
- return ret;
+ return no_link;
- return 0;
}
int
@@ -312,87 +334,10 @@
hashtb_end(e);
if(nbr_count == adl_element)
ret=1;
-
+
return ret;
}
-int
-no_active_nbr(void)
-{
- int i, adl_element;
- int no_link=0;
- struct ndn_neighbor *nbr;
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
- hashtb_start(nlsr->adl, e);
- adl_element=hashtb_n(nlsr->adl);
-
- for(i=0;i<adl_element;i++)
- {
- nbr=e->data;
- if( nbr->status == 1 )
- no_link++;
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
- return no_link;
-
-}
-
-long int
-len_active_nbr_data(void)
-{
- int i, adl_element;
- int no_link=0;
- long int len=0;
- struct ndn_neighbor *nbr;
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
- hashtb_start(nlsr->adl, e);
- adl_element=hashtb_n(nlsr->adl);
-
- for(i=0;i<adl_element;i++)
- {
- nbr=e->data;
- if( nbr->status == 1 )
- {
- char *temp_face=(char *)malloc(20);
- char *temp_metric=(char *)malloc(20);
- char *temp_length=(char *)malloc(20);
-
- len+=strlen(nbr->neighbor->name);
-
- memset( temp_face,0,20);
- sprintf(temp_face,"%d",nbr->face);
- len+=strlen(temp_face);
-
- memset( temp_metric,0,20);
- sprintf(temp_face,"%d",nbr->metric);
- len+=strlen(temp_metric);
-
- memset( temp_length,0,20);
- sprintf(temp_length,"%d",nbr->neighbor->length);
- len+=strlen(temp_length);
-
- no_link++;
-
- free(temp_face);
- free(temp_metric);
- free(temp_length);
-
- }
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
- len=len+ no_link*4+1;
-
- return len;
-
-}
void
get_active_nbr_adj_data(struct ccn_charbuf *c)
@@ -412,7 +357,7 @@
{
ccn_charbuf_append_string(c,nbr->neighbor->name);
ccn_charbuf_append_string(c,"|");
-
+
char *temp_length=(char *)malloc(20);
memset(temp_length,0,20);
sprintf(temp_length,"%d",nbr->neighbor->length);
@@ -441,6 +386,104 @@
hashtb_end(e);
}
+long int
+get_nbr_time_diff_lsdb_req(char *nbr)
+{
+ printf("get_nbr_time_diff_lsdb_req called \n");
+
+ long int time_diff=get_lsdb_synch_interval(nbr)+1;
+ int res;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
+
+ if (res == HT_OLD_ENTRY)
+ {
+ nnbr=e->data;
+
+ if (nnbr->last_lsdb_requested == 0)
+ time_diff=get_lsdb_synch_interval(nbr)+1;
+ else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
+
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+
+ return time_diff;
+}
+
+long int
+get_nbr_last_lsdb_requested(char *nbr)
+{
+ printf("get_timed_out_number called \n");
+
+ long int last_lsdb_requested=0;
+
+ int res;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
+
+ if (res == HT_OLD_ENTRY)
+ {
+ nnbr=e->data;
+ last_lsdb_requested=nnbr->last_lsdb_requested;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+
+ return last_lsdb_requested;
+}
+
+long int
+get_lsdb_synch_interval(char *nbr)
+{
+ printf("get_lsdb_synch_interval called \n");
+
+ long int lsdb_synch_interval=300;
+
+
+ int res;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
+
+ if (res == HT_OLD_ENTRY)
+ {
+ nnbr=e->data;
+ lsdb_synch_interval=nnbr->lsdb_synch_interval;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+
+ return lsdb_synch_interval;
+
+}
+
char *
get_nbr_lsdb_version(char *nbr)
{
@@ -456,7 +499,7 @@
hashtb_start(nlsr->adl, e);
res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
+
if (res == HT_OLD_ENTRY)
{
nnbr=e->data;
@@ -492,7 +535,64 @@
{
nnbr=e->data;
nnbr->last_lsdb_requested=timestamp;
-
+
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+}
+
+void
+set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
+{
+ printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
+
+ int res;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
+
+ if (res == HT_OLD_ENTRY)
+ {
+ nnbr=e->data;
+ nnbr->is_lsdb_send_interest_scheduled=0;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+}
+
+void
+update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
+{
+ printf("update_adjacent_timed_out_to_adl called \n");
+
+ int res;
+ struct ndn_neighbor *nnbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr->name, nbr->length, 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ nnbr=e->data;
+ free(nnbr->last_lsdb_version);
+ nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
+ memset(nnbr->last_lsdb_version,0,strlen(version)+1);
+ memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
}
else if(res == HT_NEW_ENTRY)
{
@@ -521,7 +621,7 @@
{
nnbr=e->data;
nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
-
+
}
else if(res == HT_NEW_ENTRY)
{
@@ -533,161 +633,3 @@
}
-long int
-get_nbr_last_lsdb_requested(char *nbr)
-{
- printf("get_timed_out_number called \n");
-
- long int last_lsdb_requested=0;
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- last_lsdb_requested=nnbr->last_lsdb_requested;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return last_lsdb_requested;
-}
-
-long int
-get_nbr_time_diff_lsdb_req(char *nbr)
-{
- printf("get_nbr_time_diff_lsdb_req called \n");
-
- long int time_diff=get_lsdb_synch_interval(nbr)+1;
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
-
- if (nnbr->last_lsdb_requested == 0)
- time_diff=get_lsdb_synch_interval(nbr)+1;
- else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
-
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return time_diff;
-}
-
-long int
-get_lsdb_synch_interval(char *nbr)
-{
- printf("get_lsdb_synch_interval called \n");
-
- long int lsdb_synch_interval=300;
-
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- lsdb_synch_interval=nnbr->lsdb_synch_interval;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return lsdb_synch_interval;
-
-}
-
-void
-set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
-{
- printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
-
- int res;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- nnbr->is_lsdb_send_interest_scheduled=0;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
-}
-
-
-int
-get_adjacent_status(struct name_prefix *nbr)
-{
- printf("get_adjacent_status called \n");
-
- int res;
- int status=-1;
- struct ndn_neighbor *nnbr;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- hashtb_start(nlsr->adl, e);
- res = hashtb_seek(e, nbr->name, nbr->length, 0);
-
- if (res == HT_OLD_ENTRY)
- {
- nnbr=e->data;
- status=nnbr->status;
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
-
- return status;
-
-}
-
diff --git a/nlsr_adl.h b/nlsr_adl.h
index 7879aa8..64d19d6 100644
--- a/nlsr_adl.h
+++ b/nlsr_adl.h
@@ -1,34 +1,42 @@
#ifndef _NLSR_ADL_H_
#define _NLSR_ADL_H_
-#define NBR_ACTIVE 1
#define NBR_DOWN 0
+#define NBR_ACTIVE 1
-void add_adjacent_to_adl(struct name_prefix *np, int face);
+struct ndn_neighbor
+{
+ struct name_prefix *neighbor;
+ int face;
+ int status;
+ char * last_lsdb_version;
+ char * last_info_version;
+ int info_interest_timed_out;
+ long int lsdb_synch_interval;
+ long int last_lsdb_requested;
+ int is_lsdb_send_interest_scheduled;
+ int metric;
+};
+
+void add_nbr_to_adl(struct name_prefix *new_nbr,int face);
void print_adjacent(struct ndn_neighbor *nbr);
void print_adjacent_from_adl(void);
-void update_adjacent_status_to_adl(struct name_prefix *nbr, int status);
int get_adjacent_status(struct name_prefix *nbr);
-void update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char * version);
-void update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval);
-
int get_timed_out_number(struct name_prefix *nbr);
void update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment);
void update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr);
-
-int is_adj_lsa_build(void);
+void update_adjacent_status_to_adl(struct name_prefix *nbr, int status);
+void update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval);
int no_active_nbr(void);
-long int len_active_nbr_data(void);
+int is_adj_lsa_build(void);
void get_active_nbr_adj_data(struct ccn_charbuf *c);
+long int get_nbr_time_diff_lsdb_req(char *nbr);
+long int get_nbr_last_lsdb_requested(char *nbr);
+long int get_nbr_last_lsdb_requested(char *nbr);
+long int get_lsdb_synch_interval(char *nbr);
char * get_nbr_lsdb_version(char *nbr);
void update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp);
-long int get_nbr_last_lsdb_requested(char *nbr);
-long int get_nbr_time_diff_lsdb_req(char *nbr);
-long int get_lsdb_synch_interval(char *nbr);
void set_is_lsdb_send_interest_scheduled_to_zero(char *nbr);
-
+void update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version);
void adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec);
-//long int get_lsdb_synch_interval(char *nbr);
-
-
#endif
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index 39a0322..29c7440 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -18,24 +18,53 @@
#include <ccn/hashtb.h>
#include "nlsr.h"
+#include "nlsr_ndn.h"
#include "nlsr_lsdb.h"
#include "utility.h"
-#include "nlsr_ndn.h"
+#include "nlsr_npl.h"
#include "nlsr_adl.h"
void
set_new_lsdb_version(void)
{
- char *time_stamp=get_current_timestamp_micro();
+ char *time_stamp=(char *)malloc(20);
+ memset(time_stamp,0,20);
+ get_current_timestamp_micro(time_stamp);
- free(nlsr->lsdb->version);
- nlsr->lsdb->version=(char *)malloc(strlen(time_stamp)+1);
- memset(nlsr->lsdb->version,0,strlen(time_stamp)+1);
- memcpy(nlsr->lsdb->version,time_stamp,strlen(time_stamp)+1);
+ free(nlsr->lsdb->lsdb_version);
+ nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
+ memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
+ memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
+
+ free(time_stamp);
}
+void
+make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
+{
+
+
+ printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
+
+ char lst[2];
+ memset(lst,0,2);
+ sprintf(lst,"%d",ls_type);
+
+ char lsid[10];
+ memset(lsid,0,10);
+ sprintf(lsid,"%ld",ls_id);
+
+ memcpy(key+strlen(key),orig_router,strlen(orig_router));
+ memcpy(key+strlen(key),"/",1);
+ memcpy(key+strlen(key),lst,strlen(lst));
+ memcpy(key+strlen(key),"/",1);
+ memcpy(key+strlen(key),lsid,strlen(lsid));
+
+ printf("Key: %s\n",key);
+
+}
void
build_and_install_name_lsas(void)
@@ -56,8 +85,13 @@
np=e->data;
struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
build_name_lsa(name_lsa,np);
- print_name_lsa(name_lsa);
+
install_name_lsa(name_lsa);
+ free(name_lsa->header->orig_router->name);
+ free(name_lsa->header->orig_router);
+ free(name_lsa->header);
+ free(name_lsa->name_prefix->name);
+ free(name_lsa->name_prefix);
free(name_lsa);
hashtb_next(e);
}
@@ -66,72 +100,28 @@
}
-void
-build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,int isValid,char *np)
-{
- printf("build_and_install_others_name_lsa called \n");
-
- struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
- build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,isValid,np);
- print_name_lsa(name_lsa);
- install_name_lsa(name_lsa);
- print_name_lsdb();
- free(name_lsa);
-}
-
-void
-build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,int isValid,char *np)
-{
- printf("build_others_name_lsa called \n");
-
- name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
- name_lsa->header->ls_type=LS_TYPE_NAME;
-
- char *time_stamp=get_current_timestamp_micro();
-
- name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
- memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
- memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
-
- name_lsa->header->ls_id=ls_id;
- name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
- memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
- memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
- name_lsa->header->orig_router->length=strlen(orig_router)+1;
- name_lsa->header->isValid=isValid;
-
- name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
- memset(name_lsa->name_prefix->name,0,strlen(np)+1);
- memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
- name_lsa->name_prefix->length=strlen(np)+1;
-
-
-}
-
void
build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
{
- printf("build_name_lsa called \n");
-
name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
name_lsa->header->ls_type=LS_TYPE_NAME;
- char *time_stamp=get_current_timestamp_micro();
+ char *time_stamp=(char *)malloc(20);
+ memset(time_stamp,0,20);
+ get_current_timestamp_micro(time_stamp);
- name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
+ name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
- name_lsa->header->orig_time[strlen(name_lsa->header->orig_time)]='\0';
-
- printf("Orig Time: %s\n",name_lsa->header->orig_time);
+
+ free(time_stamp);
name_lsa->header->ls_id=++nlsr->nlsa_id;
name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- name_lsa->header->orig_router->name=(char *)malloc(nlsr->router_name->length);
- memcpy(name_lsa->header->orig_router->name,nlsr->router_name->name,nlsr->router_name->length);
- name_lsa->header->orig_router->length=nlsr->router_name->length;
+ name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
+ memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
+ memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
+ name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
name_lsa->header->isValid=1;
@@ -142,37 +132,27 @@
}
-
-void
-print_name_lsa(struct nlsa *name_lsa)
-{
- printf("print_name_lsa called \n");
-
- printf("-----------Name LSA Content---------------\n");
- printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
- printf(" Origination Router Length: %d\n",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 : %s\n",name_lsa->header->orig_time);
- printf(" Is Valid : %d\n",name_lsa->header->isValid);
- printf(" LSA Data \n");
- printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
- printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
-
- printf("\n");
-}
-
void
install_name_lsa(struct nlsa *name_lsa)
{
- printf("install_name_lsa called \n");
- print_name_lsa(name_lsa);
+ char lst[2];
+ memset(lst,0,2);
+ sprintf(lst,"%d",name_lsa->header->ls_type);
- char *key=make_name_lsa_key(name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
+ char lsid[10];
+ memset(lsid,0,10);
+ sprintf(lsid,"%ld",name_lsa->header->ls_id);
+
+
+ char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
+ memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
+
+
+ make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
printf("Key:%s Length:%d\n",key,(int)strlen(key));
- struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
+ struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -186,32 +166,31 @@
printf("New Name LSA... Adding to LSDB\n");
new_name_lsa = e->data;
- new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
+ new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
new_name_lsa->header->ls_type=name_lsa->header->ls_type;
new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
+ memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
- printf("Orig Time: %s\n",new_name_lsa->header->orig_time);
-
new_name_lsa->header->ls_id=name_lsa->header->ls_id;
- new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
new_name_lsa->header->isValid=name_lsa->header->isValid;
- new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
printf("New Name LSA Added....\n");
- printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version);
+ printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
set_new_lsdb_version();
- printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
+ printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
}
else if(res == HT_OLD_ENTRY)
@@ -221,37 +200,27 @@
}
hashtb_end(e);
+
+ free(key);
}
-char *
-make_name_lsa_key(char *orig_router, int ls_type, long int ls_id)
+void
+print_name_lsa(struct nlsa *name_lsa)
{
-
- printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
+ printf("-----------Name LSA Content---------------\n");
+ printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
+ printf(" Origination Router Length: %d\n",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 : %s\n",name_lsa->header->orig_time);
+ printf(" Is Valid : %d\n",name_lsa->header->isValid);
+ printf(" LSA Data \n");
+ printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
+ printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
- char lst[2];
- memset(lst,0,2);
- sprintf(lst,"%d",ls_type);
-
- char lsid[10];
- memset(lsid,0,10);
- sprintf(lsid,"%ld",ls_id);
-
-
- char *key=(char *)malloc(strlen(orig_router)+1+strlen(lst)+1+strlen(lsid)+1);
- memset(key,0,strlen(orig_router)+1+strlen(lst)+1+strlen(lsid)+1);
- memcpy(key+strlen(key),orig_router,strlen(orig_router));
- memcpy(key+strlen(key),"/",1);
- memcpy(key+strlen(key),lst,strlen(lst));
- memcpy(key+strlen(key),"/",1);
- memcpy(key+strlen(key),lsid,strlen(lsid));
-
- printf("Key: %s\n",key);
-
- return key;
-
+ printf("\n");
}
void
@@ -280,138 +249,53 @@
printf("\n");
}
-int
-build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+
+void
+build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
{
- printf("build_and_install_adj_lsa called \n");
- my_lock();
+ printf("build_and_install_others_name_lsa called \n");
- printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
+ struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
+ build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
+ print_name_lsa(name_lsa);
+ install_name_lsa(name_lsa);
+ print_name_lsdb();
- if(nlsr->adj_build_flag > 0)
- {
- printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
- if ( is_adj_lsa_build()> 0)
- {
- struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
- build_adj_lsa(adj_lsa);
- print_adj_lsa(adj_lsa);
- install_adj_lsa(adj_lsa);
- free(adj_lsa);
- nlsr->adj_build_flag=0;
- print_adj_lsdb();
- }
- else
- {
- printf("Can not build adj LSA now\n");
- }
- }
- nlsr->is_build_adj_lsa_sheduled=0;
- my_unlock();
- return 0;
-}
-
-void
-build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data)
-{
- printf("build_and_install_others_adj_lsa called \n");
- struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
- build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
- print_adj_lsa(adj_lsa);
- install_adj_lsa(adj_lsa);
- free(adj_lsa);
- print_adj_lsdb();
-
-}
-
-void
-build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data)
-{
- printf("build_others_adj_lsa called \n");
-
- /*Filling Up Header Data */
- adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
- adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
- memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
- memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
-
- adj_lsa->header->orig_router->length=strlen(orig_router)+1;
-
- adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
-
- adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
- memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
- memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
-
- adj_lsa->no_link=no_link;
-
- adj_lsa->body=(char *)malloc(strlen(data)+1);
- memset(adj_lsa->body,0,strlen(data)+1);
- memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
+ free(name_lsa->header->orig_router->name);
+ free(name_lsa->header->orig_router);
+ free(name_lsa->header);
+ free(name_lsa->name_prefix->name);
+ free(name_lsa->name_prefix);
+ free(name_lsa);
}
void
-build_adj_lsa(struct alsa * adj_lsa)
+build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
{
- printf("build_adj_lsa called \n");
-
- int no_link=no_active_nbr();
- printf("Number of link in Adjacent LSA: %d\n",no_link);
-
- /*Filling Up Header Data */
- adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
- adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
+ printf("build_others_name_lsa called \n");
- char *time_stamp=get_current_timestamp_micro();
- adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
- memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
- memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
- adj_lsa->header->orig_time[strlen(adj_lsa->header->orig_time)]='\0';
+ name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
+ name_lsa->header->ls_type=LS_TYPE_NAME;
- printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length);
+ name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
+ memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
+ memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
- char *temp_r=(char *)malloc(nlsr->router_name->length);
- memset(temp_r,0,nlsr->router_name->length);
- sprintf(temp_r,"%s",nlsr->router_name->name);
- printf("Router Name: %s Length: %d \n",temp_r,(int)strlen(temp_r)+1);
-
- adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- adj_lsa->header->orig_router->name=(char *)malloc(strlen(temp_r)+1);
- memset(adj_lsa->header->orig_router->name,0,strlen(temp_r)+1);
- memcpy(adj_lsa->header->orig_router->name,temp_r,strlen(temp_r)+1);
+ name_lsa->header->ls_id=ls_id;
+ name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
+ memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
+ memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
+ name_lsa->header->orig_router->length=strlen(orig_router)+1;
+ name_lsa->header->isValid=isValid;
- adj_lsa->header->orig_router->length=strlen(temp_r)+1;
- printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length);
-
- /* Filling Up Body Data */
-
- adj_lsa->no_link=no_link;
-
-
- struct ccn_charbuf *c=ccn_charbuf_create();
- get_active_nbr_adj_data(c);
- char *data=ccn_charbuf_as_string(c);
- printf("Adjacent data: %s \n",data);
-
- adj_lsa->body=(char *)malloc(strlen(data)+1);
- memset(adj_lsa->body,0,strlen(data)+1);
- memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
-
-
- ccn_charbuf_destroy(&c);
-
- if( !nlsr->is_send_lsdb_interest_scheduled )
- {
- nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
- nlsr->is_send_lsdb_interest_scheduled=1;
- }
- nlsr->adj_build_count++;
-
-
- free(temp_r);
+ name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
+ memset(name_lsa->name_prefix->name,0,strlen(np)+1);
+ memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
+ name_lsa->name_prefix->length=strlen(np)+1;
}
@@ -426,6 +310,131 @@
key[strlen(key)]='\0';
}
+int
+build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+ printf("build_and_install_adj_lsa called \n");
+
+ printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
+
+ if(nlsr->adj_build_flag > 0)
+ {
+ printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
+ if ( is_adj_lsa_build()> 0)
+ {
+ struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
+ build_adj_lsa(adj_lsa);
+ install_adj_lsa(adj_lsa);
+
+ free(adj_lsa->header->orig_router->name);
+ free(adj_lsa->header->orig_router);
+ free(adj_lsa->header->orig_time);
+ free(adj_lsa->header);
+ free(adj_lsa->body);
+ free(adj_lsa);
+ nlsr->adj_build_flag=0;
+ print_adj_lsdb();
+ }
+ else
+ {
+ printf("Can not build adj LSA now\n");
+ }
+ }
+ nlsr->is_build_adj_lsa_sheduled=0;
+ return 0;
+}
+
+
+void
+build_adj_lsa(struct alsa * adj_lsa)
+{
+ printf("build_adj_lsa called \n");
+
+ int no_link=no_active_nbr();
+ printf("Number of link in Adjacent LSA: %d\n",no_link);
+
+ /*Filling Up Header Data */
+ adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+ adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
+ memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
+ memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
+ adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
+
+ adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
+
+ char *time_stamp=(char *)malloc(20);
+ memset(time_stamp,0,20);
+ get_current_timestamp_micro(time_stamp);
+
+ adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
+ memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
+ memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
+ free(time_stamp);
+
+
+ /* Filling Up Body Data */
+
+ adj_lsa->no_link=no_link;
+/*
+ struct link *templ=(struct link *)malloc(2*sizeof(struct link));
+ adj_lsa->links=templ;
+
+ int i, adl_element;
+ struct ndn_neighbor *nbr;
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ hashtb_start(nlsr->adl, e);
+ adl_element=hashtb_n(nlsr->adl);
+
+ for(i=0;i<adl_element;i++)
+ {
+ nbr=e->data;
+ if( nbr->status == 1 )
+ {
+ struct link *temp=(struct link *)malloc(sizeof(struct link));
+ temp->nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix));
+ temp->nbr->name=(char *)malloc(nbr->neighbor->length);
+ memset(temp->nbr->name,0,nbr->neighbor->length);
+ memcpy(temp->nbr->name,nbr->neighbor->name,nbr->neighbor->length);
+
+ temp->nbr->length=nbr->neighbor->length;
+ temp->face=nbr->face;
+ temp->metric=nbr->metric;
+
+ templ=temp;
+ templ++;
+ }
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+*/
+
+
+ struct ccn_charbuf *c=ccn_charbuf_create();
+ get_active_nbr_adj_data(c);
+ char *data=ccn_charbuf_as_string(c);
+
+ adj_lsa->body=(char *)malloc(strlen(data)+1);
+ memset(adj_lsa->body,0,strlen(data)+1);
+ memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
+ ccn_charbuf_destroy(&c);
+
+
+
+ if( !nlsr->is_send_lsdb_interest_scheduled )
+ {
+ nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
+ nlsr->is_send_lsdb_interest_scheduled=1;
+ }
+
+ nlsr->adj_build_count++;
+
+
+}
+
+
void
install_adj_lsa(struct alsa * adj_lsa)
{
@@ -435,7 +444,7 @@
memset(key,0,adj_lsa->header->orig_router->length+2);
make_adj_lsa_key(key,adj_lsa);
printf("Adjacent LSA key: %s \n",key);
-
+
struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
struct hashtb_enumerator ee;
@@ -445,7 +454,7 @@
hashtb_start(nlsr->lsdb->adj_lsdb, e);
res = hashtb_seek(e, key, strlen(key), 0);
-
+
if(res == HT_NEW_ENTRY )
{
@@ -461,17 +470,17 @@
new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
-
- new_adj_lsa->no_link=adj_lsa->no_link;
+ new_adj_lsa->no_link=adj_lsa->no_link;
+
new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
- printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version);
+ printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
set_new_lsdb_version();
- printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
-
+ printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+
}
else if(res == HT_OLD_ENTRY)
@@ -488,24 +497,23 @@
free(new_adj_lsa->header->orig_time);
new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
-
- new_adj_lsa->no_link=adj_lsa->no_link;
- free(new_adj_lsa->body);
+ new_adj_lsa->no_link=adj_lsa->no_link;
+
new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
- printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version);
+ printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
set_new_lsdb_version();
- printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version);
+ printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
}
}
hashtb_end(e);
-
+
free(key);
}
@@ -523,9 +531,6 @@
char *face;
char *metric;
- printf(" Lsa Data:\n");
- printf(" No of Link : %d\n",no_link);
-
if(no_link >0 )
{
rtr_id=strtok_r(lsa_data,sep,&rem);
@@ -538,7 +543,7 @@
printf(" Neighbor Length : %s \n",length);
printf(" Connecting Face : %s \n",face);
printf(" Metric : %s \n",metric);
-
+
for(i=1;i<no_link;i++)
{
@@ -561,18 +566,34 @@
void
print_adj_lsa(struct alsa * adj_lsa)
{
-
+
printf("print_adj_lsa called \n");
-
+
printf("-----------ADJ LSA Content---------------\n");
printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
printf(" LS Type : %d\n",adj_lsa->header->ls_type);
printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
+ printf(" Lsa Data:\n");
+ printf(" No of Link : %d\n",adj_lsa->no_link);
print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
-
+/*
+ struct link *templ=adj_lsa->links;
+ int i;
+
+ for(i=0 ; i< adj_lsa->no_link ; i++)
+ {
+ printf(" Link %d \n",i+1);
+ printf(" Neighbor : %s \n",templ->nbr->name);
+ printf(" Neighbor Length : %d \n",templ->nbr->length);
+ printf(" Connecting Face : %d \n",templ->face);
+ printf(" Metric : %d \n",templ->metric);
+
+ templ++;
+ }
+*/
printf("\n");
}
@@ -601,319 +622,60 @@
hashtb_end(e);
printf("\n");
-
-}
-
-char *
-get_name_lsdb_summary()
-{
- printf("get_name_lsdb_summary called \n");
- int i, name_lsdb_element;
-
- long int len=0;
-
- struct nlsa *name_lsa;
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- 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(sum_data,name_lsa->header->orig_router->name);
- len+=strlen(name_lsa->header->orig_router->name);
- //ccn_charbuf_append_string(sum_data,"|");
- len++;
-
- char *temp=(char *)malloc(20);
- memset(temp,0,20);
- sprintf(temp,"%d",name_lsa->header->ls_type);
- len+=strlen(temp);
- //ccn_charbuf_append_string(sum_data,temp);
- free(temp);
- //ccn_charbuf_append_string(sum_data,"|");
- len++;
-
- char *temp1=(char *)malloc(20);
- memset(temp1,0,20);
- sprintf(temp1,"%ld",name_lsa->header->ls_id);
- //ccn_charbuf_append_string(sum_data,temp1);
- len+=strlen(temp1);
- free(temp1);
- //ccn_charbuf_append_string(sum_data,"|");
- len++;
-
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
- len++;
-
- char *sum_data=malloc(len);
- memset(sum_data,0,len);
-
- hashtb_start(nlsr->lsdb->name_lsdb, e);
- for(i=0;i<name_lsdb_element;i++)
- {
- name_lsa=e->data;
-
- //ccn_charbuf_append_string(sum_data,name_lsa->header->orig_router->name);
- memcpy(sum_data+strlen(sum_data),name_lsa->header->orig_router->name,strlen(name_lsa->header->orig_router->name));
- //len+=strlen(name_lsa->header->orig_router->name);
- //ccn_charbuf_append_string(sum_data,"|");
- memcpy(sum_data+strlen(sum_data),"|",1);
- //len++;
-
- char *tempstr=(char *)malloc(20);
- memset(tempstr,0,20);
- sprintf(tempstr,"%d",name_lsa->header->ls_type);
- //len+=strlen(tempstr);
- //ccn_charbuf_append_string(sum_data,temp);
- memcpy(sum_data+strlen(sum_data),tempstr,strlen(tempstr));
- free(tempstr);
- //ccn_charbuf_append_string(sum_data,"|");
- memcpy(sum_data+strlen(sum_data),"|",1);
- //len++;
-
- char *temp1str=(char *)malloc(20);
- memset(temp1str,0,20);
- sprintf(temp1str,"%ld",name_lsa->header->ls_id);
- //ccn_charbuf_append_string(sum_data,temp1);
- memcpy(sum_data+strlen(sum_data),temp1str,strlen(temp1str));
- //len+=strlen(temp1str);
- free(temp1str);
- //ccn_charbuf_append_string(sum_data,"|");
- memcpy(sum_data+strlen(sum_data),"|",1);
- //len++;
-
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
- printf("Summary Name LSDB: %s\n",sum_data);
-
- return sum_data;
-}
-
-char *
-get_adj_lsdb_summary(void)
-{
- printf("get_adj_lsdb_summary called \n");
- int i, adj_lsdb_element;
- struct alsa *adj_lsa;
-
- long int len=0;
-
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
-
- 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(sum_data,adj_lsa->header->orig_router->name);
- len+=strlen(adj_lsa->header->orig_router->name);
- //ccn_charbuf_append_string(sum_data,"|");
- len++;
-
- char *temp=(char *)malloc(20);
- memset(temp,0,20);
- sprintf(temp,"%d",adj_lsa->header->ls_type);
- len+=strlen(temp);
- //ccn_charbuf_append_string(sum_data,temp);
- free(temp);
- //ccn_charbuf_append_string(sum_data,"|");
- len++;
-
- //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_time);
- len+=strlen(adj_lsa->header->orig_time);
- //ccn_charbuf_append_string(sum_data,"|");
- len++;
-
- hashtb_next(e);
- }
-
- hashtb_end(e);
- len++;
-
- char *sum_data=(char *)malloc(len);
- memset(sum_data,0,len);
-
- hashtb_start(nlsr->lsdb->adj_lsdb, e);
- for(i=0;i<adj_lsdb_element;i++)
- {
- adj_lsa=e->data;
-
- //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_router->name);
- memcpy(sum_data+strlen(sum_data),adj_lsa->header->orig_router->name,strlen(adj_lsa->header->orig_router->name));
- //len+=strlen(adj_lsa->header->orig_router->name);
- //ccn_charbuf_append_string(sum_data,"|");
- memcpy(sum_data+strlen(sum_data),"|",1);
- //len++;
-
- char *temp1=(char *)malloc(20);
- memset(temp1,0,20);
- sprintf(temp1,"%d",adj_lsa->header->ls_type);
- //len+=strlen(temp);
- //ccn_charbuf_append_string(sum_data,temp);
- memcpy(sum_data+strlen(sum_data),temp1,strlen(temp1));
- free(temp1);
- //ccn_charbuf_append_string(sum_data,"|");
- memcpy(sum_data+strlen(sum_data),"|",1);
- //len++;
-
- //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_time);
- memcpy(sum_data+strlen(sum_data),adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time));
- //len+=strlen(adj_lsa->header->orig_time);
- //ccn_charbuf_append_string(sum_data,"|");
- memcpy(sum_data+strlen(sum_data),"|",1);
- //len++;
-
- hashtb_next(e);
- }
-
- hashtb_end(e);
-
- printf("Summary ADJ LSDB: %s\n",sum_data);
-
- return sum_data;
}
void
-get_name_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
+build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data)
{
- printf("get_name_lsa_data called \n");
+ printf("build_and_install_others_adj_lsa called \n");
+ struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
+ build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
+ //print_adj_lsa(adj_lsa);
+ install_adj_lsa(adj_lsa);
+
- struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
+ free(adj_lsa->header->orig_router->name);
+ free(adj_lsa->header->orig_router);
+ free(adj_lsa->header->orig_time);
+ free(adj_lsa->header);
+ free(adj_lsa->body);
+ free(adj_lsa);
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
- int res;
+ print_adj_lsdb();
- hashtb_start(nlsr->lsdb->name_lsdb, e);
- res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
-
- if( res == HT_OLD_ENTRY )
- {
- name_lsa=e->data;
- printf("NAME LSA found\n");
-
- ccn_charbuf_append_string(lsa_data,name_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",name_lsa->header->orig_router->length);
- ccn_charbuf_append_string(lsa_data,temp_length);
- free(temp_length);
- ccn_charbuf_append_string(lsa_data,"|");
-
- char *temp_ltype=(char *)malloc(20);
- memset(temp_ltype,0,20);
- sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
- ccn_charbuf_append_string(lsa_data,temp_ltype);
- free(temp_ltype);
- ccn_charbuf_append_string(lsa_data,"|");
-
- char *temp_lsid=(char *)malloc(20);
- memset(temp_lsid,0,20);
- sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
- ccn_charbuf_append_string(lsa_data,temp_lsid);
- free(temp_lsid);
- ccn_charbuf_append_string(lsa_data,"|");
-
- char *temp_valid=(char *)malloc(20);
- memset(temp_valid,0,20);
- sprintf(temp_valid,"%d",name_lsa->header->isValid);
- ccn_charbuf_append_string(lsa_data,temp_valid);
- free(temp_valid);
- ccn_charbuf_append_string(lsa_data,"|");
-
- ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
- ccn_charbuf_append_string(lsa_data,"|");
-
- char *temp_npl=(char *)malloc(20);
- memset(temp_npl,0,20);
- sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
- ccn_charbuf_append_string(lsa_data,temp_npl);
- free(temp_npl);
- ccn_charbuf_append_string(lsa_data,"|");
-
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
}
+
void
-get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
+build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data)
{
- printf("get_adj_lsa_data called \n");
+ printf("build_others_adj_lsa called \n");
- struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
+ /*Filling Up Header Data */
+ adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
+ adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
+ memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
+ memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
- struct hashtb_enumerator ee;
- struct hashtb_enumerator *e = ⅇ
- int res;
+ adj_lsa->header->orig_router->length=strlen(orig_router)+1;
- hashtb_start(nlsr->lsdb->adj_lsdb, e);
- res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
- if( res == HT_OLD_ENTRY )
- {
- adj_lsa=e->data;
- printf("NAME LSA found\n");
-
- ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
- ccn_charbuf_append_string(lsa_data,"|");
+ adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
- char *temp_length=(char *)malloc(20);
- memset(temp_length,0,20);
- sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
- ccn_charbuf_append_string(lsa_data,temp_length);
- free(temp_length);
- ccn_charbuf_append_string(lsa_data,"|");
+ adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
+ memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
+ memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
- char *temp_ltype=(char *)malloc(20);
- memset(temp_ltype,0,20);
- sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
- ccn_charbuf_append_string(lsa_data,temp_ltype);
- free(temp_ltype);
- ccn_charbuf_append_string(lsa_data,"|");
+ adj_lsa->no_link=no_link;
- ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
- ccn_charbuf_append_string(lsa_data,"|");
+ adj_lsa->body=(char *)malloc(strlen(data)+1);
+ memset(adj_lsa->body,0,strlen(data)+1);
+ memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
- char *temp_nl=(char *)malloc(20);
- memset(temp_nl,0,20);
- sprintf(temp_nl,"%d",adj_lsa->no_link);
- ccn_charbuf_append_string(lsa_data,temp_nl);
- free(temp_nl);
- ccn_charbuf_append_string(lsa_data,"|");
-
- ccn_charbuf_append_string(lsa_data,adj_lsa->body);
-
-
- }
- else if(res == HT_NEW_ENTRY)
- {
- hashtb_delete(e);
- }
-
- hashtb_end(e);
}
+
long int
get_name_lsdb_num_element(void)
{
@@ -945,3 +707,332 @@
return num_element;
}
+
+void
+get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
+{
+ printf("get_name_lsdb_summary called \n");
+ int i, name_lsdb_element;
+
+ struct nlsa *name_lsa;
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ 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)
+{
+ printf("get_adj_lsdb_summary called \n");
+ int i, adj_lsdb_element;
+ struct alsa *adj_lsa;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ 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)
+{
+ 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);
+ ccn_charbuf_append_string(key,"/");
+ ccn_charbuf_append_string(key,lsid);
+
+ int res;
+ struct nlsa *name_lsa;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->lsdb->name_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)
+ {
+ name_lsa=e->data;
+ if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
+ {
+ ret=1;
+ }
+ }
+
+ hashtb_end(e);
+
+ ccn_charbuf_destroy(&key);
+
+ return ret;
+}
+
+int
+check_is_new_adj_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 alsa *adj_lsa;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->lsdb->adj_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)
+ {
+ adj_lsa=e->data;
+ if( strcmp ( orig_time , adj_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)
+{
+ printf("get_name_lsa_data called \n");
+
+ struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->lsdb->name_lsdb, e);
+ res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ name_lsa=e->data;
+ printf("NAME LSA found\n");
+
+ ccn_charbuf_append_string(lsa_data,name_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",name_lsa->header->orig_router->length);
+ ccn_charbuf_append_string(lsa_data,temp_length);
+ free(temp_length);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ char *temp_ltype=(char *)malloc(20);
+ memset(temp_ltype,0,20);
+ sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
+ ccn_charbuf_append_string(lsa_data,temp_ltype);
+ free(temp_ltype);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ char *temp_lsid=(char *)malloc(20);
+ memset(temp_lsid,0,20);
+ sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
+ ccn_charbuf_append_string(lsa_data,temp_lsid);
+ free(temp_lsid);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ char *temp_valid=(char *)malloc(20);
+ memset(temp_valid,0,20);
+ sprintf(temp_valid,"%d",name_lsa->header->isValid);
+ ccn_charbuf_append_string(lsa_data,temp_valid);
+ free(temp_valid);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ char *temp_npl=(char *)malloc(20);
+ memset(temp_npl,0,20);
+ sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
+ ccn_charbuf_append_string(lsa_data,temp_npl);
+ free(temp_npl);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+}
+
+void
+get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
+{
+ printf("get_adj_lsa_data called \n");
+
+ struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->lsdb->adj_lsdb, e);
+ res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ adj_lsa=e->data;
+ printf("NAME LSA found\n");
+
+ ccn_charbuf_append_string(lsa_data,adj_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",adj_lsa->header->orig_router->length);
+ ccn_charbuf_append_string(lsa_data,temp_length);
+ free(temp_length);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ char *temp_ltype=(char *)malloc(20);
+ memset(temp_ltype,0,20);
+ sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
+ ccn_charbuf_append_string(lsa_data,temp_ltype);
+ free(temp_ltype);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ char *temp_nl=(char *)malloc(20);
+ memset(temp_nl,0,20);
+ sprintf(temp_nl,"%d",adj_lsa->no_link);
+ ccn_charbuf_append_string(lsa_data,temp_nl);
+ free(temp_nl);
+ ccn_charbuf_append_string(lsa_data,"|");
+
+ ccn_charbuf_append_string(lsa_data,adj_lsa->body);
+
+
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ }
+
+ hashtb_end(e);
+}
diff --git a/nlsr_lsdb.h b/nlsr_lsdb.h
index 5b37c60..87c4013 100644
--- a/nlsr_lsdb.h
+++ b/nlsr_lsdb.h
@@ -1,7 +1,6 @@
#ifndef _NLSR_LSDB_H_
#define _NLSR_LSDB_H_
-
#define LS_TYPE_ADJ 1
#define LS_TYPE_NAME 2
@@ -25,7 +24,8 @@
{
struct alsa_header *header;
int no_link;
- char *body;
+ struct link *links;
+ char * body;
};
struct nlsa_header
@@ -44,33 +44,38 @@
struct name_prefix *name_prefix;
};
-void set_new_lsdb_version(void);
+void set_new_lsdb_version(void);
void build_and_install_name_lsas(void);
-void build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,int isValid,char *np);
void build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np);
-void build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,int isValid,char *np);
-void print_name_lsa(struct nlsa *name_lsa);
void install_name_lsa(struct nlsa *name_lsa);
-char * make_name_lsa_key(char *orig_router, int ls_type, long int ls_id);
+void print_name_lsa(struct nlsa *name_lsa);
void print_name_lsdb(void);
+void build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np);
+void build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id, char *orig_time, int isValid, char *np);
+void make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id);
int build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
-void build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data);
void build_adj_lsa(struct alsa * adj_lsa);
-void build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data);
void install_adj_lsa(struct alsa * adj_lsa);
-void make_adj_lsa_key(char *key,struct alsa *adj_lsa);
void print_adj_lsa_body(const char *body, int no_link);
void print_adj_lsa(struct alsa * adj_lsa);
void print_adj_lsdb(void);
-
-char * get_name_lsdb_summary(void);
-char * get_adj_lsdb_summary(void);
-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_adj_lsa_key(char *key,struct alsa *adj_lsa);
+void build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data);
+void build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data);
long int get_name_lsdb_num_element(void);
long int get_adj_lsdb_num_element(void);
+void get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data);
+void get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data);
+void get_lsdb_summary(struct ccn_charbuf *lsdb_data);
+
+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);
+
+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);
+
#endif
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index d67cd1d..f4a80cf 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -16,15 +16,14 @@
#include <ccn/signing.h>
#include <ccn/schedule.h>
#include <ccn/hashtb.h>
-#include <ccn/bloom.h>
#include "nlsr.h"
#include "nlsr_ndn.h"
+#include "nlsr_npl.h"
#include "nlsr_adl.h"
#include "nlsr_lsdb.h"
#include "utility.h"
-
int
appendLifetime(struct ccn_charbuf *cb, int lifetime)
{
@@ -84,8 +83,6 @@
memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
}
-
- //neighbor[strlen(neighbor)]='\0';
nbr->name=(char *)malloc(strlen(neighbor)+1);
memcpy(nbr->name,neighbor,strlen(neighbor)+1);
@@ -97,10 +94,10 @@
}
void
-get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info)
+get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info, int offset)
{
- printf("get_nbr called\n");
+ printf("get_lsa_identifier called\n");
int res,i;
int nlsr_position=0;
int name_comps=(int)info->interest_comps->n;
@@ -119,7 +116,7 @@
const unsigned char *comp_ptr1;
size_t comp_size;
- for(i=nlsr_position+2;i<info->interest_comps->n-2;i++)
+ for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++)
{
res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
len+=1;
@@ -130,15 +127,13 @@
char *neighbor=(char *)malloc(len);
memset(neighbor,0,len);
- for(i=nlsr_position+2; i<info->interest_comps->n-2;i++)
+ for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++)
{
res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
memcpy(neighbor+strlen(neighbor),"/",1);
memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
}
-
- //neighbor[strlen(neighbor)]='\0';
lsaId->name=(char *)malloc(strlen(neighbor)+1);
memset(lsaId->name,0,strlen(neighbor)+1);
@@ -146,42 +141,87 @@
lsaId->length=strlen(neighbor)+1;
printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
-
+
}
+int
+get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info)
+{
+ int res,i;
+ int nlsr_position=0;
+ int name_comps=(int)info->interest_comps->n;
+
+ int ret=0;
+
+ 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;
+ }
+ }
+
+
+ const unsigned char *comp_ptr1;
+ size_t comp_size;
+ res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size);
+
+ ret=atoi((char *)comp_ptr1);
+
+ return ret;
+
+}
+
+void
+get_lsdb_version(char *lsdb_version,struct ccn_closure *selfp, struct ccn_upcall_info *info )
+{
+ const unsigned char *comp_ptr1;
+ size_t comp_size;
+ ccn_name_comp_get(info->content_ccnb, info->content_comps,info->content_comps->n-2,&comp_ptr1, &comp_size);
+ memcpy(lsdb_version,(char *)comp_ptr1,(int)comp_size);
+
+}
+
+
+/* Call back function registered in ccnd to get all interest coming to NLSR application */
+
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:
- printf("Interest Received \n");
+ // 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],0);
+ printf("%s\n",ccn_charbuf_as_string(c));
+ ccn_charbuf_destroy(&c);
+
process_incoming_interest(selfp, info);
+
break;
+
default:
break;
}
- my_unlock();
+
return CCN_UPCALL_RESULT_OK;
}
+/* Function for processing incoming interest and reply with content/NACK content */
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);
- printf("%s\n",ccn_charbuf_as_string(c));
- ccn_charbuf_destroy(&c);
- */
const unsigned char *comp_ptr1;
size_t comp_size;
int res,i;
@@ -214,21 +254,19 @@
{
process_incoming_interest_lsa(selfp,info);
}
-
}
void
process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
{
printf("process_incoming_interest_info called \n");
-
- printf("Sending info Content Back ...\n");
+ printf("Sending Info Content back.....\n");
int res;
struct ccn_charbuf *data=ccn_charbuf_create();
struct ccn_charbuf *name=ccn_charbuf_create();
struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
-
+
res=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]);
if (res >= 0)
{
@@ -255,9 +293,9 @@
struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *));
- get_lsa_identifier(nbr,selfp,info);
+ get_lsa_identifier(nbr,selfp,info,-1);
printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
-
+
if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry )
{
@@ -268,13 +306,10 @@
free(raw_data);
ccn_charbuf_destroy(&sp.template_ccnb);
}
-
+
ccn_charbuf_destroy(&data);
- ccn_charbuf_destroy(&name);
+ ccn_charbuf_destroy(&name);
-
-
-
}
@@ -316,7 +351,8 @@
if (comp != NULL)
{
printf("LSDB Version in Exclusion Filter is %s\n",comp);
- dbcmp=strcmp(nlsr->lsdb->version,(char *)comp);
+ printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version);
+ dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp);
}
/* Now comp points to the start of your potential number, and size is its length */
}
@@ -331,7 +367,7 @@
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]);
+ 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);
@@ -343,45 +379,18 @@
if(dbcmp>0)
{
printf("Has Updated Database than Neighbor\n");
- printf("Sending LSDB Summary of Updated LSDB Content...\n");
- /*
- 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]);
+ printf("Sending LSDB Summary of Updated LSDB Content...\n");
- 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);
- */
+ ccn_name_append_str(name,nlsr->lsdb->lsdb_version);
- //ccn_charbuf_append_string(name,nlsr->lsdb->version);
+ struct ccn_charbuf *lsdb_data=ccn_charbuf_create();
+ get_lsdb_summary(lsdb_data);
+ char *raw_data=ccn_charbuf_as_string(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);
+ //printf("Content Data to be sent: %s \n",raw_data);
- char *name_lsdb_summary=get_name_lsdb_summary();
- char *adj_lsdb_summary=get_adj_lsdb_summary();
-
- char *raw_data=(char *)malloc(strlen(num_element) + strlen(name_lsdb_summary)+strlen(adj_lsdb_summary)+1);
- memset(raw_data,0,strlen(num_element) + strlen(name_lsdb_summary)+strlen(adj_lsdb_summary)+1);
-
- memcpy(raw_data+strlen(raw_data),num_element,strlen(num_element)+1);
-
- if( strlen(name_lsdb_summary) >0 )
- {
- memcpy(raw_data+strlen(raw_data),name_lsdb_summary,strlen(name_lsdb_summary)+1);
- }
- if( strlen(adj_lsdb_summary) >0 )
- {
- memcpy(raw_data+strlen(raw_data),adj_lsdb_summary,strlen(adj_lsdb_summary)+1);
- }
-
- printf("Content Data to be sent: %s \n",raw_data);
-
- if(nlsr->adj_build_count == 0 && nlsr->is_build_adj_lsa_sheduled == 1)
+ if( nlsr->adj_build_count == 0 || nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 )
{
res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT"));
}
@@ -396,24 +405,14 @@
if(res >= 0)
printf("Sending LSDB Summary of Updated LSDB Content is successful \n");
-
- //ccn_charbuf_destroy(&nlsd);
- //ccn_charbuf_destroy(&alsd);
- free(num_element);
+
+ ccn_charbuf_destroy(&lsdb_data);
}
else
{
printf("Does not have Updated Database than Neighbor\n");
printf("Sending NACK Content.....\n");
- //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]);
-
- /*
- 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 NACK Content is successful \n");
@@ -430,40 +429,31 @@
ccn_charbuf_destroy(&name);
ccn_charbuf_destroy(&sp.template_ccnb);
+
}
+
void
process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info)
{
printf("process_incoming_interest_lsa 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);
- printf("%s\n",ccn_charbuf_as_string(c));
- ccn_charbuf_destroy(&c);
- */
int res;
struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
- get_lsa_identifier(lsaId,selfp,info);
+ get_lsa_identifier(lsaId,selfp,info,0);
- printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
- printf("Router Name : %s Length: %d\n",nlsr->router_name->name,nlsr->router_name->length);
-
- char lsa_type=lsaId->name[nlsr->router_name->length];
- printf("LSA Type: %c\n",lsa_type);
- int ls_type=atoi(&lsa_type);
+ printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length);
+ int ls_type=get_ls_type(selfp, info);
struct ccn_charbuf *lsa_data=ccn_charbuf_create();
- if ( ls_type == LSA_NAME_TYPE )
+ if ( ls_type == LS_TYPE_NAME )
{
printf("Interest Received for NAME LSA\n");
get_name_lsa_data(lsa_data,lsaId);
}
- else if ( ls_type == LSA_ADJ_TYPE )
+ else if ( ls_type == LS_TYPE_ADJ )
{
printf("Interest Received for ADJ LSA\n");
get_adj_lsa_data(lsa_data,lsaId);
@@ -473,12 +463,12 @@
char *raw_data=(char *)malloc(strlen(rdata)+1);
memset(raw_data,0,strlen(rdata)+1);
memcpy(raw_data,(char *)rdata,strlen(rdata)+1);
- printf("Content Data to be sent: %s\n",raw_data);
+ //printf("Content Data to be sent: %s\n",raw_data);
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();
@@ -495,8 +485,8 @@
if(res >= 0)
printf("Sending LSA Content is successful \n");
-
-
+
+
ccn_charbuf_destroy(&data);
ccn_charbuf_destroy(&name);
ccn_charbuf_destroy(&sp.template_ccnb);
@@ -506,46 +496,52 @@
free(lsaId);
}
+/* Call back function registered in ccnd to get all content coming to NLSR application */
+
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 \n");
-
- process_incoming_content(selfp, info);
+ 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");
+ printf("Interest Timed Out Received for Name: ");
+
+ struct ccn_charbuf*ito;
+ ito=ccn_charbuf_create();
+ ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
+ printf("%s\n",ccn_charbuf_as_string(ito));
+ ccn_charbuf_destroy(&ito);
+
process_incoming_timed_out_interest(selfp,info);
break;
default:
fprintf(stderr, "Unexpected response of kind %d\n", kind);
- //return CCN_UPCALL_RESULT_ERR;
+ 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);
- printf("%s\n",ccn_charbuf_as_string(c));
- ccn_charbuf_destroy(&c);
- */
const unsigned char *comp_ptr1;
size_t comp_size;
@@ -579,33 +575,37 @@
{
process_incoming_content_lsa(selfp,info);
}
-
+
}
+
void
process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info)
{
printf("process_incoming_content_info called \n");
-
+
struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
get_nbr(nbr,selfp,info);
-
+
printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
-
+
const unsigned char *ptr;
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, &ptr, &length);
- printf("Content data: %s\n",ptr);
+ //printf("Content data: %s\n",ptr);
long int interval=atoi((char *)ptr);
+
update_adjacent_timed_out_zero_to_adl(nbr);
update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
update_lsdb_synch_interval_to_adl(nbr,interval);
print_adjacent_from_adl();
+
+
if(!nlsr->is_build_adj_lsa_sheduled)
{
printf("Scheduling Build and Install Adj LSA...\n");
@@ -617,21 +617,22 @@
printf("Build and Install Adj LSA already scheduled\n");
}
+
free(nbr);
-
+
}
+
void
process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info)
{
printf("process_incoming_content_lsdb called \n");
-
const unsigned char *ptr;
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, &ptr, &length);
- printf("Content data: %s\n",ptr);
+ //printf("Content data: %s\n",ptr);
if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) )
{
@@ -648,6 +649,7 @@
int ls_type;
char *lsid;
long int ls_id;
+ char *orig_time;
nl=strtok_r((char *)ptr,sep,&rem);
num_element=atoi(nl);
@@ -663,26 +665,47 @@
{
lsid=strtok_r(NULL,sep,&rem);
ls_id=atoi(lsid);
- printf(" LS Id: %ld\n",ls_id);
- send_interest_for_name_lsa(nbr,orig_router,lst,lsid);
+ orig_time=strtok_r(NULL,sep,&rem);
+ printf(" LS Id: %ld Orig Time: %s\n",ls_id ,orig_time);
+ int is_new_name_lsa=check_is_new_name_lsa(orig_router,lst,lsid,orig_time);
+ if ( is_new_name_lsa == 1 )
+ {
+ printf("New NAME LSA.....\n");
+ send_interest_for_name_lsa(nbr,orig_router,lst,lsid);
+ }
+ else
+ {
+ printf("Name LSA already exists in LSDB\n");
+ }
}
else
{
- printf("\n");
- send_interest_for_adj_lsa(nbr,orig_router,lst);
+ orig_time=strtok_r(NULL,sep,&rem);
+ printf(" Orig Time: %s\n",orig_time);
+ int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time);
+ if ( is_new_adj_lsa == 1 )
+ {
+ printf("New ADJ LSA.....\n");
+ send_interest_for_adj_lsa(nbr,orig_router,lst);
+ }
+ else
+ {
+ printf("ADJ LSA already exists in LSDB\n");
+ }
}
-
+
}
-
-
- char *version=get_current_timestamp_micro();
+ char *lsdb_version=(char *)malloc(20);
+ memset(lsdb_version,0,20);
+ get_lsdb_version(lsdb_version,selfp,info);
+
printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
- update_adjacent_lsdb_version_to_adl(nbr,version);
+ update_adjacent_lsdb_version_to_adl(nbr,lsdb_version);
printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
-
-
+
+ free(lsdb_version);
free(nbr);
}
else if (strcmp("WAIT",(char *)ptr) == 0)
@@ -691,7 +714,7 @@
get_nbr(nbr,selfp,info);
long int interval=get_lsdb_synch_interval(nbr->name);
adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2);
-
+
free(nbr);
}
@@ -699,10 +722,9 @@
{
printf("NACK Content Received\n");
}
-
-
}
+
void
process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info)
{
@@ -730,7 +752,7 @@
const unsigned char *ptr;
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, &ptr, &length);
- printf("Content data Received: %s\n",ptr);
+ //printf("Content data Received: %s\n",ptr);
printf("LSA Data\n");
@@ -749,25 +771,26 @@
printf(" LS Type : %d\n",ls_type);
- if ( ls_type == LSA_NAME_TYPE )
+ if ( ls_type == LS_TYPE_NAME )
{
lsid=strtok_r(NULL,sep,&rem);
ls_id=atoi(lsid);
+ orig_time=strtok_r(NULL,sep,&rem);
isvld=strtok_r(NULL,sep,&rem);
isValid=atoi(isvld);
np=strtok_r(NULL,sep,&rem);
np_length=strtok_r(NULL,sep,&rem);
name_length=atoi(np_length);
-
printf(" LS ID : %ld\n",ls_id);
printf(" isValid : %d\n",isValid);
printf(" Name Prefix : %s\n",np);
+ printf(" Orig Time : %s\n",orig_time);
printf(" Name Prefix length: %d\n",name_length);
- build_and_install_others_name_lsa(orig_router,ls_type,ls_id,isValid,np);
-
+ build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np);
+
}
- else if ( ls_type == LSA_ADJ_TYPE )
+ else if ( ls_type == LS_TYPE_ADJ )
{
orig_time=strtok_r(NULL,sep,&rem);
num_link=strtok_r(NULL,sep,&rem);
@@ -779,25 +802,14 @@
build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data);
}
-
-
}
-
}
+
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);
- printf("%s\n",ccn_charbuf_as_string(c));
- ccn_charbuf_destroy(&c);
- */
-
int res,i;
int nlsr_position=0;
int name_comps=(int)info->interest_comps->n;
@@ -827,12 +839,12 @@
get_nbr(nbr,selfp,info);
printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
-
-
+
+
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
{
@@ -851,20 +863,17 @@
}
free(nbr);
-
+
}
-int
+int
send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
{
printf("send_info_interest called \n");
printf("\n");
- my_lock();
-
int adl_element,i;
-
struct ndn_neighbor *nbr;
struct hashtb_enumerator ee;
@@ -879,11 +888,8 @@
send_info_interest_to_neighbor(nbr->neighbor);
hashtb_next(e);
}
-
hashtb_end(e);
- my_unlock();
-
return 0;
}
@@ -893,16 +899,8 @@
printf("send_info_interest_to_neighbor called \n");
int res;
- //int scope = 2; //no further than the next host
-
char info_str[5];
char nlsr_str[5];
- long int rnum;
- char rnumstr[20];
-
- rnum=random();
- memset(&rnumstr,0,20);
- sprintf(rnumstr,"%ld",rnum);
memset(&nlsr_str,0,5);
sprintf(nlsr_str,"nlsr");
@@ -913,21 +911,19 @@
struct ccn_charbuf *name;
name=ccn_charbuf_create();
- char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name->name)+1);
- memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name->name)+1);
+ char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1);
+ memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1);
memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
memcpy(int_name+strlen(int_name),"/",1);
memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
memcpy(int_name+strlen(int_name),"/",1);
memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
- memcpy(int_name+strlen(int_name),nlsr->router_name->name,strlen(nlsr->router_name->name));
+ memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name));
res=ccn_name_from_uri(name,int_name);
if ( res >=0 )
{
- ccn_name_append_str(name,rnumstr);
-
/* adding InterestLifeTime and InterestScope filter */
struct ccn_charbuf *templ;
@@ -936,11 +932,10 @@
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> */
- //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
- //ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
- //ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
- //ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
- //ccn_charbuf_append_closer(templ); /* </Scope> */
+ ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
+ ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
+ 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);
ccn_charbuf_append_closer(templ); /* </Interest> */
@@ -965,8 +960,6 @@
{
printf("send_lsdb_interest called \n");
- my_lock();
-
int i, adl_element;
struct ndn_neighbor *nbr;
@@ -1000,7 +993,6 @@
hashtb_end(e);
nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0);
- my_unlock();
return 0;
}
@@ -1008,7 +1000,7 @@
send_lsdb_interest_to_nbr(struct name_prefix *nbr)
{
printf("send_lsdb_interest_to_nbr called \n");
-
+
char *last_lsdb_version=get_nbr_lsdb_version(nbr->name);
if(last_lsdb_version !=NULL)
@@ -1018,14 +1010,9 @@
struct ccn_charbuf *name;
int res;
- long int rnum;
- char rnumstr[20];
char lsdb_str[5];
char nlsr_str[5];
-
- rnum=random();
- memset(&rnumstr,0,20);
- sprintf(rnumstr,"%ld",rnum);
+
memset(&nlsr_str,0,5);
sprintf(nlsr_str,"nlsr");
memset(&lsdb_str,0,5);
@@ -1039,16 +1026,14 @@
{
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);
@@ -1057,21 +1042,21 @@
ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
ccn_charbuf_reset(c);
ccn_charbuf_putf(c, "%s", 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_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
ccn_charbuf_append(templ, "2", 1);
ccn_charbuf_append_closer(templ); /* </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 )
@@ -1086,7 +1071,6 @@
ccn_charbuf_destroy(&name);
}
set_is_lsdb_send_interest_scheduled_to_zero(nbr->name);
-
}
void
@@ -1095,31 +1079,27 @@
printf("send_interest_for_name_lsa called\n");
int res;
- long int rnum;
- char rnumstr[20];
char lsa_str[5];
char nlsr_str[5];
-
- rnum=random();
- memset(&rnumstr,0,20);
- sprintf(rnumstr,"%ld",rnum);
memset(&nlsr_str,0,5);
sprintf(nlsr_str,"nlsr");
memset(&lsa_str,0,5);
sprintf(lsa_str,"lsa");
- char *int_name=(char *)malloc(nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
- memset(int_name,0,nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
+ char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
+ memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
memcpy(int_name+strlen(int_name),"/",1);
memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
memcpy(int_name+strlen(int_name),"/",1);
memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
- memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
+ memcpy(int_name+strlen(int_name),"/",1);
+ memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
+ memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
-
+
struct ccn_charbuf *name;
name=ccn_charbuf_create();
@@ -1127,7 +1107,6 @@
res=ccn_name_from_uri(name,int_name);
ccn_name_append_str(name,ls_type);
ccn_name_append_str(name,ls_id);
- ccn_name_append_str(name,rnumstr);
/* adding InterestLifeTime and InterestScope filter */
@@ -1147,7 +1126,7 @@
appendLifetime(templ,nlsr->interest_resend_time);
ccn_charbuf_append_closer(templ); /* </Interest> */
/* Adding InterestLifeTime and InterestScope filter done */
-
+
printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id);
res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
@@ -1155,12 +1134,11 @@
if ( res >= 0 )
printf("NAME LSA interest sending Successfull .... \n");
- //free(lsa_orig_router);
ccn_charbuf_destroy(&templ);
ccn_charbuf_destroy(&name);
free(int_name);
-
-
+
+
}
void
@@ -1169,38 +1147,34 @@
printf("send_interest_for_adj_lsa called\n");
int res;
- long int rnum;
- char rnumstr[20];
char lsa_str[5];
char nlsr_str[5];
-
- rnum=random();
- memset(&rnumstr,0,20);
- sprintf(rnumstr,"%ld",rnum);
memset(&nlsr_str,0,5);
sprintf(nlsr_str,"nlsr");
memset(&lsa_str,0,5);
sprintf(lsa_str,"lsa");
- char *int_name=(char *)malloc(nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
- memset(int_name,0,nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
+ char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
+ memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
memcpy(int_name+strlen(int_name),"/",1);
memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
memcpy(int_name+strlen(int_name),"/",1);
memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
+ memcpy(int_name+strlen(int_name),"/",1);
+ memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
-
+
struct ccn_charbuf *name;
name=ccn_charbuf_create();
-
+
ccn_name_from_uri(name,int_name);
ccn_name_append_str(name,ls_type);
- ccn_name_append_str(name,rnumstr);
+
/* adding InterestLifeTime and InterestScope filter */
@@ -1210,7 +1184,6 @@
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> */
- //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
@@ -1219,7 +1192,7 @@
appendLifetime(templ,nlsr->interest_resend_time);
ccn_charbuf_append_closer(templ); /* </Interest> */
/* Adding InterestLifeTime and InterestScope filter done */
-
+
printf("Sending ADJ LSA interest on name prefix : %s/%s/%s%s/%s/\n",nbr->name,nlsr_str,lsa_str,orig_router,ls_type);
res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
@@ -1227,11 +1200,9 @@
if ( res >= 0 )
printf("ADJ LSA interest sending Successfull .... \n");
- //free(lsa_orig_router);
ccn_charbuf_destroy(&templ);
ccn_charbuf_destroy(&name);
free(int_name);
-
-
}
+
diff --git a/nlsr_ndn.h b/nlsr_ndn.h
index 0b6b14c..4932fb6 100644
--- a/nlsr_ndn.h
+++ b/nlsr_ndn.h
@@ -2,16 +2,20 @@
#define _NLSR_NDN_H_
int appendLifetime(struct ccn_charbuf *cb, int lifetime);
-void get_nbr(struct name_prefix * nbr, struct ccn_closure *selfp, struct ccn_upcall_info *info);
-void get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info);
+void get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info);
+void get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info,int offset);
+void get_lsdb_version(char *lsdb_version,struct ccn_closure *selfp, struct ccn_upcall_info *info );
+int get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info);
+
enum ccn_upcall_res incoming_interest(struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info);
+
void process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info);
void process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info);
void process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info);
void process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info);
-enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info* info);
+enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info* info);
void process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info);
void process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info);
void process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info);
@@ -20,15 +24,12 @@
void process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info);
void process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info);
-
int send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
void send_info_interest_to_neighbor(struct name_prefix *nbr);
int send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
void send_lsdb_interest_to_nbr(struct name_prefix *nbr);
-
void send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id);
void send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type);
#endif
-
diff --git a/nlsr_npl.c b/nlsr_npl.c
new file mode 100644
index 0000000..62101d4
--- /dev/null
+++ b/nlsr_npl.c
@@ -0,0 +1,74 @@
+#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_npl.h"
+
+
+void
+add_name_to_npl(struct name_prefix *np)
+{
+ struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->npl, e);
+ res = hashtb_seek(e, np->name, np->length, 0);
+
+ if(res == HT_NEW_ENTRY)
+ {
+
+ hnp = e->data;
+ hnp->length=np->length;
+ hnp->name=(char *)malloc(np->length); //free
+ memcpy(hnp->name,np->name,np->length);
+ }
+
+ hashtb_end(e);
+
+}
+
+
+void
+print_name_prefix_from_npl(void)
+{
+ printf("print_name_prefix_from_npl called \n");
+ int i, npl_element;
+ struct name_prefix *np;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->npl, e);
+ npl_element=hashtb_n(nlsr->npl);
+
+ for(i=0;i<npl_element;i++)
+ {
+ np=e->data;
+ printf("Name Prefix: %s and Length: %d \n",np->name,np->length);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+ printf("\n");
+}
+
diff --git a/nlsr_npl.h b/nlsr_npl.h
new file mode 100644
index 0000000..3c22f8e
--- /dev/null
+++ b/nlsr_npl.h
@@ -0,0 +1,7 @@
+#ifndef _NLSR_NPL_H_
+#define _NLSR_NPL_H_
+
+void add_name_to_npl(struct name_prefix *np);
+void print_name_prefix_from_npl(void);
+
+#endif
diff --git a/utility.c b/utility.c
index 7ebc72d..33f3b2e 100644
--- a/utility.c
+++ b/utility.c
@@ -49,26 +49,7 @@
}
-char *
-nth_named_component(const char *name_prefix, int n)
-{
- int i;
- char * seps="/";
- char *rem=NULL;
- char *component;
-
- char *prefix=(char *)malloc(strlen(name_prefix)+1);
- memcpy(prefix,name_prefix,strlen(name_prefix)+1);
-
- component=strtok_r(prefix,seps,&rem);
-
- for(i=1;i<n;i++)
- component=strtok_r(NULL,seps,&rem);
-
- return component;
-
-}
long int
get_current_time_sec(void)
@@ -79,27 +60,16 @@
}
-long int
-get_current_time_microsec(void)
-{
- struct timeval now;
- gettimeofday(&now, NULL);
- long int microSec=1000000*now.tv_sec+now.tv_usec;
- return microSec;
-
-}
-
-char *
-get_current_timestamp_micro(void)
+void
+get_current_timestamp_micro(char * microSec)
{
struct timeval now;
gettimeofday(&now, NULL);
- char *microSec=(char *)malloc(20);
+ //char *microSec=(char *)malloc(20);
sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec);
- microSec[strlen(microSec)]='\0';
-
- return microSec;
+ //microSec[strlen(microSec)]='\0';
+ //return microSec;
}
diff --git a/utility.h b/utility.h
index 4b67bbd..fb699d6 100644
--- a/utility.h
+++ b/utility.h
@@ -3,10 +3,7 @@
char * getLocalTimeStamp(void);
char * getGmTimeStamp(void);
-char * nth_named_component(const char *name_prefix, int n);
long int get_current_time_sec(void);
-long int get_current_time_microsec(void);
-
-char * get_current_timestamp_micro(void);
+void get_current_timestamp_micro(char * microSec);
#endif