blob: 92fc82d6e00e115c4d0143b327ac69c98e3169ec [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;
akmhoque1a12ca42013-03-15 08:16:50 -05001019 if ( new_adj_lsa->body != NULL )
1020 free(new_adj_lsa->body);
akmhoquef5537b42013-02-22 08:33:32 -06001021 new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
akmhoque62c0c192012-09-24 07:49:25 -05001022 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoque62c0c192012-09-24 07:49:25 -05001023 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001024
1025 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1026 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1027 write_log_for_adj_lsa(new_adj_lsa);
1028 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -05001029 }
1030 else
1031 {
akmhoque9e9fc722012-09-26 14:03:25 -05001032 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1033 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1034 write_log_for_adj_lsa(new_adj_lsa);
1035 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1036
akmhoque62c0c192012-09-24 07:49:25 -05001037 hashtb_delete(e);
1038 }
akmhoque7b791452012-10-30 11:24:56 -05001039
1040 if ( nlsr->debugging )
1041 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1042 if ( nlsr->detailed_logging )
1043 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1044
akmhoqueffacaa82012-09-13 17:48:30 -05001045 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001046
1047 if ( nlsr->debugging )
1048 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1049 if ( nlsr->detailed_logging )
1050 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -05001051 }
1052
1053 }
1054 hashtb_end(e);
1055
1056 if ( !nlsr->is_route_calculation_scheduled )
1057 {
1058 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1059 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -05001060 }
1061
akmhoque03004e62012-09-06 01:12:28 -05001062
akmhoquef5537b42013-02-22 08:33:32 -06001063 free(key);
akmhoqueffacaa82012-09-13 17:48:30 -05001064
akmhoquef5537b42013-02-22 08:33:32 -06001065 //free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -05001066}
1067
1068void
akmhoque9e9fc722012-09-26 14:03:25 -05001069write_log_for_adj_lsa_body(const char *body, int no_link)
1070{
1071 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001072 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
akmhoque9e9fc722012-09-26 14:03:25 -05001073 memcpy(lsa_data,body,strlen(body)+1);
1074 char *sep="|";
1075 char *rem;
1076 char *rtr_id;
1077 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001078 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -05001079 char *metric;
1080
1081 if(no_link >0 )
1082 {
1083 rtr_id=strtok_r(lsa_data,sep,&rem);
1084 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001085 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001086 metric=strtok_r(NULL,sep,&rem);
1087
1088 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001089 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1090 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001091 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001092 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001093
1094
1095 for(i=1;i<no_link;i++)
1096 {
1097 rtr_id=strtok_r(NULL,sep,&rem);
1098 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001099 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001100 metric=strtok_r(NULL,sep,&rem);
1101 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001102 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1103 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001104 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001105 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001106
1107 }
1108 }
1109
akmhoquef5537b42013-02-22 08:33:32 -06001110 if(lsa_data)
1111 free(lsa_data);
akmhoque9e9fc722012-09-26 14:03:25 -05001112}
1113
1114
1115void
1116write_log_for_adj_lsa(struct alsa * adj_lsa)
1117{
1118 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001119 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1120 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1121 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1122 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001123 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001124 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001125
1126 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1127
1128 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1129
1130}
1131
1132void
akmhoque53f64222012-09-05 13:57:51 -05001133print_adj_lsa_body(const char *body, int no_link)
1134{
1135 int i=0;
akmhoquef5537b42013-02-22 08:33:32 -06001136 char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char));
1137 //memset( lsa_data,0,strlen(body)+1);
akmhoque53f64222012-09-05 13:57:51 -05001138 memcpy(lsa_data,body,strlen(body)+1);
1139 char *sep="|";
1140 char *rem;
1141 char *rtr_id;
1142 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001143 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001144 char *metric;
1145
akmhoque53f64222012-09-05 13:57:51 -05001146 if(no_link >0 )
1147 {
1148 rtr_id=strtok_r(lsa_data,sep,&rem);
1149 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001150 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001151 metric=strtok_r(NULL,sep,&rem);
1152
akmhoqueb77b95f2013-02-08 12:28:47 -06001153 if ( nlsr->debugging ) {
1154 printf(" Link %d \n",i+1);
1155 printf(" Neighbor : %s \n",rtr_id);
1156 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001157 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001158 printf(" Metric : %s \n",metric);
1159 }
akmhoque53f64222012-09-05 13:57:51 -05001160
1161 for(i=1;i<no_link;i++)
1162 {
1163 rtr_id=strtok_r(NULL,sep,&rem);
1164 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001165 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001166 metric=strtok_r(NULL,sep,&rem);
1167 printf(" Link %d \n",i+1);
1168 printf(" Neighbor : %s \n",rtr_id);
1169 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001170 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001171 printf(" Metric : %s \n",metric);
1172
1173 }
1174 }
1175
akmhoquef5537b42013-02-22 08:33:32 -06001176 if( lsa_data )
1177 free(lsa_data);
akmhoque53f64222012-09-05 13:57:51 -05001178}
1179
1180void
1181print_adj_lsa(struct alsa * adj_lsa)
1182{
akmhoque7b791452012-10-30 11:24:56 -05001183 if ( nlsr->debugging )
1184 {
1185 printf("-----------ADJ LSA Content---------------\n");
1186 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1187 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1188 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1189 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1190 printf(" Lsa Data:\n");
1191 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001192
akmhoque7b791452012-10-30 11:24:56 -05001193 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1194 printf("\n");
1195 }
akmhoque53f64222012-09-05 13:57:51 -05001196
1197}
1198
1199void
1200print_adj_lsdb(void)
1201{
akmhoque7b791452012-10-30 11:24:56 -05001202 if ( nlsr->debugging )
1203 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001204 int i, adj_lsdb_element;
1205 struct alsa *adj_lsa;
1206
1207 struct hashtb_enumerator ee;
1208 struct hashtb_enumerator *e = &ee;
1209
1210 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1211 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1212
1213 for(i=0;i<adj_lsdb_element;i++)
1214 {
akmhoque7b791452012-10-30 11:24:56 -05001215 if ( nlsr->debugging )
1216 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001217 adj_lsa=e->data;
1218 print_adj_lsa(adj_lsa);
1219 hashtb_next(e);
1220 }
1221
1222 hashtb_end(e);
1223
akmhoque3171d652012-11-13 11:44:33 -06001224 if ( nlsr->debugging )
1225 printf("\n");
1226 if ( nlsr->detailed_logging )
1227 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001228}
1229
1230void
akmhoque03004e62012-09-06 01:12:28 -05001231build_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 -05001232{
akmhoque7b791452012-10-30 11:24:56 -05001233 if ( nlsr->debugging )
1234 printf("build_and_install_others_adj_lsa called \n");
1235 if ( nlsr->detailed_logging )
1236 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001237 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1238 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001239 install_adj_lsa(adj_lsa);
1240
akmhoquef5537b42013-02-22 08:33:32 -06001241 destroy_adj_lsa(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001242
akmhoque03004e62012-09-06 01:12:28 -05001243 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001244
akmhoque53f64222012-09-05 13:57:51 -05001245}
1246
akmhoque03004e62012-09-06 01:12:28 -05001247
akmhoque53f64222012-09-05 13:57:51 -05001248void
akmhoque03004e62012-09-06 01:12:28 -05001249build_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 -05001250{
akmhoque7b791452012-10-30 11:24:56 -05001251 if ( nlsr->debugging )
1252 printf("build_others_adj_lsa called \n");
1253 if ( nlsr->detailed_logging )
1254 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001255
akmhoque03004e62012-09-06 01:12:28 -05001256 /*Filling Up Header Data */
akmhoquef5537b42013-02-22 08:33:32 -06001257 adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header ));
1258 adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
1259 adj_lsa->header->orig_router->name=(char *)calloc(strlen(orig_router)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001260 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001261
akmhoque03004e62012-09-06 01:12:28 -05001262 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001263
akmhoque53f64222012-09-05 13:57:51 -05001264
akmhoque03004e62012-09-06 01:12:28 -05001265 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001266
akmhoquef5537b42013-02-22 08:33:32 -06001267 adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001268 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001269
akmhoque03004e62012-09-06 01:12:28 -05001270 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001271
akmhoquef5537b42013-02-22 08:33:32 -06001272 adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -05001273 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001274
akmhoque53f64222012-09-05 13:57:51 -05001275}
1276
akmhoque03004e62012-09-06 01:12:28 -05001277
akmhoque53f64222012-09-05 13:57:51 -05001278long int
1279get_name_lsdb_num_element(void)
1280{
1281 long int num_element;
1282
1283
1284 struct hashtb_enumerator ee;
1285 struct hashtb_enumerator *e = &ee;
1286
1287 hashtb_start(nlsr->lsdb->name_lsdb, e);
1288 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1289 hashtb_end(e);
1290
1291 return num_element;
1292}
1293
1294long int
1295get_adj_lsdb_num_element(void)
1296{
1297 long int num_element;
1298
1299
1300 struct hashtb_enumerator ee;
1301 struct hashtb_enumerator *e = &ee;
1302
1303 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1304 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1305 hashtb_end(e);
1306
1307 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001308}
akmhoque03004e62012-09-06 01:12:28 -05001309
akmhoque03004e62012-09-06 01:12:28 -05001310
1311int
1312check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1313{
1314 int ret=0;
1315 struct ccn_charbuf *key=ccn_charbuf_create();
1316 ccn_charbuf_append_string(key,orig_router);
1317 ccn_charbuf_append_string(key,"/");
1318 ccn_charbuf_append_string(key,lst);
1319 ccn_charbuf_append_string(key,"/");
1320 ccn_charbuf_append_string(key,lsid);
1321
1322 int res;
1323 struct nlsa *name_lsa;
1324
1325 struct hashtb_enumerator ee;
1326 struct hashtb_enumerator *e = &ee;
1327
1328 hashtb_start(nlsr->lsdb->name_lsdb, e);
1329 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1330
1331 if( res == HT_NEW_ENTRY )
1332 {
1333 hashtb_delete(e);
1334 ret=1;
1335
1336 }
1337 else if(res == HT_OLD_ENTRY)
1338 {
1339 name_lsa=e->data;
1340 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1341 {
1342 ret=1;
1343 }
1344 }
1345
1346 hashtb_end(e);
1347
1348 ccn_charbuf_destroy(&key);
1349
1350 return ret;
1351}
1352
1353int
1354check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1355{
1356 int ret=0;
1357 struct ccn_charbuf *key=ccn_charbuf_create();
1358 ccn_charbuf_append_string(key,orig_router);
1359 ccn_charbuf_append_string(key,"/");
1360 ccn_charbuf_append_string(key,lst);
1361
1362 int res;
1363 struct alsa *adj_lsa;
1364
1365 struct hashtb_enumerator ee;
1366 struct hashtb_enumerator *e = &ee;
1367
1368 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1369 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1370
1371 if( res == HT_NEW_ENTRY )
1372 {
1373 hashtb_delete(e);
1374 ret=1;
1375
1376 }
1377 else if(res == HT_OLD_ENTRY)
1378 {
1379 adj_lsa=e->data;
1380 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1381 {
1382 ret=1;
1383 }
1384 }
1385
1386 hashtb_end(e);
1387
1388 ccn_charbuf_destroy(&key);
1389
1390 return ret;
1391}
1392
akmhoqueb77b95f2013-02-08 12:28:47 -06001393int
1394check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1395{
1396 int ret=0;
1397 struct ccn_charbuf *key=ccn_charbuf_create();
1398 ccn_charbuf_append_string(key,orig_router);
1399 ccn_charbuf_append_string(key,"/");
1400 ccn_charbuf_append_string(key,lst);
1401
1402 int res;
1403 struct clsa *cor_lsa;
1404
1405 struct hashtb_enumerator ee;
1406 struct hashtb_enumerator *e = &ee;
1407
1408 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1409 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1410
1411 if( res == HT_NEW_ENTRY )
1412 {
1413 hashtb_delete(e);
1414 ret=1;
1415
1416 }
1417 else if(res == HT_OLD_ENTRY)
1418 {
1419 cor_lsa=e->data;
1420 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1421 {
1422 ret=1;
1423 }
1424 }
1425
1426 hashtb_end(e);
1427
1428 ccn_charbuf_destroy(&key);
1429
1430 return ret;
1431}
1432
akmhoque03004e62012-09-06 01:12:28 -05001433void
1434get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1435{
akmhoque7b791452012-10-30 11:24:56 -05001436 if ( nlsr->debugging )
1437 printf("get_name_lsa_data called \n");
1438 if ( nlsr->detailed_logging )
1439 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001440
akmhoque8876e982013-02-21 13:35:46 -06001441 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001442
1443 struct hashtb_enumerator ee;
1444 struct hashtb_enumerator *e = &ee;
1445 int res;
1446
1447 hashtb_start(nlsr->lsdb->name_lsdb, e);
1448 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1449
1450 if( res == HT_OLD_ENTRY )
1451 {
1452 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001453
akmhoque7b791452012-10-30 11:24:56 -05001454 if ( nlsr->debugging )
1455 printf("NAME LSA found \n");
1456 if ( nlsr->detailed_logging )
1457 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001458
1459 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1460 ccn_charbuf_append_string(lsa_data,"|");
1461
1462 char *temp_length=(char *)malloc(20);
1463 memset(temp_length,0,20);
1464 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1465 ccn_charbuf_append_string(lsa_data,temp_length);
1466 free(temp_length);
1467 ccn_charbuf_append_string(lsa_data,"|");
1468
1469 char *temp_ltype=(char *)malloc(20);
1470 memset(temp_ltype,0,20);
1471 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1472 ccn_charbuf_append_string(lsa_data,temp_ltype);
1473 free(temp_ltype);
1474 ccn_charbuf_append_string(lsa_data,"|");
1475
1476 char *temp_lsid=(char *)malloc(20);
1477 memset(temp_lsid,0,20);
1478 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1479 ccn_charbuf_append_string(lsa_data,temp_lsid);
1480 free(temp_lsid);
1481 ccn_charbuf_append_string(lsa_data,"|");
1482
1483 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1484 ccn_charbuf_append_string(lsa_data,"|");
1485
1486 char *temp_valid=(char *)malloc(20);
1487 memset(temp_valid,0,20);
1488 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1489 ccn_charbuf_append_string(lsa_data,temp_valid);
1490 free(temp_valid);
1491 ccn_charbuf_append_string(lsa_data,"|");
1492
1493 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1494 ccn_charbuf_append_string(lsa_data,"|");
1495
1496 char *temp_npl=(char *)malloc(20);
1497 memset(temp_npl,0,20);
1498 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1499 ccn_charbuf_append_string(lsa_data,temp_npl);
1500 free(temp_npl);
1501 ccn_charbuf_append_string(lsa_data,"|");
1502
1503 }
1504 else if(res == HT_NEW_ENTRY)
1505 {
1506 hashtb_delete(e);
1507 }
1508
1509 hashtb_end(e);
1510}
1511
1512void
1513get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1514{
akmhoque7b791452012-10-30 11:24:56 -05001515 if ( nlsr->debugging )
1516 printf("get_adj_lsa_data called \n");
1517 if ( nlsr->detailed_logging )
1518 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001519
akmhoquececba942013-02-25 17:33:34 -06001520 struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoque03004e62012-09-06 01:12:28 -05001521
1522 struct hashtb_enumerator ee;
1523 struct hashtb_enumerator *e = &ee;
1524 int res;
1525
1526 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1527 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1528
1529 if( res == HT_OLD_ENTRY )
1530 {
1531 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001532
1533 if ( nlsr->debugging )
1534 printf("Adj LSA found \n");
1535 if ( nlsr->detailed_logging )
1536 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001537
1538 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1539 ccn_charbuf_append_string(lsa_data,"|");
1540
1541 char *temp_length=(char *)malloc(20);
1542 memset(temp_length,0,20);
1543 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1544 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001545 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001546 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001547
1548 char *temp_ltype=(char *)malloc(20);
1549 memset(temp_ltype,0,20);
1550 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1551 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001552 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001553 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001554
1555 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1556 ccn_charbuf_append_string(lsa_data,"|");
1557
1558 char *temp_nl=(char *)malloc(20);
1559 memset(temp_nl,0,20);
1560 sprintf(temp_nl,"%d",adj_lsa->no_link);
1561 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001562 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001563 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001564
1565 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1566
1567
1568 }
1569 else if(res == HT_NEW_ENTRY)
1570 {
1571 hashtb_delete(e);
1572 }
1573
1574 hashtb_end(e);
1575}
akmhoqueffacaa82012-09-13 17:48:30 -05001576
akmhoque3171d652012-11-13 11:44:33 -06001577void
1578make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1579{
1580
1581 if ( nlsr->debugging )
1582 printf("make_name_lsa_invalid called \n");
1583 if ( nlsr->detailed_logging )
1584 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1585
1586
1587 char lst[2];
1588 memset(lst,0,2);
1589 sprintf(lst,"%d",ls_type);
1590
1591 char lsid[10];
1592 memset(lsid,0,10);
1593 sprintf(lsid,"%ld",ls_id);
1594
1595
1596 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1597 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1598
1599
1600 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001601
1602 if ( nlsr->debugging )
1603 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001604
1605 struct nlsa *nlsa;
1606
1607 struct hashtb_enumerator ee;
1608 struct hashtb_enumerator *e = &ee;
1609
1610 int res;
1611
1612 hashtb_start(nlsr->lsdb->name_lsdb, e);
1613 res = hashtb_seek(e, key,strlen(key) , 0);
1614
1615 if( res == HT_OLD_ENTRY )
1616 {
1617 nlsa=e->data;
1618
1619 nlsa->header->isValid=0;
1620
1621 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1622 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1623 write_log_for_name_lsa(nlsa);
1624 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1625
1626 hashtb_delete(e);
1627 }
1628 else if( res == HT_NEW_ENTRY )
1629 {
1630 hashtb_delete(e);
1631 }
1632 hashtb_end(e);
1633
1634 if ( nlsr->debugging )
1635 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1636 if ( nlsr->detailed_logging )
1637 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1638
1639 set_new_lsdb_version();
1640
1641 if ( nlsr->debugging )
1642 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1643 if ( nlsr->detailed_logging )
1644 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1645
1646}
1647
akmhoquef5537b42013-02-22 08:33:32 -06001648
akmhoque866c2222013-02-12 10:49:33 -06001649int
1650delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001651{
akmhoqueb77b95f2013-02-08 12:28:47 -06001652
akmhoque7b791452012-10-30 11:24:56 -05001653 if ( nlsr->debugging )
1654 printf("delete_name_lsa called \n");
1655 if ( nlsr->detailed_logging )
1656 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001657
akmhoque866c2222013-02-12 10:49:33 -06001658 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
akmhoquef5537b42013-02-22 08:33:32 -06001659
akmhoqueda5b6832012-09-13 22:33:55 -05001660
akmhoque7b791452012-10-30 11:24:56 -05001661 if ( nlsr->debugging )
1662 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1663 if ( nlsr->detailed_logging )
1664 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1665
akmhoqueda5b6832012-09-13 22:33:55 -05001666 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001667
1668 if ( nlsr->debugging )
1669 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1670 if ( nlsr->detailed_logging )
1671 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001672
akmhoqueda5b6832012-09-13 22:33:55 -05001673
1674 return 0;
1675}
1676
akmhoquef5537b42013-02-22 08:33:32 -06001677
akmhoque866c2222013-02-12 10:49:33 -06001678int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001679{
akmhoque866c2222013-02-12 10:49:33 -06001680
akmhoque7b791452012-10-30 11:24:56 -05001681 if ( nlsr->debugging )
1682 printf("delete_adj_lsa called \n");
1683 if ( nlsr->detailed_logging )
1684 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001685
akmhoque7b791452012-10-30 11:24:56 -05001686 if ( nlsr->debugging )
1687 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1688 if ( nlsr->detailed_logging )
1689 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1690
akmhoqueda5b6832012-09-13 22:33:55 -05001691 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001692
1693 if ( nlsr->debugging )
1694 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1695 if ( nlsr->detailed_logging )
1696 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1697
akmhoqueda5b6832012-09-13 22:33:55 -05001698
1699 if ( !nlsr->is_route_calculation_scheduled)
1700 {
1701 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1702 nlsr->is_route_calculation_scheduled=1;
1703 }
1704
akmhoqueda5b6832012-09-13 22:33:55 -05001705 return 0;
1706}
1707
akmhoqueffacaa82012-09-13 17:48:30 -05001708void
1709refresh_name_lsdb(void)
1710{
akmhoque7b791452012-10-30 11:24:56 -05001711 if ( nlsr->debugging )
1712 printf("refresh_name_lsdb called \n");
1713 if ( nlsr->detailed_logging )
1714 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001715
akmhoquef5537b42013-02-22 08:33:32 -06001716 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueffacaa82012-09-13 17:48:30 -05001717
1718 long int lsa_life_time;
1719
1720 int i, name_lsdb_element;
1721 struct nlsa *name_lsa;
1722
1723 struct hashtb_enumerator ee;
1724 struct hashtb_enumerator *e = &ee;
1725
1726 hashtb_start(nlsr->lsdb->name_lsdb, e);
1727 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1728
1729 for(i=0;i<name_lsdb_element;i++)
1730 {
1731 name_lsa=e->data;
1732
1733 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001734 if ( nlsr->debugging )
1735 printf("LSA Life Time: %ld \n",lsa_life_time);
1736 if ( nlsr->detailed_logging )
1737 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001738
1739 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1740 {
1741 if ( lsa_life_time > nlsr->lsa_refresh_time )
1742 {
akmhoque14b3f342012-09-14 10:39:02 -05001743 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1744 {
akmhoque7b791452012-10-30 11:24:56 -05001745 if ( nlsr->debugging )
1746 printf("Own Name LSA need to be refrshed\n");
1747 if ( nlsr->detailed_logging )
1748 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001749
1750 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1751 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1752 write_log_for_name_lsa(name_lsa);
1753 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1754
akmhoquef5537b42013-02-22 08:33:32 -06001755 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001756
akmhoque14b3f342012-09-14 10:39:02 -05001757 free(name_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001758 name_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoque14b3f342012-09-14 10:39:02 -05001759 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001760
1761 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1762 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1763 write_log_for_name_lsa(name_lsa);
1764 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001765
akmhoque14b3f342012-09-14 10:39:02 -05001766 free(current_time_stamp);
akmhoqued91401d2013-03-04 11:05:27 -06001767
1768 char lst[2];
1769 memset(lst,0,2);
1770 sprintf(lst,"%d",name_lsa->header->ls_type);
1771
1772 char lsid[10];
1773 memset(lsid,0,10);
1774 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1775
1776 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)
1777 +1+strlen(lst)+1+strlen(lsid)+1);
1778 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+
1779 strlen(lst)+1+strlen(lsid)+1);
1780
1781
1782 make_name_lsa_key(key, name_lsa->header->orig_router->name,
1783 name_lsa->header->ls_type,name_lsa->header->ls_id);
1784
1785 if ( nlsr->debugging )
1786 printf("Name LSA Key: %s \n",key);
1787
1788
1789 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+1+
1790 strlen(name_lsa->header->orig_router->name)
1791 +1+strlen(lst)+1+strlen(lsid)+1+
1792 strlen(name_lsa->header->orig_time)+16,
1793 sizeof(char));
1794 make_name_lsa_prefix_for_repo(repo_key,
1795 name_lsa->header->orig_router->name,
1796 name_lsa->header->ls_type,
1797 name_lsa->header->ls_id,
1798 name_lsa->header->orig_time,
1799 nlsr->slice_prefix);
1800
1801 if ( nlsr->debugging )
1802 printf("Name LSA Repo Key: %s \n",repo_key);
1803
1804 struct name_prefix *lsaid=(struct name_prefix *)
1805 calloc(1,sizeof(struct name_prefix));
1806 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1807 memcpy(lsaid->name,key,strlen(key)+1);
1808 lsaid->length=strlen(key)+1;
1809
1810
1811 write_name_lsa_to_repo(repo_key, lsaid);
1812
1813 free(key);
1814 free(repo_key);
1815 free(lsaid->name);
1816 free(lsaid);
1817
1818
akmhoque866c2222013-02-12 10:49:33 -06001819
1820 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001821 }
1822 else
akmhoquef5537b42013-02-22 08:33:32 -06001823 {
akmhoque866c2222013-02-12 10:49:33 -06001824 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1825 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1826 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1827 write_log_for_name_lsa(name_lsa);
1828 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001829
1830 destroy_name_lsa_component(name_lsa);
1831
akmhoque866c2222013-02-12 10:49:33 -06001832 hashtb_delete(e);
1833 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001834 }
akmhoqueda5b6832012-09-13 22:33:55 -05001835
akmhoque7b791452012-10-30 11:24:56 -05001836 if ( nlsr->debugging )
1837 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1838 if ( nlsr->detailed_logging )
1839 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1840
akmhoqueda5b6832012-09-13 22:33:55 -05001841 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001842
1843 if ( nlsr->debugging )
1844 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1845 if ( nlsr->detailed_logging )
1846 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1847
1848
akmhoqueda5b6832012-09-13 22:33:55 -05001849
1850 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001851 }
1852 else
1853 {
1854 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001855 }
1856 }
1857 else
1858 {
1859 if ( lsa_life_time > nlsr->router_dead_interval )
1860 {
akmhoque7b791452012-10-30 11:24:56 -05001861 if ( nlsr->debugging )
1862 printf("Others Name LSA need to be deleted\n");
1863 if ( nlsr->detailed_logging )
1864 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001865
akmhoque866c2222013-02-12 10:49:33 -06001866 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1867 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1868 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1869 write_log_for_name_lsa(name_lsa);
1870 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoquef5537b42013-02-22 08:33:32 -06001871
1872 destroy_name_lsa_component(name_lsa);
akmhoque866c2222013-02-12 10:49:33 -06001873 hashtb_delete(e);
1874 i++;
1875 }
1876 else
1877 {
1878 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001879 }
1880 }
akmhoqueffacaa82012-09-13 17:48:30 -05001881 }
1882
1883 hashtb_end(e);
1884
1885 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001886
akmhoqueffacaa82012-09-13 17:48:30 -05001887
1888}
1889
akmhoqueda5b6832012-09-13 22:33:55 -05001890void
akmhoqueffacaa82012-09-13 17:48:30 -05001891refresh_adj_lsdb(void)
1892{
akmhoqueffacaa82012-09-13 17:48:30 -05001893
akmhoque7b791452012-10-30 11:24:56 -05001894 if ( nlsr->debugging )
1895 printf("refresh_adj_lsdb called \n");
1896 if ( nlsr->detailed_logging )
1897 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001898
akmhoquef5537b42013-02-22 08:33:32 -06001899 char *time_stamp=get_current_timestamp_micro_v2();
1900
akmhoqueffacaa82012-09-13 17:48:30 -05001901 long int lsa_life_time;
1902
1903 int i, adj_lsdb_element;
1904 struct alsa *adj_lsa;
1905
1906 struct hashtb_enumerator ee;
1907 struct hashtb_enumerator *e = &ee;
1908
1909 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1910 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1911
1912 for(i=0;i<adj_lsdb_element;i++)
1913 {
1914 adj_lsa=e->data;
1915
akmhoqueb77b95f2013-02-08 12:28:47 -06001916 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001917
1918 if ( nlsr->debugging )
1919 printf("LSA Life Time: %ld \n",lsa_life_time);
1920 if ( nlsr->detailed_logging )
1921 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001922
akmhoqueda5b6832012-09-13 22:33:55 -05001923 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1924 {
1925 if ( lsa_life_time > nlsr->lsa_refresh_time )
1926 {
akmhoque7b791452012-10-30 11:24:56 -05001927 if ( nlsr->debugging )
1928 printf("Own Adj LSA need to be refrshed\n");
1929 if ( nlsr->detailed_logging )
1930 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001931
akmhoquea98c2142012-10-25 15:22:24 -05001932 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1933 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1934 write_log_for_adj_lsa(adj_lsa);
1935 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1936
akmhoquef5537b42013-02-22 08:33:32 -06001937 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueda5b6832012-09-13 22:33:55 -05001938
1939 free(adj_lsa->header->orig_time);
akmhoquef5537b42013-02-22 08:33:32 -06001940 adj_lsa->header->orig_time=(char *)calloc(strlen(current_time_stamp)+1,sizeof(char));
akmhoqueda5b6832012-09-13 22:33:55 -05001941 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1942
1943 free(current_time_stamp);
1944
akmhoquea98c2142012-10-25 15:22:24 -05001945 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1946 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1947 write_log_for_adj_lsa(adj_lsa);
1948 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001949
akmhoque7b791452012-10-30 11:24:56 -05001950 if ( nlsr->debugging )
1951 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1952 if ( nlsr->detailed_logging )
1953 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1954
akmhoqueda5b6832012-09-13 22:33:55 -05001955 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001956
1957 if ( nlsr->debugging )
1958 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1959 if ( nlsr->detailed_logging )
1960 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001961
akmhoqued91401d2013-03-04 11:05:27 -06001962
1963 char lst[2];
1964 memset(lst,0,2);
1965 sprintf(lst,"%d",LS_TYPE_ADJ);
1966
1967 char *repo_key=(char *)calloc(strlen(nlsr->slice_prefix)+
1968 strlen(adj_lsa->header->orig_time)+
1969 strlen(adj_lsa->header->orig_router->name)
1970 + strlen(lst) + 5+15,sizeof(char));
1971 make_adj_lsa_prefix_for_repo(repo_key,
1972 adj_lsa->header->orig_router->name,LS_TYPE_ADJ,
1973 adj_lsa->header->orig_time,nlsr->slice_prefix);
1974
1975 if ( nlsr->debugging )
1976 printf("Adj LSA Repo Key: %s \n",repo_key);
1977
1978 char *key=(char *)calloc(adj_lsa->header->orig_router->length+5,
1979 sizeof(char));
1980 make_adj_lsa_key(key,adj_lsa);
1981 if ( nlsr->debugging )
1982 printf("Adj LSA Key: %s \n",key);
1983
1984 struct name_prefix *lsaid=(struct name_prefix *)
1985 calloc(1,sizeof(struct name_prefix));
1986 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
1987 memcpy(lsaid->name,key,strlen(key)+1);
1988 lsaid->length=strlen(key)+1;
1989
1990
1991 write_adj_lsa_to_repo(repo_key, lsaid);
1992
1993 free(key);
1994 free(repo_key);
1995 free(lsaid->name);
1996 free(lsaid);
1997
1998
1999
2000
2001
2002
akmhoqueda5b6832012-09-13 22:33:55 -05002003 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002004
2005
akmhoqueda5b6832012-09-13 22:33:55 -05002006 }
akmhoque866c2222013-02-12 10:49:33 -06002007
2008 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002009 }
2010 else
2011 {
2012 if ( lsa_life_time > nlsr->router_dead_interval )
2013 {
akmhoque7b791452012-10-30 11:24:56 -05002014
2015 if ( nlsr->debugging )
2016 printf("Others Adj LSA need to be deleted\n");
2017 if ( nlsr->detailed_logging )
2018 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06002019 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2020 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2021 write_log_for_adj_lsa(adj_lsa);
2022 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2023 delete_adj_lsa();
akmhoquef5537b42013-02-22 08:33:32 -06002024
2025 destroy_adj_lsa_component(adj_lsa);
akmhoque866c2222013-02-12 10:49:33 -06002026 hashtb_delete(e);
2027 i++;
2028
2029 }
2030 else
2031 {
2032 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05002033 }
2034 }
akmhoquef5537b42013-02-22 08:33:32 -06002035
akmhoqueffacaa82012-09-13 17:48:30 -05002036 }
2037
2038 hashtb_end(e);
2039
2040 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002041}
2042
akmhoqueb77b95f2013-02-08 12:28:47 -06002043
2044void
2045refresh_cor_lsdb(void)
2046{
2047
2048 if ( nlsr->debugging )
2049 printf("refresh_cor_lsdb called \n");
2050 if ( nlsr->detailed_logging )
2051 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2052
akmhoquef5537b42013-02-22 08:33:32 -06002053 char *time_stamp=get_current_timestamp_micro_v2();
2054
akmhoqueb77b95f2013-02-08 12:28:47 -06002055 long int lsa_life_time;
2056
2057 int i, cor_lsdb_element;
2058 struct clsa *cor_lsa;
2059
2060 struct hashtb_enumerator ee;
2061 struct hashtb_enumerator *e = &ee;
2062
2063 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2064 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2065
2066 for(i=0;i<cor_lsdb_element;i++)
2067 {
2068 cor_lsa=e->data;
2069
2070 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2071
2072 if ( nlsr->debugging )
2073 printf("LSA Life Time: %ld \n",lsa_life_time);
2074 if ( nlsr->detailed_logging )
2075 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2076
2077 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2078 {
2079 if ( lsa_life_time > nlsr->lsa_refresh_time )
2080 {
2081 if ( nlsr->debugging )
2082 printf("Own Cor LSA need to be refrshed\n");
2083 if ( nlsr->detailed_logging )
2084 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2085
akmhoquef5537b42013-02-22 08:33:32 -06002086 char *current_time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002087
2088 free(cor_lsa->header->orig_time);
2089 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2090 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2091 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2092
2093 free(current_time_stamp);
2094
akmhoqueb77b95f2013-02-08 12:28:47 -06002095 if ( nlsr->debugging )
2096 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2097 if ( nlsr->detailed_logging )
2098 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2099
2100 set_new_lsdb_version();
2101
2102 if ( nlsr->debugging )
2103 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2104 if ( nlsr->detailed_logging )
2105 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2106
2107 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002108 }
2109
2110 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002111 }
2112 else
2113 {
2114 if ( lsa_life_time > nlsr->router_dead_interval )
2115 {
2116
2117 if ( nlsr->debugging )
2118 printf("Others Adj LSA need to be deleted\n");
2119 if ( nlsr->detailed_logging )
2120 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoquef5537b42013-02-22 08:33:32 -06002121
2122 destroy_cor_lsa_component(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002123 hashtb_delete(e);
2124 i++;
2125 }
akmhoque866c2222013-02-12 10:49:33 -06002126 else
2127 {
2128 hashtb_next(e);
2129 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002130 }
2131
2132
akmhoque866c2222013-02-12 10:49:33 -06002133
akmhoqueb77b95f2013-02-08 12:28:47 -06002134 }
2135
2136 hashtb_end(e);
2137
2138 free(time_stamp);
2139}
2140
akmhoqueffacaa82012-09-13 17:48:30 -05002141int
2142refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2143{
2144 if(flags == CCN_SCHEDULE_CANCEL)
2145 {
2146 return -1;
2147 }
2148
2149 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002150
akmhoque7b791452012-10-30 11:24:56 -05002151 if ( nlsr->debugging )
2152 printf("refresh_lsdb called\n");
2153 if ( nlsr->detailed_logging )
2154 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002155
2156 refresh_name_lsdb();
2157 refresh_adj_lsdb();
2158
akmhoqueffacaa82012-09-13 17:48:30 -05002159 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002160
akmhoqueffacaa82012-09-13 17:48:30 -05002161 nlsr_unlock();
2162 return 0;
2163}
akmhoqueb77b95f2013-02-08 12:28:47 -06002164
2165void
2166write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2167{
2168 if ( nlsr->debugging )
2169 printf("write_adj_lsa_to_repo called\n");
2170 if ( nlsr->debugging )
2171 printf("Content Prefix: %s\n",repo_content_prefix);
2172
2173 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2174 get_adj_lsa_data(lsa_data,lsa_id);
2175 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002176 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002177
akmhoquec25f2242013-03-15 00:24:43 -05002178 //char *data;
2179 //data=ccn_charbuf_as_string(lsa_data);
2180 //data[strlen(data)]='\0';
akmhoquef5537b42013-02-22 08:33:32 -06002181
akmhoquec25f2242013-03-15 00:24:43 -05002182 //write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002183
akmhoquec25f2242013-03-15 00:24:43 -05002184 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoque323b5e92013-02-21 13:55:15 -06002185
akmhoquec25f2242013-03-15 00:24:43 -05002186 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002187}
2188
2189void
2190write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2191{
2192 if ( nlsr->debugging )
2193 printf("write_name_lsa_to_repo called\n");
2194 if ( nlsr->debugging )
2195 printf("Content Prefix: %s\n",repo_content_prefix);
2196
2197 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2198 get_name_lsa_data(lsa_data,lsa_id);
2199
2200 if ( nlsr->debugging )
2201 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2202
akmhoquec25f2242013-03-15 00:24:43 -05002203 //char *data;
2204 //data=ccn_charbuf_as_string(lsa_data);
2205 //data[strlen(data)]='\0';
akmhoque323b5e92013-02-21 13:55:15 -06002206
akmhoquec25f2242013-03-15 00:24:43 -05002207 //write_data_to_repo(data, repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002208
akmhoquec25f2242013-03-15 00:24:43 -05002209 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
2210
2211 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002212}
2213
2214
2215void
2216write_name_lsdb_to_repo(char *slice_prefix)
2217{
2218 int i, name_lsdb_element;
2219
2220 struct nlsa *name_lsa;
2221 struct hashtb_enumerator ee;
2222 struct hashtb_enumerator *e = &ee;
2223
2224 hashtb_start(nlsr->lsdb->name_lsdb, e);
2225 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2226
2227 for(i=0;i<name_lsdb_element;i++)
2228 {
2229 name_lsa=e->data;
2230
2231 char lst[2];
2232 memset(lst,0,2);
2233 sprintf(lst,"%d",name_lsa->header->ls_type);
2234
2235 char lsid[10];
2236 memset(lsid,0,10);
2237 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2238
2239
2240 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2241 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2242
2243
2244 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2245
2246 if ( nlsr->debugging )
2247 printf("Name LSA Key: %s \n",key);
2248
2249
akmhoquef5537b42013-02-22 08:33:32 -06002250 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 -06002251 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);
2252
2253 if ( nlsr->debugging )
2254 printf("Name LSA Repo Key: %s \n",repo_key);
2255
akmhoquef5537b42013-02-22 08:33:32 -06002256 struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix));
2257 lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char));
2258 memcpy(lsaid->name,key,strlen(key)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002259 lsaid->length=strlen(key)+1;
2260
2261
2262 write_name_lsa_to_repo(repo_key, lsaid);
2263
2264 free(key);
2265 free(repo_key);
2266 free(lsaid->name);
2267 free(lsaid);
2268
2269 hashtb_next(e);
2270 }
2271
2272 hashtb_end(e);
2273
2274
2275}
2276
2277void
2278print_cor_lsa(struct clsa *cor_lsa)
2279{
2280 if ( nlsr->debugging )
2281 {
2282 printf("-----------Cor LSA Content---------------\n");
2283 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2284 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2285 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2286 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2287 printf(" LSA Data \n");
2288 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2289 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2290
2291 printf("\n");
2292 }
2293}
2294
2295void
2296print_cor_lsdb()
2297{
2298
2299 if ( nlsr->debugging )
2300 printf("print_cor_lsdb called \n");
2301
2302 struct hashtb_enumerator ee;
2303 struct hashtb_enumerator *e = &ee;
2304
2305 int i=1;
2306
2307 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2308 {
2309 if ( nlsr->debugging )
2310 printf("-----------Cor LSA (%d)---------------\n",i);
2311 struct clsa *cor_lsa=e->data;
2312 print_cor_lsa(cor_lsa);
2313 i++;
2314 }
2315 hashtb_end(e);
2316
2317 if ( nlsr->debugging )
2318 printf("\n");
2319 if ( nlsr->detailed_logging )
2320 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2321}
2322
2323void
2324install_cor_lsa(struct clsa *cor_lsa)
2325{
2326 if ( nlsr->debugging )
2327 printf("install_cor_lsa called \n");
2328 if ( nlsr->detailed_logging )
2329 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2330
2331
akmhoquececba942013-02-25 17:33:34 -06002332 //char *time_stamp=(char *)malloc(20);
2333 //memset(time_stamp,0,20);
2334 //get_current_timestamp_micro(time_stamp);
akmhoqueb77b95f2013-02-08 12:28:47 -06002335
2336
akmhoque569a93d2013-02-21 10:19:54 -06002337 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2338 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002339 make_cor_lsa_key(key,cor_lsa);
2340
2341 if ( nlsr->debugging )
2342 printf("Cor LSA key: %s \n",key);
2343
2344 struct hashtb_enumerator ee;
2345 struct hashtb_enumerator *e = &ee;
2346 int res;
2347
2348 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2349 res = hashtb_seek(e, key, strlen(key), 0);
2350
2351 if ( res == HT_NEW_ENTRY )
2352 {
2353 if ( nlsr->debugging )
2354 printf("New Cor LSA... \n");
2355
akmhoque8876e982013-02-21 13:35:46 -06002356 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002357 new_cor_lsa=e->data;
2358 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2359
2360 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2361 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
akmhoquececba942013-02-25 17:33:34 -06002362 //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -06002363 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2364 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2365
akmhoque483c1eb2013-03-08 00:51:09 -06002366 new_cor_lsa->header->orig_time=(char *)calloc(strlen(cor_lsa->header->orig_time)+1,sizeof(char)); //free
akmhoquececba942013-02-25 17:33:34 -06002367 //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
akmhoque483c1eb2013-03-08 00:51:09 -06002368 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2369 //new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002370
2371 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2372
2373 new_cor_lsa->cor_r=cor_lsa->cor_r;
2374 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2375 }
2376 else if ( res == HT_OLD_ENTRY )
2377 {
2378 if ( nlsr->debugging )
2379 printf("Cor LSA exists (Old)... \n");
2380 }
2381 hashtb_end(e);
2382
akmhoquef5537b42013-02-22 08:33:32 -06002383 free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002384
2385}
2386
2387void
2388build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2389{
2390 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2391 cor_lsa->header->ls_type=LS_TYPE_COR;
2392
akmhoquef5537b42013-02-22 08:33:32 -06002393 char *time_stamp=get_current_timestamp_micro_v2();
akmhoqueb77b95f2013-02-08 12:28:47 -06002394 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2395 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2396 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2397 free(time_stamp);
2398
akmhoquef5537b42013-02-22 08:33:32 -06002399 cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
2400 cor_lsa->header->orig_router->name=(char *)calloc(strlen(nlsr->router_name)+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002401 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2402 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2403 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2404
2405 cor_lsa->cor_r=cor_r;
2406 cor_lsa->cor_theta=cor_theta;
2407
2408}
2409
2410void
2411build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2412{
2413 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2414 cor_lsa->header->ls_type=ls_type;
2415
2416 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2417 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002418 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002419
2420 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2421 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2422 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002423 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002424 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2425
2426 cor_lsa->cor_r=cor_r;
2427 cor_lsa->cor_theta=cor_theta;
2428
2429}
2430
2431void
2432build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2433{
2434 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2435 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2436 install_cor_lsa(cor_lsa);
2437
2438 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002439
akmhoquef5537b42013-02-22 08:33:32 -06002440 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002441}
2442
2443
2444void
2445build_and_install_cor_lsa()
2446{
2447
2448
2449
2450 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2451
2452 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2453 install_cor_lsa(cor_lsa);
2454
2455 write_cor_lsa_to_repo(cor_lsa);
akmhoquef5537b42013-02-22 08:33:32 -06002456 destroy_cor_lsa(cor_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06002457
2458 print_cor_lsdb();
akmhoqueb77b95f2013-02-08 12:28:47 -06002459
2460}
2461
2462void
2463get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2464{
2465 if ( nlsr->debugging )
2466 printf("get_cor_lsa_data called \n");
2467 if ( nlsr->detailed_logging )
2468 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2469
akmhoquececba942013-02-25 17:33:34 -06002470 struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002471
2472 struct hashtb_enumerator ee;
2473 struct hashtb_enumerator *e = &ee;
2474 int res;
2475
2476 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2477 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2478
2479 if( res == HT_OLD_ENTRY )
2480 {
2481 cor_lsa=e->data;
2482
2483 if ( nlsr->debugging )
2484 printf("Cor LSA found \n");
2485 if ( nlsr->detailed_logging )
2486 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2487
2488 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2489 ccn_charbuf_append_string(lsa_data,"|");
2490
2491 char *temp_length=(char *)malloc(20);
2492 memset(temp_length,0,20);
2493 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2494 ccn_charbuf_append_string(lsa_data,temp_length);
2495 ccn_charbuf_append_string(lsa_data,"|");
2496 free(temp_length);
2497
2498 char *temp_ltype=(char *)malloc(20);
2499 memset(temp_ltype,0,20);
2500 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2501 ccn_charbuf_append_string(lsa_data,temp_ltype);
2502 ccn_charbuf_append_string(lsa_data,"|");
2503 free(temp_ltype);
2504
2505 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2506 ccn_charbuf_append_string(lsa_data,"|");
2507
2508 char *cor_r=(char *)malloc(20);
2509 memset(cor_r,0,20);
2510 sprintf(cor_r,"%f",cor_lsa->cor_r);
2511 ccn_charbuf_append_string(lsa_data,cor_r);
2512 ccn_charbuf_append_string(lsa_data,"|");
2513 free(cor_r);
2514
2515 char *cor_theta=(char *)malloc(20);
2516 memset(cor_theta,0,20);
2517 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2518 ccn_charbuf_append_string(lsa_data,cor_theta);
2519 ccn_charbuf_append_string(lsa_data,"|");
2520 free(cor_theta);
2521
2522 }
2523 else if(res == HT_NEW_ENTRY)
2524 {
2525 hashtb_delete(e);
2526 }
2527
2528 hashtb_end(e);
2529}
2530
2531void
2532write_cor_lsa_to_repo(struct clsa *cor_lsa)
2533{
2534
2535
2536 if ( nlsr->debugging )
2537 printf("write_cor_lsa_to_repo called\n");
2538
2539
akmhoquef5537b42013-02-22 08:33:32 -06002540 char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06002541 make_cor_lsa_key(key,cor_lsa);
2542
2543 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2544 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002545
akmhoqueb77b95f2013-02-08 12:28:47 -06002546 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002547 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2548
akmhoqueb77b95f2013-02-08 12:28:47 -06002549 char *lst=(char *)malloc(20);
2550 memset(lst,0,20);
2551 sprintf(lst,"%d",cor_lsa->header->ls_type);
akmhoquef5537b42013-02-22 08:33:32 -06002552 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 -06002553 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);
2554
2555 if ( nlsr->debugging )
2556 printf("Cor LSA Repo Key: %s \n",repo_key);
2557
akmhoquec25f2242013-03-15 00:24:43 -05002558 //char *data;
2559 //data=ccn_charbuf_as_string(lsa_data);
2560 //data[strlen(data)]='\0';
akmhoquef5537b42013-02-22 08:33:32 -06002561
akmhoquec25f2242013-03-15 00:24:43 -05002562 //write_data_to_repo(data, repo_content_prefix);
2563
2564 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
akmhoque0800eda2013-02-21 14:17:52 -06002565
akmhoqueb77b95f2013-02-08 12:28:47 -06002566
2567
2568
2569 free(lst);
2570 free(key);
2571 free(repo_key);
akmhoquec25f2242013-03-15 00:24:43 -05002572 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002573}
2574
2575void
2576make_cor_lsa_key_by_router_name(char *key,char *router_name)
2577{
2578 memcpy(key+strlen(key),router_name,strlen(router_name));
2579 memcpy(key+strlen(key),"/",1);
2580 char ls_type[2];
2581 sprintf(ls_type,"%d",LS_TYPE_COR);
2582 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2583 key[strlen(key)]='\0';
2584}
2585
2586
2587double
2588get_hyperbolic_r(char *router)
2589{
2590 double ret=-1.0;
2591 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2592 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2593
2594
2595 struct clsa *cor_lsa;
2596 struct hashtb_enumerator ee;
2597 struct hashtb_enumerator *e = &ee;
2598 int res;
2599
2600 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2601 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2602
2603 if ( res == HT_OLD_ENTRY)
2604 {
2605 cor_lsa=e->data;
2606 ret=cor_lsa->cor_r;
2607 }
2608 else if(res == HT_NEW_ENTRY)
2609 {
2610 hashtb_delete(e);
2611 }
2612
2613 hashtb_end(e);
2614
2615 free(cor_lsa_key);
2616 return ret;
2617}
2618
2619double
2620get_hyperbolic_theta(char *router)
2621{
akmhoquef5537b42013-02-22 08:33:32 -06002622 double ret=-1.0;
akmhoqueb77b95f2013-02-08 12:28:47 -06002623 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2624 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2625
2626 struct clsa *cor_lsa;
2627 struct hashtb_enumerator ee;
2628 struct hashtb_enumerator *e = &ee;
2629 int res;
2630
2631 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2632 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2633
2634 if ( res == HT_OLD_ENTRY)
2635 {
2636 cor_lsa=e->data;
2637 ret=cor_lsa->cor_theta;
2638 }
2639 else if(res == HT_NEW_ENTRY)
2640 {
2641 hashtb_delete(e);
2642 }
2643
2644 hashtb_end(e);
2645
2646 free(cor_lsa_key);
2647 return ret;
2648}
akmhoquead584782013-02-22 10:56:03 -06002649
2650
2651void
2652destroy_name_lsdb(void)
2653{
2654 int i, name_lsdb_element;
2655 struct nlsa *name_lsa;
2656
2657 struct hashtb_enumerator ee;
2658 struct hashtb_enumerator *e = &ee;
2659
2660 hashtb_start(nlsr->lsdb->name_lsdb, e);
2661 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2662
2663 for(i=0;i<name_lsdb_element;i++)
2664 {
2665 name_lsa=e->data;
2666 destroy_name_lsa_component(name_lsa);
2667 hashtb_next(e);
2668 }
2669
2670 hashtb_end(e);
2671
2672 if ( nlsr->lsdb->name_lsdb )
2673 hashtb_destroy(&nlsr->lsdb->name_lsdb);
2674}
2675
2676void
2677destroy_adj_lsdb(void)
2678{
2679 int i, adj_lsdb_element;
2680 struct alsa *adj_lsa;
2681
2682 struct hashtb_enumerator ee;
2683 struct hashtb_enumerator *e = &ee;
2684
2685 hashtb_start(nlsr->lsdb->adj_lsdb, e);
2686 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
2687
2688 for(i=0;i<adj_lsdb_element;i++)
2689 {
2690 adj_lsa=e->data;
2691 destroy_adj_lsa_component(adj_lsa);
2692 hashtb_next(e);
2693 }
2694
2695 hashtb_end(e);
2696 if(nlsr->lsdb->adj_lsdb )
2697 hashtb_destroy(&nlsr->lsdb->adj_lsdb);
2698}
2699
2700void
2701destroy_cor_lsdb(void)
2702{
2703 int i, cor_lsdb_element;
2704 struct clsa *cor_lsa;
2705
2706 struct hashtb_enumerator ee;
2707 struct hashtb_enumerator *e = &ee;
2708
2709 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2710 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2711
2712 for(i=0;i<cor_lsdb_element;i++)
2713 {
2714 cor_lsa=e->data;
2715 destroy_cor_lsa_component(cor_lsa);
2716 hashtb_next(e);
2717 }
2718
2719 hashtb_end(e);
2720 if(nlsr->lsdb->cor_lsdb )
2721 hashtb_destroy(&nlsr->lsdb->cor_lsdb);
2722}
2723
2724void
2725destroy_lsdb(void)
2726{
2727 destroy_name_lsdb();
2728 destroy_adj_lsdb();
2729 destroy_cor_lsdb();
2730
2731 if ( nlsr->lsdb->lsdb_version )
2732 free(nlsr->lsdb->lsdb_version);
2733 if ( nlsr->lsdb )
2734 free(nlsr->lsdb);
2735}