LSA Refreshing And Dead Router LSA Removal Complete
diff --git a/nlsr.c b/nlsr.c
index 70a99a6..e73bdcc 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -479,6 +479,9 @@
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;
+ nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
+
nlsr->semaphor=NLSR_UNLOCKED;
diff --git a/nlsr.h b/nlsr.h
index 95087d3..9c8ea39 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -7,6 +7,8 @@
#define INTEREST_RESEND_TIME 15
#define NLSR_LOCKED 1
#define NLSR_UNLOCKED 0
+#define LSA_REFRESH_TIME 600
+#define ROUTER_DEAD_INTERVAL 900
struct name_prefix
{
@@ -66,6 +68,8 @@
long int lsdb_synch_interval;
int interest_retry;
long int interest_resend_time;
+ long int lsa_refresh_time;
+ long int router_dead_interval;
int semaphor;
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index f80a2b7..b145586 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -1151,11 +1151,112 @@
hashtb_end(e);
}
+int
+delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+ printf("delete_name_lsa called \n");
+
+ if(flags == CCN_SCHEDULE_CANCEL)
+ {
+ return -1;
+ }
+
+
+
+ nlsr_lock();
+
+ printf("LSA Key: %s \n",(char *)ev->evdata);
+
+ struct nlsa *nlsa;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ int res;
+
+ hashtb_start(nlsr->lsdb->name_lsdb, e);
+ res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ nlsa=e->data;
+ delete_npt_entry(nlsa->header->orig_router->name, nlsa->name_prefix->name);
+ hashtb_delete(e);
+ }
+ else if( res == HT_OLD_ENTRY )
+ {
+ nlsa=e->data;
+ delete_npt_entry(nlsa->header->orig_router->name, nlsa->name_prefix->name);
+ hashtb_delete(e);
+ }
+ hashtb_end(e);
+
+
+ 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);
+
+ //print_name_lsdb();
+
+ nlsr_unlock();
+
+ return 0;
+}
+
+int
+delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
+{
+ printf("delete_adj_lsa called \n");
+
+ if(flags == CCN_SCHEDULE_CANCEL)
+ {
+ return -1;
+ }
+ nlsr_lock();
+
+ printf("LSA Key: %s \n",(char *)ev->evdata);
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->lsdb->adj_lsdb, e);
+ res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
+
+ if( res == HT_OLD_ENTRY )
+ {
+ hashtb_delete(e);
+ }
+ else if( res == HT_OLD_ENTRY )
+ {
+ hashtb_delete(e);
+ }
+ hashtb_end(e);
+
+ 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);
+
+ if ( !nlsr->is_route_calculation_scheduled)
+ {
+ nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
+ nlsr->is_route_calculation_scheduled=1;
+ }
+
+ //print_adj_lsdb();
+
+ nlsr_unlock();
+
+ return 0;
+}
+
void
refresh_name_lsdb(void)
{
printf("refresh_name_lsdb called \n");
+ //int lsa_change_count=0;
+
char *time_stamp=(char *)malloc(20);
memset(time_stamp,0,20);
get_current_timestamp_micro(time_stamp);
@@ -1176,7 +1277,58 @@
name_lsa=e->data;
lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
- printf("LSA Life Time: %ld \n",lsa_life_time);
+ printf("LSA Life Time: %ld \n",lsa_life_time);
+
+ if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
+ {
+ if ( lsa_life_time > nlsr->lsa_refresh_time )
+ {
+ printf("Own Name LSA need to be refrshed\n");
+ char *current_time_stamp=(char *)malloc(20);
+ memset(current_time_stamp,0,20);
+ get_current_timestamp_micro(current_time_stamp);
+
+ free(name_lsa->header->orig_time);
+ name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
+ memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
+ memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
+
+ free(current_time_stamp);
+
+ 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);
+
+ print_name_lsdb();
+ //lsa_change_count++;
+ }
+ }
+ else
+ {
+ if ( lsa_life_time > nlsr->router_dead_interval )
+ {
+ printf("Others Name LSA need to be deleted\n");
+
+ char lst[2];
+ memset(lst,0,2);
+ sprintf(lst,"%d",name_lsa->header->ls_type);
+
+ 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));
+
+ nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
+ //lsa_change_count++;
+ }
+ }
hashtb_next(e);
}
@@ -1184,14 +1336,16 @@
hashtb_end(e);
free(time_stamp);
+
}
-int
+void
refresh_adj_lsdb(void)
{
printf("refresh_adj_lsdb called \n");
+
char *time_stamp=(char *)malloc(20);
memset(time_stamp,0,20);
get_current_timestamp_micro(time_stamp);
@@ -1214,14 +1368,54 @@
lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
printf("LSA Life Time: %ld \n",lsa_life_time);
+ if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
+ {
+ if ( lsa_life_time > nlsr->lsa_refresh_time )
+ {
+ printf("Own Adj LSA need to be refrshed\n");
+
+ char *current_time_stamp=(char *)malloc(20);
+ memset(current_time_stamp,0,20);
+ get_current_timestamp_micro(current_time_stamp);
+
+ free(adj_lsa->header->orig_time);
+ adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
+ memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
+ memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
+
+ free(current_time_stamp);
+
+
+ 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);
+
+ print_adj_lsdb();
+ }
+ }
+ else
+ {
+ if ( lsa_life_time > nlsr->router_dead_interval )
+ {
+ printf("Others Adj LSA need to be deleted\n");
+
+ char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
+ memset(key,0,adj_lsa->header->orig_router->length+2);
+ make_adj_lsa_key(key,adj_lsa);
+ printf("Adjacent LSA key: %s \n",key);
+
+ nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
+ }
+ }
+
+
+
hashtb_next(e);
}
hashtb_end(e);
free(time_stamp);
-
- return 0;
}
int
@@ -1233,18 +1427,14 @@
}
nlsr_lock();
+
printf("refresh_lsdb called \n");
refresh_name_lsdb();
refresh_adj_lsdb();
- if ( !nlsr->is_route_calculation_scheduled )
- {
- nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
- nlsr->is_route_calculation_scheduled=1;
- }
-
nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
+
nlsr_unlock();
return 0;
}
diff --git a/nlsr_npt.c b/nlsr_npt.c
index 9fe4565..a4f3e33 100644
--- a/nlsr_npt.c
+++ b/nlsr_npt.c
@@ -173,6 +173,11 @@
}
hashtb_end(enle);
+
+ if ( hashtb_n(ne->name_list) == 0 )
+ {
+ hashtb_delete(e);
+ }
}
hashtb_end(e);
diff --git a/utility.c b/utility.c
index 49ad52c..64e81a8 100644
--- a/utility.c
+++ b/utility.c
@@ -70,7 +70,7 @@
long int
-get_time_diff(char *time1, char *time2)
+get_time_diff(const char *time1, const char *time2)
{
long int diff_secs;
diff --git a/utility.h b/utility.h
index 75bf5ab..6015ecc 100644
--- a/utility.h
+++ b/utility.h
@@ -5,6 +5,6 @@
char * getGmTimeStamp(void);
long int get_current_time_sec(void);
void get_current_timestamp_micro(char * microSec);
-long int get_time_diff(char *time1, char *time2);
+long int get_time_diff(const char *time1, const char *time2);
#endif