Name Prefixt Table Manipulation
diff --git a/nlsr.c b/nlsr.c
index 108f7d1..dda2525 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -26,6 +26,10 @@
#include "utility.h"
#include "nlsr_npl.h"
#include "nlsr_adl.h"
+#include "nlsr_npt.h"
+#include "nlsr_route.h"
+
+
struct option longopts[] =
{
@@ -343,7 +347,25 @@
hashtb_destroy(&nlsr->lsdb->name_lsdb);
hashtb_destroy(&nlsr->lsdb->adj_lsdb);
hashtb_destroy(&nlsr->pit_alsa);
-
+ hashtb_destroy(&nlsr->routing_table);
+
+
+ int i, npt_element;
+ struct npt_entry *ne;
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ hashtb_start(nlsr->npt, e);
+ npt_element=hashtb_n(nlsr->npt);
+ for(i=0;i<npt_element;i++)
+ {
+ ne=e->data;
+ hashtb_destroy(&ne->next_hop_table);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+ hashtb_destroy(&nlsr->npt);
+
ccn_schedule_destroy(&nlsr->sched);
ccn_destroy(&nlsr->ccn);
@@ -385,6 +407,10 @@
nlsr->npl = hashtb_create(sizeof(struct name_prefix), ¶m_npl);
struct hashtb_param param_pit_alsa = {0};
nlsr->pit_alsa = hashtb_create(sizeof(struct pneding_interest), ¶m_pit_alsa);
+ struct hashtb_param param_npt = {0};
+ nlsr->npt = hashtb_create(sizeof(struct npt_entry), ¶m_npt);
+ struct hashtb_param param_rte = {0};
+ nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), ¶m_rte);
nlsr->in_interest.p = &incoming_interest;
nlsr->in_content.p = &incoming_content;
@@ -427,7 +453,7 @@
{
int res;
char *config_file;
- //int daemon_mode;
+ int daemon_mode;
init_nlsr();
@@ -436,7 +462,7 @@
switch (res)
{
case 'd':
- //daemon_mode = 1;
+ daemon_mode = 1;
break;
case 'f':
config_file = optarg;
@@ -495,7 +521,6 @@
{
res = ccn_run(nlsr->ccn, 500);
}
-
if (!(nlsr->sched && nlsr->ccn))
{
break;
diff --git a/nlsr.h b/nlsr.h
index 41df3c5..65500fa 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -42,6 +42,8 @@
struct hashtb *npl;
struct hashtb *pit_alsa;
struct hashtb *map;
+ struct hashtb *npt;
+ struct hashtb *routing_table;
struct linkStateDatabase *lsdb;
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index 4df0840..f271e50 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -24,6 +24,7 @@
#include "nlsr_npl.h"
#include "nlsr_adl.h"
#include "nlsr_route.h"
+#include "nlsr_npt.h"
void
set_new_lsdb_version(void)
@@ -191,7 +192,26 @@
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->lsdb_version);
+ printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+
+ int next_hop=get_next_hop(new_name_lsa->header->orig_router->name);
+ if ( next_hop == NO_NEXT_HOP )
+ {
+ int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_FACE);
+ if ( check == HT_NEW_ENTRY )
+ {
+ printf("Added in npt \n");
+ }
+ }
+ else
+ {
+ int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop);
+ if ( check == HT_NEW_ENTRY )
+ {
+ printf("Added in npt \n");
+ }
+
+ }
}
else if(res == HT_OLD_ENTRY)
@@ -482,7 +502,9 @@
set_new_lsdb_version();
printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+ add_next_hop_router(new_adj_lsa->header->orig_router->name);
+ add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
}
else if(res == HT_OLD_ENTRY)
{
@@ -509,6 +531,8 @@
set_new_lsdb_version();
printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
+ add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
+
}
}
diff --git a/nlsr_npt.c b/nlsr_npt.c
new file mode 100644
index 0000000..f3b5fc8
--- /dev/null
+++ b/nlsr_npt.c
@@ -0,0 +1,208 @@
+#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 <sys/types.h>
+#include <signal.h>
+
+
+
+#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_npt.h"
+#include "nlsr_fib.h"
+
+void
+make_npt_key(char *key, char *orig_router, char *name_prefix)
+{
+ memcpy(key+strlen(key),orig_router,strlen(orig_router));
+ memcpy(key+strlen(key),name_prefix,strlen(name_prefix));
+}
+
+int
+add_npt_entry(char *orig_router, char *name_prefix, int face)
+{
+ if ( strcmp(orig_router,nlsr->router_name)== 0)
+ {
+ return -1;
+ }
+
+ struct npt_entry *ne=(struct npt_entry*)malloc(sizeof(struct npt_entry ));
+
+ int res,res_nht;
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ char *key=(char *)malloc(strlen(orig_router)+strlen(name_prefix)+2);
+ memset(key,0,strlen(orig_router)+strlen(name_prefix)+2);
+
+ make_npt_key(key,orig_router,name_prefix);
+
+ hashtb_start(nlsr->npt, e);
+ res = hashtb_seek(e, key, strlen(key), 0);
+
+ if(res == HT_NEW_ENTRY)
+ {
+ ne=e->data;
+
+ ne->name_prefix=(char *)malloc(strlen(name_prefix)+1);
+ memset(ne->name_prefix,0,strlen(name_prefix)+1);
+ memcpy(ne->name_prefix,name_prefix,strlen(name_prefix));
+
+ /* Adding Orig Router in Orig Router List */
+
+ struct next_hop_entry *nhe=(struct next_hop_entry *)malloc(sizeof(struct next_hop_entry));
+
+ struct hashtb_param param_nht = {0};
+ ne->next_hop_table= hashtb_create(sizeof(struct next_hop_entry ), ¶m_nht);
+
+ struct hashtb_enumerator eenht;
+ struct hashtb_enumerator *enht = &eenht;
+
+ hashtb_start(ne->next_hop_table, enht);
+ res_nht = hashtb_seek(enht, orig_router, strlen(orig_router), 0);
+
+ if(res_nht == HT_NEW_ENTRY )
+ {
+ nhe=enht->data;
+ nhe->orig_router=(char *)malloc(strlen(orig_router)+1);
+ memset(nhe->orig_router,0,strlen(orig_router)+1);
+ memcpy(nhe->orig_router,orig_router,strlen(orig_router));
+
+ nhe->next_hop_face=face;
+
+ }
+ hashtb_end(enht);
+
+ if ( face != NO_FACE )
+ {
+ add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, face);
+ }
+
+ }
+ else if (res == HT_OLD_ENTRY)
+ {
+ free(ne);
+ struct npt_entry *one;
+
+ one=e->data;
+
+ struct next_hop_entry *nhe=(struct next_hop_entry *)malloc(sizeof(struct next_hop_entry));
+ struct hashtb_param param_nht = {0};
+ ne->next_hop_table= hashtb_create(sizeof(struct next_hop_entry ), ¶m_nht);
+
+ struct hashtb_enumerator eenht;
+ struct hashtb_enumerator *enht = &eenht;
+
+ hashtb_start(one->next_hop_table, enht);
+ res_nht = hashtb_seek(enht, orig_router, strlen(orig_router), 0);
+
+ if(res_nht == HT_NEW_ENTRY )
+ {
+ nhe=enht->data;
+ nhe->orig_router=(char *)malloc(strlen(orig_router)+1);
+ memset(nhe->orig_router,0,strlen(orig_router)+1);
+ memcpy(nhe->orig_router,orig_router,strlen(orig_router));
+
+ nhe->next_hop_face=face;
+
+ if ( face != NO_FACE )
+ {
+ add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, face);
+ }
+
+ }
+ else if ( res_nht == HT_OLD_ENTRY)
+ {
+ free(nhe);
+ struct next_hop_entry *onhe;
+ onhe=enht->data;
+
+ if(onhe->next_hop_face != face )
+ {
+ if ( onhe->next_hop_face != NO_FACE )
+ {
+ add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_UNREG, onhe->next_hop_face);
+ }
+
+ if ( face != NO_FACE )
+ {
+ add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, onhe->next_hop_face);
+ }
+
+ onhe->next_hop_face=face;
+
+ }
+
+ }
+ hashtb_end(enht);
+
+
+
+ }
+ hashtb_end(e);
+
+ free(key);
+ return res;
+}
+
+
+void
+print_npt(void)
+{
+ printf("\n");
+ printf("print_npt called\n\n");
+ int i, npt_element;
+
+ struct npt_entry *ne;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->npt, e);
+ npt_element=hashtb_n(nlsr->npt);
+
+ for(i=0;i<npt_element;i++)
+ {
+ printf("\n");
+ printf("----------NPT ENTRY %d------------------\n",i+1);
+ ne=e->data;
+ printf(" Name Prefix: %s \n",ne->name_prefix);
+
+ struct next_hop_entry *nhe;
+ struct hashtb_enumerator eenht;
+ struct hashtb_enumerator *enht = &eenht;
+
+ int j, nht_element;
+ hashtb_start(ne->next_hop_table, enht);
+ nht_element=hashtb_n(ne->next_hop_table);
+
+ for (j=0;j<nht_element;j++)
+ {
+ nhe=enht->data;
+ printf(" Origination Router: %s \n",nhe->orig_router);
+ nhe->next_hop_face == NO_FACE ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", nhe->next_hop_face);
+
+ hashtb_next(enht);
+ }
+ hashtb_end(enht);
+
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+ printf("\n");
+}
diff --git a/nlsr_npt.h b/nlsr_npt.h
new file mode 100644
index 0000000..48ef6d4
--- /dev/null
+++ b/nlsr_npt.h
@@ -0,0 +1,22 @@
+#ifndef _NLSR_NPT_H_
+#define _NLSR_NPT_H_
+
+#define NO_FACE -12345
+
+struct npt_entry
+{
+ char *name_prefix;
+ struct hashtb *next_hop_table;
+};
+
+struct next_hop_entry
+{
+ char *orig_router;
+ int next_hop_face;
+};
+
+
+int add_npt_entry(char *orig_router, char *name_prefix, int face);
+void print_npt(void);
+
+#endif
diff --git a/nlsr_route.c b/nlsr_route.c
index 8d47f3e..61bf3dc 100644
--- a/nlsr_route.c
+++ b/nlsr_route.c
@@ -22,6 +22,7 @@
#include "nlsr.h"
#include "nlsr_route.h"
#include "nlsr_lsdb.h"
+#include "nlsr_npt.h"
int
route_calculate(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
@@ -31,13 +32,19 @@
if( ! nlsr->is_build_adj_lsa_sheduled )
{
/* Calculate Route here */
-
+ print_routing_table();
+ print_npt();
+
struct hashtb_param param_me = {0};
nlsr->map = hashtb_create(sizeof(struct map_entry), ¶m_me);
make_map();
assign_mapping_number();
print_map();
+
+ do_old_routing_table_updates();
+
+
int i;
int **adj_matrix;
int map_element=hashtb_n(nlsr->map);
@@ -56,7 +63,7 @@
print_all_path_from_source(parent,source);
-
+
for(i = 0; i < map_element; i++)
{
@@ -453,4 +460,147 @@
}
}
+int
+get_next_hop(char *dest_router)
+{
+ struct routing_table_entry *rte;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res,ret;
+
+ hashtb_start(nlsr->routing_table, e);
+ res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ rte=e->data;
+ ret=rte->next_hop_face;
+ }
+ else if(res == HT_NEW_ENTRY)
+ {
+ hashtb_delete(e);
+ ret=NO_NEXT_HOP;
+ }
+
+ hashtb_end(e);
+
+ return ret;
+}
+
+void
+add_next_hop_router(char *dest_router)
+{
+ if ( strcmp(dest_router,nlsr->router_name)== 0)
+ {
+ return ;
+ }
+
+ struct routing_table_entry *rte=(struct routing_table_entry *)malloc(sizeof(struct routing_table_entry));
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->routing_table, e);
+ res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
+
+ if( res == HT_NEW_ENTRY )
+ {
+ rte=e->data;
+ rte->dest_router=(char *)malloc(strlen(dest_router)+1);
+ memset(rte->dest_router,0,strlen(dest_router)+1);
+ memcpy(rte->dest_router,dest_router,strlen(dest_router));
+ rte->next_hop_face=NO_NEXT_HOP;
+ }
+ hashtb_end(e);
+
+}
+
+void
+add_next_hop_from_lsa_adj_body(char *body, int no_link)
+{
+
+ int i=0;
+ char *lsa_data=(char *)malloc(strlen(body)+1);
+ memset( lsa_data,0,strlen(body)+1);
+ memcpy(lsa_data,body,strlen(body)+1);
+ char *sep="|";
+ char *rem;
+ char *rtr_id;
+ char *length;
+ char *face;
+ char *metric;
+
+ if(no_link >0 )
+ {
+ rtr_id=strtok_r(lsa_data,sep,&rem);
+ length=strtok_r(NULL,sep,&rem);
+ face=strtok_r(NULL,sep,&rem);
+ metric=strtok_r(NULL,sep,&rem);
+
+ //printf(" Link %d \n",i+1);
+ //printf(" Neighbor : %s \n",rtr_id);
+ //printf(" Neighbor Length : %s \n",length);
+ //printf(" Connecting Face : %s \n",face);
+ //printf(" Metric : %s \n",metric);
+
+ add_next_hop_router(rtr_id);
+
+ for(i=1;i<no_link;i++)
+ {
+ rtr_id=strtok_r(NULL,sep,&rem);
+ length=strtok_r(NULL,sep,&rem);
+ face=strtok_r(NULL,sep,&rem);
+ metric=strtok_r(NULL,sep,&rem);
+ //printf(" Link %d \n",i+1);
+ //printf(" Neighbor : %s \n",rtr_id);
+ //printf(" Neighbor Length : %s \n",length);
+ //printf(" Connecting Face : %s \n",face);
+ //printf(" Metric : %s \n",metric);
+
+ add_next_hop_router(rtr_id);
+
+ }
+ }
+
+ free(lsa_data);
+
+
+}
+
+void
+print_routing_table(void)
+{
+ printf("\n");
+ printf("print_routing_table called\n");
+ int i, rt_element;
+
+ struct routing_table_entry *rte;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->routing_table, e);
+ rt_element=hashtb_n(nlsr->routing_table);
+
+ for(i=0;i<rt_element;i++)
+ {
+ printf("----------Routing Table Entry %d------------------\n",i+1);
+ rte=e->data;
+ printf(" Destination Router: %s \n",rte->dest_router);
+ rte->next_hop_face == NO_NEXT_HOP ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", rte->next_hop_face);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+ printf("\n");
+}
+
+void
+do_old_routing_table_updates()
+{
+
+}
diff --git a/nlsr_route.h b/nlsr_route.h
index 0e7884b..ec243e9 100644
--- a/nlsr_route.h
+++ b/nlsr_route.h
@@ -4,12 +4,22 @@
#define EMPTY_PARENT -12345
#define INF_DISTANCE 2147483647
+#define NO_NEXT_HOP -4321
+
struct map_entry
{
char *router;
int mapping;
};
+
+struct routing_table_entry
+{
+ char *dest_router;
+ int next_hop_face;
+}
+;
+
int route_calculate(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
void make_map(void);
void add_map_entry(char *router);
@@ -26,4 +36,12 @@
void print_path(long int *parent, long int dest);
void print_all_path_from_source(long int *parent,long int source);
+/* Routing Table Relates function */
+
+int get_next_hop(char *dest_router);
+void add_next_hop_router(char *dest_router);
+void add_next_hop_from_lsa_adj_body(char *body, int no_link);
+void print_routing_table(void);
+void do_old_routing_table_updates();
+
#endif