blob: d08cb69628c87ae74014310c6c7f01e6439411b8 [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 )
akmhoqued91401d2013-03-04 11:05:27 -0600205 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas "
206 "called\n");
akmhoquef71d9082012-08-22 12:51:53 -0400207
akmhoquef71d9082012-08-22 12:51:53 -0400208 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600209 struct name_prefix_list_entry *npe;
akmhoquef71d9082012-08-22 12:51:53 -0400210
211 struct hashtb_enumerator ee;
212 struct hashtb_enumerator *e = &ee;
213
214 hashtb_start(nlsr->npl, e);
215 npl_element=hashtb_n(nlsr->npl);
216
217 for(i=0;i<npl_element;i++)
218 {
akmhoque3171d652012-11-13 11:44:33 -0600219 npe=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500220 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
akmhoque3171d652012-11-13 11:44:33 -0600221 build_name_lsa(name_lsa,npe->np);
akmhoque03004e62012-09-06 01:12:28 -0500222
akmhoquef71d9082012-08-22 12:51:53 -0400223 install_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600224 update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600225 destroy_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400226 hashtb_next(e);
227 }
228
akmhoque53f64222012-09-05 13:57:51 -0500229 hashtb_end(e);
akmhoque3171d652012-11-13 11:44:33 -0600230
231 print_name_prefix_from_npl();
232
233}
234
akmhoque0ab71642013-02-21 10:10:33 -0600235/**
236* Build and Install one Name LSA Use ful for API
237*/
238
akmhoque3171d652012-11-13 11:44:33 -0600239void
240build_and_install_single_name_lsa(struct name_prefix *np)
241{
242 if ( nlsr->debugging )
243 printf("build_and_install_single_name_lsa called \n");
244 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600245 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name"
246 "_lsa called\n");
akmhoque3171d652012-11-13 11:44:33 -0600247
248 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
249 build_name_lsa(name_lsa,np);
250
251 install_name_lsa(name_lsa);
252 update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600253 destroy_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600254 print_name_prefix_from_npl();
akmhoquef71d9082012-08-22 12:51:53 -0400255
akmhoquef71d9082012-08-22 12:51:53 -0400256}
257
akmhoque53f64222012-09-05 13:57:51 -0500258void
259build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
260{
akmhoque53f64222012-09-05 13:57:51 -0500261 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
262 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoqueeacf44f2013-02-22 01:02:13 -0600263
264 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500265 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500266 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
267 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500268
269 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500270
271 name_lsa->header->ls_id=++nlsr->nlsa_id;
akmhoqued91401d2013-03-04 11:05:27 -0600272 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,
273 sizeof(struct name_prefix ));
274 name_lsa->header->orig_router->name=(char *)calloc(
275 strlen(nlsr->router_name)+1,sizeof(char));
276 memcpy(name_lsa->header->orig_router->name,
277 nlsr->router_name,strlen(nlsr->router_name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500278 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500279 name_lsa->header->isValid=1;
280
281
282 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueeacf44f2013-02-22 01:02:13 -0600283 name_lsa->name_prefix->name=(char *)calloc(np->length,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -0500284 memcpy(name_lsa->name_prefix->name,np->name,np->length);
285 name_lsa->name_prefix->length=np->length;
286
287}
288
akmhoque53f64222012-09-05 13:57:51 -0500289void
290install_name_lsa(struct nlsa *name_lsa)
291{
akmhoque53f64222012-09-05 13:57:51 -0500292
akmhoque0ab71642013-02-21 10:10:33 -0600293 char lst[2];
294 memset(lst,0,2);
295 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoqueffacaa82012-09-13 17:48:30 -0500296
akmhoque0ab71642013-02-21 10:10:33 -0600297 char lsid[10];
298 memset(lsid,0,10);
299 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque3171d652012-11-13 11:44:33 -0600300
akmhoqued91401d2013-03-04 11:05:27 -0600301 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+
302 strlen(lst)+1+strlen(lsid)+1);
303 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)
304 +1+strlen(lsid)+1);
305 make_name_lsa_key(key, name_lsa->header->orig_router->name,
306 name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque53f64222012-09-05 13:57:51 -0500307
akmhoque0ab71642013-02-21 10:10:33 -0600308 if ( nlsr->debugging )
309 printf("Key:%s Length:%d\n",key,(int)strlen(key));
310 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600311 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,
312 (int)strlen(key));
akmhoque0ab71642013-02-21 10:10:33 -0600313
akmhoquef5537b42013-02-22 08:33:32 -0600314 struct nlsa *new_name_lsa;
akmhoque53f64222012-09-05 13:57:51 -0500315
akmhoque0ab71642013-02-21 10:10:33 -0600316 struct hashtb_enumerator ee;
317 struct hashtb_enumerator *e = &ee;
318 int res;
akmhoque53f64222012-09-05 13:57:51 -0500319
akmhoque0ab71642013-02-21 10:10:33 -0600320 hashtb_start(nlsr->lsdb->name_lsdb, e);
321 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500322
akmhoque0ab71642013-02-21 10:10:33 -0600323 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500324 {
akmhoqueffacaa82012-09-13 17:48:30 -0500325
akmhoquef5537b42013-02-22 08:33:32 -0600326 if ( name_lsa->header->isValid == 1 )
327 {
akmhoque7b791452012-10-30 11:24:56 -0500328 if ( nlsr->debugging )
329 printf("New Name LSA... Adding to LSDB\n");
330 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600331 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... "
332 "Adding to LSDB\n");
akmhoque7b791452012-10-30 11:24:56 -0500333
334
akmhoqueffacaa82012-09-13 17:48:30 -0500335 new_name_lsa = e->data;
akmhoque8876e982013-02-21 13:35:46 -0600336
akmhoque54d86112013-02-21 16:42:34 -0600337
akmhoqued91401d2013-03-04 11:05:27 -0600338 new_name_lsa->header=(struct nlsa_header *)calloc(1,
339 sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500340 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
341
akmhoqued91401d2013-03-04 11:05:27 -0600342 new_name_lsa->header->orig_time=(char *)calloc(
343 strlen(name_lsa->header->orig_time)+1,sizeof(char));
344 //memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
345 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,
346 strlen(name_lsa->header->orig_time)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500347
348 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoqued91401d2013-03-04 11:05:27 -0600349 new_name_lsa->header->orig_router=(struct name_prefix *)calloc(1,
350 sizeof(struct name_prefix ));
351 new_name_lsa->header->orig_router->name=(char *)calloc(
352 name_lsa->header->orig_router->length,sizeof(char));
353 memcpy(new_name_lsa->header->orig_router->name,
354 name_lsa->header->orig_router->name,
355 name_lsa->header->orig_router->length);
akmhoqueffacaa82012-09-13 17:48:30 -0500356 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
357 new_name_lsa->header->isValid=name_lsa->header->isValid;
358
359
akmhoqued91401d2013-03-04 11:05:27 -0600360 new_name_lsa->name_prefix=(struct name_prefix *)calloc(1,
361 sizeof(struct name_prefix ));
362 new_name_lsa->name_prefix->name=(char *)calloc(
363 name_lsa->name_prefix->length,sizeof(char));
364 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,
365 name_lsa->name_prefix->length);
akmhoqueffacaa82012-09-13 17:48:30 -0500366 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
akmhoque8876e982013-02-21 13:35:46 -0600367
akmhoqueffacaa82012-09-13 17:48:30 -0500368
akmhoque7b791452012-10-30 11:24:56 -0500369 if ( nlsr->debugging )
370 {
371 printf("New Name LSA Added....\n");
372 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
373 }
374 if ( nlsr->detailed_logging )
375 {
akmhoqued91401d2013-03-04 11:05:27 -0600376 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added.\n");
377 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of"
378 " LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque7b791452012-10-30 11:24:56 -0500379 }
akmhoque54d86112013-02-21 16:42:34 -0600380
akmhoqueffacaa82012-09-13 17:48:30 -0500381 set_new_lsdb_version();
akmhoque54d86112013-02-21 16:42:34 -0600382
akmhoque7b791452012-10-30 11:24:56 -0500383 if ( nlsr->debugging )
akmhoqued91401d2013-03-04 11:05:27 -0600384 printf("New Version Number of LSDB: %s \n",
385 nlsr->lsdb->lsdb_version);
akmhoque7b791452012-10-30 11:24:56 -0500386 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600387 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of"
388 " LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500389
akmhoque9e9fc722012-09-26 14:03:25 -0500390
akmhoqued91401d2013-03-04 11:05:27 -0600391 int num_next_hop=get_number_of_next_hop(
392 new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500393 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500394 {
akmhoqued91401d2013-03-04 11:05:27 -0600395 int check=add_npt_entry(new_name_lsa->header->orig_router->name,
396 new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL);
akmhoqueffacaa82012-09-13 17:48:30 -0500397 if ( check == HT_NEW_ENTRY )
398 {
akmhoque7b791452012-10-30 11:24:56 -0500399 if ( nlsr->debugging )
400 printf("Added in npt \n");
401 if ( nlsr->detailed_logging )
402 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500403 }
akmhoque3560cb62012-09-09 10:52:30 -0500404 }
akmhoqueffacaa82012-09-13 17:48:30 -0500405 else
akmhoque3560cb62012-09-09 10:52:30 -0500406 {
akmhoquede61ba92012-09-20 22:19:12 -0500407 int *faces=malloc(num_next_hop*sizeof(int));
408 int *route_costs=malloc(num_next_hop*sizeof(int));
akmhoqued91401d2013-03-04 11:05:27 -0600409 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name
410 ,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500411 if ( nlsr->debugging )
412 {
413 printf("Printing from install_name_lsa \n");
414 int j;
415 for(j=0;j<num_next_hop;j++)
416 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
417 }
418 if ( nlsr->detailed_logging )
419 {
akmhoqued91401d2013-03-04 11:05:27 -0600420 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from ins"
421 "tall_name_lsa \n");
akmhoque7b791452012-10-30 11:24:56 -0500422 int j;
423 for(j=0;j<num_next_hop;j++)
akmhoqued91401d2013-03-04 11:05:27 -0600424 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route"
425 " Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500426 }
akmhoqued91401d2013-03-04 11:05:27 -0600427 int check=add_npt_entry(new_name_lsa->header->orig_router->name,
428 new_name_lsa->name_prefix->name,next_hop,faces,route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500429 if ( check == HT_NEW_ENTRY )
430 {
akmhoque7b791452012-10-30 11:24:56 -0500431 if ( nlsr->debugging )
432 printf("Added in npt \n");
433 if ( nlsr->detailed_logging )
434 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500435 }
akmhoquede61ba92012-09-20 22:19:12 -0500436 free(faces);
437 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500438
akmhoque3560cb62012-09-09 10:52:30 -0500439 }
akmhoquede61ba92012-09-20 22:19:12 -0500440
akmhoque9e9fc722012-09-26 14:03:25 -0500441 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
442 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
akmhoquef5537b42013-02-22 08:33:32 -0600443 write_log_for_name_lsa(new_name_lsa);
akmhoque9e9fc722012-09-26 14:03:25 -0500444 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500445
akmhoque54d86112013-02-21 16:42:34 -0600446 //free(time_stamp);
akmhoquef5537b42013-02-22 08:33:32 -0600447 }
448 else
449 {
450 hashtb_delete(e);
451 }
akmhoqueffacaa82012-09-13 17:48:30 -0500452
453 }
454 else if(res == HT_OLD_ENTRY)
455 {
456 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500457 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500458 {
akmhoque7b791452012-10-30 11:24:56 -0500459 if ( nlsr->debugging )
460 printf("Older Adj LSA. Discarded... \n");
461 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600462 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Di"
463 "scarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500464 }
akmhoqued91401d2013-03-04 11:05:27 -0600465 else if( strcmp(name_lsa->header->orig_time,
466 new_name_lsa->header->orig_time) == 0 )
akmhoque14b3f342012-09-14 10:39:02 -0500467 {
akmhoque7b791452012-10-30 11:24:56 -0500468 if ( nlsr->debugging )
469 printf("Duplicate Adj LSA. Discarded... \n");
470 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600471 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA."
472 " Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500473 }
474 else
475 {
476 if ( name_lsa->header->isValid == 0 )
477 {
478 // have to call to delete npt table entry
akmhoqued91401d2013-03-04 11:05:27 -0600479 delete_npt_entry_by_router_and_name_prefix(
480 new_name_lsa->header->orig_router->name,
481 new_name_lsa->name_prefix->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500482
483 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
484 {
akmhoque9e9fc722012-09-26 14:03:25 -0500485 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
akmhoqued91401d2013-03-04 11:05:27 -0600486 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name"
487 " lsa\n");
akmhoque9e9fc722012-09-26 14:03:25 -0500488 write_log_for_name_lsa(new_name_lsa);
akmhoqued91401d2013-03-04 11:05:27 -0600489 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end"
490 "\n");
akmhoque9e9fc722012-09-26 14:03:25 -0500491
akmhoqueffacaa82012-09-13 17:48:30 -0500492 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500493 if ( nlsr->debugging )
akmhoqued91401d2013-03-04 11:05:27 -0600494 printf("isValid bit not set for Router %s so LSA De"
495 "leted from LSDB\n",
496 name_lsa->header->orig_router->name);
akmhoque7b791452012-10-30 11:24:56 -0500497 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600498 writeLogg(__FILE__,__FUNCTION__,__LINE__,"isValid b"
499 "it not set for Router %s so LSA Deleted from LSDB\n"
500 ,name_lsa->header->orig_router->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500501 }
502 else
503 {
504 new_name_lsa->header->isValid=name_lsa->header->isValid;
505 free(new_name_lsa->header->orig_time);
506 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
507 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
508 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
509 }
akmhoque7b791452012-10-30 11:24:56 -0500510 if ( nlsr->debugging )
511 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
512 if ( nlsr->detailed_logging )
513 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500514 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500515 if ( nlsr->debugging )
516 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
517 if ( nlsr->detailed_logging )
518 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500519 }
520 else
521 {
522 int is_npt_update=0;
523 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
524 {
525 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500526 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 -0500527 }
528
529 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500530 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
531 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
532 write_log_for_name_lsa(new_name_lsa);
533 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
534
akmhoqueffacaa82012-09-13 17:48:30 -0500535
536 free(new_name_lsa->header->orig_time);
537 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
538 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600539 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500540
541 new_name_lsa->header->isValid=name_lsa->header->isValid;
542
543 free(new_name_lsa->name_prefix->name);
544 free(new_name_lsa->name_prefix);
545 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
546 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
547 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
548 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
549
akmhoque9e9fc722012-09-26 14:03:25 -0500550
551 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
552 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
553 write_log_for_name_lsa(new_name_lsa);
554 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
555
akmhoque7b791452012-10-30 11:24:56 -0500556 if ( nlsr->debugging )
557 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
558 if ( nlsr->detailed_logging )
559 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
560
akmhoqueffacaa82012-09-13 17:48:30 -0500561 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500562
563 if ( nlsr->debugging )
564 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
565 if ( nlsr->detailed_logging )
566 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
567
akmhoqueffacaa82012-09-13 17:48:30 -0500568
569 if( is_npt_update == 1 )
570 {
akmhoquede61ba92012-09-20 22:19:12 -0500571 //struct hashtb *face_list;
572 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
573 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500574 {
akmhoquede61ba92012-09-20 22:19:12 -0500575
576 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 -0500577 if ( check == HT_NEW_ENTRY )
578 {
akmhoque7b791452012-10-30 11:24:56 -0500579 if ( nlsr->debugging )
580 printf("Added in npt \n");
581 if ( nlsr->detailed_logging )
582 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500583 }
584 }
585 else
586 {
akmhoquede61ba92012-09-20 22:19:12 -0500587 int *faces=malloc(num_next_hop*sizeof(int));
588 int *route_costs=malloc(num_next_hop*sizeof(int));
589 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500590
591 if ( nlsr->debugging )
592 {
593 printf("Printing from install_name_lsa \n");
594 int j;
595 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500596 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500597 }
598 if ( nlsr->detailed_logging )
599 {
600 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
601 int j;
602 for(j=0;j<num_next_hop;j++)
603 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
604 }
605
akmhoquede61ba92012-09-20 22:19:12 -0500606
607 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 -0500608 if ( check == HT_NEW_ENTRY )
609 {
akmhoque7b791452012-10-30 11:24:56 -0500610 if ( nlsr->debugging )
611 printf("Added in npt \n");
612 if ( nlsr->detailed_logging )
613 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500614 }
akmhoquede61ba92012-09-20 22:19:12 -0500615 free(faces);
616 free(route_costs);
617
akmhoqueffacaa82012-09-13 17:48:30 -0500618 }
akmhoquede61ba92012-09-20 22:19:12 -0500619
akmhoqueffacaa82012-09-13 17:48:30 -0500620 }
621 }
622 }
623
akmhoque3560cb62012-09-09 10:52:30 -0500624 }
akmhoque53f64222012-09-05 13:57:51 -0500625
akmhoqueffacaa82012-09-13 17:48:30 -0500626 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500627
akmhoquef5537b42013-02-22 08:33:32 -0600628 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500629}
630
akmhoque9e9fc722012-09-26 14:03:25 -0500631void
632write_log_for_name_lsa(struct nlsa *name_lsa)
633{
634
635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
636 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
637 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500638 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
639 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
640 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
641 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500642 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
643 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
644 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
645 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
646}
akmhoque53f64222012-09-05 13:57:51 -0500647
akmhoque03004e62012-09-06 01:12:28 -0500648void
649print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500650{
akmhoque53f64222012-09-05 13:57:51 -0500651
akmhoque7b791452012-10-30 11:24:56 -0500652 if ( nlsr->debugging )
653 {
654 printf("-----------Name LSA Content---------------\n");
655 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
656 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
657 printf(" LS Type : %d\n",name_lsa->header->ls_type);
658 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
659 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
660 printf(" Is Valid : %d\n",name_lsa->header->isValid);
661 printf(" LSA Data \n");
662 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
663 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
664
665 printf("\n");
666 }
akmhoquef71d9082012-08-22 12:51:53 -0400667}
668
669void
670print_name_lsdb(void)
671{
akmhoque7b791452012-10-30 11:24:56 -0500672 if ( nlsr->debugging )
673 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500674 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400675 struct nlsa *name_lsa;
676
677 struct hashtb_enumerator ee;
678 struct hashtb_enumerator *e = &ee;
679
680 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500681 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400682
akmhoque53f64222012-09-05 13:57:51 -0500683 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400684 {
akmhoque7b791452012-10-30 11:24:56 -0500685 if ( nlsr->debugging )
686 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400687 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500688 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400689 hashtb_next(e);
690 }
691
692 hashtb_end(e);
693
akmhoque3171d652012-11-13 11:44:33 -0600694 if ( nlsr->debugging )
695 printf("\n");
696 if ( nlsr->detailed_logging )
697 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500698}
699
akmhoque03004e62012-09-06 01:12:28 -0500700
701void
702build_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 -0500703{
akmhoque7b791452012-10-30 11:24:56 -0500704 if ( nlsr->debugging )
705 printf("build_and_install_others_name_lsa called \n");
706 if ( nlsr->detailed_logging )
707 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500708
akmhoque03004e62012-09-06 01:12:28 -0500709 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
710 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
711 print_name_lsa(name_lsa);
712 install_name_lsa(name_lsa);
713 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500714 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500715
akmhoquef5537b42013-02-22 08:33:32 -0600716 destroy_name_lsa(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500717
718}
719
720void
akmhoque03004e62012-09-06 01:12:28 -0500721build_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 -0500722{
akmhoque7b791452012-10-30 11:24:56 -0500723 if ( nlsr->debugging )
724 printf("build_others_name_lsa called\n");
725 if ( nlsr->detailed_logging )
726 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500727
akmhoquef5537b42013-02-22 08:33:32 -0600728 name_lsa->header=(struct nlsa_header *)calloc(1,sizeof(struct nlsa_header ));
akmhoque03004e62012-09-06 01:12:28 -0500729 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500730
akmhoquef5537b42013-02-22 08:33:32 -0600731 name_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
732 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500733
akmhoque03004e62012-09-06 01:12:28 -0500734 name_lsa->header->ls_id=ls_id;
akmhoquef5537b42013-02-22 08:33:32 -0600735 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
736 name_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
737 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque03004e62012-09-06 01:12:28 -0500738 name_lsa->header->orig_router->length=strlen(orig_router)+1;
739 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500740
akmhoquef5537b42013-02-22 08:33:32 -0600741 name_lsa->name_prefix=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
742 name_lsa->name_prefix->name=(char *)calloc(strlen(np)+1,sizeof(char));
743 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
akmhoque03004e62012-09-06 01:12:28 -0500744 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400745}
akmhoqued79438d2012-08-27 13:31:42 -0500746
747
akmhoqueb77b95f2013-02-08 12:28:47 -0600748void
749make_cor_lsa_key(char *key,struct clsa *cor_lsa)
750{
751 memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
752 memcpy(key+strlen(key),"/",1);
753 char ls_type[2];
754 sprintf(ls_type,"%d",cor_lsa->header->ls_type);
755 memcpy(key+strlen(key),ls_type,strlen(ls_type));
756 key[strlen(key)]='\0';
757}
akmhoqueffacaa82012-09-13 17:48:30 -0500758
759
akmhoque53f64222012-09-05 13:57:51 -0500760void
761make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500762{
akmhoque53f64222012-09-05 13:57:51 -0500763 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
764 memcpy(key+strlen(key),"/",1);
765 char ls_type[2];
766 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
767 memcpy(key+strlen(key),ls_type,strlen(ls_type));
768 key[strlen(key)]='\0';
769}
770
akmhoque03004e62012-09-06 01:12:28 -0500771int
772build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
773{
akmhoqueffacaa82012-09-13 17:48:30 -0500774 if(flags == CCN_SCHEDULE_CANCEL)
775 {
776 return -1;
777 }
778
779 nlsr_lock();
780
akmhoque7b791452012-10-30 11:24:56 -0500781 if ( nlsr->debugging )
782 printf("build_and_install_adj_lsa called \n");
783 if ( nlsr->detailed_logging )
784 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
785
786 if ( nlsr->debugging )
787 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
788 if ( nlsr->detailed_logging )
789 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500790
791 if(nlsr->adj_build_flag > 0)
792 {
akmhoque7b791452012-10-30 11:24:56 -0500793 if ( nlsr->debugging )
794 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
795 if ( nlsr->detailed_logging )
796 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
797
akmhoque03004e62012-09-06 01:12:28 -0500798 if ( is_adj_lsa_build()> 0)
799 {
800 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
801 build_adj_lsa(adj_lsa);
802 install_adj_lsa(adj_lsa);
803
akmhoqueb77b95f2013-02-08 12:28:47 -0600804 char lst[2];
805 memset(lst,0,2);
806 sprintf(lst,"%d",LS_TYPE_ADJ);
807
akmhoquef5537b42013-02-22 08:33:32 -0600808 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));
809 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 -0600810
811 if ( nlsr->debugging )
812 printf("Adj LSA Repo Key: %s \n",repo_key);
813
akmhoquef5537b42013-02-22 08:33:32 -0600814 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -0600815 make_adj_lsa_key(key,adj_lsa);
816 if ( nlsr->debugging )
817 printf("Adj LSA: %s \n",key);
818
akmhoquef5537b42013-02-22 08:33:32 -0600819 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
820 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
821 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600822 lsaid->length=strlen(key)+1;
823
824
825 write_adj_lsa_to_repo(repo_key, lsaid);
826
akmhoquef5537b42013-02-22 08:33:32 -0600827 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600828 free(repo_key);
829 free(lsaid->name);
830 free(lsaid);
831
akmhoquef5537b42013-02-22 08:33:32 -0600832 destroy_adj_lsa(adj_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -0600833
akmhoque03004e62012-09-06 01:12:28 -0500834 nlsr->adj_build_flag=0;
835 print_adj_lsdb();
836 }
837 else
838 {
akmhoque7b791452012-10-30 11:24:56 -0500839 if ( nlsr->debugging )
840 printf("Can not build adj LSA now\n");
841 if ( nlsr->detailed_logging )
842 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500843 }
844 }
845 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500846
847 nlsr_unlock();
848
akmhoque03004e62012-09-06 01:12:28 -0500849 return 0;
850}
851
852
853void
854build_adj_lsa(struct alsa * adj_lsa)
855{
akmhoque7b791452012-10-30 11:24:56 -0500856 if ( nlsr->debugging )
857 printf("build_adj_lsa called \n");
858 if ( nlsr->detailed_logging )
859 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500860
861 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500862
akmhoque03004e62012-09-06 01:12:28 -0500863 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
864 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
865 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
866 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
867 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
868 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
869
870 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
871
akmhoque03004e62012-09-06 01:12:28 -0500872
akmhoquef5537b42013-02-22 08:33:32 -0600873 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500874 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
875 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
876 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
877 free(time_stamp);
878
akmhoque03004e62012-09-06 01:12:28 -0500879 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500880
881
882 struct ccn_charbuf *c=ccn_charbuf_create();
883 get_active_nbr_adj_data(c);
884 char *data=ccn_charbuf_as_string(c);
885
akmhoquef5537b42013-02-22 08:33:32 -0600886 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
887 //memset(adj_lsa->body,0,strlen(data)+1);
akmhoque03004e62012-09-06 01:12:28 -0500888 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoquef5537b42013-02-22 08:33:32 -0600889 data[strlen(data)]='\0';
akmhoque03004e62012-09-06 01:12:28 -0500890 ccn_charbuf_destroy(&c);
891
akmhoque03004e62012-09-06 01:12:28 -0500892 nlsr->adj_build_count++;
893
894
895}
896
897
akmhoque53f64222012-09-05 13:57:51 -0500898void
899install_adj_lsa(struct alsa * adj_lsa)
900{
akmhoqued79438d2012-08-27 13:31:42 -0500901
akmhoque7b791452012-10-30 11:24:56 -0500902 if ( nlsr->debugging )
903 printf("install_adj_lsa called \n");
904 if ( nlsr->detailed_logging )
905 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
906
akmhoque03004e62012-09-06 01:12:28 -0500907
akmhoque53f64222012-09-05 13:57:51 -0500908
akmhoqueffacaa82012-09-13 17:48:30 -0500909
akmhoquef5537b42013-02-22 08:33:32 -0600910 char *key=(char *)calloc(adj_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueffacaa82012-09-13 17:48:30 -0500911 make_adj_lsa_key(key,adj_lsa);
akmhoqueffacaa82012-09-13 17:48:30 -0500912
akmhoque8876e982013-02-21 13:35:46 -0600913 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500914
915 struct hashtb_enumerator ee;
916 struct hashtb_enumerator *e = &ee;
917 int res;
918
919 hashtb_start(nlsr->lsdb->adj_lsdb, e);
920 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500921
akmhoque03004e62012-09-06 01:12:28 -0500922
akmhoque53f64222012-09-05 13:57:51 -0500923
akmhoque62c0c192012-09-24 07:49:25 -0500924 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500925 {
akmhoque62c0c192012-09-24 07:49:25 -0500926 if ( adj_lsa->no_link > 0)
927 {
akmhoque3171d652012-11-13 11:44:33 -0600928 if ( nlsr->debugging )
929 printf("New ADJ LSA... Adding to LSDB\n");
930 if ( nlsr->detailed_logging )
931 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
akmhoque62c0c192012-09-24 07:49:25 -0500932 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500933
akmhoquef5537b42013-02-22 08:33:32 -0600934 new_adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
akmhoque62c0c192012-09-24 07:49:25 -0500935 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
akmhoquef5537b42013-02-22 08:33:32 -0600936 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500937 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 -0500938
akmhoquef5537b42013-02-22 08:33:32 -0600939 new_adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
940 new_adj_lsa->header->orig_router->name=(char *)calloc(adj_lsa->header->orig_router->length,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500941 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
942 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500943
akmhoque62c0c192012-09-24 07:49:25 -0500944 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500945
akmhoque0b60ba92013-02-25 17:55:35 -0600946 //if(new_adj_lsa->body )
947 //free(new_adj_lsa->body);
akmhoquef5537b42013-02-22 08:33:32 -0600948 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
949 //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -0500950 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
951
952 add_next_hop_router(new_adj_lsa->header->orig_router->name);
953 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500954
955 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
956 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
957 write_log_for_adj_lsa(new_adj_lsa);
958 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500959 }
960 else
961 {
962 hashtb_delete(e);
963 }
akmhoque53f64222012-09-05 13:57:51 -0500964
akmhoque7b791452012-10-30 11:24:56 -0500965 if ( nlsr->debugging )
966 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
967 if ( nlsr->detailed_logging )
968 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
969
akmhoque53f64222012-09-05 13:57:51 -0500970 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500971
972 if ( nlsr->debugging )
973 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
974 if ( nlsr->detailed_logging )
975 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
976
akmhoqueffacaa82012-09-13 17:48:30 -0500977 }
978 else if(res == HT_OLD_ENTRY)
979 {
980 new_adj_lsa = e->data;
981 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
982 {
akmhoque7b791452012-10-30 11:24:56 -0500983 if ( nlsr->debugging )
984 printf("Older/Duplicate Adj LSA. Discarded...\n");
985 if ( nlsr->detailed_logging )
986 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500987 }
988 else
989 {
akmhoqueffacaa82012-09-13 17:48:30 -0500990
akmhoque62c0c192012-09-24 07:49:25 -0500991 if ( adj_lsa->no_link > 0)
992 {
akmhoque9e9fc722012-09-26 14:03:25 -0500993 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
994 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
995 write_log_for_adj_lsa(new_adj_lsa);
996 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500997
akmhoque62c0c192012-09-24 07:49:25 -0500998 free(new_adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -0600999 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -05001000 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
1001
1002 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -05001003
akmhoquef5537b42013-02-22 08:33:32 -06001004 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
1005 //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -05001006 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -05001007
akmhoque62c0c192012-09-24 07:49:25 -05001008 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001009
1010 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1011 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1012 write_log_for_adj_lsa(new_adj_lsa);
1013 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -05001014 }
1015 else
1016 {
akmhoque9e9fc722012-09-26 14:03:25 -05001017 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1018 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1019 write_log_for_adj_lsa(new_adj_lsa);
1020 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1021
akmhoque62c0c192012-09-24 07:49:25 -05001022 hashtb_delete(e);
1023 }
akmhoque7b791452012-10-30 11:24:56 -05001024
1025 if ( nlsr->debugging )
1026 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1027 if ( nlsr->detailed_logging )
1028 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1029
akmhoqueffacaa82012-09-13 17:48:30 -05001030 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001031
1032 if ( nlsr->debugging )
1033 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1034 if ( nlsr->detailed_logging )
1035 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -05001036 }
1037
1038 }
1039 hashtb_end(e);
1040
1041 if ( !nlsr->is_route_calculation_scheduled )
1042 {
1043 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1044 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -05001045 }
1046
akmhoque03004e62012-09-06 01:12:28 -05001047
akmhoquef5537b42013-02-22 08:33:32 -06001048 free(key);
akmhoqueffacaa82012-09-13 17:48:30 -05001049
akmhoquef5537b42013-02-22 08:33:32 -06001050 //free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -05001051}
1052
1053void
akmhoque9e9fc722012-09-26 14:03:25 -05001054write_log_for_adj_lsa_body(const char *body, int no_link)
1055{
1056 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001057 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1058 //memset( lsa_data,0,strlen(body)+1);
akmhoque9e9fc722012-09-26 14:03:25 -05001059 memcpy(lsa_data,body,strlen(body)+1);
1060 char *sep="|";
1061 char *rem;
1062 char *rtr_id;
1063 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001064 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -05001065 char *metric;
1066
1067 if(no_link >0 )
1068 {
1069 rtr_id=strtok_r(lsa_data,sep,&rem);
1070 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001071 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001072 metric=strtok_r(NULL,sep,&rem);
1073
1074 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001075 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1076 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001077 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001078 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001079
1080
1081 for(i=1;i<no_link;i++)
1082 {
1083 rtr_id=strtok_r(NULL,sep,&rem);
1084 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001085 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001086 metric=strtok_r(NULL,sep,&rem);
1087 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001088 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1089 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001090 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001091 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001092
1093 }
1094 }
1095
akmhoquef5537b42013-02-22 08:33:32 -06001096 if(lsa_data)
1097 free(lsa_data);
akmhoque9e9fc722012-09-26 14:03:25 -05001098}
1099
1100
1101void
1102write_log_for_adj_lsa(struct alsa * adj_lsa)
1103{
1104 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001105 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1106 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1107 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1108 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001109 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001110 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001111
1112 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1113
1114 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1115
1116}
1117
1118void
akmhoque53f64222012-09-05 13:57:51 -05001119print_adj_lsa_body(const char *body, int no_link)
1120{
1121 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001122 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1123 //memset( lsa_data,0,strlen(body)+1);
akmhoque53f64222012-09-05 13:57:51 -05001124 memcpy(lsa_data,body,strlen(body)+1);
1125 char *sep="|";
1126 char *rem;
1127 char *rtr_id;
1128 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001129 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001130 char *metric;
1131
akmhoque53f64222012-09-05 13:57:51 -05001132 if(no_link >0 )
1133 {
1134 rtr_id=strtok_r(lsa_data,sep,&rem);
1135 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001136 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001137 metric=strtok_r(NULL,sep,&rem);
1138
akmhoqueb77b95f2013-02-08 12:28:47 -06001139 if ( nlsr->debugging ) {
1140 printf(" Link %d \n",i+1);
1141 printf(" Neighbor : %s \n",rtr_id);
1142 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001143 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001144 printf(" Metric : %s \n",metric);
1145 }
akmhoque53f64222012-09-05 13:57:51 -05001146
1147 for(i=1;i<no_link;i++)
1148 {
1149 rtr_id=strtok_r(NULL,sep,&rem);
1150 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001151 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001152 metric=strtok_r(NULL,sep,&rem);
1153 printf(" Link %d \n",i+1);
1154 printf(" Neighbor : %s \n",rtr_id);
1155 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001156 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001157 printf(" Metric : %s \n",metric);
1158
1159 }
1160 }
1161
akmhoquef5537b42013-02-22 08:33:32 -06001162 if( lsa_data )
1163 free(lsa_data);
akmhoque53f64222012-09-05 13:57:51 -05001164}
1165
1166void
1167print_adj_lsa(struct alsa * adj_lsa)
1168{
akmhoque7b791452012-10-30 11:24:56 -05001169 if ( nlsr->debugging )
1170 {
1171 printf("-----------ADJ LSA Content---------------\n");
1172 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1173 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1174 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1175 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1176 printf(" Lsa Data:\n");
1177 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001178
akmhoque7b791452012-10-30 11:24:56 -05001179 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1180 printf("\n");
1181 }
akmhoque53f64222012-09-05 13:57:51 -05001182
1183}
1184
1185void
1186print_adj_lsdb(void)
1187{
akmhoque7b791452012-10-30 11:24:56 -05001188 if ( nlsr->debugging )
1189 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001190 int i, adj_lsdb_element;
1191 struct alsa *adj_lsa;
1192
1193 struct hashtb_enumerator ee;
1194 struct hashtb_enumerator *e = &ee;
1195
1196 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1197 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1198
1199 for(i=0;i<adj_lsdb_element;i++)
1200 {
akmhoque7b791452012-10-30 11:24:56 -05001201 if ( nlsr->debugging )
1202 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001203 adj_lsa=e->data;
1204 print_adj_lsa(adj_lsa);
1205 hashtb_next(e);
1206 }
1207
1208 hashtb_end(e);
1209
akmhoque3171d652012-11-13 11:44:33 -06001210 if ( nlsr->debugging )
1211 printf("\n");
1212 if ( nlsr->detailed_logging )
1213 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001214}
1215
1216void
akmhoque03004e62012-09-06 01:12:28 -05001217build_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 -05001218{
akmhoque7b791452012-10-30 11:24:56 -05001219 if ( nlsr->debugging )
1220 printf("build_and_install_others_adj_lsa called \n");
1221 if ( nlsr->detailed_logging )
1222 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001223 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1224 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001225 install_adj_lsa(adj_lsa);
1226
akmhoquef5537b42013-02-22 08:33:32 -06001227 destroy_adj_lsa(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001228
akmhoque03004e62012-09-06 01:12:28 -05001229 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001230
akmhoque53f64222012-09-05 13:57:51 -05001231}
1232
akmhoque03004e62012-09-06 01:12:28 -05001233
akmhoque53f64222012-09-05 13:57:51 -05001234void
akmhoque03004e62012-09-06 01:12:28 -05001235build_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 -05001236{
akmhoque7b791452012-10-30 11:24:56 -05001237 if ( nlsr->debugging )
1238 printf("build_others_adj_lsa called \n");
1239 if ( nlsr->detailed_logging )
1240 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001241
akmhoque03004e62012-09-06 01:12:28 -05001242 /*Filling Up Header Data */
akmhoquef5537b42013-02-22 08:33:32 -06001243 adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
1244 adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
1245 adj_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001246 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001247
akmhoque03004e62012-09-06 01:12:28 -05001248 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001249
akmhoque53f64222012-09-05 13:57:51 -05001250
akmhoque03004e62012-09-06 01:12:28 -05001251 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001252
akmhoquef5537b42013-02-22 08:33:32 -06001253 adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001254 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001255
akmhoque03004e62012-09-06 01:12:28 -05001256 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001257
akmhoquef5537b42013-02-22 08:33:32 -06001258 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001259 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001260
akmhoque53f64222012-09-05 13:57:51 -05001261}
1262
akmhoque03004e62012-09-06 01:12:28 -05001263
akmhoque53f64222012-09-05 13:57:51 -05001264long int
1265get_name_lsdb_num_element(void)
1266{
1267 long int num_element;
1268
1269
1270 struct hashtb_enumerator ee;
1271 struct hashtb_enumerator *e = &ee;
1272
1273 hashtb_start(nlsr->lsdb->name_lsdb, e);
1274 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1275 hashtb_end(e);
1276
1277 return num_element;
1278}
1279
1280long int
1281get_adj_lsdb_num_element(void)
1282{
1283 long int num_element;
1284
1285
1286 struct hashtb_enumerator ee;
1287 struct hashtb_enumerator *e = &ee;
1288
1289 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1290 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1291 hashtb_end(e);
1292
1293 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001294}
akmhoque03004e62012-09-06 01:12:28 -05001295
akmhoque03004e62012-09-06 01:12:28 -05001296
1297int
1298check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1299{
1300 int ret=0;
1301 struct ccn_charbuf *key=ccn_charbuf_create();
1302 ccn_charbuf_append_string(key,orig_router);
1303 ccn_charbuf_append_string(key,"/");
1304 ccn_charbuf_append_string(key,lst);
1305 ccn_charbuf_append_string(key,"/");
1306 ccn_charbuf_append_string(key,lsid);
1307
1308 int res;
1309 struct nlsa *name_lsa;
1310
1311 struct hashtb_enumerator ee;
1312 struct hashtb_enumerator *e = &ee;
1313
1314 hashtb_start(nlsr->lsdb->name_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 name_lsa=e->data;
1326 if( strcmp ( orig_time , name_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
1339int
1340check_is_new_adj_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 alsa *adj_lsa;
1350
1351 struct hashtb_enumerator ee;
1352 struct hashtb_enumerator *e = &ee;
1353
1354 hashtb_start(nlsr->lsdb->adj_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 adj_lsa=e->data;
1366 if( strcmp ( orig_time , adj_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
akmhoqueb77b95f2013-02-08 12:28:47 -06001379int
1380check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1381{
1382 int ret=0;
1383 struct ccn_charbuf *key=ccn_charbuf_create();
1384 ccn_charbuf_append_string(key,orig_router);
1385 ccn_charbuf_append_string(key,"/");
1386 ccn_charbuf_append_string(key,lst);
1387
1388 int res;
1389 struct clsa *cor_lsa;
1390
1391 struct hashtb_enumerator ee;
1392 struct hashtb_enumerator *e = &ee;
1393
1394 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1395 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1396
1397 if( res == HT_NEW_ENTRY )
1398 {
1399 hashtb_delete(e);
1400 ret=1;
1401
1402 }
1403 else if(res == HT_OLD_ENTRY)
1404 {
1405 cor_lsa=e->data;
1406 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1407 {
1408 ret=1;
1409 }
1410 }
1411
1412 hashtb_end(e);
1413
1414 ccn_charbuf_destroy(&key);
1415
1416 return ret;
1417}
1418
akmhoque03004e62012-09-06 01:12:28 -05001419void
1420get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1421{
akmhoque7b791452012-10-30 11:24:56 -05001422 if ( nlsr->debugging )
1423 printf("get_name_lsa_data called \n");
1424 if ( nlsr->detailed_logging )
1425 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001426
akmhoque8876e982013-02-21 13:35:46 -06001427 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001428
1429 struct hashtb_enumerator ee;
1430 struct hashtb_enumerator *e = &ee;
1431 int res;
1432
1433 hashtb_start(nlsr->lsdb->name_lsdb, e);
1434 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1435
1436 if( res == HT_OLD_ENTRY )
1437 {
1438 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001439
akmhoque7b791452012-10-30 11:24:56 -05001440 if ( nlsr->debugging )
1441 printf("NAME LSA found \n");
1442 if ( nlsr->detailed_logging )
1443 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001444
1445 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1446 ccn_charbuf_append_string(lsa_data,"|");
1447
1448 char *temp_length=(char *)malloc(20);
1449 memset(temp_length,0,20);
1450 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1451 ccn_charbuf_append_string(lsa_data,temp_length);
1452 free(temp_length);
1453 ccn_charbuf_append_string(lsa_data,"|");
1454
1455 char *temp_ltype=(char *)malloc(20);
1456 memset(temp_ltype,0,20);
1457 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1458 ccn_charbuf_append_string(lsa_data,temp_ltype);
1459 free(temp_ltype);
1460 ccn_charbuf_append_string(lsa_data,"|");
1461
1462 char *temp_lsid=(char *)malloc(20);
1463 memset(temp_lsid,0,20);
1464 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1465 ccn_charbuf_append_string(lsa_data,temp_lsid);
1466 free(temp_lsid);
1467 ccn_charbuf_append_string(lsa_data,"|");
1468
1469 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1470 ccn_charbuf_append_string(lsa_data,"|");
1471
1472 char *temp_valid=(char *)malloc(20);
1473 memset(temp_valid,0,20);
1474 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1475 ccn_charbuf_append_string(lsa_data,temp_valid);
1476 free(temp_valid);
1477 ccn_charbuf_append_string(lsa_data,"|");
1478
1479 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1480 ccn_charbuf_append_string(lsa_data,"|");
1481
1482 char *temp_npl=(char *)malloc(20);
1483 memset(temp_npl,0,20);
1484 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1485 ccn_charbuf_append_string(lsa_data,temp_npl);
1486 free(temp_npl);
1487 ccn_charbuf_append_string(lsa_data,"|");
1488
1489 }
1490 else if(res == HT_NEW_ENTRY)
1491 {
1492 hashtb_delete(e);
1493 }
1494
1495 hashtb_end(e);
1496}
1497
1498void
1499get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1500{
akmhoque7b791452012-10-30 11:24:56 -05001501 if ( nlsr->debugging )
1502 printf("get_adj_lsa_data called \n");
1503 if ( nlsr->detailed_logging )
1504 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001505
akmhoquececba942013-02-25 17:33:34 -06001506 struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoque03004e62012-09-06 01:12:28 -05001507
1508 struct hashtb_enumerator ee;
1509 struct hashtb_enumerator *e = &ee;
1510 int res;
1511
1512 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1513 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1514
1515 if( res == HT_OLD_ENTRY )
1516 {
1517 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001518
1519 if ( nlsr->debugging )
1520 printf("Adj LSA found \n");
1521 if ( nlsr->detailed_logging )
1522 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001523
1524 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1525 ccn_charbuf_append_string(lsa_data,"|");
1526
1527 char *temp_length=(char *)malloc(20);
1528 memset(temp_length,0,20);
1529 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1530 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001531 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001532 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001533
1534 char *temp_ltype=(char *)malloc(20);
1535 memset(temp_ltype,0,20);
1536 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1537 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001538 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001539 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001540
1541 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1542 ccn_charbuf_append_string(lsa_data,"|");
1543
1544 char *temp_nl=(char *)malloc(20);
1545 memset(temp_nl,0,20);
1546 sprintf(temp_nl,"%d",adj_lsa->no_link);
1547 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001548 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001549 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001550
1551 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1552
1553
1554 }
1555 else if(res == HT_NEW_ENTRY)
1556 {
1557 hashtb_delete(e);
1558 }
1559
1560 hashtb_end(e);
1561}
akmhoqueffacaa82012-09-13 17:48:30 -05001562
akmhoque3171d652012-11-13 11:44:33 -06001563void
1564make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1565{
1566
1567 if ( nlsr->debugging )
1568 printf("make_name_lsa_invalid called \n");
1569 if ( nlsr->detailed_logging )
1570 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1571
1572
1573 char lst[2];
1574 memset(lst,0,2);
1575 sprintf(lst,"%d",ls_type);
1576
1577 char lsid[10];
1578 memset(lsid,0,10);
1579 sprintf(lsid,"%ld",ls_id);
1580
1581
1582 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1583 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1584
1585
1586 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001587
1588 if ( nlsr->debugging )
1589 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001590
1591 struct nlsa *nlsa;
1592
1593 struct hashtb_enumerator ee;
1594 struct hashtb_enumerator *e = &ee;
1595
1596 int res;
1597
1598 hashtb_start(nlsr->lsdb->name_lsdb, e);
1599 res = hashtb_seek(e, key,strlen(key) , 0);
1600
1601 if( res == HT_OLD_ENTRY )
1602 {
1603 nlsa=e->data;
1604
1605 nlsa->header->isValid=0;
1606
1607 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1608 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1609 write_log_for_name_lsa(nlsa);
1610 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1611
1612 hashtb_delete(e);
1613 }
1614 else if( res == HT_NEW_ENTRY )
1615 {
1616 hashtb_delete(e);
1617 }
1618 hashtb_end(e);
1619
1620 if ( nlsr->debugging )
1621 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1622 if ( nlsr->detailed_logging )
1623 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1624
1625 set_new_lsdb_version();
1626
1627 if ( nlsr->debugging )
1628 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1629 if ( nlsr->detailed_logging )
1630 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1631
1632}
1633
akmhoquef5537b42013-02-22 08:33:32 -06001634
akmhoque866c2222013-02-12 10:49:33 -06001635int
1636delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001637{
akmhoqueb77b95f2013-02-08 12:28:47 -06001638
akmhoque7b791452012-10-30 11:24:56 -05001639 if ( nlsr->debugging )
1640 printf("delete_name_lsa called \n");
1641 if ( nlsr->detailed_logging )
1642 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001643
akmhoque866c2222013-02-12 10:49:33 -06001644 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -06001645
akmhoqueda5b6832012-09-13 22:33:55 -05001646
akmhoque7b791452012-10-30 11:24:56 -05001647 if ( nlsr->debugging )
1648 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1649 if ( nlsr->detailed_logging )
1650 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1651
akmhoqueda5b6832012-09-13 22:33:55 -05001652 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001653
1654 if ( nlsr->debugging )
1655 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1656 if ( nlsr->detailed_logging )
1657 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001658
akmhoqueda5b6832012-09-13 22:33:55 -05001659
1660 return 0;
1661}
1662
akmhoquef5537b42013-02-22 08:33:32 -06001663
akmhoque866c2222013-02-12 10:49:33 -06001664int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001665{
akmhoque866c2222013-02-12 10:49:33 -06001666
akmhoque7b791452012-10-30 11:24:56 -05001667 if ( nlsr->debugging )
1668 printf("delete_adj_lsa called \n");
1669 if ( nlsr->detailed_logging )
1670 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001671
akmhoque7b791452012-10-30 11:24:56 -05001672 if ( nlsr->debugging )
1673 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1674 if ( nlsr->detailed_logging )
1675 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1676
akmhoqueda5b6832012-09-13 22:33:55 -05001677 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001678
1679 if ( nlsr->debugging )
1680 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1681 if ( nlsr->detailed_logging )
1682 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1683
akmhoqueda5b6832012-09-13 22:33:55 -05001684
1685 if ( !nlsr->is_route_calculation_scheduled)
1686 {
1687 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1688 nlsr->is_route_calculation_scheduled=1;
1689 }
1690
akmhoqueda5b6832012-09-13 22:33:55 -05001691 return 0;
1692}
1693
akmhoqueffacaa82012-09-13 17:48:30 -05001694void
1695refresh_name_lsdb(void)
1696{
akmhoque7b791452012-10-30 11:24:56 -05001697 if ( nlsr->debugging )
1698 printf("refresh_name_lsdb called \n");
1699 if ( nlsr->detailed_logging )
1700 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001701
akmhoquef5537b42013-02-22 08:33:32 -06001702 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueffacaa82012-09-13 17:48:30 -05001703
1704 long int lsa_life_time;
1705
1706 int i, name_lsdb_element;
1707 struct nlsa *name_lsa;
1708
1709 struct hashtb_enumerator ee;
1710 struct hashtb_enumerator *e = &ee;
1711
1712 hashtb_start(nlsr->lsdb->name_lsdb, e);
1713 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1714
1715 for(i=0;i<name_lsdb_element;i++)
1716 {
1717 name_lsa=e->data;
1718
1719 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001720 if ( nlsr->debugging )
1721 printf("LSA Life Time: %ld \n",lsa_life_time);
1722 if ( nlsr->detailed_logging )
1723 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001724
1725 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1726 {
1727 if ( lsa_life_time > nlsr->lsa_refresh_time )
1728 {
akmhoque14b3f342012-09-14 10:39:02 -05001729 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1730 {
akmhoque7b791452012-10-30 11:24:56 -05001731 if ( nlsr->debugging )
1732 printf("Own Name LSA need to be refrshed\n");
1733 if ( nlsr->detailed_logging )
1734 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001735
1736 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1737 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1738 write_log_for_name_lsa(name_lsa);
1739 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1740
akmhoquef5537b42013-02-22 08:33:32 -06001741 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001742
akmhoque14b3f342012-09-14 10:39:02 -05001743 free(name_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001744 name_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoque14b3f342012-09-14 10:39:02 -05001745 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001746
1747 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1748 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1749 write_log_for_name_lsa(name_lsa);
1750 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001751
akmhoque14b3f342012-09-14 10:39:02 -05001752 free(current_time_stamp);
akmhoqued91401d2013-03-04 11:05:27 -06001753
1754 char lst[2];
1755 memset(lst,0,2);
1756 sprintf(lst,"%d",name_lsa->header->ls_type);
1757
1758 char lsid[10];
1759 memset(lsid,0,10);
1760 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1761
1762 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)
1763 +1+strlen(lst)+1+strlen(lsid)+1);
1764 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+
1765 strlen(lst)+1+strlen(lsid)+1);
1766
1767
1768 make_name_lsa_key(key, name_lsa->header->orig_router->name,
1769 name_lsa->header->ls_type,name_lsa->header->ls_id);
1770
1771 if ( nlsr->debugging )
1772 printf("Name LSA Key: %s \n",key);
1773
1774
1775 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+1+
1776 strlen(name_lsa->header->orig_router->name)
1777 +1+strlen(lst)+1+strlen(lsid)+1+
1778 strlen(name_lsa->header->orig_time)+16,
1779 sizeof(char));
1780 make_name_lsa_prefix_for_repo(repo_key,
1781 name_lsa->header->orig_router->name,
1782 name_lsa->header->ls_type,
1783 name_lsa->header->ls_id,
1784 name_lsa->header->orig_time,
1785 nlsr->slice_prefix);
1786
1787 if ( nlsr->debugging )
1788 printf("Name LSA Repo Key: %s \n",repo_key);
1789
1790 struct name_prefix *lsaid=(struct name_prefix *)
1791 calloc(1,sizeof(struct name_prefix));
1792 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1793 memcpy(lsaid->name,key,strlen(key)+1);
1794 lsaid->length=strlen(key)+1;
1795
1796
1797 write_name_lsa_to_repo(repo_key, lsaid);
1798
1799 free(key);
1800 free(repo_key);
1801 free(lsaid->name);
1802 free(lsaid);
1803
1804
akmhoque866c2222013-02-12 10:49:33 -06001805
1806 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001807 }
1808 else
akmhoquef5537b42013-02-22 08:33:32 -06001809 {
akmhoque866c2222013-02-12 10:49:33 -06001810 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1811 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1812 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1813 write_log_for_name_lsa(name_lsa);
1814 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001815
1816 destroy_name_lsa_component(name_lsa);
1817
akmhoque866c2222013-02-12 10:49:33 -06001818 hashtb_delete(e);
1819 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001820 }
akmhoqueda5b6832012-09-13 22:33:55 -05001821
akmhoque7b791452012-10-30 11:24:56 -05001822 if ( nlsr->debugging )
1823 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1824 if ( nlsr->detailed_logging )
1825 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1826
akmhoqueda5b6832012-09-13 22:33:55 -05001827 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001828
1829 if ( nlsr->debugging )
1830 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1831 if ( nlsr->detailed_logging )
1832 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1833
1834
akmhoqueda5b6832012-09-13 22:33:55 -05001835
1836 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001837 }
1838 else
1839 {
1840 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001841 }
1842 }
1843 else
1844 {
1845 if ( lsa_life_time > nlsr->router_dead_interval )
1846 {
akmhoque7b791452012-10-30 11:24:56 -05001847 if ( nlsr->debugging )
1848 printf("Others Name LSA need to be deleted\n");
1849 if ( nlsr->detailed_logging )
1850 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001851
akmhoque866c2222013-02-12 10:49:33 -06001852 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1853 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1854 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1855 write_log_for_name_lsa(name_lsa);
1856 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001857
1858 destroy_name_lsa_component(name_lsa);
akmhoque866c2222013-02-12 10:49:33 -06001859 hashtb_delete(e);
1860 i++;
1861 }
1862 else
1863 {
1864 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001865 }
1866 }
akmhoqueffacaa82012-09-13 17:48:30 -05001867 }
1868
1869 hashtb_end(e);
1870
1871 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001872
akmhoqueffacaa82012-09-13 17:48:30 -05001873
1874}
1875
akmhoqueda5b6832012-09-13 22:33:55 -05001876void
akmhoqueffacaa82012-09-13 17:48:30 -05001877refresh_adj_lsdb(void)
1878{
akmhoqueffacaa82012-09-13 17:48:30 -05001879
akmhoque7b791452012-10-30 11:24:56 -05001880 if ( nlsr->debugging )
1881 printf("refresh_adj_lsdb called \n");
1882 if ( nlsr->detailed_logging )
1883 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001884
akmhoquef5537b42013-02-22 08:33:32 -06001885 char *time_stamp=get_current_timestamp_micro_v2();
1886
akmhoqueffacaa82012-09-13 17:48:30 -05001887 long int lsa_life_time;
1888
1889 int i, adj_lsdb_element;
1890 struct alsa *adj_lsa;
1891
1892 struct hashtb_enumerator ee;
1893 struct hashtb_enumerator *e = &ee;
1894
1895 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1896 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1897
1898 for(i=0;i<adj_lsdb_element;i++)
1899 {
1900 adj_lsa=e->data;
1901
akmhoqueb77b95f2013-02-08 12:28:47 -06001902 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001903
1904 if ( nlsr->debugging )
1905 printf("LSA Life Time: %ld \n",lsa_life_time);
1906 if ( nlsr->detailed_logging )
1907 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001908
akmhoqueda5b6832012-09-13 22:33:55 -05001909 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1910 {
1911 if ( lsa_life_time > nlsr->lsa_refresh_time )
1912 {
akmhoque7b791452012-10-30 11:24:56 -05001913 if ( nlsr->debugging )
1914 printf("Own Adj LSA need to be refrshed\n");
1915 if ( nlsr->detailed_logging )
1916 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001917
akmhoquea98c2142012-10-25 15:22:24 -05001918 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1919 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1920 write_log_for_adj_lsa(adj_lsa);
1921 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1922
akmhoquef5537b42013-02-22 08:33:32 -06001923 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001924
1925 free(adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001926 adj_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoqueda5b6832012-09-13 22:33:55 -05001927 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1928
1929 free(current_time_stamp);
1930
akmhoquea98c2142012-10-25 15:22:24 -05001931 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1932 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1933 write_log_for_adj_lsa(adj_lsa);
1934 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001935
akmhoque7b791452012-10-30 11:24:56 -05001936 if ( nlsr->debugging )
1937 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1938 if ( nlsr->detailed_logging )
1939 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1940
akmhoqueda5b6832012-09-13 22:33:55 -05001941 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001942
1943 if ( nlsr->debugging )
1944 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1945 if ( nlsr->detailed_logging )
1946 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001947
akmhoqued91401d2013-03-04 11:05:27 -06001948
1949 char lst[2];
1950 memset(lst,0,2);
1951 sprintf(lst,"%d",LS_TYPE_ADJ);
1952
1953 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+
1954 strlen(adj_lsa->header->orig_time)+
1955 strlen(adj_lsa->header->orig_router->name)
1956 + strlen(lst) + 5+15,sizeof(char));
1957 make_adj_lsa_prefix_for_repo(repo_key,
1958 adj_lsa->header->orig_router->name,LS_TYPE_ADJ,
1959 adj_lsa->header->orig_time,nlsr->slice_prefix);
1960
1961 if ( nlsr->debugging )
1962 printf("Adj LSA Repo Key: %s \n",repo_key);
1963
1964 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,
1965 sizeof(char));
1966 make_adj_lsa_key(key,adj_lsa);
1967 if ( nlsr->debugging )
1968 printf("Adj LSA Key: %s \n",key);
1969
1970 struct name_prefix *lsaid=(struct name_prefix *)
1971 calloc(1,sizeof(struct name_prefix));
1972 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1973 memcpy(lsaid->name,key,strlen(key)+1);
1974 lsaid->length=strlen(key)+1;
1975
1976
1977 write_adj_lsa_to_repo(repo_key, lsaid);
1978
1979 free(key);
1980 free(repo_key);
1981 free(lsaid->name);
1982 free(lsaid);
1983
1984
1985
1986
1987
1988
akmhoqueda5b6832012-09-13 22:33:55 -05001989 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001990
1991
akmhoqueda5b6832012-09-13 22:33:55 -05001992 }
akmhoque866c2222013-02-12 10:49:33 -06001993
1994 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001995 }
1996 else
1997 {
1998 if ( lsa_life_time > nlsr->router_dead_interval )
1999 {
akmhoque7b791452012-10-30 11:24:56 -05002000
2001 if ( nlsr->debugging )
2002 printf("Others Adj LSA need to be deleted\n");
2003 if ( nlsr->detailed_logging )
2004 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06002005 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2006 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2007 write_log_for_adj_lsa(adj_lsa);
2008 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2009 delete_adj_lsa();
akmhoquef5537b42013-02-22 08:33:32 -06002010
2011 destroy_adj_lsa_component(adj_lsa);
akmhoque866c2222013-02-12 10:49:33 -06002012 hashtb_delete(e);
2013 i++;
2014
2015 }
2016 else
2017 {
2018 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002019 }
2020 }
akmhoquef5537b42013-02-22 08:33:32 -06002021
akmhoqueffacaa82012-09-13 17:48:30 -05002022 }
2023
2024 hashtb_end(e);
2025
2026 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002027}
2028
akmhoqueb77b95f2013-02-08 12:28:47 -06002029
2030void
2031refresh_cor_lsdb(void)
2032{
2033
2034 if ( nlsr->debugging )
2035 printf("refresh_cor_lsdb called \n");
2036 if ( nlsr->detailed_logging )
2037 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2038
akmhoquef5537b42013-02-22 08:33:32 -06002039 char *time_stamp=get_current_timestamp_micro_v2();
2040
akmhoqueb77b95f2013-02-08 12:28:47 -06002041 long int lsa_life_time;
2042
2043 int i, cor_lsdb_element;
2044 struct clsa *cor_lsa;
2045
2046 struct hashtb_enumerator ee;
2047 struct hashtb_enumerator *e = &ee;
2048
2049 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2050 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2051
2052 for(i=0;i<cor_lsdb_element;i++)
2053 {
2054 cor_lsa=e->data;
2055
2056 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2057
2058 if ( nlsr->debugging )
2059 printf("LSA Life Time: %ld \n",lsa_life_time);
2060 if ( nlsr->detailed_logging )
2061 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2062
2063 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2064 {
2065 if ( lsa_life_time > nlsr->lsa_refresh_time )
2066 {
2067 if ( nlsr->debugging )
2068 printf("Own Cor LSA need to be refrshed\n");
2069 if ( nlsr->detailed_logging )
2070 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2071
akmhoquef5537b42013-02-22 08:33:32 -06002072 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002073
2074 free(cor_lsa->header->orig_time);
2075 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2076 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2077 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2078
2079 free(current_time_stamp);
2080
akmhoqueb77b95f2013-02-08 12:28:47 -06002081 if ( nlsr->debugging )
2082 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2083 if ( nlsr->detailed_logging )
2084 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2085
2086 set_new_lsdb_version();
2087
2088 if ( nlsr->debugging )
2089 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2090 if ( nlsr->detailed_logging )
2091 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2092
2093 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002094 }
2095
2096 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002097 }
2098 else
2099 {
2100 if ( lsa_life_time > nlsr->router_dead_interval )
2101 {
2102
2103 if ( nlsr->debugging )
2104 printf("Others Adj LSA need to be deleted\n");
2105 if ( nlsr->detailed_logging )
2106 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoquef5537b42013-02-22 08:33:32 -06002107
2108 destroy_cor_lsa_component(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002109 hashtb_delete(e);
2110 i++;
2111 }
akmhoque866c2222013-02-12 10:49:33 -06002112 else
2113 {
2114 hashtb_next(e);
2115 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002116 }
2117
2118
akmhoque866c2222013-02-12 10:49:33 -06002119
akmhoqueb77b95f2013-02-08 12:28:47 -06002120 }
2121
2122 hashtb_end(e);
2123
2124 free(time_stamp);
2125}
2126
akmhoqueffacaa82012-09-13 17:48:30 -05002127int
2128refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2129{
2130 if(flags == CCN_SCHEDULE_CANCEL)
2131 {
2132 return -1;
2133 }
2134
2135 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002136
akmhoque7b791452012-10-30 11:24:56 -05002137 if ( nlsr->debugging )
2138 printf("refresh_lsdb called\n");
2139 if ( nlsr->detailed_logging )
2140 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002141
2142 refresh_name_lsdb();
2143 refresh_adj_lsdb();
2144
akmhoqueffacaa82012-09-13 17:48:30 -05002145 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002146
akmhoqueffacaa82012-09-13 17:48:30 -05002147 nlsr_unlock();
2148 return 0;
2149}
akmhoqueb77b95f2013-02-08 12:28:47 -06002150
2151void
2152write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2153{
2154 if ( nlsr->debugging )
2155 printf("write_adj_lsa_to_repo called\n");
2156 if ( nlsr->debugging )
2157 printf("Content Prefix: %s\n",repo_content_prefix);
2158
2159 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2160 get_adj_lsa_data(lsa_data,lsa_id);
2161 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002162 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002163
akmhoque829228c2013-02-25 17:39:40 -06002164 char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
akmhoquef5537b42013-02-22 08:33:32 -06002165 data=ccn_charbuf_as_string(lsa_data);
2166 data[strlen(data)]='\0';
2167
2168 write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002169
akmhoque323b5e92013-02-21 13:55:15 -06002170
akmhoqueaa2adc12013-02-25 17:42:28 -06002171 //ccn_charbuf_destroy(&lsa_data);
2172 //free(data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002173}
2174
2175void
2176write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2177{
2178 if ( nlsr->debugging )
2179 printf("write_name_lsa_to_repo called\n");
2180 if ( nlsr->debugging )
2181 printf("Content Prefix: %s\n",repo_content_prefix);
2182
2183 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2184 get_name_lsa_data(lsa_data,lsa_id);
2185
2186 if ( nlsr->debugging )
2187 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2188
akmhoque829228c2013-02-25 17:39:40 -06002189 char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
akmhoquef5537b42013-02-22 08:33:32 -06002190 data=ccn_charbuf_as_string(lsa_data);
2191 data[strlen(data)]='\0';
akmhoque323b5e92013-02-21 13:55:15 -06002192
akmhoquef5537b42013-02-22 08:33:32 -06002193 write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002194
akmhoqueaa2adc12013-02-25 17:42:28 -06002195 //ccn_charbuf_destroy(&lsa_data);
2196 //free(data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002197}
2198
2199
2200void
2201write_name_lsdb_to_repo(char *slice_prefix)
2202{
2203 int i, name_lsdb_element;
2204
2205 struct nlsa *name_lsa;
2206 struct hashtb_enumerator ee;
2207 struct hashtb_enumerator *e = &ee;
2208
2209 hashtb_start(nlsr->lsdb->name_lsdb, e);
2210 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2211
2212 for(i=0;i<name_lsdb_element;i++)
2213 {
2214 name_lsa=e->data;
2215
2216 char lst[2];
2217 memset(lst,0,2);
2218 sprintf(lst,"%d",name_lsa->header->ls_type);
2219
2220 char lsid[10];
2221 memset(lsid,0,10);
2222 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2223
2224
2225 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2226 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2227
2228
2229 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2230
2231 if ( nlsr->debugging )
2232 printf("Name LSA Key: %s \n",key);
2233
2234
akmhoquef5537b42013-02-22 08:33:32 -06002235 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 -06002236 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);
2237
2238 if ( nlsr->debugging )
2239 printf("Name LSA Repo Key: %s \n",repo_key);
2240
akmhoquef5537b42013-02-22 08:33:32 -06002241 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
2242 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
2243 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002244 lsaid->length=strlen(key)+1;
2245
2246
2247 write_name_lsa_to_repo(repo_key, lsaid);
2248
2249 free(key);
2250 free(repo_key);
2251 free(lsaid->name);
2252 free(lsaid);
2253
2254 hashtb_next(e);
2255 }
2256
2257 hashtb_end(e);
2258
2259
2260}
2261
2262void
2263print_cor_lsa(struct clsa *cor_lsa)
2264{
2265 if ( nlsr->debugging )
2266 {
2267 printf("-----------Cor LSA Content---------------\n");
2268 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2269 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2270 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2271 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2272 printf(" LSA Data \n");
2273 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2274 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2275
2276 printf("\n");
2277 }
2278}
2279
2280void
2281print_cor_lsdb()
2282{
2283
2284 if ( nlsr->debugging )
2285 printf("print_cor_lsdb called \n");
2286
2287 struct hashtb_enumerator ee;
2288 struct hashtb_enumerator *e = &ee;
2289
2290 int i=1;
2291
2292 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2293 {
2294 if ( nlsr->debugging )
2295 printf("-----------Cor LSA (%d)---------------\n",i);
2296 struct clsa *cor_lsa=e->data;
2297 print_cor_lsa(cor_lsa);
2298 i++;
2299 }
2300 hashtb_end(e);
2301
2302 if ( nlsr->debugging )
2303 printf("\n");
2304 if ( nlsr->detailed_logging )
2305 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2306}
2307
2308void
2309install_cor_lsa(struct clsa *cor_lsa)
2310{
2311 if ( nlsr->debugging )
2312 printf("install_cor_lsa called \n");
2313 if ( nlsr->detailed_logging )
2314 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2315
2316
akmhoquececba942013-02-25 17:33:34 -06002317 //char *time_stamp=(char *)malloc(20);
2318 //memset(time_stamp,0,20);
2319 //get_current_timestamp_micro(time_stamp);
akmhoqueb77b95f2013-02-08 12:28:47 -06002320
2321
akmhoque569a93d2013-02-21 10:19:54 -06002322 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2323 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002324 make_cor_lsa_key(key,cor_lsa);
2325
2326 if ( nlsr->debugging )
2327 printf("Cor LSA key: %s \n",key);
2328
2329 struct hashtb_enumerator ee;
2330 struct hashtb_enumerator *e = &ee;
2331 int res;
2332
2333 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2334 res = hashtb_seek(e, key, strlen(key), 0);
2335
2336 if ( res == HT_NEW_ENTRY )
2337 {
2338 if ( nlsr->debugging )
2339 printf("New Cor LSA... \n");
2340
akmhoque8876e982013-02-21 13:35:46 -06002341 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002342 new_cor_lsa=e->data;
2343 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2344
2345 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2346 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
akmhoquececba942013-02-25 17:33:34 -06002347 //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002348 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2349 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2350
akmhoque483c1eb2013-03-08 00:51:09 -06002351 new_cor_lsa->header->orig_time=(char *)calloc(strlen(cor_lsa->header->orig_time)+1,sizeof(char)); //free
akmhoquececba942013-02-25 17:33:34 -06002352 //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
akmhoque483c1eb2013-03-08 00:51:09 -06002353 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2354 //new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002355
2356 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2357
2358 new_cor_lsa->cor_r=cor_lsa->cor_r;
2359 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2360 }
2361 else if ( res == HT_OLD_ENTRY )
2362 {
2363 if ( nlsr->debugging )
2364 printf("Cor LSA exists (Old)... \n");
2365 }
2366 hashtb_end(e);
2367
akmhoquef5537b42013-02-22 08:33:32 -06002368 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002369
2370}
2371
2372void
2373build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2374{
2375 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2376 cor_lsa->header->ls_type=LS_TYPE_COR;
2377
akmhoquef5537b42013-02-22 08:33:32 -06002378 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002379 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2380 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2381 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2382 free(time_stamp);
2383
akmhoquef5537b42013-02-22 08:33:32 -06002384 cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
2385 cor_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002386 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2387 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2388 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2389
2390 cor_lsa->cor_r=cor_r;
2391 cor_lsa->cor_theta=cor_theta;
2392
2393}
2394
2395void
2396build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2397{
2398 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2399 cor_lsa->header->ls_type=ls_type;
2400
2401 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2402 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002403 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002404
2405 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2406 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2407 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002408 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002409 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2410
2411 cor_lsa->cor_r=cor_r;
2412 cor_lsa->cor_theta=cor_theta;
2413
2414}
2415
2416void
2417build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2418{
2419 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2420 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2421 install_cor_lsa(cor_lsa);
2422
2423 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002424
akmhoquef5537b42013-02-22 08:33:32 -06002425 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002426}
2427
2428
2429void
2430build_and_install_cor_lsa()
2431{
2432
2433
2434
2435 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2436
2437 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2438 install_cor_lsa(cor_lsa);
2439
2440 write_cor_lsa_to_repo(cor_lsa);
akmhoquef5537b42013-02-22 08:33:32 -06002441 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002442
2443 print_cor_lsdb();
akmhoqueb77b95f2013-02-08 12:28:47 -06002444
2445}
2446
2447void
2448get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2449{
2450 if ( nlsr->debugging )
2451 printf("get_cor_lsa_data called \n");
2452 if ( nlsr->detailed_logging )
2453 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2454
akmhoquececba942013-02-25 17:33:34 -06002455 struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002456
2457 struct hashtb_enumerator ee;
2458 struct hashtb_enumerator *e = &ee;
2459 int res;
2460
2461 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2462 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2463
2464 if( res == HT_OLD_ENTRY )
2465 {
2466 cor_lsa=e->data;
2467
2468 if ( nlsr->debugging )
2469 printf("Cor LSA found \n");
2470 if ( nlsr->detailed_logging )
2471 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2472
2473 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2474 ccn_charbuf_append_string(lsa_data,"|");
2475
2476 char *temp_length=(char *)malloc(20);
2477 memset(temp_length,0,20);
2478 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2479 ccn_charbuf_append_string(lsa_data,temp_length);
2480 ccn_charbuf_append_string(lsa_data,"|");
2481 free(temp_length);
2482
2483 char *temp_ltype=(char *)malloc(20);
2484 memset(temp_ltype,0,20);
2485 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2486 ccn_charbuf_append_string(lsa_data,temp_ltype);
2487 ccn_charbuf_append_string(lsa_data,"|");
2488 free(temp_ltype);
2489
2490 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2491 ccn_charbuf_append_string(lsa_data,"|");
2492
2493 char *cor_r=(char *)malloc(20);
2494 memset(cor_r,0,20);
2495 sprintf(cor_r,"%f",cor_lsa->cor_r);
2496 ccn_charbuf_append_string(lsa_data,cor_r);
2497 ccn_charbuf_append_string(lsa_data,"|");
2498 free(cor_r);
2499
2500 char *cor_theta=(char *)malloc(20);
2501 memset(cor_theta,0,20);
2502 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2503 ccn_charbuf_append_string(lsa_data,cor_theta);
2504 ccn_charbuf_append_string(lsa_data,"|");
2505 free(cor_theta);
2506
2507 }
2508 else if(res == HT_NEW_ENTRY)
2509 {
2510 hashtb_delete(e);
2511 }
2512
2513 hashtb_end(e);
2514}
2515
2516void
2517write_cor_lsa_to_repo(struct clsa *cor_lsa)
2518{
2519
2520
2521 if ( nlsr->debugging )
2522 printf("write_cor_lsa_to_repo called\n");
2523
2524
akmhoquef5537b42013-02-22 08:33:32 -06002525 char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002526 make_cor_lsa_key(key,cor_lsa);
2527
2528 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2529 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002530
akmhoqueb77b95f2013-02-08 12:28:47 -06002531 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002532 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2533
akmhoqueb77b95f2013-02-08 12:28:47 -06002534 char *lst=(char *)malloc(20);
2535 memset(lst,0,20);
2536 sprintf(lst,"%d",cor_lsa->header->ls_type);
akmhoquef5537b42013-02-22 08:33:32 -06002537 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 -06002538 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);
2539
2540 if ( nlsr->debugging )
2541 printf("Cor LSA Repo Key: %s \n",repo_key);
2542
akmhoque829228c2013-02-25 17:39:40 -06002543 char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
akmhoquef5537b42013-02-22 08:33:32 -06002544 data=ccn_charbuf_as_string(lsa_data);
2545 data[strlen(data)]='\0';
2546
2547 write_data_to_repo(data, repo_key);
akmhoque0800eda2013-02-21 14:17:52 -06002548
akmhoqueb77b95f2013-02-08 12:28:47 -06002549
2550
2551
2552 free(lst);
2553 free(key);
2554 free(repo_key);
akmhoqueaa2adc12013-02-25 17:42:28 -06002555 //free(data);
2556 //ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002557}
2558
2559void
2560make_cor_lsa_key_by_router_name(char *key,char *router_name)
2561{
2562 memcpy(key+strlen(key),router_name,strlen(router_name));
2563 memcpy(key+strlen(key),"/",1);
2564 char ls_type[2];
2565 sprintf(ls_type,"%d",LS_TYPE_COR);
2566 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2567 key[strlen(key)]='\0';
2568}
2569
2570
2571double
2572get_hyperbolic_r(char *router)
2573{
2574 double ret=-1.0;
2575 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2576 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2577
2578
2579 struct clsa *cor_lsa;
2580 struct hashtb_enumerator ee;
2581 struct hashtb_enumerator *e = &ee;
2582 int res;
2583
2584 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2585 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2586
2587 if ( res == HT_OLD_ENTRY)
2588 {
2589 cor_lsa=e->data;
2590 ret=cor_lsa->cor_r;
2591 }
2592 else if(res == HT_NEW_ENTRY)
2593 {
2594 hashtb_delete(e);
2595 }
2596
2597 hashtb_end(e);
2598
2599 free(cor_lsa_key);
2600 return ret;
2601}
2602
2603double
2604get_hyperbolic_theta(char *router)
2605{
akmhoquef5537b42013-02-22 08:33:32 -06002606 double ret=-1.0;
akmhoqueb77b95f2013-02-08 12:28:47 -06002607 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2608 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2609
2610 struct clsa *cor_lsa;
2611 struct hashtb_enumerator ee;
2612 struct hashtb_enumerator *e = &ee;
2613 int res;
2614
2615 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2616 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2617
2618 if ( res == HT_OLD_ENTRY)
2619 {
2620 cor_lsa=e->data;
2621 ret=cor_lsa->cor_theta;
2622 }
2623 else if(res == HT_NEW_ENTRY)
2624 {
2625 hashtb_delete(e);
2626 }
2627
2628 hashtb_end(e);
2629
2630 free(cor_lsa_key);
2631 return ret;
2632}
akmhoquead584782013-02-22 10:56:03 -06002633
2634
2635void
2636destroy_name_lsdb(void)
2637{
2638 int i, name_lsdb_element;
2639 struct nlsa *name_lsa;
2640
2641 struct hashtb_enumerator ee;
2642 struct hashtb_enumerator *e = &ee;
2643
2644 hashtb_start(nlsr->lsdb->name_lsdb, e);
2645 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2646
2647 for(i=0;i<name_lsdb_element;i++)
2648 {
2649 name_lsa=e->data;
2650 destroy_name_lsa_component(name_lsa);
2651 hashtb_next(e);
2652 }
2653
2654 hashtb_end(e);
2655
2656 if ( nlsr->lsdb->name_lsdb )
2657 hashtb_destroy(&nlsr->lsdb->name_lsdb);
2658}
2659
2660void
2661destroy_adj_lsdb(void)
2662{
2663 int i, adj_lsdb_element;
2664 struct alsa *adj_lsa;
2665
2666 struct hashtb_enumerator ee;
2667 struct hashtb_enumerator *e = &ee;
2668
2669 hashtb_start(nlsr->lsdb->adj_lsdb, e);
2670 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
2671
2672 for(i=0;i<adj_lsdb_element;i++)
2673 {
2674 adj_lsa=e->data;
2675 destroy_adj_lsa_component(adj_lsa);
2676 hashtb_next(e);
2677 }
2678
2679 hashtb_end(e);
2680 if(nlsr->lsdb->adj_lsdb )
2681 hashtb_destroy(&nlsr->lsdb->adj_lsdb);
2682}
2683
2684void
2685destroy_cor_lsdb(void)
2686{
2687 int i, cor_lsdb_element;
2688 struct clsa *cor_lsa;
2689
2690 struct hashtb_enumerator ee;
2691 struct hashtb_enumerator *e = &ee;
2692
2693 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2694 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2695
2696 for(i=0;i<cor_lsdb_element;i++)
2697 {
2698 cor_lsa=e->data;
2699 destroy_cor_lsa_component(cor_lsa);
2700 hashtb_next(e);
2701 }
2702
2703 hashtb_end(e);
2704 if(nlsr->lsdb->cor_lsdb )
2705 hashtb_destroy(&nlsr->lsdb->cor_lsdb);
2706}
2707
2708void
2709destroy_lsdb(void)
2710{
2711 destroy_name_lsdb();
2712 destroy_adj_lsdb();
2713 destroy_cor_lsdb();
2714
2715 if ( nlsr->lsdb->lsdb_version )
2716 free(nlsr->lsdb->lsdb_version);
2717 if ( nlsr->lsdb )
2718 free(nlsr->lsdb);
2719}