blob: a2eb400b5815dba2eaee457e4e5e4fc4e03399e1 [file] [log] [blame]
akmhoquef1161eb2012-08-21 09:37:21 -04001#include<stdio.h>
2#include<string.h>
3#include<stdlib.h>
4#include <unistd.h>
5#include <getopt.h>
6#include <sys/time.h>
7#include <assert.h>
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12
13#include <ccn/ccn.h>
14#include <ccn/uri.h>
15#include <ccn/keystore.h>
16#include <ccn/signing.h>
17#include <ccn/schedule.h>
18#include <ccn/hashtb.h>
19
20#include "nlsr.h"
akmhoque03004e62012-09-06 01:12:28 -050021#include "nlsr_ndn.h"
akmhoquef1161eb2012-08-21 09:37:21 -040022#include "nlsr_lsdb.h"
akmhoquef71d9082012-08-22 12:51:53 -040023#include "utility.h"
akmhoque03004e62012-09-06 01:12:28 -050024#include "nlsr_npl.h"
akmhoque53f64222012-09-05 13:57:51 -050025#include "nlsr_adl.h"
akmhoque29c1db52012-09-07 14:47:43 -050026#include "nlsr_route.h"
akmhoque3560cb62012-09-09 10:52:30 -050027#include "nlsr_npt.h"
akmhoqueb77b95f2013-02-08 12:28:47 -060028#include "nlsr_sync.h"
akmhoque438b07e2012-08-21 10:13:57 -040029
akmhoque0ab71642013-02-21 10:10:33 -060030/**
31* LSDB version is updated to last updated timestamp
32*/
33
akmhoquef71d9082012-08-22 12:51:53 -040034void
akmhoque53f64222012-09-05 13:57:51 -050035set_new_lsdb_version(void)
akmhoquef71d9082012-08-22 12:51:53 -040036{
akmhoquef71d9082012-08-22 12:51:53 -040037
akmhoque6682ca32013-02-22 00:29:35 -060038 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -050039 free(nlsr->lsdb->lsdb_version);
akmhoque6682ca32013-02-22 00:29:35 -060040 nlsr->lsdb->lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -050041 memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -050042 free(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040043}
44
akmhoque0ab71642013-02-21 10:10:33 -060045/**
46* Make key for storing Name LSA in Name LSDB
47*/
48
akmhoque03004e62012-09-06 01:12:28 -050049void
50make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
51{
52
akmhoque03004e62012-09-06 01:12:28 -050053 char lst[2];
54 memset(lst,0,2);
55 sprintf(lst,"%d",ls_type);
56
57 char lsid[10];
58 memset(lsid,0,10);
59 sprintf(lsid,"%ld",ls_id);
60
akmhoqueeacf44f2013-02-22 01:02:13 -060061 memcpy(key,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -050062 memcpy(key+strlen(key),"/",1);
63 memcpy(key+strlen(key),lst,strlen(lst));
64 memcpy(key+strlen(key),"/",1);
65 memcpy(key+strlen(key),lsid,strlen(lsid));
akmhoqueeacf44f2013-02-22 01:02:13 -060066 key[strlen(key)]='\0';
67
akmhoqueb77b95f2013-02-08 12:28:47 -060068 if ( nlsr->debugging )
69 printf("name LSA Key: %s\n", key);
70}
71
akmhoque0ab71642013-02-21 10:10:33 -060072/**
73* Make content name prefix for Name LSA to store in repo
74*/
akmhoqueb77b95f2013-02-08 12:28:47 -060075
76void
akmhoque0ab71642013-02-21 10:10:33 -060077make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
78 long int ls_id,char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060079{
akmhoque0ab71642013-02-21 10:10:33 -060080 sprintf(key,"%s%s/lsType.%d/lsId.%ld/%s",slice_prefix, orig_router, ls_type,
81 ls_id, orig_time);
akmhoqueeacf44f2013-02-22 01:02:13 -060082 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -060083 if ( nlsr->debugging )
84 printf("Name LSA prefix for repo content: %s\n",key);
85}
86
akmhoque0ab71642013-02-21 10:10:33 -060087/**
88* Make content name prefix for Adj LSA to store in repo
89*/
90
akmhoqueb77b95f2013-02-08 12:28:47 -060091void
akmhoque0ab71642013-02-21 10:10:33 -060092make_adj_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
93 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060094{
95
96 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
akmhoqueeacf44f2013-02-22 01:02:13 -060097 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -060098 if ( nlsr->debugging )
99 printf("Name LSA prefix for repo content:%s\n",key);
100}
101
akmhoque0ab71642013-02-21 10:10:33 -0600102/**
103* Make content name prefix for Cor LSA to store in repo
104*/
105
akmhoqueb77b95f2013-02-08 12:28:47 -0600106void
akmhoque0ab71642013-02-21 10:10:33 -0600107make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
108 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -0600109{
110
111 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
akmhoqueeacf44f2013-02-22 01:02:13 -0600112 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -0600113 if ( nlsr->debugging )
114 printf("Cor LSA prefix for repo content:%s\n",key);
akmhoque03004e62012-09-06 01:12:28 -0500115}
akmhoque53f64222012-09-05 13:57:51 -0500116
akmhoque0ab71642013-02-21 10:10:33 -0600117/**
118* Build name lsa for all name prefixes in Name Prefix List (NPL). Intsall Name
119* LSA in Name LSDB for router itself.
120*/
121
akmhoqueeacf44f2013-02-22 01:02:13 -0600122void
123destroy_name_lsa(struct nlsa * name_lsa)
124{
125 if ( name_lsa->header->orig_router->name )
126 free(name_lsa->header->orig_router->name);
127 if ( name_lsa->header->orig_router )
128 free(name_lsa->header->orig_router);
129 if ( name_lsa->header )
130 free(name_lsa->header);
131 if ( name_lsa->name_prefix->name )
132 free(name_lsa->name_prefix->name);
133 if ( name_lsa->name_prefix )
134 free(name_lsa->name_prefix);
135 if ( name_lsa )
136 free(name_lsa);
137}
akmhoque0ab71642013-02-21 10:10:33 -0600138
akmhoquef71d9082012-08-22 12:51:53 -0400139void
akmhoque53f64222012-09-05 13:57:51 -0500140build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -0400141{
akmhoque7b791452012-10-30 11:24:56 -0500142 if ( nlsr->debugging )
143 printf("build_and_install_name_lsas called \n");
144 if ( nlsr->detailed_logging )
145 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n");
akmhoquef71d9082012-08-22 12:51:53 -0400146
akmhoquef71d9082012-08-22 12:51:53 -0400147 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600148 struct name_prefix_list_entry *npe;
akmhoquef71d9082012-08-22 12:51:53 -0400149
150 struct hashtb_enumerator ee;
151 struct hashtb_enumerator *e = &ee;
152
153 hashtb_start(nlsr->npl, e);
154 npl_element=hashtb_n(nlsr->npl);
155
156 for(i=0;i<npl_element;i++)
157 {
akmhoque3171d652012-11-13 11:44:33 -0600158 npe=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500159 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
akmhoque3171d652012-11-13 11:44:33 -0600160 build_name_lsa(name_lsa,npe->np);
akmhoque03004e62012-09-06 01:12:28 -0500161
akmhoquef71d9082012-08-22 12:51:53 -0400162 install_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600163 update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600164 destroy_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400165 hashtb_next(e);
166 }
167
akmhoque53f64222012-09-05 13:57:51 -0500168 hashtb_end(e);
akmhoque3171d652012-11-13 11:44:33 -0600169
170 print_name_prefix_from_npl();
171
172}
173
akmhoque0ab71642013-02-21 10:10:33 -0600174/**
175* Build and Install one Name LSA Use ful for API
176*/
177
akmhoque3171d652012-11-13 11:44:33 -0600178void
179build_and_install_single_name_lsa(struct name_prefix *np)
180{
181 if ( nlsr->debugging )
182 printf("build_and_install_single_name_lsa called \n");
183 if ( nlsr->detailed_logging )
184 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name_lsa called\n");
185
186 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
187 build_name_lsa(name_lsa,np);
188
189 install_name_lsa(name_lsa);
190 update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600191 destroy_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600192 print_name_prefix_from_npl();
akmhoquef71d9082012-08-22 12:51:53 -0400193
akmhoquef71d9082012-08-22 12:51:53 -0400194}
195
akmhoque53f64222012-09-05 13:57:51 -0500196void
197build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
198{
akmhoque53f64222012-09-05 13:57:51 -0500199 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
200 name_lsa->header->ls_type=LS_TYPE_NAME;
201
akmhoqueeacf44f2013-02-22 01:02:13 -0600202 //char *time_stamp=(char *)malloc(20);
203 //memset(time_stamp,0,20);
204 //get_current_timestamp_micro(time_stamp);
205
206 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500207 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500208 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
209 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500210
211 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500212
213 name_lsa->header->ls_id=++nlsr->nlsa_id;
akmhoqueeacf44f2013-02-22 01:02:13 -0600214 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
215 name_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
216 //memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500217 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
218 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500219 name_lsa->header->isValid=1;
220
221
222 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueeacf44f2013-02-22 01:02:13 -0600223 name_lsa->name_prefix->name=(char *)calloc(np->length,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -0500224 memcpy(name_lsa->name_prefix->name,np->name,np->length);
225 name_lsa->name_prefix->length=np->length;
226
227}
228
akmhoque53f64222012-09-05 13:57:51 -0500229void
230install_name_lsa(struct nlsa *name_lsa)
231{
akmhoque53f64222012-09-05 13:57:51 -0500232
akmhoque54d86112013-02-21 16:42:34 -0600233 /*char *time_stamp=(char *)malloc(20);
akmhoqueffacaa82012-09-13 17:48:30 -0500234 memset(time_stamp,0,20);
akmhoque54d86112013-02-21 16:42:34 -0600235 get_current_timestamp_micro(time_stamp);*/
akmhoqueffacaa82012-09-13 17:48:30 -0500236
237
akmhoque0ab71642013-02-21 10:10:33 -0600238 char lst[2];
239 memset(lst,0,2);
240 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoqueffacaa82012-09-13 17:48:30 -0500241
akmhoque0ab71642013-02-21 10:10:33 -0600242 char lsid[10];
243 memset(lsid,0,10);
244 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque3171d652012-11-13 11:44:33 -0600245
akmhoque0ab71642013-02-21 10:10:33 -0600246 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
247 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
248 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque53f64222012-09-05 13:57:51 -0500249
akmhoque0ab71642013-02-21 10:10:33 -0600250 if ( nlsr->debugging )
251 printf("Key:%s Length:%d\n",key,(int)strlen(key));
252 if ( nlsr->detailed_logging )
253 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key));
254
akmhoque8876e982013-02-21 13:35:46 -0600255 struct nlsa *new_name_lsa; //=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque53f64222012-09-05 13:57:51 -0500256
akmhoque0ab71642013-02-21 10:10:33 -0600257 struct hashtb_enumerator ee;
258 struct hashtb_enumerator *e = &ee;
259 int res;
akmhoque53f64222012-09-05 13:57:51 -0500260
akmhoque0ab71642013-02-21 10:10:33 -0600261 hashtb_start(nlsr->lsdb->name_lsdb, e);
262 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500263
akmhoque0ab71642013-02-21 10:10:33 -0600264 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500265 {
akmhoqueffacaa82012-09-13 17:48:30 -0500266
akmhoque7b791452012-10-30 11:24:56 -0500267 if ( nlsr->debugging )
268 printf("New Name LSA... Adding to LSDB\n");
269 if ( nlsr->detailed_logging )
270 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n");
271
272
akmhoqueffacaa82012-09-13 17:48:30 -0500273 new_name_lsa = e->data;
akmhoque54d86112013-02-21 16:42:34 -0600274 //memcpy(e->data, name_lsa, sizeof(name_lsa));
akmhoque8876e982013-02-21 13:35:46 -0600275
akmhoque54d86112013-02-21 16:42:34 -0600276
akmhoque0ab71642013-02-21 10:10:33 -0600277 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500278 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
279
280 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
281 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque8876e982013-02-21 13:35:46 -0600282 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500283
284 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque0ab71642013-02-21 10:10:33 -0600285 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500286 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
287 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
288 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
289 new_name_lsa->header->isValid=name_lsa->header->isValid;
290
291
akmhoque0ab71642013-02-21 10:10:33 -0600292 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500293 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
294 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
295 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
akmhoque8876e982013-02-21 13:35:46 -0600296
akmhoqueffacaa82012-09-13 17:48:30 -0500297
akmhoque7b791452012-10-30 11:24:56 -0500298 if ( nlsr->debugging )
299 {
300 printf("New Name LSA Added....\n");
301 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
302 }
303 if ( nlsr->detailed_logging )
304 {
305 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n");
306 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
307 }
akmhoque54d86112013-02-21 16:42:34 -0600308
akmhoqueffacaa82012-09-13 17:48:30 -0500309 set_new_lsdb_version();
akmhoque54d86112013-02-21 16:42:34 -0600310
akmhoque7b791452012-10-30 11:24:56 -0500311 if ( nlsr->debugging )
312 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
313 if ( nlsr->detailed_logging )
314 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500315
akmhoque9e9fc722012-09-26 14:03:25 -0500316
akmhoquede61ba92012-09-20 22:19:12 -0500317 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500318 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500319 {
akmhoquede61ba92012-09-20 22:19:12 -0500320 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL);
akmhoqueffacaa82012-09-13 17:48:30 -0500321 if ( check == HT_NEW_ENTRY )
322 {
akmhoque7b791452012-10-30 11:24:56 -0500323 if ( nlsr->debugging )
324 printf("Added in npt \n");
325 if ( nlsr->detailed_logging )
326 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500327 }
akmhoque3560cb62012-09-09 10:52:30 -0500328 }
akmhoqueffacaa82012-09-13 17:48:30 -0500329 else
akmhoque3560cb62012-09-09 10:52:30 -0500330 {
akmhoquede61ba92012-09-20 22:19:12 -0500331 int *faces=malloc(num_next_hop*sizeof(int));
332 int *route_costs=malloc(num_next_hop*sizeof(int));
333 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500334 if ( nlsr->debugging )
335 {
336 printf("Printing from install_name_lsa \n");
337 int j;
338 for(j=0;j<num_next_hop;j++)
339 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
340 }
341 if ( nlsr->detailed_logging )
342 {
343 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
344 int j;
345 for(j=0;j<num_next_hop;j++)
346 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
347 }
akmhoquede61ba92012-09-20 22:19:12 -0500348 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500349 if ( check == HT_NEW_ENTRY )
350 {
akmhoque7b791452012-10-30 11:24:56 -0500351 if ( nlsr->debugging )
352 printf("Added in npt \n");
353 if ( nlsr->detailed_logging )
354 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500355 }
akmhoquede61ba92012-09-20 22:19:12 -0500356 free(faces);
357 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500358
akmhoque3560cb62012-09-09 10:52:30 -0500359 }
akmhoquede61ba92012-09-20 22:19:12 -0500360
akmhoque9e9fc722012-09-26 14:03:25 -0500361 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
362 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
akmhoque54d86112013-02-21 16:42:34 -0600363 //write_log_for_name_lsa(new_name_lsa);
akmhoque9e9fc722012-09-26 14:03:25 -0500364 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500365
akmhoque54d86112013-02-21 16:42:34 -0600366 //free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -0500367
368 }
369 else if(res == HT_OLD_ENTRY)
370 {
371 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500372 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500373 {
akmhoque7b791452012-10-30 11:24:56 -0500374 if ( nlsr->debugging )
375 printf("Older Adj LSA. Discarded... \n");
376 if ( nlsr->detailed_logging )
377 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500378 }
379 else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 )
380 {
akmhoque7b791452012-10-30 11:24:56 -0500381 if ( nlsr->debugging )
382 printf("Duplicate Adj LSA. Discarded... \n");
383 if ( nlsr->detailed_logging )
384 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500385 }
386 else
387 {
388 if ( name_lsa->header->isValid == 0 )
389 {
390 // have to call to delete npt table entry
akmhoque3cced642012-09-24 16:20:20 -0500391 delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500392
393 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
394 {
akmhoque9e9fc722012-09-26 14:03:25 -0500395 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
396 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
397 write_log_for_name_lsa(new_name_lsa);
398 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
399
akmhoqueffacaa82012-09-13 17:48:30 -0500400 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500401 if ( nlsr->debugging )
402 printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
403 if ( nlsr->detailed_logging )
404 writeLogg(__FILE__,__FUNCTION__,__LINE__,"isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500405 }
406 else
407 {
408 new_name_lsa->header->isValid=name_lsa->header->isValid;
409 free(new_name_lsa->header->orig_time);
410 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
411 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
412 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
413 }
akmhoque7b791452012-10-30 11:24:56 -0500414 if ( nlsr->debugging )
415 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
416 if ( nlsr->detailed_logging )
417 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500418 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500419 if ( nlsr->debugging )
420 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
421 if ( nlsr->detailed_logging )
422 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500423 }
424 else
425 {
426 int is_npt_update=0;
427 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
428 {
429 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500430 delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500431 }
432
433 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500434 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
435 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
436 write_log_for_name_lsa(new_name_lsa);
437 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
438
akmhoqueffacaa82012-09-13 17:48:30 -0500439
440 free(new_name_lsa->header->orig_time);
441 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
442 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600443 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500444
445 new_name_lsa->header->isValid=name_lsa->header->isValid;
446
447 free(new_name_lsa->name_prefix->name);
448 free(new_name_lsa->name_prefix);
449 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
450 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
451 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
452 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
453
akmhoque9e9fc722012-09-26 14:03:25 -0500454
455 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
456 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
457 write_log_for_name_lsa(new_name_lsa);
458 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
459
akmhoque7b791452012-10-30 11:24:56 -0500460 if ( nlsr->debugging )
461 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
462 if ( nlsr->detailed_logging )
463 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
464
akmhoqueffacaa82012-09-13 17:48:30 -0500465 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500466
467 if ( nlsr->debugging )
468 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
469 if ( nlsr->detailed_logging )
470 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
471
akmhoqueffacaa82012-09-13 17:48:30 -0500472
473 if( is_npt_update == 1 )
474 {
akmhoquede61ba92012-09-20 22:19:12 -0500475 //struct hashtb *face_list;
476 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
477 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500478 {
akmhoquede61ba92012-09-20 22:19:12 -0500479
480 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL);
akmhoqueffacaa82012-09-13 17:48:30 -0500481 if ( check == HT_NEW_ENTRY )
482 {
akmhoque7b791452012-10-30 11:24:56 -0500483 if ( nlsr->debugging )
484 printf("Added in npt \n");
485 if ( nlsr->detailed_logging )
486 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500487 }
488 }
489 else
490 {
akmhoquede61ba92012-09-20 22:19:12 -0500491 int *faces=malloc(num_next_hop*sizeof(int));
492 int *route_costs=malloc(num_next_hop*sizeof(int));
493 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500494
495 if ( nlsr->debugging )
496 {
497 printf("Printing from install_name_lsa \n");
498 int j;
499 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500500 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500501 }
502 if ( nlsr->detailed_logging )
503 {
504 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
505 int j;
506 for(j=0;j<num_next_hop;j++)
507 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
508 }
509
akmhoquede61ba92012-09-20 22:19:12 -0500510
511 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500512 if ( check == HT_NEW_ENTRY )
513 {
akmhoque7b791452012-10-30 11:24:56 -0500514 if ( nlsr->debugging )
515 printf("Added in npt \n");
516 if ( nlsr->detailed_logging )
517 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500518 }
akmhoquede61ba92012-09-20 22:19:12 -0500519 free(faces);
520 free(route_costs);
521
akmhoqueffacaa82012-09-13 17:48:30 -0500522 }
akmhoquede61ba92012-09-20 22:19:12 -0500523
akmhoqueffacaa82012-09-13 17:48:30 -0500524 }
525 }
526 }
527
akmhoque3560cb62012-09-09 10:52:30 -0500528 }
akmhoque53f64222012-09-05 13:57:51 -0500529
akmhoqueffacaa82012-09-13 17:48:30 -0500530 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500531
akmhoque569a93d2013-02-21 10:19:54 -0600532 //free(key);
akmhoque53f64222012-09-05 13:57:51 -0500533}
534
akmhoque9e9fc722012-09-26 14:03:25 -0500535void
536write_log_for_name_lsa(struct nlsa *name_lsa)
537{
538
539 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
540 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
541 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500542 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
543 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
544 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
545 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500546 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
547 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
548 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
549 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
550}
akmhoque53f64222012-09-05 13:57:51 -0500551
akmhoque03004e62012-09-06 01:12:28 -0500552void
553print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500554{
akmhoque53f64222012-09-05 13:57:51 -0500555
akmhoque7b791452012-10-30 11:24:56 -0500556 if ( nlsr->debugging )
557 {
558 printf("-----------Name LSA Content---------------\n");
559 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
560 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
561 printf(" LS Type : %d\n",name_lsa->header->ls_type);
562 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
563 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
564 printf(" Is Valid : %d\n",name_lsa->header->isValid);
565 printf(" LSA Data \n");
566 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
567 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
568
569 printf("\n");
570 }
akmhoquef71d9082012-08-22 12:51:53 -0400571}
572
573void
574print_name_lsdb(void)
575{
akmhoque7b791452012-10-30 11:24:56 -0500576 if ( nlsr->debugging )
577 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500578 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400579 struct nlsa *name_lsa;
580
581 struct hashtb_enumerator ee;
582 struct hashtb_enumerator *e = &ee;
583
584 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500585 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400586
akmhoque53f64222012-09-05 13:57:51 -0500587 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400588 {
akmhoque7b791452012-10-30 11:24:56 -0500589 if ( nlsr->debugging )
590 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400591 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500592 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400593 hashtb_next(e);
594 }
595
596 hashtb_end(e);
597
akmhoque3171d652012-11-13 11:44:33 -0600598 if ( nlsr->debugging )
599 printf("\n");
600 if ( nlsr->detailed_logging )
601 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500602}
603
akmhoque03004e62012-09-06 01:12:28 -0500604
605void
606build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500607{
akmhoque7b791452012-10-30 11:24:56 -0500608 if ( nlsr->debugging )
609 printf("build_and_install_others_name_lsa called \n");
610 if ( nlsr->detailed_logging )
611 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500612
akmhoque03004e62012-09-06 01:12:28 -0500613 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
614 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
615 print_name_lsa(name_lsa);
616 install_name_lsa(name_lsa);
617 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500618 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500619
akmhoque03004e62012-09-06 01:12:28 -0500620 free(name_lsa->header->orig_router->name);
621 free(name_lsa->header->orig_router);
622 free(name_lsa->header);
623 free(name_lsa->name_prefix->name);
624 free(name_lsa->name_prefix);
625 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500626
627}
628
629void
akmhoque03004e62012-09-06 01:12:28 -0500630build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500631{
akmhoque7b791452012-10-30 11:24:56 -0500632 if ( nlsr->debugging )
633 printf("build_others_name_lsa called\n");
634 if ( nlsr->detailed_logging )
635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500636
akmhoque03004e62012-09-06 01:12:28 -0500637 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
638 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500639
akmhoque03004e62012-09-06 01:12:28 -0500640 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
641 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600642 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoque53f64222012-09-05 13:57:51 -0500643
akmhoque03004e62012-09-06 01:12:28 -0500644 name_lsa->header->ls_id=ls_id;
645 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
646 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
647 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600648 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -0500649 name_lsa->header->orig_router->length=strlen(orig_router)+1;
650 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500651
akmhoque03004e62012-09-06 01:12:28 -0500652 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
653 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
654 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600655 memcpy(name_lsa->name_prefix->name,np,strlen(np));
akmhoque03004e62012-09-06 01:12:28 -0500656 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400657}
akmhoqued79438d2012-08-27 13:31:42 -0500658
659
akmhoqueb77b95f2013-02-08 12:28:47 -0600660void
661make_cor_lsa_key(char *key,struct clsa *cor_lsa)
662{
663 memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
664 memcpy(key+strlen(key),"/",1);
665 char ls_type[2];
666 sprintf(ls_type,"%d",cor_lsa->header->ls_type);
667 memcpy(key+strlen(key),ls_type,strlen(ls_type));
668 key[strlen(key)]='\0';
669}
akmhoqueffacaa82012-09-13 17:48:30 -0500670
671
akmhoque53f64222012-09-05 13:57:51 -0500672void
673make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500674{
akmhoque53f64222012-09-05 13:57:51 -0500675 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
676 memcpy(key+strlen(key),"/",1);
677 char ls_type[2];
678 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
679 memcpy(key+strlen(key),ls_type,strlen(ls_type));
680 key[strlen(key)]='\0';
681}
682
akmhoque03004e62012-09-06 01:12:28 -0500683int
684build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
685{
akmhoqueffacaa82012-09-13 17:48:30 -0500686 if(flags == CCN_SCHEDULE_CANCEL)
687 {
688 return -1;
689 }
690
691 nlsr_lock();
692
akmhoque7b791452012-10-30 11:24:56 -0500693 if ( nlsr->debugging )
694 printf("build_and_install_adj_lsa called \n");
695 if ( nlsr->detailed_logging )
696 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
697
698 if ( nlsr->debugging )
699 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
700 if ( nlsr->detailed_logging )
701 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500702
703 if(nlsr->adj_build_flag > 0)
704 {
akmhoque7b791452012-10-30 11:24:56 -0500705 if ( nlsr->debugging )
706 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
707 if ( nlsr->detailed_logging )
708 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
709
akmhoque03004e62012-09-06 01:12:28 -0500710 if ( is_adj_lsa_build()> 0)
711 {
712 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
713 build_adj_lsa(adj_lsa);
714 install_adj_lsa(adj_lsa);
715
akmhoqueb77b95f2013-02-08 12:28:47 -0600716 char lst[2];
717 memset(lst,0,2);
718 sprintf(lst,"%d",LS_TYPE_ADJ);
719
720 char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15);
721 memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15);
722 make_adj_lsa_prefix_for_repo(repo_key, adj_lsa->header->orig_router->name,LS_TYPE_ADJ,adj_lsa->header->orig_time,nlsr->slice_prefix);
723
724 if ( nlsr->debugging )
725 printf("Adj LSA Repo Key: %s \n",repo_key);
726
727 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
728 memset(key,0,adj_lsa->header->orig_router->length+2+2);
729 make_adj_lsa_key(key,adj_lsa);
730 if ( nlsr->debugging )
731 printf("Adj LSA: %s \n",key);
732
733 struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
734 lsaid->name=(char *)malloc(strlen(key)+1);
735 memset(lsaid->name, 0, strlen(key)+1);
736 memcpy(lsaid->name,key,strlen(key));
737 lsaid->length=strlen(key)+1;
738
739
740 write_adj_lsa_to_repo(repo_key, lsaid);
741
akmhoque569a93d2013-02-21 10:19:54 -0600742 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600743 free(repo_key);
744 free(lsaid->name);
745 free(lsaid);
746
747
748
akmhoque03004e62012-09-06 01:12:28 -0500749 free(adj_lsa->header->orig_router->name);
750 free(adj_lsa->header->orig_router);
751 free(adj_lsa->header->orig_time);
752 free(adj_lsa->header);
753 free(adj_lsa->body);
754 free(adj_lsa);
755 nlsr->adj_build_flag=0;
756 print_adj_lsdb();
757 }
758 else
759 {
akmhoque7b791452012-10-30 11:24:56 -0500760 if ( nlsr->debugging )
761 printf("Can not build adj LSA now\n");
762 if ( nlsr->detailed_logging )
763 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500764 }
765 }
766 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500767
768 nlsr_unlock();
769
akmhoque03004e62012-09-06 01:12:28 -0500770 return 0;
771}
772
773
774void
775build_adj_lsa(struct alsa * adj_lsa)
776{
akmhoque7b791452012-10-30 11:24:56 -0500777 if ( nlsr->debugging )
778 printf("build_adj_lsa called \n");
779 if ( nlsr->detailed_logging )
780 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500781
782 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500783
akmhoque03004e62012-09-06 01:12:28 -0500784 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
785 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
786 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
787 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
788 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
789 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
790
791 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
792
793 char *time_stamp=(char *)malloc(20);
794 memset(time_stamp,0,20);
795 get_current_timestamp_micro(time_stamp);
796
797 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
798 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
799 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
800 free(time_stamp);
801
akmhoque03004e62012-09-06 01:12:28 -0500802 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500803
804
805 struct ccn_charbuf *c=ccn_charbuf_create();
806 get_active_nbr_adj_data(c);
807 char *data=ccn_charbuf_as_string(c);
808
809 adj_lsa->body=(char *)malloc(strlen(data)+1);
810 memset(adj_lsa->body,0,strlen(data)+1);
811 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
812 ccn_charbuf_destroy(&c);
813
akmhoque03004e62012-09-06 01:12:28 -0500814 nlsr->adj_build_count++;
815
816
817}
818
819
akmhoque53f64222012-09-05 13:57:51 -0500820void
821install_adj_lsa(struct alsa * adj_lsa)
822{
akmhoqued79438d2012-08-27 13:31:42 -0500823
akmhoque7b791452012-10-30 11:24:56 -0500824 if ( nlsr->debugging )
825 printf("install_adj_lsa called \n");
826 if ( nlsr->detailed_logging )
827 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
828
akmhoque03004e62012-09-06 01:12:28 -0500829
akmhoqueffacaa82012-09-13 17:48:30 -0500830 char *time_stamp=(char *)malloc(20);
831 memset(time_stamp,0,20);
832 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500833
akmhoqueffacaa82012-09-13 17:48:30 -0500834
835 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
836 memset(key,0,adj_lsa->header->orig_router->length+2);
837 make_adj_lsa_key(key,adj_lsa);
akmhoqueffacaa82012-09-13 17:48:30 -0500838
akmhoque8876e982013-02-21 13:35:46 -0600839 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500840
841 struct hashtb_enumerator ee;
842 struct hashtb_enumerator *e = &ee;
843 int res;
844
845 hashtb_start(nlsr->lsdb->adj_lsdb, e);
846 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500847
akmhoque03004e62012-09-06 01:12:28 -0500848
akmhoque53f64222012-09-05 13:57:51 -0500849
akmhoque62c0c192012-09-24 07:49:25 -0500850 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500851 {
akmhoque62c0c192012-09-24 07:49:25 -0500852 if ( adj_lsa->no_link > 0)
853 {
akmhoque3171d652012-11-13 11:44:33 -0600854 if ( nlsr->debugging )
855 printf("New ADJ LSA... Adding to LSDB\n");
856 if ( nlsr->detailed_logging )
857 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
akmhoque62c0c192012-09-24 07:49:25 -0500858 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500859
akmhoque62c0c192012-09-24 07:49:25 -0500860 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
861 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
862 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
863 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500864
akmhoque62c0c192012-09-24 07:49:25 -0500865 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
866 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
867 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
868 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500869
akmhoque62c0c192012-09-24 07:49:25 -0500870 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500871
akmhoque62c0c192012-09-24 07:49:25 -0500872 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
873 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
874 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
875
876 add_next_hop_router(new_adj_lsa->header->orig_router->name);
877 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500878
879 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
880 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
881 write_log_for_adj_lsa(new_adj_lsa);
882 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500883 }
884 else
885 {
886 hashtb_delete(e);
887 }
akmhoque53f64222012-09-05 13:57:51 -0500888
akmhoque7b791452012-10-30 11:24:56 -0500889 if ( nlsr->debugging )
890 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
891 if ( nlsr->detailed_logging )
892 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
893
akmhoque53f64222012-09-05 13:57:51 -0500894 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500895
896 if ( nlsr->debugging )
897 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
898 if ( nlsr->detailed_logging )
899 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
900
akmhoqueffacaa82012-09-13 17:48:30 -0500901 }
902 else if(res == HT_OLD_ENTRY)
903 {
904 new_adj_lsa = e->data;
905 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
906 {
akmhoque7b791452012-10-30 11:24:56 -0500907 if ( nlsr->debugging )
908 printf("Older/Duplicate Adj LSA. Discarded...\n");
909 if ( nlsr->detailed_logging )
910 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500911 }
912 else
913 {
akmhoqueffacaa82012-09-13 17:48:30 -0500914
akmhoque62c0c192012-09-24 07:49:25 -0500915 if ( adj_lsa->no_link > 0)
916 {
akmhoque9e9fc722012-09-26 14:03:25 -0500917 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
918 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
919 write_log_for_adj_lsa(new_adj_lsa);
920 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500921
akmhoque62c0c192012-09-24 07:49:25 -0500922 free(new_adj_lsa->header->orig_time);
923 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
924 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
925
926 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500927
akmhoque62c0c192012-09-24 07:49:25 -0500928 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
929 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
930 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500931
akmhoque62c0c192012-09-24 07:49:25 -0500932 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500933
934 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
935 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
936 write_log_for_adj_lsa(new_adj_lsa);
937 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500938 }
939 else
940 {
akmhoque9e9fc722012-09-26 14:03:25 -0500941 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
942 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
943 write_log_for_adj_lsa(new_adj_lsa);
944 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
945
akmhoque62c0c192012-09-24 07:49:25 -0500946 hashtb_delete(e);
947 }
akmhoque7b791452012-10-30 11:24:56 -0500948
949 if ( nlsr->debugging )
950 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
951 if ( nlsr->detailed_logging )
952 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
953
akmhoqueffacaa82012-09-13 17:48:30 -0500954 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500955
956 if ( nlsr->debugging )
957 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
958 if ( nlsr->detailed_logging )
959 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500960 }
961
962 }
963 hashtb_end(e);
964
965 if ( !nlsr->is_route_calculation_scheduled )
966 {
967 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
968 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -0500969 }
970
akmhoque03004e62012-09-06 01:12:28 -0500971
akmhoque569a93d2013-02-21 10:19:54 -0600972 //free(key);
akmhoqueffacaa82012-09-13 17:48:30 -0500973
974 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500975}
976
977void
akmhoque9e9fc722012-09-26 14:03:25 -0500978write_log_for_adj_lsa_body(const char *body, int no_link)
979{
980 int i=0;
981 char *lsa_data=(char *)malloc(strlen(body)+1);
982 memset( lsa_data,0,strlen(body)+1);
983 memcpy(lsa_data,body,strlen(body)+1);
984 char *sep="|";
985 char *rem;
986 char *rtr_id;
987 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -0600988 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -0500989 char *metric;
990
991 if(no_link >0 )
992 {
993 rtr_id=strtok_r(lsa_data,sep,&rem);
994 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -0600995 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -0500996 metric=strtok_r(NULL,sep,&rem);
997
998 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -0500999 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1000 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001001 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001002 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001003
1004
1005 for(i=1;i<no_link;i++)
1006 {
1007 rtr_id=strtok_r(NULL,sep,&rem);
1008 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001009 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001010 metric=strtok_r(NULL,sep,&rem);
1011 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001012 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1013 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001014 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001015 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001016
1017 }
1018 }
1019
1020 free(lsa_data);
1021}
1022
1023
1024void
1025write_log_for_adj_lsa(struct alsa * adj_lsa)
1026{
1027 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001028 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1029 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1030 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1031 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001032 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001033 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001034
1035 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1036
1037 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1038
1039}
1040
1041void
akmhoque53f64222012-09-05 13:57:51 -05001042print_adj_lsa_body(const char *body, int no_link)
1043{
1044 int i=0;
1045 char *lsa_data=(char *)malloc(strlen(body)+1);
1046 memset( lsa_data,0,strlen(body)+1);
1047 memcpy(lsa_data,body,strlen(body)+1);
1048 char *sep="|";
1049 char *rem;
1050 char *rtr_id;
1051 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001052 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001053 char *metric;
1054
akmhoque53f64222012-09-05 13:57:51 -05001055 if(no_link >0 )
1056 {
1057 rtr_id=strtok_r(lsa_data,sep,&rem);
1058 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001059 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001060 metric=strtok_r(NULL,sep,&rem);
1061
akmhoqueb77b95f2013-02-08 12:28:47 -06001062 if ( nlsr->debugging ) {
1063 printf(" Link %d \n",i+1);
1064 printf(" Neighbor : %s \n",rtr_id);
1065 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001066 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001067 printf(" Metric : %s \n",metric);
1068 }
akmhoque53f64222012-09-05 13:57:51 -05001069
1070 for(i=1;i<no_link;i++)
1071 {
1072 rtr_id=strtok_r(NULL,sep,&rem);
1073 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001074 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001075 metric=strtok_r(NULL,sep,&rem);
1076 printf(" Link %d \n",i+1);
1077 printf(" Neighbor : %s \n",rtr_id);
1078 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001079 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001080 printf(" Metric : %s \n",metric);
1081
1082 }
1083 }
1084
1085 free(lsa_data);
1086}
1087
1088void
1089print_adj_lsa(struct alsa * adj_lsa)
1090{
akmhoque7b791452012-10-30 11:24:56 -05001091 if ( nlsr->debugging )
1092 {
1093 printf("-----------ADJ LSA Content---------------\n");
1094 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1095 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1096 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1097 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1098 printf(" Lsa Data:\n");
1099 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001100
akmhoque7b791452012-10-30 11:24:56 -05001101 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1102 printf("\n");
1103 }
akmhoque53f64222012-09-05 13:57:51 -05001104
1105}
1106
1107void
1108print_adj_lsdb(void)
1109{
akmhoque7b791452012-10-30 11:24:56 -05001110 if ( nlsr->debugging )
1111 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001112 int i, adj_lsdb_element;
1113 struct alsa *adj_lsa;
1114
1115 struct hashtb_enumerator ee;
1116 struct hashtb_enumerator *e = &ee;
1117
1118 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1119 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1120
1121 for(i=0;i<adj_lsdb_element;i++)
1122 {
akmhoque7b791452012-10-30 11:24:56 -05001123 if ( nlsr->debugging )
1124 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001125 adj_lsa=e->data;
1126 print_adj_lsa(adj_lsa);
1127 hashtb_next(e);
1128 }
1129
1130 hashtb_end(e);
1131
akmhoque3171d652012-11-13 11:44:33 -06001132 if ( nlsr->debugging )
1133 printf("\n");
1134 if ( nlsr->detailed_logging )
1135 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001136}
1137
1138void
akmhoque03004e62012-09-06 01:12:28 -05001139build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data)
akmhoque53f64222012-09-05 13:57:51 -05001140{
akmhoque7b791452012-10-30 11:24:56 -05001141 if ( nlsr->debugging )
1142 printf("build_and_install_others_adj_lsa called \n");
1143 if ( nlsr->detailed_logging )
1144 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001145 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1146 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001147 install_adj_lsa(adj_lsa);
1148
akmhoque53f64222012-09-05 13:57:51 -05001149
akmhoque03004e62012-09-06 01:12:28 -05001150 free(adj_lsa->header->orig_router->name);
1151 free(adj_lsa->header->orig_router);
1152 free(adj_lsa->header->orig_time);
1153 free(adj_lsa->header);
1154 free(adj_lsa->body);
1155 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001156
akmhoque03004e62012-09-06 01:12:28 -05001157 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001158
akmhoque53f64222012-09-05 13:57:51 -05001159}
1160
akmhoque03004e62012-09-06 01:12:28 -05001161
akmhoque53f64222012-09-05 13:57:51 -05001162void
akmhoque03004e62012-09-06 01:12:28 -05001163build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data)
akmhoque53f64222012-09-05 13:57:51 -05001164{
akmhoque7b791452012-10-30 11:24:56 -05001165 if ( nlsr->debugging )
1166 printf("build_others_adj_lsa called \n");
1167 if ( nlsr->detailed_logging )
1168 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001169
akmhoque03004e62012-09-06 01:12:28 -05001170 /*Filling Up Header Data */
1171 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
1172 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1173 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
1174 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
1175 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001176
akmhoque03004e62012-09-06 01:12:28 -05001177 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001178
akmhoque53f64222012-09-05 13:57:51 -05001179
akmhoque03004e62012-09-06 01:12:28 -05001180 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001181
akmhoque03004e62012-09-06 01:12:28 -05001182 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
1183 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
1184 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001185
akmhoque03004e62012-09-06 01:12:28 -05001186 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001187
akmhoque03004e62012-09-06 01:12:28 -05001188 adj_lsa->body=(char *)malloc(strlen(data)+1);
1189 memset(adj_lsa->body,0,strlen(data)+1);
1190 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001191
akmhoque53f64222012-09-05 13:57:51 -05001192}
1193
akmhoque03004e62012-09-06 01:12:28 -05001194
akmhoque53f64222012-09-05 13:57:51 -05001195long int
1196get_name_lsdb_num_element(void)
1197{
1198 long int num_element;
1199
1200
1201 struct hashtb_enumerator ee;
1202 struct hashtb_enumerator *e = &ee;
1203
1204 hashtb_start(nlsr->lsdb->name_lsdb, e);
1205 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1206 hashtb_end(e);
1207
1208 return num_element;
1209}
1210
1211long int
1212get_adj_lsdb_num_element(void)
1213{
1214 long int num_element;
1215
1216
1217 struct hashtb_enumerator ee;
1218 struct hashtb_enumerator *e = &ee;
1219
1220 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1221 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1222 hashtb_end(e);
1223
1224 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001225}
akmhoque03004e62012-09-06 01:12:28 -05001226
akmhoque03004e62012-09-06 01:12:28 -05001227
1228int
1229check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1230{
1231 int ret=0;
1232 struct ccn_charbuf *key=ccn_charbuf_create();
1233 ccn_charbuf_append_string(key,orig_router);
1234 ccn_charbuf_append_string(key,"/");
1235 ccn_charbuf_append_string(key,lst);
1236 ccn_charbuf_append_string(key,"/");
1237 ccn_charbuf_append_string(key,lsid);
1238
1239 int res;
1240 struct nlsa *name_lsa;
1241
1242 struct hashtb_enumerator ee;
1243 struct hashtb_enumerator *e = &ee;
1244
1245 hashtb_start(nlsr->lsdb->name_lsdb, e);
1246 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1247
1248 if( res == HT_NEW_ENTRY )
1249 {
1250 hashtb_delete(e);
1251 ret=1;
1252
1253 }
1254 else if(res == HT_OLD_ENTRY)
1255 {
1256 name_lsa=e->data;
1257 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1258 {
1259 ret=1;
1260 }
1261 }
1262
1263 hashtb_end(e);
1264
1265 ccn_charbuf_destroy(&key);
1266
1267 return ret;
1268}
1269
1270int
1271check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1272{
1273 int ret=0;
1274 struct ccn_charbuf *key=ccn_charbuf_create();
1275 ccn_charbuf_append_string(key,orig_router);
1276 ccn_charbuf_append_string(key,"/");
1277 ccn_charbuf_append_string(key,lst);
1278
1279 int res;
1280 struct alsa *adj_lsa;
1281
1282 struct hashtb_enumerator ee;
1283 struct hashtb_enumerator *e = &ee;
1284
1285 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1286 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1287
1288 if( res == HT_NEW_ENTRY )
1289 {
1290 hashtb_delete(e);
1291 ret=1;
1292
1293 }
1294 else if(res == HT_OLD_ENTRY)
1295 {
1296 adj_lsa=e->data;
1297 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1298 {
1299 ret=1;
1300 }
1301 }
1302
1303 hashtb_end(e);
1304
1305 ccn_charbuf_destroy(&key);
1306
1307 return ret;
1308}
1309
akmhoqueb77b95f2013-02-08 12:28:47 -06001310int
1311check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1312{
1313 int ret=0;
1314 struct ccn_charbuf *key=ccn_charbuf_create();
1315 ccn_charbuf_append_string(key,orig_router);
1316 ccn_charbuf_append_string(key,"/");
1317 ccn_charbuf_append_string(key,lst);
1318
1319 int res;
1320 struct clsa *cor_lsa;
1321
1322 struct hashtb_enumerator ee;
1323 struct hashtb_enumerator *e = &ee;
1324
1325 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1326 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1327
1328 if( res == HT_NEW_ENTRY )
1329 {
1330 hashtb_delete(e);
1331 ret=1;
1332
1333 }
1334 else if(res == HT_OLD_ENTRY)
1335 {
1336 cor_lsa=e->data;
1337 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1338 {
1339 ret=1;
1340 }
1341 }
1342
1343 hashtb_end(e);
1344
1345 ccn_charbuf_destroy(&key);
1346
1347 return ret;
1348}
1349
akmhoque03004e62012-09-06 01:12:28 -05001350void
1351get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1352{
akmhoque7b791452012-10-30 11:24:56 -05001353 if ( nlsr->debugging )
1354 printf("get_name_lsa_data called \n");
1355 if ( nlsr->detailed_logging )
1356 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001357
akmhoque8876e982013-02-21 13:35:46 -06001358 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001359
1360 struct hashtb_enumerator ee;
1361 struct hashtb_enumerator *e = &ee;
1362 int res;
1363
1364 hashtb_start(nlsr->lsdb->name_lsdb, e);
1365 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1366
1367 if( res == HT_OLD_ENTRY )
1368 {
1369 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001370
akmhoque7b791452012-10-30 11:24:56 -05001371 if ( nlsr->debugging )
1372 printf("NAME LSA found \n");
1373 if ( nlsr->detailed_logging )
1374 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001375
1376 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1377 ccn_charbuf_append_string(lsa_data,"|");
1378
1379 char *temp_length=(char *)malloc(20);
1380 memset(temp_length,0,20);
1381 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1382 ccn_charbuf_append_string(lsa_data,temp_length);
1383 free(temp_length);
1384 ccn_charbuf_append_string(lsa_data,"|");
1385
1386 char *temp_ltype=(char *)malloc(20);
1387 memset(temp_ltype,0,20);
1388 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1389 ccn_charbuf_append_string(lsa_data,temp_ltype);
1390 free(temp_ltype);
1391 ccn_charbuf_append_string(lsa_data,"|");
1392
1393 char *temp_lsid=(char *)malloc(20);
1394 memset(temp_lsid,0,20);
1395 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1396 ccn_charbuf_append_string(lsa_data,temp_lsid);
1397 free(temp_lsid);
1398 ccn_charbuf_append_string(lsa_data,"|");
1399
1400 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1401 ccn_charbuf_append_string(lsa_data,"|");
1402
1403 char *temp_valid=(char *)malloc(20);
1404 memset(temp_valid,0,20);
1405 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1406 ccn_charbuf_append_string(lsa_data,temp_valid);
1407 free(temp_valid);
1408 ccn_charbuf_append_string(lsa_data,"|");
1409
1410 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1411 ccn_charbuf_append_string(lsa_data,"|");
1412
1413 char *temp_npl=(char *)malloc(20);
1414 memset(temp_npl,0,20);
1415 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1416 ccn_charbuf_append_string(lsa_data,temp_npl);
1417 free(temp_npl);
1418 ccn_charbuf_append_string(lsa_data,"|");
1419
1420 }
1421 else if(res == HT_NEW_ENTRY)
1422 {
1423 hashtb_delete(e);
1424 }
1425
1426 hashtb_end(e);
1427}
1428
1429void
1430get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1431{
akmhoque7b791452012-10-30 11:24:56 -05001432 if ( nlsr->debugging )
1433 printf("get_adj_lsa_data called \n");
1434 if ( nlsr->detailed_logging )
1435 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001436
1437 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
1438
1439 struct hashtb_enumerator ee;
1440 struct hashtb_enumerator *e = &ee;
1441 int res;
1442
1443 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1444 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1445
1446 if( res == HT_OLD_ENTRY )
1447 {
1448 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001449
1450 if ( nlsr->debugging )
1451 printf("Adj LSA found \n");
1452 if ( nlsr->detailed_logging )
1453 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001454
1455 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1456 ccn_charbuf_append_string(lsa_data,"|");
1457
1458 char *temp_length=(char *)malloc(20);
1459 memset(temp_length,0,20);
1460 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1461 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001462 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001463 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001464
1465 char *temp_ltype=(char *)malloc(20);
1466 memset(temp_ltype,0,20);
1467 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1468 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001469 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001470 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001471
1472 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1473 ccn_charbuf_append_string(lsa_data,"|");
1474
1475 char *temp_nl=(char *)malloc(20);
1476 memset(temp_nl,0,20);
1477 sprintf(temp_nl,"%d",adj_lsa->no_link);
1478 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001479 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001480 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001481
1482 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1483
1484
1485 }
1486 else if(res == HT_NEW_ENTRY)
1487 {
1488 hashtb_delete(e);
1489 }
1490
1491 hashtb_end(e);
1492}
akmhoqueffacaa82012-09-13 17:48:30 -05001493
akmhoque3171d652012-11-13 11:44:33 -06001494void
1495make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1496{
1497
1498 if ( nlsr->debugging )
1499 printf("make_name_lsa_invalid called \n");
1500 if ( nlsr->detailed_logging )
1501 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1502
1503
1504 char lst[2];
1505 memset(lst,0,2);
1506 sprintf(lst,"%d",ls_type);
1507
1508 char lsid[10];
1509 memset(lsid,0,10);
1510 sprintf(lsid,"%ld",ls_id);
1511
1512
1513 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1514 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1515
1516
1517 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001518
1519 if ( nlsr->debugging )
1520 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001521
1522 struct nlsa *nlsa;
1523
1524 struct hashtb_enumerator ee;
1525 struct hashtb_enumerator *e = &ee;
1526
1527 int res;
1528
1529 hashtb_start(nlsr->lsdb->name_lsdb, e);
1530 res = hashtb_seek(e, key,strlen(key) , 0);
1531
1532 if( res == HT_OLD_ENTRY )
1533 {
1534 nlsa=e->data;
1535
1536 nlsa->header->isValid=0;
1537
1538 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1539 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1540 write_log_for_name_lsa(nlsa);
1541 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1542
1543 hashtb_delete(e);
1544 }
1545 else if( res == HT_NEW_ENTRY )
1546 {
1547 hashtb_delete(e);
1548 }
1549 hashtb_end(e);
1550
1551 if ( nlsr->debugging )
1552 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1553 if ( nlsr->detailed_logging )
1554 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1555
1556 set_new_lsdb_version();
1557
1558 if ( nlsr->debugging )
1559 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1560 if ( nlsr->detailed_logging )
1561 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1562
1563}
1564
akmhoque866c2222013-02-12 10:49:33 -06001565//int
1566//delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1567int
1568delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001569{
akmhoqueb77b95f2013-02-08 12:28:47 -06001570
akmhoque7b791452012-10-30 11:24:56 -05001571 if ( nlsr->debugging )
1572 printf("delete_name_lsa called \n");
1573 if ( nlsr->detailed_logging )
1574 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001575 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001576 if(flags == CCN_SCHEDULE_CANCEL)
1577 {
1578 return -1;
1579 }
1580
1581
1582
1583 nlsr_lock();
1584
akmhoque7b791452012-10-30 11:24:56 -05001585 if ( nlsr->debugging )
1586 printf("LSA Key: %s \n",(char *)ev->evdata);
1587 if ( nlsr->detailed_logging )
1588 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001589
1590 struct nlsa *nlsa;
1591
1592 struct hashtb_enumerator ee;
1593 struct hashtb_enumerator *e = &ee;
1594
1595 int res;
1596
1597 hashtb_start(nlsr->lsdb->name_lsdb, e);
1598 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1599
1600 if( res == HT_OLD_ENTRY )
1601 {
1602 nlsa=e->data;
akmhoque866c2222013-02-12 10:49:33 -06001603 */
1604 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
1605 /*
akmhoque9e9fc722012-09-26 14:03:25 -05001606 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1607 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1608 write_log_for_name_lsa(nlsa);
1609 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1610
akmhoqueda5b6832012-09-13 22:33:55 -05001611 hashtb_delete(e);
1612 }
akmhoque3cced642012-09-24 16:20:20 -05001613 else if( res == HT_NEW_ENTRY )
akmhoqueda5b6832012-09-13 22:33:55 -05001614 {
akmhoqueda5b6832012-09-13 22:33:55 -05001615 hashtb_delete(e);
1616 }
1617 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001618 */
akmhoqueda5b6832012-09-13 22:33:55 -05001619
akmhoque7b791452012-10-30 11:24:56 -05001620 if ( nlsr->debugging )
1621 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1622 if ( nlsr->detailed_logging )
1623 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1624
akmhoqueda5b6832012-09-13 22:33:55 -05001625 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001626
1627 if ( nlsr->debugging )
1628 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1629 if ( nlsr->detailed_logging )
1630 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001631
akmhoque866c2222013-02-12 10:49:33 -06001632 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001633
1634 return 0;
1635}
1636
akmhoque866c2222013-02-12 10:49:33 -06001637//int
1638//delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1639int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001640{
akmhoque866c2222013-02-12 10:49:33 -06001641
akmhoque7b791452012-10-30 11:24:56 -05001642 if ( nlsr->debugging )
1643 printf("delete_adj_lsa called \n");
1644 if ( nlsr->detailed_logging )
1645 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001646
1647 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001648 if(flags == CCN_SCHEDULE_CANCEL)
1649 {
1650 return -1;
1651 }
1652 nlsr_lock();
1653
akmhoque7b791452012-10-30 11:24:56 -05001654 if ( nlsr->debugging )
1655 printf("LSA Key: %s \n",(char *)ev->evdata);
1656 if ( nlsr->detailed_logging )
1657 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001658
akmhoque9e9fc722012-09-26 14:03:25 -05001659 struct alsa *alsa;
akmhoqueda5b6832012-09-13 22:33:55 -05001660 struct hashtb_enumerator ee;
1661 struct hashtb_enumerator *e = &ee;
1662 int res;
1663
1664 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1665 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1666
1667 if( res == HT_OLD_ENTRY )
1668 {
akmhoque9e9fc722012-09-26 14:03:25 -05001669 alsa=e->data;
1670 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1671 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1672 write_log_for_adj_lsa(alsa);
1673 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1674
akmhoqueda5b6832012-09-13 22:33:55 -05001675 hashtb_delete(e);
1676 }
1677 else if( res == HT_OLD_ENTRY )
1678 {
1679 hashtb_delete(e);
1680 }
1681 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001682 */
akmhoqueda5b6832012-09-13 22:33:55 -05001683
akmhoque7b791452012-10-30 11:24:56 -05001684 if ( nlsr->debugging )
1685 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1686 if ( nlsr->detailed_logging )
1687 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1688
akmhoqueda5b6832012-09-13 22:33:55 -05001689 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001690
1691 if ( nlsr->debugging )
1692 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1693 if ( nlsr->detailed_logging )
1694 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1695
akmhoqueda5b6832012-09-13 22:33:55 -05001696
1697 if ( !nlsr->is_route_calculation_scheduled)
1698 {
1699 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1700 nlsr->is_route_calculation_scheduled=1;
1701 }
1702
akmhoque866c2222013-02-12 10:49:33 -06001703 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001704
1705 return 0;
1706}
1707
akmhoqueffacaa82012-09-13 17:48:30 -05001708void
1709refresh_name_lsdb(void)
1710{
akmhoque7b791452012-10-30 11:24:56 -05001711 if ( nlsr->debugging )
1712 printf("refresh_name_lsdb called \n");
1713 if ( nlsr->detailed_logging )
1714 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001715
1716 char *time_stamp=(char *)malloc(20);
1717 memset(time_stamp,0,20);
1718 get_current_timestamp_micro(time_stamp);
1719
1720 long int lsa_life_time;
1721
1722 int i, name_lsdb_element;
1723 struct nlsa *name_lsa;
1724
1725 struct hashtb_enumerator ee;
1726 struct hashtb_enumerator *e = &ee;
1727
1728 hashtb_start(nlsr->lsdb->name_lsdb, e);
1729 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1730
1731 for(i=0;i<name_lsdb_element;i++)
1732 {
1733 name_lsa=e->data;
1734
1735 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001736 if ( nlsr->debugging )
1737 printf("LSA Life Time: %ld \n",lsa_life_time);
1738 if ( nlsr->detailed_logging )
1739 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001740
1741 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1742 {
1743 if ( lsa_life_time > nlsr->lsa_refresh_time )
1744 {
akmhoque14b3f342012-09-14 10:39:02 -05001745 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1746 {
akmhoque7b791452012-10-30 11:24:56 -05001747 if ( nlsr->debugging )
1748 printf("Own Name LSA need to be refrshed\n");
1749 if ( nlsr->detailed_logging )
1750 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001751
1752 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1753 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1754 write_log_for_name_lsa(name_lsa);
1755 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1756
1757
akmhoque14b3f342012-09-14 10:39:02 -05001758 char *current_time_stamp=(char *)malloc(20);
1759 memset(current_time_stamp,0,20);
1760 get_current_timestamp_micro(current_time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001761
akmhoque14b3f342012-09-14 10:39:02 -05001762 free(name_lsa->header->orig_time);
1763 name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1764 memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1765 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001766
1767 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1768 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1769 write_log_for_name_lsa(name_lsa);
1770 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001771
akmhoque14b3f342012-09-14 10:39:02 -05001772 free(current_time_stamp);
akmhoque866c2222013-02-12 10:49:33 -06001773
1774 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001775 }
1776 else
akmhoque866c2222013-02-12 10:49:33 -06001777 { /*
akmhoque14b3f342012-09-14 10:39:02 -05001778 char lst[2];
1779 memset(lst,0,2);
1780 sprintf(lst,"%d",name_lsa->header->ls_type);
1781
1782 char lsid[10];
1783 memset(lsid,0,10);
1784 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1785
akmhoque866c2222013-02-12 10:49:33 -06001786
akmhoque14b3f342012-09-14 10:39:02 -05001787 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1788 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1789
1790
1791 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque14b3f342012-09-14 10:39:02 -05001792
1793 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001794 */
1795 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1796 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1797 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1798 write_log_for_name_lsa(name_lsa);
1799 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1800 hashtb_delete(e);
1801 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001802 }
akmhoqueda5b6832012-09-13 22:33:55 -05001803
akmhoque7b791452012-10-30 11:24:56 -05001804 if ( nlsr->debugging )
1805 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1806 if ( nlsr->detailed_logging )
1807 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1808
akmhoqueda5b6832012-09-13 22:33:55 -05001809 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001810
1811 if ( nlsr->debugging )
1812 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1813 if ( nlsr->detailed_logging )
1814 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1815
1816
akmhoqueda5b6832012-09-13 22:33:55 -05001817
1818 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001819 }
1820 else
1821 {
1822 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001823 }
1824 }
1825 else
1826 {
1827 if ( lsa_life_time > nlsr->router_dead_interval )
1828 {
akmhoque7b791452012-10-30 11:24:56 -05001829 if ( nlsr->debugging )
1830 printf("Others Name LSA need to be deleted\n");
1831 if ( nlsr->detailed_logging )
1832 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001833
akmhoque866c2222013-02-12 10:49:33 -06001834 /*char lst[2];
akmhoqueda5b6832012-09-13 22:33:55 -05001835 memset(lst,0,2);
1836 sprintf(lst,"%d",name_lsa->header->ls_type);
1837
1838 char lsid[10];
1839 memset(lsid,0,10);
1840 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1841
1842
1843 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1844 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1845
1846
1847 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoqueda5b6832012-09-13 22:33:55 -05001848
1849 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001850 */
1851 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1852 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1853 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1854 write_log_for_name_lsa(name_lsa);
1855 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1856 hashtb_delete(e);
1857 i++;
1858 }
1859 else
1860 {
1861 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001862 }
1863 }
akmhoque866c2222013-02-12 10:49:33 -06001864 /*else
1865 {
1866 hashtb_next(e);
1867 }*/
akmhoqueffacaa82012-09-13 17:48:30 -05001868 }
1869
1870 hashtb_end(e);
1871
1872 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001873
akmhoqueffacaa82012-09-13 17:48:30 -05001874
1875}
1876
akmhoqueda5b6832012-09-13 22:33:55 -05001877void
akmhoqueffacaa82012-09-13 17:48:30 -05001878refresh_adj_lsdb(void)
1879{
akmhoqueffacaa82012-09-13 17:48:30 -05001880
akmhoque7b791452012-10-30 11:24:56 -05001881 if ( nlsr->debugging )
1882 printf("refresh_adj_lsdb called \n");
1883 if ( nlsr->detailed_logging )
1884 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001885
akmhoqueffacaa82012-09-13 17:48:30 -05001886 char *time_stamp=(char *)malloc(20);
1887 memset(time_stamp,0,20);
1888 get_current_timestamp_micro(time_stamp);
1889
1890 long int lsa_life_time;
1891
1892 int i, adj_lsdb_element;
1893 struct alsa *adj_lsa;
1894
1895 struct hashtb_enumerator ee;
1896 struct hashtb_enumerator *e = &ee;
1897
1898 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1899 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1900
1901 for(i=0;i<adj_lsdb_element;i++)
1902 {
1903 adj_lsa=e->data;
1904
akmhoqueb77b95f2013-02-08 12:28:47 -06001905 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001906
1907 if ( nlsr->debugging )
1908 printf("LSA Life Time: %ld \n",lsa_life_time);
1909 if ( nlsr->detailed_logging )
1910 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001911
akmhoqueda5b6832012-09-13 22:33:55 -05001912 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1913 {
1914 if ( lsa_life_time > nlsr->lsa_refresh_time )
1915 {
akmhoque7b791452012-10-30 11:24:56 -05001916 if ( nlsr->debugging )
1917 printf("Own Adj LSA need to be refrshed\n");
1918 if ( nlsr->detailed_logging )
1919 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001920
akmhoquea98c2142012-10-25 15:22:24 -05001921 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1922 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1923 write_log_for_adj_lsa(adj_lsa);
1924 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1925
akmhoqueda5b6832012-09-13 22:33:55 -05001926 char *current_time_stamp=(char *)malloc(20);
1927 memset(current_time_stamp,0,20);
1928 get_current_timestamp_micro(current_time_stamp);
1929
1930 free(adj_lsa->header->orig_time);
1931 adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1932 memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1933 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1934
1935 free(current_time_stamp);
1936
akmhoquea98c2142012-10-25 15:22:24 -05001937 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1938 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1939 write_log_for_adj_lsa(adj_lsa);
1940 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001941
akmhoque7b791452012-10-30 11:24:56 -05001942 if ( nlsr->debugging )
1943 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1944 if ( nlsr->detailed_logging )
1945 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1946
akmhoqueda5b6832012-09-13 22:33:55 -05001947 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001948
1949 if ( nlsr->debugging )
1950 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1951 if ( nlsr->detailed_logging )
1952 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001953
1954 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001955
1956
akmhoqueda5b6832012-09-13 22:33:55 -05001957 }
akmhoque866c2222013-02-12 10:49:33 -06001958
1959 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001960 }
1961 else
1962 {
1963 if ( lsa_life_time > nlsr->router_dead_interval )
1964 {
akmhoque7b791452012-10-30 11:24:56 -05001965
1966 if ( nlsr->debugging )
1967 printf("Others Adj LSA need to be deleted\n");
1968 if ( nlsr->detailed_logging )
1969 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06001970 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001971 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
1972 memset(key,0,adj_lsa->header->orig_router->length+2);
1973 make_adj_lsa_key(key,adj_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06001974
akmhoqueda5b6832012-09-13 22:33:55 -05001975 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001976 */
1977
1978 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1979 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1980 write_log_for_adj_lsa(adj_lsa);
1981 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1982 delete_adj_lsa();
1983 hashtb_delete(e);
1984 i++;
1985
1986 }
1987 else
1988 {
1989 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001990 }
1991 }
1992
1993
1994
akmhoque866c2222013-02-12 10:49:33 -06001995 //hashtb_next(e);
akmhoqueffacaa82012-09-13 17:48:30 -05001996 }
1997
1998 hashtb_end(e);
1999
2000 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002001}
2002
akmhoqueb77b95f2013-02-08 12:28:47 -06002003
2004void
2005refresh_cor_lsdb(void)
2006{
2007
2008 if ( nlsr->debugging )
2009 printf("refresh_cor_lsdb called \n");
2010 if ( nlsr->detailed_logging )
2011 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2012
2013 char *time_stamp=(char *)malloc(20);
2014 memset(time_stamp,0,20);
2015 get_current_timestamp_micro(time_stamp);
2016
2017 long int lsa_life_time;
2018
2019 int i, cor_lsdb_element;
2020 struct clsa *cor_lsa;
2021
2022 struct hashtb_enumerator ee;
2023 struct hashtb_enumerator *e = &ee;
2024
2025 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2026 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2027
2028 for(i=0;i<cor_lsdb_element;i++)
2029 {
2030 cor_lsa=e->data;
2031
2032 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2033
2034 if ( nlsr->debugging )
2035 printf("LSA Life Time: %ld \n",lsa_life_time);
2036 if ( nlsr->detailed_logging )
2037 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2038
2039 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2040 {
2041 if ( lsa_life_time > nlsr->lsa_refresh_time )
2042 {
2043 if ( nlsr->debugging )
2044 printf("Own Cor LSA need to be refrshed\n");
2045 if ( nlsr->detailed_logging )
2046 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2047
2048 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2049 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2050 //write_log_for_adj_lsa(adj_lsa);
2051 //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2052
2053 char *current_time_stamp=(char *)malloc(20);
2054 memset(current_time_stamp,0,20);
2055 get_current_timestamp_micro(current_time_stamp);
2056
2057 free(cor_lsa->header->orig_time);
2058 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2059 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2060 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2061
2062 free(current_time_stamp);
2063
2064 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2065 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
2066 //write_log_for_adj_lsa(adj_lsa);
2067 //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2068
2069 if ( nlsr->debugging )
2070 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2071 if ( nlsr->detailed_logging )
2072 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2073
2074 set_new_lsdb_version();
2075
2076 if ( nlsr->debugging )
2077 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2078 if ( nlsr->detailed_logging )
2079 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2080
2081 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002082 }
2083
2084 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002085 }
2086 else
2087 {
2088 if ( lsa_life_time > nlsr->router_dead_interval )
2089 {
2090
2091 if ( nlsr->debugging )
2092 printf("Others Adj LSA need to be deleted\n");
2093 if ( nlsr->detailed_logging )
2094 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
2095
2096 hashtb_delete(e);
2097 i++;
2098 }
akmhoque866c2222013-02-12 10:49:33 -06002099 else
2100 {
2101 hashtb_next(e);
2102 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002103 }
2104
2105
akmhoque866c2222013-02-12 10:49:33 -06002106
akmhoqueb77b95f2013-02-08 12:28:47 -06002107 }
2108
2109 hashtb_end(e);
2110
2111 free(time_stamp);
2112}
2113
akmhoqueffacaa82012-09-13 17:48:30 -05002114int
2115refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2116{
2117 if(flags == CCN_SCHEDULE_CANCEL)
2118 {
2119 return -1;
2120 }
2121
2122 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002123
akmhoque7b791452012-10-30 11:24:56 -05002124 if ( nlsr->debugging )
2125 printf("refresh_lsdb called\n");
2126 if ( nlsr->detailed_logging )
2127 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002128
2129 refresh_name_lsdb();
2130 refresh_adj_lsdb();
akmhoque8876e982013-02-21 13:35:46 -06002131 //refresh_cor_lsdb();
akmhoqueffacaa82012-09-13 17:48:30 -05002132
akmhoqueffacaa82012-09-13 17:48:30 -05002133 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002134
akmhoqueffacaa82012-09-13 17:48:30 -05002135 nlsr_unlock();
2136 return 0;
2137}
akmhoqueb77b95f2013-02-08 12:28:47 -06002138
2139void
2140write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2141{
2142 if ( nlsr->debugging )
2143 printf("write_adj_lsa_to_repo called\n");
2144 if ( nlsr->debugging )
2145 printf("Content Prefix: %s\n",repo_content_prefix);
2146
2147 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2148 get_adj_lsa_data(lsa_data,lsa_id);
2149 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002150 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002151
akmhoque0800eda2013-02-21 14:17:52 -06002152 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002153
akmhoque323b5e92013-02-21 13:55:15 -06002154
2155 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002156}
2157
2158void
2159write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2160{
2161 if ( nlsr->debugging )
2162 printf("write_name_lsa_to_repo called\n");
2163 if ( nlsr->debugging )
2164 printf("Content Prefix: %s\n",repo_content_prefix);
2165
2166 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2167 get_name_lsa_data(lsa_data,lsa_id);
2168
2169 if ( nlsr->debugging )
2170 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2171
akmhoque0800eda2013-02-21 14:17:52 -06002172
akmhoque323b5e92013-02-21 13:55:15 -06002173
akmhoque0800eda2013-02-21 14:17:52 -06002174 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002175
akmhoque4f85aab2013-02-21 13:58:50 -06002176 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002177}
2178
2179
2180void
2181write_name_lsdb_to_repo(char *slice_prefix)
2182{
2183 int i, name_lsdb_element;
2184
2185 struct nlsa *name_lsa;
2186 struct hashtb_enumerator ee;
2187 struct hashtb_enumerator *e = &ee;
2188
2189 hashtb_start(nlsr->lsdb->name_lsdb, e);
2190 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2191
2192 for(i=0;i<name_lsdb_element;i++)
2193 {
2194 name_lsa=e->data;
2195
2196 char lst[2];
2197 memset(lst,0,2);
2198 sprintf(lst,"%d",name_lsa->header->ls_type);
2199
2200 char lsid[10];
2201 memset(lsid,0,10);
2202 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2203
2204
2205 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2206 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2207
2208
2209 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2210
2211 if ( nlsr->debugging )
2212 printf("Name LSA Key: %s \n",key);
2213
2214
2215 char *repo_key=(char *)malloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15);
2216 memset(repo_key,0,strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15);
2217 make_name_lsa_prefix_for_repo(repo_key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id,name_lsa->header->orig_time,slice_prefix);
2218
2219 if ( nlsr->debugging )
2220 printf("Name LSA Repo Key: %s \n",repo_key);
2221
2222 struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
2223 lsaid->name=(char *)malloc(strlen(key)+1);
2224 memset(lsaid->name, 0, strlen(key)+1);
2225 memcpy(lsaid->name,key,strlen(key));
2226 lsaid->length=strlen(key)+1;
2227
2228
2229 write_name_lsa_to_repo(repo_key, lsaid);
2230
2231 free(key);
2232 free(repo_key);
2233 free(lsaid->name);
2234 free(lsaid);
2235
2236 hashtb_next(e);
2237 }
2238
2239 hashtb_end(e);
2240
2241
2242}
2243
2244void
2245print_cor_lsa(struct clsa *cor_lsa)
2246{
2247 if ( nlsr->debugging )
2248 {
2249 printf("-----------Cor LSA Content---------------\n");
2250 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2251 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2252 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2253 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2254 printf(" LSA Data \n");
2255 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2256 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2257
2258 printf("\n");
2259 }
2260}
2261
2262void
2263print_cor_lsdb()
2264{
2265
2266 if ( nlsr->debugging )
2267 printf("print_cor_lsdb called \n");
2268
2269 struct hashtb_enumerator ee;
2270 struct hashtb_enumerator *e = &ee;
2271
2272 int i=1;
2273
2274 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2275 {
2276 if ( nlsr->debugging )
2277 printf("-----------Cor LSA (%d)---------------\n",i);
2278 struct clsa *cor_lsa=e->data;
2279 print_cor_lsa(cor_lsa);
2280 i++;
2281 }
2282 hashtb_end(e);
2283
2284 if ( nlsr->debugging )
2285 printf("\n");
2286 if ( nlsr->detailed_logging )
2287 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2288}
2289
2290void
2291install_cor_lsa(struct clsa *cor_lsa)
2292{
2293 if ( nlsr->debugging )
2294 printf("install_cor_lsa called \n");
2295 if ( nlsr->detailed_logging )
2296 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2297
2298
2299 char *time_stamp=(char *)malloc(20);
2300 memset(time_stamp,0,20);
2301 get_current_timestamp_micro(time_stamp);
2302
2303
akmhoque569a93d2013-02-21 10:19:54 -06002304 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2305 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002306 make_cor_lsa_key(key,cor_lsa);
2307
2308 if ( nlsr->debugging )
2309 printf("Cor LSA key: %s \n",key);
2310
2311 struct hashtb_enumerator ee;
2312 struct hashtb_enumerator *e = &ee;
2313 int res;
2314
2315 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2316 res = hashtb_seek(e, key, strlen(key), 0);
2317
2318 if ( res == HT_NEW_ENTRY )
2319 {
2320 if ( nlsr->debugging )
2321 printf("New Cor LSA... \n");
2322
akmhoque8876e982013-02-21 13:35:46 -06002323 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002324 new_cor_lsa=e->data;
2325 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2326
2327 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2328 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
2329 memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
2330 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2331 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2332
2333 new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free
2334 memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
2335 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2336
2337 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2338
2339 new_cor_lsa->cor_r=cor_lsa->cor_r;
2340 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2341 }
2342 else if ( res == HT_OLD_ENTRY )
2343 {
2344 if ( nlsr->debugging )
2345 printf("Cor LSA exists (Old)... \n");
2346 }
2347 hashtb_end(e);
2348
akmhoque569a93d2013-02-21 10:19:54 -06002349 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002350
2351}
2352
2353void
2354build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2355{
2356 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2357 cor_lsa->header->ls_type=LS_TYPE_COR;
2358
2359 char *time_stamp=(char *)malloc(20);
2360 memset(time_stamp,0,20);
2361 get_current_timestamp_micro(time_stamp);
2362
2363 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2364 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2365 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2366 free(time_stamp);
2367
2368 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2369 cor_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
2370 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2371 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2372 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2373
2374 cor_lsa->cor_r=cor_r;
2375 cor_lsa->cor_theta=cor_theta;
2376
2377}
2378
2379void
2380build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2381{
2382 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2383 cor_lsa->header->ls_type=ls_type;
2384
2385 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2386 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002387 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002388
2389 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2390 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2391 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002392 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002393 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2394
2395 cor_lsa->cor_r=cor_r;
2396 cor_lsa->cor_theta=cor_theta;
2397
2398}
2399
2400void
2401build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2402{
2403 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2404 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2405 install_cor_lsa(cor_lsa);
2406
2407 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002408
2409 free(cor_lsa->header->orig_router->name);
akmhoqueb77b95f2013-02-08 12:28:47 -06002410 free(cor_lsa->header->orig_router);
2411 free(cor_lsa->header->orig_time);
2412 free(cor_lsa->header);
2413 free(cor_lsa);
2414
2415}
2416
2417
2418void
2419build_and_install_cor_lsa()
2420{
2421
2422
2423
2424 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2425
2426 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2427 install_cor_lsa(cor_lsa);
2428
2429 write_cor_lsa_to_repo(cor_lsa);
2430
2431 print_cor_lsdb();
2432
2433 free(cor_lsa->header->orig_router);
2434 free(cor_lsa->header->orig_time);
2435 free(cor_lsa->header);
2436 free(cor_lsa);
2437
2438}
2439
2440void
2441get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2442{
2443 if ( nlsr->debugging )
2444 printf("get_cor_lsa_data called \n");
2445 if ( nlsr->detailed_logging )
2446 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2447
2448 struct clsa *cor_lsa=(struct clsa*)malloc(sizeof(struct clsa ));
2449
2450 struct hashtb_enumerator ee;
2451 struct hashtb_enumerator *e = &ee;
2452 int res;
2453
2454 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2455 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2456
2457 if( res == HT_OLD_ENTRY )
2458 {
2459 cor_lsa=e->data;
2460
2461 if ( nlsr->debugging )
2462 printf("Cor LSA found \n");
2463 if ( nlsr->detailed_logging )
2464 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2465
2466 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2467 ccn_charbuf_append_string(lsa_data,"|");
2468
2469 char *temp_length=(char *)malloc(20);
2470 memset(temp_length,0,20);
2471 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2472 ccn_charbuf_append_string(lsa_data,temp_length);
2473 ccn_charbuf_append_string(lsa_data,"|");
2474 free(temp_length);
2475
2476 char *temp_ltype=(char *)malloc(20);
2477 memset(temp_ltype,0,20);
2478 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2479 ccn_charbuf_append_string(lsa_data,temp_ltype);
2480 ccn_charbuf_append_string(lsa_data,"|");
2481 free(temp_ltype);
2482
2483 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2484 ccn_charbuf_append_string(lsa_data,"|");
2485
2486 char *cor_r=(char *)malloc(20);
2487 memset(cor_r,0,20);
2488 sprintf(cor_r,"%f",cor_lsa->cor_r);
2489 ccn_charbuf_append_string(lsa_data,cor_r);
2490 ccn_charbuf_append_string(lsa_data,"|");
2491 free(cor_r);
2492
2493 char *cor_theta=(char *)malloc(20);
2494 memset(cor_theta,0,20);
2495 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2496 ccn_charbuf_append_string(lsa_data,cor_theta);
2497 ccn_charbuf_append_string(lsa_data,"|");
2498 free(cor_theta);
2499
2500 }
2501 else if(res == HT_NEW_ENTRY)
2502 {
2503 hashtb_delete(e);
2504 }
2505
2506 hashtb_end(e);
2507}
2508
2509void
2510write_cor_lsa_to_repo(struct clsa *cor_lsa)
2511{
2512
2513
2514 if ( nlsr->debugging )
2515 printf("write_cor_lsa_to_repo called\n");
2516
2517
2518 char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2);
2519 memset(key,0,cor_lsa->header->orig_router->length+2+2);
2520 make_cor_lsa_key(key,cor_lsa);
2521
2522 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2523 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002524
akmhoqueb77b95f2013-02-08 12:28:47 -06002525 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002526 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2527
akmhoqueb77b95f2013-02-08 12:28:47 -06002528 char *lst=(char *)malloc(20);
2529 memset(lst,0,20);
2530 sprintf(lst,"%d",cor_lsa->header->ls_type);
2531 char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15);
2532 memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15);
2533 make_cor_lsa_prefix_for_repo(repo_key, cor_lsa->header->orig_router->name,LS_TYPE_COR,cor_lsa->header->orig_time,nlsr->slice_prefix);
2534
2535 if ( nlsr->debugging )
2536 printf("Cor LSA Repo Key: %s \n",repo_key);
2537
akmhoque0800eda2013-02-21 14:17:52 -06002538 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
2539
akmhoqueb77b95f2013-02-08 12:28:47 -06002540
2541
2542
2543 free(lst);
2544 free(key);
2545 free(repo_key);
akmhoque4f85aab2013-02-21 13:58:50 -06002546 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002547}
2548
2549void
2550make_cor_lsa_key_by_router_name(char *key,char *router_name)
2551{
2552 memcpy(key+strlen(key),router_name,strlen(router_name));
2553 memcpy(key+strlen(key),"/",1);
2554 char ls_type[2];
2555 sprintf(ls_type,"%d",LS_TYPE_COR);
2556 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2557 key[strlen(key)]='\0';
2558}
2559
2560
2561double
2562get_hyperbolic_r(char *router)
2563{
2564 double ret=-1.0;
2565 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2566 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2567
2568
2569 struct clsa *cor_lsa;
2570 struct hashtb_enumerator ee;
2571 struct hashtb_enumerator *e = &ee;
2572 int res;
2573
2574 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2575 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2576
2577 if ( res == HT_OLD_ENTRY)
2578 {
2579 cor_lsa=e->data;
2580 ret=cor_lsa->cor_r;
2581 }
2582 else if(res == HT_NEW_ENTRY)
2583 {
2584 hashtb_delete(e);
2585 }
2586
2587 hashtb_end(e);
2588
2589 free(cor_lsa_key);
2590 return ret;
2591}
2592
2593double
2594get_hyperbolic_theta(char *router)
2595{
2596 double ret=-1.0;
2597 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2598 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2599
2600 struct clsa *cor_lsa;
2601 struct hashtb_enumerator ee;
2602 struct hashtb_enumerator *e = &ee;
2603 int res;
2604
2605 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2606 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2607
2608 if ( res == HT_OLD_ENTRY)
2609 {
2610 cor_lsa=e->data;
2611 ret=cor_lsa->cor_theta;
2612 }
2613 else if(res == HT_NEW_ENTRY)
2614 {
2615 hashtb_delete(e);
2616 }
2617
2618 hashtb_end(e);
2619
2620 free(cor_lsa_key);
2621 return ret;
2622}