Deep Cleaning Routing Table, NPT, Map
diff --git a/nlsr.c b/nlsr.c
index 3f98b94..f865944 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -1087,39 +1087,8 @@
destroy_adl();
destroy_npl();
destroy_lsdb();
-
-
- /*
- int i, npt_element,rt_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->name_list);
- hashtb_destroy(&ne->face_list);
- hashtb_next(e);
- }
-
- hashtb_end(e);
- hashtb_destroy(&nlsr->npt);
- */
- /*
- struct routing_table_entry *rte;
- hashtb_start(nlsr->routing_table, e);
- rt_element=hashtb_n(nlsr->routing_table);
- for(i=0;i<rt_element;i++)
- {
- rte=e->data;
- hashtb_destroy(&rte->face_list);
- hashtb_next(e);
- }
- hashtb_end(e);
- hashtb_destroy(&nlsr->routing_table);
- */
+ destroy_npt();
+ destroy_routing_table();
if ( nlsr->ccns != NULL )
ccns_close(&nlsr->ccns, NULL, NULL);
@@ -1199,20 +1168,23 @@
nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);
- nlsr->in_interest.p = &incoming_interest;
- nlsr->in_content.p = &incoming_content;
-
nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
+ nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
+ nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
+ nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
+ /*
char *time_stamp=(char *) calloc (20,sizeof(char));
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);
+ */
- nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
- nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
- nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
+ nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
+
+ nlsr->in_interest.p = &incoming_interest;
+ nlsr->in_content.p = &incoming_content;
nlsr->is_synch_init=1;
nlsr->nlsa_id=0;
@@ -1225,7 +1197,6 @@
nlsr->detailed_logging=0;
nlsr->debugging=0;
- //nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL;
nlsr->interest_retry = INTEREST_RETRY;
nlsr->interest_resend_time = INTEREST_RESEND_TIME;
nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index feffb18..e46f60d 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -35,11 +35,12 @@
set_new_lsdb_version(void)
{
- char *time_stamp=get_current_timestamp_micro_v2();
+ //char *time_stamp=get_current_timestamp_micro_v2();
free(nlsr->lsdb->lsdb_version);
- nlsr->lsdb->lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
- memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
- free(time_stamp);
+ nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
+ //nlsr->lsdb->lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
+ //memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
+ //free(time_stamp);
}
/**
diff --git a/nlsr_npt.c b/nlsr_npt.c
index 81786af..948e0fb 100644
--- a/nlsr_npt.c
+++ b/nlsr_npt.c
@@ -241,7 +241,7 @@
hashtb_start(ne->name_list, enle);
nl_element=hashtb_n(ne->name_list);
-
+
for (i=0;i<nl_element;i++)
{
nle=enle->data;
@@ -258,9 +258,8 @@
hashtb_next(enle);
}
-
-
hashtb_end(enle);
+
if ( nlsr->debugging )
{
@@ -565,8 +564,10 @@
}
}
- hashtb_destroy(&ne->name_list);
- hashtb_destroy(&ne->face_list);
+ //hashtb_destroy(&ne->name_list);
+ //hashtb_destroy(&ne->face_list);
+ destroy_name_list(ne->name_list);
+ destroy_face_list(ne->face_list);
hashtb_delete(e);
}
else if ( res == HT_NEW_ENTRY )
@@ -735,6 +736,7 @@
res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
if ( res1 == HT_OLD_ENTRY )
{
+
hashtb_delete(ef);
}
else if ( res1 == HT_NEW_ENTRY )
@@ -1095,15 +1097,31 @@
}
void
-destroy_name_list(void)
+destroy_name_list(struct hashtb *name_list)
{
-
+ int j,nl_element;
+ struct name_list_entry *nle;
+ struct hashtb_enumerator eenle;
+ struct hashtb_enumerator *enle = &eenle;
+
+ hashtb_start(name_list, enle);
+ nl_element=hashtb_n(name_list);
+
+ for (j=0;j<nl_element;j++)
+ {
+ nle=enle->data;
+ free(nle->name);
+ hashtb_next(enle);
+ }
+ hashtb_end(enle);
+
+ hashtb_destroy(&name_list);
}
void
-destroy_face_list(void)
+destroy_face_list(struct hashtb *face_list)
{
-
+ hashtb_destroy(&face_list);
}
void
@@ -1123,41 +1141,12 @@
for(i=0;i<npt_element;i++)
{
ne=e->data;
-
- int j, nl_element,face_list_element;
- struct name_list_entry *nle;
- struct hashtb_enumerator eenle;
- struct hashtb_enumerator *enle = &eenle;
-
- hashtb_start(ne->name_list, enle);
- nl_element=hashtb_n(ne->name_list);
-
- for (j=0;j<nl_element;j++)
- {
- nle=enle->data;
- hashtb_next(enle);
- }
- hashtb_end(enle);
-
- struct face_list_entry *fle;
- struct hashtb_enumerator eef;
- struct hashtb_enumerator *ef = &eef;
-
- hashtb_start(ne->face_list, ef);
- face_list_element=hashtb_n(ne->face_list);
-
- for(j=0;j<face_list_element;j++)
- {
- fle=ef->data;
- hashtb_next(ef);
- }
-
- hashtb_end(ef);
-
-
+ destroy_name_list(ne->name_list);
+ destroy_face_list(ne->face_list);
hashtb_next(e);
}
-
hashtb_end(e);
+
+ hashtb_destroy(&nlsr->npt);
}
diff --git a/nlsr_npt.h b/nlsr_npt.h
index 8d54828..ecb6bda 100644
--- a/nlsr_npt.h
+++ b/nlsr_npt.h
@@ -26,5 +26,8 @@
void sort_faces_by_distance(int *faces,int *route_costs,int start,int element);
void update_ccnd_fib_for_orig_router(char *orig_router);
void get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces);
+void destroy_name_list(struct hashtb *name_list);
+void destroy_face_list(struct hashtb *face_list);
+void destroy_npt(void);
#endif
diff --git a/nlsr_route.c b/nlsr_route.c
index 6b45ed2..b6619ef 100644
--- a/nlsr_route.c
+++ b/nlsr_route.c
@@ -192,8 +192,10 @@
}
free(adj_matrix);
- hashtb_destroy(&nlsr->map);
- hashtb_destroy(&nlsr->rev_map);
+ destroy_map();
+ destroy_rev_map();
+ //hashtb_destroy(&nlsr->map);
+ //hashtb_destroy(&nlsr->rev_map);
}
nlsr->is_route_calculation_scheduled=0;
@@ -1059,7 +1061,7 @@
}
hashtb_end(ef);
}
- else if ( res == HT_OLD_ENTRY )
+ else if ( res == HT_NEW_ENTRY )
{
hashtb_delete(e);
}
@@ -1249,6 +1251,7 @@
memcpy(router,rte->dest_router,strlen(rte->dest_router)+1);
nlsr->event = ccn_schedule_event(nlsr->sched, 1, &delete_empty_rte, (void *)router , 0);
*/
+ destroy_routing_table_entry_comp(rte);
hashtb_delete(e);
i++;
}
@@ -1399,3 +1402,88 @@
return distance;
}
+
+void
+destroy_routing_table_entry_comp(struct routing_table_entry *rte)
+{
+
+ free(rte->dest_router);
+ hashtb_destroy(&rte->face_list);
+
+}
+
+void
+destroy_routing_table_entry(struct routing_table_entry *rte)
+{
+
+ destroy_routing_table_entry_comp(rte);
+ free(rte);
+}
+
+void
+destroy_routing_table(void)
+{
+ int i, rt_element;
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ struct routing_table_entry *rte;
+ hashtb_start(nlsr->routing_table, e);
+ rt_element=hashtb_n(nlsr->routing_table);
+ for(i=0;i<rt_element;i++)
+ {
+ rte=e->data;
+ free(rte->dest_router);
+ hashtb_destroy(&rte->face_list);
+ hashtb_next(e);
+ }
+ hashtb_end(e);
+ hashtb_destroy(&nlsr->routing_table);
+
+}
+
+void
+destroy_map(void)
+{
+
+ int i, map_element;
+ struct map_entry *me;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->map, e);
+ map_element=hashtb_n(nlsr->map);
+
+ for(i=0;i<map_element;i++)
+ {
+ me=e->data;
+ free(me->router);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+}
+
+void
+destroy_rev_map(void)
+{
+ int i, map_element;
+ struct map_entry *me;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->rev_map, e);
+ map_element=hashtb_n(nlsr->rev_map);
+
+ for(i=0;i<map_element;i++)
+ {
+ me=e->data;
+ free(me->router);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+}
diff --git a/nlsr_route.h b/nlsr_route.h
index b6dff03..1a3d70d 100644
--- a/nlsr_route.h
+++ b/nlsr_route.h
@@ -17,7 +17,6 @@
struct routing_table_entry
{
char *dest_router;
- //int next_hop_face;
struct hashtb *face_list;
};
@@ -68,4 +67,10 @@
void sort_hyperbolic_route(double *dist_dest,double *dist_nbr, long int *faces,long int start,long int element);
void update_routing_table_with_new_hyperbolic_route(long int dest_router_rev_map_index, long int face, double nbr_to_dest_dist);
+void destroy_routing_table_entry_comp(struct routing_table_entry *rte);
+void destroy_routing_table_entry(struct routing_table_entry *rte);
+void destroy_routing_table(void);
+void destroy_map(void);
+void destroy_rev_map(void);
+
#endif