blob: f271e507ff719d9cc9df15ff98e92097c7f22977 [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
51 printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
52
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{
akmhoque53f64222012-09-05 13:57:51 -050074 printf("build_and_install_name_lsas called \n");
akmhoquef71d9082012-08-22 12:51:53 -040075
akmhoquef71d9082012-08-22 12:51:53 -040076 int i, npl_element;
77 struct name_prefix *np;
78
79 struct hashtb_enumerator ee;
80 struct hashtb_enumerator *e = &ee;
81
82 hashtb_start(nlsr->npl, e);
83 npl_element=hashtb_n(nlsr->npl);
84
85 for(i=0;i<npl_element;i++)
86 {
87 np=e->data;
akmhoque53f64222012-09-05 13:57:51 -050088 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
89 build_name_lsa(name_lsa,np);
akmhoque03004e62012-09-06 01:12:28 -050090
akmhoquef71d9082012-08-22 12:51:53 -040091 install_name_lsa(name_lsa);
akmhoque03004e62012-09-06 01:12:28 -050092 free(name_lsa->header->orig_router->name);
93 free(name_lsa->header->orig_router);
94 free(name_lsa->header);
95 free(name_lsa->name_prefix->name);
96 free(name_lsa->name_prefix);
akmhoquef71d9082012-08-22 12:51:53 -040097 free(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -040098 hashtb_next(e);
99 }
100
akmhoque53f64222012-09-05 13:57:51 -0500101 hashtb_end(e);
akmhoquef71d9082012-08-22 12:51:53 -0400102
akmhoquef71d9082012-08-22 12:51:53 -0400103}
104
akmhoque53f64222012-09-05 13:57:51 -0500105void
106build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
107{
akmhoque53f64222012-09-05 13:57:51 -0500108 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
109 name_lsa->header->ls_type=LS_TYPE_NAME;
110
akmhoque03004e62012-09-06 01:12:28 -0500111 char *time_stamp=(char *)malloc(20);
112 memset(time_stamp,0,20);
113 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500114
akmhoque03004e62012-09-06 01:12:28 -0500115 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500116 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
117 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500118
119 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500120
121 name_lsa->header->ls_id=++nlsr->nlsa_id;
122 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500123 name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
124 memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
125 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
126 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500127 name_lsa->header->isValid=1;
128
129
130 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
131 name_lsa->name_prefix->name=(char *)malloc(np->length);
132 memcpy(name_lsa->name_prefix->name,np->name,np->length);
133 name_lsa->name_prefix->length=np->length;
134
135}
136
akmhoque53f64222012-09-05 13:57:51 -0500137void
138install_name_lsa(struct nlsa *name_lsa)
139{
akmhoque53f64222012-09-05 13:57:51 -0500140
akmhoque03004e62012-09-06 01:12:28 -0500141 char lst[2];
142 memset(lst,0,2);
143 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoque53f64222012-09-05 13:57:51 -0500144
akmhoque03004e62012-09-06 01:12:28 -0500145 char lsid[10];
146 memset(lsid,0,10);
147 sprintf(lsid,"%ld",name_lsa->header->ls_id);
148
149
150 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
151 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
152
153
154 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 -0500155 printf("Key:%s Length:%d\n",key,(int)strlen(key));
156
akmhoque03004e62012-09-06 01:12:28 -0500157 struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
akmhoque53f64222012-09-05 13:57:51 -0500158
159 struct hashtb_enumerator ee;
160 struct hashtb_enumerator *e = &ee;
161 int res;
162
163 hashtb_start(nlsr->lsdb->name_lsdb, e);
164 res = hashtb_seek(e, key, strlen(key), 0);
165
166 if(res == HT_NEW_ENTRY )
167 {
168 printf("New Name LSA... Adding to LSDB\n");
169 new_name_lsa = e->data;
170
akmhoque03004e62012-09-06 01:12:28 -0500171 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
akmhoque53f64222012-09-05 13:57:51 -0500172 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
173
174 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
akmhoque03004e62012-09-06 01:12:28 -0500175 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500176 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
177
akmhoque53f64222012-09-05 13:57:51 -0500178 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque03004e62012-09-06 01:12:28 -0500179 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque53f64222012-09-05 13:57:51 -0500180 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
181 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
182 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
183 new_name_lsa->header->isValid=name_lsa->header->isValid;
184
185
akmhoque03004e62012-09-06 01:12:28 -0500186 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque53f64222012-09-05 13:57:51 -0500187 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
188 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
189 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
190
191 printf("New Name LSA Added....\n");
192
akmhoque03004e62012-09-06 01:12:28 -0500193 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500194 set_new_lsdb_version();
akmhoque3560cb62012-09-09 10:52:30 -0500195 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
196
197 int next_hop=get_next_hop(new_name_lsa->header->orig_router->name);
198 if ( next_hop == NO_NEXT_HOP )
199 {
200 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_FACE);
201 if ( check == HT_NEW_ENTRY )
202 {
203 printf("Added in npt \n");
204 }
205 }
206 else
207 {
208 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop);
209 if ( check == HT_NEW_ENTRY )
210 {
211 printf("Added in npt \n");
212 }
213
214 }
akmhoque53f64222012-09-05 13:57:51 -0500215
216 }
217 else if(res == HT_OLD_ENTRY)
218 {
219 printf("Duplicate Name LSA. Discarded...\n");
220
221 }
222
223 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500224
225 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500226}
227
228
akmhoque03004e62012-09-06 01:12:28 -0500229void
230print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500231{
232
akmhoque03004e62012-09-06 01:12:28 -0500233 printf("-----------Name LSA Content---------------\n");
234 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
235 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
236 printf(" LS Type : %d\n",name_lsa->header->ls_type);
237 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
238 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
239 printf(" Is Valid : %d\n",name_lsa->header->isValid);
240 printf(" LSA Data \n");
241 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
242 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
akmhoque53f64222012-09-05 13:57:51 -0500243
akmhoque03004e62012-09-06 01:12:28 -0500244 printf("\n");
akmhoquef71d9082012-08-22 12:51:53 -0400245}
246
247void
248print_name_lsdb(void)
249{
250 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500251 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400252 struct nlsa *name_lsa;
253
254 struct hashtb_enumerator ee;
255 struct hashtb_enumerator *e = &ee;
256
257 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500258 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400259
akmhoque53f64222012-09-05 13:57:51 -0500260 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400261 {
akmhoque53f64222012-09-05 13:57:51 -0500262 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400263 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500264 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400265 hashtb_next(e);
266 }
267
268 hashtb_end(e);
269
akmhoque53f64222012-09-05 13:57:51 -0500270 printf("\n");
271}
272
akmhoque03004e62012-09-06 01:12:28 -0500273
274void
275build_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 -0500276{
akmhoque03004e62012-09-06 01:12:28 -0500277 printf("build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500278
akmhoque03004e62012-09-06 01:12:28 -0500279 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
280 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
281 print_name_lsa(name_lsa);
282 install_name_lsa(name_lsa);
283 print_name_lsdb();
akmhoque53f64222012-09-05 13:57:51 -0500284
akmhoque53f64222012-09-05 13:57:51 -0500285
akmhoque03004e62012-09-06 01:12:28 -0500286 free(name_lsa->header->orig_router->name);
287 free(name_lsa->header->orig_router);
288 free(name_lsa->header);
289 free(name_lsa->name_prefix->name);
290 free(name_lsa->name_prefix);
291 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500292
293}
294
295void
akmhoque03004e62012-09-06 01:12:28 -0500296build_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 -0500297{
akmhoque03004e62012-09-06 01:12:28 -0500298 printf("build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500299
akmhoque03004e62012-09-06 01:12:28 -0500300 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
301 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500302
akmhoque03004e62012-09-06 01:12:28 -0500303 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
304 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
305 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500306
akmhoque03004e62012-09-06 01:12:28 -0500307 name_lsa->header->ls_id=ls_id;
308 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
309 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
310 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
311 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
312 name_lsa->header->orig_router->length=strlen(orig_router)+1;
313 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500314
akmhoque03004e62012-09-06 01:12:28 -0500315 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
316 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
317 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
318 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
319 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400320}
akmhoqued79438d2012-08-27 13:31:42 -0500321
322
akmhoque53f64222012-09-05 13:57:51 -0500323void
324make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500325{
akmhoque53f64222012-09-05 13:57:51 -0500326 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
327 memcpy(key+strlen(key),"/",1);
328 char ls_type[2];
329 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
330 memcpy(key+strlen(key),ls_type,strlen(ls_type));
331 key[strlen(key)]='\0';
332}
333
akmhoque03004e62012-09-06 01:12:28 -0500334int
335build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
336{
337 printf("build_and_install_adj_lsa called \n");
338
339 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
340
341 if(nlsr->adj_build_flag > 0)
342 {
343 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
344 if ( is_adj_lsa_build()> 0)
345 {
346 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
347 build_adj_lsa(adj_lsa);
348 install_adj_lsa(adj_lsa);
349
350 free(adj_lsa->header->orig_router->name);
351 free(adj_lsa->header->orig_router);
352 free(adj_lsa->header->orig_time);
353 free(adj_lsa->header);
354 free(adj_lsa->body);
355 free(adj_lsa);
356 nlsr->adj_build_flag=0;
357 print_adj_lsdb();
358 }
359 else
360 {
361 printf("Can not build adj LSA now\n");
362 }
363 }
364 nlsr->is_build_adj_lsa_sheduled=0;
365 return 0;
366}
367
368
369void
370build_adj_lsa(struct alsa * adj_lsa)
371{
372 printf("build_adj_lsa called \n");
373
374 int no_link=no_active_nbr();
375 printf("Number of link in Adjacent LSA: %d\n",no_link);
376
377 /*Filling Up Header Data */
378 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
379 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
380 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
381 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
382 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
383 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
384
385 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
386
387 char *time_stamp=(char *)malloc(20);
388 memset(time_stamp,0,20);
389 get_current_timestamp_micro(time_stamp);
390
391 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
392 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
393 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
394 free(time_stamp);
395
396
397 /* Filling Up Body Data */
398
399 adj_lsa->no_link=no_link;
400/*
401 struct link *templ=(struct link *)malloc(2*sizeof(struct link));
402 adj_lsa->links=templ;
403
404 int i, adl_element;
405 struct ndn_neighbor *nbr;
406 struct hashtb_enumerator ee;
407 struct hashtb_enumerator *e = &ee;
408 hashtb_start(nlsr->adl, e);
409 adl_element=hashtb_n(nlsr->adl);
410
411 for(i=0;i<adl_element;i++)
412 {
413 nbr=e->data;
414 if( nbr->status == 1 )
415 {
416 struct link *temp=(struct link *)malloc(sizeof(struct link));
417 temp->nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix));
418 temp->nbr->name=(char *)malloc(nbr->neighbor->length);
419 memset(temp->nbr->name,0,nbr->neighbor->length);
420 memcpy(temp->nbr->name,nbr->neighbor->name,nbr->neighbor->length);
421
422 temp->nbr->length=nbr->neighbor->length;
423 temp->face=nbr->face;
424 temp->metric=nbr->metric;
425
426 templ=temp;
427 templ++;
428 }
429 hashtb_next(e);
430 }
431
432 hashtb_end(e);
433*/
434
435
436 struct ccn_charbuf *c=ccn_charbuf_create();
437 get_active_nbr_adj_data(c);
438 char *data=ccn_charbuf_as_string(c);
439
440 adj_lsa->body=(char *)malloc(strlen(data)+1);
441 memset(adj_lsa->body,0,strlen(data)+1);
442 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
443 ccn_charbuf_destroy(&c);
444
445
446
447 if( !nlsr->is_send_lsdb_interest_scheduled )
448 {
449 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
450 nlsr->is_send_lsdb_interest_scheduled=1;
451 }
452
453 nlsr->adj_build_count++;
454
455
456}
457
458
akmhoque53f64222012-09-05 13:57:51 -0500459void
460install_adj_lsa(struct alsa * adj_lsa)
461{
akmhoqued79438d2012-08-27 13:31:42 -0500462 printf("install_adj_lsa called \n");
463
akmhoque53f64222012-09-05 13:57:51 -0500464 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
465 memset(key,0,adj_lsa->header->orig_router->length+2);
466 make_adj_lsa_key(key,adj_lsa);
467 printf("Adjacent LSA key: %s \n",key);
akmhoque03004e62012-09-06 01:12:28 -0500468
akmhoque53f64222012-09-05 13:57:51 -0500469 struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
470
471 struct hashtb_enumerator ee;
472 struct hashtb_enumerator *e = &ee;
473 int res;
474
475 hashtb_start(nlsr->lsdb->adj_lsdb, e);
476 res = hashtb_seek(e, key, strlen(key), 0);
477
akmhoque03004e62012-09-06 01:12:28 -0500478
akmhoque53f64222012-09-05 13:57:51 -0500479
480 if(res == HT_NEW_ENTRY )
481 {
482 printf("New ADJ LSA... Adding to LSDB\n");
483 new_adj_lsa = e->data;
484
485 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
486 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
487 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
488 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
489
490 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
491 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
492 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
493 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500494
akmhoque03004e62012-09-06 01:12:28 -0500495 new_adj_lsa->no_link=adj_lsa->no_link;
496
akmhoque53f64222012-09-05 13:57:51 -0500497 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
498 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
499 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
500
akmhoque03004e62012-09-06 01:12:28 -0500501 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500502 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500503 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
504
akmhoque3560cb62012-09-09 10:52:30 -0500505 add_next_hop_router(new_adj_lsa->header->orig_router->name);
akmhoque53f64222012-09-05 13:57:51 -0500506
akmhoque3560cb62012-09-09 10:52:30 -0500507 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500508 }
509 else if(res == HT_OLD_ENTRY)
510 {
511 new_adj_lsa = e->data;
512 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
513 {
514 printf("Older/Duplicate Adj LSA. Discarded...\n");
515 }
516 else
517 {
518 new_adj_lsa = e->data;
519
520 free(new_adj_lsa->header->orig_time);
521 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
522 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500523
akmhoque03004e62012-09-06 01:12:28 -0500524 new_adj_lsa->no_link=adj_lsa->no_link;
525
akmhoque53f64222012-09-05 13:57:51 -0500526 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
527 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
528 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
529
akmhoque03004e62012-09-06 01:12:28 -0500530 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500531 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500532 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500533
akmhoque3560cb62012-09-09 10:52:30 -0500534 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
535
akmhoque53f64222012-09-05 13:57:51 -0500536 }
537
538 }
akmhoque53f64222012-09-05 13:57:51 -0500539 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500540
akmhoque29c1db52012-09-07 14:47:43 -0500541 if ( !nlsr->is_route_calculation_scheduled )
542 {
543 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
544 nlsr->is_route_calculation_scheduled=1;
545 }
akmhoque53f64222012-09-05 13:57:51 -0500546 free(key);
547}
548
549void
550print_adj_lsa_body(const char *body, int no_link)
551{
552 int i=0;
553 char *lsa_data=(char *)malloc(strlen(body)+1);
554 memset( lsa_data,0,strlen(body)+1);
555 memcpy(lsa_data,body,strlen(body)+1);
556 char *sep="|";
557 char *rem;
558 char *rtr_id;
559 char *length;
560 char *face;
561 char *metric;
562
akmhoque53f64222012-09-05 13:57:51 -0500563 if(no_link >0 )
564 {
565 rtr_id=strtok_r(lsa_data,sep,&rem);
566 length=strtok_r(NULL,sep,&rem);
567 face=strtok_r(NULL,sep,&rem);
568 metric=strtok_r(NULL,sep,&rem);
569
570 printf(" Link %d \n",i+1);
571 printf(" Neighbor : %s \n",rtr_id);
572 printf(" Neighbor Length : %s \n",length);
573 printf(" Connecting Face : %s \n",face);
574 printf(" Metric : %s \n",metric);
akmhoque03004e62012-09-06 01:12:28 -0500575
akmhoque53f64222012-09-05 13:57:51 -0500576
577 for(i=1;i<no_link;i++)
578 {
579 rtr_id=strtok_r(NULL,sep,&rem);
580 length=strtok_r(NULL,sep,&rem);
581 face=strtok_r(NULL,sep,&rem);
582 metric=strtok_r(NULL,sep,&rem);
583 printf(" Link %d \n",i+1);
584 printf(" Neighbor : %s \n",rtr_id);
585 printf(" Neighbor Length : %s \n",length);
586 printf(" Connecting Face : %s \n",face);
587 printf(" Metric : %s \n",metric);
588
589 }
590 }
591
592 free(lsa_data);
593}
594
595void
596print_adj_lsa(struct alsa * adj_lsa)
597{
akmhoque03004e62012-09-06 01:12:28 -0500598
akmhoque53f64222012-09-05 13:57:51 -0500599 printf("print_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500600
akmhoque53f64222012-09-05 13:57:51 -0500601 printf("-----------ADJ LSA Content---------------\n");
602 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
603 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
604 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
605 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
akmhoque03004e62012-09-06 01:12:28 -0500606 printf(" Lsa Data:\n");
607 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500608
609 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500610
akmhoque03004e62012-09-06 01:12:28 -0500611/*
612 struct link *templ=adj_lsa->links;
613 int i;
614
615 for(i=0 ; i< adj_lsa->no_link ; i++)
616 {
617 printf(" Link %d \n",i+1);
618 printf(" Neighbor : %s \n",templ->nbr->name);
619 printf(" Neighbor Length : %d \n",templ->nbr->length);
620 printf(" Connecting Face : %d \n",templ->face);
621 printf(" Metric : %d \n",templ->metric);
622
623 templ++;
624 }
625*/
akmhoque53f64222012-09-05 13:57:51 -0500626 printf("\n");
627
628}
629
630void
631print_adj_lsdb(void)
632{
633 printf("print_name_lsdb called \n");
634 int i, adj_lsdb_element;
635 struct alsa *adj_lsa;
636
637 struct hashtb_enumerator ee;
638 struct hashtb_enumerator *e = &ee;
639
640 hashtb_start(nlsr->lsdb->adj_lsdb, e);
641 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
642
643 for(i=0;i<adj_lsdb_element;i++)
644 {
645 printf("-----------Adj LSA (%d)---------------\n",i+1);
646 adj_lsa=e->data;
647 print_adj_lsa(adj_lsa);
648 hashtb_next(e);
649 }
650
651 hashtb_end(e);
652
653 printf("\n");
akmhoque53f64222012-09-05 13:57:51 -0500654}
655
656void
akmhoque03004e62012-09-06 01:12:28 -0500657build_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 -0500658{
akmhoque03004e62012-09-06 01:12:28 -0500659 printf("build_and_install_others_adj_lsa called \n");
660 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
661 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
662 //print_adj_lsa(adj_lsa);
663 install_adj_lsa(adj_lsa);
664
akmhoque53f64222012-09-05 13:57:51 -0500665
akmhoque03004e62012-09-06 01:12:28 -0500666 free(adj_lsa->header->orig_router->name);
667 free(adj_lsa->header->orig_router);
668 free(adj_lsa->header->orig_time);
669 free(adj_lsa->header);
670 free(adj_lsa->body);
671 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500672
akmhoque03004e62012-09-06 01:12:28 -0500673 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -0500674
akmhoque53f64222012-09-05 13:57:51 -0500675}
676
akmhoque03004e62012-09-06 01:12:28 -0500677
akmhoque53f64222012-09-05 13:57:51 -0500678void
akmhoque03004e62012-09-06 01:12:28 -0500679build_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 -0500680{
akmhoque03004e62012-09-06 01:12:28 -0500681 printf("build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500682
akmhoque03004e62012-09-06 01:12:28 -0500683 /*Filling Up Header Data */
684 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
685 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
686 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
687 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
688 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -0500689
akmhoque03004e62012-09-06 01:12:28 -0500690 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -0500691
akmhoque53f64222012-09-05 13:57:51 -0500692
akmhoque03004e62012-09-06 01:12:28 -0500693 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -0500694
akmhoque03004e62012-09-06 01:12:28 -0500695 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
696 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
697 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500698
akmhoque03004e62012-09-06 01:12:28 -0500699 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -0500700
akmhoque03004e62012-09-06 01:12:28 -0500701 adj_lsa->body=(char *)malloc(strlen(data)+1);
702 memset(adj_lsa->body,0,strlen(data)+1);
703 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -0500704
akmhoque53f64222012-09-05 13:57:51 -0500705}
706
akmhoque03004e62012-09-06 01:12:28 -0500707
akmhoque53f64222012-09-05 13:57:51 -0500708long int
709get_name_lsdb_num_element(void)
710{
711 long int num_element;
712
713
714 struct hashtb_enumerator ee;
715 struct hashtb_enumerator *e = &ee;
716
717 hashtb_start(nlsr->lsdb->name_lsdb, e);
718 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
719 hashtb_end(e);
720
721 return num_element;
722}
723
724long int
725get_adj_lsdb_num_element(void)
726{
727 long int num_element;
728
729
730 struct hashtb_enumerator ee;
731 struct hashtb_enumerator *e = &ee;
732
733 hashtb_start(nlsr->lsdb->adj_lsdb, e);
734 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
735 hashtb_end(e);
736
737 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -0500738}
akmhoque03004e62012-09-06 01:12:28 -0500739
740void
741get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
742{
743 printf("get_name_lsdb_summary called \n");
744 int i, name_lsdb_element;
745
746 struct nlsa *name_lsa;
747 struct hashtb_enumerator ee;
748 struct hashtb_enumerator *e = &ee;
749
750 hashtb_start(nlsr->lsdb->name_lsdb, e);
751 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
752
753 for(i=0;i<name_lsdb_element;i++)
754 {
755 name_lsa=e->data;
756
757 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name);
758 ccn_charbuf_append_string(name_lsdb_data,"|");
759
760 char *lst=(char *)malloc(20);
761 memset(lst,0,20);
762 sprintf(lst,"%d",name_lsa->header->ls_type);
763 ccn_charbuf_append_string(name_lsdb_data,lst);
764 free(lst);
765 ccn_charbuf_append_string(name_lsdb_data,"|");
766
767 char *lsid=(char *)malloc(20);
768 memset(lsid,0,20);
769 sprintf(lsid,"%ld",name_lsa->header->ls_id);
770 ccn_charbuf_append_string(name_lsdb_data,lsid);
771 free(lsid);
772 ccn_charbuf_append_string(name_lsdb_data,"|");
773
774 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time);
775 ccn_charbuf_append_string(name_lsdb_data,"|");
776
777 hashtb_next(e);
778 }
779
780 hashtb_end(e);
781
782}
783
784
785void
786get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data)
787{
788 printf("get_adj_lsdb_summary called \n");
789 int i, adj_lsdb_element;
790 struct alsa *adj_lsa;
791
792 struct hashtb_enumerator ee;
793 struct hashtb_enumerator *e = &ee;
794
795 hashtb_start(nlsr->lsdb->adj_lsdb, e);
796 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
797
798 for(i=0;i<adj_lsdb_element;i++)
799 {
800 adj_lsa=e->data;
801
802 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name);
803 ccn_charbuf_append_string(adj_lsdb_data,"|");
804
805 char *lst=(char *)malloc(20);
806 memset(lst,0,20);
807 sprintf(lst,"%d",adj_lsa->header->ls_type);
808 ccn_charbuf_append_string(adj_lsdb_data,lst);
809 free(lst);
810 ccn_charbuf_append_string(adj_lsdb_data,"|");
811
812 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time);
813 ccn_charbuf_append_string(adj_lsdb_data,"|");
814
815 hashtb_next(e);
816 }
817
818 hashtb_end(e);
819}
820
821
822void
823get_lsdb_summary(struct ccn_charbuf *lsdb_data)
824{
825 struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create();
826 struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create();
827
828 get_name_lsdb_summary(name_lsdb_data);
829 get_adj_lsdb_summary(adj_lsdb_data);
830
831 long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element();
832 char *num_element=(char *)malloc(15);
833 memset(num_element,0,15);
834 sprintf(num_element,"%ld",num_lsa);
835
836 if( num_lsa > 0)
837 {
838 ccn_charbuf_append_string(lsdb_data,num_element);
839 ccn_charbuf_append_string(lsdb_data,"|");
840 }
841 if(name_lsdb_data->length>0)
842 {
843 char *data1=ccn_charbuf_as_string(name_lsdb_data);
844 ccn_charbuf_append_string(lsdb_data,(char *)data1);
845 }
846 if(adj_lsdb_data->length>0)
847 {
848 char *data2=ccn_charbuf_as_string(adj_lsdb_data);
849 ccn_charbuf_append_string(lsdb_data,(char *)data2);
850 }
851 ccn_charbuf_destroy(&name_lsdb_data);
852 ccn_charbuf_destroy(&adj_lsdb_data);
853 free(num_element);
854
855}
856
857int
858check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
859{
860 int ret=0;
861 struct ccn_charbuf *key=ccn_charbuf_create();
862 ccn_charbuf_append_string(key,orig_router);
863 ccn_charbuf_append_string(key,"/");
864 ccn_charbuf_append_string(key,lst);
865 ccn_charbuf_append_string(key,"/");
866 ccn_charbuf_append_string(key,lsid);
867
868 int res;
869 struct nlsa *name_lsa;
870
871 struct hashtb_enumerator ee;
872 struct hashtb_enumerator *e = &ee;
873
874 hashtb_start(nlsr->lsdb->name_lsdb, e);
875 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
876
877 if( res == HT_NEW_ENTRY )
878 {
879 hashtb_delete(e);
880 ret=1;
881
882 }
883 else if(res == HT_OLD_ENTRY)
884 {
885 name_lsa=e->data;
886 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
887 {
888 ret=1;
889 }
890 }
891
892 hashtb_end(e);
893
894 ccn_charbuf_destroy(&key);
895
896 return ret;
897}
898
899int
900check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
901{
902 int ret=0;
903 struct ccn_charbuf *key=ccn_charbuf_create();
904 ccn_charbuf_append_string(key,orig_router);
905 ccn_charbuf_append_string(key,"/");
906 ccn_charbuf_append_string(key,lst);
907
908 int res;
909 struct alsa *adj_lsa;
910
911 struct hashtb_enumerator ee;
912 struct hashtb_enumerator *e = &ee;
913
914 hashtb_start(nlsr->lsdb->adj_lsdb, e);
915 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
916
917 if( res == HT_NEW_ENTRY )
918 {
919 hashtb_delete(e);
920 ret=1;
921
922 }
923 else if(res == HT_OLD_ENTRY)
924 {
925 adj_lsa=e->data;
926 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
927 {
928 ret=1;
929 }
930 }
931
932 hashtb_end(e);
933
934 ccn_charbuf_destroy(&key);
935
936 return ret;
937}
938
939void
940get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
941{
942 printf("get_name_lsa_data called \n");
943
944 struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
945
946 struct hashtb_enumerator ee;
947 struct hashtb_enumerator *e = &ee;
948 int res;
949
950 hashtb_start(nlsr->lsdb->name_lsdb, e);
951 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
952
953 if( res == HT_OLD_ENTRY )
954 {
955 name_lsa=e->data;
956 printf("NAME LSA found\n");
957
958 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
959 ccn_charbuf_append_string(lsa_data,"|");
960
961 char *temp_length=(char *)malloc(20);
962 memset(temp_length,0,20);
963 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
964 ccn_charbuf_append_string(lsa_data,temp_length);
965 free(temp_length);
966 ccn_charbuf_append_string(lsa_data,"|");
967
968 char *temp_ltype=(char *)malloc(20);
969 memset(temp_ltype,0,20);
970 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
971 ccn_charbuf_append_string(lsa_data,temp_ltype);
972 free(temp_ltype);
973 ccn_charbuf_append_string(lsa_data,"|");
974
975 char *temp_lsid=(char *)malloc(20);
976 memset(temp_lsid,0,20);
977 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
978 ccn_charbuf_append_string(lsa_data,temp_lsid);
979 free(temp_lsid);
980 ccn_charbuf_append_string(lsa_data,"|");
981
982 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
983 ccn_charbuf_append_string(lsa_data,"|");
984
985 char *temp_valid=(char *)malloc(20);
986 memset(temp_valid,0,20);
987 sprintf(temp_valid,"%d",name_lsa->header->isValid);
988 ccn_charbuf_append_string(lsa_data,temp_valid);
989 free(temp_valid);
990 ccn_charbuf_append_string(lsa_data,"|");
991
992 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
993 ccn_charbuf_append_string(lsa_data,"|");
994
995 char *temp_npl=(char *)malloc(20);
996 memset(temp_npl,0,20);
997 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
998 ccn_charbuf_append_string(lsa_data,temp_npl);
999 free(temp_npl);
1000 ccn_charbuf_append_string(lsa_data,"|");
1001
1002 }
1003 else if(res == HT_NEW_ENTRY)
1004 {
1005 hashtb_delete(e);
1006 }
1007
1008 hashtb_end(e);
1009}
1010
1011void
1012get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1013{
1014 printf("get_adj_lsa_data called \n");
1015
1016 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
1017
1018 struct hashtb_enumerator ee;
1019 struct hashtb_enumerator *e = &ee;
1020 int res;
1021
1022 hashtb_start(nlsr->lsdb->adj_lsdb, e);
1023 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1024
1025 if( res == HT_OLD_ENTRY )
1026 {
1027 adj_lsa=e->data;
1028 printf("NAME LSA found\n");
1029
1030 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1031 ccn_charbuf_append_string(lsa_data,"|");
1032
1033 char *temp_length=(char *)malloc(20);
1034 memset(temp_length,0,20);
1035 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1036 ccn_charbuf_append_string(lsa_data,temp_length);
1037 free(temp_length);
1038 ccn_charbuf_append_string(lsa_data,"|");
1039
1040 char *temp_ltype=(char *)malloc(20);
1041 memset(temp_ltype,0,20);
1042 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1043 ccn_charbuf_append_string(lsa_data,temp_ltype);
1044 free(temp_ltype);
1045 ccn_charbuf_append_string(lsa_data,"|");
1046
1047 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1048 ccn_charbuf_append_string(lsa_data,"|");
1049
1050 char *temp_nl=(char *)malloc(20);
1051 memset(temp_nl,0,20);
1052 sprintf(temp_nl,"%d",adj_lsa->no_link);
1053 ccn_charbuf_append_string(lsa_data,temp_nl);
1054 free(temp_nl);
1055 ccn_charbuf_append_string(lsa_data,"|");
1056
1057 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1058
1059
1060 }
1061 else if(res == HT_NEW_ENTRY)
1062 {
1063 hashtb_delete(e);
1064 }
1065
1066 hashtb_end(e);
1067}