blob: c1d484f30796a985b7518915e4a7e42eeffce915 [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
akmhoque80817e22013-03-15 08:13:41 -0500932 struct alsa *new_adj_lsa;
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;
akmhoque80817e22013-03-15 08:13:41 -0500964
akmhoquef5537b42013-02-22 08:33:32 -0600965 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -0500966 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
967
968 add_next_hop_router(new_adj_lsa->header->orig_router->name);
969 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500970
971 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
972 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
973 write_log_for_adj_lsa(new_adj_lsa);
974 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500975 }
976 else
977 {
978 hashtb_delete(e);
979 }
akmhoque53f64222012-09-05 13:57:51 -0500980
akmhoque7b791452012-10-30 11:24:56 -0500981 if ( nlsr->debugging )
982 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
983 if ( nlsr->detailed_logging )
984 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
985
akmhoque53f64222012-09-05 13:57:51 -0500986 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500987
988 if ( nlsr->debugging )
989 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
990 if ( nlsr->detailed_logging )
991 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
992
akmhoqueffacaa82012-09-13 17:48:30 -0500993 }
994 else if(res == HT_OLD_ENTRY)
995 {
996 new_adj_lsa = e->data;
997 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
998 {
akmhoque7b791452012-10-30 11:24:56 -0500999 if ( nlsr->debugging )
1000 printf("Older/Duplicate Adj LSA. Discarded...\n");
1001 if ( nlsr->detailed_logging )
1002 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -05001003 }
1004 else
1005 {
akmhoqueffacaa82012-09-13 17:48:30 -05001006
akmhoque62c0c192012-09-24 07:49:25 -05001007 if ( adj_lsa->no_link > 0)
1008 {
akmhoque9e9fc722012-09-26 14:03:25 -05001009 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1010 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1011 write_log_for_adj_lsa(new_adj_lsa);
1012 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -05001013
akmhoque62c0c192012-09-24 07:49:25 -05001014 free(new_adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001015 new_adj_lsa->header->orig_time=(char *)calloc(strlen(adj_lsa->header->orig_time)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -05001016 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
1017
1018 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoquef5537b42013-02-22 08:33:32 -06001019 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -05001020 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -05001021 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001022
1023 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1024 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1025 write_log_for_adj_lsa(new_adj_lsa);
1026 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -05001027 }
1028 else
1029 {
akmhoque9e9fc722012-09-26 14:03:25 -05001030 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1031 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1032 write_log_for_adj_lsa(new_adj_lsa);
1033 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1034
akmhoque62c0c192012-09-24 07:49:25 -05001035 hashtb_delete(e);
1036 }
akmhoque7b791452012-10-30 11:24:56 -05001037
1038 if ( nlsr->debugging )
1039 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1040 if ( nlsr->detailed_logging )
1041 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1042
akmhoqueffacaa82012-09-13 17:48:30 -05001043 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001044
1045 if ( nlsr->debugging )
1046 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1047 if ( nlsr->detailed_logging )
1048 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -05001049 }
1050
1051 }
1052 hashtb_end(e);
1053
1054 if ( !nlsr->is_route_calculation_scheduled )
1055 {
1056 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1057 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -05001058 }
1059
akmhoque03004e62012-09-06 01:12:28 -05001060
akmhoquef5537b42013-02-22 08:33:32 -06001061 free(key);
akmhoqueffacaa82012-09-13 17:48:30 -05001062
akmhoquef5537b42013-02-22 08:33:32 -06001063 //free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -05001064}
1065
1066void
akmhoque9e9fc722012-09-26 14:03:25 -05001067write_log_for_adj_lsa_body(const char *body, int no_link)
1068{
1069 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001070 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
akmhoque9e9fc722012-09-26 14:03:25 -05001071 memcpy(lsa_data,body,strlen(body)+1);
1072 char *sep="|";
1073 char *rem;
1074 char *rtr_id;
1075 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001076 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -05001077 char *metric;
1078
1079 if(no_link >0 )
1080 {
1081 rtr_id=strtok_r(lsa_data,sep,&rem);
1082 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001083 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001084 metric=strtok_r(NULL,sep,&rem);
1085
1086 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001087 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1088 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001089 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001090 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001091
1092
1093 for(i=1;i<no_link;i++)
1094 {
1095 rtr_id=strtok_r(NULL,sep,&rem);
1096 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001097 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001098 metric=strtok_r(NULL,sep,&rem);
1099 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001100 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1101 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001102 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001103 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001104
1105 }
1106 }
1107
akmhoquef5537b42013-02-22 08:33:32 -06001108 if(lsa_data)
1109 free(lsa_data);
akmhoque9e9fc722012-09-26 14:03:25 -05001110}
1111
1112
1113void
1114write_log_for_adj_lsa(struct alsa * adj_lsa)
1115{
1116 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001117 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1118 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1119 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1120 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001121 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001122 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001123
1124 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1125
1126 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1127
1128}
1129
1130void
akmhoque53f64222012-09-05 13:57:51 -05001131print_adj_lsa_body(const char *body, int no_link)
1132{
1133 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001134 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1135 //memset( lsa_data,0,strlen(body)+1);
akmhoque53f64222012-09-05 13:57:51 -05001136 memcpy(lsa_data,body,strlen(body)+1);
1137 char *sep="|";
1138 char *rem;
1139 char *rtr_id;
1140 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001141 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001142 char *metric;
1143
akmhoque53f64222012-09-05 13:57:51 -05001144 if(no_link >0 )
1145 {
1146 rtr_id=strtok_r(lsa_data,sep,&rem);
1147 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001148 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001149 metric=strtok_r(NULL,sep,&rem);
1150
akmhoqueb77b95f2013-02-08 12:28:47 -06001151 if ( nlsr->debugging ) {
1152 printf(" Link %d \n",i+1);
1153 printf(" Neighbor : %s \n",rtr_id);
1154 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001155 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001156 printf(" Metric : %s \n",metric);
1157 }
akmhoque53f64222012-09-05 13:57:51 -05001158
1159 for(i=1;i<no_link;i++)
1160 {
1161 rtr_id=strtok_r(NULL,sep,&rem);
1162 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001163 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001164 metric=strtok_r(NULL,sep,&rem);
1165 printf(" Link %d \n",i+1);
1166 printf(" Neighbor : %s \n",rtr_id);
1167 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001168 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001169 printf(" Metric : %s \n",metric);
1170
1171 }
1172 }
1173
akmhoquef5537b42013-02-22 08:33:32 -06001174 if( lsa_data )
1175 free(lsa_data);
akmhoque53f64222012-09-05 13:57:51 -05001176}
1177
1178void
1179print_adj_lsa(struct alsa * adj_lsa)
1180{
akmhoque7b791452012-10-30 11:24:56 -05001181 if ( nlsr->debugging )
1182 {
1183 printf("-----------ADJ LSA Content---------------\n");
1184 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1185 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1186 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1187 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1188 printf(" Lsa Data:\n");
1189 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001190
akmhoque7b791452012-10-30 11:24:56 -05001191 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1192 printf("\n");
1193 }
akmhoque53f64222012-09-05 13:57:51 -05001194
1195}
1196
1197void
1198print_adj_lsdb(void)
1199{
akmhoque7b791452012-10-30 11:24:56 -05001200 if ( nlsr->debugging )
1201 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001202 int i, adj_lsdb_element;
1203 struct alsa *adj_lsa;
1204
1205 struct hashtb_enumerator ee;
1206 struct hashtb_enumerator *e = &ee;
1207
1208 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1209 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1210
1211 for(i=0;i<adj_lsdb_element;i++)
1212 {
akmhoque7b791452012-10-30 11:24:56 -05001213 if ( nlsr->debugging )
1214 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001215 adj_lsa=e->data;
1216 print_adj_lsa(adj_lsa);
1217 hashtb_next(e);
1218 }
1219
1220 hashtb_end(e);
1221
akmhoque3171d652012-11-13 11:44:33 -06001222 if ( nlsr->debugging )
1223 printf("\n");
1224 if ( nlsr->detailed_logging )
1225 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001226}
1227
1228void
akmhoque03004e62012-09-06 01:12:28 -05001229build_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 -05001230{
akmhoque7b791452012-10-30 11:24:56 -05001231 if ( nlsr->debugging )
1232 printf("build_and_install_others_adj_lsa called \n");
1233 if ( nlsr->detailed_logging )
1234 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001235 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1236 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001237 install_adj_lsa(adj_lsa);
1238
akmhoquef5537b42013-02-22 08:33:32 -06001239 destroy_adj_lsa(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001240
akmhoque03004e62012-09-06 01:12:28 -05001241 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001242
akmhoque53f64222012-09-05 13:57:51 -05001243}
1244
akmhoque03004e62012-09-06 01:12:28 -05001245
akmhoque53f64222012-09-05 13:57:51 -05001246void
akmhoque03004e62012-09-06 01:12:28 -05001247build_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 -05001248{
akmhoque7b791452012-10-30 11:24:56 -05001249 if ( nlsr->debugging )
1250 printf("build_others_adj_lsa called \n");
1251 if ( nlsr->detailed_logging )
1252 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001253
akmhoque03004e62012-09-06 01:12:28 -05001254 /*Filling Up Header Data */
akmhoquef5537b42013-02-22 08:33:32 -06001255 adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
1256 adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
1257 adj_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001258 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001259
akmhoque03004e62012-09-06 01:12:28 -05001260 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001261
akmhoque53f64222012-09-05 13:57:51 -05001262
akmhoque03004e62012-09-06 01:12:28 -05001263 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001264
akmhoquef5537b42013-02-22 08:33:32 -06001265 adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001266 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001267
akmhoque03004e62012-09-06 01:12:28 -05001268 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001269
akmhoquef5537b42013-02-22 08:33:32 -06001270 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001271 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001272
akmhoque53f64222012-09-05 13:57:51 -05001273}
1274
akmhoque03004e62012-09-06 01:12:28 -05001275
akmhoque53f64222012-09-05 13:57:51 -05001276long int
1277get_name_lsdb_num_element(void)
1278{
1279 long int num_element;
1280
1281
1282 struct hashtb_enumerator ee;
1283 struct hashtb_enumerator *e = &ee;
1284
1285 hashtb_start(nlsr->lsdb->name_lsdb, e);
1286 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1287 hashtb_end(e);
1288
1289 return num_element;
1290}
1291
1292long int
1293get_adj_lsdb_num_element(void)
1294{
1295 long int num_element;
1296
1297
1298 struct hashtb_enumerator ee;
1299 struct hashtb_enumerator *e = &ee;
1300
1301 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1302 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1303 hashtb_end(e);
1304
1305 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001306}
akmhoque03004e62012-09-06 01:12:28 -05001307
akmhoque03004e62012-09-06 01:12:28 -05001308
1309int
1310check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1311{
1312 int ret=0;
1313 struct ccn_charbuf *key=ccn_charbuf_create();
1314 ccn_charbuf_append_string(key,orig_router);
1315 ccn_charbuf_append_string(key,"/");
1316 ccn_charbuf_append_string(key,lst);
1317 ccn_charbuf_append_string(key,"/");
1318 ccn_charbuf_append_string(key,lsid);
1319
1320 int res;
1321 struct nlsa *name_lsa;
1322
1323 struct hashtb_enumerator ee;
1324 struct hashtb_enumerator *e = &ee;
1325
1326 hashtb_start(nlsr->lsdb->name_lsdb, e);
1327 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1328
1329 if( res == HT_NEW_ENTRY )
1330 {
1331 hashtb_delete(e);
1332 ret=1;
1333
1334 }
1335 else if(res == HT_OLD_ENTRY)
1336 {
1337 name_lsa=e->data;
1338 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1339 {
1340 ret=1;
1341 }
1342 }
1343
1344 hashtb_end(e);
1345
1346 ccn_charbuf_destroy(&key);
1347
1348 return ret;
1349}
1350
1351int
1352check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1353{
1354 int ret=0;
1355 struct ccn_charbuf *key=ccn_charbuf_create();
1356 ccn_charbuf_append_string(key,orig_router);
1357 ccn_charbuf_append_string(key,"/");
1358 ccn_charbuf_append_string(key,lst);
1359
1360 int res;
1361 struct alsa *adj_lsa;
1362
1363 struct hashtb_enumerator ee;
1364 struct hashtb_enumerator *e = &ee;
1365
1366 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1367 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1368
1369 if( res == HT_NEW_ENTRY )
1370 {
1371 hashtb_delete(e);
1372 ret=1;
1373
1374 }
1375 else if(res == HT_OLD_ENTRY)
1376 {
1377 adj_lsa=e->data;
1378 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1379 {
1380 ret=1;
1381 }
1382 }
1383
1384 hashtb_end(e);
1385
1386 ccn_charbuf_destroy(&key);
1387
1388 return ret;
1389}
1390
akmhoqueb77b95f2013-02-08 12:28:47 -06001391int
1392check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1393{
1394 int ret=0;
1395 struct ccn_charbuf *key=ccn_charbuf_create();
1396 ccn_charbuf_append_string(key,orig_router);
1397 ccn_charbuf_append_string(key,"/");
1398 ccn_charbuf_append_string(key,lst);
1399
1400 int res;
1401 struct clsa *cor_lsa;
1402
1403 struct hashtb_enumerator ee;
1404 struct hashtb_enumerator *e = &ee;
1405
1406 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1407 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1408
1409 if( res == HT_NEW_ENTRY )
1410 {
1411 hashtb_delete(e);
1412 ret=1;
1413
1414 }
1415 else if(res == HT_OLD_ENTRY)
1416 {
1417 cor_lsa=e->data;
1418 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1419 {
1420 ret=1;
1421 }
1422 }
1423
1424 hashtb_end(e);
1425
1426 ccn_charbuf_destroy(&key);
1427
1428 return ret;
1429}
1430
akmhoque03004e62012-09-06 01:12:28 -05001431void
1432get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1433{
akmhoque7b791452012-10-30 11:24:56 -05001434 if ( nlsr->debugging )
1435 printf("get_name_lsa_data called \n");
1436 if ( nlsr->detailed_logging )
1437 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001438
akmhoque8876e982013-02-21 13:35:46 -06001439 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001440
1441 struct hashtb_enumerator ee;
1442 struct hashtb_enumerator *e = &ee;
1443 int res;
1444
1445 hashtb_start(nlsr->lsdb->name_lsdb, e);
1446 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1447
1448 if( res == HT_OLD_ENTRY )
1449 {
1450 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001451
akmhoque7b791452012-10-30 11:24:56 -05001452 if ( nlsr->debugging )
1453 printf("NAME LSA found \n");
1454 if ( nlsr->detailed_logging )
1455 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001456
1457 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1458 ccn_charbuf_append_string(lsa_data,"|");
1459
1460 char *temp_length=(char *)malloc(20);
1461 memset(temp_length,0,20);
1462 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1463 ccn_charbuf_append_string(lsa_data,temp_length);
1464 free(temp_length);
1465 ccn_charbuf_append_string(lsa_data,"|");
1466
1467 char *temp_ltype=(char *)malloc(20);
1468 memset(temp_ltype,0,20);
1469 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1470 ccn_charbuf_append_string(lsa_data,temp_ltype);
1471 free(temp_ltype);
1472 ccn_charbuf_append_string(lsa_data,"|");
1473
1474 char *temp_lsid=(char *)malloc(20);
1475 memset(temp_lsid,0,20);
1476 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1477 ccn_charbuf_append_string(lsa_data,temp_lsid);
1478 free(temp_lsid);
1479 ccn_charbuf_append_string(lsa_data,"|");
1480
1481 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1482 ccn_charbuf_append_string(lsa_data,"|");
1483
1484 char *temp_valid=(char *)malloc(20);
1485 memset(temp_valid,0,20);
1486 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1487 ccn_charbuf_append_string(lsa_data,temp_valid);
1488 free(temp_valid);
1489 ccn_charbuf_append_string(lsa_data,"|");
1490
1491 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1492 ccn_charbuf_append_string(lsa_data,"|");
1493
1494 char *temp_npl=(char *)malloc(20);
1495 memset(temp_npl,0,20);
1496 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1497 ccn_charbuf_append_string(lsa_data,temp_npl);
1498 free(temp_npl);
1499 ccn_charbuf_append_string(lsa_data,"|");
1500
1501 }
1502 else if(res == HT_NEW_ENTRY)
1503 {
1504 hashtb_delete(e);
1505 }
1506
1507 hashtb_end(e);
1508}
1509
1510void
1511get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1512{
akmhoque7b791452012-10-30 11:24:56 -05001513 if ( nlsr->debugging )
1514 printf("get_adj_lsa_data called \n");
1515 if ( nlsr->detailed_logging )
1516 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001517
akmhoquececba942013-02-25 17:33:34 -06001518 struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoque03004e62012-09-06 01:12:28 -05001519
1520 struct hashtb_enumerator ee;
1521 struct hashtb_enumerator *e = &ee;
1522 int res;
1523
1524 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1525 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1526
1527 if( res == HT_OLD_ENTRY )
1528 {
1529 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001530
1531 if ( nlsr->debugging )
1532 printf("Adj LSA found \n");
1533 if ( nlsr->detailed_logging )
1534 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001535
1536 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1537 ccn_charbuf_append_string(lsa_data,"|");
1538
1539 char *temp_length=(char *)malloc(20);
1540 memset(temp_length,0,20);
1541 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1542 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001543 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001544 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001545
1546 char *temp_ltype=(char *)malloc(20);
1547 memset(temp_ltype,0,20);
1548 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1549 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001550 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001551 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001552
1553 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1554 ccn_charbuf_append_string(lsa_data,"|");
1555
1556 char *temp_nl=(char *)malloc(20);
1557 memset(temp_nl,0,20);
1558 sprintf(temp_nl,"%d",adj_lsa->no_link);
1559 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001560 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001561 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001562
1563 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1564
1565
1566 }
1567 else if(res == HT_NEW_ENTRY)
1568 {
1569 hashtb_delete(e);
1570 }
1571
1572 hashtb_end(e);
1573}
akmhoqueffacaa82012-09-13 17:48:30 -05001574
akmhoque3171d652012-11-13 11:44:33 -06001575void
1576make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1577{
1578
1579 if ( nlsr->debugging )
1580 printf("make_name_lsa_invalid called \n");
1581 if ( nlsr->detailed_logging )
1582 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1583
1584
1585 char lst[2];
1586 memset(lst,0,2);
1587 sprintf(lst,"%d",ls_type);
1588
1589 char lsid[10];
1590 memset(lsid,0,10);
1591 sprintf(lsid,"%ld",ls_id);
1592
1593
1594 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1595 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1596
1597
1598 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001599
1600 if ( nlsr->debugging )
1601 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001602
1603 struct nlsa *nlsa;
1604
1605 struct hashtb_enumerator ee;
1606 struct hashtb_enumerator *e = &ee;
1607
1608 int res;
1609
1610 hashtb_start(nlsr->lsdb->name_lsdb, e);
1611 res = hashtb_seek(e, key,strlen(key) , 0);
1612
1613 if( res == HT_OLD_ENTRY )
1614 {
1615 nlsa=e->data;
1616
1617 nlsa->header->isValid=0;
1618
1619 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1620 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1621 write_log_for_name_lsa(nlsa);
1622 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1623
1624 hashtb_delete(e);
1625 }
1626 else if( res == HT_NEW_ENTRY )
1627 {
1628 hashtb_delete(e);
1629 }
1630 hashtb_end(e);
1631
1632 if ( nlsr->debugging )
1633 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1634 if ( nlsr->detailed_logging )
1635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1636
1637 set_new_lsdb_version();
1638
1639 if ( nlsr->debugging )
1640 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1641 if ( nlsr->detailed_logging )
1642 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1643
1644}
1645
akmhoquef5537b42013-02-22 08:33:32 -06001646
akmhoque866c2222013-02-12 10:49:33 -06001647int
1648delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001649{
akmhoqueb77b95f2013-02-08 12:28:47 -06001650
akmhoque7b791452012-10-30 11:24:56 -05001651 if ( nlsr->debugging )
1652 printf("delete_name_lsa called \n");
1653 if ( nlsr->detailed_logging )
1654 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001655
akmhoque866c2222013-02-12 10:49:33 -06001656 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -06001657
akmhoqueda5b6832012-09-13 22:33:55 -05001658
akmhoque7b791452012-10-30 11:24:56 -05001659 if ( nlsr->debugging )
1660 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1661 if ( nlsr->detailed_logging )
1662 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1663
akmhoqueda5b6832012-09-13 22:33:55 -05001664 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001665
1666 if ( nlsr->debugging )
1667 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1668 if ( nlsr->detailed_logging )
1669 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001670
akmhoqueda5b6832012-09-13 22:33:55 -05001671
1672 return 0;
1673}
1674
akmhoquef5537b42013-02-22 08:33:32 -06001675
akmhoque866c2222013-02-12 10:49:33 -06001676int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001677{
akmhoque866c2222013-02-12 10:49:33 -06001678
akmhoque7b791452012-10-30 11:24:56 -05001679 if ( nlsr->debugging )
1680 printf("delete_adj_lsa called \n");
1681 if ( nlsr->detailed_logging )
1682 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001683
akmhoque7b791452012-10-30 11:24:56 -05001684 if ( nlsr->debugging )
1685 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1686 if ( nlsr->detailed_logging )
1687 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1688
akmhoqueda5b6832012-09-13 22:33:55 -05001689 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001690
1691 if ( nlsr->debugging )
1692 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1693 if ( nlsr->detailed_logging )
1694 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1695
akmhoqueda5b6832012-09-13 22:33:55 -05001696
1697 if ( !nlsr->is_route_calculation_scheduled)
1698 {
1699 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1700 nlsr->is_route_calculation_scheduled=1;
1701 }
1702
akmhoqueda5b6832012-09-13 22:33:55 -05001703 return 0;
1704}
1705
akmhoqueffacaa82012-09-13 17:48:30 -05001706void
1707refresh_name_lsdb(void)
1708{
akmhoque7b791452012-10-30 11:24:56 -05001709 if ( nlsr->debugging )
1710 printf("refresh_name_lsdb called \n");
1711 if ( nlsr->detailed_logging )
1712 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001713
akmhoquef5537b42013-02-22 08:33:32 -06001714 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueffacaa82012-09-13 17:48:30 -05001715
1716 long int lsa_life_time;
1717
1718 int i, name_lsdb_element;
1719 struct nlsa *name_lsa;
1720
1721 struct hashtb_enumerator ee;
1722 struct hashtb_enumerator *e = &ee;
1723
1724 hashtb_start(nlsr->lsdb->name_lsdb, e);
1725 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1726
1727 for(i=0;i<name_lsdb_element;i++)
1728 {
1729 name_lsa=e->data;
1730
1731 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001732 if ( nlsr->debugging )
1733 printf("LSA Life Time: %ld \n",lsa_life_time);
1734 if ( nlsr->detailed_logging )
1735 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001736
1737 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1738 {
1739 if ( lsa_life_time > nlsr->lsa_refresh_time )
1740 {
akmhoque14b3f342012-09-14 10:39:02 -05001741 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1742 {
akmhoque7b791452012-10-30 11:24:56 -05001743 if ( nlsr->debugging )
1744 printf("Own Name LSA need to be refrshed\n");
1745 if ( nlsr->detailed_logging )
1746 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001747
1748 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1749 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1750 write_log_for_name_lsa(name_lsa);
1751 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1752
akmhoquef5537b42013-02-22 08:33:32 -06001753 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001754
akmhoque14b3f342012-09-14 10:39:02 -05001755 free(name_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001756 name_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoque14b3f342012-09-14 10:39:02 -05001757 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001758
1759 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1760 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1761 write_log_for_name_lsa(name_lsa);
1762 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001763
akmhoque14b3f342012-09-14 10:39:02 -05001764 free(current_time_stamp);
akmhoqued91401d2013-03-04 11:05:27 -06001765
1766 char lst[2];
1767 memset(lst,0,2);
1768 sprintf(lst,"%d",name_lsa->header->ls_type);
1769
1770 char lsid[10];
1771 memset(lsid,0,10);
1772 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1773
1774 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)
1775 +1+strlen(lst)+1+strlen(lsid)+1);
1776 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+
1777 strlen(lst)+1+strlen(lsid)+1);
1778
1779
1780 make_name_lsa_key(key, name_lsa->header->orig_router->name,
1781 name_lsa->header->ls_type,name_lsa->header->ls_id);
1782
1783 if ( nlsr->debugging )
1784 printf("Name LSA Key: %s \n",key);
1785
1786
1787 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+1+
1788 strlen(name_lsa->header->orig_router->name)
1789 +1+strlen(lst)+1+strlen(lsid)+1+
1790 strlen(name_lsa->header->orig_time)+16,
1791 sizeof(char));
1792 make_name_lsa_prefix_for_repo(repo_key,
1793 name_lsa->header->orig_router->name,
1794 name_lsa->header->ls_type,
1795 name_lsa->header->ls_id,
1796 name_lsa->header->orig_time,
1797 nlsr->slice_prefix);
1798
1799 if ( nlsr->debugging )
1800 printf("Name LSA Repo Key: %s \n",repo_key);
1801
1802 struct name_prefix *lsaid=(struct name_prefix *)
1803 calloc(1,sizeof(struct name_prefix));
1804 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1805 memcpy(lsaid->name,key,strlen(key)+1);
1806 lsaid->length=strlen(key)+1;
1807
1808
1809 write_name_lsa_to_repo(repo_key, lsaid);
1810
1811 free(key);
1812 free(repo_key);
1813 free(lsaid->name);
1814 free(lsaid);
1815
1816
akmhoque866c2222013-02-12 10:49:33 -06001817
1818 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001819 }
1820 else
akmhoquef5537b42013-02-22 08:33:32 -06001821 {
akmhoque866c2222013-02-12 10:49:33 -06001822 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1823 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1824 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1825 write_log_for_name_lsa(name_lsa);
1826 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001827
1828 destroy_name_lsa_component(name_lsa);
1829
akmhoque866c2222013-02-12 10:49:33 -06001830 hashtb_delete(e);
1831 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001832 }
akmhoqueda5b6832012-09-13 22:33:55 -05001833
akmhoque7b791452012-10-30 11:24:56 -05001834 if ( nlsr->debugging )
1835 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1836 if ( nlsr->detailed_logging )
1837 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1838
akmhoqueda5b6832012-09-13 22:33:55 -05001839 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001840
1841 if ( nlsr->debugging )
1842 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1843 if ( nlsr->detailed_logging )
1844 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1845
1846
akmhoqueda5b6832012-09-13 22:33:55 -05001847
1848 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001849 }
1850 else
1851 {
1852 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001853 }
1854 }
1855 else
1856 {
1857 if ( lsa_life_time > nlsr->router_dead_interval )
1858 {
akmhoque7b791452012-10-30 11:24:56 -05001859 if ( nlsr->debugging )
1860 printf("Others Name LSA need to be deleted\n");
1861 if ( nlsr->detailed_logging )
1862 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001863
akmhoque866c2222013-02-12 10:49:33 -06001864 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1865 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1866 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1867 write_log_for_name_lsa(name_lsa);
1868 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001869
1870 destroy_name_lsa_component(name_lsa);
akmhoque866c2222013-02-12 10:49:33 -06001871 hashtb_delete(e);
1872 i++;
1873 }
1874 else
1875 {
1876 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001877 }
1878 }
akmhoqueffacaa82012-09-13 17:48:30 -05001879 }
1880
1881 hashtb_end(e);
1882
1883 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001884
akmhoqueffacaa82012-09-13 17:48:30 -05001885
1886}
1887
akmhoqueda5b6832012-09-13 22:33:55 -05001888void
akmhoqueffacaa82012-09-13 17:48:30 -05001889refresh_adj_lsdb(void)
1890{
akmhoqueffacaa82012-09-13 17:48:30 -05001891
akmhoque7b791452012-10-30 11:24:56 -05001892 if ( nlsr->debugging )
1893 printf("refresh_adj_lsdb called \n");
1894 if ( nlsr->detailed_logging )
1895 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001896
akmhoquef5537b42013-02-22 08:33:32 -06001897 char *time_stamp=get_current_timestamp_micro_v2();
1898
akmhoqueffacaa82012-09-13 17:48:30 -05001899 long int lsa_life_time;
1900
1901 int i, adj_lsdb_element;
1902 struct alsa *adj_lsa;
1903
1904 struct hashtb_enumerator ee;
1905 struct hashtb_enumerator *e = &ee;
1906
1907 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1908 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1909
1910 for(i=0;i<adj_lsdb_element;i++)
1911 {
1912 adj_lsa=e->data;
1913
akmhoqueb77b95f2013-02-08 12:28:47 -06001914 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001915
1916 if ( nlsr->debugging )
1917 printf("LSA Life Time: %ld \n",lsa_life_time);
1918 if ( nlsr->detailed_logging )
1919 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001920
akmhoqueda5b6832012-09-13 22:33:55 -05001921 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1922 {
1923 if ( lsa_life_time > nlsr->lsa_refresh_time )
1924 {
akmhoque7b791452012-10-30 11:24:56 -05001925 if ( nlsr->debugging )
1926 printf("Own Adj LSA need to be refrshed\n");
1927 if ( nlsr->detailed_logging )
1928 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001929
akmhoquea98c2142012-10-25 15:22:24 -05001930 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1931 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1932 write_log_for_adj_lsa(adj_lsa);
1933 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1934
akmhoquef5537b42013-02-22 08:33:32 -06001935 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001936
1937 free(adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001938 adj_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoqueda5b6832012-09-13 22:33:55 -05001939 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1940
1941 free(current_time_stamp);
1942
akmhoquea98c2142012-10-25 15:22:24 -05001943 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1944 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1945 write_log_for_adj_lsa(adj_lsa);
1946 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001947
akmhoque7b791452012-10-30 11:24:56 -05001948 if ( nlsr->debugging )
1949 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1950 if ( nlsr->detailed_logging )
1951 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1952
akmhoqueda5b6832012-09-13 22:33:55 -05001953 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001954
1955 if ( nlsr->debugging )
1956 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1957 if ( nlsr->detailed_logging )
1958 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001959
akmhoqued91401d2013-03-04 11:05:27 -06001960
1961 char lst[2];
1962 memset(lst,0,2);
1963 sprintf(lst,"%d",LS_TYPE_ADJ);
1964
1965 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+
1966 strlen(adj_lsa->header->orig_time)+
1967 strlen(adj_lsa->header->orig_router->name)
1968 + strlen(lst) + 5+15,sizeof(char));
1969 make_adj_lsa_prefix_for_repo(repo_key,
1970 adj_lsa->header->orig_router->name,LS_TYPE_ADJ,
1971 adj_lsa->header->orig_time,nlsr->slice_prefix);
1972
1973 if ( nlsr->debugging )
1974 printf("Adj LSA Repo Key: %s \n",repo_key);
1975
1976 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,
1977 sizeof(char));
1978 make_adj_lsa_key(key,adj_lsa);
1979 if ( nlsr->debugging )
1980 printf("Adj LSA Key: %s \n",key);
1981
1982 struct name_prefix *lsaid=(struct name_prefix *)
1983 calloc(1,sizeof(struct name_prefix));
1984 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1985 memcpy(lsaid->name,key,strlen(key)+1);
1986 lsaid->length=strlen(key)+1;
1987
1988
1989 write_adj_lsa_to_repo(repo_key, lsaid);
1990
1991 free(key);
1992 free(repo_key);
1993 free(lsaid->name);
1994 free(lsaid);
1995
1996
1997
1998
1999
2000
akmhoqueda5b6832012-09-13 22:33:55 -05002001 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002002
2003
akmhoqueda5b6832012-09-13 22:33:55 -05002004 }
akmhoque866c2222013-02-12 10:49:33 -06002005
2006 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002007 }
2008 else
2009 {
2010 if ( lsa_life_time > nlsr->router_dead_interval )
2011 {
akmhoque7b791452012-10-30 11:24:56 -05002012
2013 if ( nlsr->debugging )
2014 printf("Others Adj LSA need to be deleted\n");
2015 if ( nlsr->detailed_logging )
2016 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06002017 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2018 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2019 write_log_for_adj_lsa(adj_lsa);
2020 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2021 delete_adj_lsa();
akmhoquef5537b42013-02-22 08:33:32 -06002022
2023 destroy_adj_lsa_component(adj_lsa);
akmhoque866c2222013-02-12 10:49:33 -06002024 hashtb_delete(e);
2025 i++;
2026
2027 }
2028 else
2029 {
2030 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002031 }
2032 }
akmhoquef5537b42013-02-22 08:33:32 -06002033
akmhoqueffacaa82012-09-13 17:48:30 -05002034 }
2035
2036 hashtb_end(e);
2037
2038 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002039}
2040
akmhoqueb77b95f2013-02-08 12:28:47 -06002041
2042void
2043refresh_cor_lsdb(void)
2044{
2045
2046 if ( nlsr->debugging )
2047 printf("refresh_cor_lsdb called \n");
2048 if ( nlsr->detailed_logging )
2049 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2050
akmhoquef5537b42013-02-22 08:33:32 -06002051 char *time_stamp=get_current_timestamp_micro_v2();
2052
akmhoqueb77b95f2013-02-08 12:28:47 -06002053 long int lsa_life_time;
2054
2055 int i, cor_lsdb_element;
2056 struct clsa *cor_lsa;
2057
2058 struct hashtb_enumerator ee;
2059 struct hashtb_enumerator *e = &ee;
2060
2061 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2062 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2063
2064 for(i=0;i<cor_lsdb_element;i++)
2065 {
2066 cor_lsa=e->data;
2067
2068 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2069
2070 if ( nlsr->debugging )
2071 printf("LSA Life Time: %ld \n",lsa_life_time);
2072 if ( nlsr->detailed_logging )
2073 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2074
2075 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2076 {
2077 if ( lsa_life_time > nlsr->lsa_refresh_time )
2078 {
2079 if ( nlsr->debugging )
2080 printf("Own Cor LSA need to be refrshed\n");
2081 if ( nlsr->detailed_logging )
2082 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2083
akmhoquef5537b42013-02-22 08:33:32 -06002084 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002085
2086 free(cor_lsa->header->orig_time);
2087 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2088 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2089 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2090
2091 free(current_time_stamp);
2092
akmhoqueb77b95f2013-02-08 12:28:47 -06002093 if ( nlsr->debugging )
2094 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2095 if ( nlsr->detailed_logging )
2096 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2097
2098 set_new_lsdb_version();
2099
2100 if ( nlsr->debugging )
2101 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2102 if ( nlsr->detailed_logging )
2103 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2104
2105 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002106 }
2107
2108 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002109 }
2110 else
2111 {
2112 if ( lsa_life_time > nlsr->router_dead_interval )
2113 {
2114
2115 if ( nlsr->debugging )
2116 printf("Others Adj LSA need to be deleted\n");
2117 if ( nlsr->detailed_logging )
2118 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoquef5537b42013-02-22 08:33:32 -06002119
2120 destroy_cor_lsa_component(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002121 hashtb_delete(e);
2122 i++;
2123 }
akmhoque866c2222013-02-12 10:49:33 -06002124 else
2125 {
2126 hashtb_next(e);
2127 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002128 }
2129
2130
akmhoque866c2222013-02-12 10:49:33 -06002131
akmhoqueb77b95f2013-02-08 12:28:47 -06002132 }
2133
2134 hashtb_end(e);
2135
2136 free(time_stamp);
2137}
2138
akmhoqueffacaa82012-09-13 17:48:30 -05002139int
2140refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2141{
2142 if(flags == CCN_SCHEDULE_CANCEL)
2143 {
2144 return -1;
2145 }
2146
2147 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002148
akmhoque7b791452012-10-30 11:24:56 -05002149 if ( nlsr->debugging )
2150 printf("refresh_lsdb called\n");
2151 if ( nlsr->detailed_logging )
2152 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002153
2154 refresh_name_lsdb();
2155 refresh_adj_lsdb();
2156
akmhoqueffacaa82012-09-13 17:48:30 -05002157 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002158
akmhoqueffacaa82012-09-13 17:48:30 -05002159 nlsr_unlock();
2160 return 0;
2161}
akmhoqueb77b95f2013-02-08 12:28:47 -06002162
2163void
2164write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2165{
2166 if ( nlsr->debugging )
2167 printf("write_adj_lsa_to_repo called\n");
2168 if ( nlsr->debugging )
2169 printf("Content Prefix: %s\n",repo_content_prefix);
2170
2171 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2172 get_adj_lsa_data(lsa_data,lsa_id);
2173 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002174 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002175
akmhoquec25f2242013-03-15 00:24:43 -05002176 //char *data;
2177 //data=ccn_charbuf_as_string(lsa_data);
2178 //data[strlen(data)]='\0';
akmhoquef5537b42013-02-22 08:33:32 -06002179
akmhoquec25f2242013-03-15 00:24:43 -05002180 //write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002181
akmhoquec25f2242013-03-15 00:24:43 -05002182 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoque323b5e92013-02-21 13:55:15 -06002183
akmhoquec25f2242013-03-15 00:24:43 -05002184 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002185}
2186
2187void
2188write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2189{
2190 if ( nlsr->debugging )
2191 printf("write_name_lsa_to_repo called\n");
2192 if ( nlsr->debugging )
2193 printf("Content Prefix: %s\n",repo_content_prefix);
2194
2195 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2196 get_name_lsa_data(lsa_data,lsa_id);
2197
2198 if ( nlsr->debugging )
2199 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2200
akmhoquec25f2242013-03-15 00:24:43 -05002201 //char *data;
2202 //data=ccn_charbuf_as_string(lsa_data);
2203 //data[strlen(data)]='\0';
akmhoque323b5e92013-02-21 13:55:15 -06002204
akmhoquec25f2242013-03-15 00:24:43 -05002205 //write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002206
akmhoquec25f2242013-03-15 00:24:43 -05002207 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
2208
2209 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002210}
2211
2212
2213void
2214write_name_lsdb_to_repo(char *slice_prefix)
2215{
2216 int i, name_lsdb_element;
2217
2218 struct nlsa *name_lsa;
2219 struct hashtb_enumerator ee;
2220 struct hashtb_enumerator *e = &ee;
2221
2222 hashtb_start(nlsr->lsdb->name_lsdb, e);
2223 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2224
2225 for(i=0;i<name_lsdb_element;i++)
2226 {
2227 name_lsa=e->data;
2228
2229 char lst[2];
2230 memset(lst,0,2);
2231 sprintf(lst,"%d",name_lsa->header->ls_type);
2232
2233 char lsid[10];
2234 memset(lsid,0,10);
2235 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2236
2237
2238 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2239 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2240
2241
2242 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2243
2244 if ( nlsr->debugging )
2245 printf("Name LSA Key: %s \n",key);
2246
2247
akmhoquef5537b42013-02-22 08:33:32 -06002248 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 -06002249 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);
2250
2251 if ( nlsr->debugging )
2252 printf("Name LSA Repo Key: %s \n",repo_key);
2253
akmhoquef5537b42013-02-22 08:33:32 -06002254 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
2255 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
2256 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002257 lsaid->length=strlen(key)+1;
2258
2259
2260 write_name_lsa_to_repo(repo_key, lsaid);
2261
2262 free(key);
2263 free(repo_key);
2264 free(lsaid->name);
2265 free(lsaid);
2266
2267 hashtb_next(e);
2268 }
2269
2270 hashtb_end(e);
2271
2272
2273}
2274
2275void
2276print_cor_lsa(struct clsa *cor_lsa)
2277{
2278 if ( nlsr->debugging )
2279 {
2280 printf("-----------Cor LSA Content---------------\n");
2281 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2282 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2283 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2284 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2285 printf(" LSA Data \n");
2286 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2287 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2288
2289 printf("\n");
2290 }
2291}
2292
2293void
2294print_cor_lsdb()
2295{
2296
2297 if ( nlsr->debugging )
2298 printf("print_cor_lsdb called \n");
2299
2300 struct hashtb_enumerator ee;
2301 struct hashtb_enumerator *e = &ee;
2302
2303 int i=1;
2304
2305 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2306 {
2307 if ( nlsr->debugging )
2308 printf("-----------Cor LSA (%d)---------------\n",i);
2309 struct clsa *cor_lsa=e->data;
2310 print_cor_lsa(cor_lsa);
2311 i++;
2312 }
2313 hashtb_end(e);
2314
2315 if ( nlsr->debugging )
2316 printf("\n");
2317 if ( nlsr->detailed_logging )
2318 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2319}
2320
2321void
2322install_cor_lsa(struct clsa *cor_lsa)
2323{
2324 if ( nlsr->debugging )
2325 printf("install_cor_lsa called \n");
2326 if ( nlsr->detailed_logging )
2327 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2328
2329
akmhoquececba942013-02-25 17:33:34 -06002330 //char *time_stamp=(char *)malloc(20);
2331 //memset(time_stamp,0,20);
2332 //get_current_timestamp_micro(time_stamp);
akmhoqueb77b95f2013-02-08 12:28:47 -06002333
2334
akmhoque569a93d2013-02-21 10:19:54 -06002335 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2336 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002337 make_cor_lsa_key(key,cor_lsa);
2338
2339 if ( nlsr->debugging )
2340 printf("Cor LSA key: %s \n",key);
2341
2342 struct hashtb_enumerator ee;
2343 struct hashtb_enumerator *e = &ee;
2344 int res;
2345
2346 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2347 res = hashtb_seek(e, key, strlen(key), 0);
2348
2349 if ( res == HT_NEW_ENTRY )
2350 {
2351 if ( nlsr->debugging )
2352 printf("New Cor LSA... \n");
2353
akmhoque8876e982013-02-21 13:35:46 -06002354 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002355 new_cor_lsa=e->data;
2356 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2357
2358 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2359 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
akmhoquececba942013-02-25 17:33:34 -06002360 //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002361 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2362 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2363
akmhoque483c1eb2013-03-08 00:51:09 -06002364 new_cor_lsa->header->orig_time=(char *)calloc(strlen(cor_lsa->header->orig_time)+1,sizeof(char)); //free
akmhoquececba942013-02-25 17:33:34 -06002365 //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
akmhoque483c1eb2013-03-08 00:51:09 -06002366 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2367 //new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002368
2369 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2370
2371 new_cor_lsa->cor_r=cor_lsa->cor_r;
2372 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2373 }
2374 else if ( res == HT_OLD_ENTRY )
2375 {
2376 if ( nlsr->debugging )
2377 printf("Cor LSA exists (Old)... \n");
2378 }
2379 hashtb_end(e);
2380
akmhoquef5537b42013-02-22 08:33:32 -06002381 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002382
2383}
2384
2385void
2386build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2387{
2388 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2389 cor_lsa->header->ls_type=LS_TYPE_COR;
2390
akmhoquef5537b42013-02-22 08:33:32 -06002391 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002392 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2393 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2394 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2395 free(time_stamp);
2396
akmhoquef5537b42013-02-22 08:33:32 -06002397 cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
2398 cor_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002399 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2400 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2401 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2402
2403 cor_lsa->cor_r=cor_r;
2404 cor_lsa->cor_theta=cor_theta;
2405
2406}
2407
2408void
2409build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2410{
2411 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2412 cor_lsa->header->ls_type=ls_type;
2413
2414 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2415 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002416 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002417
2418 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2419 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2420 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002421 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002422 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2423
2424 cor_lsa->cor_r=cor_r;
2425 cor_lsa->cor_theta=cor_theta;
2426
2427}
2428
2429void
2430build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2431{
2432 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2433 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2434 install_cor_lsa(cor_lsa);
2435
2436 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002437
akmhoquef5537b42013-02-22 08:33:32 -06002438 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002439}
2440
2441
2442void
2443build_and_install_cor_lsa()
2444{
2445
2446
2447
2448 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2449
2450 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2451 install_cor_lsa(cor_lsa);
2452
2453 write_cor_lsa_to_repo(cor_lsa);
akmhoquef5537b42013-02-22 08:33:32 -06002454 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002455
2456 print_cor_lsdb();
akmhoqueb77b95f2013-02-08 12:28:47 -06002457
2458}
2459
2460void
2461get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2462{
2463 if ( nlsr->debugging )
2464 printf("get_cor_lsa_data called \n");
2465 if ( nlsr->detailed_logging )
2466 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2467
akmhoquececba942013-02-25 17:33:34 -06002468 struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002469
2470 struct hashtb_enumerator ee;
2471 struct hashtb_enumerator *e = &ee;
2472 int res;
2473
2474 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2475 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2476
2477 if( res == HT_OLD_ENTRY )
2478 {
2479 cor_lsa=e->data;
2480
2481 if ( nlsr->debugging )
2482 printf("Cor LSA found \n");
2483 if ( nlsr->detailed_logging )
2484 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2485
2486 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2487 ccn_charbuf_append_string(lsa_data,"|");
2488
2489 char *temp_length=(char *)malloc(20);
2490 memset(temp_length,0,20);
2491 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2492 ccn_charbuf_append_string(lsa_data,temp_length);
2493 ccn_charbuf_append_string(lsa_data,"|");
2494 free(temp_length);
2495
2496 char *temp_ltype=(char *)malloc(20);
2497 memset(temp_ltype,0,20);
2498 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2499 ccn_charbuf_append_string(lsa_data,temp_ltype);
2500 ccn_charbuf_append_string(lsa_data,"|");
2501 free(temp_ltype);
2502
2503 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2504 ccn_charbuf_append_string(lsa_data,"|");
2505
2506 char *cor_r=(char *)malloc(20);
2507 memset(cor_r,0,20);
2508 sprintf(cor_r,"%f",cor_lsa->cor_r);
2509 ccn_charbuf_append_string(lsa_data,cor_r);
2510 ccn_charbuf_append_string(lsa_data,"|");
2511 free(cor_r);
2512
2513 char *cor_theta=(char *)malloc(20);
2514 memset(cor_theta,0,20);
2515 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2516 ccn_charbuf_append_string(lsa_data,cor_theta);
2517 ccn_charbuf_append_string(lsa_data,"|");
2518 free(cor_theta);
2519
2520 }
2521 else if(res == HT_NEW_ENTRY)
2522 {
2523 hashtb_delete(e);
2524 }
2525
2526 hashtb_end(e);
2527}
2528
2529void
2530write_cor_lsa_to_repo(struct clsa *cor_lsa)
2531{
2532
2533
2534 if ( nlsr->debugging )
2535 printf("write_cor_lsa_to_repo called\n");
2536
2537
akmhoquef5537b42013-02-22 08:33:32 -06002538 char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002539 make_cor_lsa_key(key,cor_lsa);
2540
2541 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2542 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002543
akmhoqueb77b95f2013-02-08 12:28:47 -06002544 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002545 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2546
akmhoqueb77b95f2013-02-08 12:28:47 -06002547 char *lst=(char *)malloc(20);
2548 memset(lst,0,20);
2549 sprintf(lst,"%d",cor_lsa->header->ls_type);
akmhoquef5537b42013-02-22 08:33:32 -06002550 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 -06002551 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);
2552
2553 if ( nlsr->debugging )
2554 printf("Cor LSA Repo Key: %s \n",repo_key);
2555
akmhoquec25f2242013-03-15 00:24:43 -05002556 //char *data;
2557 //data=ccn_charbuf_as_string(lsa_data);
2558 //data[strlen(data)]='\0';
akmhoquef5537b42013-02-22 08:33:32 -06002559
akmhoquec25f2242013-03-15 00:24:43 -05002560 //write_data_to_repo(data, repo_content_prefix);
2561
2562 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
akmhoque0800eda2013-02-21 14:17:52 -06002563
akmhoqueb77b95f2013-02-08 12:28:47 -06002564
2565
2566
2567 free(lst);
2568 free(key);
2569 free(repo_key);
akmhoquec25f2242013-03-15 00:24:43 -05002570 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002571}
2572
2573void
2574make_cor_lsa_key_by_router_name(char *key,char *router_name)
2575{
2576 memcpy(key+strlen(key),router_name,strlen(router_name));
2577 memcpy(key+strlen(key),"/",1);
2578 char ls_type[2];
2579 sprintf(ls_type,"%d",LS_TYPE_COR);
2580 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2581 key[strlen(key)]='\0';
2582}
2583
2584
2585double
2586get_hyperbolic_r(char *router)
2587{
2588 double ret=-1.0;
2589 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2590 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2591
2592
2593 struct clsa *cor_lsa;
2594 struct hashtb_enumerator ee;
2595 struct hashtb_enumerator *e = &ee;
2596 int res;
2597
2598 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2599 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2600
2601 if ( res == HT_OLD_ENTRY)
2602 {
2603 cor_lsa=e->data;
2604 ret=cor_lsa->cor_r;
2605 }
2606 else if(res == HT_NEW_ENTRY)
2607 {
2608 hashtb_delete(e);
2609 }
2610
2611 hashtb_end(e);
2612
2613 free(cor_lsa_key);
2614 return ret;
2615}
2616
2617double
2618get_hyperbolic_theta(char *router)
2619{
akmhoquef5537b42013-02-22 08:33:32 -06002620 double ret=-1.0;
akmhoqueb77b95f2013-02-08 12:28:47 -06002621 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2622 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2623
2624 struct clsa *cor_lsa;
2625 struct hashtb_enumerator ee;
2626 struct hashtb_enumerator *e = &ee;
2627 int res;
2628
2629 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2630 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2631
2632 if ( res == HT_OLD_ENTRY)
2633 {
2634 cor_lsa=e->data;
2635 ret=cor_lsa->cor_theta;
2636 }
2637 else if(res == HT_NEW_ENTRY)
2638 {
2639 hashtb_delete(e);
2640 }
2641
2642 hashtb_end(e);
2643
2644 free(cor_lsa_key);
2645 return ret;
2646}
akmhoquead584782013-02-22 10:56:03 -06002647
2648
2649void
2650destroy_name_lsdb(void)
2651{
2652 int i, name_lsdb_element;
2653 struct nlsa *name_lsa;
2654
2655 struct hashtb_enumerator ee;
2656 struct hashtb_enumerator *e = &ee;
2657
2658 hashtb_start(nlsr->lsdb->name_lsdb, e);
2659 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2660
2661 for(i=0;i<name_lsdb_element;i++)
2662 {
2663 name_lsa=e->data;
2664 destroy_name_lsa_component(name_lsa);
2665 hashtb_next(e);
2666 }
2667
2668 hashtb_end(e);
2669
2670 if ( nlsr->lsdb->name_lsdb )
2671 hashtb_destroy(&nlsr->lsdb->name_lsdb);
2672}
2673
2674void
2675destroy_adj_lsdb(void)
2676{
2677 int i, adj_lsdb_element;
2678 struct alsa *adj_lsa;
2679
2680 struct hashtb_enumerator ee;
2681 struct hashtb_enumerator *e = &ee;
2682
2683 hashtb_start(nlsr->lsdb->adj_lsdb, e);
2684 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
2685
2686 for(i=0;i<adj_lsdb_element;i++)
2687 {
2688 adj_lsa=e->data;
2689 destroy_adj_lsa_component(adj_lsa);
2690 hashtb_next(e);
2691 }
2692
2693 hashtb_end(e);
2694 if(nlsr->lsdb->adj_lsdb )
2695 hashtb_destroy(&nlsr->lsdb->adj_lsdb);
2696}
2697
2698void
2699destroy_cor_lsdb(void)
2700{
2701 int i, cor_lsdb_element;
2702 struct clsa *cor_lsa;
2703
2704 struct hashtb_enumerator ee;
2705 struct hashtb_enumerator *e = &ee;
2706
2707 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2708 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2709
2710 for(i=0;i<cor_lsdb_element;i++)
2711 {
2712 cor_lsa=e->data;
2713 destroy_cor_lsa_component(cor_lsa);
2714 hashtb_next(e);
2715 }
2716
2717 hashtb_end(e);
2718 if(nlsr->lsdb->cor_lsdb )
2719 hashtb_destroy(&nlsr->lsdb->cor_lsdb);
2720}
2721
2722void
2723destroy_lsdb(void)
2724{
2725 destroy_name_lsdb();
2726 destroy_adj_lsdb();
2727 destroy_cor_lsdb();
2728
2729 if ( nlsr->lsdb->lsdb_version )
2730 free(nlsr->lsdb->lsdb_version);
2731 if ( nlsr->lsdb )
2732 free(nlsr->lsdb);
2733}