blob: 46a9428b41969067ced851e8f7b5a26a96dfe43f [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);
akmhoque54d86112013-02-21 16:42:34 -0600152 //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);
157 //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
akmhoque54d86112013-02-21 16:42:34 -0600185 //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);
akmhoque3171d652012-11-13 11:44:33 -0600190 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
akmhoque54d86112013-02-21 16:42:34 -0600232 /*char *time_stamp=(char *)malloc(20);
akmhoqueffacaa82012-09-13 17:48:30 -0500233 memset(time_stamp,0,20);
akmhoque54d86112013-02-21 16:42:34 -0600234 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;
akmhoque54d86112013-02-21 16:42:34 -0600273 //memcpy(e->data, name_lsa, sizeof(name_lsa));
akmhoque8876e982013-02-21 13:35:46 -0600274
akmhoque54d86112013-02-21 16:42:34 -0600275
akmhoque0ab71642013-02-21 10:10:33 -0600276 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500277 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
278
279 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
280 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque8876e982013-02-21 13:35:46 -0600281 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 -0500282
283 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque0ab71642013-02-21 10:10:33 -0600284 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500285 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
286 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
287 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
288 new_name_lsa->header->isValid=name_lsa->header->isValid;
289
290
akmhoque0ab71642013-02-21 10:10:33 -0600291 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500292 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
293 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
294 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
akmhoque8876e982013-02-21 13:35:46 -0600295
akmhoqueffacaa82012-09-13 17:48:30 -0500296
akmhoque7b791452012-10-30 11:24:56 -0500297 if ( nlsr->debugging )
298 {
299 printf("New Name LSA Added....\n");
300 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
301 }
302 if ( nlsr->detailed_logging )
303 {
304 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n");
305 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
306 }
akmhoque54d86112013-02-21 16:42:34 -0600307
akmhoqueffacaa82012-09-13 17:48:30 -0500308 set_new_lsdb_version();
akmhoque54d86112013-02-21 16:42:34 -0600309
akmhoque7b791452012-10-30 11:24:56 -0500310 if ( nlsr->debugging )
311 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
312 if ( nlsr->detailed_logging )
313 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500314
akmhoque9e9fc722012-09-26 14:03:25 -0500315
akmhoquede61ba92012-09-20 22:19:12 -0500316 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500317 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500318 {
akmhoquede61ba92012-09-20 22:19:12 -0500319 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 -0500320 if ( check == HT_NEW_ENTRY )
321 {
akmhoque7b791452012-10-30 11:24:56 -0500322 if ( nlsr->debugging )
323 printf("Added in npt \n");
324 if ( nlsr->detailed_logging )
325 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500326 }
akmhoque3560cb62012-09-09 10:52:30 -0500327 }
akmhoqueffacaa82012-09-13 17:48:30 -0500328 else
akmhoque3560cb62012-09-09 10:52:30 -0500329 {
akmhoquede61ba92012-09-20 22:19:12 -0500330 int *faces=malloc(num_next_hop*sizeof(int));
331 int *route_costs=malloc(num_next_hop*sizeof(int));
332 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500333 if ( nlsr->debugging )
334 {
335 printf("Printing from install_name_lsa \n");
336 int j;
337 for(j=0;j<num_next_hop;j++)
338 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
339 }
340 if ( nlsr->detailed_logging )
341 {
342 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
343 int j;
344 for(j=0;j<num_next_hop;j++)
345 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
346 }
akmhoquede61ba92012-09-20 22:19:12 -0500347 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 -0500348 if ( check == HT_NEW_ENTRY )
349 {
akmhoque7b791452012-10-30 11:24:56 -0500350 if ( nlsr->debugging )
351 printf("Added in npt \n");
352 if ( nlsr->detailed_logging )
353 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500354 }
akmhoquede61ba92012-09-20 22:19:12 -0500355 free(faces);
356 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500357
akmhoque3560cb62012-09-09 10:52:30 -0500358 }
akmhoquede61ba92012-09-20 22:19:12 -0500359
akmhoque9e9fc722012-09-26 14:03:25 -0500360 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
361 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
akmhoque54d86112013-02-21 16:42:34 -0600362 //write_log_for_name_lsa(new_name_lsa);
akmhoque9e9fc722012-09-26 14:03:25 -0500363 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500364
akmhoque54d86112013-02-21 16:42:34 -0600365 //free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -0500366
367 }
368 else if(res == HT_OLD_ENTRY)
369 {
370 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500371 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500372 {
akmhoque7b791452012-10-30 11:24:56 -0500373 if ( nlsr->debugging )
374 printf("Older Adj LSA. Discarded... \n");
375 if ( nlsr->detailed_logging )
376 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500377 }
378 else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 )
379 {
akmhoque7b791452012-10-30 11:24:56 -0500380 if ( nlsr->debugging )
381 printf("Duplicate Adj LSA. Discarded... \n");
382 if ( nlsr->detailed_logging )
383 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500384 }
385 else
386 {
387 if ( name_lsa->header->isValid == 0 )
388 {
389 // have to call to delete npt table entry
akmhoque3cced642012-09-24 16:20:20 -0500390 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 -0500391
392 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
393 {
akmhoque9e9fc722012-09-26 14:03:25 -0500394 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
395 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
396 write_log_for_name_lsa(new_name_lsa);
397 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
398
akmhoqueffacaa82012-09-13 17:48:30 -0500399 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500400 if ( nlsr->debugging )
401 printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
402 if ( nlsr->detailed_logging )
403 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 -0500404 }
405 else
406 {
407 new_name_lsa->header->isValid=name_lsa->header->isValid;
408 free(new_name_lsa->header->orig_time);
409 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
410 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
411 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
412 }
akmhoque7b791452012-10-30 11:24:56 -0500413 if ( nlsr->debugging )
414 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
415 if ( nlsr->detailed_logging )
416 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500417 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500418 if ( nlsr->debugging )
419 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
420 if ( nlsr->detailed_logging )
421 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500422 }
423 else
424 {
425 int is_npt_update=0;
426 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
427 {
428 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500429 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 -0500430 }
431
432 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500433 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
434 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
435 write_log_for_name_lsa(new_name_lsa);
436 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
437
akmhoqueffacaa82012-09-13 17:48:30 -0500438
439 free(new_name_lsa->header->orig_time);
440 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
441 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600442 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500443
444 new_name_lsa->header->isValid=name_lsa->header->isValid;
445
446 free(new_name_lsa->name_prefix->name);
447 free(new_name_lsa->name_prefix);
448 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
449 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
450 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
451 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
452
akmhoque9e9fc722012-09-26 14:03:25 -0500453
454 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
455 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
456 write_log_for_name_lsa(new_name_lsa);
457 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
458
akmhoque7b791452012-10-30 11:24:56 -0500459 if ( nlsr->debugging )
460 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
461 if ( nlsr->detailed_logging )
462 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
463
akmhoqueffacaa82012-09-13 17:48:30 -0500464 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500465
466 if ( nlsr->debugging )
467 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
468 if ( nlsr->detailed_logging )
469 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
470
akmhoqueffacaa82012-09-13 17:48:30 -0500471
472 if( is_npt_update == 1 )
473 {
akmhoquede61ba92012-09-20 22:19:12 -0500474 //struct hashtb *face_list;
475 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
476 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500477 {
akmhoquede61ba92012-09-20 22:19:12 -0500478
479 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 -0500480 if ( check == HT_NEW_ENTRY )
481 {
akmhoque7b791452012-10-30 11:24:56 -0500482 if ( nlsr->debugging )
483 printf("Added in npt \n");
484 if ( nlsr->detailed_logging )
485 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500486 }
487 }
488 else
489 {
akmhoquede61ba92012-09-20 22:19:12 -0500490 int *faces=malloc(num_next_hop*sizeof(int));
491 int *route_costs=malloc(num_next_hop*sizeof(int));
492 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500493
494 if ( nlsr->debugging )
495 {
496 printf("Printing from install_name_lsa \n");
497 int j;
498 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500499 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500500 }
501 if ( nlsr->detailed_logging )
502 {
503 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
504 int j;
505 for(j=0;j<num_next_hop;j++)
506 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
507 }
508
akmhoquede61ba92012-09-20 22:19:12 -0500509
510 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 -0500511 if ( check == HT_NEW_ENTRY )
512 {
akmhoque7b791452012-10-30 11:24:56 -0500513 if ( nlsr->debugging )
514 printf("Added in npt \n");
515 if ( nlsr->detailed_logging )
516 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500517 }
akmhoquede61ba92012-09-20 22:19:12 -0500518 free(faces);
519 free(route_costs);
520
akmhoqueffacaa82012-09-13 17:48:30 -0500521 }
akmhoquede61ba92012-09-20 22:19:12 -0500522
akmhoqueffacaa82012-09-13 17:48:30 -0500523 }
524 }
525 }
526
akmhoque3560cb62012-09-09 10:52:30 -0500527 }
akmhoque53f64222012-09-05 13:57:51 -0500528
akmhoqueffacaa82012-09-13 17:48:30 -0500529 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500530
akmhoque569a93d2013-02-21 10:19:54 -0600531 //free(key);
akmhoque53f64222012-09-05 13:57:51 -0500532}
533
akmhoque9e9fc722012-09-26 14:03:25 -0500534void
535write_log_for_name_lsa(struct nlsa *name_lsa)
536{
537
538 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
539 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
540 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500541 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
542 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
543 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
544 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500545 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
546 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
547 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
548 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
549}
akmhoque53f64222012-09-05 13:57:51 -0500550
akmhoque03004e62012-09-06 01:12:28 -0500551void
552print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500553{
akmhoque53f64222012-09-05 13:57:51 -0500554
akmhoque7b791452012-10-30 11:24:56 -0500555 if ( nlsr->debugging )
556 {
557 printf("-----------Name LSA Content---------------\n");
558 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
559 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
560 printf(" LS Type : %d\n",name_lsa->header->ls_type);
561 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
562 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
563 printf(" Is Valid : %d\n",name_lsa->header->isValid);
564 printf(" LSA Data \n");
565 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
566 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
567
568 printf("\n");
569 }
akmhoquef71d9082012-08-22 12:51:53 -0400570}
571
572void
573print_name_lsdb(void)
574{
akmhoque7b791452012-10-30 11:24:56 -0500575 if ( nlsr->debugging )
576 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500577 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400578 struct nlsa *name_lsa;
579
580 struct hashtb_enumerator ee;
581 struct hashtb_enumerator *e = &ee;
582
583 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500584 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400585
akmhoque53f64222012-09-05 13:57:51 -0500586 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400587 {
akmhoque7b791452012-10-30 11:24:56 -0500588 if ( nlsr->debugging )
589 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400590 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500591 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400592 hashtb_next(e);
593 }
594
595 hashtb_end(e);
596
akmhoque3171d652012-11-13 11:44:33 -0600597 if ( nlsr->debugging )
598 printf("\n");
599 if ( nlsr->detailed_logging )
600 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500601}
602
akmhoque03004e62012-09-06 01:12:28 -0500603
604void
605build_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 -0500606{
akmhoque7b791452012-10-30 11:24:56 -0500607 if ( nlsr->debugging )
608 printf("build_and_install_others_name_lsa called \n");
609 if ( nlsr->detailed_logging )
610 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500611
akmhoque03004e62012-09-06 01:12:28 -0500612 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
613 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
614 print_name_lsa(name_lsa);
615 install_name_lsa(name_lsa);
616 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500617 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500618
akmhoque03004e62012-09-06 01:12:28 -0500619 free(name_lsa->header->orig_router->name);
620 free(name_lsa->header->orig_router);
621 free(name_lsa->header);
622 free(name_lsa->name_prefix->name);
623 free(name_lsa->name_prefix);
624 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500625
626}
627
628void
akmhoque03004e62012-09-06 01:12:28 -0500629build_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 -0500630{
akmhoque7b791452012-10-30 11:24:56 -0500631 if ( nlsr->debugging )
632 printf("build_others_name_lsa called\n");
633 if ( nlsr->detailed_logging )
634 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500635
akmhoque03004e62012-09-06 01:12:28 -0500636 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
637 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500638
akmhoque03004e62012-09-06 01:12:28 -0500639 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
640 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600641 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoque53f64222012-09-05 13:57:51 -0500642
akmhoque03004e62012-09-06 01:12:28 -0500643 name_lsa->header->ls_id=ls_id;
644 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
645 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
646 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600647 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -0500648 name_lsa->header->orig_router->length=strlen(orig_router)+1;
649 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500650
akmhoque03004e62012-09-06 01:12:28 -0500651 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
652 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
653 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600654 memcpy(name_lsa->name_prefix->name,np,strlen(np));
akmhoque03004e62012-09-06 01:12:28 -0500655 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400656}
akmhoqued79438d2012-08-27 13:31:42 -0500657
658
akmhoqueb77b95f2013-02-08 12:28:47 -0600659void
660make_cor_lsa_key(char *key,struct clsa *cor_lsa)
661{
662 memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length);
663 memcpy(key+strlen(key),"/",1);
664 char ls_type[2];
665 sprintf(ls_type,"%d",cor_lsa->header->ls_type);
666 memcpy(key+strlen(key),ls_type,strlen(ls_type));
667 key[strlen(key)]='\0';
668}
akmhoqueffacaa82012-09-13 17:48:30 -0500669
670
akmhoque53f64222012-09-05 13:57:51 -0500671void
672make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500673{
akmhoque53f64222012-09-05 13:57:51 -0500674 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
675 memcpy(key+strlen(key),"/",1);
676 char ls_type[2];
677 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
678 memcpy(key+strlen(key),ls_type,strlen(ls_type));
679 key[strlen(key)]='\0';
680}
681
akmhoque03004e62012-09-06 01:12:28 -0500682int
683build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
684{
akmhoqueffacaa82012-09-13 17:48:30 -0500685 if(flags == CCN_SCHEDULE_CANCEL)
686 {
687 return -1;
688 }
689
690 nlsr_lock();
691
akmhoque7b791452012-10-30 11:24:56 -0500692 if ( nlsr->debugging )
693 printf("build_and_install_adj_lsa called \n");
694 if ( nlsr->detailed_logging )
695 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
696
697 if ( nlsr->debugging )
698 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
699 if ( nlsr->detailed_logging )
700 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500701
702 if(nlsr->adj_build_flag > 0)
703 {
akmhoque7b791452012-10-30 11:24:56 -0500704 if ( nlsr->debugging )
705 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
706 if ( nlsr->detailed_logging )
707 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
708
akmhoque03004e62012-09-06 01:12:28 -0500709 if ( is_adj_lsa_build()> 0)
710 {
711 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
712 build_adj_lsa(adj_lsa);
713 install_adj_lsa(adj_lsa);
714
akmhoqueb77b95f2013-02-08 12:28:47 -0600715 char lst[2];
716 memset(lst,0,2);
717 sprintf(lst,"%d",LS_TYPE_ADJ);
718
719 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);
720 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);
721 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);
722
723 if ( nlsr->debugging )
724 printf("Adj LSA Repo Key: %s \n",repo_key);
725
726 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
727 memset(key,0,adj_lsa->header->orig_router->length+2+2);
728 make_adj_lsa_key(key,adj_lsa);
729 if ( nlsr->debugging )
730 printf("Adj LSA: %s \n",key);
731
732 struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
733 lsaid->name=(char *)malloc(strlen(key)+1);
734 memset(lsaid->name, 0, strlen(key)+1);
735 memcpy(lsaid->name,key,strlen(key));
736 lsaid->length=strlen(key)+1;
737
738
739 write_adj_lsa_to_repo(repo_key, lsaid);
740
akmhoque569a93d2013-02-21 10:19:54 -0600741 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600742 free(repo_key);
743 free(lsaid->name);
744 free(lsaid);
745
746
747
akmhoque03004e62012-09-06 01:12:28 -0500748 free(adj_lsa->header->orig_router->name);
749 free(adj_lsa->header->orig_router);
750 free(adj_lsa->header->orig_time);
751 free(adj_lsa->header);
752 free(adj_lsa->body);
753 free(adj_lsa);
754 nlsr->adj_build_flag=0;
755 print_adj_lsdb();
756 }
757 else
758 {
akmhoque7b791452012-10-30 11:24:56 -0500759 if ( nlsr->debugging )
760 printf("Can not build adj LSA now\n");
761 if ( nlsr->detailed_logging )
762 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500763 }
764 }
765 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500766
767 nlsr_unlock();
768
akmhoque03004e62012-09-06 01:12:28 -0500769 return 0;
770}
771
772
773void
774build_adj_lsa(struct alsa * adj_lsa)
775{
akmhoque7b791452012-10-30 11:24:56 -0500776 if ( nlsr->debugging )
777 printf("build_adj_lsa called \n");
778 if ( nlsr->detailed_logging )
779 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500780
781 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500782
akmhoque03004e62012-09-06 01:12:28 -0500783 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
784 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
785 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
786 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
787 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
788 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
789
790 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
791
792 char *time_stamp=(char *)malloc(20);
793 memset(time_stamp,0,20);
794 get_current_timestamp_micro(time_stamp);
795
796 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
797 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
798 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
799 free(time_stamp);
800
akmhoque03004e62012-09-06 01:12:28 -0500801 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500802
803
804 struct ccn_charbuf *c=ccn_charbuf_create();
805 get_active_nbr_adj_data(c);
806 char *data=ccn_charbuf_as_string(c);
807
808 adj_lsa->body=(char *)malloc(strlen(data)+1);
809 memset(adj_lsa->body,0,strlen(data)+1);
810 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
811 ccn_charbuf_destroy(&c);
812
akmhoque03004e62012-09-06 01:12:28 -0500813 nlsr->adj_build_count++;
814
815
816}
817
818
akmhoque53f64222012-09-05 13:57:51 -0500819void
820install_adj_lsa(struct alsa * adj_lsa)
821{
akmhoqued79438d2012-08-27 13:31:42 -0500822
akmhoque7b791452012-10-30 11:24:56 -0500823 if ( nlsr->debugging )
824 printf("install_adj_lsa called \n");
825 if ( nlsr->detailed_logging )
826 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
827
akmhoque03004e62012-09-06 01:12:28 -0500828
akmhoqueffacaa82012-09-13 17:48:30 -0500829 char *time_stamp=(char *)malloc(20);
830 memset(time_stamp,0,20);
831 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500832
akmhoqueffacaa82012-09-13 17:48:30 -0500833
834 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
835 memset(key,0,adj_lsa->header->orig_router->length+2);
836 make_adj_lsa_key(key,adj_lsa);
akmhoqueffacaa82012-09-13 17:48:30 -0500837
akmhoque8876e982013-02-21 13:35:46 -0600838 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500839
840 struct hashtb_enumerator ee;
841 struct hashtb_enumerator *e = &ee;
842 int res;
843
844 hashtb_start(nlsr->lsdb->adj_lsdb, e);
845 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500846
akmhoque03004e62012-09-06 01:12:28 -0500847
akmhoque53f64222012-09-05 13:57:51 -0500848
akmhoque62c0c192012-09-24 07:49:25 -0500849 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500850 {
akmhoque62c0c192012-09-24 07:49:25 -0500851 if ( adj_lsa->no_link > 0)
852 {
akmhoque3171d652012-11-13 11:44:33 -0600853 if ( nlsr->debugging )
854 printf("New ADJ LSA... Adding to LSDB\n");
855 if ( nlsr->detailed_logging )
856 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n");
akmhoque62c0c192012-09-24 07:49:25 -0500857 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500858
akmhoque62c0c192012-09-24 07:49:25 -0500859 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
860 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
861 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
862 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 -0500863
akmhoque62c0c192012-09-24 07:49:25 -0500864 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
865 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
866 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
867 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500868
akmhoque62c0c192012-09-24 07:49:25 -0500869 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500870
akmhoque62c0c192012-09-24 07:49:25 -0500871 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
872 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
873 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
874
875 add_next_hop_router(new_adj_lsa->header->orig_router->name);
876 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500877
878 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
879 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
880 write_log_for_adj_lsa(new_adj_lsa);
881 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500882 }
883 else
884 {
885 hashtb_delete(e);
886 }
akmhoque53f64222012-09-05 13:57:51 -0500887
akmhoque7b791452012-10-30 11:24:56 -0500888 if ( nlsr->debugging )
889 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
890 if ( nlsr->detailed_logging )
891 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
892
akmhoque53f64222012-09-05 13:57:51 -0500893 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500894
895 if ( nlsr->debugging )
896 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
897 if ( nlsr->detailed_logging )
898 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
899
akmhoqueffacaa82012-09-13 17:48:30 -0500900 }
901 else if(res == HT_OLD_ENTRY)
902 {
903 new_adj_lsa = e->data;
904 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
905 {
akmhoque7b791452012-10-30 11:24:56 -0500906 if ( nlsr->debugging )
907 printf("Older/Duplicate Adj LSA. Discarded...\n");
908 if ( nlsr->detailed_logging )
909 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500910 }
911 else
912 {
akmhoqueffacaa82012-09-13 17:48:30 -0500913
akmhoque62c0c192012-09-24 07:49:25 -0500914 if ( adj_lsa->no_link > 0)
915 {
akmhoque9e9fc722012-09-26 14:03:25 -0500916 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
917 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
918 write_log_for_adj_lsa(new_adj_lsa);
919 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500920
akmhoque62c0c192012-09-24 07:49:25 -0500921 free(new_adj_lsa->header->orig_time);
922 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
923 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
924
925 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500926
akmhoque62c0c192012-09-24 07:49:25 -0500927 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
928 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
929 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500930
akmhoque62c0c192012-09-24 07:49:25 -0500931 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500932
933 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
934 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
935 write_log_for_adj_lsa(new_adj_lsa);
936 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500937 }
938 else
939 {
akmhoque9e9fc722012-09-26 14:03:25 -0500940 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
941 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
942 write_log_for_adj_lsa(new_adj_lsa);
943 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
944
akmhoque62c0c192012-09-24 07:49:25 -0500945 hashtb_delete(e);
946 }
akmhoque7b791452012-10-30 11:24:56 -0500947
948 if ( nlsr->debugging )
949 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
950 if ( nlsr->detailed_logging )
951 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
952
akmhoqueffacaa82012-09-13 17:48:30 -0500953 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500954
955 if ( nlsr->debugging )
956 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
957 if ( nlsr->detailed_logging )
958 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500959 }
960
961 }
962 hashtb_end(e);
963
964 if ( !nlsr->is_route_calculation_scheduled )
965 {
966 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
967 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -0500968 }
969
akmhoque03004e62012-09-06 01:12:28 -0500970
akmhoque569a93d2013-02-21 10:19:54 -0600971 //free(key);
akmhoqueffacaa82012-09-13 17:48:30 -0500972
973 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500974}
975
976void
akmhoque9e9fc722012-09-26 14:03:25 -0500977write_log_for_adj_lsa_body(const char *body, int no_link)
978{
979 int i=0;
980 char *lsa_data=(char *)malloc(strlen(body)+1);
981 memset( lsa_data,0,strlen(body)+1);
982 memcpy(lsa_data,body,strlen(body)+1);
983 char *sep="|";
984 char *rem;
985 char *rtr_id;
986 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -0600987 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -0500988 char *metric;
989
990 if(no_link >0 )
991 {
992 rtr_id=strtok_r(lsa_data,sep,&rem);
993 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -0600994 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -0500995 metric=strtok_r(NULL,sep,&rem);
996
997 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -0500998 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
999 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001000 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001001 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001002
1003
1004 for(i=1;i<no_link;i++)
1005 {
1006 rtr_id=strtok_r(NULL,sep,&rem);
1007 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001008 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001009 metric=strtok_r(NULL,sep,&rem);
1010 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001011 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1012 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001013 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001014 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001015
1016 }
1017 }
1018
1019 free(lsa_data);
1020}
1021
1022
1023void
1024write_log_for_adj_lsa(struct alsa * adj_lsa)
1025{
1026 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001027 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
1028 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1029 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
1030 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -05001031 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001032 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001033
1034 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1035
1036 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1037
1038}
1039
1040void
akmhoque53f64222012-09-05 13:57:51 -05001041print_adj_lsa_body(const char *body, int no_link)
1042{
1043 int i=0;
1044 char *lsa_data=(char *)malloc(strlen(body)+1);
1045 memset( lsa_data,0,strlen(body)+1);
1046 memcpy(lsa_data,body,strlen(body)+1);
1047 char *sep="|";
1048 char *rem;
1049 char *rtr_id;
1050 char *length;
akmhoqueb28579d2013-02-12 11:15:52 -06001051 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001052 char *metric;
1053
akmhoque53f64222012-09-05 13:57:51 -05001054 if(no_link >0 )
1055 {
1056 rtr_id=strtok_r(lsa_data,sep,&rem);
1057 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001058 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001059 metric=strtok_r(NULL,sep,&rem);
1060
akmhoqueb77b95f2013-02-08 12:28:47 -06001061 if ( nlsr->debugging ) {
1062 printf(" Link %d \n",i+1);
1063 printf(" Neighbor : %s \n",rtr_id);
1064 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001065 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001066 printf(" Metric : %s \n",metric);
1067 }
akmhoque53f64222012-09-05 13:57:51 -05001068
1069 for(i=1;i<no_link;i++)
1070 {
1071 rtr_id=strtok_r(NULL,sep,&rem);
1072 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001073 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001074 metric=strtok_r(NULL,sep,&rem);
1075 printf(" Link %d \n",i+1);
1076 printf(" Neighbor : %s \n",rtr_id);
1077 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001078 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001079 printf(" Metric : %s \n",metric);
1080
1081 }
1082 }
1083
1084 free(lsa_data);
1085}
1086
1087void
1088print_adj_lsa(struct alsa * adj_lsa)
1089{
akmhoque7b791452012-10-30 11:24:56 -05001090 if ( nlsr->debugging )
1091 {
1092 printf("-----------ADJ LSA Content---------------\n");
1093 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
1094 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
1095 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
1096 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
1097 printf(" Lsa Data:\n");
1098 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -05001099
akmhoque7b791452012-10-30 11:24:56 -05001100 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1101 printf("\n");
1102 }
akmhoque53f64222012-09-05 13:57:51 -05001103
1104}
1105
1106void
1107print_adj_lsdb(void)
1108{
akmhoque7b791452012-10-30 11:24:56 -05001109 if ( nlsr->debugging )
1110 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001111 int i, adj_lsdb_element;
1112 struct alsa *adj_lsa;
1113
1114 struct hashtb_enumerator ee;
1115 struct hashtb_enumerator *e = &ee;
1116
1117 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1118 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1119
1120 for(i=0;i<adj_lsdb_element;i++)
1121 {
akmhoque7b791452012-10-30 11:24:56 -05001122 if ( nlsr->debugging )
1123 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001124 adj_lsa=e->data;
1125 print_adj_lsa(adj_lsa);
1126 hashtb_next(e);
1127 }
1128
1129 hashtb_end(e);
1130
akmhoque3171d652012-11-13 11:44:33 -06001131 if ( nlsr->debugging )
1132 printf("\n");
1133 if ( nlsr->detailed_logging )
1134 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001135}
1136
1137void
akmhoque03004e62012-09-06 01:12:28 -05001138build_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 -05001139{
akmhoque7b791452012-10-30 11:24:56 -05001140 if ( nlsr->debugging )
1141 printf("build_and_install_others_adj_lsa called \n");
1142 if ( nlsr->detailed_logging )
1143 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001144 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1145 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
akmhoque03004e62012-09-06 01:12:28 -05001146 install_adj_lsa(adj_lsa);
1147
akmhoque53f64222012-09-05 13:57:51 -05001148
akmhoque03004e62012-09-06 01:12:28 -05001149 free(adj_lsa->header->orig_router->name);
1150 free(adj_lsa->header->orig_router);
1151 free(adj_lsa->header->orig_time);
1152 free(adj_lsa->header);
1153 free(adj_lsa->body);
1154 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001155
akmhoque03004e62012-09-06 01:12:28 -05001156 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001157
akmhoque53f64222012-09-05 13:57:51 -05001158}
1159
akmhoque03004e62012-09-06 01:12:28 -05001160
akmhoque53f64222012-09-05 13:57:51 -05001161void
akmhoque03004e62012-09-06 01:12:28 -05001162build_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 -05001163{
akmhoque7b791452012-10-30 11:24:56 -05001164 if ( nlsr->debugging )
1165 printf("build_others_adj_lsa called \n");
1166 if ( nlsr->detailed_logging )
1167 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001168
akmhoque03004e62012-09-06 01:12:28 -05001169 /*Filling Up Header Data */
1170 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
1171 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1172 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
1173 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
1174 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001175
akmhoque03004e62012-09-06 01:12:28 -05001176 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001177
akmhoque53f64222012-09-05 13:57:51 -05001178
akmhoque03004e62012-09-06 01:12:28 -05001179 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001180
akmhoque03004e62012-09-06 01:12:28 -05001181 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
1182 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
1183 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001184
akmhoque03004e62012-09-06 01:12:28 -05001185 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001186
akmhoque03004e62012-09-06 01:12:28 -05001187 adj_lsa->body=(char *)malloc(strlen(data)+1);
1188 memset(adj_lsa->body,0,strlen(data)+1);
1189 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001190
akmhoque53f64222012-09-05 13:57:51 -05001191}
1192
akmhoque03004e62012-09-06 01:12:28 -05001193
akmhoque53f64222012-09-05 13:57:51 -05001194long int
1195get_name_lsdb_num_element(void)
1196{
1197 long int num_element;
1198
1199
1200 struct hashtb_enumerator ee;
1201 struct hashtb_enumerator *e = &ee;
1202
1203 hashtb_start(nlsr->lsdb->name_lsdb, e);
1204 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1205 hashtb_end(e);
1206
1207 return num_element;
1208}
1209
1210long int
1211get_adj_lsdb_num_element(void)
1212{
1213 long int num_element;
1214
1215
1216 struct hashtb_enumerator ee;
1217 struct hashtb_enumerator *e = &ee;
1218
1219 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1220 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1221 hashtb_end(e);
1222
1223 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001224}
akmhoque03004e62012-09-06 01:12:28 -05001225
akmhoque03004e62012-09-06 01:12:28 -05001226
1227int
1228check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1229{
1230 int ret=0;
1231 struct ccn_charbuf *key=ccn_charbuf_create();
1232 ccn_charbuf_append_string(key,orig_router);
1233 ccn_charbuf_append_string(key,"/");
1234 ccn_charbuf_append_string(key,lst);
1235 ccn_charbuf_append_string(key,"/");
1236 ccn_charbuf_append_string(key,lsid);
1237
1238 int res;
1239 struct nlsa *name_lsa;
1240
1241 struct hashtb_enumerator ee;
1242 struct hashtb_enumerator *e = &ee;
1243
1244 hashtb_start(nlsr->lsdb->name_lsdb, e);
1245 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1246
1247 if( res == HT_NEW_ENTRY )
1248 {
1249 hashtb_delete(e);
1250 ret=1;
1251
1252 }
1253 else if(res == HT_OLD_ENTRY)
1254 {
1255 name_lsa=e->data;
1256 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1257 {
1258 ret=1;
1259 }
1260 }
1261
1262 hashtb_end(e);
1263
1264 ccn_charbuf_destroy(&key);
1265
1266 return ret;
1267}
1268
1269int
1270check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1271{
1272 int ret=0;
1273 struct ccn_charbuf *key=ccn_charbuf_create();
1274 ccn_charbuf_append_string(key,orig_router);
1275 ccn_charbuf_append_string(key,"/");
1276 ccn_charbuf_append_string(key,lst);
1277
1278 int res;
1279 struct alsa *adj_lsa;
1280
1281 struct hashtb_enumerator ee;
1282 struct hashtb_enumerator *e = &ee;
1283
1284 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1285 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1286
1287 if( res == HT_NEW_ENTRY )
1288 {
1289 hashtb_delete(e);
1290 ret=1;
1291
1292 }
1293 else if(res == HT_OLD_ENTRY)
1294 {
1295 adj_lsa=e->data;
1296 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1297 {
1298 ret=1;
1299 }
1300 }
1301
1302 hashtb_end(e);
1303
1304 ccn_charbuf_destroy(&key);
1305
1306 return ret;
1307}
1308
akmhoqueb77b95f2013-02-08 12:28:47 -06001309int
1310check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time)
1311{
1312 int ret=0;
1313 struct ccn_charbuf *key=ccn_charbuf_create();
1314 ccn_charbuf_append_string(key,orig_router);
1315 ccn_charbuf_append_string(key,"/");
1316 ccn_charbuf_append_string(key,lst);
1317
1318 int res;
1319 struct clsa *cor_lsa;
1320
1321 struct hashtb_enumerator ee;
1322 struct hashtb_enumerator *e = &ee;
1323
1324 hashtb_start(nlsr->lsdb->cor_lsdb, e);
1325 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1326
1327 if( res == HT_NEW_ENTRY )
1328 {
1329 hashtb_delete(e);
1330 ret=1;
1331
1332 }
1333 else if(res == HT_OLD_ENTRY)
1334 {
1335 cor_lsa=e->data;
1336 if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 )
1337 {
1338 ret=1;
1339 }
1340 }
1341
1342 hashtb_end(e);
1343
1344 ccn_charbuf_destroy(&key);
1345
1346 return ret;
1347}
1348
akmhoque03004e62012-09-06 01:12:28 -05001349void
1350get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1351{
akmhoque7b791452012-10-30 11:24:56 -05001352 if ( nlsr->debugging )
1353 printf("get_name_lsa_data called \n");
1354 if ( nlsr->detailed_logging )
1355 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001356
akmhoque8876e982013-02-21 13:35:46 -06001357 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001358
1359 struct hashtb_enumerator ee;
1360 struct hashtb_enumerator *e = &ee;
1361 int res;
1362
1363 hashtb_start(nlsr->lsdb->name_lsdb, e);
1364 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1365
1366 if( res == HT_OLD_ENTRY )
1367 {
1368 name_lsa=e->data;
akmhoqueb77b95f2013-02-08 12:28:47 -06001369
akmhoque7b791452012-10-30 11:24:56 -05001370 if ( nlsr->debugging )
1371 printf("NAME LSA found \n");
1372 if ( nlsr->detailed_logging )
1373 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001374
1375 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1376 ccn_charbuf_append_string(lsa_data,"|");
1377
1378 char *temp_length=(char *)malloc(20);
1379 memset(temp_length,0,20);
1380 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1381 ccn_charbuf_append_string(lsa_data,temp_length);
1382 free(temp_length);
1383 ccn_charbuf_append_string(lsa_data,"|");
1384
1385 char *temp_ltype=(char *)malloc(20);
1386 memset(temp_ltype,0,20);
1387 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1388 ccn_charbuf_append_string(lsa_data,temp_ltype);
1389 free(temp_ltype);
1390 ccn_charbuf_append_string(lsa_data,"|");
1391
1392 char *temp_lsid=(char *)malloc(20);
1393 memset(temp_lsid,0,20);
1394 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1395 ccn_charbuf_append_string(lsa_data,temp_lsid);
1396 free(temp_lsid);
1397 ccn_charbuf_append_string(lsa_data,"|");
1398
1399 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1400 ccn_charbuf_append_string(lsa_data,"|");
1401
1402 char *temp_valid=(char *)malloc(20);
1403 memset(temp_valid,0,20);
1404 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1405 ccn_charbuf_append_string(lsa_data,temp_valid);
1406 free(temp_valid);
1407 ccn_charbuf_append_string(lsa_data,"|");
1408
1409 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1410 ccn_charbuf_append_string(lsa_data,"|");
1411
1412 char *temp_npl=(char *)malloc(20);
1413 memset(temp_npl,0,20);
1414 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1415 ccn_charbuf_append_string(lsa_data,temp_npl);
1416 free(temp_npl);
1417 ccn_charbuf_append_string(lsa_data,"|");
1418
1419 }
1420 else if(res == HT_NEW_ENTRY)
1421 {
1422 hashtb_delete(e);
1423 }
1424
1425 hashtb_end(e);
1426}
1427
1428void
1429get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1430{
akmhoque7b791452012-10-30 11:24:56 -05001431 if ( nlsr->debugging )
1432 printf("get_adj_lsa_data called \n");
1433 if ( nlsr->detailed_logging )
1434 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001435
1436 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
1437
1438 struct hashtb_enumerator ee;
1439 struct hashtb_enumerator *e = &ee;
1440 int res;
1441
1442 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1443 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1444
1445 if( res == HT_OLD_ENTRY )
1446 {
1447 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001448
1449 if ( nlsr->debugging )
1450 printf("Adj LSA found \n");
1451 if ( nlsr->detailed_logging )
1452 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001453
1454 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1455 ccn_charbuf_append_string(lsa_data,"|");
1456
1457 char *temp_length=(char *)malloc(20);
1458 memset(temp_length,0,20);
1459 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1460 ccn_charbuf_append_string(lsa_data,temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001461 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001462 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001463
1464 char *temp_ltype=(char *)malloc(20);
1465 memset(temp_ltype,0,20);
1466 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1467 ccn_charbuf_append_string(lsa_data,temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001468 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001469 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001470
1471 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1472 ccn_charbuf_append_string(lsa_data,"|");
1473
1474 char *temp_nl=(char *)malloc(20);
1475 memset(temp_nl,0,20);
1476 sprintf(temp_nl,"%d",adj_lsa->no_link);
1477 ccn_charbuf_append_string(lsa_data,temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001478 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001479 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001480
1481 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1482
1483
1484 }
1485 else if(res == HT_NEW_ENTRY)
1486 {
1487 hashtb_delete(e);
1488 }
1489
1490 hashtb_end(e);
1491}
akmhoqueffacaa82012-09-13 17:48:30 -05001492
akmhoque3171d652012-11-13 11:44:33 -06001493void
1494make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id)
1495{
1496
1497 if ( nlsr->debugging )
1498 printf("make_name_lsa_invalid called \n");
1499 if ( nlsr->detailed_logging )
1500 writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n");
1501
1502
1503 char lst[2];
1504 memset(lst,0,2);
1505 sprintf(lst,"%d",ls_type);
1506
1507 char lsid[10];
1508 memset(lsid,0,10);
1509 sprintf(lsid,"%ld",ls_id);
1510
1511
1512 char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1513 memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1);
1514
1515
1516 make_name_lsa_key(key, np->name,ls_type,ls_id);
akmhoqueb77b95f2013-02-08 12:28:47 -06001517
1518 if ( nlsr->debugging )
1519 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001520
1521 struct nlsa *nlsa;
1522
1523 struct hashtb_enumerator ee;
1524 struct hashtb_enumerator *e = &ee;
1525
1526 int res;
1527
1528 hashtb_start(nlsr->lsdb->name_lsdb, e);
1529 res = hashtb_seek(e, key,strlen(key) , 0);
1530
1531 if( res == HT_OLD_ENTRY )
1532 {
1533 nlsa=e->data;
1534
1535 nlsa->header->isValid=0;
1536
1537 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1538 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1539 write_log_for_name_lsa(nlsa);
1540 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1541
1542 hashtb_delete(e);
1543 }
1544 else if( res == HT_NEW_ENTRY )
1545 {
1546 hashtb_delete(e);
1547 }
1548 hashtb_end(e);
1549
1550 if ( nlsr->debugging )
1551 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1552 if ( nlsr->detailed_logging )
1553 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1554
1555 set_new_lsdb_version();
1556
1557 if ( nlsr->debugging )
1558 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1559 if ( nlsr->detailed_logging )
1560 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1561
1562}
1563
akmhoque866c2222013-02-12 10:49:33 -06001564//int
1565//delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1566int
1567delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001568{
akmhoqueb77b95f2013-02-08 12:28:47 -06001569
akmhoque7b791452012-10-30 11:24:56 -05001570 if ( nlsr->debugging )
1571 printf("delete_name_lsa called \n");
1572 if ( nlsr->detailed_logging )
1573 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001574 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001575 if(flags == CCN_SCHEDULE_CANCEL)
1576 {
1577 return -1;
1578 }
1579
1580
1581
1582 nlsr_lock();
1583
akmhoque7b791452012-10-30 11:24:56 -05001584 if ( nlsr->debugging )
1585 printf("LSA Key: %s \n",(char *)ev->evdata);
1586 if ( nlsr->detailed_logging )
1587 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001588
1589 struct nlsa *nlsa;
1590
1591 struct hashtb_enumerator ee;
1592 struct hashtb_enumerator *e = &ee;
1593
1594 int res;
1595
1596 hashtb_start(nlsr->lsdb->name_lsdb, e);
1597 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1598
1599 if( res == HT_OLD_ENTRY )
1600 {
1601 nlsa=e->data;
akmhoque866c2222013-02-12 10:49:33 -06001602 */
1603 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
1604 /*
akmhoque9e9fc722012-09-26 14:03:25 -05001605 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1606 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1607 write_log_for_name_lsa(nlsa);
1608 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1609
akmhoqueda5b6832012-09-13 22:33:55 -05001610 hashtb_delete(e);
1611 }
akmhoque3cced642012-09-24 16:20:20 -05001612 else if( res == HT_NEW_ENTRY )
akmhoqueda5b6832012-09-13 22:33:55 -05001613 {
akmhoqueda5b6832012-09-13 22:33:55 -05001614 hashtb_delete(e);
1615 }
1616 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001617 */
akmhoqueda5b6832012-09-13 22:33:55 -05001618
akmhoque7b791452012-10-30 11:24:56 -05001619 if ( nlsr->debugging )
1620 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1621 if ( nlsr->detailed_logging )
1622 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1623
akmhoqueda5b6832012-09-13 22:33:55 -05001624 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001625
1626 if ( nlsr->debugging )
1627 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1628 if ( nlsr->detailed_logging )
1629 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001630
akmhoque866c2222013-02-12 10:49:33 -06001631 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001632
1633 return 0;
1634}
1635
akmhoque866c2222013-02-12 10:49:33 -06001636//int
1637//delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1638int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001639{
akmhoque866c2222013-02-12 10:49:33 -06001640
akmhoque7b791452012-10-30 11:24:56 -05001641 if ( nlsr->debugging )
1642 printf("delete_adj_lsa called \n");
1643 if ( nlsr->detailed_logging )
1644 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoque866c2222013-02-12 10:49:33 -06001645
1646 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001647 if(flags == CCN_SCHEDULE_CANCEL)
1648 {
1649 return -1;
1650 }
1651 nlsr_lock();
1652
akmhoque7b791452012-10-30 11:24:56 -05001653 if ( nlsr->debugging )
1654 printf("LSA Key: %s \n",(char *)ev->evdata);
1655 if ( nlsr->detailed_logging )
1656 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001657
akmhoque9e9fc722012-09-26 14:03:25 -05001658 struct alsa *alsa;
akmhoqueda5b6832012-09-13 22:33:55 -05001659 struct hashtb_enumerator ee;
1660 struct hashtb_enumerator *e = &ee;
1661 int res;
1662
1663 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1664 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1665
1666 if( res == HT_OLD_ENTRY )
1667 {
akmhoque9e9fc722012-09-26 14:03:25 -05001668 alsa=e->data;
1669 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1670 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1671 write_log_for_adj_lsa(alsa);
1672 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1673
akmhoqueda5b6832012-09-13 22:33:55 -05001674 hashtb_delete(e);
1675 }
1676 else if( res == HT_OLD_ENTRY )
1677 {
1678 hashtb_delete(e);
1679 }
1680 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001681 */
akmhoqueda5b6832012-09-13 22:33:55 -05001682
akmhoque7b791452012-10-30 11:24:56 -05001683 if ( nlsr->debugging )
1684 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1685 if ( nlsr->detailed_logging )
1686 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1687
akmhoqueda5b6832012-09-13 22:33:55 -05001688 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001689
1690 if ( nlsr->debugging )
1691 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1692 if ( nlsr->detailed_logging )
1693 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1694
akmhoqueda5b6832012-09-13 22:33:55 -05001695
1696 if ( !nlsr->is_route_calculation_scheduled)
1697 {
1698 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1699 nlsr->is_route_calculation_scheduled=1;
1700 }
1701
akmhoque866c2222013-02-12 10:49:33 -06001702 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001703
1704 return 0;
1705}
1706
akmhoqueffacaa82012-09-13 17:48:30 -05001707void
1708refresh_name_lsdb(void)
1709{
akmhoque7b791452012-10-30 11:24:56 -05001710 if ( nlsr->debugging )
1711 printf("refresh_name_lsdb called \n");
1712 if ( nlsr->detailed_logging )
1713 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001714
1715 char *time_stamp=(char *)malloc(20);
1716 memset(time_stamp,0,20);
1717 get_current_timestamp_micro(time_stamp);
1718
1719 long int lsa_life_time;
1720
1721 int i, name_lsdb_element;
1722 struct nlsa *name_lsa;
1723
1724 struct hashtb_enumerator ee;
1725 struct hashtb_enumerator *e = &ee;
1726
1727 hashtb_start(nlsr->lsdb->name_lsdb, e);
1728 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1729
1730 for(i=0;i<name_lsdb_element;i++)
1731 {
1732 name_lsa=e->data;
1733
1734 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001735 if ( nlsr->debugging )
1736 printf("LSA Life Time: %ld \n",lsa_life_time);
1737 if ( nlsr->detailed_logging )
1738 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001739
1740 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1741 {
1742 if ( lsa_life_time > nlsr->lsa_refresh_time )
1743 {
akmhoque14b3f342012-09-14 10:39:02 -05001744 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1745 {
akmhoque7b791452012-10-30 11:24:56 -05001746 if ( nlsr->debugging )
1747 printf("Own Name LSA need to be refrshed\n");
1748 if ( nlsr->detailed_logging )
1749 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001750
1751 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1752 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1753 write_log_for_name_lsa(name_lsa);
1754 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1755
1756
akmhoque14b3f342012-09-14 10:39:02 -05001757 char *current_time_stamp=(char *)malloc(20);
1758 memset(current_time_stamp,0,20);
1759 get_current_timestamp_micro(current_time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001760
akmhoque14b3f342012-09-14 10:39:02 -05001761 free(name_lsa->header->orig_time);
1762 name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1763 memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1764 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001765
1766 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1767 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1768 write_log_for_name_lsa(name_lsa);
1769 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001770
akmhoque14b3f342012-09-14 10:39:02 -05001771 free(current_time_stamp);
akmhoque866c2222013-02-12 10:49:33 -06001772
1773 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001774 }
1775 else
akmhoque866c2222013-02-12 10:49:33 -06001776 { /*
akmhoque14b3f342012-09-14 10:39:02 -05001777 char lst[2];
1778 memset(lst,0,2);
1779 sprintf(lst,"%d",name_lsa->header->ls_type);
1780
1781 char lsid[10];
1782 memset(lsid,0,10);
1783 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1784
akmhoque866c2222013-02-12 10:49:33 -06001785
akmhoque14b3f342012-09-14 10:39:02 -05001786 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1787 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1788
1789
1790 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 -05001791
1792 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001793 */
1794 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1795 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1796 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1797 write_log_for_name_lsa(name_lsa);
1798 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1799 hashtb_delete(e);
1800 i++;
akmhoque14b3f342012-09-14 10:39:02 -05001801 }
akmhoqueda5b6832012-09-13 22:33:55 -05001802
akmhoque7b791452012-10-30 11:24:56 -05001803 if ( nlsr->debugging )
1804 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1805 if ( nlsr->detailed_logging )
1806 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1807
akmhoqueda5b6832012-09-13 22:33:55 -05001808 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001809
1810 if ( nlsr->debugging )
1811 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1812 if ( nlsr->detailed_logging )
1813 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1814
1815
akmhoqueda5b6832012-09-13 22:33:55 -05001816
1817 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001818 }
1819 else
1820 {
1821 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001822 }
1823 }
1824 else
1825 {
1826 if ( lsa_life_time > nlsr->router_dead_interval )
1827 {
akmhoque7b791452012-10-30 11:24:56 -05001828 if ( nlsr->debugging )
1829 printf("Others Name LSA need to be deleted\n");
1830 if ( nlsr->detailed_logging )
1831 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001832
akmhoque866c2222013-02-12 10:49:33 -06001833 /*char lst[2];
akmhoqueda5b6832012-09-13 22:33:55 -05001834 memset(lst,0,2);
1835 sprintf(lst,"%d",name_lsa->header->ls_type);
1836
1837 char lsid[10];
1838 memset(lsid,0,10);
1839 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1840
1841
1842 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1843 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1844
1845
1846 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 -05001847
1848 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001849 */
1850 delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name);
1851 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1852 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1853 write_log_for_name_lsa(name_lsa);
1854 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1855 hashtb_delete(e);
1856 i++;
1857 }
1858 else
1859 {
1860 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001861 }
1862 }
akmhoque866c2222013-02-12 10:49:33 -06001863 /*else
1864 {
1865 hashtb_next(e);
1866 }*/
akmhoqueffacaa82012-09-13 17:48:30 -05001867 }
1868
1869 hashtb_end(e);
1870
1871 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001872
akmhoqueffacaa82012-09-13 17:48:30 -05001873
1874}
1875
akmhoqueda5b6832012-09-13 22:33:55 -05001876void
akmhoqueffacaa82012-09-13 17:48:30 -05001877refresh_adj_lsdb(void)
1878{
akmhoqueffacaa82012-09-13 17:48:30 -05001879
akmhoque7b791452012-10-30 11:24:56 -05001880 if ( nlsr->debugging )
1881 printf("refresh_adj_lsdb called \n");
1882 if ( nlsr->detailed_logging )
1883 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001884
akmhoqueffacaa82012-09-13 17:48:30 -05001885 char *time_stamp=(char *)malloc(20);
1886 memset(time_stamp,0,20);
1887 get_current_timestamp_micro(time_stamp);
1888
1889 long int lsa_life_time;
1890
1891 int i, adj_lsdb_element;
1892 struct alsa *adj_lsa;
1893
1894 struct hashtb_enumerator ee;
1895 struct hashtb_enumerator *e = &ee;
1896
1897 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1898 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1899
1900 for(i=0;i<adj_lsdb_element;i++)
1901 {
1902 adj_lsa=e->data;
1903
akmhoqueb77b95f2013-02-08 12:28:47 -06001904 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001905
1906 if ( nlsr->debugging )
1907 printf("LSA Life Time: %ld \n",lsa_life_time);
1908 if ( nlsr->detailed_logging )
1909 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001910
akmhoqueda5b6832012-09-13 22:33:55 -05001911 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1912 {
1913 if ( lsa_life_time > nlsr->lsa_refresh_time )
1914 {
akmhoque7b791452012-10-30 11:24:56 -05001915 if ( nlsr->debugging )
1916 printf("Own Adj LSA need to be refrshed\n");
1917 if ( nlsr->detailed_logging )
1918 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001919
akmhoquea98c2142012-10-25 15:22:24 -05001920 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1921 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1922 write_log_for_adj_lsa(adj_lsa);
1923 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1924
akmhoqueda5b6832012-09-13 22:33:55 -05001925 char *current_time_stamp=(char *)malloc(20);
1926 memset(current_time_stamp,0,20);
1927 get_current_timestamp_micro(current_time_stamp);
1928
1929 free(adj_lsa->header->orig_time);
1930 adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1931 memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1932 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1933
1934 free(current_time_stamp);
1935
akmhoquea98c2142012-10-25 15:22:24 -05001936 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1937 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1938 write_log_for_adj_lsa(adj_lsa);
1939 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001940
akmhoque7b791452012-10-30 11:24:56 -05001941 if ( nlsr->debugging )
1942 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1943 if ( nlsr->detailed_logging )
1944 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1945
akmhoqueda5b6832012-09-13 22:33:55 -05001946 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001947
1948 if ( nlsr->debugging )
1949 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1950 if ( nlsr->detailed_logging )
1951 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001952
1953 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001954
1955
akmhoqueda5b6832012-09-13 22:33:55 -05001956 }
akmhoque866c2222013-02-12 10:49:33 -06001957
1958 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001959 }
1960 else
1961 {
1962 if ( lsa_life_time > nlsr->router_dead_interval )
1963 {
akmhoque7b791452012-10-30 11:24:56 -05001964
1965 if ( nlsr->debugging )
1966 printf("Others Adj LSA need to be deleted\n");
1967 if ( nlsr->detailed_logging )
1968 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoque866c2222013-02-12 10:49:33 -06001969 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001970 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
1971 memset(key,0,adj_lsa->header->orig_router->length+2);
1972 make_adj_lsa_key(key,adj_lsa);
akmhoqueb77b95f2013-02-08 12:28:47 -06001973
akmhoqueda5b6832012-09-13 22:33:55 -05001974 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001975 */
1976
1977 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1978 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1979 write_log_for_adj_lsa(adj_lsa);
1980 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1981 delete_adj_lsa();
1982 hashtb_delete(e);
1983 i++;
1984
1985 }
1986 else
1987 {
1988 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001989 }
1990 }
1991
1992
1993
akmhoque866c2222013-02-12 10:49:33 -06001994 //hashtb_next(e);
akmhoqueffacaa82012-09-13 17:48:30 -05001995 }
1996
1997 hashtb_end(e);
1998
1999 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002000}
2001
akmhoqueb77b95f2013-02-08 12:28:47 -06002002
2003void
2004refresh_cor_lsdb(void)
2005{
2006
2007 if ( nlsr->debugging )
2008 printf("refresh_cor_lsdb called \n");
2009 if ( nlsr->detailed_logging )
2010 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n");
2011
2012 char *time_stamp=(char *)malloc(20);
2013 memset(time_stamp,0,20);
2014 get_current_timestamp_micro(time_stamp);
2015
2016 long int lsa_life_time;
2017
2018 int i, cor_lsdb_element;
2019 struct clsa *cor_lsa;
2020
2021 struct hashtb_enumerator ee;
2022 struct hashtb_enumerator *e = &ee;
2023
2024 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2025 cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb);
2026
2027 for(i=0;i<cor_lsdb_element;i++)
2028 {
2029 cor_lsa=e->data;
2030
2031 lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time);
2032
2033 if ( nlsr->debugging )
2034 printf("LSA Life Time: %ld \n",lsa_life_time);
2035 if ( nlsr->detailed_logging )
2036 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
2037
2038 if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0)
2039 {
2040 if ( lsa_life_time > nlsr->lsa_refresh_time )
2041 {
2042 if ( nlsr->debugging )
2043 printf("Own Cor LSA need to be refrshed\n");
2044 if ( nlsr->detailed_logging )
2045 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n");
2046
2047 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2048 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
2049 //write_log_for_adj_lsa(adj_lsa);
2050 //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2051
2052 char *current_time_stamp=(char *)malloc(20);
2053 memset(current_time_stamp,0,20);
2054 get_current_timestamp_micro(current_time_stamp);
2055
2056 free(cor_lsa->header->orig_time);
2057 cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
2058 memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
2059 memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
2060
2061 free(current_time_stamp);
2062
2063 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
2064 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
2065 //write_log_for_adj_lsa(adj_lsa);
2066 //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
2067
2068 if ( nlsr->debugging )
2069 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2070 if ( nlsr->detailed_logging )
2071 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2072
2073 set_new_lsdb_version();
2074
2075 if ( nlsr->debugging )
2076 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2077 if ( nlsr->detailed_logging )
2078 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
2079
2080 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06002081 }
2082
2083 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002084 }
2085 else
2086 {
2087 if ( lsa_life_time > nlsr->router_dead_interval )
2088 {
2089
2090 if ( nlsr->debugging )
2091 printf("Others Adj LSA need to be deleted\n");
2092 if ( nlsr->detailed_logging )
2093 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
2094
2095 hashtb_delete(e);
2096 i++;
2097 }
akmhoque866c2222013-02-12 10:49:33 -06002098 else
2099 {
2100 hashtb_next(e);
2101 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002102 }
2103
2104
akmhoque866c2222013-02-12 10:49:33 -06002105
akmhoqueb77b95f2013-02-08 12:28:47 -06002106 }
2107
2108 hashtb_end(e);
2109
2110 free(time_stamp);
2111}
2112
akmhoqueffacaa82012-09-13 17:48:30 -05002113int
2114refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
2115{
2116 if(flags == CCN_SCHEDULE_CANCEL)
2117 {
2118 return -1;
2119 }
2120
2121 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05002122
akmhoque7b791452012-10-30 11:24:56 -05002123 if ( nlsr->debugging )
2124 printf("refresh_lsdb called\n");
2125 if ( nlsr->detailed_logging )
2126 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002127
2128 refresh_name_lsdb();
2129 refresh_adj_lsdb();
akmhoque8876e982013-02-21 13:35:46 -06002130 //refresh_cor_lsdb();
akmhoqueffacaa82012-09-13 17:48:30 -05002131
akmhoqueffacaa82012-09-13 17:48:30 -05002132 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002133
akmhoqueffacaa82012-09-13 17:48:30 -05002134 nlsr_unlock();
2135 return 0;
2136}
akmhoqueb77b95f2013-02-08 12:28:47 -06002137
2138void
2139write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id)
2140{
2141 if ( nlsr->debugging )
2142 printf("write_adj_lsa_to_repo called\n");
2143 if ( nlsr->debugging )
2144 printf("Content Prefix: %s\n",repo_content_prefix);
2145
2146 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2147 get_adj_lsa_data(lsa_data,lsa_id);
2148 if ( nlsr->debugging )
akmhoque323b5e92013-02-21 13:55:15 -06002149 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002150
akmhoque0800eda2013-02-21 14:17:52 -06002151 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002152
akmhoque323b5e92013-02-21 13:55:15 -06002153
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
akmhoque0800eda2013-02-21 14:17:52 -06002171
akmhoque323b5e92013-02-21 13:55:15 -06002172
akmhoque0800eda2013-02-21 14:17:52 -06002173 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002174
akmhoque4f85aab2013-02-21 13:58:50 -06002175 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002176}
2177
2178
2179void
2180write_name_lsdb_to_repo(char *slice_prefix)
2181{
2182 int i, name_lsdb_element;
2183
2184 struct nlsa *name_lsa;
2185 struct hashtb_enumerator ee;
2186 struct hashtb_enumerator *e = &ee;
2187
2188 hashtb_start(nlsr->lsdb->name_lsdb, e);
2189 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
2190
2191 for(i=0;i<name_lsdb_element;i++)
2192 {
2193 name_lsa=e->data;
2194
2195 char lst[2];
2196 memset(lst,0,2);
2197 sprintf(lst,"%d",name_lsa->header->ls_type);
2198
2199 char lsid[10];
2200 memset(lsid,0,10);
2201 sprintf(lsid,"%ld",name_lsa->header->ls_id);
2202
2203
2204 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2205 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
2206
2207
2208 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
2209
2210 if ( nlsr->debugging )
2211 printf("Name LSA Key: %s \n",key);
2212
2213
2214 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);
2215 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);
2216 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);
2217
2218 if ( nlsr->debugging )
2219 printf("Name LSA Repo Key: %s \n",repo_key);
2220
2221 struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix));
2222 lsaid->name=(char *)malloc(strlen(key)+1);
2223 memset(lsaid->name, 0, strlen(key)+1);
2224 memcpy(lsaid->name,key,strlen(key));
2225 lsaid->length=strlen(key)+1;
2226
2227
2228 write_name_lsa_to_repo(repo_key, lsaid);
2229
2230 free(key);
2231 free(repo_key);
2232 free(lsaid->name);
2233 free(lsaid);
2234
2235 hashtb_next(e);
2236 }
2237
2238 hashtb_end(e);
2239
2240
2241}
2242
2243void
2244print_cor_lsa(struct clsa *cor_lsa)
2245{
2246 if ( nlsr->debugging )
2247 {
2248 printf("-----------Cor LSA Content---------------\n");
2249 printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name);
2250 printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length);
2251 printf(" LS Type : %d\n",cor_lsa->header->ls_type);
2252 printf(" Origination Time : %s\n",cor_lsa->header->orig_time);
2253 printf(" LSA Data \n");
2254 printf(" Cor R: : %f\n",cor_lsa->cor_r);
2255 printf(" Cor Theta : %f\n",cor_lsa->cor_theta);
2256
2257 printf("\n");
2258 }
2259}
2260
2261void
2262print_cor_lsdb()
2263{
2264
2265 if ( nlsr->debugging )
2266 printf("print_cor_lsdb called \n");
2267
2268 struct hashtb_enumerator ee;
2269 struct hashtb_enumerator *e = &ee;
2270
2271 int i=1;
2272
2273 for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e))
2274 {
2275 if ( nlsr->debugging )
2276 printf("-----------Cor LSA (%d)---------------\n",i);
2277 struct clsa *cor_lsa=e->data;
2278 print_cor_lsa(cor_lsa);
2279 i++;
2280 }
2281 hashtb_end(e);
2282
2283 if ( nlsr->debugging )
2284 printf("\n");
2285 if ( nlsr->detailed_logging )
2286 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
2287}
2288
2289void
2290install_cor_lsa(struct clsa *cor_lsa)
2291{
2292 if ( nlsr->debugging )
2293 printf("install_cor_lsa called \n");
2294 if ( nlsr->detailed_logging )
2295 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
2296
2297
2298 char *time_stamp=(char *)malloc(20);
2299 memset(time_stamp,0,20);
2300 get_current_timestamp_micro(time_stamp);
2301
2302
akmhoque569a93d2013-02-21 10:19:54 -06002303 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2304 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002305 make_cor_lsa_key(key,cor_lsa);
2306
2307 if ( nlsr->debugging )
2308 printf("Cor LSA key: %s \n",key);
2309
2310 struct hashtb_enumerator ee;
2311 struct hashtb_enumerator *e = &ee;
2312 int res;
2313
2314 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2315 res = hashtb_seek(e, key, strlen(key), 0);
2316
2317 if ( res == HT_NEW_ENTRY )
2318 {
2319 if ( nlsr->debugging )
2320 printf("New Cor LSA... \n");
2321
akmhoque8876e982013-02-21 13:35:46 -06002322 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002323 new_cor_lsa=e->data;
2324 new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2325
2326 new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2327 new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
2328 memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
2329 memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
2330 new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
2331
2332 new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free
2333 memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
2334 memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
2335
2336 new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
2337
2338 new_cor_lsa->cor_r=cor_lsa->cor_r;
2339 new_cor_lsa->cor_theta=cor_lsa->cor_theta;
2340 }
2341 else if ( res == HT_OLD_ENTRY )
2342 {
2343 if ( nlsr->debugging )
2344 printf("Cor LSA exists (Old)... \n");
2345 }
2346 hashtb_end(e);
2347
akmhoque569a93d2013-02-21 10:19:54 -06002348 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002349
2350}
2351
2352void
2353build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta)
2354{
2355 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2356 cor_lsa->header->ls_type=LS_TYPE_COR;
2357
2358 char *time_stamp=(char *)malloc(20);
2359 memset(time_stamp,0,20);
2360 get_current_timestamp_micro(time_stamp);
2361
2362 cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
2363 memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1);
2364 memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
2365 free(time_stamp);
2366
2367 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2368 cor_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
2369 memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
2370 memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
2371 cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
2372
2373 cor_lsa->cor_r=cor_r;
2374 cor_lsa->cor_theta=cor_theta;
2375
2376}
2377
2378void
2379build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta)
2380{
2381 cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
2382 cor_lsa->header->ls_type=ls_type;
2383
2384 cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
2385 memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002386 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002387
2388 cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
2389 cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
2390 memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1);
akmhoque569a93d2013-02-21 10:19:54 -06002391 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002392 cor_lsa->header->orig_router->length=strlen(orig_router)+1;
2393
2394 cor_lsa->cor_r=cor_r;
2395 cor_lsa->cor_theta=cor_theta;
2396
2397}
2398
2399void
2400build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta)
2401{
2402 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2403 build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta);
2404 install_cor_lsa(cor_lsa);
2405
2406 print_cor_lsdb();
akmhoque569a93d2013-02-21 10:19:54 -06002407
2408 free(cor_lsa->header->orig_router->name);
akmhoqueb77b95f2013-02-08 12:28:47 -06002409 free(cor_lsa->header->orig_router);
2410 free(cor_lsa->header->orig_time);
2411 free(cor_lsa->header);
2412 free(cor_lsa);
2413
2414}
2415
2416
2417void
2418build_and_install_cor_lsa()
2419{
2420
2421
2422
2423 struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa ));
2424
2425 build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta);
2426 install_cor_lsa(cor_lsa);
2427
2428 write_cor_lsa_to_repo(cor_lsa);
2429
2430 print_cor_lsdb();
2431
2432 free(cor_lsa->header->orig_router);
2433 free(cor_lsa->header->orig_time);
2434 free(cor_lsa->header);
2435 free(cor_lsa);
2436
2437}
2438
2439void
2440get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key)
2441{
2442 if ( nlsr->debugging )
2443 printf("get_cor_lsa_data called \n");
2444 if ( nlsr->detailed_logging )
2445 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
2446
2447 struct clsa *cor_lsa=(struct clsa*)malloc(sizeof(struct clsa ));
2448
2449 struct hashtb_enumerator ee;
2450 struct hashtb_enumerator *e = &ee;
2451 int res;
2452
2453 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2454 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2455
2456 if( res == HT_OLD_ENTRY )
2457 {
2458 cor_lsa=e->data;
2459
2460 if ( nlsr->debugging )
2461 printf("Cor LSA found \n");
2462 if ( nlsr->detailed_logging )
2463 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n");
2464
2465 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name);
2466 ccn_charbuf_append_string(lsa_data,"|");
2467
2468 char *temp_length=(char *)malloc(20);
2469 memset(temp_length,0,20);
2470 sprintf(temp_length,"%d",cor_lsa->header->orig_router->length);
2471 ccn_charbuf_append_string(lsa_data,temp_length);
2472 ccn_charbuf_append_string(lsa_data,"|");
2473 free(temp_length);
2474
2475 char *temp_ltype=(char *)malloc(20);
2476 memset(temp_ltype,0,20);
2477 sprintf(temp_ltype,"%d",cor_lsa->header->ls_type);
2478 ccn_charbuf_append_string(lsa_data,temp_ltype);
2479 ccn_charbuf_append_string(lsa_data,"|");
2480 free(temp_ltype);
2481
2482 ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time);
2483 ccn_charbuf_append_string(lsa_data,"|");
2484
2485 char *cor_r=(char *)malloc(20);
2486 memset(cor_r,0,20);
2487 sprintf(cor_r,"%f",cor_lsa->cor_r);
2488 ccn_charbuf_append_string(lsa_data,cor_r);
2489 ccn_charbuf_append_string(lsa_data,"|");
2490 free(cor_r);
2491
2492 char *cor_theta=(char *)malloc(20);
2493 memset(cor_theta,0,20);
2494 sprintf(cor_theta,"%f",cor_lsa->cor_theta);
2495 ccn_charbuf_append_string(lsa_data,cor_theta);
2496 ccn_charbuf_append_string(lsa_data,"|");
2497 free(cor_theta);
2498
2499 }
2500 else if(res == HT_NEW_ENTRY)
2501 {
2502 hashtb_delete(e);
2503 }
2504
2505 hashtb_end(e);
2506}
2507
2508void
2509write_cor_lsa_to_repo(struct clsa *cor_lsa)
2510{
2511
2512
2513 if ( nlsr->debugging )
2514 printf("write_cor_lsa_to_repo called\n");
2515
2516
2517 char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2);
2518 memset(key,0,cor_lsa->header->orig_router->length+2+2);
2519 make_cor_lsa_key(key,cor_lsa);
2520
2521 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
2522 get_cor_lsa_data(lsa_data,key);
akmhoque323b5e92013-02-21 13:55:15 -06002523
akmhoqueb77b95f2013-02-08 12:28:47 -06002524 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002525 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2526
akmhoqueb77b95f2013-02-08 12:28:47 -06002527 char *lst=(char *)malloc(20);
2528 memset(lst,0,20);
2529 sprintf(lst,"%d",cor_lsa->header->ls_type);
2530 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);
2531 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);
2532 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);
2533
2534 if ( nlsr->debugging )
2535 printf("Cor LSA Repo Key: %s \n",repo_key);
2536
akmhoque0800eda2013-02-21 14:17:52 -06002537 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
2538
akmhoqueb77b95f2013-02-08 12:28:47 -06002539
2540
2541
2542 free(lst);
2543 free(key);
2544 free(repo_key);
akmhoque4f85aab2013-02-21 13:58:50 -06002545 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002546}
2547
2548void
2549make_cor_lsa_key_by_router_name(char *key,char *router_name)
2550{
2551 memcpy(key+strlen(key),router_name,strlen(router_name));
2552 memcpy(key+strlen(key),"/",1);
2553 char ls_type[2];
2554 sprintf(ls_type,"%d",LS_TYPE_COR);
2555 memcpy(key+strlen(key),ls_type,strlen(ls_type));
2556 key[strlen(key)]='\0';
2557}
2558
2559
2560double
2561get_hyperbolic_r(char *router)
2562{
2563 double ret=-1.0;
2564 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2565 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2566
2567
2568 struct clsa *cor_lsa;
2569 struct hashtb_enumerator ee;
2570 struct hashtb_enumerator *e = &ee;
2571 int res;
2572
2573 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2574 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2575
2576 if ( res == HT_OLD_ENTRY)
2577 {
2578 cor_lsa=e->data;
2579 ret=cor_lsa->cor_r;
2580 }
2581 else if(res == HT_NEW_ENTRY)
2582 {
2583 hashtb_delete(e);
2584 }
2585
2586 hashtb_end(e);
2587
2588 free(cor_lsa_key);
2589 return ret;
2590}
2591
2592double
2593get_hyperbolic_theta(char *router)
2594{
2595 double ret=-1.0;
2596 char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char));
2597 make_cor_lsa_key_by_router_name(cor_lsa_key,router);
2598
2599 struct clsa *cor_lsa;
2600 struct hashtb_enumerator ee;
2601 struct hashtb_enumerator *e = &ee;
2602 int res;
2603
2604 hashtb_start(nlsr->lsdb->cor_lsdb, e);
2605 res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0);
2606
2607 if ( res == HT_OLD_ENTRY)
2608 {
2609 cor_lsa=e->data;
2610 ret=cor_lsa->cor_theta;
2611 }
2612 else if(res == HT_NEW_ENTRY)
2613 {
2614 hashtb_delete(e);
2615 }
2616
2617 hashtb_end(e);
2618
2619 free(cor_lsa_key);
2620 return ret;
2621}