blob: 8e4fe16e3c1cb87cc436aba8bf5aaaca7fa61dd9 [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
akmhoque54a14f42013-02-24 06:16:20 -060038 //char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -050039 free(nlsr->lsdb->lsdb_version);
akmhoque54a14f42013-02-24 06:16:20 -060040 nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
41 //nlsr->lsdb->lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
42 //memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
43 //free(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040044}
45
akmhoque0ab71642013-02-21 10:10:33 -060046/**
47* Make key for storing Name LSA in Name LSDB
48*/
49
akmhoque03004e62012-09-06 01:12:28 -050050void
51make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
52{
53
akmhoque03004e62012-09-06 01:12:28 -050054 char lst[2];
55 memset(lst,0,2);
56 sprintf(lst,"%d",ls_type);
57
58 char lsid[10];
59 memset(lsid,0,10);
60 sprintf(lsid,"%ld",ls_id);
61
akmhoqueeacf44f2013-02-22 01:02:13 -060062 memcpy(key,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -050063 memcpy(key+strlen(key),"/",1);
64 memcpy(key+strlen(key),lst,strlen(lst));
65 memcpy(key+strlen(key),"/",1);
66 memcpy(key+strlen(key),lsid,strlen(lsid));
akmhoqueeacf44f2013-02-22 01:02:13 -060067 key[strlen(key)]='\0';
68
akmhoqueb77b95f2013-02-08 12:28:47 -060069 if ( nlsr->debugging )
70 printf("name LSA Key: %s\n", key);
71}
72
akmhoque0ed6d982013-02-22 14:28:01 -060073
akmhoque0ab71642013-02-21 10:10:33 -060074/**
75* Make content name prefix for Name LSA to store in repo
76*/
akmhoqueb77b95f2013-02-08 12:28:47 -060077
78void
akmhoque0ab71642013-02-21 10:10:33 -060079make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
80 long int ls_id,char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060081{
akmhoque0ab71642013-02-21 10:10:33 -060082 sprintf(key,"%s%s/lsType.%d/lsId.%ld/%s",slice_prefix, orig_router, ls_type,
83 ls_id, orig_time);
akmhoqueeacf44f2013-02-22 01:02:13 -060084 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -060085 if ( nlsr->debugging )
86 printf("Name LSA prefix for repo content: %s\n",key);
87}
88
akmhoque0ab71642013-02-21 10:10:33 -060089/**
90* Make content name prefix for Adj LSA to store in repo
91*/
92
akmhoqueb77b95f2013-02-08 12:28:47 -060093void
akmhoque0ab71642013-02-21 10:10:33 -060094make_adj_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
95 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060096{
97
98 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
akmhoqueeacf44f2013-02-22 01:02:13 -060099 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -0600100 if ( nlsr->debugging )
101 printf("Name LSA prefix for repo content:%s\n",key);
102}
103
akmhoque0ab71642013-02-21 10:10:33 -0600104/**
105* Make content name prefix for Cor LSA to store in repo
106*/
107
akmhoqueb77b95f2013-02-08 12:28:47 -0600108void
akmhoque0ab71642013-02-21 10:10:33 -0600109make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
110 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -0600111{
112
113 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
akmhoqueeacf44f2013-02-22 01:02:13 -0600114 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -0600115 if ( nlsr->debugging )
116 printf("Cor LSA prefix for repo content:%s\n",key);
akmhoque03004e62012-09-06 01:12:28 -0500117}
akmhoque53f64222012-09-05 13:57:51 -0500118
akmhoque0ab71642013-02-21 10:10:33 -0600119/**
120* Build name lsa for all name prefixes in Name Prefix List (NPL). Intsall Name
121* LSA in Name LSDB for router itself.
122*/
123
akmhoqueeacf44f2013-02-22 01:02:13 -0600124void
akmhoquef5537b42013-02-22 08:33:32 -0600125destroy_name_lsa_component(struct nlsa * name_lsa)
akmhoqueeacf44f2013-02-22 01:02:13 -0600126{
127 if ( name_lsa->header->orig_router->name )
128 free(name_lsa->header->orig_router->name);
129 if ( name_lsa->header->orig_router )
130 free(name_lsa->header->orig_router);
akmhoquef5537b42013-02-22 08:33:32 -0600131 if ( name_lsa->header->orig_time )
132 free(name_lsa->header->orig_time);
akmhoqueeacf44f2013-02-22 01:02:13 -0600133 if ( name_lsa->header )
134 free(name_lsa->header);
akmhoquef5537b42013-02-22 08:33:32 -0600135
akmhoqueeacf44f2013-02-22 01:02:13 -0600136 if ( name_lsa->name_prefix->name )
137 free(name_lsa->name_prefix->name);
138 if ( name_lsa->name_prefix )
139 free(name_lsa->name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -0600140}
141
142void
143destroy_name_lsa(struct nlsa * name_lsa)
144{
145 destroy_name_lsa_component(name_lsa);
akmhoqueeacf44f2013-02-22 01:02:13 -0600146 if ( name_lsa )
147 free(name_lsa);
148}
akmhoque0ab71642013-02-21 10:10:33 -0600149
akmhoquef5537b42013-02-22 08:33:32 -0600150void
151destroy_adj_lsa_component(struct alsa * adj_lsa)
152{
153 if ( adj_lsa->header->orig_router->name )
154 free(adj_lsa->header->orig_router->name);
155 if ( adj_lsa->header->orig_router )
156 free(adj_lsa->header->orig_router);
157 if ( adj_lsa->header->orig_time )
158 free(adj_lsa->header->orig_time);
159 if ( adj_lsa->header )
160 free(adj_lsa->header);
161
162 if ( adj_lsa->body )
163 free(adj_lsa->body);
164}
165
166void
167destroy_adj_lsa(struct alsa * adj_lsa)
168{
169
170 destroy_adj_lsa_component(adj_lsa);
171 if ( adj_lsa )
172 free(adj_lsa);
173}
174
175void
176destroy_cor_lsa_component(struct clsa * cor_lsa)
177{
178 if ( cor_lsa->header->orig_router->name )
179 free(cor_lsa->header->orig_router->name);
180 if ( cor_lsa->header->orig_router )
181 free(cor_lsa->header->orig_router);
182 if ( cor_lsa->header->orig_time )
183 free(cor_lsa->header->orig_time);
184 if ( cor_lsa->header )
185 free(cor_lsa->header);
186}
187
188void
189destroy_cor_lsa(struct clsa * cor_lsa)
190{
191
192 destroy_cor_lsa_component(cor_lsa);
193 if ( cor_lsa )
194 free(cor_lsa);
195}
196
197
198
akmhoquef71d9082012-08-22 12:51:53 -0400199void
akmhoque53f64222012-09-05 13:57:51 -0500200build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -0400201{
akmhoque7b791452012-10-30 11:24:56 -0500202 if ( nlsr->debugging )
203 printf("build_and_install_name_lsas called \n");
204 if ( nlsr->detailed_logging )
205 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n");
akmhoquef71d9082012-08-22 12:51:53 -0400206
akmhoquef71d9082012-08-22 12:51:53 -0400207 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600208 struct name_prefix_list_entry *npe;
akmhoquef71d9082012-08-22 12:51:53 -0400209
210 struct hashtb_enumerator ee;
211 struct hashtb_enumerator *e = &ee;
212
213 hashtb_start(nlsr->npl, e);
214 npl_element=hashtb_n(nlsr->npl);
215
216 for(i=0;i<npl_element;i++)
217 {
akmhoque3171d652012-11-13 11:44:33 -0600218 npe=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500219 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
akmhoque3171d652012-11-13 11:44:33 -0600220 build_name_lsa(name_lsa,npe->np);
akmhoque03004e62012-09-06 01:12:28 -0500221
akmhoquef71d9082012-08-22 12:51:53 -0400222 install_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600223 update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600224 destroy_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400225 hashtb_next(e);
226 }
227
akmhoque53f64222012-09-05 13:57:51 -0500228 hashtb_end(e);
akmhoque3171d652012-11-13 11:44:33 -0600229
230 print_name_prefix_from_npl();
231
232}
233
akmhoque0ab71642013-02-21 10:10:33 -0600234/**
235* Build and Install one Name LSA Use ful for API
236*/
237
akmhoque3171d652012-11-13 11:44:33 -0600238void
239build_and_install_single_name_lsa(struct name_prefix *np)
240{
241 if ( nlsr->debugging )
242 printf("build_and_install_single_name_lsa called \n");
243 if ( nlsr->detailed_logging )
244 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name_lsa called\n");
245
246 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
247 build_name_lsa(name_lsa,np);
248
249 install_name_lsa(name_lsa);
250 update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600251 destroy_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600252 print_name_prefix_from_npl();
akmhoquef71d9082012-08-22 12:51:53 -0400253
akmhoquef71d9082012-08-22 12:51:53 -0400254}
255
akmhoque53f64222012-09-05 13:57:51 -0500256void
257build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
258{
akmhoque53f64222012-09-05 13:57:51 -0500259 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
260 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoqueeacf44f2013-02-22 01:02:13 -0600261
262 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500263 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500264 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
265 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500266
267 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500268
269 name_lsa->header->ls_id=++nlsr->nlsa_id;
akmhoqueeacf44f2013-02-22 01:02:13 -0600270 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
271 name_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -0500272 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
273 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500274 name_lsa->header->isValid=1;
275
276
277 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueeacf44f2013-02-22 01:02:13 -0600278 name_lsa->name_prefix->name=(char *)calloc(np->length,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -0500279 memcpy(name_lsa->name_prefix->name,np->name,np->length);
280 name_lsa->name_prefix->length=np->length;
281
282}
283
akmhoque53f64222012-09-05 13:57:51 -0500284void
285install_name_lsa(struct nlsa *name_lsa)
286{
akmhoque53f64222012-09-05 13:57:51 -0500287
akmhoque0ab71642013-02-21 10:10:33 -0600288 char lst[2];
289 memset(lst,0,2);
290 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoqueffacaa82012-09-13 17:48:30 -0500291
akmhoque0ab71642013-02-21 10:10:33 -0600292 char lsid[10];
293 memset(lsid,0,10);
294 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque3171d652012-11-13 11:44:33 -0600295
akmhoque0ab71642013-02-21 10:10:33 -0600296 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
297 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
298 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 -0500299
akmhoque0ab71642013-02-21 10:10:33 -0600300 if ( nlsr->debugging )
301 printf("Key:%s Length:%d\n",key,(int)strlen(key));
302 if ( nlsr->detailed_logging )
303 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key));
304
akmhoquef5537b42013-02-22 08:33:32 -0600305 struct nlsa *new_name_lsa;
akmhoque53f64222012-09-05 13:57:51 -0500306
akmhoque0ab71642013-02-21 10:10:33 -0600307 struct hashtb_enumerator ee;
308 struct hashtb_enumerator *e = &ee;
309 int res;
akmhoque53f64222012-09-05 13:57:51 -0500310
akmhoque0ab71642013-02-21 10:10:33 -0600311 hashtb_start(nlsr->lsdb->name_lsdb, e);
312 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500313
akmhoque0ab71642013-02-21 10:10:33 -0600314 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500315 {
akmhoqueffacaa82012-09-13 17:48:30 -0500316
akmhoquef5537b42013-02-22 08:33:32 -0600317 if ( name_lsa->header->isValid == 1 )
318 {
akmhoque7b791452012-10-30 11:24:56 -0500319 if ( nlsr->debugging )
320 printf("New Name LSA... Adding to LSDB\n");
321 if ( nlsr->detailed_logging )
322 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n");
323
324
akmhoqueffacaa82012-09-13 17:48:30 -0500325 new_name_lsa = e->data;
akmhoque8876e982013-02-21 13:35:46 -0600326
akmhoque54d86112013-02-21 16:42:34 -0600327
akmhoque0ab71642013-02-21 10:10:33 -0600328 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500329 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
330
331 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
332 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque8876e982013-02-21 13:35:46 -0600333 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 -0500334
335 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque0ab71642013-02-21 10:10:33 -0600336 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500337 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
338 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
339 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
340 new_name_lsa->header->isValid=name_lsa->header->isValid;
341
342
akmhoque0ab71642013-02-21 10:10:33 -0600343 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500344 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
345 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
346 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
akmhoque8876e982013-02-21 13:35:46 -0600347
akmhoqueffacaa82012-09-13 17:48:30 -0500348
akmhoque7b791452012-10-30 11:24:56 -0500349 if ( nlsr->debugging )
350 {
351 printf("New Name LSA Added....\n");
352 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
353 }
354 if ( nlsr->detailed_logging )
355 {
356 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n");
357 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
358 }
akmhoque54d86112013-02-21 16:42:34 -0600359
akmhoqueffacaa82012-09-13 17:48:30 -0500360 set_new_lsdb_version();
akmhoque54d86112013-02-21 16:42:34 -0600361
akmhoque7b791452012-10-30 11:24:56 -0500362 if ( nlsr->debugging )
363 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
364 if ( nlsr->detailed_logging )
365 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500366
akmhoque9e9fc722012-09-26 14:03:25 -0500367
akmhoquede61ba92012-09-20 22:19:12 -0500368 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500369 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500370 {
akmhoquede61ba92012-09-20 22:19:12 -0500371 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 -0500372 if ( check == HT_NEW_ENTRY )
373 {
akmhoque7b791452012-10-30 11:24:56 -0500374 if ( nlsr->debugging )
375 printf("Added in npt \n");
376 if ( nlsr->detailed_logging )
377 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500378 }
akmhoque3560cb62012-09-09 10:52:30 -0500379 }
akmhoqueffacaa82012-09-13 17:48:30 -0500380 else
akmhoque3560cb62012-09-09 10:52:30 -0500381 {
akmhoquede61ba92012-09-20 22:19:12 -0500382 int *faces=malloc(num_next_hop*sizeof(int));
383 int *route_costs=malloc(num_next_hop*sizeof(int));
384 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500385 if ( nlsr->debugging )
386 {
387 printf("Printing from install_name_lsa \n");
388 int j;
389 for(j=0;j<num_next_hop;j++)
390 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
391 }
392 if ( nlsr->detailed_logging )
393 {
394 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
395 int j;
396 for(j=0;j<num_next_hop;j++)
397 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
398 }
akmhoquede61ba92012-09-20 22:19:12 -0500399 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 -0500400 if ( check == HT_NEW_ENTRY )
401 {
akmhoque7b791452012-10-30 11:24:56 -0500402 if ( nlsr->debugging )
403 printf("Added in npt \n");
404 if ( nlsr->detailed_logging )
405 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500406 }
akmhoquede61ba92012-09-20 22:19:12 -0500407 free(faces);
408 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500409
akmhoque3560cb62012-09-09 10:52:30 -0500410 }
akmhoquede61ba92012-09-20 22:19:12 -0500411
akmhoque9e9fc722012-09-26 14:03:25 -0500412 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
413 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
akmhoquef5537b42013-02-22 08:33:32 -0600414 write_log_for_name_lsa(new_name_lsa);
akmhoque9e9fc722012-09-26 14:03:25 -0500415 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500416
akmhoque54d86112013-02-21 16:42:34 -0600417 //free(time_stamp);
akmhoquef5537b42013-02-22 08:33:32 -0600418 }
419 else
420 {
421 hashtb_delete(e);
422 }
akmhoqueffacaa82012-09-13 17:48:30 -0500423
424 }
425 else if(res == HT_OLD_ENTRY)
426 {
427 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500428 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500429 {
akmhoque7b791452012-10-30 11:24:56 -0500430 if ( nlsr->debugging )
431 printf("Older Adj LSA. Discarded... \n");
432 if ( nlsr->detailed_logging )
433 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500434 }
435 else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 )
436 {
akmhoque7b791452012-10-30 11:24:56 -0500437 if ( nlsr->debugging )
438 printf("Duplicate Adj LSA. Discarded... \n");
439 if ( nlsr->detailed_logging )
440 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500441 }
442 else
443 {
444 if ( name_lsa->header->isValid == 0 )
445 {
446 // have to call to delete npt table entry
akmhoque3cced642012-09-24 16:20:20 -0500447 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 -0500448
449 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
450 {
akmhoque9e9fc722012-09-26 14:03:25 -0500451 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
452 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
453 write_log_for_name_lsa(new_name_lsa);
454 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
455
akmhoqueffacaa82012-09-13 17:48:30 -0500456 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500457 if ( nlsr->debugging )
458 printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
459 if ( nlsr->detailed_logging )
460 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 -0500461 }
462 else
463 {
464 new_name_lsa->header->isValid=name_lsa->header->isValid;
465 free(new_name_lsa->header->orig_time);
466 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
467 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
468 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
469 }
akmhoque7b791452012-10-30 11:24:56 -0500470 if ( nlsr->debugging )
471 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
472 if ( nlsr->detailed_logging )
473 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500474 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500475 if ( nlsr->debugging )
476 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
477 if ( nlsr->detailed_logging )
478 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500479 }
480 else
481 {
482 int is_npt_update=0;
483 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
484 {
485 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500486 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 -0500487 }
488
489 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500490 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
491 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
492 write_log_for_name_lsa(new_name_lsa);
493 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
494
akmhoqueffacaa82012-09-13 17:48:30 -0500495
496 free(new_name_lsa->header->orig_time);
497 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
498 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600499 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500500
501 new_name_lsa->header->isValid=name_lsa->header->isValid;
502
503 free(new_name_lsa->name_prefix->name);
504 free(new_name_lsa->name_prefix);
505 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
506 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
507 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
508 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
509
akmhoque9e9fc722012-09-26 14:03:25 -0500510
511 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
512 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
513 write_log_for_name_lsa(new_name_lsa);
514 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
515
akmhoque7b791452012-10-30 11:24:56 -0500516 if ( nlsr->debugging )
517 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
518 if ( nlsr->detailed_logging )
519 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
520
akmhoqueffacaa82012-09-13 17:48:30 -0500521 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500522
523 if ( nlsr->debugging )
524 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
525 if ( nlsr->detailed_logging )
526 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
527
akmhoqueffacaa82012-09-13 17:48:30 -0500528
529 if( is_npt_update == 1 )
530 {
akmhoquede61ba92012-09-20 22:19:12 -0500531 //struct hashtb *face_list;
532 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
533 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500534 {
akmhoquede61ba92012-09-20 22:19:12 -0500535
536 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 -0500537 if ( check == HT_NEW_ENTRY )
538 {
akmhoque7b791452012-10-30 11:24:56 -0500539 if ( nlsr->debugging )
540 printf("Added in npt \n");
541 if ( nlsr->detailed_logging )
542 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500543 }
544 }
545 else
546 {
akmhoquede61ba92012-09-20 22:19:12 -0500547 int *faces=malloc(num_next_hop*sizeof(int));
548 int *route_costs=malloc(num_next_hop*sizeof(int));
549 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500550
551 if ( nlsr->debugging )
552 {
553 printf("Printing from install_name_lsa \n");
554 int j;
555 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500556 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500557 }
558 if ( nlsr->detailed_logging )
559 {
560 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
561 int j;
562 for(j=0;j<num_next_hop;j++)
563 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
564 }
565
akmhoquede61ba92012-09-20 22:19:12 -0500566
567 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 -0500568 if ( check == HT_NEW_ENTRY )
569 {
akmhoque7b791452012-10-30 11:24:56 -0500570 if ( nlsr->debugging )
571 printf("Added in npt \n");
572 if ( nlsr->detailed_logging )
573 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500574 }
akmhoquede61ba92012-09-20 22:19:12 -0500575 free(faces);
576 free(route_costs);
577
akmhoqueffacaa82012-09-13 17:48:30 -0500578 }
akmhoquede61ba92012-09-20 22:19:12 -0500579
akmhoqueffacaa82012-09-13 17:48:30 -0500580 }
581 }
582 }
583
akmhoque3560cb62012-09-09 10:52:30 -0500584 }
akmhoque53f64222012-09-05 13:57:51 -0500585
akmhoqueffacaa82012-09-13 17:48:30 -0500586 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500587
akmhoquef5537b42013-02-22 08:33:32 -0600588 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500589}
590
akmhoque9e9fc722012-09-26 14:03:25 -0500591void
592write_log_for_name_lsa(struct nlsa *name_lsa)
593{
594
595 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
596 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
597 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500598 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
599 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
600 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
601 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500602 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
603 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
604 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
605 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
606}
akmhoque53f64222012-09-05 13:57:51 -0500607
akmhoque03004e62012-09-06 01:12:28 -0500608void
609print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500610{
akmhoque53f64222012-09-05 13:57:51 -0500611
akmhoque7b791452012-10-30 11:24:56 -0500612 if ( nlsr->debugging )
613 {
614 printf("-----------Name LSA Content---------------\n");
615 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
616 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
617 printf(" LS Type : %d\n",name_lsa->header->ls_type);
618 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
619 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
620 printf(" Is Valid : %d\n",name_lsa->header->isValid);
621 printf(" LSA Data \n");
622 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
623 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
624
625 printf("\n");
626 }
akmhoquef71d9082012-08-22 12:51:53 -0400627}
628
629void
630print_name_lsdb(void)
631{
akmhoque7b791452012-10-30 11:24:56 -0500632 if ( nlsr->debugging )
633 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500634 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400635 struct nlsa *name_lsa;
636
637 struct hashtb_enumerator ee;
638 struct hashtb_enumerator *e = &ee;
639
640 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500641 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400642
akmhoque53f64222012-09-05 13:57:51 -0500643 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400644 {
akmhoque7b791452012-10-30 11:24:56 -0500645 if ( nlsr->debugging )
646 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400647 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500648 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400649 hashtb_next(e);
650 }
651
652 hashtb_end(e);
653
akmhoque3171d652012-11-13 11:44:33 -0600654 if ( nlsr->debugging )
655 printf("\n");
656 if ( nlsr->detailed_logging )
657 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500658}
659
akmhoque03004e62012-09-06 01:12:28 -0500660
661void
662build_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 -0500663{
akmhoque7b791452012-10-30 11:24:56 -0500664 if ( nlsr->debugging )
665 printf("build_and_install_others_name_lsa called \n");
666 if ( nlsr->detailed_logging )
667 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500668
akmhoque03004e62012-09-06 01:12:28 -0500669 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
670 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
671 print_name_lsa(name_lsa);
672 install_name_lsa(name_lsa);
673 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500674 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500675
akmhoquef5537b42013-02-22 08:33:32 -0600676 destroy_name_lsa(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500677
678}
679
680void
akmhoque03004e62012-09-06 01:12:28 -0500681build_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 -0500682{
akmhoque7b791452012-10-30 11:24:56 -0500683 if ( nlsr->debugging )
684 printf("build_others_name_lsa called\n");
685 if ( nlsr->detailed_logging )
686 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500687
akmhoquef5537b42013-02-22 08:33:32 -0600688 name_lsa->header=(struct nlsa_header *)calloc(1,sizeof(struct nlsa_header ));
akmhoque03004e62012-09-06 01:12:28 -0500689 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500690
akmhoquef5537b42013-02-22 08:33:32 -0600691 name_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
692 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500693
akmhoque03004e62012-09-06 01:12:28 -0500694 name_lsa->header->ls_id=ls_id;
akmhoquef5537b42013-02-22 08:33:32 -0600695 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
696 name_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
697 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque03004e62012-09-06 01:12:28 -0500698 name_lsa->header->orig_router->length=strlen(orig_router)+1;
699 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500700
akmhoquef5537b42013-02-22 08:33:32 -0600701 name_lsa->name_prefix=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
702 name_lsa->name_prefix->name=(char *)calloc(strlen(np)+1,sizeof(char));
703 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
akmhoque03004e62012-09-06 01:12:28 -0500704 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400705}
akmhoqued79438d2012-08-27 13:31:42 -0500706
707
akmhoqueb77b95f2013-02-08 12:28:47 -0600708void
709make_cor_lsa_key(char *key,struct clsa *cor_lsa)
710{
711 memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
712 memcpy(key+strlen(key),"/",1);
713 char ls_type[2];
714 sprintf(ls_type,"%d",cor_lsa->header->ls_type);
715 memcpy(key+strlen(key),ls_type,strlen(ls_type));
716 key[strlen(key)]='\0';
717}
akmhoqueffacaa82012-09-13 17:48:30 -0500718
719
akmhoque53f64222012-09-05 13:57:51 -0500720void
721make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500722{
akmhoque53f64222012-09-05 13:57:51 -0500723 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
724 memcpy(key+strlen(key),"/",1);
725 char ls_type[2];
726 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
727 memcpy(key+strlen(key),ls_type,strlen(ls_type));
728 key[strlen(key)]='\0';
729}
730
akmhoque03004e62012-09-06 01:12:28 -0500731int
732build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
733{
akmhoqueffacaa82012-09-13 17:48:30 -0500734 if(flags == CCN_SCHEDULE_CANCEL)
735 {
736 return -1;
737 }
738
739 nlsr_lock();
740
akmhoque7b791452012-10-30 11:24:56 -0500741 if ( nlsr->debugging )
742 printf("build_and_install_adj_lsa called \n");
743 if ( nlsr->detailed_logging )
744 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
745
746 if ( nlsr->debugging )
747 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
748 if ( nlsr->detailed_logging )
749 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500750
751 if(nlsr->adj_build_flag > 0)
752 {
akmhoque7b791452012-10-30 11:24:56 -0500753 if ( nlsr->debugging )
754 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
755 if ( nlsr->detailed_logging )
756 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
757
akmhoque03004e62012-09-06 01:12:28 -0500758 if ( is_adj_lsa_build()> 0)
759 {
760 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
761 build_adj_lsa(adj_lsa);
762 install_adj_lsa(adj_lsa);
763
akmhoqueb77b95f2013-02-08 12:28:47 -0600764 char lst[2];
765 memset(lst,0,2);
766 sprintf(lst,"%d",LS_TYPE_ADJ);
767
akmhoquef5537b42013-02-22 08:33:32 -0600768 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15,sizeof(char));
769 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);
akmhoqueb77b95f2013-02-08 12:28:47 -0600770
771 if ( nlsr->debugging )
772 printf("Adj LSA Repo Key: %s \n",repo_key);
773
akmhoquef5537b42013-02-22 08:33:32 -0600774 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -0600775 make_adj_lsa_key(key,adj_lsa);
776 if ( nlsr->debugging )
777 printf("Adj LSA: %s \n",key);
778
akmhoquef5537b42013-02-22 08:33:32 -0600779 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
780 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
781 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600782 lsaid->length=strlen(key)+1;
783
784
785 write_adj_lsa_to_repo(repo_key, lsaid);
786
akmhoquef5537b42013-02-22 08:33:32 -0600787 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600788 free(repo_key);
789 free(lsaid->name);
790 free(lsaid);
791
akmhoquef5537b42013-02-22 08:33:32 -0600792 destroy_adj_lsa(adj_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -0600793
akmhoque03004e62012-09-06 01:12:28 -0500794 nlsr->adj_build_flag=0;
795 print_adj_lsdb();
796 }
797 else
798 {
akmhoque7b791452012-10-30 11:24:56 -0500799 if ( nlsr->debugging )
800 printf("Can not build adj LSA now\n");
801 if ( nlsr->detailed_logging )
802 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500803 }
804 }
805 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500806
807 nlsr_unlock();
808
akmhoque03004e62012-09-06 01:12:28 -0500809 return 0;
810}
811
812
813void
814build_adj_lsa(struct alsa * adj_lsa)
815{
akmhoque7b791452012-10-30 11:24:56 -0500816 if ( nlsr->debugging )
817 printf("build_adj_lsa called \n");
818 if ( nlsr->detailed_logging )
819 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500820
821 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500822
akmhoque03004e62012-09-06 01:12:28 -0500823 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
824 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
825 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
826 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
827 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
828 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
829
830 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
831
akmhoque03004e62012-09-06 01:12:28 -0500832
akmhoquef5537b42013-02-22 08:33:32 -0600833 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500834 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
835 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
836 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
837 free(time_stamp);
838
akmhoque03004e62012-09-06 01:12:28 -0500839 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500840
841
842 struct ccn_charbuf *c=ccn_charbuf_create();
843 get_active_nbr_adj_data(c);
844 char *data=ccn_charbuf_as_string(c);
845
akmhoquef5537b42013-02-22 08:33:32 -0600846 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
847 //memset(adj_lsa->body,0,strlen(data)+1);
akmhoque03004e62012-09-06 01:12:28 -0500848 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoquef5537b42013-02-22 08:33:32 -0600849 data[strlen(data)]='\0';
akmhoque03004e62012-09-06 01:12:28 -0500850 ccn_charbuf_destroy(&c);
851
akmhoque03004e62012-09-06 01:12:28 -0500852 nlsr->adj_build_count++;
853
854
855}
856
857
akmhoque53f64222012-09-05 13:57:51 -0500858void
859install_adj_lsa(struct alsa * adj_lsa)
860{
akmhoqued79438d2012-08-27 13:31:42 -0500861
akmhoque7b791452012-10-30 11:24:56 -0500862 if ( nlsr->debugging )
863 printf("install_adj_lsa called \n");
864 if ( nlsr->detailed_logging )
865 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
866
akmhoque03004e62012-09-06 01:12:28 -0500867
akmhoque53f64222012-09-05 13:57:51 -0500868
akmhoqueffacaa82012-09-13 17:48:30 -0500869
akmhoquef5537b42013-02-22 08:33:32 -0600870 char *key=(char *)calloc(adj_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueffacaa82012-09-13 17:48:30 -0500871 make_adj_lsa_key(key,adj_lsa);
akmhoqueffacaa82012-09-13 17:48:30 -0500872
akmhoque8876e982013-02-21 13:35:46 -0600873 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500874
875 struct hashtb_enumerator ee;
876 struct hashtb_enumerator *e = &ee;
877 int res;
878
879 hashtb_start(nlsr->lsdb->adj_lsdb, e);
880 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500881
akmhoque03004e62012-09-06 01:12:28 -0500882
akmhoque53f64222012-09-05 13:57:51 -0500883
akmhoque62c0c192012-09-24 07:49:25 -0500884 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500885 {
akmhoque62c0c192012-09-24 07:49:25 -0500886 if ( adj_lsa->no_link > 0)
887 {
akmhoque3171d652012-11-13 11:44:33 -0600888 if ( nlsr->debugging )
889 printf("New ADJ LSA... Adding to LSDB\n");
890 if ( nlsr->detailed_logging )
891 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
akmhoque62c0c192012-09-24 07:49:25 -0500892 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500893
akmhoquef5537b42013-02-22 08:33:32 -0600894 new_adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
akmhoque62c0c192012-09-24 07:49:25 -0500895 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
akmhoquef5537b42013-02-22 08:33:32 -0600896 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500897 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 -0500898
akmhoquef5537b42013-02-22 08:33:32 -0600899 new_adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
900 new_adj_lsa->header->orig_router->name=(char *)calloc(adj_lsa->header->orig_router->length,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500901 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
902 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500903
akmhoque62c0c192012-09-24 07:49:25 -0500904 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500905
akmhoque0b60ba92013-02-25 17:55:35 -0600906 //if(new_adj_lsa->body )
907 //free(new_adj_lsa->body);
akmhoquef5537b42013-02-22 08:33:32 -0600908 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
909 //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -0500910 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
911
912 add_next_hop_router(new_adj_lsa->header->orig_router->name);
913 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500914
915 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
916 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
917 write_log_for_adj_lsa(new_adj_lsa);
918 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500919 }
920 else
921 {
922 hashtb_delete(e);
923 }
akmhoque53f64222012-09-05 13:57:51 -0500924
akmhoque7b791452012-10-30 11:24:56 -0500925 if ( nlsr->debugging )
926 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
927 if ( nlsr->detailed_logging )
928 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
929
akmhoque53f64222012-09-05 13:57:51 -0500930 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500931
932 if ( nlsr->debugging )
933 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
934 if ( nlsr->detailed_logging )
935 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
936
akmhoqueffacaa82012-09-13 17:48:30 -0500937 }
938 else if(res == HT_OLD_ENTRY)
939 {
940 new_adj_lsa = e->data;
941 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
942 {
akmhoque7b791452012-10-30 11:24:56 -0500943 if ( nlsr->debugging )
944 printf("Older/Duplicate Adj LSA. Discarded...\n");
945 if ( nlsr->detailed_logging )
946 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500947 }
948 else
949 {
akmhoqueffacaa82012-09-13 17:48:30 -0500950
akmhoque62c0c192012-09-24 07:49:25 -0500951 if ( adj_lsa->no_link > 0)
952 {
akmhoque9e9fc722012-09-26 14:03:25 -0500953 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
954 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
955 write_log_for_adj_lsa(new_adj_lsa);
956 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500957
akmhoque62c0c192012-09-24 07:49:25 -0500958 free(new_adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -0600959 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500960 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
961
962 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500963
akmhoquef5537b42013-02-22 08:33:32 -0600964 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
965 //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -0500966 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500967
akmhoque62c0c192012-09-24 07:49:25 -0500968 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500969
970 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
971 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
972 write_log_for_adj_lsa(new_adj_lsa);
973 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500974 }
975 else
976 {
akmhoque9e9fc722012-09-26 14:03:25 -0500977 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
978 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
979 write_log_for_adj_lsa(new_adj_lsa);
980 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
981
akmhoque62c0c192012-09-24 07:49:25 -0500982 hashtb_delete(e);
983 }
akmhoque7b791452012-10-30 11:24:56 -0500984
985 if ( nlsr->debugging )
986 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
987 if ( nlsr->detailed_logging )
988 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
989
akmhoqueffacaa82012-09-13 17:48:30 -0500990 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500991
992 if ( nlsr->debugging )
993 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
994 if ( nlsr->detailed_logging )
995 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500996 }
997
998 }
999 hashtb_end(e);
1000
1001 if ( !nlsr->is_route_calculation_scheduled )
1002 {
1003 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1004 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -05001005 }
1006
akmhoque03004e62012-09-06 01:12:28 -05001007
akmhoquef5537b42013-02-22 08:33:32 -06001008 free(key);
akmhoqueffacaa82012-09-13 17:48:30 -05001009
akmhoquef5537b42013-02-22 08:33:32 -06001010 //free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -05001011}
1012
1013void
akmhoque9e9fc722012-09-26 14:03:25 -05001014write_log_for_adj_lsa_body(const char *body, int no_link)
1015{
1016 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001017 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1018 //memset( lsa_data,0,strlen(body)+1);
akmhoque9e9fc722012-09-26 14:03:25 -05001019 memcpy(lsa_data,body,strlen(body)+1);
1020 char *sep="|";
1021 char *rem;
1022 char *rtr_id;
1023 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001024 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -05001025 char *metric;
1026
1027 if(no_link >0 )
1028 {
1029 rtr_id=strtok_r(lsa_data,sep,&rem);
1030 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001031 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001032 metric=strtok_r(NULL,sep,&rem);
1033
1034 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001035 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1036 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001037 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001038 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001039
1040
1041 for(i=1;i<no_link;i++)
1042 {
1043 rtr_id=strtok_r(NULL,sep,&rem);
1044 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001045 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001046 metric=strtok_r(NULL,sep,&rem);
1047 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001048 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1049 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001050 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001051 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001052
1053 }
1054 }
1055
akmhoquef5537b42013-02-22 08:33:32 -06001056 if(lsa_data)
1057 free(lsa_data);
akmhoque9e9fc722012-09-26 14:03:25 -05001058}
1059
1060
1061void
1062write_log_for_adj_lsa(struct alsa * adj_lsa)
1063{
1064 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001065 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1066 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1067 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1068 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001069 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001070 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001071
1072 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1073
1074 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1075
1076}
1077
1078void
akmhoque53f64222012-09-05 13:57:51 -05001079print_adj_lsa_body(const char *body, int no_link)
1080{
1081 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001082 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1083 //memset( lsa_data,0,strlen(body)+1);
akmhoque53f64222012-09-05 13:57:51 -05001084 memcpy(lsa_data,body,strlen(body)+1);
1085 char *sep="|";
1086 char *rem;
1087 char *rtr_id;
1088 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001089 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001090 char *metric;
1091
akmhoque53f64222012-09-05 13:57:51 -05001092 if(no_link >0 )
1093 {
1094 rtr_id=strtok_r(lsa_data,sep,&rem);
1095 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001096 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001097 metric=strtok_r(NULL,sep,&rem);
1098
akmhoqueb77b95f2013-02-08 12:28:47 -06001099 if ( nlsr->debugging ) {
1100 printf(" Link %d \n",i+1);
1101 printf(" Neighbor : %s \n",rtr_id);
1102 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001103 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001104 printf(" Metric : %s \n",metric);
1105 }
akmhoque53f64222012-09-05 13:57:51 -05001106
1107 for(i=1;i<no_link;i++)
1108 {
1109 rtr_id=strtok_r(NULL,sep,&rem);
1110 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001111 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001112 metric=strtok_r(NULL,sep,&rem);
1113 printf(" Link %d \n",i+1);
1114 printf(" Neighbor : %s \n",rtr_id);
1115 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001116 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001117 printf(" Metric : %s \n",metric);
1118
1119 }
1120 }
1121
akmhoquef5537b42013-02-22 08:33:32 -06001122 if( lsa_data )
1123 free(lsa_data);
akmhoque53f64222012-09-05 13:57:51 -05001124}
1125
1126void
1127print_adj_lsa(struct alsa * adj_lsa)
1128{
akmhoque7b791452012-10-30 11:24:56 -05001129 if ( nlsr->debugging )
1130 {
1131 printf("-----------ADJ LSA Content---------------\n");
1132 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1133 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1134 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1135 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1136 printf(" Lsa Data:\n");
1137 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001138
akmhoque7b791452012-10-30 11:24:56 -05001139 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1140 printf("\n");
1141 }
akmhoque53f64222012-09-05 13:57:51 -05001142
1143}
1144
1145void
1146print_adj_lsdb(void)
1147{
akmhoque7b791452012-10-30 11:24:56 -05001148 if ( nlsr->debugging )
1149 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001150 int i, adj_lsdb_element;
1151 struct alsa *adj_lsa;
1152
1153 struct hashtb_enumerator ee;
1154 struct hashtb_enumerator *e = &ee;
1155
1156 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1157 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1158
1159 for(i=0;i<adj_lsdb_element;i++)
1160 {
akmhoque7b791452012-10-30 11:24:56 -05001161 if ( nlsr->debugging )
1162 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001163 adj_lsa=e->data;
1164 print_adj_lsa(adj_lsa);
1165 hashtb_next(e);
1166 }
1167
1168 hashtb_end(e);
1169
akmhoque3171d652012-11-13 11:44:33 -06001170 if ( nlsr->debugging )
1171 printf("\n");
1172 if ( nlsr->detailed_logging )
1173 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001174}
1175
1176void
akmhoque03004e62012-09-06 01:12:28 -05001177build_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 -05001178{
akmhoque7b791452012-10-30 11:24:56 -05001179 if ( nlsr->debugging )
1180 printf("build_and_install_others_adj_lsa called \n");
1181 if ( nlsr->detailed_logging )
1182 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001183 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1184 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001185 install_adj_lsa(adj_lsa);
1186
akmhoquef5537b42013-02-22 08:33:32 -06001187 destroy_adj_lsa(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001188
akmhoque03004e62012-09-06 01:12:28 -05001189 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001190
akmhoque53f64222012-09-05 13:57:51 -05001191}
1192
akmhoque03004e62012-09-06 01:12:28 -05001193
akmhoque53f64222012-09-05 13:57:51 -05001194void
akmhoque03004e62012-09-06 01:12:28 -05001195build_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 -05001196{
akmhoque7b791452012-10-30 11:24:56 -05001197 if ( nlsr->debugging )
1198 printf("build_others_adj_lsa called \n");
1199 if ( nlsr->detailed_logging )
1200 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001201
akmhoque03004e62012-09-06 01:12:28 -05001202 /*Filling Up Header Data */
akmhoquef5537b42013-02-22 08:33:32 -06001203 adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
1204 adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
1205 adj_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001206 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001207
akmhoque03004e62012-09-06 01:12:28 -05001208 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001209
akmhoque53f64222012-09-05 13:57:51 -05001210
akmhoque03004e62012-09-06 01:12:28 -05001211 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001212
akmhoquef5537b42013-02-22 08:33:32 -06001213 adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001214 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001215
akmhoque03004e62012-09-06 01:12:28 -05001216 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001217
akmhoquef5537b42013-02-22 08:33:32 -06001218 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001219 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001220
akmhoque53f64222012-09-05 13:57:51 -05001221}
1222
akmhoque03004e62012-09-06 01:12:28 -05001223
akmhoque53f64222012-09-05 13:57:51 -05001224long int
1225get_name_lsdb_num_element(void)
1226{
1227 long int num_element;
1228
1229
1230 struct hashtb_enumerator ee;
1231 struct hashtb_enumerator *e = &ee;
1232
1233 hashtb_start(nlsr->lsdb->name_lsdb, e);
1234 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1235 hashtb_end(e);
1236
1237 return num_element;
1238}
1239
1240long int
1241get_adj_lsdb_num_element(void)
1242{
1243 long int num_element;
1244
1245
1246 struct hashtb_enumerator ee;
1247 struct hashtb_enumerator *e = &ee;
1248
1249 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1250 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1251 hashtb_end(e);
1252
1253 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001254}
akmhoque03004e62012-09-06 01:12:28 -05001255
akmhoque03004e62012-09-06 01:12:28 -05001256
1257int
1258check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1259{
1260 int ret=0;
1261 struct ccn_charbuf *key=ccn_charbuf_create();
1262 ccn_charbuf_append_string(key,orig_router);
1263 ccn_charbuf_append_string(key,"/");
1264 ccn_charbuf_append_string(key,lst);
1265 ccn_charbuf_append_string(key,"/");
1266 ccn_charbuf_append_string(key,lsid);
1267
1268 int res;
1269 struct nlsa *name_lsa;
1270
1271 struct hashtb_enumerator ee;
1272 struct hashtb_enumerator *e = &ee;
1273
1274 hashtb_start(nlsr->lsdb->name_lsdb, e);
1275 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1276
1277 if( res == HT_NEW_ENTRY )
1278 {
1279 hashtb_delete(e);
1280 ret=1;
1281
1282 }
1283 else if(res == HT_OLD_ENTRY)
1284 {
1285 name_lsa=e->data;
1286 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1287 {
1288 ret=1;
1289 }
1290 }
1291
1292 hashtb_end(e);
1293
1294 ccn_charbuf_destroy(&key);
1295
1296 return ret;
1297}
1298
1299int
1300check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1301{
1302 int ret=0;
1303 struct ccn_charbuf *key=ccn_charbuf_create();
1304 ccn_charbuf_append_string(key,orig_router);
1305 ccn_charbuf_append_string(key,"/");
1306 ccn_charbuf_append_string(key,lst);
1307
1308 int res;
1309 struct alsa *adj_lsa;
1310
1311 struct hashtb_enumerator ee;
1312 struct hashtb_enumerator *e = &ee;
1313
1314 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1315 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1316
1317 if( res == HT_NEW_ENTRY )
1318 {
1319 hashtb_delete(e);
1320 ret=1;
1321
1322 }
1323 else if(res == HT_OLD_ENTRY)
1324 {
1325 adj_lsa=e->data;
1326 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1327 {
1328 ret=1;
1329 }
1330 }
1331
1332 hashtb_end(e);
1333
1334 ccn_charbuf_destroy(&key);
1335
1336 return ret;
1337}
1338
akmhoqueb77b95f2013-02-08 12:28:47 -06001339int
1340check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1341{
1342 int ret=0;
1343 struct ccn_charbuf *key=ccn_charbuf_create();
1344 ccn_charbuf_append_string(key,orig_router);
1345 ccn_charbuf_append_string(key,"/");
1346 ccn_charbuf_append_string(key,lst);
1347
1348 int res;
1349 struct clsa *cor_lsa;
1350
1351 struct hashtb_enumerator ee;
1352 struct hashtb_enumerator *e = &ee;
1353
1354 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1355 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1356
1357 if( res == HT_NEW_ENTRY )
1358 {
1359 hashtb_delete(e);
1360 ret=1;
1361
1362 }
1363 else if(res == HT_OLD_ENTRY)
1364 {
1365 cor_lsa=e->data;
1366 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1367 {
1368 ret=1;
1369 }
1370 }
1371
1372 hashtb_end(e);
1373
1374 ccn_charbuf_destroy(&key);
1375
1376 return ret;
1377}
1378
akmhoque03004e62012-09-06 01:12:28 -05001379void
1380get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1381{
akmhoque7b791452012-10-30 11:24:56 -05001382 if ( nlsr->debugging )
1383 printf("get_name_lsa_data called \n");
1384 if ( nlsr->detailed_logging )
1385 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001386
akmhoque8876e982013-02-21 13:35:46 -06001387 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001388
1389 struct hashtb_enumerator ee;
1390 struct hashtb_enumerator *e = &ee;
1391 int res;
1392
1393 hashtb_start(nlsr->lsdb->name_lsdb, e);
1394 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1395
1396 if( res == HT_OLD_ENTRY )
1397 {
1398 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001399
akmhoque7b791452012-10-30 11:24:56 -05001400 if ( nlsr->debugging )
1401 printf("NAME LSA found \n");
1402 if ( nlsr->detailed_logging )
1403 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001404
1405 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1406 ccn_charbuf_append_string(lsa_data,"|");
1407
1408 char *temp_length=(char *)malloc(20);
1409 memset(temp_length,0,20);
1410 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1411 ccn_charbuf_append_string(lsa_data,temp_length);
1412 free(temp_length);
1413 ccn_charbuf_append_string(lsa_data,"|");
1414
1415 char *temp_ltype=(char *)malloc(20);
1416 memset(temp_ltype,0,20);
1417 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1418 ccn_charbuf_append_string(lsa_data,temp_ltype);
1419 free(temp_ltype);
1420 ccn_charbuf_append_string(lsa_data,"|");
1421
1422 char *temp_lsid=(char *)malloc(20);
1423 memset(temp_lsid,0,20);
1424 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1425 ccn_charbuf_append_string(lsa_data,temp_lsid);
1426 free(temp_lsid);
1427 ccn_charbuf_append_string(lsa_data,"|");
1428
1429 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1430 ccn_charbuf_append_string(lsa_data,"|");
1431
1432 char *temp_valid=(char *)malloc(20);
1433 memset(temp_valid,0,20);
1434 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1435 ccn_charbuf_append_string(lsa_data,temp_valid);
1436 free(temp_valid);
1437 ccn_charbuf_append_string(lsa_data,"|");
1438
1439 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1440 ccn_charbuf_append_string(lsa_data,"|");
1441
1442 char *temp_npl=(char *)malloc(20);
1443 memset(temp_npl,0,20);
1444 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1445 ccn_charbuf_append_string(lsa_data,temp_npl);
1446 free(temp_npl);
1447 ccn_charbuf_append_string(lsa_data,"|");
1448
1449 }
1450 else if(res == HT_NEW_ENTRY)
1451 {
1452 hashtb_delete(e);
1453 }
1454
1455 hashtb_end(e);
1456}
1457
1458void
1459get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1460{
akmhoque7b791452012-10-30 11:24:56 -05001461 if ( nlsr->debugging )
1462 printf("get_adj_lsa_data called \n");
1463 if ( nlsr->detailed_logging )
1464 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001465
akmhoquececba942013-02-25 17:33:34 -06001466 struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoque03004e62012-09-06 01:12:28 -05001467
1468 struct hashtb_enumerator ee;
1469 struct hashtb_enumerator *e = &ee;
1470 int res;
1471
1472 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1473 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1474
1475 if( res == HT_OLD_ENTRY )
1476 {
1477 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001478
1479 if ( nlsr->debugging )
1480 printf("Adj LSA found \n");
1481 if ( nlsr->detailed_logging )
1482 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001483
1484 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1485 ccn_charbuf_append_string(lsa_data,"|");
1486
1487 char *temp_length=(char *)malloc(20);
1488 memset(temp_length,0,20);
1489 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1490 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001491 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001492 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001493
1494 char *temp_ltype=(char *)malloc(20);
1495 memset(temp_ltype,0,20);
1496 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1497 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001498 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001499 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001500
1501 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1502 ccn_charbuf_append_string(lsa_data,"|");
1503
1504 char *temp_nl=(char *)malloc(20);
1505 memset(temp_nl,0,20);
1506 sprintf(temp_nl,"%d",adj_lsa->no_link);
1507 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001508 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001509 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001510
1511 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1512
1513
1514 }
1515 else if(res == HT_NEW_ENTRY)
1516 {
1517 hashtb_delete(e);
1518 }
1519
1520 hashtb_end(e);
1521}
akmhoqueffacaa82012-09-13 17:48:30 -05001522
akmhoque3171d652012-11-13 11:44:33 -06001523void
1524make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1525{
1526
1527 if ( nlsr->debugging )
1528 printf("make_name_lsa_invalid called \n");
1529 if ( nlsr->detailed_logging )
1530 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1531
1532
1533 char lst[2];
1534 memset(lst,0,2);
1535 sprintf(lst,"%d",ls_type);
1536
1537 char lsid[10];
1538 memset(lsid,0,10);
1539 sprintf(lsid,"%ld",ls_id);
1540
1541
1542 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1543 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1544
1545
1546 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001547
1548 if ( nlsr->debugging )
1549 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001550
1551 struct nlsa *nlsa;
1552
1553 struct hashtb_enumerator ee;
1554 struct hashtb_enumerator *e = &ee;
1555
1556 int res;
1557
1558 hashtb_start(nlsr->lsdb->name_lsdb, e);
1559 res = hashtb_seek(e, key,strlen(key) , 0);
1560
1561 if( res == HT_OLD_ENTRY )
1562 {
1563 nlsa=e->data;
1564
1565 nlsa->header->isValid=0;
1566
1567 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1568 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1569 write_log_for_name_lsa(nlsa);
1570 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1571
1572 hashtb_delete(e);
1573 }
1574 else if( res == HT_NEW_ENTRY )
1575 {
1576 hashtb_delete(e);
1577 }
1578 hashtb_end(e);
1579
1580 if ( nlsr->debugging )
1581 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1582 if ( nlsr->detailed_logging )
1583 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1584
1585 set_new_lsdb_version();
1586
1587 if ( nlsr->debugging )
1588 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1589 if ( nlsr->detailed_logging )
1590 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1591
1592}
1593
akmhoquef5537b42013-02-22 08:33:32 -06001594
akmhoque866c2222013-02-12 10:49:33 -06001595int
1596delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001597{
akmhoqueb77b95f2013-02-08 12:28:47 -06001598
akmhoque7b791452012-10-30 11:24:56 -05001599 if ( nlsr->debugging )
1600 printf("delete_name_lsa called \n");
1601 if ( nlsr->detailed_logging )
1602 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001603
akmhoque866c2222013-02-12 10:49:33 -06001604 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -06001605
akmhoqueda5b6832012-09-13 22:33:55 -05001606
akmhoque7b791452012-10-30 11:24:56 -05001607 if ( nlsr->debugging )
1608 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1609 if ( nlsr->detailed_logging )
1610 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1611
akmhoqueda5b6832012-09-13 22:33:55 -05001612 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001613
1614 if ( nlsr->debugging )
1615 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1616 if ( nlsr->detailed_logging )
1617 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001618
akmhoqueda5b6832012-09-13 22:33:55 -05001619
1620 return 0;
1621}
1622
akmhoquef5537b42013-02-22 08:33:32 -06001623
akmhoque866c2222013-02-12 10:49:33 -06001624int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001625{
akmhoque866c2222013-02-12 10:49:33 -06001626
akmhoque7b791452012-10-30 11:24:56 -05001627 if ( nlsr->debugging )
1628 printf("delete_adj_lsa called \n");
1629 if ( nlsr->detailed_logging )
1630 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001631
akmhoque7b791452012-10-30 11:24:56 -05001632 if ( nlsr->debugging )
1633 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1634 if ( nlsr->detailed_logging )
1635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1636
akmhoqueda5b6832012-09-13 22:33:55 -05001637 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001638
1639 if ( nlsr->debugging )
1640 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1641 if ( nlsr->detailed_logging )
1642 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1643
akmhoqueda5b6832012-09-13 22:33:55 -05001644
1645 if ( !nlsr->is_route_calculation_scheduled)
1646 {
1647 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1648 nlsr->is_route_calculation_scheduled=1;
1649 }
1650
akmhoqueda5b6832012-09-13 22:33:55 -05001651 return 0;
1652}
1653
akmhoqueffacaa82012-09-13 17:48:30 -05001654void
1655refresh_name_lsdb(void)
1656{
akmhoque7b791452012-10-30 11:24:56 -05001657 if ( nlsr->debugging )
1658 printf("refresh_name_lsdb called \n");
1659 if ( nlsr->detailed_logging )
1660 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001661
akmhoquef5537b42013-02-22 08:33:32 -06001662 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueffacaa82012-09-13 17:48:30 -05001663
1664 long int lsa_life_time;
1665
1666 int i, name_lsdb_element;
1667 struct nlsa *name_lsa;
1668
1669 struct hashtb_enumerator ee;
1670 struct hashtb_enumerator *e = &ee;
1671
1672 hashtb_start(nlsr->lsdb->name_lsdb, e);
1673 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1674
1675 for(i=0;i<name_lsdb_element;i++)
1676 {
1677 name_lsa=e->data;
1678
1679 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001680 if ( nlsr->debugging )
1681 printf("LSA Life Time: %ld \n",lsa_life_time);
1682 if ( nlsr->detailed_logging )
1683 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001684
1685 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1686 {
1687 if ( lsa_life_time > nlsr->lsa_refresh_time )
1688 {
akmhoque14b3f342012-09-14 10:39:02 -05001689 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1690 {
akmhoque7b791452012-10-30 11:24:56 -05001691 if ( nlsr->debugging )
1692 printf("Own Name LSA need to be refrshed\n");
1693 if ( nlsr->detailed_logging )
1694 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001695
1696 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1697 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1698 write_log_for_name_lsa(name_lsa);
1699 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1700
akmhoquef5537b42013-02-22 08:33:32 -06001701 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001702
akmhoque14b3f342012-09-14 10:39:02 -05001703 free(name_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001704 name_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoque14b3f342012-09-14 10:39:02 -05001705 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001706
1707 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1708 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1709 write_log_for_name_lsa(name_lsa);
1710 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001711
akmhoque14b3f342012-09-14 10:39:02 -05001712 free(current_time_stamp);
akmhoque866c2222013-02-12 10:49:33 -06001713
1714 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001715 }
1716 else
akmhoquef5537b42013-02-22 08:33:32 -06001717 {
akmhoque866c2222013-02-12 10:49:33 -06001718 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1719 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1720 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1721 write_log_for_name_lsa(name_lsa);
1722 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001723
1724 destroy_name_lsa_component(name_lsa);
1725
akmhoque866c2222013-02-12 10:49:33 -06001726 hashtb_delete(e);
1727 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001728 }
akmhoqueda5b6832012-09-13 22:33:55 -05001729
akmhoque7b791452012-10-30 11:24:56 -05001730 if ( nlsr->debugging )
1731 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1732 if ( nlsr->detailed_logging )
1733 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1734
akmhoqueda5b6832012-09-13 22:33:55 -05001735 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001736
1737 if ( nlsr->debugging )
1738 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1739 if ( nlsr->detailed_logging )
1740 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1741
1742
akmhoqueda5b6832012-09-13 22:33:55 -05001743
1744 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001745 }
1746 else
1747 {
1748 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001749 }
1750 }
1751 else
1752 {
1753 if ( lsa_life_time > nlsr->router_dead_interval )
1754 {
akmhoque7b791452012-10-30 11:24:56 -05001755 if ( nlsr->debugging )
1756 printf("Others Name LSA need to be deleted\n");
1757 if ( nlsr->detailed_logging )
1758 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001759
akmhoque866c2222013-02-12 10:49:33 -06001760 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1761 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1762 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1763 write_log_for_name_lsa(name_lsa);
1764 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001765
1766 destroy_name_lsa_component(name_lsa);
akmhoque866c2222013-02-12 10:49:33 -06001767 hashtb_delete(e);
1768 i++;
1769 }
1770 else
1771 {
1772 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001773 }
1774 }
akmhoqueffacaa82012-09-13 17:48:30 -05001775 }
1776
1777 hashtb_end(e);
1778
1779 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001780
akmhoqueffacaa82012-09-13 17:48:30 -05001781
1782}
1783
akmhoqueda5b6832012-09-13 22:33:55 -05001784void
akmhoqueffacaa82012-09-13 17:48:30 -05001785refresh_adj_lsdb(void)
1786{
akmhoqueffacaa82012-09-13 17:48:30 -05001787
akmhoque7b791452012-10-30 11:24:56 -05001788 if ( nlsr->debugging )
1789 printf("refresh_adj_lsdb called \n");
1790 if ( nlsr->detailed_logging )
1791 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001792
akmhoquef5537b42013-02-22 08:33:32 -06001793 char *time_stamp=get_current_timestamp_micro_v2();
1794
akmhoqueffacaa82012-09-13 17:48:30 -05001795 long int lsa_life_time;
1796
1797 int i, adj_lsdb_element;
1798 struct alsa *adj_lsa;
1799
1800 struct hashtb_enumerator ee;
1801 struct hashtb_enumerator *e = &ee;
1802
1803 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1804 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1805
1806 for(i=0;i<adj_lsdb_element;i++)
1807 {
1808 adj_lsa=e->data;
1809
akmhoqueb77b95f2013-02-08 12:28:47 -06001810 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001811
1812 if ( nlsr->debugging )
1813 printf("LSA Life Time: %ld \n",lsa_life_time);
1814 if ( nlsr->detailed_logging )
1815 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001816
akmhoqueda5b6832012-09-13 22:33:55 -05001817 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1818 {
1819 if ( lsa_life_time > nlsr->lsa_refresh_time )
1820 {
akmhoque7b791452012-10-30 11:24:56 -05001821 if ( nlsr->debugging )
1822 printf("Own Adj LSA need to be refrshed\n");
1823 if ( nlsr->detailed_logging )
1824 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001825
akmhoquea98c2142012-10-25 15:22:24 -05001826 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1827 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1828 write_log_for_adj_lsa(adj_lsa);
1829 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1830
akmhoquef5537b42013-02-22 08:33:32 -06001831 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001832
1833 free(adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001834 adj_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoqueda5b6832012-09-13 22:33:55 -05001835 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1836
1837 free(current_time_stamp);
1838
akmhoquea98c2142012-10-25 15:22:24 -05001839 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1840 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1841 write_log_for_adj_lsa(adj_lsa);
1842 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001843
akmhoque7b791452012-10-30 11:24:56 -05001844 if ( nlsr->debugging )
1845 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1846 if ( nlsr->detailed_logging )
1847 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1848
akmhoqueda5b6832012-09-13 22:33:55 -05001849 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001850
1851 if ( nlsr->debugging )
1852 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1853 if ( nlsr->detailed_logging )
1854 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001855
1856 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001857
1858
akmhoqueda5b6832012-09-13 22:33:55 -05001859 }
akmhoque866c2222013-02-12 10:49:33 -06001860
1861 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001862 }
1863 else
1864 {
1865 if ( lsa_life_time > nlsr->router_dead_interval )
1866 {
akmhoque7b791452012-10-30 11:24:56 -05001867
1868 if ( nlsr->debugging )
1869 printf("Others Adj LSA need to be deleted\n");
1870 if ( nlsr->detailed_logging )
1871 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06001872 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1873 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1874 write_log_for_adj_lsa(adj_lsa);
1875 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1876 delete_adj_lsa();
akmhoquef5537b42013-02-22 08:33:32 -06001877
1878 destroy_adj_lsa_component(adj_lsa);
akmhoque866c2222013-02-12 10:49:33 -06001879 hashtb_delete(e);
1880 i++;
1881
1882 }
1883 else
1884 {
1885 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001886 }
1887 }
akmhoquef5537b42013-02-22 08:33:32 -06001888
akmhoqueffacaa82012-09-13 17:48:30 -05001889 }
1890
1891 hashtb_end(e);
1892
1893 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05001894}
1895
akmhoqueb77b95f2013-02-08 12:28:47 -06001896
1897void
1898refresh_cor_lsdb(void)
1899{
1900
1901 if ( nlsr->debugging )
1902 printf("refresh_cor_lsdb called \n");
1903 if ( nlsr->detailed_logging )
1904 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
1905
akmhoquef5537b42013-02-22 08:33:32 -06001906 char *time_stamp=get_current_timestamp_micro_v2();
1907
akmhoqueb77b95f2013-02-08 12:28:47 -06001908 long int lsa_life_time;
1909
1910 int i, cor_lsdb_element;
1911 struct clsa *cor_lsa;
1912
1913 struct hashtb_enumerator ee;
1914 struct hashtb_enumerator *e = &ee;
1915
1916 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1917 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
1918
1919 for(i=0;i<cor_lsdb_element;i++)
1920 {
1921 cor_lsa=e->data;
1922
1923 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
1924
1925 if ( nlsr->debugging )
1926 printf("LSA Life Time: %ld \n",lsa_life_time);
1927 if ( nlsr->detailed_logging )
1928 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
1929
1930 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
1931 {
1932 if ( lsa_life_time > nlsr->lsa_refresh_time )
1933 {
1934 if ( nlsr->debugging )
1935 printf("Own Cor LSA need to be refrshed\n");
1936 if ( nlsr->detailed_logging )
1937 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
1938
akmhoquef5537b42013-02-22 08:33:32 -06001939 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06001940
1941 free(cor_lsa->header->orig_time);
1942 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1943 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1944 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1945
1946 free(current_time_stamp);
1947
akmhoqueb77b95f2013-02-08 12:28:47 -06001948 if ( nlsr->debugging )
1949 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1950 if ( nlsr->detailed_logging )
1951 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1952
1953 set_new_lsdb_version();
1954
1955 if ( nlsr->debugging )
1956 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1957 if ( nlsr->detailed_logging )
1958 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1959
1960 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001961 }
1962
1963 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06001964 }
1965 else
1966 {
1967 if ( lsa_life_time > nlsr->router_dead_interval )
1968 {
1969
1970 if ( nlsr->debugging )
1971 printf("Others Adj LSA need to be deleted\n");
1972 if ( nlsr->detailed_logging )
1973 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoquef5537b42013-02-22 08:33:32 -06001974
1975 destroy_cor_lsa_component(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06001976 hashtb_delete(e);
1977 i++;
1978 }
akmhoque866c2222013-02-12 10:49:33 -06001979 else
1980 {
1981 hashtb_next(e);
1982 }
akmhoqueb77b95f2013-02-08 12:28:47 -06001983 }
1984
1985
akmhoque866c2222013-02-12 10:49:33 -06001986
akmhoqueb77b95f2013-02-08 12:28:47 -06001987 }
1988
1989 hashtb_end(e);
1990
1991 free(time_stamp);
1992}
1993
akmhoqueffacaa82012-09-13 17:48:30 -05001994int
1995refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1996{
1997 if(flags == CCN_SCHEDULE_CANCEL)
1998 {
1999 return -1;
2000 }
2001
2002 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002003
akmhoque7b791452012-10-30 11:24:56 -05002004 if ( nlsr->debugging )
2005 printf("refresh_lsdb called\n");
2006 if ( nlsr->detailed_logging )
2007 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002008
2009 refresh_name_lsdb();
2010 refresh_adj_lsdb();
2011
akmhoqueffacaa82012-09-13 17:48:30 -05002012 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002013
akmhoqueffacaa82012-09-13 17:48:30 -05002014 nlsr_unlock();
2015 return 0;
2016}
akmhoqueb77b95f2013-02-08 12:28:47 -06002017
2018void
2019write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2020{
2021 if ( nlsr->debugging )
2022 printf("write_adj_lsa_to_repo called\n");
2023 if ( nlsr->debugging )
2024 printf("Content Prefix: %s\n",repo_content_prefix);
2025
2026 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2027 get_adj_lsa_data(lsa_data,lsa_id);
2028 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002029 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002030
akmhoque829228c2013-02-25 17:39:40 -06002031 char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
akmhoquef5537b42013-02-22 08:33:32 -06002032 data=ccn_charbuf_as_string(lsa_data);
2033 data[strlen(data)]='\0';
2034
2035 write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002036
akmhoque323b5e92013-02-21 13:55:15 -06002037
akmhoqueaa2adc12013-02-25 17:42:28 -06002038 //ccn_charbuf_destroy(&lsa_data);
2039 //free(data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002040}
2041
2042void
2043write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2044{
2045 if ( nlsr->debugging )
2046 printf("write_name_lsa_to_repo called\n");
2047 if ( nlsr->debugging )
2048 printf("Content Prefix: %s\n",repo_content_prefix);
2049
2050 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2051 get_name_lsa_data(lsa_data,lsa_id);
2052
2053 if ( nlsr->debugging )
2054 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2055
akmhoque829228c2013-02-25 17:39:40 -06002056 char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
akmhoquef5537b42013-02-22 08:33:32 -06002057 data=ccn_charbuf_as_string(lsa_data);
2058 data[strlen(data)]='\0';
akmhoque323b5e92013-02-21 13:55:15 -06002059
akmhoquef5537b42013-02-22 08:33:32 -06002060 write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002061
akmhoqueaa2adc12013-02-25 17:42:28 -06002062 //ccn_charbuf_destroy(&lsa_data);
2063 //free(data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002064}
2065
2066
2067void
2068write_name_lsdb_to_repo(char *slice_prefix)
2069{
2070 int i, name_lsdb_element;
2071
2072 struct nlsa *name_lsa;
2073 struct hashtb_enumerator ee;
2074 struct hashtb_enumerator *e = &ee;
2075
2076 hashtb_start(nlsr->lsdb->name_lsdb, e);
2077 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2078
2079 for(i=0;i<name_lsdb_element;i++)
2080 {
2081 name_lsa=e->data;
2082
2083 char lst[2];
2084 memset(lst,0,2);
2085 sprintf(lst,"%d",name_lsa->header->ls_type);
2086
2087 char lsid[10];
2088 memset(lsid,0,10);
2089 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2090
2091
2092 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2093 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2094
2095
2096 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2097
2098 if ( nlsr->debugging )
2099 printf("Name LSA Key: %s \n",key);
2100
2101
akmhoquef5537b42013-02-22 08:33:32 -06002102 char *repo_key=(char *)calloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+16,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002103 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);
2104
2105 if ( nlsr->debugging )
2106 printf("Name LSA Repo Key: %s \n",repo_key);
2107
akmhoquef5537b42013-02-22 08:33:32 -06002108 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
2109 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
2110 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002111 lsaid->length=strlen(key)+1;
2112
2113
2114 write_name_lsa_to_repo(repo_key, lsaid);
2115
2116 free(key);
2117 free(repo_key);
2118 free(lsaid->name);
2119 free(lsaid);
2120
2121 hashtb_next(e);
2122 }
2123
2124 hashtb_end(e);
2125
2126
2127}
2128
2129void
2130print_cor_lsa(struct clsa *cor_lsa)
2131{
2132 if ( nlsr->debugging )
2133 {
2134 printf("-----------Cor LSA Content---------------\n");
2135 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2136 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2137 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2138 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2139 printf(" LSA Data \n");
2140 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2141 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2142
2143 printf("\n");
2144 }
2145}
2146
2147void
2148print_cor_lsdb()
2149{
2150
2151 if ( nlsr->debugging )
2152 printf("print_cor_lsdb called \n");
2153
2154 struct hashtb_enumerator ee;
2155 struct hashtb_enumerator *e = &ee;
2156
2157 int i=1;
2158
2159 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2160 {
2161 if ( nlsr->debugging )
2162 printf("-----------Cor LSA (%d)---------------\n",i);
2163 struct clsa *cor_lsa=e->data;
2164 print_cor_lsa(cor_lsa);
2165 i++;
2166 }
2167 hashtb_end(e);
2168
2169 if ( nlsr->debugging )
2170 printf("\n");
2171 if ( nlsr->detailed_logging )
2172 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2173}
2174
2175void
2176install_cor_lsa(struct clsa *cor_lsa)
2177{
2178 if ( nlsr->debugging )
2179 printf("install_cor_lsa called \n");
2180 if ( nlsr->detailed_logging )
2181 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2182
2183
akmhoquececba942013-02-25 17:33:34 -06002184 //char *time_stamp=(char *)malloc(20);
2185 //memset(time_stamp,0,20);
2186 //get_current_timestamp_micro(time_stamp);
akmhoqueb77b95f2013-02-08 12:28:47 -06002187
2188
akmhoque569a93d2013-02-21 10:19:54 -06002189 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2190 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002191 make_cor_lsa_key(key,cor_lsa);
2192
2193 if ( nlsr->debugging )
2194 printf("Cor LSA key: %s \n",key);
2195
2196 struct hashtb_enumerator ee;
2197 struct hashtb_enumerator *e = &ee;
2198 int res;
2199
2200 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2201 res = hashtb_seek(e, key, strlen(key), 0);
2202
2203 if ( res == HT_NEW_ENTRY )
2204 {
2205 if ( nlsr->debugging )
2206 printf("New Cor LSA... \n");
2207
akmhoque8876e982013-02-21 13:35:46 -06002208 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002209 new_cor_lsa=e->data;
2210 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2211
2212 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2213 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
akmhoquececba942013-02-25 17:33:34 -06002214 //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002215 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2216 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2217
akmhoquececba942013-02-25 17:33:34 -06002218 //new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free
2219 //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
2220 //memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2221 new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002222
2223 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2224
2225 new_cor_lsa->cor_r=cor_lsa->cor_r;
2226 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2227 }
2228 else if ( res == HT_OLD_ENTRY )
2229 {
2230 if ( nlsr->debugging )
2231 printf("Cor LSA exists (Old)... \n");
2232 }
2233 hashtb_end(e);
2234
akmhoquef5537b42013-02-22 08:33:32 -06002235 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002236
2237}
2238
2239void
2240build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2241{
2242 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2243 cor_lsa->header->ls_type=LS_TYPE_COR;
2244
akmhoquef5537b42013-02-22 08:33:32 -06002245 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002246 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2247 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2248 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2249 free(time_stamp);
2250
akmhoquef5537b42013-02-22 08:33:32 -06002251 cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
2252 cor_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002253 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2254 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2255 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2256
2257 cor_lsa->cor_r=cor_r;
2258 cor_lsa->cor_theta=cor_theta;
2259
2260}
2261
2262void
2263build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2264{
2265 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2266 cor_lsa->header->ls_type=ls_type;
2267
2268 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2269 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002270 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002271
2272 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2273 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2274 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002275 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002276 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2277
2278 cor_lsa->cor_r=cor_r;
2279 cor_lsa->cor_theta=cor_theta;
2280
2281}
2282
2283void
2284build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2285{
2286 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2287 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2288 install_cor_lsa(cor_lsa);
2289
2290 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002291
akmhoquef5537b42013-02-22 08:33:32 -06002292 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002293}
2294
2295
2296void
2297build_and_install_cor_lsa()
2298{
2299
2300
2301
2302 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2303
2304 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2305 install_cor_lsa(cor_lsa);
2306
2307 write_cor_lsa_to_repo(cor_lsa);
akmhoquef5537b42013-02-22 08:33:32 -06002308 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002309
2310 print_cor_lsdb();
akmhoqueb77b95f2013-02-08 12:28:47 -06002311
2312}
2313
2314void
2315get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2316{
2317 if ( nlsr->debugging )
2318 printf("get_cor_lsa_data called \n");
2319 if ( nlsr->detailed_logging )
2320 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2321
akmhoquececba942013-02-25 17:33:34 -06002322 struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002323
2324 struct hashtb_enumerator ee;
2325 struct hashtb_enumerator *e = &ee;
2326 int res;
2327
2328 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2329 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2330
2331 if( res == HT_OLD_ENTRY )
2332 {
2333 cor_lsa=e->data;
2334
2335 if ( nlsr->debugging )
2336 printf("Cor LSA found \n");
2337 if ( nlsr->detailed_logging )
2338 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2339
2340 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2341 ccn_charbuf_append_string(lsa_data,"|");
2342
2343 char *temp_length=(char *)malloc(20);
2344 memset(temp_length,0,20);
2345 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2346 ccn_charbuf_append_string(lsa_data,temp_length);
2347 ccn_charbuf_append_string(lsa_data,"|");
2348 free(temp_length);
2349
2350 char *temp_ltype=(char *)malloc(20);
2351 memset(temp_ltype,0,20);
2352 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2353 ccn_charbuf_append_string(lsa_data,temp_ltype);
2354 ccn_charbuf_append_string(lsa_data,"|");
2355 free(temp_ltype);
2356
2357 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2358 ccn_charbuf_append_string(lsa_data,"|");
2359
2360 char *cor_r=(char *)malloc(20);
2361 memset(cor_r,0,20);
2362 sprintf(cor_r,"%f",cor_lsa->cor_r);
2363 ccn_charbuf_append_string(lsa_data,cor_r);
2364 ccn_charbuf_append_string(lsa_data,"|");
2365 free(cor_r);
2366
2367 char *cor_theta=(char *)malloc(20);
2368 memset(cor_theta,0,20);
2369 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2370 ccn_charbuf_append_string(lsa_data,cor_theta);
2371 ccn_charbuf_append_string(lsa_data,"|");
2372 free(cor_theta);
2373
2374 }
2375 else if(res == HT_NEW_ENTRY)
2376 {
2377 hashtb_delete(e);
2378 }
2379
2380 hashtb_end(e);
2381}
2382
2383void
2384write_cor_lsa_to_repo(struct clsa *cor_lsa)
2385{
2386
2387
2388 if ( nlsr->debugging )
2389 printf("write_cor_lsa_to_repo called\n");
2390
2391
akmhoquef5537b42013-02-22 08:33:32 -06002392 char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002393 make_cor_lsa_key(key,cor_lsa);
2394
2395 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2396 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002397
akmhoqueb77b95f2013-02-08 12:28:47 -06002398 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002399 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2400
akmhoqueb77b95f2013-02-08 12:28:47 -06002401 char *lst=(char *)malloc(20);
2402 memset(lst,0,20);
2403 sprintf(lst,"%d",cor_lsa->header->ls_type);
akmhoquef5537b42013-02-22 08:33:32 -06002404 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 20,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002405 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);
2406
2407 if ( nlsr->debugging )
2408 printf("Cor LSA Repo Key: %s \n",repo_key);
2409
akmhoque829228c2013-02-25 17:39:40 -06002410 char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
akmhoquef5537b42013-02-22 08:33:32 -06002411 data=ccn_charbuf_as_string(lsa_data);
2412 data[strlen(data)]='\0';
2413
2414 write_data_to_repo(data, repo_key);
akmhoque0800eda2013-02-21 14:17:52 -06002415
akmhoqueb77b95f2013-02-08 12:28:47 -06002416
2417
2418
2419 free(lst);
2420 free(key);
2421 free(repo_key);
akmhoqueaa2adc12013-02-25 17:42:28 -06002422 //free(data);
2423 //ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002424}
2425
2426void
2427make_cor_lsa_key_by_router_name(char *key,char *router_name)
2428{
2429 memcpy(key+strlen(key),router_name,strlen(router_name));
2430 memcpy(key+strlen(key),"/",1);
2431 char ls_type[2];
2432 sprintf(ls_type,"%d",LS_TYPE_COR);
2433 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2434 key[strlen(key)]='\0';
2435}
2436
2437
2438double
2439get_hyperbolic_r(char *router)
2440{
2441 double ret=-1.0;
2442 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2443 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2444
2445
2446 struct clsa *cor_lsa;
2447 struct hashtb_enumerator ee;
2448 struct hashtb_enumerator *e = &ee;
2449 int res;
2450
2451 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2452 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2453
2454 if ( res == HT_OLD_ENTRY)
2455 {
2456 cor_lsa=e->data;
2457 ret=cor_lsa->cor_r;
2458 }
2459 else if(res == HT_NEW_ENTRY)
2460 {
2461 hashtb_delete(e);
2462 }
2463
2464 hashtb_end(e);
2465
2466 free(cor_lsa_key);
2467 return ret;
2468}
2469
2470double
2471get_hyperbolic_theta(char *router)
2472{
akmhoquef5537b42013-02-22 08:33:32 -06002473 double ret=-1.0;
akmhoqueb77b95f2013-02-08 12:28:47 -06002474 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2475 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2476
2477 struct clsa *cor_lsa;
2478 struct hashtb_enumerator ee;
2479 struct hashtb_enumerator *e = &ee;
2480 int res;
2481
2482 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2483 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2484
2485 if ( res == HT_OLD_ENTRY)
2486 {
2487 cor_lsa=e->data;
2488 ret=cor_lsa->cor_theta;
2489 }
2490 else if(res == HT_NEW_ENTRY)
2491 {
2492 hashtb_delete(e);
2493 }
2494
2495 hashtb_end(e);
2496
2497 free(cor_lsa_key);
2498 return ret;
2499}
akmhoquead584782013-02-22 10:56:03 -06002500
2501
2502void
2503destroy_name_lsdb(void)
2504{
2505 int i, name_lsdb_element;
2506 struct nlsa *name_lsa;
2507
2508 struct hashtb_enumerator ee;
2509 struct hashtb_enumerator *e = &ee;
2510
2511 hashtb_start(nlsr->lsdb->name_lsdb, e);
2512 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2513
2514 for(i=0;i<name_lsdb_element;i++)
2515 {
2516 name_lsa=e->data;
2517 destroy_name_lsa_component(name_lsa);
2518 hashtb_next(e);
2519 }
2520
2521 hashtb_end(e);
2522
2523 if ( nlsr->lsdb->name_lsdb )
2524 hashtb_destroy(&nlsr->lsdb->name_lsdb);
2525}
2526
2527void
2528destroy_adj_lsdb(void)
2529{
2530 int i, adj_lsdb_element;
2531 struct alsa *adj_lsa;
2532
2533 struct hashtb_enumerator ee;
2534 struct hashtb_enumerator *e = &ee;
2535
2536 hashtb_start(nlsr->lsdb->adj_lsdb, e);
2537 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
2538
2539 for(i=0;i<adj_lsdb_element;i++)
2540 {
2541 adj_lsa=e->data;
2542 destroy_adj_lsa_component(adj_lsa);
2543 hashtb_next(e);
2544 }
2545
2546 hashtb_end(e);
2547 if(nlsr->lsdb->adj_lsdb )
2548 hashtb_destroy(&nlsr->lsdb->adj_lsdb);
2549}
2550
2551void
2552destroy_cor_lsdb(void)
2553{
2554 int i, cor_lsdb_element;
2555 struct clsa *cor_lsa;
2556
2557 struct hashtb_enumerator ee;
2558 struct hashtb_enumerator *e = &ee;
2559
2560 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2561 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2562
2563 for(i=0;i<cor_lsdb_element;i++)
2564 {
2565 cor_lsa=e->data;
2566 destroy_cor_lsa_component(cor_lsa);
2567 hashtb_next(e);
2568 }
2569
2570 hashtb_end(e);
2571 if(nlsr->lsdb->cor_lsdb )
2572 hashtb_destroy(&nlsr->lsdb->cor_lsdb);
2573}
2574
2575void
2576destroy_lsdb(void)
2577{
2578 destroy_name_lsdb();
2579 destroy_adj_lsdb();
2580 destroy_cor_lsdb();
2581
2582 if ( nlsr->lsdb->lsdb_version )
2583 free(nlsr->lsdb->lsdb_version);
2584 if ( nlsr->lsdb )
2585 free(nlsr->lsdb);
2586}