blob: cd58097e693294498df400201427d2dcfbbbb197 [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 char *time_stamp=(char *)malloc(20);
38 memset(time_stamp,0,20);
39 get_current_timestamp_micro(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040040
akmhoque03004e62012-09-06 01:12:28 -050041 free(nlsr->lsdb->lsdb_version);
42 nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
43 memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
44 memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
45
46 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050047
akmhoquef71d9082012-08-22 12:51:53 -040048}
49
akmhoque0ab71642013-02-21 10:10:33 -060050/**
51* Make key for storing Name LSA in Name LSDB
52*/
53
akmhoque03004e62012-09-06 01:12:28 -050054void
55make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
56{
57
akmhoque03004e62012-09-06 01:12:28 -050058 char lst[2];
59 memset(lst,0,2);
60 sprintf(lst,"%d",ls_type);
61
62 char lsid[10];
63 memset(lsid,0,10);
64 sprintf(lsid,"%ld",ls_id);
65
66 memcpy(key+strlen(key),orig_router,strlen(orig_router));
67 memcpy(key+strlen(key),"/",1);
68 memcpy(key+strlen(key),lst,strlen(lst));
69 memcpy(key+strlen(key),"/",1);
70 memcpy(key+strlen(key),lsid,strlen(lsid));
akmhoque03004e62012-09-06 01:12:28 -050071
akmhoqueb77b95f2013-02-08 12:28:47 -060072 if ( nlsr->debugging )
73 printf("name LSA Key: %s\n", key);
74}
75
akmhoque0ab71642013-02-21 10:10:33 -060076/**
77* Make content name prefix for Name LSA to store in repo
78*/
akmhoqueb77b95f2013-02-08 12:28:47 -060079
80void
akmhoque0ab71642013-02-21 10:10:33 -060081make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
82 long int ls_id,char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060083{
akmhoque0ab71642013-02-21 10:10:33 -060084 sprintf(key,"%s%s/lsType.%d/lsId.%ld/%s",slice_prefix, orig_router, ls_type,
85 ls_id, orig_time);
akmhoqueb77b95f2013-02-08 12:28:47 -060086
87 if ( nlsr->debugging )
88 printf("Name LSA prefix for repo content: %s\n",key);
89}
90
akmhoque0ab71642013-02-21 10:10:33 -060091/**
92* Make content name prefix for Adj LSA to store in repo
93*/
94
akmhoqueb77b95f2013-02-08 12:28:47 -060095void
akmhoque0ab71642013-02-21 10:10:33 -060096make_adj_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
97 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060098{
99
100 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
101
102 if ( nlsr->debugging )
103 printf("Name LSA prefix for repo content:%s\n",key);
104}
105
akmhoque0ab71642013-02-21 10:10:33 -0600106/**
107* Make content name prefix for Cor LSA to store in repo
108*/
109
akmhoqueb77b95f2013-02-08 12:28:47 -0600110void
akmhoque0ab71642013-02-21 10:10:33 -0600111make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
112 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -0600113{
114
115 sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time );
116
117 if ( nlsr->debugging )
118 printf("Cor LSA prefix for repo content:%s\n",key);
akmhoque03004e62012-09-06 01:12:28 -0500119}
akmhoque53f64222012-09-05 13:57:51 -0500120
akmhoque0ab71642013-02-21 10:10:33 -0600121/**
122* Build name lsa for all name prefixes in Name Prefix List (NPL). Intsall Name
123* LSA in Name LSDB for router itself.
124*/
125
126
akmhoquef71d9082012-08-22 12:51:53 -0400127void
akmhoque53f64222012-09-05 13:57:51 -0500128build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -0400129{
akmhoque7b791452012-10-30 11:24:56 -0500130 if ( nlsr->debugging )
131 printf("build_and_install_name_lsas called \n");
132 if ( nlsr->detailed_logging )
133 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n");
akmhoquef71d9082012-08-22 12:51:53 -0400134
akmhoquef71d9082012-08-22 12:51:53 -0400135 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600136 struct name_prefix_list_entry *npe;
akmhoquef71d9082012-08-22 12:51:53 -0400137
138 struct hashtb_enumerator ee;
139 struct hashtb_enumerator *e = &ee;
140
141 hashtb_start(nlsr->npl, e);
142 npl_element=hashtb_n(nlsr->npl);
143
144 for(i=0;i<npl_element;i++)
145 {
akmhoque3171d652012-11-13 11:44:33 -0600146 npe=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500147 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
akmhoque3171d652012-11-13 11:44:33 -0600148 build_name_lsa(name_lsa,npe->np);
akmhoque03004e62012-09-06 01:12:28 -0500149
akmhoquef71d9082012-08-22 12:51:53 -0400150 install_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600151 update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id);
akmhoque03004e62012-09-06 01:12:28 -0500152 free(name_lsa->header->orig_router->name);
153 free(name_lsa->header->orig_router);
154 free(name_lsa->header);
155 free(name_lsa->name_prefix->name);
156 free(name_lsa->name_prefix);
akmhoquef71d9082012-08-22 12:51:53 -0400157 free(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400158 hashtb_next(e);
159 }
160
akmhoque53f64222012-09-05 13:57:51 -0500161 hashtb_end(e);
akmhoque3171d652012-11-13 11:44:33 -0600162
163 print_name_prefix_from_npl();
164
165}
166
akmhoque0ab71642013-02-21 10:10:33 -0600167/**
168* Build and Install one Name LSA Use ful for API
169*/
170
akmhoque3171d652012-11-13 11:44:33 -0600171void
172build_and_install_single_name_lsa(struct name_prefix *np)
173{
174 if ( nlsr->debugging )
175 printf("build_and_install_single_name_lsa called \n");
176 if ( nlsr->detailed_logging )
177 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name_lsa called\n");
178
179 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
180 build_name_lsa(name_lsa,np);
181
182 install_name_lsa(name_lsa);
183 update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id);
184
185 free(name_lsa->header->orig_router->name);
186 free(name_lsa->header->orig_router);
187 free(name_lsa->header);
188 free(name_lsa->name_prefix->name);
189 free(name_lsa->name_prefix);
190 free(name_lsa);
191
192 print_name_prefix_from_npl();
akmhoquef71d9082012-08-22 12:51:53 -0400193
akmhoquef71d9082012-08-22 12:51:53 -0400194}
195
akmhoque53f64222012-09-05 13:57:51 -0500196void
197build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
198{
akmhoque53f64222012-09-05 13:57:51 -0500199 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
200 name_lsa->header->ls_type=LS_TYPE_NAME;
201
akmhoque03004e62012-09-06 01:12:28 -0500202 char *time_stamp=(char *)malloc(20);
203 memset(time_stamp,0,20);
204 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500205
akmhoque03004e62012-09-06 01:12:28 -0500206 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500207 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
208 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500209
210 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500211
212 name_lsa->header->ls_id=++nlsr->nlsa_id;
213 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500214 name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
215 memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
216 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
217 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500218 name_lsa->header->isValid=1;
219
220
221 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
222 name_lsa->name_prefix->name=(char *)malloc(np->length);
223 memcpy(name_lsa->name_prefix->name,np->name,np->length);
224 name_lsa->name_prefix->length=np->length;
225
226}
227
akmhoque53f64222012-09-05 13:57:51 -0500228void
229install_name_lsa(struct nlsa *name_lsa)
230{
akmhoque53f64222012-09-05 13:57:51 -0500231
akmhoqueffacaa82012-09-13 17:48:30 -0500232 char *time_stamp=(char *)malloc(20);
233 memset(time_stamp,0,20);
234 get_current_timestamp_micro(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -0500235
236
akmhoque0ab71642013-02-21 10:10:33 -0600237 char lst[2];
238 memset(lst,0,2);
239 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoqueffacaa82012-09-13 17:48:30 -0500240
akmhoque0ab71642013-02-21 10:10:33 -0600241 char lsid[10];
242 memset(lsid,0,10);
243 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque3171d652012-11-13 11:44:33 -0600244
akmhoque0ab71642013-02-21 10:10:33 -0600245 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
246 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
247 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque53f64222012-09-05 13:57:51 -0500248
akmhoque0ab71642013-02-21 10:10:33 -0600249 if ( nlsr->debugging )
250 printf("Key:%s Length:%d\n",key,(int)strlen(key));
251 if ( nlsr->detailed_logging )
252 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key));
253
akmhoque8876e982013-02-21 13:35:46 -0600254 struct nlsa *new_name_lsa; //=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque53f64222012-09-05 13:57:51 -0500255
akmhoque0ab71642013-02-21 10:10:33 -0600256 struct hashtb_enumerator ee;
257 struct hashtb_enumerator *e = &ee;
258 int res;
akmhoque53f64222012-09-05 13:57:51 -0500259
akmhoque0ab71642013-02-21 10:10:33 -0600260 hashtb_start(nlsr->lsdb->name_lsdb, e);
261 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500262
akmhoque0ab71642013-02-21 10:10:33 -0600263 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500264 {
akmhoqueffacaa82012-09-13 17:48:30 -0500265
akmhoque7b791452012-10-30 11:24:56 -0500266 if ( nlsr->debugging )
267 printf("New Name LSA... Adding to LSDB\n");
268 if ( nlsr->detailed_logging )
269 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n");
270
271
akmhoqueffacaa82012-09-13 17:48:30 -0500272 new_name_lsa = e->data;
akmhoque8876e982013-02-21 13:35:46 -0600273
akmhoque0ab71642013-02-21 10:10:33 -0600274 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500275 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
276
277 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
278 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque8876e982013-02-21 13:35:46 -0600279 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500280
281 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque0ab71642013-02-21 10:10:33 -0600282 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500283 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
284 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
285 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
286 new_name_lsa->header->isValid=name_lsa->header->isValid;
287
288
akmhoque0ab71642013-02-21 10:10:33 -0600289 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500290 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
291 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
292 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
akmhoque8876e982013-02-21 13:35:46 -0600293
akmhoqueffacaa82012-09-13 17:48:30 -0500294
akmhoque7b791452012-10-30 11:24:56 -0500295 if ( nlsr->debugging )
296 {
297 printf("New Name LSA Added....\n");
298 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
299 }
300 if ( nlsr->detailed_logging )
301 {
302 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n");
303 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
304 }
akmhoqueffacaa82012-09-13 17:48:30 -0500305 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500306 if ( nlsr->debugging )
307 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
308 if ( nlsr->detailed_logging )
309 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500310
akmhoque9e9fc722012-09-26 14:03:25 -0500311
akmhoquede61ba92012-09-20 22:19:12 -0500312 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500313 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500314 {
akmhoquede61ba92012-09-20 22:19:12 -0500315 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 -0500316 if ( check == HT_NEW_ENTRY )
317 {
akmhoque7b791452012-10-30 11:24:56 -0500318 if ( nlsr->debugging )
319 printf("Added in npt \n");
320 if ( nlsr->detailed_logging )
321 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500322 }
akmhoque3560cb62012-09-09 10:52:30 -0500323 }
akmhoqueffacaa82012-09-13 17:48:30 -0500324 else
akmhoque3560cb62012-09-09 10:52:30 -0500325 {
akmhoquede61ba92012-09-20 22:19:12 -0500326 int *faces=malloc(num_next_hop*sizeof(int));
327 int *route_costs=malloc(num_next_hop*sizeof(int));
328 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500329 if ( nlsr->debugging )
330 {
331 printf("Printing from install_name_lsa \n");
332 int j;
333 for(j=0;j<num_next_hop;j++)
334 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
335 }
336 if ( nlsr->detailed_logging )
337 {
338 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
339 int j;
340 for(j=0;j<num_next_hop;j++)
341 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
342 }
akmhoquede61ba92012-09-20 22:19:12 -0500343 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 -0500344 if ( check == HT_NEW_ENTRY )
345 {
akmhoque7b791452012-10-30 11:24:56 -0500346 if ( nlsr->debugging )
347 printf("Added in npt \n");
348 if ( nlsr->detailed_logging )
349 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500350 }
akmhoquede61ba92012-09-20 22:19:12 -0500351 free(faces);
352 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500353
akmhoque3560cb62012-09-09 10:52:30 -0500354 }
akmhoquede61ba92012-09-20 22:19:12 -0500355
akmhoque9e9fc722012-09-26 14:03:25 -0500356 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
357 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
358 write_log_for_name_lsa(new_name_lsa);
359 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500360
akmhoquede61ba92012-09-20 22:19:12 -0500361 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -0500362
363 }
364 else if(res == HT_OLD_ENTRY)
365 {
366 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500367 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500368 {
akmhoque7b791452012-10-30 11:24:56 -0500369 if ( nlsr->debugging )
370 printf("Older Adj LSA. Discarded... \n");
371 if ( nlsr->detailed_logging )
372 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500373 }
374 else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 )
375 {
akmhoque7b791452012-10-30 11:24:56 -0500376 if ( nlsr->debugging )
377 printf("Duplicate Adj LSA. Discarded... \n");
378 if ( nlsr->detailed_logging )
379 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500380 }
381 else
382 {
383 if ( name_lsa->header->isValid == 0 )
384 {
385 // have to call to delete npt table entry
akmhoque3cced642012-09-24 16:20:20 -0500386 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 -0500387
388 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
389 {
akmhoque9e9fc722012-09-26 14:03:25 -0500390 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
391 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
392 write_log_for_name_lsa(new_name_lsa);
393 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
394
akmhoqueffacaa82012-09-13 17:48:30 -0500395 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500396 if ( nlsr->debugging )
397 printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
398 if ( nlsr->detailed_logging )
399 writeLogg(__FILE__,__FUNCTION__,__LINE__,"isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500400 }
401 else
402 {
403 new_name_lsa->header->isValid=name_lsa->header->isValid;
404 free(new_name_lsa->header->orig_time);
405 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
406 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
407 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
408 }
akmhoque7b791452012-10-30 11:24:56 -0500409 if ( nlsr->debugging )
410 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
411 if ( nlsr->detailed_logging )
412 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500413 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500414 if ( nlsr->debugging )
415 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
416 if ( nlsr->detailed_logging )
417 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500418 }
419 else
420 {
421 int is_npt_update=0;
422 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
423 {
424 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500425 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 -0500426 }
427
428 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500429 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
430 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
431 write_log_for_name_lsa(new_name_lsa);
432 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
433
akmhoqueffacaa82012-09-13 17:48:30 -0500434
435 free(new_name_lsa->header->orig_time);
436 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
437 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600438 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500439
440 new_name_lsa->header->isValid=name_lsa->header->isValid;
441
442 free(new_name_lsa->name_prefix->name);
443 free(new_name_lsa->name_prefix);
444 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
445 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
446 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
447 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
448
akmhoque9e9fc722012-09-26 14:03:25 -0500449
450 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
451 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
452 write_log_for_name_lsa(new_name_lsa);
453 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
454
akmhoque7b791452012-10-30 11:24:56 -0500455 if ( nlsr->debugging )
456 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
457 if ( nlsr->detailed_logging )
458 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
459
akmhoqueffacaa82012-09-13 17:48:30 -0500460 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500461
462 if ( nlsr->debugging )
463 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
464 if ( nlsr->detailed_logging )
465 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
466
akmhoqueffacaa82012-09-13 17:48:30 -0500467
468 if( is_npt_update == 1 )
469 {
akmhoquede61ba92012-09-20 22:19:12 -0500470 //struct hashtb *face_list;
471 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
472 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500473 {
akmhoquede61ba92012-09-20 22:19:12 -0500474
475 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 -0500476 if ( check == HT_NEW_ENTRY )
477 {
akmhoque7b791452012-10-30 11:24:56 -0500478 if ( nlsr->debugging )
479 printf("Added in npt \n");
480 if ( nlsr->detailed_logging )
481 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500482 }
483 }
484 else
485 {
akmhoquede61ba92012-09-20 22:19:12 -0500486 int *faces=malloc(num_next_hop*sizeof(int));
487 int *route_costs=malloc(num_next_hop*sizeof(int));
488 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500489
490 if ( nlsr->debugging )
491 {
492 printf("Printing from install_name_lsa \n");
493 int j;
494 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500495 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500496 }
497 if ( nlsr->detailed_logging )
498 {
499 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
500 int j;
501 for(j=0;j<num_next_hop;j++)
502 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
503 }
504
akmhoquede61ba92012-09-20 22:19:12 -0500505
506 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 -0500507 if ( check == HT_NEW_ENTRY )
508 {
akmhoque7b791452012-10-30 11:24:56 -0500509 if ( nlsr->debugging )
510 printf("Added in npt \n");
511 if ( nlsr->detailed_logging )
512 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500513 }
akmhoquede61ba92012-09-20 22:19:12 -0500514 free(faces);
515 free(route_costs);
516
akmhoqueffacaa82012-09-13 17:48:30 -0500517 }
akmhoquede61ba92012-09-20 22:19:12 -0500518
akmhoqueffacaa82012-09-13 17:48:30 -0500519 }
520 }
521 }
522
akmhoque3560cb62012-09-09 10:52:30 -0500523 }
akmhoque53f64222012-09-05 13:57:51 -0500524
akmhoqueffacaa82012-09-13 17:48:30 -0500525 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500526
akmhoque569a93d2013-02-21 10:19:54 -0600527 //free(key);
akmhoque53f64222012-09-05 13:57:51 -0500528}
529
akmhoque9e9fc722012-09-26 14:03:25 -0500530void
531write_log_for_name_lsa(struct nlsa *name_lsa)
532{
533
534 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
535 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
536 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500537 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
538 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
539 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
540 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500541 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
542 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
543 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
544 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
545}
akmhoque53f64222012-09-05 13:57:51 -0500546
akmhoque03004e62012-09-06 01:12:28 -0500547void
548print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500549{
akmhoque53f64222012-09-05 13:57:51 -0500550
akmhoque7b791452012-10-30 11:24:56 -0500551 if ( nlsr->debugging )
552 {
553 printf("-----------Name LSA Content---------------\n");
554 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
555 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
556 printf(" LS Type : %d\n",name_lsa->header->ls_type);
557 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
558 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
559 printf(" Is Valid : %d\n",name_lsa->header->isValid);
560 printf(" LSA Data \n");
561 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
562 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
563
564 printf("\n");
565 }
akmhoquef71d9082012-08-22 12:51:53 -0400566}
567
568void
569print_name_lsdb(void)
570{
akmhoque7b791452012-10-30 11:24:56 -0500571 if ( nlsr->debugging )
572 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500573 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400574 struct nlsa *name_lsa;
575
576 struct hashtb_enumerator ee;
577 struct hashtb_enumerator *e = &ee;
578
579 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500580 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400581
akmhoque53f64222012-09-05 13:57:51 -0500582 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400583 {
akmhoque7b791452012-10-30 11:24:56 -0500584 if ( nlsr->debugging )
585 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400586 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500587 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400588 hashtb_next(e);
589 }
590
591 hashtb_end(e);
592
akmhoque3171d652012-11-13 11:44:33 -0600593 if ( nlsr->debugging )
594 printf("\n");
595 if ( nlsr->detailed_logging )
596 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500597}
598
akmhoque03004e62012-09-06 01:12:28 -0500599
600void
601build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500602{
akmhoque7b791452012-10-30 11:24:56 -0500603 if ( nlsr->debugging )
604 printf("build_and_install_others_name_lsa called \n");
605 if ( nlsr->detailed_logging )
606 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500607
akmhoque03004e62012-09-06 01:12:28 -0500608 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
609 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
610 print_name_lsa(name_lsa);
611 install_name_lsa(name_lsa);
612 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500613 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500614
akmhoque03004e62012-09-06 01:12:28 -0500615 free(name_lsa->header->orig_router->name);
616 free(name_lsa->header->orig_router);
617 free(name_lsa->header);
618 free(name_lsa->name_prefix->name);
619 free(name_lsa->name_prefix);
620 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500621
622}
623
624void
akmhoque03004e62012-09-06 01:12:28 -0500625build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500626{
akmhoque7b791452012-10-30 11:24:56 -0500627 if ( nlsr->debugging )
628 printf("build_others_name_lsa called\n");
629 if ( nlsr->detailed_logging )
630 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500631
akmhoque03004e62012-09-06 01:12:28 -0500632 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
633 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500634
akmhoque03004e62012-09-06 01:12:28 -0500635 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
636 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600637 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoque53f64222012-09-05 13:57:51 -0500638
akmhoque03004e62012-09-06 01:12:28 -0500639 name_lsa->header->ls_id=ls_id;
640 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
641 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
642 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600643 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -0500644 name_lsa->header->orig_router->length=strlen(orig_router)+1;
645 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500646
akmhoque03004e62012-09-06 01:12:28 -0500647 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
648 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
649 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600650 memcpy(name_lsa->name_prefix->name,np,strlen(np));
akmhoque03004e62012-09-06 01:12:28 -0500651 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400652}
akmhoqued79438d2012-08-27 13:31:42 -0500653
654
akmhoqueb77b95f2013-02-08 12:28:47 -0600655void
656make_cor_lsa_key(char *key,struct clsa *cor_lsa)
657{
658 memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
659 memcpy(key+strlen(key),"/",1);
660 char ls_type[2];
661 sprintf(ls_type,"%d",cor_lsa->header->ls_type);
662 memcpy(key+strlen(key),ls_type,strlen(ls_type));
663 key[strlen(key)]='\0';
664}
akmhoqueffacaa82012-09-13 17:48:30 -0500665
666
akmhoque53f64222012-09-05 13:57:51 -0500667void
668make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500669{
akmhoque53f64222012-09-05 13:57:51 -0500670 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
671 memcpy(key+strlen(key),"/",1);
672 char ls_type[2];
673 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
674 memcpy(key+strlen(key),ls_type,strlen(ls_type));
675 key[strlen(key)]='\0';
676}
677
akmhoque03004e62012-09-06 01:12:28 -0500678int
679build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
680{
akmhoqueffacaa82012-09-13 17:48:30 -0500681 if(flags == CCN_SCHEDULE_CANCEL)
682 {
683 return -1;
684 }
685
686 nlsr_lock();
687
akmhoque7b791452012-10-30 11:24:56 -0500688 if ( nlsr->debugging )
689 printf("build_and_install_adj_lsa called \n");
690 if ( nlsr->detailed_logging )
691 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
692
693 if ( nlsr->debugging )
694 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
695 if ( nlsr->detailed_logging )
696 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500697
698 if(nlsr->adj_build_flag > 0)
699 {
akmhoque7b791452012-10-30 11:24:56 -0500700 if ( nlsr->debugging )
701 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
702 if ( nlsr->detailed_logging )
703 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
704
akmhoque03004e62012-09-06 01:12:28 -0500705 if ( is_adj_lsa_build()> 0)
706 {
707 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
708 build_adj_lsa(adj_lsa);
709 install_adj_lsa(adj_lsa);
710
akmhoqueb77b95f2013-02-08 12:28:47 -0600711 char lst[2];
712 memset(lst,0,2);
713 sprintf(lst,"%d",LS_TYPE_ADJ);
714
715 char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15);
716 memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15);
717 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);
718
719 if ( nlsr->debugging )
720 printf("Adj LSA Repo Key: %s \n",repo_key);
721
722 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
723 memset(key,0,adj_lsa->header->orig_router->length+2+2);
724 make_adj_lsa_key(key,adj_lsa);
725 if ( nlsr->debugging )
726 printf("Adj LSA: %s \n",key);
727
728 struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
729 lsaid->name=(char *)malloc(strlen(key)+1);
730 memset(lsaid->name, 0, strlen(key)+1);
731 memcpy(lsaid->name,key,strlen(key));
732 lsaid->length=strlen(key)+1;
733
734
735 write_adj_lsa_to_repo(repo_key, lsaid);
736
akmhoque569a93d2013-02-21 10:19:54 -0600737 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600738 free(repo_key);
739 free(lsaid->name);
740 free(lsaid);
741
742
743
akmhoque03004e62012-09-06 01:12:28 -0500744 free(adj_lsa->header->orig_router->name);
745 free(adj_lsa->header->orig_router);
746 free(adj_lsa->header->orig_time);
747 free(adj_lsa->header);
748 free(adj_lsa->body);
749 free(adj_lsa);
750 nlsr->adj_build_flag=0;
751 print_adj_lsdb();
752 }
753 else
754 {
akmhoque7b791452012-10-30 11:24:56 -0500755 if ( nlsr->debugging )
756 printf("Can not build adj LSA now\n");
757 if ( nlsr->detailed_logging )
758 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500759 }
760 }
761 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500762
763 nlsr_unlock();
764
akmhoque03004e62012-09-06 01:12:28 -0500765 return 0;
766}
767
768
769void
770build_adj_lsa(struct alsa * adj_lsa)
771{
akmhoque7b791452012-10-30 11:24:56 -0500772 if ( nlsr->debugging )
773 printf("build_adj_lsa called \n");
774 if ( nlsr->detailed_logging )
775 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500776
777 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500778
akmhoque03004e62012-09-06 01:12:28 -0500779 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
780 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
781 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
782 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
783 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
784 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
785
786 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
787
788 char *time_stamp=(char *)malloc(20);
789 memset(time_stamp,0,20);
790 get_current_timestamp_micro(time_stamp);
791
792 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
793 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
794 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
795 free(time_stamp);
796
akmhoque03004e62012-09-06 01:12:28 -0500797 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500798
799
800 struct ccn_charbuf *c=ccn_charbuf_create();
801 get_active_nbr_adj_data(c);
802 char *data=ccn_charbuf_as_string(c);
803
804 adj_lsa->body=(char *)malloc(strlen(data)+1);
805 memset(adj_lsa->body,0,strlen(data)+1);
806 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
807 ccn_charbuf_destroy(&c);
808
akmhoque03004e62012-09-06 01:12:28 -0500809 nlsr->adj_build_count++;
810
811
812}
813
814
akmhoque53f64222012-09-05 13:57:51 -0500815void
816install_adj_lsa(struct alsa * adj_lsa)
817{
akmhoqued79438d2012-08-27 13:31:42 -0500818
akmhoque7b791452012-10-30 11:24:56 -0500819 if ( nlsr->debugging )
820 printf("install_adj_lsa called \n");
821 if ( nlsr->detailed_logging )
822 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
823
akmhoque03004e62012-09-06 01:12:28 -0500824
akmhoqueffacaa82012-09-13 17:48:30 -0500825 char *time_stamp=(char *)malloc(20);
826 memset(time_stamp,0,20);
827 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500828
akmhoqueffacaa82012-09-13 17:48:30 -0500829
830 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
831 memset(key,0,adj_lsa->header->orig_router->length+2);
832 make_adj_lsa_key(key,adj_lsa);
akmhoqueffacaa82012-09-13 17:48:30 -0500833
akmhoque8876e982013-02-21 13:35:46 -0600834 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500835
836 struct hashtb_enumerator ee;
837 struct hashtb_enumerator *e = &ee;
838 int res;
839
840 hashtb_start(nlsr->lsdb->adj_lsdb, e);
841 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500842
akmhoque03004e62012-09-06 01:12:28 -0500843
akmhoque53f64222012-09-05 13:57:51 -0500844
akmhoque62c0c192012-09-24 07:49:25 -0500845 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500846 {
akmhoque62c0c192012-09-24 07:49:25 -0500847 if ( adj_lsa->no_link > 0)
848 {
akmhoque3171d652012-11-13 11:44:33 -0600849 if ( nlsr->debugging )
850 printf("New ADJ LSA... Adding to LSDB\n");
851 if ( nlsr->detailed_logging )
852 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
akmhoque62c0c192012-09-24 07:49:25 -0500853 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500854
akmhoque62c0c192012-09-24 07:49:25 -0500855 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
856 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
857 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
858 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 -0500859
akmhoque62c0c192012-09-24 07:49:25 -0500860 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
861 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
862 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
863 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500864
akmhoque62c0c192012-09-24 07:49:25 -0500865 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500866
akmhoque62c0c192012-09-24 07:49:25 -0500867 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
868 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
869 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
870
871 add_next_hop_router(new_adj_lsa->header->orig_router->name);
872 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500873
874 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
875 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
876 write_log_for_adj_lsa(new_adj_lsa);
877 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500878 }
879 else
880 {
881 hashtb_delete(e);
882 }
akmhoque53f64222012-09-05 13:57:51 -0500883
akmhoque7b791452012-10-30 11:24:56 -0500884 if ( nlsr->debugging )
885 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
886 if ( nlsr->detailed_logging )
887 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
888
akmhoque53f64222012-09-05 13:57:51 -0500889 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500890
891 if ( nlsr->debugging )
892 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
893 if ( nlsr->detailed_logging )
894 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
895
akmhoqueffacaa82012-09-13 17:48:30 -0500896 }
897 else if(res == HT_OLD_ENTRY)
898 {
899 new_adj_lsa = e->data;
900 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
901 {
akmhoque7b791452012-10-30 11:24:56 -0500902 if ( nlsr->debugging )
903 printf("Older/Duplicate Adj LSA. Discarded...\n");
904 if ( nlsr->detailed_logging )
905 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500906 }
907 else
908 {
akmhoqueffacaa82012-09-13 17:48:30 -0500909
akmhoque62c0c192012-09-24 07:49:25 -0500910 if ( adj_lsa->no_link > 0)
911 {
akmhoque9e9fc722012-09-26 14:03:25 -0500912 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
913 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
914 write_log_for_adj_lsa(new_adj_lsa);
915 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500916
akmhoque62c0c192012-09-24 07:49:25 -0500917 free(new_adj_lsa->header->orig_time);
918 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
919 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
920
921 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500922
akmhoque62c0c192012-09-24 07:49:25 -0500923 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
924 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
925 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500926
akmhoque62c0c192012-09-24 07:49:25 -0500927 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500928
929 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
930 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
931 write_log_for_adj_lsa(new_adj_lsa);
932 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500933 }
934 else
935 {
akmhoque9e9fc722012-09-26 14:03:25 -0500936 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
937 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
938 write_log_for_adj_lsa(new_adj_lsa);
939 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
940
akmhoque62c0c192012-09-24 07:49:25 -0500941 hashtb_delete(e);
942 }
akmhoque7b791452012-10-30 11:24:56 -0500943
944 if ( nlsr->debugging )
945 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
946 if ( nlsr->detailed_logging )
947 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
948
akmhoqueffacaa82012-09-13 17:48:30 -0500949 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500950
951 if ( nlsr->debugging )
952 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
953 if ( nlsr->detailed_logging )
954 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500955 }
956
957 }
958 hashtb_end(e);
959
960 if ( !nlsr->is_route_calculation_scheduled )
961 {
962 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
963 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -0500964 }
965
akmhoque03004e62012-09-06 01:12:28 -0500966
akmhoque569a93d2013-02-21 10:19:54 -0600967 //free(key);
akmhoqueffacaa82012-09-13 17:48:30 -0500968
969 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500970}
971
972void
akmhoque9e9fc722012-09-26 14:03:25 -0500973write_log_for_adj_lsa_body(const char *body, int no_link)
974{
975 int i=0;
976 char *lsa_data=(char *)malloc(strlen(body)+1);
977 memset( lsa_data,0,strlen(body)+1);
978 memcpy(lsa_data,body,strlen(body)+1);
979 char *sep="|";
980 char *rem;
981 char *rtr_id;
982 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -0600983 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -0500984 char *metric;
985
986 if(no_link >0 )
987 {
988 rtr_id=strtok_r(lsa_data,sep,&rem);
989 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -0600990 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -0500991 metric=strtok_r(NULL,sep,&rem);
992
993 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -0500994 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
995 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -0600996 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -0500997 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -0500998
999
1000 for(i=1;i<no_link;i++)
1001 {
1002 rtr_id=strtok_r(NULL,sep,&rem);
1003 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001004 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001005 metric=strtok_r(NULL,sep,&rem);
1006 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001007 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1008 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001009 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001010 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001011
1012 }
1013 }
1014
1015 free(lsa_data);
1016}
1017
1018
1019void
1020write_log_for_adj_lsa(struct alsa * adj_lsa)
1021{
1022 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001023 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1024 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1025 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1026 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001027 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001028 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001029
1030 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1031
1032 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1033
1034}
1035
1036void
akmhoque53f64222012-09-05 13:57:51 -05001037print_adj_lsa_body(const char *body, int no_link)
1038{
1039 int i=0;
1040 char *lsa_data=(char *)malloc(strlen(body)+1);
1041 memset( lsa_data,0,strlen(body)+1);
1042 memcpy(lsa_data,body,strlen(body)+1);
1043 char *sep="|";
1044 char *rem;
1045 char *rtr_id;
1046 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001047 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001048 char *metric;
1049
akmhoque53f64222012-09-05 13:57:51 -05001050 if(no_link >0 )
1051 {
1052 rtr_id=strtok_r(lsa_data,sep,&rem);
1053 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001054 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001055 metric=strtok_r(NULL,sep,&rem);
1056
akmhoqueb77b95f2013-02-08 12:28:47 -06001057 if ( nlsr->debugging ) {
1058 printf(" Link %d \n",i+1);
1059 printf(" Neighbor : %s \n",rtr_id);
1060 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001061 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001062 printf(" Metric : %s \n",metric);
1063 }
akmhoque53f64222012-09-05 13:57:51 -05001064
1065 for(i=1;i<no_link;i++)
1066 {
1067 rtr_id=strtok_r(NULL,sep,&rem);
1068 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001069 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001070 metric=strtok_r(NULL,sep,&rem);
1071 printf(" Link %d \n",i+1);
1072 printf(" Neighbor : %s \n",rtr_id);
1073 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001074 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001075 printf(" Metric : %s \n",metric);
1076
1077 }
1078 }
1079
1080 free(lsa_data);
1081}
1082
1083void
1084print_adj_lsa(struct alsa * adj_lsa)
1085{
akmhoque7b791452012-10-30 11:24:56 -05001086 if ( nlsr->debugging )
1087 {
1088 printf("-----------ADJ LSA Content---------------\n");
1089 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1090 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1091 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1092 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1093 printf(" Lsa Data:\n");
1094 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001095
akmhoque7b791452012-10-30 11:24:56 -05001096 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1097 printf("\n");
1098 }
akmhoque53f64222012-09-05 13:57:51 -05001099
1100}
1101
1102void
1103print_adj_lsdb(void)
1104{
akmhoque7b791452012-10-30 11:24:56 -05001105 if ( nlsr->debugging )
1106 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001107 int i, adj_lsdb_element;
1108 struct alsa *adj_lsa;
1109
1110 struct hashtb_enumerator ee;
1111 struct hashtb_enumerator *e = &ee;
1112
1113 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1114 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1115
1116 for(i=0;i<adj_lsdb_element;i++)
1117 {
akmhoque7b791452012-10-30 11:24:56 -05001118 if ( nlsr->debugging )
1119 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001120 adj_lsa=e->data;
1121 print_adj_lsa(adj_lsa);
1122 hashtb_next(e);
1123 }
1124
1125 hashtb_end(e);
1126
akmhoque3171d652012-11-13 11:44:33 -06001127 if ( nlsr->debugging )
1128 printf("\n");
1129 if ( nlsr->detailed_logging )
1130 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001131}
1132
1133void
akmhoque03004e62012-09-06 01:12:28 -05001134build_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 -05001135{
akmhoque7b791452012-10-30 11:24:56 -05001136 if ( nlsr->debugging )
1137 printf("build_and_install_others_adj_lsa called \n");
1138 if ( nlsr->detailed_logging )
1139 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001140 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1141 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001142 install_adj_lsa(adj_lsa);
1143
akmhoque53f64222012-09-05 13:57:51 -05001144
akmhoque03004e62012-09-06 01:12:28 -05001145 free(adj_lsa->header->orig_router->name);
1146 free(adj_lsa->header->orig_router);
1147 free(adj_lsa->header->orig_time);
1148 free(adj_lsa->header);
1149 free(adj_lsa->body);
1150 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001151
akmhoque03004e62012-09-06 01:12:28 -05001152 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001153
akmhoque53f64222012-09-05 13:57:51 -05001154}
1155
akmhoque03004e62012-09-06 01:12:28 -05001156
akmhoque53f64222012-09-05 13:57:51 -05001157void
akmhoque03004e62012-09-06 01:12:28 -05001158build_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 -05001159{
akmhoque7b791452012-10-30 11:24:56 -05001160 if ( nlsr->debugging )
1161 printf("build_others_adj_lsa called \n");
1162 if ( nlsr->detailed_logging )
1163 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001164
akmhoque03004e62012-09-06 01:12:28 -05001165 /*Filling Up Header Data */
1166 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
1167 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1168 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
1169 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
1170 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001171
akmhoque03004e62012-09-06 01:12:28 -05001172 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001173
akmhoque53f64222012-09-05 13:57:51 -05001174
akmhoque03004e62012-09-06 01:12:28 -05001175 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001176
akmhoque03004e62012-09-06 01:12:28 -05001177 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
1178 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
1179 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001180
akmhoque03004e62012-09-06 01:12:28 -05001181 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001182
akmhoque03004e62012-09-06 01:12:28 -05001183 adj_lsa->body=(char *)malloc(strlen(data)+1);
1184 memset(adj_lsa->body,0,strlen(data)+1);
1185 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001186
akmhoque53f64222012-09-05 13:57:51 -05001187}
1188
akmhoque03004e62012-09-06 01:12:28 -05001189
akmhoque53f64222012-09-05 13:57:51 -05001190long int
1191get_name_lsdb_num_element(void)
1192{
1193 long int num_element;
1194
1195
1196 struct hashtb_enumerator ee;
1197 struct hashtb_enumerator *e = &ee;
1198
1199 hashtb_start(nlsr->lsdb->name_lsdb, e);
1200 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1201 hashtb_end(e);
1202
1203 return num_element;
1204}
1205
1206long int
1207get_adj_lsdb_num_element(void)
1208{
1209 long int num_element;
1210
1211
1212 struct hashtb_enumerator ee;
1213 struct hashtb_enumerator *e = &ee;
1214
1215 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1216 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1217 hashtb_end(e);
1218
1219 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001220}
akmhoque03004e62012-09-06 01:12:28 -05001221
akmhoque03004e62012-09-06 01:12:28 -05001222
1223int
1224check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1225{
1226 int ret=0;
1227 struct ccn_charbuf *key=ccn_charbuf_create();
1228 ccn_charbuf_append_string(key,orig_router);
1229 ccn_charbuf_append_string(key,"/");
1230 ccn_charbuf_append_string(key,lst);
1231 ccn_charbuf_append_string(key,"/");
1232 ccn_charbuf_append_string(key,lsid);
1233
1234 int res;
1235 struct nlsa *name_lsa;
1236
1237 struct hashtb_enumerator ee;
1238 struct hashtb_enumerator *e = &ee;
1239
1240 hashtb_start(nlsr->lsdb->name_lsdb, e);
1241 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1242
1243 if( res == HT_NEW_ENTRY )
1244 {
1245 hashtb_delete(e);
1246 ret=1;
1247
1248 }
1249 else if(res == HT_OLD_ENTRY)
1250 {
1251 name_lsa=e->data;
1252 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1253 {
1254 ret=1;
1255 }
1256 }
1257
1258 hashtb_end(e);
1259
1260 ccn_charbuf_destroy(&key);
1261
1262 return ret;
1263}
1264
1265int
1266check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1267{
1268 int ret=0;
1269 struct ccn_charbuf *key=ccn_charbuf_create();
1270 ccn_charbuf_append_string(key,orig_router);
1271 ccn_charbuf_append_string(key,"/");
1272 ccn_charbuf_append_string(key,lst);
1273
1274 int res;
1275 struct alsa *adj_lsa;
1276
1277 struct hashtb_enumerator ee;
1278 struct hashtb_enumerator *e = &ee;
1279
1280 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1281 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1282
1283 if( res == HT_NEW_ENTRY )
1284 {
1285 hashtb_delete(e);
1286 ret=1;
1287
1288 }
1289 else if(res == HT_OLD_ENTRY)
1290 {
1291 adj_lsa=e->data;
1292 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1293 {
1294 ret=1;
1295 }
1296 }
1297
1298 hashtb_end(e);
1299
1300 ccn_charbuf_destroy(&key);
1301
1302 return ret;
1303}
1304
akmhoqueb77b95f2013-02-08 12:28:47 -06001305int
1306check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1307{
1308 int ret=0;
1309 struct ccn_charbuf *key=ccn_charbuf_create();
1310 ccn_charbuf_append_string(key,orig_router);
1311 ccn_charbuf_append_string(key,"/");
1312 ccn_charbuf_append_string(key,lst);
1313
1314 int res;
1315 struct clsa *cor_lsa;
1316
1317 struct hashtb_enumerator ee;
1318 struct hashtb_enumerator *e = &ee;
1319
1320 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1321 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1322
1323 if( res == HT_NEW_ENTRY )
1324 {
1325 hashtb_delete(e);
1326 ret=1;
1327
1328 }
1329 else if(res == HT_OLD_ENTRY)
1330 {
1331 cor_lsa=e->data;
1332 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1333 {
1334 ret=1;
1335 }
1336 }
1337
1338 hashtb_end(e);
1339
1340 ccn_charbuf_destroy(&key);
1341
1342 return ret;
1343}
1344
akmhoque03004e62012-09-06 01:12:28 -05001345void
1346get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1347{
akmhoque7b791452012-10-30 11:24:56 -05001348 if ( nlsr->debugging )
1349 printf("get_name_lsa_data called \n");
1350 if ( nlsr->detailed_logging )
1351 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001352
akmhoque8876e982013-02-21 13:35:46 -06001353 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001354
1355 struct hashtb_enumerator ee;
1356 struct hashtb_enumerator *e = &ee;
1357 int res;
1358
1359 hashtb_start(nlsr->lsdb->name_lsdb, e);
1360 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1361
1362 if( res == HT_OLD_ENTRY )
1363 {
1364 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001365
akmhoque7b791452012-10-30 11:24:56 -05001366 if ( nlsr->debugging )
1367 printf("NAME LSA found \n");
1368 if ( nlsr->detailed_logging )
1369 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001370
1371 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1372 ccn_charbuf_append_string(lsa_data,"|");
1373
1374 char *temp_length=(char *)malloc(20);
1375 memset(temp_length,0,20);
1376 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1377 ccn_charbuf_append_string(lsa_data,temp_length);
1378 free(temp_length);
1379 ccn_charbuf_append_string(lsa_data,"|");
1380
1381 char *temp_ltype=(char *)malloc(20);
1382 memset(temp_ltype,0,20);
1383 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1384 ccn_charbuf_append_string(lsa_data,temp_ltype);
1385 free(temp_ltype);
1386 ccn_charbuf_append_string(lsa_data,"|");
1387
1388 char *temp_lsid=(char *)malloc(20);
1389 memset(temp_lsid,0,20);
1390 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1391 ccn_charbuf_append_string(lsa_data,temp_lsid);
1392 free(temp_lsid);
1393 ccn_charbuf_append_string(lsa_data,"|");
1394
1395 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1396 ccn_charbuf_append_string(lsa_data,"|");
1397
1398 char *temp_valid=(char *)malloc(20);
1399 memset(temp_valid,0,20);
1400 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1401 ccn_charbuf_append_string(lsa_data,temp_valid);
1402 free(temp_valid);
1403 ccn_charbuf_append_string(lsa_data,"|");
1404
1405 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1406 ccn_charbuf_append_string(lsa_data,"|");
1407
1408 char *temp_npl=(char *)malloc(20);
1409 memset(temp_npl,0,20);
1410 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1411 ccn_charbuf_append_string(lsa_data,temp_npl);
1412 free(temp_npl);
1413 ccn_charbuf_append_string(lsa_data,"|");
1414
1415 }
1416 else if(res == HT_NEW_ENTRY)
1417 {
1418 hashtb_delete(e);
1419 }
1420
1421 hashtb_end(e);
1422}
1423
1424void
1425get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1426{
akmhoque7b791452012-10-30 11:24:56 -05001427 if ( nlsr->debugging )
1428 printf("get_adj_lsa_data called \n");
1429 if ( nlsr->detailed_logging )
1430 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001431
1432 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
1433
1434 struct hashtb_enumerator ee;
1435 struct hashtb_enumerator *e = &ee;
1436 int res;
1437
1438 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1439 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1440
1441 if( res == HT_OLD_ENTRY )
1442 {
1443 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001444
1445 if ( nlsr->debugging )
1446 printf("Adj LSA found \n");
1447 if ( nlsr->detailed_logging )
1448 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001449
1450 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1451 ccn_charbuf_append_string(lsa_data,"|");
1452
1453 char *temp_length=(char *)malloc(20);
1454 memset(temp_length,0,20);
1455 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1456 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001457 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001458 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001459
1460 char *temp_ltype=(char *)malloc(20);
1461 memset(temp_ltype,0,20);
1462 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1463 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001464 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001465 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001466
1467 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1468 ccn_charbuf_append_string(lsa_data,"|");
1469
1470 char *temp_nl=(char *)malloc(20);
1471 memset(temp_nl,0,20);
1472 sprintf(temp_nl,"%d",adj_lsa->no_link);
1473 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001474 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001475 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001476
1477 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1478
1479
1480 }
1481 else if(res == HT_NEW_ENTRY)
1482 {
1483 hashtb_delete(e);
1484 }
1485
1486 hashtb_end(e);
1487}
akmhoqueffacaa82012-09-13 17:48:30 -05001488
akmhoque3171d652012-11-13 11:44:33 -06001489void
1490make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1491{
1492
1493 if ( nlsr->debugging )
1494 printf("make_name_lsa_invalid called \n");
1495 if ( nlsr->detailed_logging )
1496 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1497
1498
1499 char lst[2];
1500 memset(lst,0,2);
1501 sprintf(lst,"%d",ls_type);
1502
1503 char lsid[10];
1504 memset(lsid,0,10);
1505 sprintf(lsid,"%ld",ls_id);
1506
1507
1508 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1509 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1510
1511
1512 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001513
1514 if ( nlsr->debugging )
1515 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001516
1517 struct nlsa *nlsa;
1518
1519 struct hashtb_enumerator ee;
1520 struct hashtb_enumerator *e = &ee;
1521
1522 int res;
1523
1524 hashtb_start(nlsr->lsdb->name_lsdb, e);
1525 res = hashtb_seek(e, key,strlen(key) , 0);
1526
1527 if( res == HT_OLD_ENTRY )
1528 {
1529 nlsa=e->data;
1530
1531 nlsa->header->isValid=0;
1532
1533 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1534 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1535 write_log_for_name_lsa(nlsa);
1536 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1537
1538 hashtb_delete(e);
1539 }
1540 else if( res == HT_NEW_ENTRY )
1541 {
1542 hashtb_delete(e);
1543 }
1544 hashtb_end(e);
1545
1546 if ( nlsr->debugging )
1547 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1548 if ( nlsr->detailed_logging )
1549 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1550
1551 set_new_lsdb_version();
1552
1553 if ( nlsr->debugging )
1554 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1555 if ( nlsr->detailed_logging )
1556 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1557
1558}
1559
akmhoque866c2222013-02-12 10:49:33 -06001560//int
1561//delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1562int
1563delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001564{
akmhoqueb77b95f2013-02-08 12:28:47 -06001565
akmhoque7b791452012-10-30 11:24:56 -05001566 if ( nlsr->debugging )
1567 printf("delete_name_lsa called \n");
1568 if ( nlsr->detailed_logging )
1569 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001570 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001571 if(flags == CCN_SCHEDULE_CANCEL)
1572 {
1573 return -1;
1574 }
1575
1576
1577
1578 nlsr_lock();
1579
akmhoque7b791452012-10-30 11:24:56 -05001580 if ( nlsr->debugging )
1581 printf("LSA Key: %s \n",(char *)ev->evdata);
1582 if ( nlsr->detailed_logging )
1583 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001584
1585 struct nlsa *nlsa;
1586
1587 struct hashtb_enumerator ee;
1588 struct hashtb_enumerator *e = &ee;
1589
1590 int res;
1591
1592 hashtb_start(nlsr->lsdb->name_lsdb, e);
1593 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1594
1595 if( res == HT_OLD_ENTRY )
1596 {
1597 nlsa=e->data;
akmhoque866c2222013-02-12 10:49:33 -06001598 */
1599 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
1600 /*
akmhoque9e9fc722012-09-26 14:03:25 -05001601 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1602 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1603 write_log_for_name_lsa(nlsa);
1604 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1605
akmhoqueda5b6832012-09-13 22:33:55 -05001606 hashtb_delete(e);
1607 }
akmhoque3cced642012-09-24 16:20:20 -05001608 else if( res == HT_NEW_ENTRY )
akmhoqueda5b6832012-09-13 22:33:55 -05001609 {
akmhoqueda5b6832012-09-13 22:33:55 -05001610 hashtb_delete(e);
1611 }
1612 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001613 */
akmhoqueda5b6832012-09-13 22:33:55 -05001614
akmhoque7b791452012-10-30 11:24:56 -05001615 if ( nlsr->debugging )
1616 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1617 if ( nlsr->detailed_logging )
1618 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1619
akmhoqueda5b6832012-09-13 22:33:55 -05001620 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001621
1622 if ( nlsr->debugging )
1623 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1624 if ( nlsr->detailed_logging )
1625 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001626
akmhoque866c2222013-02-12 10:49:33 -06001627 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001628
1629 return 0;
1630}
1631
akmhoque866c2222013-02-12 10:49:33 -06001632//int
1633//delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1634int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001635{
akmhoque866c2222013-02-12 10:49:33 -06001636
akmhoque7b791452012-10-30 11:24:56 -05001637 if ( nlsr->debugging )
1638 printf("delete_adj_lsa called \n");
1639 if ( nlsr->detailed_logging )
1640 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001641
1642 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001643 if(flags == CCN_SCHEDULE_CANCEL)
1644 {
1645 return -1;
1646 }
1647 nlsr_lock();
1648
akmhoque7b791452012-10-30 11:24:56 -05001649 if ( nlsr->debugging )
1650 printf("LSA Key: %s \n",(char *)ev->evdata);
1651 if ( nlsr->detailed_logging )
1652 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001653
akmhoque9e9fc722012-09-26 14:03:25 -05001654 struct alsa *alsa;
akmhoqueda5b6832012-09-13 22:33:55 -05001655 struct hashtb_enumerator ee;
1656 struct hashtb_enumerator *e = &ee;
1657 int res;
1658
1659 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1660 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1661
1662 if( res == HT_OLD_ENTRY )
1663 {
akmhoque9e9fc722012-09-26 14:03:25 -05001664 alsa=e->data;
1665 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1666 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1667 write_log_for_adj_lsa(alsa);
1668 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1669
akmhoqueda5b6832012-09-13 22:33:55 -05001670 hashtb_delete(e);
1671 }
1672 else if( res == HT_OLD_ENTRY )
1673 {
1674 hashtb_delete(e);
1675 }
1676 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001677 */
akmhoqueda5b6832012-09-13 22:33:55 -05001678
akmhoque7b791452012-10-30 11:24:56 -05001679 if ( nlsr->debugging )
1680 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1681 if ( nlsr->detailed_logging )
1682 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1683
akmhoqueda5b6832012-09-13 22:33:55 -05001684 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001685
1686 if ( nlsr->debugging )
1687 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1688 if ( nlsr->detailed_logging )
1689 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1690
akmhoqueda5b6832012-09-13 22:33:55 -05001691
1692 if ( !nlsr->is_route_calculation_scheduled)
1693 {
1694 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1695 nlsr->is_route_calculation_scheduled=1;
1696 }
1697
akmhoque866c2222013-02-12 10:49:33 -06001698 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001699
1700 return 0;
1701}
1702
akmhoqueffacaa82012-09-13 17:48:30 -05001703void
1704refresh_name_lsdb(void)
1705{
akmhoque7b791452012-10-30 11:24:56 -05001706 if ( nlsr->debugging )
1707 printf("refresh_name_lsdb called \n");
1708 if ( nlsr->detailed_logging )
1709 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001710
1711 char *time_stamp=(char *)malloc(20);
1712 memset(time_stamp,0,20);
1713 get_current_timestamp_micro(time_stamp);
1714
1715 long int lsa_life_time;
1716
1717 int i, name_lsdb_element;
1718 struct nlsa *name_lsa;
1719
1720 struct hashtb_enumerator ee;
1721 struct hashtb_enumerator *e = &ee;
1722
1723 hashtb_start(nlsr->lsdb->name_lsdb, e);
1724 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1725
1726 for(i=0;i<name_lsdb_element;i++)
1727 {
1728 name_lsa=e->data;
1729
1730 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001731 if ( nlsr->debugging )
1732 printf("LSA Life Time: %ld \n",lsa_life_time);
1733 if ( nlsr->detailed_logging )
1734 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001735
1736 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1737 {
1738 if ( lsa_life_time > nlsr->lsa_refresh_time )
1739 {
akmhoque14b3f342012-09-14 10:39:02 -05001740 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1741 {
akmhoque7b791452012-10-30 11:24:56 -05001742 if ( nlsr->debugging )
1743 printf("Own Name LSA need to be refrshed\n");
1744 if ( nlsr->detailed_logging )
1745 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001746
1747 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1748 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1749 write_log_for_name_lsa(name_lsa);
1750 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1751
1752
akmhoque14b3f342012-09-14 10:39:02 -05001753 char *current_time_stamp=(char *)malloc(20);
1754 memset(current_time_stamp,0,20);
1755 get_current_timestamp_micro(current_time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001756
akmhoque14b3f342012-09-14 10:39:02 -05001757 free(name_lsa->header->orig_time);
1758 name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1759 memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1760 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001761
1762 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1763 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1764 write_log_for_name_lsa(name_lsa);
1765 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001766
akmhoque14b3f342012-09-14 10:39:02 -05001767 free(current_time_stamp);
akmhoque866c2222013-02-12 10:49:33 -06001768
1769 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001770 }
1771 else
akmhoque866c2222013-02-12 10:49:33 -06001772 { /*
akmhoque14b3f342012-09-14 10:39:02 -05001773 char lst[2];
1774 memset(lst,0,2);
1775 sprintf(lst,"%d",name_lsa->header->ls_type);
1776
1777 char lsid[10];
1778 memset(lsid,0,10);
1779 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1780
akmhoque866c2222013-02-12 10:49:33 -06001781
akmhoque14b3f342012-09-14 10:39:02 -05001782 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1783 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1784
1785
1786 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque14b3f342012-09-14 10:39:02 -05001787
1788 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001789 */
1790 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1791 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1792 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1793 write_log_for_name_lsa(name_lsa);
1794 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1795 hashtb_delete(e);
1796 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001797 }
akmhoqueda5b6832012-09-13 22:33:55 -05001798
akmhoque7b791452012-10-30 11:24:56 -05001799 if ( nlsr->debugging )
1800 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1801 if ( nlsr->detailed_logging )
1802 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1803
akmhoqueda5b6832012-09-13 22:33:55 -05001804 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001805
1806 if ( nlsr->debugging )
1807 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1808 if ( nlsr->detailed_logging )
1809 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1810
1811
akmhoqueda5b6832012-09-13 22:33:55 -05001812
1813 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001814 }
1815 else
1816 {
1817 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001818 }
1819 }
1820 else
1821 {
1822 if ( lsa_life_time > nlsr->router_dead_interval )
1823 {
akmhoque7b791452012-10-30 11:24:56 -05001824 if ( nlsr->debugging )
1825 printf("Others Name LSA need to be deleted\n");
1826 if ( nlsr->detailed_logging )
1827 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001828
akmhoque866c2222013-02-12 10:49:33 -06001829 /*char lst[2];
akmhoqueda5b6832012-09-13 22:33:55 -05001830 memset(lst,0,2);
1831 sprintf(lst,"%d",name_lsa->header->ls_type);
1832
1833 char lsid[10];
1834 memset(lsid,0,10);
1835 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1836
1837
1838 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1839 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1840
1841
1842 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoqueda5b6832012-09-13 22:33:55 -05001843
1844 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001845 */
1846 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1847 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1848 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1849 write_log_for_name_lsa(name_lsa);
1850 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1851 hashtb_delete(e);
1852 i++;
1853 }
1854 else
1855 {
1856 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001857 }
1858 }
akmhoque866c2222013-02-12 10:49:33 -06001859 /*else
1860 {
1861 hashtb_next(e);
1862 }*/
akmhoqueffacaa82012-09-13 17:48:30 -05001863 }
1864
1865 hashtb_end(e);
1866
1867 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001868
akmhoqueffacaa82012-09-13 17:48:30 -05001869
1870}
1871
akmhoqueda5b6832012-09-13 22:33:55 -05001872void
akmhoqueffacaa82012-09-13 17:48:30 -05001873refresh_adj_lsdb(void)
1874{
akmhoqueffacaa82012-09-13 17:48:30 -05001875
akmhoque7b791452012-10-30 11:24:56 -05001876 if ( nlsr->debugging )
1877 printf("refresh_adj_lsdb called \n");
1878 if ( nlsr->detailed_logging )
1879 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001880
akmhoqueffacaa82012-09-13 17:48:30 -05001881 char *time_stamp=(char *)malloc(20);
1882 memset(time_stamp,0,20);
1883 get_current_timestamp_micro(time_stamp);
1884
1885 long int lsa_life_time;
1886
1887 int i, adj_lsdb_element;
1888 struct alsa *adj_lsa;
1889
1890 struct hashtb_enumerator ee;
1891 struct hashtb_enumerator *e = &ee;
1892
1893 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1894 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1895
1896 for(i=0;i<adj_lsdb_element;i++)
1897 {
1898 adj_lsa=e->data;
1899
akmhoqueb77b95f2013-02-08 12:28:47 -06001900 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001901
1902 if ( nlsr->debugging )
1903 printf("LSA Life Time: %ld \n",lsa_life_time);
1904 if ( nlsr->detailed_logging )
1905 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001906
akmhoqueda5b6832012-09-13 22:33:55 -05001907 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1908 {
1909 if ( lsa_life_time > nlsr->lsa_refresh_time )
1910 {
akmhoque7b791452012-10-30 11:24:56 -05001911 if ( nlsr->debugging )
1912 printf("Own Adj LSA need to be refrshed\n");
1913 if ( nlsr->detailed_logging )
1914 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001915
akmhoquea98c2142012-10-25 15:22:24 -05001916 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1917 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1918 write_log_for_adj_lsa(adj_lsa);
1919 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1920
akmhoqueda5b6832012-09-13 22:33:55 -05001921 char *current_time_stamp=(char *)malloc(20);
1922 memset(current_time_stamp,0,20);
1923 get_current_timestamp_micro(current_time_stamp);
1924
1925 free(adj_lsa->header->orig_time);
1926 adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1927 memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1928 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1929
1930 free(current_time_stamp);
1931
akmhoquea98c2142012-10-25 15:22:24 -05001932 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1933 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1934 write_log_for_adj_lsa(adj_lsa);
1935 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001936
akmhoque7b791452012-10-30 11:24:56 -05001937 if ( nlsr->debugging )
1938 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1939 if ( nlsr->detailed_logging )
1940 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1941
akmhoqueda5b6832012-09-13 22:33:55 -05001942 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001943
1944 if ( nlsr->debugging )
1945 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1946 if ( nlsr->detailed_logging )
1947 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001948
1949 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001950
1951
akmhoqueda5b6832012-09-13 22:33:55 -05001952 }
akmhoque866c2222013-02-12 10:49:33 -06001953
1954 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001955 }
1956 else
1957 {
1958 if ( lsa_life_time > nlsr->router_dead_interval )
1959 {
akmhoque7b791452012-10-30 11:24:56 -05001960
1961 if ( nlsr->debugging )
1962 printf("Others Adj LSA need to be deleted\n");
1963 if ( nlsr->detailed_logging )
1964 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06001965 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001966 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
1967 memset(key,0,adj_lsa->header->orig_router->length+2);
1968 make_adj_lsa_key(key,adj_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06001969
akmhoqueda5b6832012-09-13 22:33:55 -05001970 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001971 */
1972
1973 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1974 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1975 write_log_for_adj_lsa(adj_lsa);
1976 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1977 delete_adj_lsa();
1978 hashtb_delete(e);
1979 i++;
1980
1981 }
1982 else
1983 {
1984 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001985 }
1986 }
1987
1988
1989
akmhoque866c2222013-02-12 10:49:33 -06001990 //hashtb_next(e);
akmhoqueffacaa82012-09-13 17:48:30 -05001991 }
1992
1993 hashtb_end(e);
1994
1995 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05001996}
1997
akmhoqueb77b95f2013-02-08 12:28:47 -06001998
1999void
2000refresh_cor_lsdb(void)
2001{
2002
2003 if ( nlsr->debugging )
2004 printf("refresh_cor_lsdb called \n");
2005 if ( nlsr->detailed_logging )
2006 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2007
2008 char *time_stamp=(char *)malloc(20);
2009 memset(time_stamp,0,20);
2010 get_current_timestamp_micro(time_stamp);
2011
2012 long int lsa_life_time;
2013
2014 int i, cor_lsdb_element;
2015 struct clsa *cor_lsa;
2016
2017 struct hashtb_enumerator ee;
2018 struct hashtb_enumerator *e = &ee;
2019
2020 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2021 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2022
2023 for(i=0;i<cor_lsdb_element;i++)
2024 {
2025 cor_lsa=e->data;
2026
2027 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2028
2029 if ( nlsr->debugging )
2030 printf("LSA Life Time: %ld \n",lsa_life_time);
2031 if ( nlsr->detailed_logging )
2032 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2033
2034 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2035 {
2036 if ( lsa_life_time > nlsr->lsa_refresh_time )
2037 {
2038 if ( nlsr->debugging )
2039 printf("Own Cor LSA need to be refrshed\n");
2040 if ( nlsr->detailed_logging )
2041 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2042
2043 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2044 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2045 //write_log_for_adj_lsa(adj_lsa);
2046 //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2047
2048 char *current_time_stamp=(char *)malloc(20);
2049 memset(current_time_stamp,0,20);
2050 get_current_timestamp_micro(current_time_stamp);
2051
2052 free(cor_lsa->header->orig_time);
2053 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2054 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2055 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2056
2057 free(current_time_stamp);
2058
2059 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2060 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
2061 //write_log_for_adj_lsa(adj_lsa);
2062 //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2063
2064 if ( nlsr->debugging )
2065 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2066 if ( nlsr->detailed_logging )
2067 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2068
2069 set_new_lsdb_version();
2070
2071 if ( nlsr->debugging )
2072 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2073 if ( nlsr->detailed_logging )
2074 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2075
2076 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002077 }
2078
2079 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002080 }
2081 else
2082 {
2083 if ( lsa_life_time > nlsr->router_dead_interval )
2084 {
2085
2086 if ( nlsr->debugging )
2087 printf("Others Adj LSA need to be deleted\n");
2088 if ( nlsr->detailed_logging )
2089 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
2090
2091 hashtb_delete(e);
2092 i++;
2093 }
akmhoque866c2222013-02-12 10:49:33 -06002094 else
2095 {
2096 hashtb_next(e);
2097 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002098 }
2099
2100
akmhoque866c2222013-02-12 10:49:33 -06002101
akmhoqueb77b95f2013-02-08 12:28:47 -06002102 }
2103
2104 hashtb_end(e);
2105
2106 free(time_stamp);
2107}
2108
akmhoqueffacaa82012-09-13 17:48:30 -05002109int
2110refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2111{
2112 if(flags == CCN_SCHEDULE_CANCEL)
2113 {
2114 return -1;
2115 }
2116
2117 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002118
akmhoque7b791452012-10-30 11:24:56 -05002119 if ( nlsr->debugging )
2120 printf("refresh_lsdb called\n");
2121 if ( nlsr->detailed_logging )
2122 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002123
2124 refresh_name_lsdb();
2125 refresh_adj_lsdb();
akmhoque8876e982013-02-21 13:35:46 -06002126 //refresh_cor_lsdb();
akmhoqueffacaa82012-09-13 17:48:30 -05002127
akmhoqueffacaa82012-09-13 17:48:30 -05002128 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002129
akmhoqueffacaa82012-09-13 17:48:30 -05002130 nlsr_unlock();
2131 return 0;
2132}
akmhoqueb77b95f2013-02-08 12:28:47 -06002133
2134void
2135write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2136{
2137 if ( nlsr->debugging )
2138 printf("write_adj_lsa_to_repo called\n");
2139 if ( nlsr->debugging )
2140 printf("Content Prefix: %s\n",repo_content_prefix);
2141
2142 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2143 get_adj_lsa_data(lsa_data,lsa_id);
2144 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002145 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002146
akmhoque323b5e92013-02-21 13:55:15 -06002147 char *data=(char *)calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
2148 memcpy(data, ccn_charbuf_as_string(lsa_data),strlen(ccn_charbuf_as_string(lsa_data)));
2149 data[strlen(ccn_charbuf_as_string(lsa_data))]='\0';
akmhoqueb77b95f2013-02-08 12:28:47 -06002150
akmhoque323b5e92013-02-21 13:55:15 -06002151 //write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
2152 write_data_to_repo(data, repo_content_prefix);
2153
2154 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002155}
2156
2157void
2158write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2159{
2160 if ( nlsr->debugging )
2161 printf("write_name_lsa_to_repo called\n");
2162 if ( nlsr->debugging )
2163 printf("Content Prefix: %s\n",repo_content_prefix);
2164
2165 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2166 get_name_lsa_data(lsa_data,lsa_id);
2167
2168 if ( nlsr->debugging )
2169 printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2170
akmhoque323b5e92013-02-21 13:55:15 -06002171 char *data=(char *)calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
2172 memcpy(data, ccn_charbuf_as_string(lsa_data),strlen(ccn_charbuf_as_string(lsa_data)));
2173 data[strlen(ccn_charbuf_as_string(lsa_data))]='\0';
2174
2175 write_data_to_repo(data, repo_content_prefix);
2176
2177 //write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002178
akmhoque4f85aab2013-02-21 13:58:50 -06002179 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002180}
2181
2182
2183void
2184write_name_lsdb_to_repo(char *slice_prefix)
2185{
2186 int i, name_lsdb_element;
2187
2188 struct nlsa *name_lsa;
2189 struct hashtb_enumerator ee;
2190 struct hashtb_enumerator *e = &ee;
2191
2192 hashtb_start(nlsr->lsdb->name_lsdb, e);
2193 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2194
2195 for(i=0;i<name_lsdb_element;i++)
2196 {
2197 name_lsa=e->data;
2198
2199 char lst[2];
2200 memset(lst,0,2);
2201 sprintf(lst,"%d",name_lsa->header->ls_type);
2202
2203 char lsid[10];
2204 memset(lsid,0,10);
2205 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2206
2207
2208 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2209 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2210
2211
2212 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2213
2214 if ( nlsr->debugging )
2215 printf("Name LSA Key: %s \n",key);
2216
2217
2218 char *repo_key=(char *)malloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15);
2219 memset(repo_key,0,strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15);
2220 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);
2221
2222 if ( nlsr->debugging )
2223 printf("Name LSA Repo Key: %s \n",repo_key);
2224
2225 struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
2226 lsaid->name=(char *)malloc(strlen(key)+1);
2227 memset(lsaid->name, 0, strlen(key)+1);
2228 memcpy(lsaid->name,key,strlen(key));
2229 lsaid->length=strlen(key)+1;
2230
2231
2232 write_name_lsa_to_repo(repo_key, lsaid);
2233
2234 free(key);
2235 free(repo_key);
2236 free(lsaid->name);
2237 free(lsaid);
2238
2239 hashtb_next(e);
2240 }
2241
2242 hashtb_end(e);
2243
2244
2245}
2246
2247void
2248print_cor_lsa(struct clsa *cor_lsa)
2249{
2250 if ( nlsr->debugging )
2251 {
2252 printf("-----------Cor LSA Content---------------\n");
2253 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2254 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2255 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2256 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2257 printf(" LSA Data \n");
2258 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2259 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2260
2261 printf("\n");
2262 }
2263}
2264
2265void
2266print_cor_lsdb()
2267{
2268
2269 if ( nlsr->debugging )
2270 printf("print_cor_lsdb called \n");
2271
2272 struct hashtb_enumerator ee;
2273 struct hashtb_enumerator *e = &ee;
2274
2275 int i=1;
2276
2277 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2278 {
2279 if ( nlsr->debugging )
2280 printf("-----------Cor LSA (%d)---------------\n",i);
2281 struct clsa *cor_lsa=e->data;
2282 print_cor_lsa(cor_lsa);
2283 i++;
2284 }
2285 hashtb_end(e);
2286
2287 if ( nlsr->debugging )
2288 printf("\n");
2289 if ( nlsr->detailed_logging )
2290 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2291}
2292
2293void
2294install_cor_lsa(struct clsa *cor_lsa)
2295{
2296 if ( nlsr->debugging )
2297 printf("install_cor_lsa called \n");
2298 if ( nlsr->detailed_logging )
2299 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2300
2301
2302 char *time_stamp=(char *)malloc(20);
2303 memset(time_stamp,0,20);
2304 get_current_timestamp_micro(time_stamp);
2305
2306
akmhoque569a93d2013-02-21 10:19:54 -06002307 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2308 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002309 make_cor_lsa_key(key,cor_lsa);
2310
2311 if ( nlsr->debugging )
2312 printf("Cor LSA key: %s \n",key);
2313
2314 struct hashtb_enumerator ee;
2315 struct hashtb_enumerator *e = &ee;
2316 int res;
2317
2318 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2319 res = hashtb_seek(e, key, strlen(key), 0);
2320
2321 if ( res == HT_NEW_ENTRY )
2322 {
2323 if ( nlsr->debugging )
2324 printf("New Cor LSA... \n");
2325
akmhoque8876e982013-02-21 13:35:46 -06002326 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002327 new_cor_lsa=e->data;
2328 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2329
2330 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2331 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
2332 memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
2333 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2334 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2335
2336 new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free
2337 memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
2338 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2339
2340 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2341
2342 new_cor_lsa->cor_r=cor_lsa->cor_r;
2343 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2344 }
2345 else if ( res == HT_OLD_ENTRY )
2346 {
2347 if ( nlsr->debugging )
2348 printf("Cor LSA exists (Old)... \n");
2349 }
2350 hashtb_end(e);
2351
akmhoque569a93d2013-02-21 10:19:54 -06002352 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002353
2354}
2355
2356void
2357build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2358{
2359 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2360 cor_lsa->header->ls_type=LS_TYPE_COR;
2361
2362 char *time_stamp=(char *)malloc(20);
2363 memset(time_stamp,0,20);
2364 get_current_timestamp_micro(time_stamp);
2365
2366 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2367 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2368 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2369 free(time_stamp);
2370
2371 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2372 cor_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
2373 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2374 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2375 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2376
2377 cor_lsa->cor_r=cor_r;
2378 cor_lsa->cor_theta=cor_theta;
2379
2380}
2381
2382void
2383build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2384{
2385 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2386 cor_lsa->header->ls_type=ls_type;
2387
2388 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2389 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002390 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002391
2392 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2393 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2394 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002395 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002396 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2397
2398 cor_lsa->cor_r=cor_r;
2399 cor_lsa->cor_theta=cor_theta;
2400
2401}
2402
2403void
2404build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2405{
2406 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2407 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2408 install_cor_lsa(cor_lsa);
2409
2410 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002411
2412 free(cor_lsa->header->orig_router->name);
akmhoqueb77b95f2013-02-08 12:28:47 -06002413 free(cor_lsa->header->orig_router);
2414 free(cor_lsa->header->orig_time);
2415 free(cor_lsa->header);
2416 free(cor_lsa);
2417
2418}
2419
2420
2421void
2422build_and_install_cor_lsa()
2423{
2424
2425
2426
2427 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2428
2429 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2430 install_cor_lsa(cor_lsa);
2431
2432 write_cor_lsa_to_repo(cor_lsa);
2433
2434 print_cor_lsdb();
2435
2436 free(cor_lsa->header->orig_router);
2437 free(cor_lsa->header->orig_time);
2438 free(cor_lsa->header);
2439 free(cor_lsa);
2440
2441}
2442
2443void
2444get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2445{
2446 if ( nlsr->debugging )
2447 printf("get_cor_lsa_data called \n");
2448 if ( nlsr->detailed_logging )
2449 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2450
2451 struct clsa *cor_lsa=(struct clsa*)malloc(sizeof(struct clsa ));
2452
2453 struct hashtb_enumerator ee;
2454 struct hashtb_enumerator *e = &ee;
2455 int res;
2456
2457 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2458 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2459
2460 if( res == HT_OLD_ENTRY )
2461 {
2462 cor_lsa=e->data;
2463
2464 if ( nlsr->debugging )
2465 printf("Cor LSA found \n");
2466 if ( nlsr->detailed_logging )
2467 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2468
2469 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2470 ccn_charbuf_append_string(lsa_data,"|");
2471
2472 char *temp_length=(char *)malloc(20);
2473 memset(temp_length,0,20);
2474 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2475 ccn_charbuf_append_string(lsa_data,temp_length);
2476 ccn_charbuf_append_string(lsa_data,"|");
2477 free(temp_length);
2478
2479 char *temp_ltype=(char *)malloc(20);
2480 memset(temp_ltype,0,20);
2481 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2482 ccn_charbuf_append_string(lsa_data,temp_ltype);
2483 ccn_charbuf_append_string(lsa_data,"|");
2484 free(temp_ltype);
2485
2486 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2487 ccn_charbuf_append_string(lsa_data,"|");
2488
2489 char *cor_r=(char *)malloc(20);
2490 memset(cor_r,0,20);
2491 sprintf(cor_r,"%f",cor_lsa->cor_r);
2492 ccn_charbuf_append_string(lsa_data,cor_r);
2493 ccn_charbuf_append_string(lsa_data,"|");
2494 free(cor_r);
2495
2496 char *cor_theta=(char *)malloc(20);
2497 memset(cor_theta,0,20);
2498 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2499 ccn_charbuf_append_string(lsa_data,cor_theta);
2500 ccn_charbuf_append_string(lsa_data,"|");
2501 free(cor_theta);
2502
2503 }
2504 else if(res == HT_NEW_ENTRY)
2505 {
2506 hashtb_delete(e);
2507 }
2508
2509 hashtb_end(e);
2510}
2511
2512void
2513write_cor_lsa_to_repo(struct clsa *cor_lsa)
2514{
2515
2516
2517 if ( nlsr->debugging )
2518 printf("write_cor_lsa_to_repo called\n");
2519
2520
2521 char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2);
2522 memset(key,0,cor_lsa->header->orig_router->length+2+2);
2523 make_cor_lsa_key(key,cor_lsa);
2524
2525 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2526 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002527
2528 char *data=(char *)calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char));
2529 memcpy(data, ccn_charbuf_as_string(lsa_data),strlen(ccn_charbuf_as_string(lsa_data)));
2530 data[strlen(ccn_charbuf_as_string(lsa_data))]='\0';
2531
2532 //if ( nlsr->debugging )
2533 //printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002534 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002535 printf("Cor LSA Data: %s \n",data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002536 char *lst=(char *)malloc(20);
2537 memset(lst,0,20);
2538 sprintf(lst,"%d",cor_lsa->header->ls_type);
2539 char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15);
2540 memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15);
2541 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);
2542
2543 if ( nlsr->debugging )
2544 printf("Cor LSA Repo Key: %s \n",repo_key);
2545
akmhoque323b5e92013-02-21 13:55:15 -06002546 //write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
2547 write_data_to_repo(data, repo_key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002548
2549
2550
2551 free(lst);
2552 free(key);
2553 free(repo_key);
akmhoque4f85aab2013-02-21 13:58:50 -06002554 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002555}
2556
2557void
2558make_cor_lsa_key_by_router_name(char *key,char *router_name)
2559{
2560 memcpy(key+strlen(key),router_name,strlen(router_name));
2561 memcpy(key+strlen(key),"/",1);
2562 char ls_type[2];
2563 sprintf(ls_type,"%d",LS_TYPE_COR);
2564 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2565 key[strlen(key)]='\0';
2566}
2567
2568
2569double
2570get_hyperbolic_r(char *router)
2571{
2572 double ret=-1.0;
2573 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2574 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2575
2576
2577 struct clsa *cor_lsa;
2578 struct hashtb_enumerator ee;
2579 struct hashtb_enumerator *e = &ee;
2580 int res;
2581
2582 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2583 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2584
2585 if ( res == HT_OLD_ENTRY)
2586 {
2587 cor_lsa=e->data;
2588 ret=cor_lsa->cor_r;
2589 }
2590 else if(res == HT_NEW_ENTRY)
2591 {
2592 hashtb_delete(e);
2593 }
2594
2595 hashtb_end(e);
2596
2597 free(cor_lsa_key);
2598 return ret;
2599}
2600
2601double
2602get_hyperbolic_theta(char *router)
2603{
2604 double ret=-1.0;
2605 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2606 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2607
2608 struct clsa *cor_lsa;
2609 struct hashtb_enumerator ee;
2610 struct hashtb_enumerator *e = &ee;
2611 int res;
2612
2613 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2614 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2615
2616 if ( res == HT_OLD_ENTRY)
2617 {
2618 cor_lsa=e->data;
2619 ret=cor_lsa->cor_theta;
2620 }
2621 else if(res == HT_NEW_ENTRY)
2622 {
2623 hashtb_delete(e);
2624 }
2625
2626 hashtb_end(e);
2627
2628 free(cor_lsa_key);
2629 return ret;
2630}