blob: 5b30e70a6f527a789c2a6fa345c625286e39741a [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"
akmhoque438b07e2012-08-21 10:13:57 -040028
akmhoquef71d9082012-08-22 12:51:53 -040029void
akmhoque53f64222012-09-05 13:57:51 -050030set_new_lsdb_version(void)
akmhoquef71d9082012-08-22 12:51:53 -040031{
akmhoquef71d9082012-08-22 12:51:53 -040032
akmhoque03004e62012-09-06 01:12:28 -050033 char *time_stamp=(char *)malloc(20);
34 memset(time_stamp,0,20);
35 get_current_timestamp_micro(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040036
akmhoque03004e62012-09-06 01:12:28 -050037 free(nlsr->lsdb->lsdb_version);
38 nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
39 memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
40 memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
41
42 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050043
akmhoquef71d9082012-08-22 12:51:53 -040044}
45
akmhoque03004e62012-09-06 01:12:28 -050046void
47make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
48{
49
50
akmhoque7b791452012-10-30 11:24:56 -050051 //printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
akmhoque03004e62012-09-06 01:12:28 -050052
53 char lst[2];
54 memset(lst,0,2);
55 sprintf(lst,"%d",ls_type);
56
57 char lsid[10];
58 memset(lsid,0,10);
59 sprintf(lsid,"%ld",ls_id);
60
61 memcpy(key+strlen(key),orig_router,strlen(orig_router));
62 memcpy(key+strlen(key),"/",1);
63 memcpy(key+strlen(key),lst,strlen(lst));
64 memcpy(key+strlen(key),"/",1);
65 memcpy(key+strlen(key),lsid,strlen(lsid));
66
67 printf("Key: %s\n",key);
68
69}
akmhoque53f64222012-09-05 13:57:51 -050070
akmhoquef71d9082012-08-22 12:51:53 -040071void
akmhoque53f64222012-09-05 13:57:51 -050072build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -040073{
akmhoque7b791452012-10-30 11:24:56 -050074 if ( nlsr->debugging )
75 printf("build_and_install_name_lsas called \n");
76 if ( nlsr->detailed_logging )
77 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n");
akmhoquef71d9082012-08-22 12:51:53 -040078
akmhoquef71d9082012-08-22 12:51:53 -040079 int i, npl_element;
80 struct name_prefix *np;
81
82 struct hashtb_enumerator ee;
83 struct hashtb_enumerator *e = &ee;
84
85 hashtb_start(nlsr->npl, e);
86 npl_element=hashtb_n(nlsr->npl);
87
88 for(i=0;i<npl_element;i++)
89 {
90 np=e->data;
akmhoque53f64222012-09-05 13:57:51 -050091 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
92 build_name_lsa(name_lsa,np);
akmhoque03004e62012-09-06 01:12:28 -050093
akmhoquef71d9082012-08-22 12:51:53 -040094 install_name_lsa(name_lsa);
akmhoque03004e62012-09-06 01:12:28 -050095 free(name_lsa->header->orig_router->name);
96 free(name_lsa->header->orig_router);
97 free(name_lsa->header);
98 free(name_lsa->name_prefix->name);
99 free(name_lsa->name_prefix);
akmhoquef71d9082012-08-22 12:51:53 -0400100 free(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400101 hashtb_next(e);
102 }
103
akmhoque53f64222012-09-05 13:57:51 -0500104 hashtb_end(e);
akmhoquef71d9082012-08-22 12:51:53 -0400105
akmhoquef71d9082012-08-22 12:51:53 -0400106}
107
akmhoque53f64222012-09-05 13:57:51 -0500108void
109build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
110{
akmhoque53f64222012-09-05 13:57:51 -0500111 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
112 name_lsa->header->ls_type=LS_TYPE_NAME;
113
akmhoque03004e62012-09-06 01:12:28 -0500114 char *time_stamp=(char *)malloc(20);
115 memset(time_stamp,0,20);
116 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500117
akmhoque03004e62012-09-06 01:12:28 -0500118 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500119 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
120 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500121
122 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500123
124 name_lsa->header->ls_id=++nlsr->nlsa_id;
125 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500126 name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
127 memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
128 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
129 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500130 name_lsa->header->isValid=1;
131
132
133 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
134 name_lsa->name_prefix->name=(char *)malloc(np->length);
135 memcpy(name_lsa->name_prefix->name,np->name,np->length);
136 name_lsa->name_prefix->length=np->length;
137
138}
139
akmhoque53f64222012-09-05 13:57:51 -0500140void
141install_name_lsa(struct nlsa *name_lsa)
142{
akmhoque53f64222012-09-05 13:57:51 -0500143
akmhoqueffacaa82012-09-13 17:48:30 -0500144 char *time_stamp=(char *)malloc(20);
145 memset(time_stamp,0,20);
146 get_current_timestamp_micro(time_stamp);
akmhoque7b791452012-10-30 11:24:56 -0500147 //long int lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoqueffacaa82012-09-13 17:48:30 -0500148
akmhoque7b791452012-10-30 11:24:56 -0500149 //printf("time difference: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -0500150
151
152 char lst[2];
153 memset(lst,0,2);
154 sprintf(lst,"%d",name_lsa->header->ls_type);
155
156 char lsid[10];
157 memset(lsid,0,10);
158 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque03004e62012-09-06 01:12:28 -0500159
160
akmhoqueffacaa82012-09-13 17:48:30 -0500161 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
162 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
akmhoque03004e62012-09-06 01:12:28 -0500163
164
akmhoqueffacaa82012-09-13 17:48:30 -0500165 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
166 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque53f64222012-09-05 13:57:51 -0500167
akmhoqueffacaa82012-09-13 17:48:30 -0500168 struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
akmhoque53f64222012-09-05 13:57:51 -0500169
akmhoqueffacaa82012-09-13 17:48:30 -0500170 struct hashtb_enumerator ee;
171 struct hashtb_enumerator *e = &ee;
172 int res;
akmhoque53f64222012-09-05 13:57:51 -0500173
akmhoqueffacaa82012-09-13 17:48:30 -0500174 hashtb_start(nlsr->lsdb->name_lsdb, e);
175 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500176
akmhoqueffacaa82012-09-13 17:48:30 -0500177 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500178 {
akmhoqueffacaa82012-09-13 17:48:30 -0500179
akmhoque7b791452012-10-30 11:24:56 -0500180 if ( nlsr->debugging )
181 printf("New Name LSA... Adding to LSDB\n");
182 if ( nlsr->detailed_logging )
183 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n");
184
185
akmhoqueffacaa82012-09-13 17:48:30 -0500186 new_name_lsa = e->data;
187
188 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
189 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
190
191 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
192 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
193 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
194
195 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
196 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
197 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
198 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
199 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
200 new_name_lsa->header->isValid=name_lsa->header->isValid;
201
202
203 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
204 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
205 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
206 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
207
akmhoque7b791452012-10-30 11:24:56 -0500208 if ( nlsr->debugging )
209 {
210 printf("New Name LSA Added....\n");
211 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
212 }
213 if ( nlsr->detailed_logging )
214 {
215 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n");
216 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
217 }
akmhoqueffacaa82012-09-13 17:48:30 -0500218 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500219 if ( nlsr->debugging )
220 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
221 if ( nlsr->detailed_logging )
222 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500223
akmhoque9e9fc722012-09-26 14:03:25 -0500224
akmhoquede61ba92012-09-20 22:19:12 -0500225 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500226 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500227 {
akmhoquede61ba92012-09-20 22:19:12 -0500228 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 -0500229 if ( check == HT_NEW_ENTRY )
230 {
akmhoque7b791452012-10-30 11:24:56 -0500231 if ( nlsr->debugging )
232 printf("Added in npt \n");
233 if ( nlsr->detailed_logging )
234 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500235 }
akmhoque3560cb62012-09-09 10:52:30 -0500236 }
akmhoqueffacaa82012-09-13 17:48:30 -0500237 else
akmhoque3560cb62012-09-09 10:52:30 -0500238 {
akmhoquede61ba92012-09-20 22:19:12 -0500239 int *faces=malloc(num_next_hop*sizeof(int));
240 int *route_costs=malloc(num_next_hop*sizeof(int));
241 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500242 if ( nlsr->debugging )
243 {
244 printf("Printing from install_name_lsa \n");
245 int j;
246 for(j=0;j<num_next_hop;j++)
247 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
248 }
249 if ( nlsr->detailed_logging )
250 {
251 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
252 int j;
253 for(j=0;j<num_next_hop;j++)
254 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
255 }
akmhoquede61ba92012-09-20 22:19:12 -0500256 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 -0500257 if ( check == HT_NEW_ENTRY )
258 {
akmhoque7b791452012-10-30 11:24:56 -0500259 if ( nlsr->debugging )
260 printf("Added in npt \n");
261 if ( nlsr->detailed_logging )
262 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500263 }
akmhoquede61ba92012-09-20 22:19:12 -0500264 free(faces);
265 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500266
akmhoque3560cb62012-09-09 10:52:30 -0500267 }
akmhoquede61ba92012-09-20 22:19:12 -0500268
akmhoque9e9fc722012-09-26 14:03:25 -0500269 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
270 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
271 write_log_for_name_lsa(new_name_lsa);
272 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500273
akmhoquede61ba92012-09-20 22:19:12 -0500274 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -0500275
276 }
277 else if(res == HT_OLD_ENTRY)
278 {
279 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500280 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500281 {
akmhoque7b791452012-10-30 11:24:56 -0500282 if ( nlsr->debugging )
283 printf("Older Adj LSA. Discarded... \n");
284 if ( nlsr->detailed_logging )
285 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n");
akmhoque14b3f342012-09-14 10:39:02 -0500286 }
287 else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 )
288 {
akmhoque7b791452012-10-30 11:24:56 -0500289 if ( nlsr->debugging )
290 printf("Duplicate Adj LSA. Discarded... \n");
291 if ( nlsr->detailed_logging )
292 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500293 }
294 else
295 {
296 if ( name_lsa->header->isValid == 0 )
297 {
298 // have to call to delete npt table entry
akmhoque3cced642012-09-24 16:20:20 -0500299 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 -0500300
301 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
302 {
akmhoque9e9fc722012-09-26 14:03:25 -0500303 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
304 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
305 write_log_for_name_lsa(new_name_lsa);
306 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
307
akmhoqueffacaa82012-09-13 17:48:30 -0500308 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500309 if ( nlsr->debugging )
310 printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name);
311 if ( nlsr->detailed_logging )
312 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 -0500313 }
314 else
315 {
316 new_name_lsa->header->isValid=name_lsa->header->isValid;
317 free(new_name_lsa->header->orig_time);
318 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
319 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
320 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
321 }
akmhoque7b791452012-10-30 11:24:56 -0500322 if ( nlsr->debugging )
323 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
324 if ( nlsr->detailed_logging )
325 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500326 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500327 if ( nlsr->debugging )
328 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
329 if ( nlsr->detailed_logging )
330 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500331 }
332 else
333 {
334 int is_npt_update=0;
335 if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
336 {
337 is_npt_update=1;
akmhoque3cced642012-09-24 16:20:20 -0500338 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 -0500339 }
340
341 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500342 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
343 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
344 write_log_for_name_lsa(new_name_lsa);
345 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
346
akmhoqueffacaa82012-09-13 17:48:30 -0500347
348 free(new_name_lsa->header->orig_time);
349 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
350 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
351 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
352
353 new_name_lsa->header->isValid=name_lsa->header->isValid;
354
355 free(new_name_lsa->name_prefix->name);
356 free(new_name_lsa->name_prefix);
357 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
358 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
359 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
360 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
361
akmhoque9e9fc722012-09-26 14:03:25 -0500362
363 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
364 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
365 write_log_for_name_lsa(new_name_lsa);
366 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
367
akmhoque7b791452012-10-30 11:24:56 -0500368 if ( nlsr->debugging )
369 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
370 if ( nlsr->detailed_logging )
371 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
372
akmhoqueffacaa82012-09-13 17:48:30 -0500373 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500374
375 if ( nlsr->debugging )
376 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
377 if ( nlsr->detailed_logging )
378 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
379
akmhoqueffacaa82012-09-13 17:48:30 -0500380
381 if( is_npt_update == 1 )
382 {
akmhoquede61ba92012-09-20 22:19:12 -0500383 //struct hashtb *face_list;
384 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
385 if ( num_next_hop < 0 )
akmhoqueffacaa82012-09-13 17:48:30 -0500386 {
akmhoquede61ba92012-09-20 22:19:12 -0500387
388 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 -0500389 if ( check == HT_NEW_ENTRY )
390 {
akmhoque7b791452012-10-30 11:24:56 -0500391 if ( nlsr->debugging )
392 printf("Added in npt \n");
393 if ( nlsr->detailed_logging )
394 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500395 }
396 }
397 else
398 {
akmhoquede61ba92012-09-20 22:19:12 -0500399 int *faces=malloc(num_next_hop*sizeof(int));
400 int *route_costs=malloc(num_next_hop*sizeof(int));
401 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs);
akmhoque7b791452012-10-30 11:24:56 -0500402
403 if ( nlsr->debugging )
404 {
405 printf("Printing from install_name_lsa \n");
406 int j;
407 for(j=0;j<num_next_hop;j++)
akmhoquede61ba92012-09-20 22:19:12 -0500408 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500409 }
410 if ( nlsr->detailed_logging )
411 {
412 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n");
413 int j;
414 for(j=0;j<num_next_hop;j++)
415 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
416 }
417
akmhoquede61ba92012-09-20 22:19:12 -0500418
419 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 -0500420 if ( check == HT_NEW_ENTRY )
421 {
akmhoque7b791452012-10-30 11:24:56 -0500422 //printf("Added in npt \n");
423 if ( nlsr->debugging )
424 printf("Added in npt \n");
425 if ( nlsr->detailed_logging )
426 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500427 }
akmhoquede61ba92012-09-20 22:19:12 -0500428 free(faces);
429 free(route_costs);
430
akmhoqueffacaa82012-09-13 17:48:30 -0500431 }
akmhoquede61ba92012-09-20 22:19:12 -0500432
akmhoqueffacaa82012-09-13 17:48:30 -0500433 }
434 }
435 }
436
akmhoque3560cb62012-09-09 10:52:30 -0500437 }
akmhoque53f64222012-09-05 13:57:51 -0500438
akmhoqueffacaa82012-09-13 17:48:30 -0500439 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500440
akmhoqueffacaa82012-09-13 17:48:30 -0500441 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500442}
443
akmhoque9e9fc722012-09-26 14:03:25 -0500444void
445write_log_for_name_lsa(struct nlsa *name_lsa)
446{
447
448 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n");
449 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name);
450 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length);
akmhoque34b99f92012-09-27 12:24:27 -0500451 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type);
452 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id);
453 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time);
454 writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid);
akmhoque9e9fc722012-09-26 14:03:25 -0500455 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n");
456 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name);
457 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length);
458 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
459}
akmhoque53f64222012-09-05 13:57:51 -0500460
akmhoque03004e62012-09-06 01:12:28 -0500461void
462print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500463{
akmhoque53f64222012-09-05 13:57:51 -0500464
akmhoque7b791452012-10-30 11:24:56 -0500465 if ( nlsr->debugging )
466 {
467 printf("-----------Name LSA Content---------------\n");
468 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
469 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
470 printf(" LS Type : %d\n",name_lsa->header->ls_type);
471 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
472 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
473 printf(" Is Valid : %d\n",name_lsa->header->isValid);
474 printf(" LSA Data \n");
475 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
476 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
477
478 printf("\n");
479 }
akmhoquef71d9082012-08-22 12:51:53 -0400480}
481
482void
483print_name_lsdb(void)
484{
akmhoque7b791452012-10-30 11:24:56 -0500485 if ( nlsr->debugging )
486 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500487 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400488 struct nlsa *name_lsa;
489
490 struct hashtb_enumerator ee;
491 struct hashtb_enumerator *e = &ee;
492
493 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500494 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400495
akmhoque53f64222012-09-05 13:57:51 -0500496 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400497 {
akmhoque7b791452012-10-30 11:24:56 -0500498 if ( nlsr->debugging )
499 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400500 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500501 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400502 hashtb_next(e);
503 }
504
505 hashtb_end(e);
506
akmhoque53f64222012-09-05 13:57:51 -0500507 printf("\n");
508}
509
akmhoque03004e62012-09-06 01:12:28 -0500510
511void
512build_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 -0500513{
akmhoque7b791452012-10-30 11:24:56 -0500514 if ( nlsr->debugging )
515 printf("build_and_install_others_name_lsa called \n");
516 if ( nlsr->detailed_logging )
517 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500518
akmhoque03004e62012-09-06 01:12:28 -0500519 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
520 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
521 print_name_lsa(name_lsa);
522 install_name_lsa(name_lsa);
523 print_name_lsdb();
akmhoquede61ba92012-09-20 22:19:12 -0500524 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500525
akmhoque03004e62012-09-06 01:12:28 -0500526 free(name_lsa->header->orig_router->name);
527 free(name_lsa->header->orig_router);
528 free(name_lsa->header);
529 free(name_lsa->name_prefix->name);
530 free(name_lsa->name_prefix);
531 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500532
533}
534
535void
akmhoque03004e62012-09-06 01:12:28 -0500536build_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 -0500537{
akmhoque7b791452012-10-30 11:24:56 -0500538 if ( nlsr->debugging )
539 printf("build_others_name_lsa called\n");
540 if ( nlsr->detailed_logging )
541 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500542
akmhoque03004e62012-09-06 01:12:28 -0500543 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
544 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500545
akmhoque03004e62012-09-06 01:12:28 -0500546 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
547 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
548 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500549
akmhoque03004e62012-09-06 01:12:28 -0500550 name_lsa->header->ls_id=ls_id;
551 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
552 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
553 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
554 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
555 name_lsa->header->orig_router->length=strlen(orig_router)+1;
556 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500557
akmhoque03004e62012-09-06 01:12:28 -0500558 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
559 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
560 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
561 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
562 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400563}
akmhoqued79438d2012-08-27 13:31:42 -0500564
565
akmhoqueffacaa82012-09-13 17:48:30 -0500566
567
akmhoque53f64222012-09-05 13:57:51 -0500568void
569make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500570{
akmhoque53f64222012-09-05 13:57:51 -0500571 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
572 memcpy(key+strlen(key),"/",1);
573 char ls_type[2];
574 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
575 memcpy(key+strlen(key),ls_type,strlen(ls_type));
576 key[strlen(key)]='\0';
577}
578
akmhoque03004e62012-09-06 01:12:28 -0500579int
580build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
581{
akmhoqueffacaa82012-09-13 17:48:30 -0500582 if(flags == CCN_SCHEDULE_CANCEL)
583 {
584 return -1;
585 }
586
587 nlsr_lock();
588
akmhoque7b791452012-10-30 11:24:56 -0500589 if ( nlsr->debugging )
590 printf("build_and_install_adj_lsa called \n");
591 if ( nlsr->detailed_logging )
592 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n");
593
594 if ( nlsr->debugging )
595 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
596 if ( nlsr->detailed_logging )
597 writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag);
akmhoque03004e62012-09-06 01:12:28 -0500598
599 if(nlsr->adj_build_flag > 0)
600 {
akmhoque7b791452012-10-30 11:24:56 -0500601 if ( nlsr->debugging )
602 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
603 if ( nlsr->detailed_logging )
604 writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build());
605
akmhoque03004e62012-09-06 01:12:28 -0500606 if ( is_adj_lsa_build()> 0)
607 {
608 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
609 build_adj_lsa(adj_lsa);
610 install_adj_lsa(adj_lsa);
611
612 free(adj_lsa->header->orig_router->name);
613 free(adj_lsa->header->orig_router);
614 free(adj_lsa->header->orig_time);
615 free(adj_lsa->header);
616 free(adj_lsa->body);
617 free(adj_lsa);
618 nlsr->adj_build_flag=0;
619 print_adj_lsdb();
620 }
621 else
622 {
akmhoque7b791452012-10-30 11:24:56 -0500623 if ( nlsr->debugging )
624 printf("Can not build adj LSA now\n");
625 if ( nlsr->detailed_logging )
626 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n");
akmhoque03004e62012-09-06 01:12:28 -0500627 }
628 }
629 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500630
631 nlsr_unlock();
632
akmhoque03004e62012-09-06 01:12:28 -0500633 return 0;
634}
635
636
637void
638build_adj_lsa(struct alsa * adj_lsa)
639{
akmhoque7b791452012-10-30 11:24:56 -0500640 if ( nlsr->debugging )
641 printf("build_adj_lsa called \n");
642 if ( nlsr->detailed_logging )
643 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500644
645 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500646
647 //printf("Number of link in Adjacent LSA: %d\n",no_link);
akmhoque03004e62012-09-06 01:12:28 -0500648
649 /*Filling Up Header Data */
650 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
651 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
652 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
653 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
654 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
655 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
656
657 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
658
659 char *time_stamp=(char *)malloc(20);
660 memset(time_stamp,0,20);
661 get_current_timestamp_micro(time_stamp);
662
663 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
664 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
665 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
666 free(time_stamp);
667
668
669 /* Filling Up Body Data */
670
671 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500672
673
674 struct ccn_charbuf *c=ccn_charbuf_create();
675 get_active_nbr_adj_data(c);
676 char *data=ccn_charbuf_as_string(c);
677
678 adj_lsa->body=(char *)malloc(strlen(data)+1);
679 memset(adj_lsa->body,0,strlen(data)+1);
680 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
681 ccn_charbuf_destroy(&c);
682
683
684
685 if( !nlsr->is_send_lsdb_interest_scheduled )
686 {
687 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
688 nlsr->is_send_lsdb_interest_scheduled=1;
689 }
690
691 nlsr->adj_build_count++;
692
693
694}
695
696
akmhoque53f64222012-09-05 13:57:51 -0500697void
698install_adj_lsa(struct alsa * adj_lsa)
699{
akmhoqued79438d2012-08-27 13:31:42 -0500700
akmhoque7b791452012-10-30 11:24:56 -0500701 if ( nlsr->debugging )
702 printf("install_adj_lsa called \n");
703 if ( nlsr->detailed_logging )
704 writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n");
705
akmhoque03004e62012-09-06 01:12:28 -0500706
akmhoqueffacaa82012-09-13 17:48:30 -0500707 char *time_stamp=(char *)malloc(20);
708 memset(time_stamp,0,20);
709 get_current_timestamp_micro(time_stamp);
akmhoque7b791452012-10-30 11:24:56 -0500710 //long int lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque53f64222012-09-05 13:57:51 -0500711
akmhoque7b791452012-10-30 11:24:56 -0500712 //printf("time difference: %ld \n",lsa_life_time);
akmhoque53f64222012-09-05 13:57:51 -0500713
akmhoqueffacaa82012-09-13 17:48:30 -0500714
715 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
716 memset(key,0,adj_lsa->header->orig_router->length+2);
717 make_adj_lsa_key(key,adj_lsa);
akmhoque7b791452012-10-30 11:24:56 -0500718 //printf("Adjacent LSA key: %s \n",key);
akmhoqueffacaa82012-09-13 17:48:30 -0500719
720 struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
721
722 struct hashtb_enumerator ee;
723 struct hashtb_enumerator *e = &ee;
724 int res;
725
726 hashtb_start(nlsr->lsdb->adj_lsdb, e);
727 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500728
akmhoque03004e62012-09-06 01:12:28 -0500729
akmhoque53f64222012-09-05 13:57:51 -0500730
akmhoque62c0c192012-09-24 07:49:25 -0500731 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500732 {
akmhoque62c0c192012-09-24 07:49:25 -0500733 if ( adj_lsa->no_link > 0)
734 {
735 printf("New ADJ LSA... Adding to LSDB\n");
736 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500737
akmhoque62c0c192012-09-24 07:49:25 -0500738 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
739 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
740 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
741 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 -0500742
akmhoque62c0c192012-09-24 07:49:25 -0500743 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
744 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
745 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
746 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500747
akmhoque62c0c192012-09-24 07:49:25 -0500748 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500749
akmhoque62c0c192012-09-24 07:49:25 -0500750 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
751 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
752 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
753
754 add_next_hop_router(new_adj_lsa->header->orig_router->name);
755 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500756
757 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
758 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
759 write_log_for_adj_lsa(new_adj_lsa);
760 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500761 }
762 else
763 {
764 hashtb_delete(e);
765 }
akmhoque53f64222012-09-05 13:57:51 -0500766
akmhoque7b791452012-10-30 11:24:56 -0500767 if ( nlsr->debugging )
768 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
769 if ( nlsr->detailed_logging )
770 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
771
akmhoque53f64222012-09-05 13:57:51 -0500772 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500773
774 if ( nlsr->debugging )
775 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
776 if ( nlsr->detailed_logging )
777 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
778
akmhoqueffacaa82012-09-13 17:48:30 -0500779 }
780 else if(res == HT_OLD_ENTRY)
781 {
782 new_adj_lsa = e->data;
783 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
784 {
akmhoque7b791452012-10-30 11:24:56 -0500785 if ( nlsr->debugging )
786 printf("Older/Duplicate Adj LSA. Discarded...\n");
787 if ( nlsr->detailed_logging )
788 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500789 }
790 else
791 {
akmhoqueffacaa82012-09-13 17:48:30 -0500792
akmhoque62c0c192012-09-24 07:49:25 -0500793 if ( adj_lsa->no_link > 0)
794 {
akmhoque9e9fc722012-09-26 14:03:25 -0500795 //new_adj_lsa = e->data;
796
797 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
798 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
799 write_log_for_adj_lsa(new_adj_lsa);
800 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500801
akmhoque62c0c192012-09-24 07:49:25 -0500802 free(new_adj_lsa->header->orig_time);
803 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
804 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
805
806 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500807
akmhoque62c0c192012-09-24 07:49:25 -0500808 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
809 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
810 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500811
akmhoque62c0c192012-09-24 07:49:25 -0500812 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500813
814 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
815 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
816 write_log_for_adj_lsa(new_adj_lsa);
817 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoque62c0c192012-09-24 07:49:25 -0500818 }
819 else
820 {
akmhoque9e9fc722012-09-26 14:03:25 -0500821 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
822 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
823 write_log_for_adj_lsa(new_adj_lsa);
824 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
825
akmhoque62c0c192012-09-24 07:49:25 -0500826 hashtb_delete(e);
827 }
akmhoque7b791452012-10-30 11:24:56 -0500828
829 if ( nlsr->debugging )
830 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
831 if ( nlsr->detailed_logging )
832 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
833
akmhoqueffacaa82012-09-13 17:48:30 -0500834 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500835
836 if ( nlsr->debugging )
837 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
838 if ( nlsr->detailed_logging )
839 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueffacaa82012-09-13 17:48:30 -0500840 }
841
842 }
843 hashtb_end(e);
844
845 if ( !nlsr->is_route_calculation_scheduled )
846 {
847 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
848 nlsr->is_route_calculation_scheduled=1;
akmhoque53f64222012-09-05 13:57:51 -0500849 }
850
akmhoque03004e62012-09-06 01:12:28 -0500851
akmhoqueffacaa82012-09-13 17:48:30 -0500852 free(key);
853
854 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500855}
856
857void
akmhoque9e9fc722012-09-26 14:03:25 -0500858write_log_for_adj_lsa_body(const char *body, int no_link)
859{
860 int i=0;
861 char *lsa_data=(char *)malloc(strlen(body)+1);
862 memset( lsa_data,0,strlen(body)+1);
863 memcpy(lsa_data,body,strlen(body)+1);
864 char *sep="|";
865 char *rem;
866 char *rtr_id;
867 char *length;
868 char *face;
869 char *metric;
870
871 if(no_link >0 )
872 {
873 rtr_id=strtok_r(lsa_data,sep,&rem);
874 length=strtok_r(NULL,sep,&rem);
875 face=strtok_r(NULL,sep,&rem);
876 metric=strtok_r(NULL,sep,&rem);
877
878 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -0500879 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
880 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
881 writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
882 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -0500883
884
885 for(i=1;i<no_link;i++)
886 {
887 rtr_id=strtok_r(NULL,sep,&rem);
888 length=strtok_r(NULL,sep,&rem);
889 face=strtok_r(NULL,sep,&rem);
890 metric=strtok_r(NULL,sep,&rem);
891 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -0500892 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
893 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
894 writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
895 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -0500896
897 }
898 }
899
900 free(lsa_data);
901}
902
903
904void
905write_log_for_adj_lsa(struct alsa * adj_lsa)
906{
907 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -0500908 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name);
909 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
910 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type);
911 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time);
akmhoque9e9fc722012-09-26 14:03:25 -0500912 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -0500913 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500914
915 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
916
917 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
918
919}
920
921void
akmhoque53f64222012-09-05 13:57:51 -0500922print_adj_lsa_body(const char *body, int no_link)
923{
924 int i=0;
925 char *lsa_data=(char *)malloc(strlen(body)+1);
926 memset( lsa_data,0,strlen(body)+1);
927 memcpy(lsa_data,body,strlen(body)+1);
928 char *sep="|";
929 char *rem;
930 char *rtr_id;
931 char *length;
932 char *face;
933 char *metric;
934
akmhoque53f64222012-09-05 13:57:51 -0500935 if(no_link >0 )
936 {
937 rtr_id=strtok_r(lsa_data,sep,&rem);
938 length=strtok_r(NULL,sep,&rem);
939 face=strtok_r(NULL,sep,&rem);
940 metric=strtok_r(NULL,sep,&rem);
941
942 printf(" Link %d \n",i+1);
943 printf(" Neighbor : %s \n",rtr_id);
944 printf(" Neighbor Length : %s \n",length);
945 printf(" Connecting Face : %s \n",face);
946 printf(" Metric : %s \n",metric);
akmhoque03004e62012-09-06 01:12:28 -0500947
akmhoque53f64222012-09-05 13:57:51 -0500948
949 for(i=1;i<no_link;i++)
950 {
951 rtr_id=strtok_r(NULL,sep,&rem);
952 length=strtok_r(NULL,sep,&rem);
953 face=strtok_r(NULL,sep,&rem);
954 metric=strtok_r(NULL,sep,&rem);
955 printf(" Link %d \n",i+1);
956 printf(" Neighbor : %s \n",rtr_id);
957 printf(" Neighbor Length : %s \n",length);
958 printf(" Connecting Face : %s \n",face);
959 printf(" Metric : %s \n",metric);
960
961 }
962 }
963
964 free(lsa_data);
965}
966
967void
968print_adj_lsa(struct alsa * adj_lsa)
969{
akmhoque7b791452012-10-30 11:24:56 -0500970 if ( nlsr->debugging )
971 {
972 printf("-----------ADJ LSA Content---------------\n");
973 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
974 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
975 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
976 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
977 printf(" Lsa Data:\n");
978 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500979
akmhoque7b791452012-10-30 11:24:56 -0500980 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
981 printf("\n");
982 }
akmhoque53f64222012-09-05 13:57:51 -0500983
984}
985
986void
987print_adj_lsdb(void)
988{
akmhoque7b791452012-10-30 11:24:56 -0500989 if ( nlsr->debugging )
990 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500991 int i, adj_lsdb_element;
992 struct alsa *adj_lsa;
993
994 struct hashtb_enumerator ee;
995 struct hashtb_enumerator *e = &ee;
996
997 hashtb_start(nlsr->lsdb->adj_lsdb, e);
998 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
999
1000 for(i=0;i<adj_lsdb_element;i++)
1001 {
akmhoque7b791452012-10-30 11:24:56 -05001002 if ( nlsr->debugging )
1003 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001004 adj_lsa=e->data;
1005 print_adj_lsa(adj_lsa);
1006 hashtb_next(e);
1007 }
1008
1009 hashtb_end(e);
1010
1011 printf("\n");
akmhoque53f64222012-09-05 13:57:51 -05001012}
1013
1014void
akmhoque03004e62012-09-06 01:12:28 -05001015build_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 -05001016{
akmhoque7b791452012-10-30 11:24:56 -05001017 if ( nlsr->debugging )
1018 printf("build_and_install_others_adj_lsa called \n");
1019 if ( nlsr->detailed_logging )
1020 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -05001021 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
1022 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
1023 //print_adj_lsa(adj_lsa);
1024 install_adj_lsa(adj_lsa);
1025
akmhoque53f64222012-09-05 13:57:51 -05001026
akmhoque03004e62012-09-06 01:12:28 -05001027 free(adj_lsa->header->orig_router->name);
1028 free(adj_lsa->header->orig_router);
1029 free(adj_lsa->header->orig_time);
1030 free(adj_lsa->header);
1031 free(adj_lsa->body);
1032 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -05001033
akmhoque03004e62012-09-06 01:12:28 -05001034 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001035
akmhoque53f64222012-09-05 13:57:51 -05001036}
1037
akmhoque03004e62012-09-06 01:12:28 -05001038
akmhoque53f64222012-09-05 13:57:51 -05001039void
akmhoque03004e62012-09-06 01:12:28 -05001040build_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 -05001041{
akmhoque7b791452012-10-30 11:24:56 -05001042 //printf("build_others_adj_lsa called \n");
1043 if ( nlsr->debugging )
1044 printf("build_others_adj_lsa called \n");
1045 if ( nlsr->detailed_logging )
1046 writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -05001047
akmhoque03004e62012-09-06 01:12:28 -05001048 /*Filling Up Header Data */
1049 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
1050 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1051 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
1052 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
1053 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -05001054
akmhoque03004e62012-09-06 01:12:28 -05001055 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001056
akmhoque53f64222012-09-05 13:57:51 -05001057
akmhoque03004e62012-09-06 01:12:28 -05001058 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001059
akmhoque03004e62012-09-06 01:12:28 -05001060 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
1061 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
1062 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -05001063
akmhoque03004e62012-09-06 01:12:28 -05001064 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001065
akmhoque03004e62012-09-06 01:12:28 -05001066 adj_lsa->body=(char *)malloc(strlen(data)+1);
1067 memset(adj_lsa->body,0,strlen(data)+1);
1068 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -05001069
akmhoque53f64222012-09-05 13:57:51 -05001070}
1071
akmhoque03004e62012-09-06 01:12:28 -05001072
akmhoque53f64222012-09-05 13:57:51 -05001073long int
1074get_name_lsdb_num_element(void)
1075{
1076 long int num_element;
1077
1078
1079 struct hashtb_enumerator ee;
1080 struct hashtb_enumerator *e = &ee;
1081
1082 hashtb_start(nlsr->lsdb->name_lsdb, e);
1083 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
1084 hashtb_end(e);
1085
1086 return num_element;
1087}
1088
1089long int
1090get_adj_lsdb_num_element(void)
1091{
1092 long int num_element;
1093
1094
1095 struct hashtb_enumerator ee;
1096 struct hashtb_enumerator *e = &ee;
1097
1098 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1099 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1100 hashtb_end(e);
1101
1102 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -05001103}
akmhoque03004e62012-09-06 01:12:28 -05001104
1105void
1106get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
1107{
akmhoque7b791452012-10-30 11:24:56 -05001108 //printf("get_name_lsdb_summary called \n");
1109 if ( nlsr->debugging )
1110 printf("get_name_lsdb_summary called \n");
1111 if ( nlsr->detailed_logging )
1112 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsdb_summary called \n");
1113
akmhoque03004e62012-09-06 01:12:28 -05001114 int i, name_lsdb_element;
1115
1116 struct nlsa *name_lsa;
1117 struct hashtb_enumerator ee;
1118 struct hashtb_enumerator *e = &ee;
1119
1120 hashtb_start(nlsr->lsdb->name_lsdb, e);
1121 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1122
1123 for(i=0;i<name_lsdb_element;i++)
1124 {
1125 name_lsa=e->data;
1126
1127 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name);
1128 ccn_charbuf_append_string(name_lsdb_data,"|");
1129
1130 char *lst=(char *)malloc(20);
1131 memset(lst,0,20);
1132 sprintf(lst,"%d",name_lsa->header->ls_type);
1133 ccn_charbuf_append_string(name_lsdb_data,lst);
1134 free(lst);
1135 ccn_charbuf_append_string(name_lsdb_data,"|");
1136
1137 char *lsid=(char *)malloc(20);
1138 memset(lsid,0,20);
1139 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1140 ccn_charbuf_append_string(name_lsdb_data,lsid);
1141 free(lsid);
1142 ccn_charbuf_append_string(name_lsdb_data,"|");
1143
1144 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time);
1145 ccn_charbuf_append_string(name_lsdb_data,"|");
1146
1147 hashtb_next(e);
1148 }
1149
1150 hashtb_end(e);
1151
1152}
1153
1154
1155void
1156get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data)
1157{
akmhoque7b791452012-10-30 11:24:56 -05001158 if ( nlsr->debugging )
1159 printf("get_adj_lsdb_summary called \n");
1160 if ( nlsr->detailed_logging )
1161 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsdb_summary called \n");
akmhoque03004e62012-09-06 01:12:28 -05001162 int i, adj_lsdb_element;
1163 struct alsa *adj_lsa;
1164
1165 struct hashtb_enumerator ee;
1166 struct hashtb_enumerator *e = &ee;
1167
1168 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1169 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1170
1171 for(i=0;i<adj_lsdb_element;i++)
1172 {
1173 adj_lsa=e->data;
1174
1175 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name);
1176 ccn_charbuf_append_string(adj_lsdb_data,"|");
1177
1178 char *lst=(char *)malloc(20);
1179 memset(lst,0,20);
1180 sprintf(lst,"%d",adj_lsa->header->ls_type);
1181 ccn_charbuf_append_string(adj_lsdb_data,lst);
1182 free(lst);
1183 ccn_charbuf_append_string(adj_lsdb_data,"|");
1184
1185 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time);
1186 ccn_charbuf_append_string(adj_lsdb_data,"|");
1187
1188 hashtb_next(e);
1189 }
1190
1191 hashtb_end(e);
1192}
1193
1194
1195void
1196get_lsdb_summary(struct ccn_charbuf *lsdb_data)
1197{
1198 struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create();
1199 struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create();
1200
1201 get_name_lsdb_summary(name_lsdb_data);
1202 get_adj_lsdb_summary(adj_lsdb_data);
1203
1204 long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element();
1205 char *num_element=(char *)malloc(15);
1206 memset(num_element,0,15);
1207 sprintf(num_element,"%ld",num_lsa);
1208
1209 if( num_lsa > 0)
1210 {
1211 ccn_charbuf_append_string(lsdb_data,num_element);
1212 ccn_charbuf_append_string(lsdb_data,"|");
1213 }
1214 if(name_lsdb_data->length>0)
1215 {
1216 char *data1=ccn_charbuf_as_string(name_lsdb_data);
1217 ccn_charbuf_append_string(lsdb_data,(char *)data1);
1218 }
1219 if(adj_lsdb_data->length>0)
1220 {
1221 char *data2=ccn_charbuf_as_string(adj_lsdb_data);
1222 ccn_charbuf_append_string(lsdb_data,(char *)data2);
1223 }
1224 ccn_charbuf_destroy(&name_lsdb_data);
1225 ccn_charbuf_destroy(&adj_lsdb_data);
1226 free(num_element);
1227
1228}
1229
1230int
1231check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
1232{
1233 int ret=0;
1234 struct ccn_charbuf *key=ccn_charbuf_create();
1235 ccn_charbuf_append_string(key,orig_router);
1236 ccn_charbuf_append_string(key,"/");
1237 ccn_charbuf_append_string(key,lst);
1238 ccn_charbuf_append_string(key,"/");
1239 ccn_charbuf_append_string(key,lsid);
1240
1241 int res;
1242 struct nlsa *name_lsa;
1243
1244 struct hashtb_enumerator ee;
1245 struct hashtb_enumerator *e = &ee;
1246
1247 hashtb_start(nlsr->lsdb->name_lsdb, e);
1248 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1249
1250 if( res == HT_NEW_ENTRY )
1251 {
1252 hashtb_delete(e);
1253 ret=1;
1254
1255 }
1256 else if(res == HT_OLD_ENTRY)
1257 {
1258 name_lsa=e->data;
1259 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
1260 {
1261 ret=1;
1262 }
1263 }
1264
1265 hashtb_end(e);
1266
1267 ccn_charbuf_destroy(&key);
1268
1269 return ret;
1270}
1271
1272int
1273check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
1274{
1275 int ret=0;
1276 struct ccn_charbuf *key=ccn_charbuf_create();
1277 ccn_charbuf_append_string(key,orig_router);
1278 ccn_charbuf_append_string(key,"/");
1279 ccn_charbuf_append_string(key,lst);
1280
1281 int res;
1282 struct alsa *adj_lsa;
1283
1284 struct hashtb_enumerator ee;
1285 struct hashtb_enumerator *e = &ee;
1286
1287 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1288 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
1289
1290 if( res == HT_NEW_ENTRY )
1291 {
1292 hashtb_delete(e);
1293 ret=1;
1294
1295 }
1296 else if(res == HT_OLD_ENTRY)
1297 {
1298 adj_lsa=e->data;
1299 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
1300 {
1301 ret=1;
1302 }
1303 }
1304
1305 hashtb_end(e);
1306
1307 ccn_charbuf_destroy(&key);
1308
1309 return ret;
1310}
1311
1312void
1313get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1314{
akmhoque7b791452012-10-30 11:24:56 -05001315 //printf("get_name_lsa_data called \n");
1316 if ( nlsr->debugging )
1317 printf("get_name_lsa_data called \n");
1318 if ( nlsr->detailed_logging )
1319 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001320
1321 struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
1322
1323 struct hashtb_enumerator ee;
1324 struct hashtb_enumerator *e = &ee;
1325 int res;
1326
1327 hashtb_start(nlsr->lsdb->name_lsdb, e);
1328 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1329
1330 if( res == HT_OLD_ENTRY )
1331 {
1332 name_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001333 //printf("NAME LSA found\n");
1334
1335 if ( nlsr->debugging )
1336 printf("NAME LSA found \n");
1337 if ( nlsr->detailed_logging )
1338 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001339
1340 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
1341 ccn_charbuf_append_string(lsa_data,"|");
1342
1343 char *temp_length=(char *)malloc(20);
1344 memset(temp_length,0,20);
1345 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
1346 ccn_charbuf_append_string(lsa_data,temp_length);
1347 free(temp_length);
1348 ccn_charbuf_append_string(lsa_data,"|");
1349
1350 char *temp_ltype=(char *)malloc(20);
1351 memset(temp_ltype,0,20);
1352 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
1353 ccn_charbuf_append_string(lsa_data,temp_ltype);
1354 free(temp_ltype);
1355 ccn_charbuf_append_string(lsa_data,"|");
1356
1357 char *temp_lsid=(char *)malloc(20);
1358 memset(temp_lsid,0,20);
1359 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
1360 ccn_charbuf_append_string(lsa_data,temp_lsid);
1361 free(temp_lsid);
1362 ccn_charbuf_append_string(lsa_data,"|");
1363
1364 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
1365 ccn_charbuf_append_string(lsa_data,"|");
1366
1367 char *temp_valid=(char *)malloc(20);
1368 memset(temp_valid,0,20);
1369 sprintf(temp_valid,"%d",name_lsa->header->isValid);
1370 ccn_charbuf_append_string(lsa_data,temp_valid);
1371 free(temp_valid);
1372 ccn_charbuf_append_string(lsa_data,"|");
1373
1374 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
1375 ccn_charbuf_append_string(lsa_data,"|");
1376
1377 char *temp_npl=(char *)malloc(20);
1378 memset(temp_npl,0,20);
1379 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
1380 ccn_charbuf_append_string(lsa_data,temp_npl);
1381 free(temp_npl);
1382 ccn_charbuf_append_string(lsa_data,"|");
1383
1384 }
1385 else if(res == HT_NEW_ENTRY)
1386 {
1387 hashtb_delete(e);
1388 }
1389
1390 hashtb_end(e);
1391}
1392
1393void
1394get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1395{
akmhoque7b791452012-10-30 11:24:56 -05001396 if ( nlsr->debugging )
1397 printf("get_adj_lsa_data called \n");
1398 if ( nlsr->detailed_logging )
1399 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
akmhoque03004e62012-09-06 01:12:28 -05001400
1401 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
1402
1403 struct hashtb_enumerator ee;
1404 struct hashtb_enumerator *e = &ee;
1405 int res;
1406
1407 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1408 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1409
1410 if( res == HT_OLD_ENTRY )
1411 {
1412 adj_lsa=e->data;
akmhoque7b791452012-10-30 11:24:56 -05001413 //printf("Adj LSA found\n");
1414
1415 if ( nlsr->debugging )
1416 printf("Adj LSA found \n");
1417 if ( nlsr->detailed_logging )
1418 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001419
1420 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1421 ccn_charbuf_append_string(lsa_data,"|");
1422
1423 char *temp_length=(char *)malloc(20);
1424 memset(temp_length,0,20);
1425 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1426 ccn_charbuf_append_string(lsa_data,temp_length);
1427 free(temp_length);
1428 ccn_charbuf_append_string(lsa_data,"|");
1429
1430 char *temp_ltype=(char *)malloc(20);
1431 memset(temp_ltype,0,20);
1432 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1433 ccn_charbuf_append_string(lsa_data,temp_ltype);
1434 free(temp_ltype);
1435 ccn_charbuf_append_string(lsa_data,"|");
1436
1437 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1438 ccn_charbuf_append_string(lsa_data,"|");
1439
1440 char *temp_nl=(char *)malloc(20);
1441 memset(temp_nl,0,20);
1442 sprintf(temp_nl,"%d",adj_lsa->no_link);
1443 ccn_charbuf_append_string(lsa_data,temp_nl);
1444 free(temp_nl);
1445 ccn_charbuf_append_string(lsa_data,"|");
1446
1447 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1448
1449
1450 }
1451 else if(res == HT_NEW_ENTRY)
1452 {
1453 hashtb_delete(e);
1454 }
1455
1456 hashtb_end(e);
1457}
akmhoqueffacaa82012-09-13 17:48:30 -05001458
akmhoqueda5b6832012-09-13 22:33:55 -05001459int
1460delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1461{
akmhoque7b791452012-10-30 11:24:56 -05001462 //printf("delete_name_lsa called \n");
1463
1464 if ( nlsr->debugging )
1465 printf("delete_name_lsa called \n");
1466 if ( nlsr->detailed_logging )
1467 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001468
1469 if(flags == CCN_SCHEDULE_CANCEL)
1470 {
1471 return -1;
1472 }
1473
1474
1475
1476 nlsr_lock();
1477
akmhoque7b791452012-10-30 11:24:56 -05001478 if ( nlsr->debugging )
1479 printf("LSA Key: %s \n",(char *)ev->evdata);
1480 if ( nlsr->detailed_logging )
1481 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001482
1483 struct nlsa *nlsa;
1484
1485 struct hashtb_enumerator ee;
1486 struct hashtb_enumerator *e = &ee;
1487
1488 int res;
1489
1490 hashtb_start(nlsr->lsdb->name_lsdb, e);
1491 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1492
1493 if( res == HT_OLD_ENTRY )
1494 {
1495 nlsa=e->data;
akmhoque3cced642012-09-24 16:20:20 -05001496 delete_npt_entry_by_router_and_name_prefix(nlsa->header->orig_router->name, nlsa->name_prefix->name);
akmhoque9e9fc722012-09-26 14:03:25 -05001497
1498 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1499 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1500 write_log_for_name_lsa(nlsa);
1501 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1502
akmhoqueda5b6832012-09-13 22:33:55 -05001503 hashtb_delete(e);
1504 }
akmhoque3cced642012-09-24 16:20:20 -05001505 else if( res == HT_NEW_ENTRY )
akmhoqueda5b6832012-09-13 22:33:55 -05001506 {
akmhoqueda5b6832012-09-13 22:33:55 -05001507 hashtb_delete(e);
1508 }
1509 hashtb_end(e);
1510
akmhoque7b791452012-10-30 11:24:56 -05001511 if ( nlsr->debugging )
1512 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1513 if ( nlsr->detailed_logging )
1514 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1515
akmhoqueda5b6832012-09-13 22:33:55 -05001516 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001517
1518 if ( nlsr->debugging )
1519 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1520 if ( nlsr->detailed_logging )
1521 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001522
1523 //print_name_lsdb();
1524
1525 nlsr_unlock();
1526
1527 return 0;
1528}
1529
1530int
1531delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1532{
akmhoque7b791452012-10-30 11:24:56 -05001533 //printf("delete_adj_lsa called \n");
1534
1535 if ( nlsr->debugging )
1536 printf("delete_adj_lsa called \n");
1537 if ( nlsr->detailed_logging )
1538 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001539
1540 if(flags == CCN_SCHEDULE_CANCEL)
1541 {
1542 return -1;
1543 }
1544 nlsr_lock();
1545
akmhoque7b791452012-10-30 11:24:56 -05001546 //printf("LSA Key: %s \n",(char *)ev->evdata);
1547
1548 if ( nlsr->debugging )
1549 printf("LSA Key: %s \n",(char *)ev->evdata);
1550 if ( nlsr->detailed_logging )
1551 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata);
akmhoqueda5b6832012-09-13 22:33:55 -05001552
akmhoque9e9fc722012-09-26 14:03:25 -05001553 struct alsa *alsa;
akmhoqueda5b6832012-09-13 22:33:55 -05001554 struct hashtb_enumerator ee;
1555 struct hashtb_enumerator *e = &ee;
1556 int res;
1557
1558 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1559 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
1560
1561 if( res == HT_OLD_ENTRY )
1562 {
akmhoque9e9fc722012-09-26 14:03:25 -05001563 alsa=e->data;
1564 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1565 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1566 write_log_for_adj_lsa(alsa);
1567 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1568
akmhoqueda5b6832012-09-13 22:33:55 -05001569 hashtb_delete(e);
1570 }
1571 else if( res == HT_OLD_ENTRY )
1572 {
1573 hashtb_delete(e);
1574 }
1575 hashtb_end(e);
1576
akmhoque7b791452012-10-30 11:24:56 -05001577 if ( nlsr->debugging )
1578 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1579 if ( nlsr->detailed_logging )
1580 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1581
akmhoqueda5b6832012-09-13 22:33:55 -05001582 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001583
1584 if ( nlsr->debugging )
1585 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1586 if ( nlsr->detailed_logging )
1587 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1588
akmhoqueda5b6832012-09-13 22:33:55 -05001589
1590 if ( !nlsr->is_route_calculation_scheduled)
1591 {
1592 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
1593 nlsr->is_route_calculation_scheduled=1;
1594 }
1595
1596 //print_adj_lsdb();
1597
1598 nlsr_unlock();
1599
1600 return 0;
1601}
1602
akmhoqueffacaa82012-09-13 17:48:30 -05001603void
1604refresh_name_lsdb(void)
1605{
akmhoque7b791452012-10-30 11:24:56 -05001606 //printf("refresh_name_lsdb called \n");
1607
1608 if ( nlsr->debugging )
1609 printf("refresh_name_lsdb called \n");
1610 if ( nlsr->detailed_logging )
1611 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001612
akmhoqueda5b6832012-09-13 22:33:55 -05001613 //int lsa_change_count=0;
1614
akmhoqueffacaa82012-09-13 17:48:30 -05001615 char *time_stamp=(char *)malloc(20);
1616 memset(time_stamp,0,20);
1617 get_current_timestamp_micro(time_stamp);
1618
1619 long int lsa_life_time;
1620
1621 int i, name_lsdb_element;
1622 struct nlsa *name_lsa;
1623
1624 struct hashtb_enumerator ee;
1625 struct hashtb_enumerator *e = &ee;
1626
1627 hashtb_start(nlsr->lsdb->name_lsdb, e);
1628 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
1629
1630 for(i=0;i<name_lsdb_element;i++)
1631 {
1632 name_lsa=e->data;
1633
1634 lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001635 if ( nlsr->debugging )
1636 printf("LSA Life Time: %ld \n",lsa_life_time);
1637 if ( nlsr->detailed_logging )
1638 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueda5b6832012-09-13 22:33:55 -05001639
1640 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1641 {
1642 if ( lsa_life_time > nlsr->lsa_refresh_time )
1643 {
akmhoque14b3f342012-09-14 10:39:02 -05001644 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1645 {
akmhoque7b791452012-10-30 11:24:56 -05001646 if ( nlsr->debugging )
1647 printf("Own Name LSA need to be refrshed\n");
1648 if ( nlsr->detailed_logging )
1649 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n");
akmhoquea98c2142012-10-25 15:22:24 -05001650
1651 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1652 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n");
1653 write_log_for_name_lsa(name_lsa);
1654 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
1655
1656
akmhoque14b3f342012-09-14 10:39:02 -05001657 char *current_time_stamp=(char *)malloc(20);
1658 memset(current_time_stamp,0,20);
1659 get_current_timestamp_micro(current_time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001660
akmhoque14b3f342012-09-14 10:39:02 -05001661 free(name_lsa->header->orig_time);
1662 name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1663 memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1664 memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
akmhoquea98c2142012-10-25 15:22:24 -05001665
1666 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
1667 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
1668 write_log_for_name_lsa(name_lsa);
1669 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001670
akmhoque14b3f342012-09-14 10:39:02 -05001671 free(current_time_stamp);
1672 }
1673 else
1674 {
1675 char lst[2];
1676 memset(lst,0,2);
1677 sprintf(lst,"%d",name_lsa->header->ls_type);
1678
1679 char lsid[10];
1680 memset(lsid,0,10);
1681 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1682
1683
1684 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1685 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1686
1687
1688 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque7b791452012-10-30 11:24:56 -05001689 //printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque14b3f342012-09-14 10:39:02 -05001690
1691 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
1692 }
akmhoqueda5b6832012-09-13 22:33:55 -05001693
akmhoque7b791452012-10-30 11:24:56 -05001694 if ( nlsr->debugging )
1695 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1696 if ( nlsr->detailed_logging )
1697 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1698
akmhoqueda5b6832012-09-13 22:33:55 -05001699 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001700
1701 if ( nlsr->debugging )
1702 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1703 if ( nlsr->detailed_logging )
1704 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1705
1706
akmhoqueda5b6832012-09-13 22:33:55 -05001707
1708 print_name_lsdb();
1709 //lsa_change_count++;
1710 }
1711 }
1712 else
1713 {
1714 if ( lsa_life_time > nlsr->router_dead_interval )
1715 {
akmhoque7b791452012-10-30 11:24:56 -05001716 if ( nlsr->debugging )
1717 printf("Others Name LSA need to be deleted\n");
1718 if ( nlsr->detailed_logging )
1719 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001720
1721 char lst[2];
1722 memset(lst,0,2);
1723 sprintf(lst,"%d",name_lsa->header->ls_type);
1724
1725 char lsid[10];
1726 memset(lsid,0,10);
1727 sprintf(lsid,"%ld",name_lsa->header->ls_id);
1728
1729
1730 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1731 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
1732
1733
1734 make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id);
akmhoque7b791452012-10-30 11:24:56 -05001735 //printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoqueda5b6832012-09-13 22:33:55 -05001736
1737 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
1738 //lsa_change_count++;
1739 }
1740 }
akmhoqueffacaa82012-09-13 17:48:30 -05001741
1742 hashtb_next(e);
1743 }
1744
1745 hashtb_end(e);
1746
1747 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001748
akmhoqueffacaa82012-09-13 17:48:30 -05001749
1750}
1751
akmhoqueda5b6832012-09-13 22:33:55 -05001752void
akmhoqueffacaa82012-09-13 17:48:30 -05001753refresh_adj_lsdb(void)
1754{
akmhoque7b791452012-10-30 11:24:56 -05001755 //printf("refresh_adj_lsdb called \n");
akmhoqueffacaa82012-09-13 17:48:30 -05001756
akmhoque7b791452012-10-30 11:24:56 -05001757 if ( nlsr->debugging )
1758 printf("refresh_adj_lsdb called \n");
1759 if ( nlsr->detailed_logging )
1760 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n");
akmhoqueda5b6832012-09-13 22:33:55 -05001761
akmhoqueffacaa82012-09-13 17:48:30 -05001762 char *time_stamp=(char *)malloc(20);
1763 memset(time_stamp,0,20);
1764 get_current_timestamp_micro(time_stamp);
1765
1766 long int lsa_life_time;
1767
1768 int i, adj_lsdb_element;
1769 struct alsa *adj_lsa;
1770
1771 struct hashtb_enumerator ee;
1772 struct hashtb_enumerator *e = &ee;
1773
1774 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1775 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
1776
1777 for(i=0;i<adj_lsdb_element;i++)
1778 {
1779 adj_lsa=e->data;
1780
1781 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001782 //printf("LSA Life Time: %ld \n",lsa_life_time);
1783
1784 if ( nlsr->debugging )
1785 printf("LSA Life Time: %ld \n",lsa_life_time);
1786 if ( nlsr->detailed_logging )
1787 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time);
akmhoqueffacaa82012-09-13 17:48:30 -05001788
akmhoqueda5b6832012-09-13 22:33:55 -05001789 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1790 {
1791 if ( lsa_life_time > nlsr->lsa_refresh_time )
1792 {
akmhoque7b791452012-10-30 11:24:56 -05001793 //printf("Own Adj LSA need to be refrshed\n");
1794 if ( nlsr->debugging )
1795 printf("Own Adj LSA need to be refrshed\n");
1796 if ( nlsr->detailed_logging )
1797 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001798
akmhoquea98c2142012-10-25 15:22:24 -05001799 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1800 writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n");
1801 write_log_for_adj_lsa(adj_lsa);
1802 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
1803
akmhoqueda5b6832012-09-13 22:33:55 -05001804 char *current_time_stamp=(char *)malloc(20);
1805 memset(current_time_stamp,0,20);
1806 get_current_timestamp_micro(current_time_stamp);
1807
1808 free(adj_lsa->header->orig_time);
1809 adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free
1810 memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1);
1811 memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1);
1812
1813 free(current_time_stamp);
1814
akmhoquea98c2142012-10-25 15:22:24 -05001815 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n");
1816 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n");
1817 write_log_for_adj_lsa(adj_lsa);
1818 writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001819
akmhoque7b791452012-10-30 11:24:56 -05001820 if ( nlsr->debugging )
1821 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1822 if ( nlsr->detailed_logging )
1823 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1824
akmhoqueda5b6832012-09-13 22:33:55 -05001825 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001826
1827 if ( nlsr->debugging )
1828 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
1829 if ( nlsr->detailed_logging )
1830 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoqueda5b6832012-09-13 22:33:55 -05001831
1832 print_adj_lsdb();
1833 }
1834 }
1835 else
1836 {
1837 if ( lsa_life_time > nlsr->router_dead_interval )
1838 {
akmhoque7b791452012-10-30 11:24:56 -05001839 //printf("Others Adj LSA need to be deleted\n");
1840
1841 if ( nlsr->debugging )
1842 printf("Others Adj LSA need to be deleted\n");
1843 if ( nlsr->detailed_logging )
1844 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n");
akmhoqueda5b6832012-09-13 22:33:55 -05001845
1846 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
1847 memset(key,0,adj_lsa->header->orig_router->length+2);
1848 make_adj_lsa_key(key,adj_lsa);
akmhoque7b791452012-10-30 11:24:56 -05001849 //printf("Adjacent LSA key: %s \n",key);
akmhoqueda5b6832012-09-13 22:33:55 -05001850 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
1851 }
1852 }
1853
1854
1855
akmhoqueffacaa82012-09-13 17:48:30 -05001856 hashtb_next(e);
1857 }
1858
1859 hashtb_end(e);
1860
1861 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05001862}
1863
1864int
1865refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1866{
1867 if(flags == CCN_SCHEDULE_CANCEL)
1868 {
1869 return -1;
1870 }
1871
1872 nlsr_lock();
akmhoqueda5b6832012-09-13 22:33:55 -05001873
akmhoque7b791452012-10-30 11:24:56 -05001874 //printf("refresh_lsdb called \n");
1875
1876 if ( nlsr->debugging )
1877 printf("refresh_lsdb called\n");
1878 if ( nlsr->detailed_logging )
1879 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05001880
1881 refresh_name_lsdb();
1882 refresh_adj_lsdb();
1883
akmhoqueffacaa82012-09-13 17:48:30 -05001884 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05001885
akmhoqueffacaa82012-09-13 17:48:30 -05001886 nlsr_unlock();
1887 return 0;
1888}