blob: 36f2dbd80ad1b6b4052aefedab007dc7da4ec417 [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{
akmhoque03004e62012-09-06 01:12:28 -050037 free(nlsr->lsdb->lsdb_version);
akmhoque54a14f42013-02-24 06:16:20 -060038 nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
akmhoquef71d9082012-08-22 12:51:53 -040039}
40
akmhoque0ab71642013-02-21 10:10:33 -060041/**
42* Make key for storing Name LSA in Name LSDB
43*/
44
akmhoque03004e62012-09-06 01:12:28 -050045void
46make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
47{
48
akmhoque03004e62012-09-06 01:12:28 -050049 char lst[2];
50 memset(lst,0,2);
51 sprintf(lst,"%d",ls_type);
52
53 char lsid[10];
54 memset(lsid,0,10);
55 sprintf(lsid,"%ld",ls_id);
56
akmhoqueeacf44f2013-02-22 01:02:13 -060057 memcpy(key,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -050058 memcpy(key+strlen(key),"/",1);
59 memcpy(key+strlen(key),lst,strlen(lst));
60 memcpy(key+strlen(key),"/",1);
61 memcpy(key+strlen(key),lsid,strlen(lsid));
akmhoqueeacf44f2013-02-22 01:02:13 -060062 key[strlen(key)]='\0';
63
akmhoqueb77b95f2013-02-08 12:28:47 -060064 if ( nlsr->debugging )
65 printf("name LSA Key: %s\n", key);
66}
67
akmhoque0ed6d982013-02-22 14:28:01 -060068
akmhoque0ab71642013-02-21 10:10:33 -060069/**
70* Make content name prefix for Name LSA to store in repo
71*/
akmhoqueb77b95f2013-02-08 12:28:47 -060072
73void
akmhoque0ab71642013-02-21 10:10:33 -060074make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
75 long int ls_id,char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060076{
akmhoque0ab71642013-02-21 10:10:33 -060077 sprintf(key,"%s%s/lsType.%d/lsId.%ld/%s",slice_prefix, orig_router, ls_type,
78 ls_id, orig_time);
akmhoqueeacf44f2013-02-22 01:02:13 -060079 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -060080 if ( nlsr->debugging )
81 printf("Name LSA prefix for repo content: %s\n",key);
82}
83
akmhoque0ab71642013-02-21 10:10:33 -060084/**
85* Make content name prefix for Adj LSA to store in repo
86*/
87
akmhoqueb77b95f2013-02-08 12:28:47 -060088void
akmhoque0ab71642013-02-21 10:10:33 -060089make_adj_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
90 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060091{
92
93 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
akmhoqueeacf44f2013-02-22 01:02:13 -060094 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -060095 if ( nlsr->debugging )
96 printf("Name LSA prefix for repo content:%s\n",key);
97}
98
akmhoque0ab71642013-02-21 10:10:33 -060099/**
100* Make content name prefix for Cor LSA to store in repo
101*/
102
akmhoqueb77b95f2013-02-08 12:28:47 -0600103void
akmhoque0ab71642013-02-21 10:10:33 -0600104make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
105 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -0600106{
107
108 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
akmhoqueeacf44f2013-02-22 01:02:13 -0600109 key[strlen(key)]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -0600110 if ( nlsr->debugging )
111 printf("Cor LSA prefix for repo content:%s\n",key);
akmhoque03004e62012-09-06 01:12:28 -0500112}
akmhoque53f64222012-09-05 13:57:51 -0500113
akmhoquec25f2242013-03-15 00:24:43 -0500114
akmhoque0ab71642013-02-21 10:10:33 -0600115
akmhoqueeacf44f2013-02-22 01:02:13 -0600116void
akmhoquef5537b42013-02-22 08:33:32 -0600117destroy_name_lsa_component(struct nlsa * name_lsa)
akmhoqueeacf44f2013-02-22 01:02:13 -0600118{
119 if ( name_lsa->header->orig_router->name )
120 free(name_lsa->header->orig_router->name);
121 if ( name_lsa->header->orig_router )
122 free(name_lsa->header->orig_router);
akmhoquef5537b42013-02-22 08:33:32 -0600123 if ( name_lsa->header->orig_time )
124 free(name_lsa->header->orig_time);
akmhoqueeacf44f2013-02-22 01:02:13 -0600125 if ( name_lsa->header )
126 free(name_lsa->header);
akmhoquef5537b42013-02-22 08:33:32 -0600127
akmhoqueeacf44f2013-02-22 01:02:13 -0600128 if ( name_lsa->name_prefix->name )
129 free(name_lsa->name_prefix->name);
130 if ( name_lsa->name_prefix )
131 free(name_lsa->name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -0600132}
133
134void
135destroy_name_lsa(struct nlsa * name_lsa)
136{
137 destroy_name_lsa_component(name_lsa);
akmhoqueeacf44f2013-02-22 01:02:13 -0600138 if ( name_lsa )
139 free(name_lsa);
140}
akmhoque0ab71642013-02-21 10:10:33 -0600141
akmhoquef5537b42013-02-22 08:33:32 -0600142void
143destroy_adj_lsa_component(struct alsa * adj_lsa)
144{
145 if ( adj_lsa->header->orig_router->name )
146 free(adj_lsa->header->orig_router->name);
147 if ( adj_lsa->header->orig_router )
148 free(adj_lsa->header->orig_router);
149 if ( adj_lsa->header->orig_time )
150 free(adj_lsa->header->orig_time);
151 if ( adj_lsa->header )
152 free(adj_lsa->header);
153
154 if ( adj_lsa->body )
155 free(adj_lsa->body);
156}
157
158void
159destroy_adj_lsa(struct alsa * adj_lsa)
160{
161
162 destroy_adj_lsa_component(adj_lsa);
163 if ( adj_lsa )
164 free(adj_lsa);
165}
166
167void
168destroy_cor_lsa_component(struct clsa * cor_lsa)
169{
170 if ( cor_lsa->header->orig_router->name )
171 free(cor_lsa->header->orig_router->name);
172 if ( cor_lsa->header->orig_router )
173 free(cor_lsa->header->orig_router);
174 if ( cor_lsa->header->orig_time )
175 free(cor_lsa->header->orig_time);
176 if ( cor_lsa->header )
177 free(cor_lsa->header);
178}
179
180void
181destroy_cor_lsa(struct clsa * cor_lsa)
182{
183
184 destroy_cor_lsa_component(cor_lsa);
185 if ( cor_lsa )
186 free(cor_lsa);
187}
188
akmhoquec25f2242013-03-15 00:24:43 -0500189/**
190* Build name lsa for all name prefixes in Name Prefix List (NPL). Intsall Name
191* LSA in Name LSDB for router itself.
192*/
akmhoquef5537b42013-02-22 08:33:32 -0600193
194
akmhoquef71d9082012-08-22 12:51:53 -0400195void
akmhoque53f64222012-09-05 13:57:51 -0500196build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -0400197{
akmhoque7b791452012-10-30 11:24:56 -0500198 if ( nlsr->debugging )
199 printf("build_and_install_name_lsas called \n");
200 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600201 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas "
202 "called\n");
akmhoquef71d9082012-08-22 12:51:53 -0400203
akmhoquef71d9082012-08-22 12:51:53 -0400204 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600205 struct name_prefix_list_entry *npe;
akmhoquef71d9082012-08-22 12:51:53 -0400206
207 struct hashtb_enumerator ee;
208 struct hashtb_enumerator *e = &ee;
209
210 hashtb_start(nlsr->npl, e);
211 npl_element=hashtb_n(nlsr->npl);
212
213 for(i=0;i<npl_element;i++)
214 {
akmhoque3171d652012-11-13 11:44:33 -0600215 npe=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500216 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
akmhoque3171d652012-11-13 11:44:33 -0600217 build_name_lsa(name_lsa,npe->np);
akmhoque03004e62012-09-06 01:12:28 -0500218
akmhoquef71d9082012-08-22 12:51:53 -0400219 install_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600220 update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600221 destroy_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400222 hashtb_next(e);
223 }
224
akmhoque53f64222012-09-05 13:57:51 -0500225 hashtb_end(e);
akmhoque3171d652012-11-13 11:44:33 -0600226
227 print_name_prefix_from_npl();
228
229}
230
akmhoque0ab71642013-02-21 10:10:33 -0600231/**
232* Build and Install one Name LSA Use ful for API
233*/
234
akmhoque3171d652012-11-13 11:44:33 -0600235void
236build_and_install_single_name_lsa(struct name_prefix *np)
237{
238 if ( nlsr->debugging )
239 printf("build_and_install_single_name_lsa called \n");
240 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600241 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name"
242 "_lsa called\n");
akmhoque3171d652012-11-13 11:44:33 -0600243
244 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
245 build_name_lsa(name_lsa,np);
246
247 install_name_lsa(name_lsa);
248 update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id);
akmhoqueeacf44f2013-02-22 01:02:13 -0600249 destroy_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600250 print_name_prefix_from_npl();
akmhoquef71d9082012-08-22 12:51:53 -0400251
akmhoquef71d9082012-08-22 12:51:53 -0400252}
253
akmhoquec25f2242013-03-15 00:24:43 -0500254/**
255* Build Name LSA for own router from name_prefix np and fill up the name_lsa
256*/
257
258
akmhoque53f64222012-09-05 13:57:51 -0500259void
260build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
261{
akmhoque53f64222012-09-05 13:57:51 -0500262 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
263 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoqueeacf44f2013-02-22 01:02:13 -0600264
265 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500266 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500267 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
268 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500269
270 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500271
272 name_lsa->header->ls_id=++nlsr->nlsa_id;
akmhoqued91401d2013-03-04 11:05:27 -0600273 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,
274 sizeof(struct name_prefix ));
275 name_lsa->header->orig_router->name=(char *)calloc(
276 strlen(nlsr->router_name)+1,sizeof(char));
277 memcpy(name_lsa->header->orig_router->name,
278 nlsr->router_name,strlen(nlsr->router_name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500279 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500280 name_lsa->header->isValid=1;
281
282
283 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueeacf44f2013-02-22 01:02:13 -0600284 name_lsa->name_prefix->name=(char *)calloc(np->length,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -0500285 memcpy(name_lsa->name_prefix->name,np->name,np->length);
286 name_lsa->name_prefix->length=np->length;
287
288}
289
akmhoquec25f2242013-03-15 00:24:43 -0500290/**
291* install name lsa into lsdb
292*/
293
akmhoque53f64222012-09-05 13:57:51 -0500294void
295install_name_lsa(struct nlsa *name_lsa)
296{
akmhoque53f64222012-09-05 13:57:51 -0500297
akmhoque0ab71642013-02-21 10:10:33 -0600298 char lst[2];
299 memset(lst,0,2);
300 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoqueffacaa82012-09-13 17:48:30 -0500301
akmhoque0ab71642013-02-21 10:10:33 -0600302 char lsid[10];
303 memset(lsid,0,10);
304 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque3171d652012-11-13 11:44:33 -0600305
akmhoqued91401d2013-03-04 11:05:27 -0600306 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+
307 strlen(lst)+1+strlen(lsid)+1);
308 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)
309 +1+strlen(lsid)+1);
310 make_name_lsa_key(key, name_lsa->header->orig_router->name,
311 name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque53f64222012-09-05 13:57:51 -0500312
akmhoque0ab71642013-02-21 10:10:33 -0600313 if ( nlsr->debugging )
314 printf("Key:%s Length:%d\n",key,(int)strlen(key));
315 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600316 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,
317 (int)strlen(key));
akmhoque0ab71642013-02-21 10:10:33 -0600318
akmhoquef5537b42013-02-22 08:33:32 -0600319 struct nlsa *new_name_lsa;
akmhoque53f64222012-09-05 13:57:51 -0500320
akmhoque0ab71642013-02-21 10:10:33 -0600321 struct hashtb_enumerator ee;
322 struct hashtb_enumerator *e = &ee;
323 int res;
akmhoque53f64222012-09-05 13:57:51 -0500324
akmhoque0ab71642013-02-21 10:10:33 -0600325 hashtb_start(nlsr->lsdb->name_lsdb, e);
326 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500327
akmhoque0ab71642013-02-21 10:10:33 -0600328 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500329 {
akmhoqueffacaa82012-09-13 17:48:30 -0500330
akmhoquef5537b42013-02-22 08:33:32 -0600331 if ( name_lsa->header->isValid == 1 )
332 {
akmhoque7b791452012-10-30 11:24:56 -0500333 if ( nlsr->debugging )
334 printf("New Name LSA... Adding to LSDB\n");
335 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600336 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... "
337 "Adding to LSDB\n");
akmhoque7b791452012-10-30 11:24:56 -0500338
339
akmhoqueffacaa82012-09-13 17:48:30 -0500340 new_name_lsa = e->data;
akmhoque8876e982013-02-21 13:35:46 -0600341
akmhoque54d86112013-02-21 16:42:34 -0600342
akmhoqued91401d2013-03-04 11:05:27 -0600343 new_name_lsa->header=(struct nlsa_header *)calloc(1,
344 sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500345 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
346
akmhoqued91401d2013-03-04 11:05:27 -0600347 new_name_lsa->header->orig_time=(char *)calloc(
348 strlen(name_lsa->header->orig_time)+1,sizeof(char));
349 //memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
350 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,
351 strlen(name_lsa->header->orig_time)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500352
353 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoqued91401d2013-03-04 11:05:27 -0600354 new_name_lsa->header->orig_router=(struct name_prefix *)calloc(1,
355 sizeof(struct name_prefix ));
356 new_name_lsa->header->orig_router->name=(char *)calloc(
357 name_lsa->header->orig_router->length,sizeof(char));
358 memcpy(new_name_lsa->header->orig_router->name,
359 name_lsa->header->orig_router->name,
360 name_lsa->header->orig_router->length);
akmhoqueffacaa82012-09-13 17:48:30 -0500361 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
362 new_name_lsa->header->isValid=name_lsa->header->isValid;
363
364
akmhoqued91401d2013-03-04 11:05:27 -0600365 new_name_lsa->name_prefix=(struct name_prefix *)calloc(1,
366 sizeof(struct name_prefix ));
367 new_name_lsa->name_prefix->name=(char *)calloc(
368 name_lsa->name_prefix->length,sizeof(char));
369 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,
370 name_lsa->name_prefix->length);
akmhoqueffacaa82012-09-13 17:48:30 -0500371 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
akmhoque8876e982013-02-21 13:35:46 -0600372
akmhoqueffacaa82012-09-13 17:48:30 -0500373
akmhoque7b791452012-10-30 11:24:56 -0500374 if ( nlsr->debugging )
375 {
376 printf("New Name LSA Added....\n");
377 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
378 }
379 if ( nlsr->detailed_logging )
380 {
akmhoqued91401d2013-03-04 11:05:27 -0600381 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added.\n");
382 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of"
383 " LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque7b791452012-10-30 11:24:56 -0500384 }
akmhoque54d86112013-02-21 16:42:34 -0600385
akmhoqueffacaa82012-09-13 17:48:30 -0500386 set_new_lsdb_version();
akmhoque54d86112013-02-21 16:42:34 -0600387
akmhoque7b791452012-10-30 11:24:56 -0500388 if ( nlsr->debugging )
akmhoqued91401d2013-03-04 11:05:27 -0600389 printf("New Version Number of LSDB: %s \n",
390 nlsr->lsdb->lsdb_version);
akmhoque7b791452012-10-30 11:24:56 -0500391 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600392 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of"
393 " LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500394
akmhoque9e9fc722012-09-26 14:03:25 -0500395
akmhoqued91401d2013-03-04 11:05:27 -0600396 int num_next_hop=get_number_of_next_hop(
397 new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500398 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500399 {
akmhoqued91401d2013-03-04 11:05:27 -0600400 int check=add_npt_entry(new_name_lsa->header->orig_router->name,
401 new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL);
akmhoqueffacaa82012-09-13 17:48:30 -0500402 if ( check == HT_NEW_ENTRY )
403 {
akmhoque7b791452012-10-30 11:24:56 -0500404 if ( nlsr->debugging )
405 printf("Added in npt \n");
406 if ( nlsr->detailed_logging )
407 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500408 }
akmhoque3560cb62012-09-09 10:52:30 -0500409 }
akmhoqueffacaa82012-09-13 17:48:30 -0500410 else
akmhoque3560cb62012-09-09 10:52:30 -0500411 {
akmhoquede61ba92012-09-20 22:19:12 -0500412 int *faces=malloc(num_next_hop*sizeof(int));
413 int *route_costs=malloc(num_next_hop*sizeof(int));
akmhoqued91401d2013-03-04 11:05:27 -0600414 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name
415 ,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500416 if ( nlsr->debugging )
417 {
418 printf("Printing from install_name_lsa \n");
419 int j;
420 for(j=0;j<num_next_hop;j++)
421 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
422 }
423 if ( nlsr->detailed_logging )
424 {
akmhoqued91401d2013-03-04 11:05:27 -0600425 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from ins"
426 "tall_name_lsa \n");
akmhoque7b791452012-10-30 11:24:56 -0500427 int j;
428 for(j=0;j<num_next_hop;j++)
akmhoqued91401d2013-03-04 11:05:27 -0600429 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route"
430 " Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500431 }
akmhoqued91401d2013-03-04 11:05:27 -0600432 int check=add_npt_entry(new_name_lsa->header->orig_router->name,
433 new_name_lsa->name_prefix->name,next_hop,faces,route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500434 if ( check == HT_NEW_ENTRY )
435 {
akmhoque7b791452012-10-30 11:24:56 -0500436 if ( nlsr->debugging )
437 printf("Added in npt \n");
438 if ( nlsr->detailed_logging )
439 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500440 }
akmhoquede61ba92012-09-20 22:19:12 -0500441 free(faces);
442 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500443
akmhoque3560cb62012-09-09 10:52:30 -0500444 }
akmhoquede61ba92012-09-20 22:19:12 -0500445
akmhoque9e9fc722012-09-26 14:03:25 -0500446 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
447 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
akmhoquef5537b42013-02-22 08:33:32 -0600448 write_log_for_name_lsa(new_name_lsa);
akmhoque9e9fc722012-09-26 14:03:25 -0500449 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500450
akmhoque54d86112013-02-21 16:42:34 -0600451 //free(time_stamp);
akmhoquef5537b42013-02-22 08:33:32 -0600452 }
453 else
454 {
455 hashtb_delete(e);
456 }
akmhoqueffacaa82012-09-13 17:48:30 -0500457
458 }
459 else if(res == HT_OLD_ENTRY)
460 {
461 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500462 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500463 {
akmhoque7b791452012-10-30 11:24:56 -0500464 if ( nlsr->debugging )
465 printf("Older Adj LSA. Discarded... \n");
466 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600467 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Di"
468 "scarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500469 }
akmhoqued91401d2013-03-04 11:05:27 -0600470 else if( strcmp(name_lsa->header->orig_time,
471 new_name_lsa->header->orig_time) == 0 )
akmhoque14b3f342012-09-14 10:39:02 -0500472 {
akmhoque7b791452012-10-30 11:24:56 -0500473 if ( nlsr->debugging )
474 printf("Duplicate Adj LSA. Discarded... \n");
475 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600476 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA."
477 " Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500478 }
479 else
480 {
481 if ( name_lsa->header->isValid == 0 )
482 {
483 // have to call to delete npt table entry
akmhoqued91401d2013-03-04 11:05:27 -0600484 delete_npt_entry_by_router_and_name_prefix(
485 new_name_lsa->header->orig_router->name,
486 new_name_lsa->name_prefix->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500487
488 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
489 {
akmhoque9e9fc722012-09-26 14:03:25 -0500490 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
akmhoqued91401d2013-03-04 11:05:27 -0600491 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name"
492 " lsa\n");
akmhoque9e9fc722012-09-26 14:03:25 -0500493 write_log_for_name_lsa(new_name_lsa);
akmhoqued91401d2013-03-04 11:05:27 -0600494 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end"
495 "\n");
akmhoque9e9fc722012-09-26 14:03:25 -0500496
akmhoqueffacaa82012-09-13 17:48:30 -0500497 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500498 if ( nlsr->debugging )
akmhoqued91401d2013-03-04 11:05:27 -0600499 printf("isValid bit not set for Router %s so LSA De"
500 "leted from LSDB\n",
501 name_lsa->header->orig_router->name);
akmhoque7b791452012-10-30 11:24:56 -0500502 if ( nlsr->detailed_logging )
akmhoqued91401d2013-03-04 11:05:27 -0600503 writeLogg(__FILE__,__FUNCTION__,__LINE__,"isValid b"
504 "it not set for Router %s so LSA Deleted from LSDB\n"
505 ,name_lsa->header->orig_router->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500506 }
507 else
508 {
509 new_name_lsa->header->isValid=name_lsa->header->isValid;
510 free(new_name_lsa->header->orig_time);
511 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
512 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
513 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
514 }
akmhoque7b791452012-10-30 11:24:56 -0500515 if ( nlsr->debugging )
516 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
517 if ( nlsr->detailed_logging )
518 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500519 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500520 if ( nlsr->debugging )
521 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
522 if ( nlsr->detailed_logging )
523 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500524 }
525 else
526 {
527 int is_npt_update=0;
528 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
529 {
530 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500531 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 -0500532 }
533
534 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500535 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
536 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
537 write_log_for_name_lsa(new_name_lsa);
538 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
539
akmhoqueffacaa82012-09-13 17:48:30 -0500540
541 free(new_name_lsa->header->orig_time);
542 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
543 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600544 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500545
546 new_name_lsa->header->isValid=name_lsa->header->isValid;
547
548 free(new_name_lsa->name_prefix->name);
549 free(new_name_lsa->name_prefix);
550 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
551 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
552 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
553 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
554
akmhoque9e9fc722012-09-26 14:03:25 -0500555
556 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
557 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
558 write_log_for_name_lsa(new_name_lsa);
559 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
560
akmhoque7b791452012-10-30 11:24:56 -0500561 if ( nlsr->debugging )
562 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
563 if ( nlsr->detailed_logging )
564 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
565
akmhoqueffacaa82012-09-13 17:48:30 -0500566 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500567
568 if ( nlsr->debugging )
569 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
570 if ( nlsr->detailed_logging )
571 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
572
akmhoqueffacaa82012-09-13 17:48:30 -0500573
574 if( is_npt_update == 1 )
575 {
akmhoquede61ba92012-09-20 22:19:12 -0500576 //struct hashtb *face_list;
577 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
578 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500579 {
akmhoquede61ba92012-09-20 22:19:12 -0500580
581 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 -0500582 if ( check == HT_NEW_ENTRY )
583 {
akmhoque7b791452012-10-30 11:24:56 -0500584 if ( nlsr->debugging )
585 printf("Added in npt \n");
586 if ( nlsr->detailed_logging )
587 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500588 }
589 }
590 else
591 {
akmhoquede61ba92012-09-20 22:19:12 -0500592 int *faces=malloc(num_next_hop*sizeof(int));
593 int *route_costs=malloc(num_next_hop*sizeof(int));
594 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500595
596 if ( nlsr->debugging )
597 {
598 printf("Printing from install_name_lsa \n");
599 int j;
600 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500601 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500602 }
603 if ( nlsr->detailed_logging )
604 {
605 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
606 int j;
607 for(j=0;j<num_next_hop;j++)
608 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
609 }
610
akmhoquede61ba92012-09-20 22:19:12 -0500611
612 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 -0500613 if ( check == HT_NEW_ENTRY )
614 {
akmhoque7b791452012-10-30 11:24:56 -0500615 if ( nlsr->debugging )
616 printf("Added in npt \n");
617 if ( nlsr->detailed_logging )
618 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500619 }
akmhoquede61ba92012-09-20 22:19:12 -0500620 free(faces);
621 free(route_costs);
622
akmhoqueffacaa82012-09-13 17:48:30 -0500623 }
akmhoquede61ba92012-09-20 22:19:12 -0500624
akmhoqueffacaa82012-09-13 17:48:30 -0500625 }
626 }
627 }
628
akmhoque3560cb62012-09-09 10:52:30 -0500629 }
akmhoque53f64222012-09-05 13:57:51 -0500630
akmhoqueffacaa82012-09-13 17:48:30 -0500631 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500632
akmhoquef5537b42013-02-22 08:33:32 -0600633 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500634}
635
akmhoquec25f2242013-03-15 00:24:43 -0500636/**
637* Write log for name LSA
638*/
639
akmhoque9e9fc722012-09-26 14:03:25 -0500640void
641write_log_for_name_lsa(struct nlsa *name_lsa)
642{
643
644 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
645 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
646 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500647 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
648 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
649 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
650 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500651 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
652 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
653 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
654 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
655}
akmhoque53f64222012-09-05 13:57:51 -0500656
akmhoque03004e62012-09-06 01:12:28 -0500657void
658print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500659{
akmhoque53f64222012-09-05 13:57:51 -0500660
akmhoque7b791452012-10-30 11:24:56 -0500661 if ( nlsr->debugging )
662 {
663 printf("-----------Name LSA Content---------------\n");
664 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
665 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
666 printf(" LS Type : %d\n",name_lsa->header->ls_type);
667 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
668 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
669 printf(" Is Valid : %d\n",name_lsa->header->isValid);
670 printf(" LSA Data \n");
671 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
672 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
673
674 printf("\n");
675 }
akmhoquef71d9082012-08-22 12:51:53 -0400676}
677
678void
679print_name_lsdb(void)
680{
akmhoque7b791452012-10-30 11:24:56 -0500681 if ( nlsr->debugging )
682 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500683 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400684 struct nlsa *name_lsa;
685
686 struct hashtb_enumerator ee;
687 struct hashtb_enumerator *e = &ee;
688
689 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500690 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400691
akmhoque53f64222012-09-05 13:57:51 -0500692 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400693 {
akmhoque7b791452012-10-30 11:24:56 -0500694 if ( nlsr->debugging )
695 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400696 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500697 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400698 hashtb_next(e);
699 }
700
701 hashtb_end(e);
702
akmhoque3171d652012-11-13 11:44:33 -0600703 if ( nlsr->debugging )
704 printf("\n");
705 if ( nlsr->detailed_logging )
706 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500707}
708
akmhoquec25f2242013-03-15 00:24:43 -0500709/**
710* Build and install name LSA by the parameter provided
711*/
712
akmhoque03004e62012-09-06 01:12:28 -0500713
714void
akmhoquec25f2242013-03-15 00:24:43 -0500715build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,
716 char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500717{
akmhoque7b791452012-10-30 11:24:56 -0500718 if ( nlsr->debugging )
719 printf("build_and_install_others_name_lsa called \n");
720 if ( nlsr->detailed_logging )
721 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500722
akmhoque03004e62012-09-06 01:12:28 -0500723 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
724 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
725 print_name_lsa(name_lsa);
726 install_name_lsa(name_lsa);
727 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500728 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500729
akmhoquef5537b42013-02-22 08:33:32 -0600730 destroy_name_lsa(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500731
732}
733
akmhoquec25f2242013-03-15 00:24:43 -0500734/**
735* Build name LSA by the parameter provided
736*/
737
akmhoque53f64222012-09-05 13:57:51 -0500738void
akmhoquec25f2242013-03-15 00:24:43 -0500739build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long
740 int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500741{
akmhoque7b791452012-10-30 11:24:56 -0500742 if ( nlsr->debugging )
743 printf("build_others_name_lsa called\n");
744 if ( nlsr->detailed_logging )
745 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500746
akmhoquef5537b42013-02-22 08:33:32 -0600747 name_lsa->header=(struct nlsa_header *)calloc(1,sizeof(struct nlsa_header ));
akmhoque03004e62012-09-06 01:12:28 -0500748 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500749
akmhoquef5537b42013-02-22 08:33:32 -0600750 name_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
751 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500752
akmhoque03004e62012-09-06 01:12:28 -0500753 name_lsa->header->ls_id=ls_id;
akmhoquef5537b42013-02-22 08:33:32 -0600754 name_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
755 name_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
756 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque03004e62012-09-06 01:12:28 -0500757 name_lsa->header->orig_router->length=strlen(orig_router)+1;
758 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500759
akmhoquef5537b42013-02-22 08:33:32 -0600760 name_lsa->name_prefix=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
761 name_lsa->name_prefix->name=(char *)calloc(strlen(np)+1,sizeof(char));
762 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
akmhoque03004e62012-09-06 01:12:28 -0500763 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400764}
akmhoqued79438d2012-08-27 13:31:42 -0500765
766
akmhoqueb77b95f2013-02-08 12:28:47 -0600767void
768make_cor_lsa_key(char *key,struct clsa *cor_lsa)
769{
770 memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
771 memcpy(key+strlen(key),"/",1);
772 char ls_type[2];
773 sprintf(ls_type,"%d",cor_lsa->header->ls_type);
774 memcpy(key+strlen(key),ls_type,strlen(ls_type));
775 key[strlen(key)]='\0';
776}
akmhoqueffacaa82012-09-13 17:48:30 -0500777
778
akmhoque53f64222012-09-05 13:57:51 -0500779void
780make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500781{
akmhoque53f64222012-09-05 13:57:51 -0500782 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
783 memcpy(key+strlen(key),"/",1);
784 char ls_type[2];
785 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
786 memcpy(key+strlen(key),ls_type,strlen(ls_type));
787 key[strlen(key)]='\0';
788}
789
akmhoque03004e62012-09-06 01:12:28 -0500790int
791build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
792{
akmhoqueffacaa82012-09-13 17:48:30 -0500793 if(flags == CCN_SCHEDULE_CANCEL)
794 {
795 return -1;
796 }
797
798 nlsr_lock();
799
akmhoque7b791452012-10-30 11:24:56 -0500800 if ( nlsr->debugging )
801 printf("build_and_install_adj_lsa called \n");
802 if ( nlsr->detailed_logging )
803 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
804
805 if ( nlsr->debugging )
806 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
807 if ( nlsr->detailed_logging )
808 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500809
810 if(nlsr->adj_build_flag > 0)
811 {
akmhoque7b791452012-10-30 11:24:56 -0500812 if ( nlsr->debugging )
813 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
814 if ( nlsr->detailed_logging )
815 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
816
akmhoque03004e62012-09-06 01:12:28 -0500817 if ( is_adj_lsa_build()> 0)
818 {
819 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
820 build_adj_lsa(adj_lsa);
821 install_adj_lsa(adj_lsa);
822
akmhoqueb77b95f2013-02-08 12:28:47 -0600823 char lst[2];
824 memset(lst,0,2);
825 sprintf(lst,"%d",LS_TYPE_ADJ);
826
akmhoquef5537b42013-02-22 08:33:32 -0600827 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));
828 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 -0600829
830 if ( nlsr->debugging )
831 printf("Adj LSA Repo Key: %s \n",repo_key);
832
akmhoquef5537b42013-02-22 08:33:32 -0600833 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -0600834 make_adj_lsa_key(key,adj_lsa);
835 if ( nlsr->debugging )
836 printf("Adj LSA: %s \n",key);
837
akmhoquef5537b42013-02-22 08:33:32 -0600838 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
839 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
840 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600841 lsaid->length=strlen(key)+1;
842
843
844 write_adj_lsa_to_repo(repo_key, lsaid);
845
akmhoquef5537b42013-02-22 08:33:32 -0600846 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600847 free(repo_key);
848 free(lsaid->name);
849 free(lsaid);
850
akmhoquef5537b42013-02-22 08:33:32 -0600851 destroy_adj_lsa(adj_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -0600852
akmhoque03004e62012-09-06 01:12:28 -0500853 nlsr->adj_build_flag=0;
854 print_adj_lsdb();
855 }
856 else
857 {
akmhoque7b791452012-10-30 11:24:56 -0500858 if ( nlsr->debugging )
859 printf("Can not build adj LSA now\n");
860 if ( nlsr->detailed_logging )
861 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500862 }
863 }
864 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500865
866 nlsr_unlock();
867
akmhoque03004e62012-09-06 01:12:28 -0500868 return 0;
869}
870
871
872void
873build_adj_lsa(struct alsa * adj_lsa)
874{
akmhoque7b791452012-10-30 11:24:56 -0500875 if ( nlsr->debugging )
876 printf("build_adj_lsa called \n");
877 if ( nlsr->detailed_logging )
878 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500879
880 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500881
akmhoque03004e62012-09-06 01:12:28 -0500882 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
883 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
884 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
885 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
886 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
887 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
888
889 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
890
akmhoque03004e62012-09-06 01:12:28 -0500891
akmhoquef5537b42013-02-22 08:33:32 -0600892 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -0500893 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
894 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
895 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
896 free(time_stamp);
897
akmhoque03004e62012-09-06 01:12:28 -0500898 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500899
900
901 struct ccn_charbuf *c=ccn_charbuf_create();
902 get_active_nbr_adj_data(c);
903 char *data=ccn_charbuf_as_string(c);
904
akmhoquef5537b42013-02-22 08:33:32 -0600905 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
906 //memset(adj_lsa->body,0,strlen(data)+1);
akmhoque03004e62012-09-06 01:12:28 -0500907 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoquef5537b42013-02-22 08:33:32 -0600908 data[strlen(data)]='\0';
akmhoque03004e62012-09-06 01:12:28 -0500909 ccn_charbuf_destroy(&c);
910
akmhoque03004e62012-09-06 01:12:28 -0500911 nlsr->adj_build_count++;
912
913
914}
915
916
akmhoque53f64222012-09-05 13:57:51 -0500917void
918install_adj_lsa(struct alsa * adj_lsa)
919{
akmhoqued79438d2012-08-27 13:31:42 -0500920
akmhoque7b791452012-10-30 11:24:56 -0500921 if ( nlsr->debugging )
922 printf("install_adj_lsa called \n");
923 if ( nlsr->detailed_logging )
924 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
925
akmhoque03004e62012-09-06 01:12:28 -0500926
akmhoque53f64222012-09-05 13:57:51 -0500927
akmhoqueffacaa82012-09-13 17:48:30 -0500928
akmhoquef5537b42013-02-22 08:33:32 -0600929 char *key=(char *)calloc(adj_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueffacaa82012-09-13 17:48:30 -0500930 make_adj_lsa_key(key,adj_lsa);
akmhoqueffacaa82012-09-13 17:48:30 -0500931
akmhoque8876e982013-02-21 13:35:46 -0600932 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500933
934 struct hashtb_enumerator ee;
935 struct hashtb_enumerator *e = &ee;
936 int res;
937
938 hashtb_start(nlsr->lsdb->adj_lsdb, e);
939 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500940
akmhoque03004e62012-09-06 01:12:28 -0500941
akmhoque53f64222012-09-05 13:57:51 -0500942
akmhoque62c0c192012-09-24 07:49:25 -0500943 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500944 {
akmhoque62c0c192012-09-24 07:49:25 -0500945 if ( adj_lsa->no_link > 0)
946 {
akmhoque3171d652012-11-13 11:44:33 -0600947 if ( nlsr->debugging )
948 printf("New ADJ LSA... Adding to LSDB\n");
949 if ( nlsr->detailed_logging )
950 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
akmhoque62c0c192012-09-24 07:49:25 -0500951 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500952
akmhoquef5537b42013-02-22 08:33:32 -0600953 new_adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
akmhoque62c0c192012-09-24 07:49:25 -0500954 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
akmhoquef5537b42013-02-22 08:33:32 -0600955 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500956 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 -0500957
akmhoquef5537b42013-02-22 08:33:32 -0600958 new_adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
959 new_adj_lsa->header->orig_router->name=(char *)calloc(adj_lsa->header->orig_router->length,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500960 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
961 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500962
akmhoque62c0c192012-09-24 07:49:25 -0500963 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500964
akmhoque0b60ba92013-02-25 17:55:35 -0600965 //if(new_adj_lsa->body )
966 //free(new_adj_lsa->body);
akmhoquef5537b42013-02-22 08:33:32 -0600967 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
968 //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -0500969 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
970
971 add_next_hop_router(new_adj_lsa->header->orig_router->name);
972 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500973
974 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
975 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
976 write_log_for_adj_lsa(new_adj_lsa);
977 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500978 }
979 else
980 {
981 hashtb_delete(e);
982 }
akmhoque53f64222012-09-05 13:57:51 -0500983
akmhoque7b791452012-10-30 11:24:56 -0500984 if ( nlsr->debugging )
985 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
986 if ( nlsr->detailed_logging )
987 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
988
akmhoque53f64222012-09-05 13:57:51 -0500989 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500990
991 if ( nlsr->debugging )
992 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
993 if ( nlsr->detailed_logging )
994 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
995
akmhoqueffacaa82012-09-13 17:48:30 -0500996 }
997 else if(res == HT_OLD_ENTRY)
998 {
999 new_adj_lsa = e->data;
1000 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
1001 {
akmhoque7b791452012-10-30 11:24:56 -05001002 if ( nlsr->debugging )
1003 printf("Older/Duplicate Adj LSA. Discarded...\n");
1004 if ( nlsr->detailed_logging )
1005 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -05001006 }
1007 else
1008 {
akmhoqueffacaa82012-09-13 17:48:30 -05001009
akmhoque62c0c192012-09-24 07:49:25 -05001010 if ( adj_lsa->no_link > 0)
1011 {
akmhoque9e9fc722012-09-26 14:03:25 -05001012 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1013 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1014 write_log_for_adj_lsa(new_adj_lsa);
1015 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -05001016
akmhoque62c0c192012-09-24 07:49:25 -05001017 free(new_adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001018 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -05001019 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
1020
1021 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -05001022
akmhoquef5537b42013-02-22 08:33:32 -06001023 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
1024 //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -05001025 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -05001026
akmhoque62c0c192012-09-24 07:49:25 -05001027 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001028
1029 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1030 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1031 write_log_for_adj_lsa(new_adj_lsa);
1032 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -05001033 }
1034 else
1035 {
akmhoque9e9fc722012-09-26 14:03:25 -05001036 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1037 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1038 write_log_for_adj_lsa(new_adj_lsa);
1039 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1040
akmhoque62c0c192012-09-24 07:49:25 -05001041 hashtb_delete(e);
1042 }
akmhoque7b791452012-10-30 11:24:56 -05001043
1044 if ( nlsr->debugging )
1045 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1046 if ( nlsr->detailed_logging )
1047 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1048
akmhoqueffacaa82012-09-13 17:48:30 -05001049 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001050
1051 if ( nlsr->debugging )
1052 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1053 if ( nlsr->detailed_logging )
1054 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -05001055 }
1056
1057 }
1058 hashtb_end(e);
1059
1060 if ( !nlsr->is_route_calculation_scheduled )
1061 {
1062 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1063 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -05001064 }
1065
akmhoque03004e62012-09-06 01:12:28 -05001066
akmhoquef5537b42013-02-22 08:33:32 -06001067 free(key);
akmhoqueffacaa82012-09-13 17:48:30 -05001068
akmhoquef5537b42013-02-22 08:33:32 -06001069 //free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -05001070}
1071
1072void
akmhoque9e9fc722012-09-26 14:03:25 -05001073write_log_for_adj_lsa_body(const char *body, int no_link)
1074{
1075 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001076 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
akmhoque9e9fc722012-09-26 14:03:25 -05001077 memcpy(lsa_data,body,strlen(body)+1);
1078 char *sep="|";
1079 char *rem;
1080 char *rtr_id;
1081 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001082 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -05001083 char *metric;
1084
1085 if(no_link >0 )
1086 {
1087 rtr_id=strtok_r(lsa_data,sep,&rem);
1088 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001089 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001090 metric=strtok_r(NULL,sep,&rem);
1091
1092 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001093 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1094 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001095 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001096 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001097
1098
1099 for(i=1;i<no_link;i++)
1100 {
1101 rtr_id=strtok_r(NULL,sep,&rem);
1102 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001103 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001104 metric=strtok_r(NULL,sep,&rem);
1105 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001106 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1107 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001108 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001109 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001110
1111 }
1112 }
1113
akmhoquef5537b42013-02-22 08:33:32 -06001114 if(lsa_data)
1115 free(lsa_data);
akmhoque9e9fc722012-09-26 14:03:25 -05001116}
1117
1118
1119void
1120write_log_for_adj_lsa(struct alsa * adj_lsa)
1121{
1122 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001123 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1124 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1125 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1126 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001127 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001128 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001129
1130 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1131
1132 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1133
1134}
1135
1136void
akmhoque53f64222012-09-05 13:57:51 -05001137print_adj_lsa_body(const char *body, int no_link)
1138{
1139 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001140 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1141 //memset( lsa_data,0,strlen(body)+1);
akmhoque53f64222012-09-05 13:57:51 -05001142 memcpy(lsa_data,body,strlen(body)+1);
1143 char *sep="|";
1144 char *rem;
1145 char *rtr_id;
1146 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001147 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001148 char *metric;
1149
akmhoque53f64222012-09-05 13:57:51 -05001150 if(no_link >0 )
1151 {
1152 rtr_id=strtok_r(lsa_data,sep,&rem);
1153 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001154 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001155 metric=strtok_r(NULL,sep,&rem);
1156
akmhoqueb77b95f2013-02-08 12:28:47 -06001157 if ( nlsr->debugging ) {
1158 printf(" Link %d \n",i+1);
1159 printf(" Neighbor : %s \n",rtr_id);
1160 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001161 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001162 printf(" Metric : %s \n",metric);
1163 }
akmhoque53f64222012-09-05 13:57:51 -05001164
1165 for(i=1;i<no_link;i++)
1166 {
1167 rtr_id=strtok_r(NULL,sep,&rem);
1168 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001169 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001170 metric=strtok_r(NULL,sep,&rem);
1171 printf(" Link %d \n",i+1);
1172 printf(" Neighbor : %s \n",rtr_id);
1173 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001174 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001175 printf(" Metric : %s \n",metric);
1176
1177 }
1178 }
1179
akmhoquef5537b42013-02-22 08:33:32 -06001180 if( lsa_data )
1181 free(lsa_data);
akmhoque53f64222012-09-05 13:57:51 -05001182}
1183
1184void
1185print_adj_lsa(struct alsa * adj_lsa)
1186{
akmhoque7b791452012-10-30 11:24:56 -05001187 if ( nlsr->debugging )
1188 {
1189 printf("-----------ADJ LSA Content---------------\n");
1190 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1191 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1192 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1193 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1194 printf(" Lsa Data:\n");
1195 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001196
akmhoque7b791452012-10-30 11:24:56 -05001197 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1198 printf("\n");
1199 }
akmhoque53f64222012-09-05 13:57:51 -05001200
1201}
1202
1203void
1204print_adj_lsdb(void)
1205{
akmhoque7b791452012-10-30 11:24:56 -05001206 if ( nlsr->debugging )
1207 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001208 int i, adj_lsdb_element;
1209 struct alsa *adj_lsa;
1210
1211 struct hashtb_enumerator ee;
1212 struct hashtb_enumerator *e = &ee;
1213
1214 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1215 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1216
1217 for(i=0;i<adj_lsdb_element;i++)
1218 {
akmhoque7b791452012-10-30 11:24:56 -05001219 if ( nlsr->debugging )
1220 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001221 adj_lsa=e->data;
1222 print_adj_lsa(adj_lsa);
1223 hashtb_next(e);
1224 }
1225
1226 hashtb_end(e);
1227
akmhoque3171d652012-11-13 11:44:33 -06001228 if ( nlsr->debugging )
1229 printf("\n");
1230 if ( nlsr->detailed_logging )
1231 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001232}
1233
1234void
akmhoque03004e62012-09-06 01:12:28 -05001235build_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 -05001236{
akmhoque7b791452012-10-30 11:24:56 -05001237 if ( nlsr->debugging )
1238 printf("build_and_install_others_adj_lsa called \n");
1239 if ( nlsr->detailed_logging )
1240 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001241 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1242 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001243 install_adj_lsa(adj_lsa);
1244
akmhoquef5537b42013-02-22 08:33:32 -06001245 destroy_adj_lsa(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001246
akmhoque03004e62012-09-06 01:12:28 -05001247 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001248
akmhoque53f64222012-09-05 13:57:51 -05001249}
1250
akmhoque03004e62012-09-06 01:12:28 -05001251
akmhoque53f64222012-09-05 13:57:51 -05001252void
akmhoque03004e62012-09-06 01:12:28 -05001253build_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 -05001254{
akmhoque7b791452012-10-30 11:24:56 -05001255 if ( nlsr->debugging )
1256 printf("build_others_adj_lsa called \n");
1257 if ( nlsr->detailed_logging )
1258 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001259
akmhoque03004e62012-09-06 01:12:28 -05001260 /*Filling Up Header Data */
akmhoquef5537b42013-02-22 08:33:32 -06001261 adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
1262 adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
1263 adj_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001264 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001265
akmhoque03004e62012-09-06 01:12:28 -05001266 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001267
akmhoque53f64222012-09-05 13:57:51 -05001268
akmhoque03004e62012-09-06 01:12:28 -05001269 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001270
akmhoquef5537b42013-02-22 08:33:32 -06001271 adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001272 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001273
akmhoque03004e62012-09-06 01:12:28 -05001274 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001275
akmhoquef5537b42013-02-22 08:33:32 -06001276 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001277 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001278
akmhoque53f64222012-09-05 13:57:51 -05001279}
1280
akmhoque03004e62012-09-06 01:12:28 -05001281
akmhoque53f64222012-09-05 13:57:51 -05001282long int
1283get_name_lsdb_num_element(void)
1284{
1285 long int num_element;
1286
1287
1288 struct hashtb_enumerator ee;
1289 struct hashtb_enumerator *e = &ee;
1290
1291 hashtb_start(nlsr->lsdb->name_lsdb, e);
1292 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1293 hashtb_end(e);
1294
1295 return num_element;
1296}
1297
1298long int
1299get_adj_lsdb_num_element(void)
1300{
1301 long int num_element;
1302
1303
1304 struct hashtb_enumerator ee;
1305 struct hashtb_enumerator *e = &ee;
1306
1307 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1308 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1309 hashtb_end(e);
1310
1311 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001312}
akmhoque03004e62012-09-06 01:12:28 -05001313
akmhoque03004e62012-09-06 01:12:28 -05001314
1315int
1316check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1317{
1318 int ret=0;
1319 struct ccn_charbuf *key=ccn_charbuf_create();
1320 ccn_charbuf_append_string(key,orig_router);
1321 ccn_charbuf_append_string(key,"/");
1322 ccn_charbuf_append_string(key,lst);
1323 ccn_charbuf_append_string(key,"/");
1324 ccn_charbuf_append_string(key,lsid);
1325
1326 int res;
1327 struct nlsa *name_lsa;
1328
1329 struct hashtb_enumerator ee;
1330 struct hashtb_enumerator *e = &ee;
1331
1332 hashtb_start(nlsr->lsdb->name_lsdb, e);
1333 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1334
1335 if( res == HT_NEW_ENTRY )
1336 {
1337 hashtb_delete(e);
1338 ret=1;
1339
1340 }
1341 else if(res == HT_OLD_ENTRY)
1342 {
1343 name_lsa=e->data;
1344 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1345 {
1346 ret=1;
1347 }
1348 }
1349
1350 hashtb_end(e);
1351
1352 ccn_charbuf_destroy(&key);
1353
1354 return ret;
1355}
1356
1357int
1358check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1359{
1360 int ret=0;
1361 struct ccn_charbuf *key=ccn_charbuf_create();
1362 ccn_charbuf_append_string(key,orig_router);
1363 ccn_charbuf_append_string(key,"/");
1364 ccn_charbuf_append_string(key,lst);
1365
1366 int res;
1367 struct alsa *adj_lsa;
1368
1369 struct hashtb_enumerator ee;
1370 struct hashtb_enumerator *e = &ee;
1371
1372 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1373 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1374
1375 if( res == HT_NEW_ENTRY )
1376 {
1377 hashtb_delete(e);
1378 ret=1;
1379
1380 }
1381 else if(res == HT_OLD_ENTRY)
1382 {
1383 adj_lsa=e->data;
1384 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1385 {
1386 ret=1;
1387 }
1388 }
1389
1390 hashtb_end(e);
1391
1392 ccn_charbuf_destroy(&key);
1393
1394 return ret;
1395}
1396
akmhoqueb77b95f2013-02-08 12:28:47 -06001397int
1398check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1399{
1400 int ret=0;
1401 struct ccn_charbuf *key=ccn_charbuf_create();
1402 ccn_charbuf_append_string(key,orig_router);
1403 ccn_charbuf_append_string(key,"/");
1404 ccn_charbuf_append_string(key,lst);
1405
1406 int res;
1407 struct clsa *cor_lsa;
1408
1409 struct hashtb_enumerator ee;
1410 struct hashtb_enumerator *e = &ee;
1411
1412 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1413 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1414
1415 if( res == HT_NEW_ENTRY )
1416 {
1417 hashtb_delete(e);
1418 ret=1;
1419
1420 }
1421 else if(res == HT_OLD_ENTRY)
1422 {
1423 cor_lsa=e->data;
1424 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1425 {
1426 ret=1;
1427 }
1428 }
1429
1430 hashtb_end(e);
1431
1432 ccn_charbuf_destroy(&key);
1433
1434 return ret;
1435}
1436
akmhoque03004e62012-09-06 01:12:28 -05001437void
1438get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1439{
akmhoque7b791452012-10-30 11:24:56 -05001440 if ( nlsr->debugging )
1441 printf("get_name_lsa_data called \n");
1442 if ( nlsr->detailed_logging )
1443 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001444
akmhoque8876e982013-02-21 13:35:46 -06001445 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001446
1447 struct hashtb_enumerator ee;
1448 struct hashtb_enumerator *e = &ee;
1449 int res;
1450
1451 hashtb_start(nlsr->lsdb->name_lsdb, e);
1452 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1453
1454 if( res == HT_OLD_ENTRY )
1455 {
1456 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001457
akmhoque7b791452012-10-30 11:24:56 -05001458 if ( nlsr->debugging )
1459 printf("NAME LSA found \n");
1460 if ( nlsr->detailed_logging )
1461 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001462
1463 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1464 ccn_charbuf_append_string(lsa_data,"|");
1465
1466 char *temp_length=(char *)malloc(20);
1467 memset(temp_length,0,20);
1468 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1469 ccn_charbuf_append_string(lsa_data,temp_length);
1470 free(temp_length);
1471 ccn_charbuf_append_string(lsa_data,"|");
1472
1473 char *temp_ltype=(char *)malloc(20);
1474 memset(temp_ltype,0,20);
1475 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1476 ccn_charbuf_append_string(lsa_data,temp_ltype);
1477 free(temp_ltype);
1478 ccn_charbuf_append_string(lsa_data,"|");
1479
1480 char *temp_lsid=(char *)malloc(20);
1481 memset(temp_lsid,0,20);
1482 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1483 ccn_charbuf_append_string(lsa_data,temp_lsid);
1484 free(temp_lsid);
1485 ccn_charbuf_append_string(lsa_data,"|");
1486
1487 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1488 ccn_charbuf_append_string(lsa_data,"|");
1489
1490 char *temp_valid=(char *)malloc(20);
1491 memset(temp_valid,0,20);
1492 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1493 ccn_charbuf_append_string(lsa_data,temp_valid);
1494 free(temp_valid);
1495 ccn_charbuf_append_string(lsa_data,"|");
1496
1497 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1498 ccn_charbuf_append_string(lsa_data,"|");
1499
1500 char *temp_npl=(char *)malloc(20);
1501 memset(temp_npl,0,20);
1502 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1503 ccn_charbuf_append_string(lsa_data,temp_npl);
1504 free(temp_npl);
1505 ccn_charbuf_append_string(lsa_data,"|");
1506
1507 }
1508 else if(res == HT_NEW_ENTRY)
1509 {
1510 hashtb_delete(e);
1511 }
1512
1513 hashtb_end(e);
1514}
1515
1516void
1517get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1518{
akmhoque7b791452012-10-30 11:24:56 -05001519 if ( nlsr->debugging )
1520 printf("get_adj_lsa_data called \n");
1521 if ( nlsr->detailed_logging )
1522 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001523
akmhoquececba942013-02-25 17:33:34 -06001524 struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoque03004e62012-09-06 01:12:28 -05001525
1526 struct hashtb_enumerator ee;
1527 struct hashtb_enumerator *e = &ee;
1528 int res;
1529
1530 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1531 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1532
1533 if( res == HT_OLD_ENTRY )
1534 {
1535 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001536
1537 if ( nlsr->debugging )
1538 printf("Adj LSA found \n");
1539 if ( nlsr->detailed_logging )
1540 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001541
1542 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1543 ccn_charbuf_append_string(lsa_data,"|");
1544
1545 char *temp_length=(char *)malloc(20);
1546 memset(temp_length,0,20);
1547 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1548 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001549 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001550 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001551
1552 char *temp_ltype=(char *)malloc(20);
1553 memset(temp_ltype,0,20);
1554 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1555 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001556 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001557 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001558
1559 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1560 ccn_charbuf_append_string(lsa_data,"|");
1561
1562 char *temp_nl=(char *)malloc(20);
1563 memset(temp_nl,0,20);
1564 sprintf(temp_nl,"%d",adj_lsa->no_link);
1565 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001566 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001567 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001568
1569 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1570
1571
1572 }
1573 else if(res == HT_NEW_ENTRY)
1574 {
1575 hashtb_delete(e);
1576 }
1577
1578 hashtb_end(e);
1579}
akmhoqueffacaa82012-09-13 17:48:30 -05001580
akmhoque3171d652012-11-13 11:44:33 -06001581void
1582make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1583{
1584
1585 if ( nlsr->debugging )
1586 printf("make_name_lsa_invalid called \n");
1587 if ( nlsr->detailed_logging )
1588 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1589
1590
1591 char lst[2];
1592 memset(lst,0,2);
1593 sprintf(lst,"%d",ls_type);
1594
1595 char lsid[10];
1596 memset(lsid,0,10);
1597 sprintf(lsid,"%ld",ls_id);
1598
1599
1600 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1601 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1602
1603
1604 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001605
1606 if ( nlsr->debugging )
1607 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001608
1609 struct nlsa *nlsa;
1610
1611 struct hashtb_enumerator ee;
1612 struct hashtb_enumerator *e = &ee;
1613
1614 int res;
1615
1616 hashtb_start(nlsr->lsdb->name_lsdb, e);
1617 res = hashtb_seek(e, key,strlen(key) , 0);
1618
1619 if( res == HT_OLD_ENTRY )
1620 {
1621 nlsa=e->data;
1622
1623 nlsa->header->isValid=0;
1624
1625 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1626 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1627 write_log_for_name_lsa(nlsa);
1628 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1629
1630 hashtb_delete(e);
1631 }
1632 else if( res == HT_NEW_ENTRY )
1633 {
1634 hashtb_delete(e);
1635 }
1636 hashtb_end(e);
1637
1638 if ( nlsr->debugging )
1639 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1640 if ( nlsr->detailed_logging )
1641 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1642
1643 set_new_lsdb_version();
1644
1645 if ( nlsr->debugging )
1646 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1647 if ( nlsr->detailed_logging )
1648 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1649
1650}
1651
akmhoquef5537b42013-02-22 08:33:32 -06001652
akmhoque866c2222013-02-12 10:49:33 -06001653int
1654delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001655{
akmhoqueb77b95f2013-02-08 12:28:47 -06001656
akmhoque7b791452012-10-30 11:24:56 -05001657 if ( nlsr->debugging )
1658 printf("delete_name_lsa called \n");
1659 if ( nlsr->detailed_logging )
1660 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001661
akmhoque866c2222013-02-12 10:49:33 -06001662 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -06001663
akmhoqueda5b6832012-09-13 22:33:55 -05001664
akmhoque7b791452012-10-30 11:24:56 -05001665 if ( nlsr->debugging )
1666 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1667 if ( nlsr->detailed_logging )
1668 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1669
akmhoqueda5b6832012-09-13 22:33:55 -05001670 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001671
1672 if ( nlsr->debugging )
1673 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1674 if ( nlsr->detailed_logging )
1675 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001676
akmhoqueda5b6832012-09-13 22:33:55 -05001677
1678 return 0;
1679}
1680
akmhoquef5537b42013-02-22 08:33:32 -06001681
akmhoque866c2222013-02-12 10:49:33 -06001682int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001683{
akmhoque866c2222013-02-12 10:49:33 -06001684
akmhoque7b791452012-10-30 11:24:56 -05001685 if ( nlsr->debugging )
1686 printf("delete_adj_lsa called \n");
1687 if ( nlsr->detailed_logging )
1688 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001689
akmhoque7b791452012-10-30 11:24:56 -05001690 if ( nlsr->debugging )
1691 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1692 if ( nlsr->detailed_logging )
1693 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1694
akmhoqueda5b6832012-09-13 22:33:55 -05001695 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001696
1697 if ( nlsr->debugging )
1698 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1699 if ( nlsr->detailed_logging )
1700 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1701
akmhoqueda5b6832012-09-13 22:33:55 -05001702
1703 if ( !nlsr->is_route_calculation_scheduled)
1704 {
1705 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1706 nlsr->is_route_calculation_scheduled=1;
1707 }
1708
akmhoqueda5b6832012-09-13 22:33:55 -05001709 return 0;
1710}
1711
akmhoqueffacaa82012-09-13 17:48:30 -05001712void
1713refresh_name_lsdb(void)
1714{
akmhoque7b791452012-10-30 11:24:56 -05001715 if ( nlsr->debugging )
1716 printf("refresh_name_lsdb called \n");
1717 if ( nlsr->detailed_logging )
1718 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001719
akmhoquef5537b42013-02-22 08:33:32 -06001720 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueffacaa82012-09-13 17:48:30 -05001721
1722 long int lsa_life_time;
1723
1724 int i, name_lsdb_element;
1725 struct nlsa *name_lsa;
1726
1727 struct hashtb_enumerator ee;
1728 struct hashtb_enumerator *e = &ee;
1729
1730 hashtb_start(nlsr->lsdb->name_lsdb, e);
1731 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1732
1733 for(i=0;i<name_lsdb_element;i++)
1734 {
1735 name_lsa=e->data;
1736
1737 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001738 if ( nlsr->debugging )
1739 printf("LSA Life Time: %ld \n",lsa_life_time);
1740 if ( nlsr->detailed_logging )
1741 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001742
1743 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1744 {
1745 if ( lsa_life_time > nlsr->lsa_refresh_time )
1746 {
akmhoque14b3f342012-09-14 10:39:02 -05001747 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1748 {
akmhoque7b791452012-10-30 11:24:56 -05001749 if ( nlsr->debugging )
1750 printf("Own Name LSA need to be refrshed\n");
1751 if ( nlsr->detailed_logging )
1752 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001753
1754 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1755 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1756 write_log_for_name_lsa(name_lsa);
1757 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1758
akmhoquef5537b42013-02-22 08:33:32 -06001759 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001760
akmhoque14b3f342012-09-14 10:39:02 -05001761 free(name_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001762 name_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoque14b3f342012-09-14 10:39:02 -05001763 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001764
1765 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1766 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1767 write_log_for_name_lsa(name_lsa);
1768 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001769
akmhoque14b3f342012-09-14 10:39:02 -05001770 free(current_time_stamp);
akmhoqued91401d2013-03-04 11:05:27 -06001771
1772 char lst[2];
1773 memset(lst,0,2);
1774 sprintf(lst,"%d",name_lsa->header->ls_type);
1775
1776 char lsid[10];
1777 memset(lsid,0,10);
1778 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1779
1780 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)
1781 +1+strlen(lst)+1+strlen(lsid)+1);
1782 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+
1783 strlen(lst)+1+strlen(lsid)+1);
1784
1785
1786 make_name_lsa_key(key, name_lsa->header->orig_router->name,
1787 name_lsa->header->ls_type,name_lsa->header->ls_id);
1788
1789 if ( nlsr->debugging )
1790 printf("Name LSA Key: %s \n",key);
1791
1792
1793 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+1+
1794 strlen(name_lsa->header->orig_router->name)
1795 +1+strlen(lst)+1+strlen(lsid)+1+
1796 strlen(name_lsa->header->orig_time)+16,
1797 sizeof(char));
1798 make_name_lsa_prefix_for_repo(repo_key,
1799 name_lsa->header->orig_router->name,
1800 name_lsa->header->ls_type,
1801 name_lsa->header->ls_id,
1802 name_lsa->header->orig_time,
1803 nlsr->slice_prefix);
1804
1805 if ( nlsr->debugging )
1806 printf("Name LSA Repo Key: %s \n",repo_key);
1807
1808 struct name_prefix *lsaid=(struct name_prefix *)
1809 calloc(1,sizeof(struct name_prefix));
1810 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1811 memcpy(lsaid->name,key,strlen(key)+1);
1812 lsaid->length=strlen(key)+1;
1813
1814
1815 write_name_lsa_to_repo(repo_key, lsaid);
1816
1817 free(key);
1818 free(repo_key);
1819 free(lsaid->name);
1820 free(lsaid);
1821
1822
akmhoque866c2222013-02-12 10:49:33 -06001823
1824 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001825 }
1826 else
akmhoquef5537b42013-02-22 08:33:32 -06001827 {
akmhoque866c2222013-02-12 10:49:33 -06001828 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1829 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1830 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1831 write_log_for_name_lsa(name_lsa);
1832 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001833
1834 destroy_name_lsa_component(name_lsa);
1835
akmhoque866c2222013-02-12 10:49:33 -06001836 hashtb_delete(e);
1837 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001838 }
akmhoqueda5b6832012-09-13 22:33:55 -05001839
akmhoque7b791452012-10-30 11:24:56 -05001840 if ( nlsr->debugging )
1841 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1842 if ( nlsr->detailed_logging )
1843 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1844
akmhoqueda5b6832012-09-13 22:33:55 -05001845 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001846
1847 if ( nlsr->debugging )
1848 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1849 if ( nlsr->detailed_logging )
1850 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1851
1852
akmhoqueda5b6832012-09-13 22:33:55 -05001853
1854 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001855 }
1856 else
1857 {
1858 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001859 }
1860 }
1861 else
1862 {
1863 if ( lsa_life_time > nlsr->router_dead_interval )
1864 {
akmhoque7b791452012-10-30 11:24:56 -05001865 if ( nlsr->debugging )
1866 printf("Others Name LSA need to be deleted\n");
1867 if ( nlsr->detailed_logging )
1868 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001869
akmhoque866c2222013-02-12 10:49:33 -06001870 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1871 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1872 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1873 write_log_for_name_lsa(name_lsa);
1874 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001875
1876 destroy_name_lsa_component(name_lsa);
akmhoque866c2222013-02-12 10:49:33 -06001877 hashtb_delete(e);
1878 i++;
1879 }
1880 else
1881 {
1882 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001883 }
1884 }
akmhoqueffacaa82012-09-13 17:48:30 -05001885 }
1886
1887 hashtb_end(e);
1888
1889 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001890
akmhoqueffacaa82012-09-13 17:48:30 -05001891
1892}
1893
akmhoqueda5b6832012-09-13 22:33:55 -05001894void
akmhoqueffacaa82012-09-13 17:48:30 -05001895refresh_adj_lsdb(void)
1896{
akmhoqueffacaa82012-09-13 17:48:30 -05001897
akmhoque7b791452012-10-30 11:24:56 -05001898 if ( nlsr->debugging )
1899 printf("refresh_adj_lsdb called \n");
1900 if ( nlsr->detailed_logging )
1901 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001902
akmhoquef5537b42013-02-22 08:33:32 -06001903 char *time_stamp=get_current_timestamp_micro_v2();
1904
akmhoqueffacaa82012-09-13 17:48:30 -05001905 long int lsa_life_time;
1906
1907 int i, adj_lsdb_element;
1908 struct alsa *adj_lsa;
1909
1910 struct hashtb_enumerator ee;
1911 struct hashtb_enumerator *e = &ee;
1912
1913 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1914 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1915
1916 for(i=0;i<adj_lsdb_element;i++)
1917 {
1918 adj_lsa=e->data;
1919
akmhoqueb77b95f2013-02-08 12:28:47 -06001920 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001921
1922 if ( nlsr->debugging )
1923 printf("LSA Life Time: %ld \n",lsa_life_time);
1924 if ( nlsr->detailed_logging )
1925 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001926
akmhoqueda5b6832012-09-13 22:33:55 -05001927 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1928 {
1929 if ( lsa_life_time > nlsr->lsa_refresh_time )
1930 {
akmhoque7b791452012-10-30 11:24:56 -05001931 if ( nlsr->debugging )
1932 printf("Own Adj LSA need to be refrshed\n");
1933 if ( nlsr->detailed_logging )
1934 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001935
akmhoquea98c2142012-10-25 15:22:24 -05001936 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1937 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1938 write_log_for_adj_lsa(adj_lsa);
1939 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1940
akmhoquef5537b42013-02-22 08:33:32 -06001941 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001942
1943 free(adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001944 adj_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoqueda5b6832012-09-13 22:33:55 -05001945 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1946
1947 free(current_time_stamp);
1948
akmhoquea98c2142012-10-25 15:22:24 -05001949 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1950 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1951 write_log_for_adj_lsa(adj_lsa);
1952 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001953
akmhoque7b791452012-10-30 11:24:56 -05001954 if ( nlsr->debugging )
1955 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1956 if ( nlsr->detailed_logging )
1957 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1958
akmhoqueda5b6832012-09-13 22:33:55 -05001959 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001960
1961 if ( nlsr->debugging )
1962 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1963 if ( nlsr->detailed_logging )
1964 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001965
akmhoqued91401d2013-03-04 11:05:27 -06001966
1967 char lst[2];
1968 memset(lst,0,2);
1969 sprintf(lst,"%d",LS_TYPE_ADJ);
1970
1971 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+
1972 strlen(adj_lsa->header->orig_time)+
1973 strlen(adj_lsa->header->orig_router->name)
1974 + strlen(lst) + 5+15,sizeof(char));
1975 make_adj_lsa_prefix_for_repo(repo_key,
1976 adj_lsa->header->orig_router->name,LS_TYPE_ADJ,
1977 adj_lsa->header->orig_time,nlsr->slice_prefix);
1978
1979 if ( nlsr->debugging )
1980 printf("Adj LSA Repo Key: %s \n",repo_key);
1981
1982 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,
1983 sizeof(char));
1984 make_adj_lsa_key(key,adj_lsa);
1985 if ( nlsr->debugging )
1986 printf("Adj LSA Key: %s \n",key);
1987
1988 struct name_prefix *lsaid=(struct name_prefix *)
1989 calloc(1,sizeof(struct name_prefix));
1990 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1991 memcpy(lsaid->name,key,strlen(key)+1);
1992 lsaid->length=strlen(key)+1;
1993
1994
1995 write_adj_lsa_to_repo(repo_key, lsaid);
1996
1997 free(key);
1998 free(repo_key);
1999 free(lsaid->name);
2000 free(lsaid);
2001
2002
2003
2004
2005
2006
akmhoqueda5b6832012-09-13 22:33:55 -05002007 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002008
2009
akmhoqueda5b6832012-09-13 22:33:55 -05002010 }
akmhoque866c2222013-02-12 10:49:33 -06002011
2012 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002013 }
2014 else
2015 {
2016 if ( lsa_life_time > nlsr->router_dead_interval )
2017 {
akmhoque7b791452012-10-30 11:24:56 -05002018
2019 if ( nlsr->debugging )
2020 printf("Others Adj LSA need to be deleted\n");
2021 if ( nlsr->detailed_logging )
2022 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06002023 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2024 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2025 write_log_for_adj_lsa(adj_lsa);
2026 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2027 delete_adj_lsa();
akmhoquef5537b42013-02-22 08:33:32 -06002028
2029 destroy_adj_lsa_component(adj_lsa);
akmhoque866c2222013-02-12 10:49:33 -06002030 hashtb_delete(e);
2031 i++;
2032
2033 }
2034 else
2035 {
2036 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002037 }
2038 }
akmhoquef5537b42013-02-22 08:33:32 -06002039
akmhoqueffacaa82012-09-13 17:48:30 -05002040 }
2041
2042 hashtb_end(e);
2043
2044 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002045}
2046
akmhoqueb77b95f2013-02-08 12:28:47 -06002047
2048void
2049refresh_cor_lsdb(void)
2050{
2051
2052 if ( nlsr->debugging )
2053 printf("refresh_cor_lsdb called \n");
2054 if ( nlsr->detailed_logging )
2055 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2056
akmhoquef5537b42013-02-22 08:33:32 -06002057 char *time_stamp=get_current_timestamp_micro_v2();
2058
akmhoqueb77b95f2013-02-08 12:28:47 -06002059 long int lsa_life_time;
2060
2061 int i, cor_lsdb_element;
2062 struct clsa *cor_lsa;
2063
2064 struct hashtb_enumerator ee;
2065 struct hashtb_enumerator *e = &ee;
2066
2067 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2068 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2069
2070 for(i=0;i<cor_lsdb_element;i++)
2071 {
2072 cor_lsa=e->data;
2073
2074 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2075
2076 if ( nlsr->debugging )
2077 printf("LSA Life Time: %ld \n",lsa_life_time);
2078 if ( nlsr->detailed_logging )
2079 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2080
2081 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2082 {
2083 if ( lsa_life_time > nlsr->lsa_refresh_time )
2084 {
2085 if ( nlsr->debugging )
2086 printf("Own Cor LSA need to be refrshed\n");
2087 if ( nlsr->detailed_logging )
2088 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2089
akmhoquef5537b42013-02-22 08:33:32 -06002090 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002091
2092 free(cor_lsa->header->orig_time);
2093 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2094 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2095 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2096
2097 free(current_time_stamp);
2098
akmhoqueb77b95f2013-02-08 12:28:47 -06002099 if ( nlsr->debugging )
2100 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2101 if ( nlsr->detailed_logging )
2102 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2103
2104 set_new_lsdb_version();
2105
2106 if ( nlsr->debugging )
2107 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2108 if ( nlsr->detailed_logging )
2109 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2110
2111 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002112 }
2113
2114 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002115 }
2116 else
2117 {
2118 if ( lsa_life_time > nlsr->router_dead_interval )
2119 {
2120
2121 if ( nlsr->debugging )
2122 printf("Others Adj LSA need to be deleted\n");
2123 if ( nlsr->detailed_logging )
2124 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoquef5537b42013-02-22 08:33:32 -06002125
2126 destroy_cor_lsa_component(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002127 hashtb_delete(e);
2128 i++;
2129 }
akmhoque866c2222013-02-12 10:49:33 -06002130 else
2131 {
2132 hashtb_next(e);
2133 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002134 }
2135
2136
akmhoque866c2222013-02-12 10:49:33 -06002137
akmhoqueb77b95f2013-02-08 12:28:47 -06002138 }
2139
2140 hashtb_end(e);
2141
2142 free(time_stamp);
2143}
2144
akmhoqueffacaa82012-09-13 17:48:30 -05002145int
2146refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2147{
2148 if(flags == CCN_SCHEDULE_CANCEL)
2149 {
2150 return -1;
2151 }
2152
2153 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002154
akmhoque7b791452012-10-30 11:24:56 -05002155 if ( nlsr->debugging )
2156 printf("refresh_lsdb called\n");
2157 if ( nlsr->detailed_logging )
2158 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002159
2160 refresh_name_lsdb();
2161 refresh_adj_lsdb();
2162
akmhoqueffacaa82012-09-13 17:48:30 -05002163 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002164
akmhoqueffacaa82012-09-13 17:48:30 -05002165 nlsr_unlock();
2166 return 0;
2167}
akmhoqueb77b95f2013-02-08 12:28:47 -06002168
2169void
2170write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2171{
2172 if ( nlsr->debugging )
2173 printf("write_adj_lsa_to_repo called\n");
2174 if ( nlsr->debugging )
2175 printf("Content Prefix: %s\n",repo_content_prefix);
2176
2177 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2178 get_adj_lsa_data(lsa_data,lsa_id);
2179 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002180 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002181
akmhoquec25f2242013-03-15 00:24:43 -05002182 //char *data;
2183 //data=ccn_charbuf_as_string(lsa_data);
2184 //data[strlen(data)]='\0';
akmhoquef5537b42013-02-22 08:33:32 -06002185
akmhoquec25f2242013-03-15 00:24:43 -05002186 //write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002187
akmhoquec25f2242013-03-15 00:24:43 -05002188 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoque323b5e92013-02-21 13:55:15 -06002189
akmhoquec25f2242013-03-15 00:24:43 -05002190 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002191}
2192
2193void
2194write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2195{
2196 if ( nlsr->debugging )
2197 printf("write_name_lsa_to_repo called\n");
2198 if ( nlsr->debugging )
2199 printf("Content Prefix: %s\n",repo_content_prefix);
2200
2201 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2202 get_name_lsa_data(lsa_data,lsa_id);
2203
2204 if ( nlsr->debugging )
2205 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2206
akmhoquec25f2242013-03-15 00:24:43 -05002207 //char *data;
2208 //data=ccn_charbuf_as_string(lsa_data);
2209 //data[strlen(data)]='\0';
akmhoque323b5e92013-02-21 13:55:15 -06002210
akmhoquec25f2242013-03-15 00:24:43 -05002211 //write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002212
akmhoquec25f2242013-03-15 00:24:43 -05002213 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
2214
2215 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002216}
2217
2218
2219void
2220write_name_lsdb_to_repo(char *slice_prefix)
2221{
2222 int i, name_lsdb_element;
2223
2224 struct nlsa *name_lsa;
2225 struct hashtb_enumerator ee;
2226 struct hashtb_enumerator *e = &ee;
2227
2228 hashtb_start(nlsr->lsdb->name_lsdb, e);
2229 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2230
2231 for(i=0;i<name_lsdb_element;i++)
2232 {
2233 name_lsa=e->data;
2234
2235 char lst[2];
2236 memset(lst,0,2);
2237 sprintf(lst,"%d",name_lsa->header->ls_type);
2238
2239 char lsid[10];
2240 memset(lsid,0,10);
2241 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2242
2243
2244 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2245 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2246
2247
2248 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2249
2250 if ( nlsr->debugging )
2251 printf("Name LSA Key: %s \n",key);
2252
2253
akmhoquef5537b42013-02-22 08:33:32 -06002254 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 -06002255 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);
2256
2257 if ( nlsr->debugging )
2258 printf("Name LSA Repo Key: %s \n",repo_key);
2259
akmhoquef5537b42013-02-22 08:33:32 -06002260 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
2261 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
2262 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002263 lsaid->length=strlen(key)+1;
2264
2265
2266 write_name_lsa_to_repo(repo_key, lsaid);
2267
2268 free(key);
2269 free(repo_key);
2270 free(lsaid->name);
2271 free(lsaid);
2272
2273 hashtb_next(e);
2274 }
2275
2276 hashtb_end(e);
2277
2278
2279}
2280
2281void
2282print_cor_lsa(struct clsa *cor_lsa)
2283{
2284 if ( nlsr->debugging )
2285 {
2286 printf("-----------Cor LSA Content---------------\n");
2287 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2288 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2289 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2290 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2291 printf(" LSA Data \n");
2292 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2293 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2294
2295 printf("\n");
2296 }
2297}
2298
2299void
2300print_cor_lsdb()
2301{
2302
2303 if ( nlsr->debugging )
2304 printf("print_cor_lsdb called \n");
2305
2306 struct hashtb_enumerator ee;
2307 struct hashtb_enumerator *e = &ee;
2308
2309 int i=1;
2310
2311 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2312 {
2313 if ( nlsr->debugging )
2314 printf("-----------Cor LSA (%d)---------------\n",i);
2315 struct clsa *cor_lsa=e->data;
2316 print_cor_lsa(cor_lsa);
2317 i++;
2318 }
2319 hashtb_end(e);
2320
2321 if ( nlsr->debugging )
2322 printf("\n");
2323 if ( nlsr->detailed_logging )
2324 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2325}
2326
2327void
2328install_cor_lsa(struct clsa *cor_lsa)
2329{
2330 if ( nlsr->debugging )
2331 printf("install_cor_lsa called \n");
2332 if ( nlsr->detailed_logging )
2333 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2334
2335
akmhoquececba942013-02-25 17:33:34 -06002336 //char *time_stamp=(char *)malloc(20);
2337 //memset(time_stamp,0,20);
2338 //get_current_timestamp_micro(time_stamp);
akmhoqueb77b95f2013-02-08 12:28:47 -06002339
2340
akmhoque569a93d2013-02-21 10:19:54 -06002341 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2342 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002343 make_cor_lsa_key(key,cor_lsa);
2344
2345 if ( nlsr->debugging )
2346 printf("Cor LSA key: %s \n",key);
2347
2348 struct hashtb_enumerator ee;
2349 struct hashtb_enumerator *e = &ee;
2350 int res;
2351
2352 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2353 res = hashtb_seek(e, key, strlen(key), 0);
2354
2355 if ( res == HT_NEW_ENTRY )
2356 {
2357 if ( nlsr->debugging )
2358 printf("New Cor LSA... \n");
2359
akmhoque8876e982013-02-21 13:35:46 -06002360 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002361 new_cor_lsa=e->data;
2362 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2363
2364 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2365 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
akmhoquececba942013-02-25 17:33:34 -06002366 //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002367 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2368 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2369
akmhoque483c1eb2013-03-08 00:51:09 -06002370 new_cor_lsa->header->orig_time=(char *)calloc(strlen(cor_lsa->header->orig_time)+1,sizeof(char)); //free
akmhoquececba942013-02-25 17:33:34 -06002371 //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
akmhoque483c1eb2013-03-08 00:51:09 -06002372 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2373 //new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002374
2375 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2376
2377 new_cor_lsa->cor_r=cor_lsa->cor_r;
2378 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2379 }
2380 else if ( res == HT_OLD_ENTRY )
2381 {
2382 if ( nlsr->debugging )
2383 printf("Cor LSA exists (Old)... \n");
2384 }
2385 hashtb_end(e);
2386
akmhoquef5537b42013-02-22 08:33:32 -06002387 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002388
2389}
2390
2391void
2392build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2393{
2394 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2395 cor_lsa->header->ls_type=LS_TYPE_COR;
2396
akmhoquef5537b42013-02-22 08:33:32 -06002397 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002398 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2399 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2400 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2401 free(time_stamp);
2402
akmhoquef5537b42013-02-22 08:33:32 -06002403 cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
2404 cor_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002405 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2406 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2407 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2408
2409 cor_lsa->cor_r=cor_r;
2410 cor_lsa->cor_theta=cor_theta;
2411
2412}
2413
2414void
2415build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2416{
2417 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2418 cor_lsa->header->ls_type=ls_type;
2419
2420 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2421 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002422 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002423
2424 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2425 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2426 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002427 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002428 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2429
2430 cor_lsa->cor_r=cor_r;
2431 cor_lsa->cor_theta=cor_theta;
2432
2433}
2434
2435void
2436build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2437{
2438 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2439 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2440 install_cor_lsa(cor_lsa);
2441
2442 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002443
akmhoquef5537b42013-02-22 08:33:32 -06002444 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002445}
2446
2447
2448void
2449build_and_install_cor_lsa()
2450{
2451
2452
2453
2454 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2455
2456 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2457 install_cor_lsa(cor_lsa);
2458
2459 write_cor_lsa_to_repo(cor_lsa);
akmhoquef5537b42013-02-22 08:33:32 -06002460 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002461
2462 print_cor_lsdb();
akmhoqueb77b95f2013-02-08 12:28:47 -06002463
2464}
2465
2466void
2467get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2468{
2469 if ( nlsr->debugging )
2470 printf("get_cor_lsa_data called \n");
2471 if ( nlsr->detailed_logging )
2472 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2473
akmhoquececba942013-02-25 17:33:34 -06002474 struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002475
2476 struct hashtb_enumerator ee;
2477 struct hashtb_enumerator *e = &ee;
2478 int res;
2479
2480 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2481 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2482
2483 if( res == HT_OLD_ENTRY )
2484 {
2485 cor_lsa=e->data;
2486
2487 if ( nlsr->debugging )
2488 printf("Cor LSA found \n");
2489 if ( nlsr->detailed_logging )
2490 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2491
2492 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2493 ccn_charbuf_append_string(lsa_data,"|");
2494
2495 char *temp_length=(char *)malloc(20);
2496 memset(temp_length,0,20);
2497 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2498 ccn_charbuf_append_string(lsa_data,temp_length);
2499 ccn_charbuf_append_string(lsa_data,"|");
2500 free(temp_length);
2501
2502 char *temp_ltype=(char *)malloc(20);
2503 memset(temp_ltype,0,20);
2504 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2505 ccn_charbuf_append_string(lsa_data,temp_ltype);
2506 ccn_charbuf_append_string(lsa_data,"|");
2507 free(temp_ltype);
2508
2509 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2510 ccn_charbuf_append_string(lsa_data,"|");
2511
2512 char *cor_r=(char *)malloc(20);
2513 memset(cor_r,0,20);
2514 sprintf(cor_r,"%f",cor_lsa->cor_r);
2515 ccn_charbuf_append_string(lsa_data,cor_r);
2516 ccn_charbuf_append_string(lsa_data,"|");
2517 free(cor_r);
2518
2519 char *cor_theta=(char *)malloc(20);
2520 memset(cor_theta,0,20);
2521 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2522 ccn_charbuf_append_string(lsa_data,cor_theta);
2523 ccn_charbuf_append_string(lsa_data,"|");
2524 free(cor_theta);
2525
2526 }
2527 else if(res == HT_NEW_ENTRY)
2528 {
2529 hashtb_delete(e);
2530 }
2531
2532 hashtb_end(e);
2533}
2534
2535void
2536write_cor_lsa_to_repo(struct clsa *cor_lsa)
2537{
2538
2539
2540 if ( nlsr->debugging )
2541 printf("write_cor_lsa_to_repo called\n");
2542
2543
akmhoquef5537b42013-02-22 08:33:32 -06002544 char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002545 make_cor_lsa_key(key,cor_lsa);
2546
2547 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2548 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002549
akmhoqueb77b95f2013-02-08 12:28:47 -06002550 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002551 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2552
akmhoqueb77b95f2013-02-08 12:28:47 -06002553 char *lst=(char *)malloc(20);
2554 memset(lst,0,20);
2555 sprintf(lst,"%d",cor_lsa->header->ls_type);
akmhoquef5537b42013-02-22 08:33:32 -06002556 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 -06002557 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);
2558
2559 if ( nlsr->debugging )
2560 printf("Cor LSA Repo Key: %s \n",repo_key);
2561
akmhoquec25f2242013-03-15 00:24:43 -05002562 //char *data;
2563 //data=ccn_charbuf_as_string(lsa_data);
2564 //data[strlen(data)]='\0';
akmhoquef5537b42013-02-22 08:33:32 -06002565
akmhoquec25f2242013-03-15 00:24:43 -05002566 //write_data_to_repo(data, repo_content_prefix);
2567
2568 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
akmhoque0800eda2013-02-21 14:17:52 -06002569
akmhoqueb77b95f2013-02-08 12:28:47 -06002570
2571
2572
2573 free(lst);
2574 free(key);
2575 free(repo_key);
akmhoquec25f2242013-03-15 00:24:43 -05002576 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002577}
2578
2579void
2580make_cor_lsa_key_by_router_name(char *key,char *router_name)
2581{
2582 memcpy(key+strlen(key),router_name,strlen(router_name));
2583 memcpy(key+strlen(key),"/",1);
2584 char ls_type[2];
2585 sprintf(ls_type,"%d",LS_TYPE_COR);
2586 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2587 key[strlen(key)]='\0';
2588}
2589
2590
2591double
2592get_hyperbolic_r(char *router)
2593{
2594 double ret=-1.0;
2595 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2596 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2597
2598
2599 struct clsa *cor_lsa;
2600 struct hashtb_enumerator ee;
2601 struct hashtb_enumerator *e = &ee;
2602 int res;
2603
2604 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2605 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2606
2607 if ( res == HT_OLD_ENTRY)
2608 {
2609 cor_lsa=e->data;
2610 ret=cor_lsa->cor_r;
2611 }
2612 else if(res == HT_NEW_ENTRY)
2613 {
2614 hashtb_delete(e);
2615 }
2616
2617 hashtb_end(e);
2618
2619 free(cor_lsa_key);
2620 return ret;
2621}
2622
2623double
2624get_hyperbolic_theta(char *router)
2625{
akmhoquef5537b42013-02-22 08:33:32 -06002626 double ret=-1.0;
akmhoqueb77b95f2013-02-08 12:28:47 -06002627 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2628 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2629
2630 struct clsa *cor_lsa;
2631 struct hashtb_enumerator ee;
2632 struct hashtb_enumerator *e = &ee;
2633 int res;
2634
2635 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2636 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2637
2638 if ( res == HT_OLD_ENTRY)
2639 {
2640 cor_lsa=e->data;
2641 ret=cor_lsa->cor_theta;
2642 }
2643 else if(res == HT_NEW_ENTRY)
2644 {
2645 hashtb_delete(e);
2646 }
2647
2648 hashtb_end(e);
2649
2650 free(cor_lsa_key);
2651 return ret;
2652}
akmhoquead584782013-02-22 10:56:03 -06002653
2654
2655void
2656destroy_name_lsdb(void)
2657{
2658 int i, name_lsdb_element;
2659 struct nlsa *name_lsa;
2660
2661 struct hashtb_enumerator ee;
2662 struct hashtb_enumerator *e = &ee;
2663
2664 hashtb_start(nlsr->lsdb->name_lsdb, e);
2665 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2666
2667 for(i=0;i<name_lsdb_element;i++)
2668 {
2669 name_lsa=e->data;
2670 destroy_name_lsa_component(name_lsa);
2671 hashtb_next(e);
2672 }
2673
2674 hashtb_end(e);
2675
2676 if ( nlsr->lsdb->name_lsdb )
2677 hashtb_destroy(&nlsr->lsdb->name_lsdb);
2678}
2679
2680void
2681destroy_adj_lsdb(void)
2682{
2683 int i, adj_lsdb_element;
2684 struct alsa *adj_lsa;
2685
2686 struct hashtb_enumerator ee;
2687 struct hashtb_enumerator *e = &ee;
2688
2689 hashtb_start(nlsr->lsdb->adj_lsdb, e);
2690 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
2691
2692 for(i=0;i<adj_lsdb_element;i++)
2693 {
2694 adj_lsa=e->data;
2695 destroy_adj_lsa_component(adj_lsa);
2696 hashtb_next(e);
2697 }
2698
2699 hashtb_end(e);
2700 if(nlsr->lsdb->adj_lsdb )
2701 hashtb_destroy(&nlsr->lsdb->adj_lsdb);
2702}
2703
2704void
2705destroy_cor_lsdb(void)
2706{
2707 int i, cor_lsdb_element;
2708 struct clsa *cor_lsa;
2709
2710 struct hashtb_enumerator ee;
2711 struct hashtb_enumerator *e = &ee;
2712
2713 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2714 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2715
2716 for(i=0;i<cor_lsdb_element;i++)
2717 {
2718 cor_lsa=e->data;
2719 destroy_cor_lsa_component(cor_lsa);
2720 hashtb_next(e);
2721 }
2722
2723 hashtb_end(e);
2724 if(nlsr->lsdb->cor_lsdb )
2725 hashtb_destroy(&nlsr->lsdb->cor_lsdb);
2726}
2727
2728void
2729destroy_lsdb(void)
2730{
2731 destroy_name_lsdb();
2732 destroy_adj_lsdb();
2733 destroy_cor_lsdb();
2734
2735 if ( nlsr->lsdb->lsdb_version )
2736 free(nlsr->lsdb->lsdb_version);
2737 if ( nlsr->lsdb )
2738 free(nlsr->lsdb);
2739}