API Addition 2nd Version
diff --git a/nlsr_npt.c b/nlsr_npt.c
index a83e2fe..9f690ff 100644
--- a/nlsr_npt.c
+++ b/nlsr_npt.c
@@ -25,6 +25,7 @@
#include "nlsr_fib.h"
#include "nlsr_route.h"
#include "nlsr_adl.h"
+#include "utility.h"
int
add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs)
@@ -242,14 +243,22 @@
if ( is_neighbor(orig_router) == 0 )
{
- printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->debugging )
+ printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
+ //printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
}
else
{
if ( j == last_face && is_neighbor(nle->name)==0)
{
- printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->debugging )
+ printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
+ //printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
}
}
@@ -347,14 +356,20 @@
if ( is_neighbor(orig_router) == 0 )
{
- printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->debugging )
+ printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
}
else
{
if ( j == last_face && is_neighbor(nle->name)==0)
{
- printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->debugging )
+ printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
}
}
@@ -385,8 +400,17 @@
void
print_npt(void)
{
- printf("\n");
- printf("print_npt called\n\n");
+
+ if ( nlsr->debugging )
+ {
+ printf("\n");
+ printf("print_npt called\n");
+ }
+ if ( nlsr->detailed_logging )
+ {
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n");
+ }
int i, npt_element;
struct npt_entry *ne;
@@ -399,10 +423,21 @@
for(i=0;i<npt_element;i++)
{
- printf("\n");
- printf("----------NPT ENTRY %d------------------\n",i+1);
+ if ( nlsr->debugging )
+ {
+ printf("\n");
+ printf("----------NPT ENTRY %d------------------\n",i+1);
+ }
+ if ( nlsr->detailed_logging )
+ {
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1);
+ }
ne=e->data;
- printf(" Origination Router: %s \n",ne->orig_router);
+ if ( nlsr->debugging )
+ printf(" Origination Router: %s \n",ne->orig_router);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router);
//ne->next_hop_face == NO_FACE ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", ne->next_hop_face);
int j, nl_element,face_list_element;
@@ -416,7 +451,10 @@
for (j=0;j<nl_element;j++)
{
nle=enle->data;
- printf(" Name Prefix: %s \n",nle->name);
+ if ( nlsr->debugging )
+ printf(" Name Prefix: %s \n",nle->name);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name);
hashtb_next(enle);
}
hashtb_end(enle);
@@ -430,14 +468,21 @@
face_list_element=hashtb_n(ne->face_list);
if ( face_list_element <= 0 )
{
- printf(" Face: No Face \n");
+ if ( nlsr->debugging )
+ printf(" Face: No Face \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
+
}
else
{
for(j=0;j<face_list_element;j++)
{
fle=ef->data;
- printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
+ if ( nlsr->debugging )
+ printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
hashtb_next(ef);
}
}
@@ -510,9 +555,18 @@
void
add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost)
{
- printf("add_face_to_npt_by_face_id called\n");
+ if ( nlsr->debugging )
+ {
+ printf("add_face_to_npt_by_face_id called\n");
+ printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
+ }
+ if ( nlsr->detailed_logging )
+ {
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_face_to_npt_by_face_id called\n");
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
+ }
- printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
+
int res,res1;
struct npt_entry *ne;
@@ -524,7 +578,11 @@
if ( res == HT_OLD_ENTRY )
{
- printf("Dest Router Found \n");
+ if ( nlsr->debugging )
+ printf("Dest Router Found \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router Found \n");
+
ne=e->data;
struct hashtb_enumerator eef;
@@ -535,7 +593,10 @@
if ( res1 == HT_OLD_ENTRY )
{
- printf("Face Found \n");
+ if ( nlsr->debugging )
+ printf("Face Found \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Found \n");
struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
fle=ef->data;
fle->next_hop_face=face_id;
@@ -543,7 +604,10 @@
}
else if ( res1 == HT_NEW_ENTRY )
{
- printf("Face Not Found \n");
+ if ( nlsr->debugging )
+ printf("Face Not Found \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n");
struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
fle=ef->data;
fle->next_hop_face=face_id;
@@ -564,7 +628,10 @@
void
add_new_fib_entries_to_npt(void)
{
- printf("add_new_fib_entries_to_npt called\n");
+ if ( nlsr->debugging )
+ printf("add_new_fib_entries_to_npt called\n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_new_fib_entries_to_npt called\n");
int i,j, rt_element,face_list_element;
struct routing_table_entry *rte;
@@ -588,7 +655,10 @@
face_list_element=hashtb_n(rte->face_list);
if ( face_list_element <= 0 )
{
- printf(" Face: No Face \n");
+ if ( nlsr->debugging )
+ printf(" Face: No Face \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
}
else
{
@@ -612,7 +682,10 @@
void
delete_face_from_npt_by_face_id(char *dest_router, int face_id)
{
- printf("delete_face_from_npt_by_face_id called\n");
+ if ( nlsr->debugging )
+ printf("delete_face_from_npt_by_face_id\n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_face_from_npt_by_face_id\n");
int res,res1;
struct npt_entry *ne;
@@ -661,10 +734,17 @@
nlsr_lock();
- printf("delete_old_face_from_npt called\n");
+ if ( nlsr->debugging )
+ printf("delete_old_face_from_npt\n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_old_face_from_npt\n");
+
if ( ev->evdata != NULL )
- {
- printf("Event Data: %s \n",(char *)ev->evdata);
+ {
+ if ( nlsr->debugging )
+ printf("Event Data: %s \n",(char *)ev->evdata);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Event Data: %s \n",(char *)ev->evdata);
char *sep="|";
char *rem;
char *orig_router;
@@ -678,7 +758,11 @@
orig_router=strtok_r(face_data,sep,&rem);
faceid=strtok_r(NULL,sep,&rem);
face_id=atoi(faceid);
- printf("Orig Router: %s Face: %d \n",orig_router,face_id);
+
+ if ( nlsr->debugging )
+ printf("Orig Router: %s Face: %d \n",orig_router,face_id);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig Router: %s Face: %d \n",orig_router,face_id);
delete_face_from_npt_by_face_id(orig_router,face_id);
}
@@ -692,7 +776,11 @@
clean_old_fib_entries_from_npt(void)
{
- printf("clean_old_fib_entries_from_npt called\n\n");
+
+ if ( nlsr->debugging )
+ printf("clean_old_fib_entries_from_npt called\n\n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n");
int i, npt_element;
struct npt_entry *ne;
@@ -717,7 +805,11 @@
face_list_element=hashtb_n(ne->face_list);
if ( face_list_element <= 0 )
{
- printf(" Face: No Face \n");
+ if ( nlsr->debugging )
+ printf(" Face: No Face \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
+
}
else
{
@@ -739,12 +831,15 @@
nle=enle->data;
//delete all the fib entries here
- printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
-
+ //printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
+
if( is_neighbor(nle->name) == 0 )
{
- printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
+ if ( nlsr->debugging )
+ printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face);
}
@@ -941,14 +1036,20 @@
{
if ( is_neighbor(orig_router) == 0 )
{
- printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->debugging )
+ printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
}
else
{
if ( j == last_face && is_neighbor(nle->name)==0)
{
- printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->debugging )
+ printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
}
}