blob: 4df08401cc2df61e96dbd7c1e611bb2da41b254a [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"
akmhoque438b07e2012-08-21 10:13:57 -040027
akmhoquef71d9082012-08-22 12:51:53 -040028void
akmhoque53f64222012-09-05 13:57:51 -050029set_new_lsdb_version(void)
akmhoquef71d9082012-08-22 12:51:53 -040030{
akmhoquef71d9082012-08-22 12:51:53 -040031
akmhoque03004e62012-09-06 01:12:28 -050032 char *time_stamp=(char *)malloc(20);
33 memset(time_stamp,0,20);
34 get_current_timestamp_micro(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040035
akmhoque03004e62012-09-06 01:12:28 -050036 free(nlsr->lsdb->lsdb_version);
37 nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
38 memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
39 memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
40
41 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050042
akmhoquef71d9082012-08-22 12:51:53 -040043}
44
akmhoque03004e62012-09-06 01:12:28 -050045void
46make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
47{
48
49
50 printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
51
52 char lst[2];
53 memset(lst,0,2);
54 sprintf(lst,"%d",ls_type);
55
56 char lsid[10];
57 memset(lsid,0,10);
58 sprintf(lsid,"%ld",ls_id);
59
60 memcpy(key+strlen(key),orig_router,strlen(orig_router));
61 memcpy(key+strlen(key),"/",1);
62 memcpy(key+strlen(key),lst,strlen(lst));
63 memcpy(key+strlen(key),"/",1);
64 memcpy(key+strlen(key),lsid,strlen(lsid));
65
66 printf("Key: %s\n",key);
67
68}
akmhoque53f64222012-09-05 13:57:51 -050069
akmhoquef71d9082012-08-22 12:51:53 -040070void
akmhoque53f64222012-09-05 13:57:51 -050071build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -040072{
akmhoque53f64222012-09-05 13:57:51 -050073 printf("build_and_install_name_lsas called \n");
akmhoquef71d9082012-08-22 12:51:53 -040074
akmhoquef71d9082012-08-22 12:51:53 -040075 int i, npl_element;
76 struct name_prefix *np;
77
78 struct hashtb_enumerator ee;
79 struct hashtb_enumerator *e = &ee;
80
81 hashtb_start(nlsr->npl, e);
82 npl_element=hashtb_n(nlsr->npl);
83
84 for(i=0;i<npl_element;i++)
85 {
86 np=e->data;
akmhoque53f64222012-09-05 13:57:51 -050087 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
88 build_name_lsa(name_lsa,np);
akmhoque03004e62012-09-06 01:12:28 -050089
akmhoquef71d9082012-08-22 12:51:53 -040090 install_name_lsa(name_lsa);
akmhoque03004e62012-09-06 01:12:28 -050091 free(name_lsa->header->orig_router->name);
92 free(name_lsa->header->orig_router);
93 free(name_lsa->header);
94 free(name_lsa->name_prefix->name);
95 free(name_lsa->name_prefix);
akmhoquef71d9082012-08-22 12:51:53 -040096 free(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -040097 hashtb_next(e);
98 }
99
akmhoque53f64222012-09-05 13:57:51 -0500100 hashtb_end(e);
akmhoquef71d9082012-08-22 12:51:53 -0400101
akmhoquef71d9082012-08-22 12:51:53 -0400102}
103
akmhoque53f64222012-09-05 13:57:51 -0500104void
105build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
106{
akmhoque53f64222012-09-05 13:57:51 -0500107 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
108 name_lsa->header->ls_type=LS_TYPE_NAME;
109
akmhoque03004e62012-09-06 01:12:28 -0500110 char *time_stamp=(char *)malloc(20);
111 memset(time_stamp,0,20);
112 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500113
akmhoque03004e62012-09-06 01:12:28 -0500114 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500115 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
116 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500117
118 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500119
120 name_lsa->header->ls_id=++nlsr->nlsa_id;
121 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500122 name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
123 memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
124 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
125 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500126 name_lsa->header->isValid=1;
127
128
129 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
130 name_lsa->name_prefix->name=(char *)malloc(np->length);
131 memcpy(name_lsa->name_prefix->name,np->name,np->length);
132 name_lsa->name_prefix->length=np->length;
133
134}
135
akmhoque53f64222012-09-05 13:57:51 -0500136void
137install_name_lsa(struct nlsa *name_lsa)
138{
akmhoque53f64222012-09-05 13:57:51 -0500139
akmhoque03004e62012-09-06 01:12:28 -0500140 char lst[2];
141 memset(lst,0,2);
142 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoque53f64222012-09-05 13:57:51 -0500143
akmhoque03004e62012-09-06 01:12:28 -0500144 char lsid[10];
145 memset(lsid,0,10);
146 sprintf(lsid,"%ld",name_lsa->header->ls_id);
147
148
149 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
150 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
151
152
153 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 -0500154 printf("Key:%s Length:%d\n",key,(int)strlen(key));
155
akmhoque03004e62012-09-06 01:12:28 -0500156 struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
akmhoque53f64222012-09-05 13:57:51 -0500157
158 struct hashtb_enumerator ee;
159 struct hashtb_enumerator *e = &ee;
160 int res;
161
162 hashtb_start(nlsr->lsdb->name_lsdb, e);
163 res = hashtb_seek(e, key, strlen(key), 0);
164
165 if(res == HT_NEW_ENTRY )
166 {
167 printf("New Name LSA... Adding to LSDB\n");
168 new_name_lsa = e->data;
169
akmhoque03004e62012-09-06 01:12:28 -0500170 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
akmhoque53f64222012-09-05 13:57:51 -0500171 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
172
173 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
akmhoque03004e62012-09-06 01:12:28 -0500174 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500175 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
176
akmhoque53f64222012-09-05 13:57:51 -0500177 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque03004e62012-09-06 01:12:28 -0500178 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque53f64222012-09-05 13:57:51 -0500179 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
180 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
181 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
182 new_name_lsa->header->isValid=name_lsa->header->isValid;
183
184
akmhoque03004e62012-09-06 01:12:28 -0500185 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque53f64222012-09-05 13:57:51 -0500186 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
187 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
188 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
189
190 printf("New Name LSA Added....\n");
191
akmhoque03004e62012-09-06 01:12:28 -0500192 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500193 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500194 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500195
196 }
197 else if(res == HT_OLD_ENTRY)
198 {
199 printf("Duplicate Name LSA. Discarded...\n");
200
201 }
202
203 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500204
205 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500206}
207
208
akmhoque03004e62012-09-06 01:12:28 -0500209void
210print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500211{
212
akmhoque03004e62012-09-06 01:12:28 -0500213 printf("-----------Name LSA Content---------------\n");
214 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
215 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
216 printf(" LS Type : %d\n",name_lsa->header->ls_type);
217 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
218 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
219 printf(" Is Valid : %d\n",name_lsa->header->isValid);
220 printf(" LSA Data \n");
221 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
222 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
akmhoque53f64222012-09-05 13:57:51 -0500223
akmhoque03004e62012-09-06 01:12:28 -0500224 printf("\n");
akmhoquef71d9082012-08-22 12:51:53 -0400225}
226
227void
228print_name_lsdb(void)
229{
230 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500231 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400232 struct nlsa *name_lsa;
233
234 struct hashtb_enumerator ee;
235 struct hashtb_enumerator *e = &ee;
236
237 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500238 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400239
akmhoque53f64222012-09-05 13:57:51 -0500240 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400241 {
akmhoque53f64222012-09-05 13:57:51 -0500242 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400243 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500244 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400245 hashtb_next(e);
246 }
247
248 hashtb_end(e);
249
akmhoque53f64222012-09-05 13:57:51 -0500250 printf("\n");
251}
252
akmhoque03004e62012-09-06 01:12:28 -0500253
254void
255build_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 -0500256{
akmhoque03004e62012-09-06 01:12:28 -0500257 printf("build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500258
akmhoque03004e62012-09-06 01:12:28 -0500259 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
260 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
261 print_name_lsa(name_lsa);
262 install_name_lsa(name_lsa);
263 print_name_lsdb();
akmhoque53f64222012-09-05 13:57:51 -0500264
akmhoque53f64222012-09-05 13:57:51 -0500265
akmhoque03004e62012-09-06 01:12:28 -0500266 free(name_lsa->header->orig_router->name);
267 free(name_lsa->header->orig_router);
268 free(name_lsa->header);
269 free(name_lsa->name_prefix->name);
270 free(name_lsa->name_prefix);
271 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500272
273}
274
275void
akmhoque03004e62012-09-06 01:12:28 -0500276build_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 -0500277{
akmhoque03004e62012-09-06 01:12:28 -0500278 printf("build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500279
akmhoque03004e62012-09-06 01:12:28 -0500280 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
281 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500282
akmhoque03004e62012-09-06 01:12:28 -0500283 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
284 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
285 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500286
akmhoque03004e62012-09-06 01:12:28 -0500287 name_lsa->header->ls_id=ls_id;
288 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
289 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
290 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
291 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
292 name_lsa->header->orig_router->length=strlen(orig_router)+1;
293 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500294
akmhoque03004e62012-09-06 01:12:28 -0500295 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
296 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
297 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
298 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
299 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400300}
akmhoqued79438d2012-08-27 13:31:42 -0500301
302
akmhoque53f64222012-09-05 13:57:51 -0500303void
304make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500305{
akmhoque53f64222012-09-05 13:57:51 -0500306 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
307 memcpy(key+strlen(key),"/",1);
308 char ls_type[2];
309 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
310 memcpy(key+strlen(key),ls_type,strlen(ls_type));
311 key[strlen(key)]='\0';
312}
313
akmhoque03004e62012-09-06 01:12:28 -0500314int
315build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
316{
317 printf("build_and_install_adj_lsa called \n");
318
319 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
320
321 if(nlsr->adj_build_flag > 0)
322 {
323 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
324 if ( is_adj_lsa_build()> 0)
325 {
326 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
327 build_adj_lsa(adj_lsa);
328 install_adj_lsa(adj_lsa);
329
330 free(adj_lsa->header->orig_router->name);
331 free(adj_lsa->header->orig_router);
332 free(adj_lsa->header->orig_time);
333 free(adj_lsa->header);
334 free(adj_lsa->body);
335 free(adj_lsa);
336 nlsr->adj_build_flag=0;
337 print_adj_lsdb();
338 }
339 else
340 {
341 printf("Can not build adj LSA now\n");
342 }
343 }
344 nlsr->is_build_adj_lsa_sheduled=0;
345 return 0;
346}
347
348
349void
350build_adj_lsa(struct alsa * adj_lsa)
351{
352 printf("build_adj_lsa called \n");
353
354 int no_link=no_active_nbr();
355 printf("Number of link in Adjacent LSA: %d\n",no_link);
356
357 /*Filling Up Header Data */
358 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
359 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
360 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
361 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
362 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
363 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
364
365 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
366
367 char *time_stamp=(char *)malloc(20);
368 memset(time_stamp,0,20);
369 get_current_timestamp_micro(time_stamp);
370
371 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
372 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
373 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
374 free(time_stamp);
375
376
377 /* Filling Up Body Data */
378
379 adj_lsa->no_link=no_link;
380/*
381 struct link *templ=(struct link *)malloc(2*sizeof(struct link));
382 adj_lsa->links=templ;
383
384 int i, adl_element;
385 struct ndn_neighbor *nbr;
386 struct hashtb_enumerator ee;
387 struct hashtb_enumerator *e = &ee;
388 hashtb_start(nlsr->adl, e);
389 adl_element=hashtb_n(nlsr->adl);
390
391 for(i=0;i<adl_element;i++)
392 {
393 nbr=e->data;
394 if( nbr->status == 1 )
395 {
396 struct link *temp=(struct link *)malloc(sizeof(struct link));
397 temp->nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix));
398 temp->nbr->name=(char *)malloc(nbr->neighbor->length);
399 memset(temp->nbr->name,0,nbr->neighbor->length);
400 memcpy(temp->nbr->name,nbr->neighbor->name,nbr->neighbor->length);
401
402 temp->nbr->length=nbr->neighbor->length;
403 temp->face=nbr->face;
404 temp->metric=nbr->metric;
405
406 templ=temp;
407 templ++;
408 }
409 hashtb_next(e);
410 }
411
412 hashtb_end(e);
413*/
414
415
416 struct ccn_charbuf *c=ccn_charbuf_create();
417 get_active_nbr_adj_data(c);
418 char *data=ccn_charbuf_as_string(c);
419
420 adj_lsa->body=(char *)malloc(strlen(data)+1);
421 memset(adj_lsa->body,0,strlen(data)+1);
422 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
423 ccn_charbuf_destroy(&c);
424
425
426
427 if( !nlsr->is_send_lsdb_interest_scheduled )
428 {
429 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
430 nlsr->is_send_lsdb_interest_scheduled=1;
431 }
432
433 nlsr->adj_build_count++;
434
435
436}
437
438
akmhoque53f64222012-09-05 13:57:51 -0500439void
440install_adj_lsa(struct alsa * adj_lsa)
441{
akmhoqued79438d2012-08-27 13:31:42 -0500442 printf("install_adj_lsa called \n");
443
akmhoque53f64222012-09-05 13:57:51 -0500444 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
445 memset(key,0,adj_lsa->header->orig_router->length+2);
446 make_adj_lsa_key(key,adj_lsa);
447 printf("Adjacent LSA key: %s \n",key);
akmhoque03004e62012-09-06 01:12:28 -0500448
akmhoque53f64222012-09-05 13:57:51 -0500449 struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
450
451 struct hashtb_enumerator ee;
452 struct hashtb_enumerator *e = &ee;
453 int res;
454
455 hashtb_start(nlsr->lsdb->adj_lsdb, e);
456 res = hashtb_seek(e, key, strlen(key), 0);
457
akmhoque03004e62012-09-06 01:12:28 -0500458
akmhoque53f64222012-09-05 13:57:51 -0500459
460 if(res == HT_NEW_ENTRY )
461 {
462 printf("New ADJ LSA... Adding to LSDB\n");
463 new_adj_lsa = e->data;
464
465 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
466 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
467 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
468 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
469
470 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
471 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
472 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
473 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500474
akmhoque03004e62012-09-06 01:12:28 -0500475 new_adj_lsa->no_link=adj_lsa->no_link;
476
akmhoque53f64222012-09-05 13:57:51 -0500477 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
478 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
479 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
480
akmhoque03004e62012-09-06 01:12:28 -0500481 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500482 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500483 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
484
akmhoque53f64222012-09-05 13:57:51 -0500485
486 }
487 else if(res == HT_OLD_ENTRY)
488 {
489 new_adj_lsa = e->data;
490 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
491 {
492 printf("Older/Duplicate Adj LSA. Discarded...\n");
493 }
494 else
495 {
496 new_adj_lsa = e->data;
497
498 free(new_adj_lsa->header->orig_time);
499 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
500 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 -0500501
akmhoque03004e62012-09-06 01:12:28 -0500502 new_adj_lsa->no_link=adj_lsa->no_link;
503
akmhoque53f64222012-09-05 13:57:51 -0500504 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
505 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
506 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
507
akmhoque03004e62012-09-06 01:12:28 -0500508 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500509 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500510 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500511
512 }
513
514 }
akmhoque53f64222012-09-05 13:57:51 -0500515 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500516
akmhoque29c1db52012-09-07 14:47:43 -0500517 if ( !nlsr->is_route_calculation_scheduled )
518 {
519 nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0);
520 nlsr->is_route_calculation_scheduled=1;
521 }
akmhoque53f64222012-09-05 13:57:51 -0500522 free(key);
523}
524
525void
526print_adj_lsa_body(const char *body, int no_link)
527{
528 int i=0;
529 char *lsa_data=(char *)malloc(strlen(body)+1);
530 memset( lsa_data,0,strlen(body)+1);
531 memcpy(lsa_data,body,strlen(body)+1);
532 char *sep="|";
533 char *rem;
534 char *rtr_id;
535 char *length;
536 char *face;
537 char *metric;
538
akmhoque53f64222012-09-05 13:57:51 -0500539 if(no_link >0 )
540 {
541 rtr_id=strtok_r(lsa_data,sep,&rem);
542 length=strtok_r(NULL,sep,&rem);
543 face=strtok_r(NULL,sep,&rem);
544 metric=strtok_r(NULL,sep,&rem);
545
546 printf(" Link %d \n",i+1);
547 printf(" Neighbor : %s \n",rtr_id);
548 printf(" Neighbor Length : %s \n",length);
549 printf(" Connecting Face : %s \n",face);
550 printf(" Metric : %s \n",metric);
akmhoque03004e62012-09-06 01:12:28 -0500551
akmhoque53f64222012-09-05 13:57:51 -0500552
553 for(i=1;i<no_link;i++)
554 {
555 rtr_id=strtok_r(NULL,sep,&rem);
556 length=strtok_r(NULL,sep,&rem);
557 face=strtok_r(NULL,sep,&rem);
558 metric=strtok_r(NULL,sep,&rem);
559 printf(" Link %d \n",i+1);
560 printf(" Neighbor : %s \n",rtr_id);
561 printf(" Neighbor Length : %s \n",length);
562 printf(" Connecting Face : %s \n",face);
563 printf(" Metric : %s \n",metric);
564
565 }
566 }
567
568 free(lsa_data);
569}
570
571void
572print_adj_lsa(struct alsa * adj_lsa)
573{
akmhoque03004e62012-09-06 01:12:28 -0500574
akmhoque53f64222012-09-05 13:57:51 -0500575 printf("print_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500576
akmhoque53f64222012-09-05 13:57:51 -0500577 printf("-----------ADJ LSA Content---------------\n");
578 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
579 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
580 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
581 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
akmhoque03004e62012-09-06 01:12:28 -0500582 printf(" Lsa Data:\n");
583 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500584
585 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500586
akmhoque03004e62012-09-06 01:12:28 -0500587/*
588 struct link *templ=adj_lsa->links;
589 int i;
590
591 for(i=0 ; i< adj_lsa->no_link ; i++)
592 {
593 printf(" Link %d \n",i+1);
594 printf(" Neighbor : %s \n",templ->nbr->name);
595 printf(" Neighbor Length : %d \n",templ->nbr->length);
596 printf(" Connecting Face : %d \n",templ->face);
597 printf(" Metric : %d \n",templ->metric);
598
599 templ++;
600 }
601*/
akmhoque53f64222012-09-05 13:57:51 -0500602 printf("\n");
603
604}
605
606void
607print_adj_lsdb(void)
608{
609 printf("print_name_lsdb called \n");
610 int i, adj_lsdb_element;
611 struct alsa *adj_lsa;
612
613 struct hashtb_enumerator ee;
614 struct hashtb_enumerator *e = &ee;
615
616 hashtb_start(nlsr->lsdb->adj_lsdb, e);
617 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
618
619 for(i=0;i<adj_lsdb_element;i++)
620 {
621 printf("-----------Adj LSA (%d)---------------\n",i+1);
622 adj_lsa=e->data;
623 print_adj_lsa(adj_lsa);
624 hashtb_next(e);
625 }
626
627 hashtb_end(e);
628
629 printf("\n");
akmhoque53f64222012-09-05 13:57:51 -0500630}
631
632void
akmhoque03004e62012-09-06 01:12:28 -0500633build_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 -0500634{
akmhoque03004e62012-09-06 01:12:28 -0500635 printf("build_and_install_others_adj_lsa called \n");
636 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
637 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
638 //print_adj_lsa(adj_lsa);
639 install_adj_lsa(adj_lsa);
640
akmhoque53f64222012-09-05 13:57:51 -0500641
akmhoque03004e62012-09-06 01:12:28 -0500642 free(adj_lsa->header->orig_router->name);
643 free(adj_lsa->header->orig_router);
644 free(adj_lsa->header->orig_time);
645 free(adj_lsa->header);
646 free(adj_lsa->body);
647 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500648
akmhoque03004e62012-09-06 01:12:28 -0500649 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -0500650
akmhoque53f64222012-09-05 13:57:51 -0500651}
652
akmhoque03004e62012-09-06 01:12:28 -0500653
akmhoque53f64222012-09-05 13:57:51 -0500654void
akmhoque03004e62012-09-06 01:12:28 -0500655build_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 -0500656{
akmhoque03004e62012-09-06 01:12:28 -0500657 printf("build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500658
akmhoque03004e62012-09-06 01:12:28 -0500659 /*Filling Up Header Data */
660 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
661 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
662 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
663 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
664 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -0500665
akmhoque03004e62012-09-06 01:12:28 -0500666 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -0500667
akmhoque53f64222012-09-05 13:57:51 -0500668
akmhoque03004e62012-09-06 01:12:28 -0500669 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -0500670
akmhoque03004e62012-09-06 01:12:28 -0500671 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
672 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
673 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500674
akmhoque03004e62012-09-06 01:12:28 -0500675 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -0500676
akmhoque03004e62012-09-06 01:12:28 -0500677 adj_lsa->body=(char *)malloc(strlen(data)+1);
678 memset(adj_lsa->body,0,strlen(data)+1);
679 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -0500680
akmhoque53f64222012-09-05 13:57:51 -0500681}
682
akmhoque03004e62012-09-06 01:12:28 -0500683
akmhoque53f64222012-09-05 13:57:51 -0500684long int
685get_name_lsdb_num_element(void)
686{
687 long int num_element;
688
689
690 struct hashtb_enumerator ee;
691 struct hashtb_enumerator *e = &ee;
692
693 hashtb_start(nlsr->lsdb->name_lsdb, e);
694 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
695 hashtb_end(e);
696
697 return num_element;
698}
699
700long int
701get_adj_lsdb_num_element(void)
702{
703 long int num_element;
704
705
706 struct hashtb_enumerator ee;
707 struct hashtb_enumerator *e = &ee;
708
709 hashtb_start(nlsr->lsdb->adj_lsdb, e);
710 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
711 hashtb_end(e);
712
713 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -0500714}
akmhoque03004e62012-09-06 01:12:28 -0500715
716void
717get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
718{
719 printf("get_name_lsdb_summary called \n");
720 int i, name_lsdb_element;
721
722 struct nlsa *name_lsa;
723 struct hashtb_enumerator ee;
724 struct hashtb_enumerator *e = &ee;
725
726 hashtb_start(nlsr->lsdb->name_lsdb, e);
727 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
728
729 for(i=0;i<name_lsdb_element;i++)
730 {
731 name_lsa=e->data;
732
733 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name);
734 ccn_charbuf_append_string(name_lsdb_data,"|");
735
736 char *lst=(char *)malloc(20);
737 memset(lst,0,20);
738 sprintf(lst,"%d",name_lsa->header->ls_type);
739 ccn_charbuf_append_string(name_lsdb_data,lst);
740 free(lst);
741 ccn_charbuf_append_string(name_lsdb_data,"|");
742
743 char *lsid=(char *)malloc(20);
744 memset(lsid,0,20);
745 sprintf(lsid,"%ld",name_lsa->header->ls_id);
746 ccn_charbuf_append_string(name_lsdb_data,lsid);
747 free(lsid);
748 ccn_charbuf_append_string(name_lsdb_data,"|");
749
750 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time);
751 ccn_charbuf_append_string(name_lsdb_data,"|");
752
753 hashtb_next(e);
754 }
755
756 hashtb_end(e);
757
758}
759
760
761void
762get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data)
763{
764 printf("get_adj_lsdb_summary called \n");
765 int i, adj_lsdb_element;
766 struct alsa *adj_lsa;
767
768 struct hashtb_enumerator ee;
769 struct hashtb_enumerator *e = &ee;
770
771 hashtb_start(nlsr->lsdb->adj_lsdb, e);
772 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
773
774 for(i=0;i<adj_lsdb_element;i++)
775 {
776 adj_lsa=e->data;
777
778 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name);
779 ccn_charbuf_append_string(adj_lsdb_data,"|");
780
781 char *lst=(char *)malloc(20);
782 memset(lst,0,20);
783 sprintf(lst,"%d",adj_lsa->header->ls_type);
784 ccn_charbuf_append_string(adj_lsdb_data,lst);
785 free(lst);
786 ccn_charbuf_append_string(adj_lsdb_data,"|");
787
788 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time);
789 ccn_charbuf_append_string(adj_lsdb_data,"|");
790
791 hashtb_next(e);
792 }
793
794 hashtb_end(e);
795}
796
797
798void
799get_lsdb_summary(struct ccn_charbuf *lsdb_data)
800{
801 struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create();
802 struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create();
803
804 get_name_lsdb_summary(name_lsdb_data);
805 get_adj_lsdb_summary(adj_lsdb_data);
806
807 long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element();
808 char *num_element=(char *)malloc(15);
809 memset(num_element,0,15);
810 sprintf(num_element,"%ld",num_lsa);
811
812 if( num_lsa > 0)
813 {
814 ccn_charbuf_append_string(lsdb_data,num_element);
815 ccn_charbuf_append_string(lsdb_data,"|");
816 }
817 if(name_lsdb_data->length>0)
818 {
819 char *data1=ccn_charbuf_as_string(name_lsdb_data);
820 ccn_charbuf_append_string(lsdb_data,(char *)data1);
821 }
822 if(adj_lsdb_data->length>0)
823 {
824 char *data2=ccn_charbuf_as_string(adj_lsdb_data);
825 ccn_charbuf_append_string(lsdb_data,(char *)data2);
826 }
827 ccn_charbuf_destroy(&name_lsdb_data);
828 ccn_charbuf_destroy(&adj_lsdb_data);
829 free(num_element);
830
831}
832
833int
834check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
835{
836 int ret=0;
837 struct ccn_charbuf *key=ccn_charbuf_create();
838 ccn_charbuf_append_string(key,orig_router);
839 ccn_charbuf_append_string(key,"/");
840 ccn_charbuf_append_string(key,lst);
841 ccn_charbuf_append_string(key,"/");
842 ccn_charbuf_append_string(key,lsid);
843
844 int res;
845 struct nlsa *name_lsa;
846
847 struct hashtb_enumerator ee;
848 struct hashtb_enumerator *e = &ee;
849
850 hashtb_start(nlsr->lsdb->name_lsdb, e);
851 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
852
853 if( res == HT_NEW_ENTRY )
854 {
855 hashtb_delete(e);
856 ret=1;
857
858 }
859 else if(res == HT_OLD_ENTRY)
860 {
861 name_lsa=e->data;
862 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
863 {
864 ret=1;
865 }
866 }
867
868 hashtb_end(e);
869
870 ccn_charbuf_destroy(&key);
871
872 return ret;
873}
874
875int
876check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
877{
878 int ret=0;
879 struct ccn_charbuf *key=ccn_charbuf_create();
880 ccn_charbuf_append_string(key,orig_router);
881 ccn_charbuf_append_string(key,"/");
882 ccn_charbuf_append_string(key,lst);
883
884 int res;
885 struct alsa *adj_lsa;
886
887 struct hashtb_enumerator ee;
888 struct hashtb_enumerator *e = &ee;
889
890 hashtb_start(nlsr->lsdb->adj_lsdb, e);
891 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
892
893 if( res == HT_NEW_ENTRY )
894 {
895 hashtb_delete(e);
896 ret=1;
897
898 }
899 else if(res == HT_OLD_ENTRY)
900 {
901 adj_lsa=e->data;
902 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
903 {
904 ret=1;
905 }
906 }
907
908 hashtb_end(e);
909
910 ccn_charbuf_destroy(&key);
911
912 return ret;
913}
914
915void
916get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
917{
918 printf("get_name_lsa_data called \n");
919
920 struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
921
922 struct hashtb_enumerator ee;
923 struct hashtb_enumerator *e = &ee;
924 int res;
925
926 hashtb_start(nlsr->lsdb->name_lsdb, e);
927 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
928
929 if( res == HT_OLD_ENTRY )
930 {
931 name_lsa=e->data;
932 printf("NAME LSA found\n");
933
934 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
935 ccn_charbuf_append_string(lsa_data,"|");
936
937 char *temp_length=(char *)malloc(20);
938 memset(temp_length,0,20);
939 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
940 ccn_charbuf_append_string(lsa_data,temp_length);
941 free(temp_length);
942 ccn_charbuf_append_string(lsa_data,"|");
943
944 char *temp_ltype=(char *)malloc(20);
945 memset(temp_ltype,0,20);
946 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
947 ccn_charbuf_append_string(lsa_data,temp_ltype);
948 free(temp_ltype);
949 ccn_charbuf_append_string(lsa_data,"|");
950
951 char *temp_lsid=(char *)malloc(20);
952 memset(temp_lsid,0,20);
953 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
954 ccn_charbuf_append_string(lsa_data,temp_lsid);
955 free(temp_lsid);
956 ccn_charbuf_append_string(lsa_data,"|");
957
958 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
959 ccn_charbuf_append_string(lsa_data,"|");
960
961 char *temp_valid=(char *)malloc(20);
962 memset(temp_valid,0,20);
963 sprintf(temp_valid,"%d",name_lsa->header->isValid);
964 ccn_charbuf_append_string(lsa_data,temp_valid);
965 free(temp_valid);
966 ccn_charbuf_append_string(lsa_data,"|");
967
968 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
969 ccn_charbuf_append_string(lsa_data,"|");
970
971 char *temp_npl=(char *)malloc(20);
972 memset(temp_npl,0,20);
973 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
974 ccn_charbuf_append_string(lsa_data,temp_npl);
975 free(temp_npl);
976 ccn_charbuf_append_string(lsa_data,"|");
977
978 }
979 else if(res == HT_NEW_ENTRY)
980 {
981 hashtb_delete(e);
982 }
983
984 hashtb_end(e);
985}
986
987void
988get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
989{
990 printf("get_adj_lsa_data called \n");
991
992 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
993
994 struct hashtb_enumerator ee;
995 struct hashtb_enumerator *e = &ee;
996 int res;
997
998 hashtb_start(nlsr->lsdb->adj_lsdb, e);
999 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
1000
1001 if( res == HT_OLD_ENTRY )
1002 {
1003 adj_lsa=e->data;
1004 printf("NAME LSA found\n");
1005
1006 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1007 ccn_charbuf_append_string(lsa_data,"|");
1008
1009 char *temp_length=(char *)malloc(20);
1010 memset(temp_length,0,20);
1011 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1012 ccn_charbuf_append_string(lsa_data,temp_length);
1013 free(temp_length);
1014 ccn_charbuf_append_string(lsa_data,"|");
1015
1016 char *temp_ltype=(char *)malloc(20);
1017 memset(temp_ltype,0,20);
1018 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1019 ccn_charbuf_append_string(lsa_data,temp_ltype);
1020 free(temp_ltype);
1021 ccn_charbuf_append_string(lsa_data,"|");
1022
1023 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1024 ccn_charbuf_append_string(lsa_data,"|");
1025
1026 char *temp_nl=(char *)malloc(20);
1027 memset(temp_nl,0,20);
1028 sprintf(temp_nl,"%d",adj_lsa->no_link);
1029 ccn_charbuf_append_string(lsa_data,temp_nl);
1030 free(temp_nl);
1031 ccn_charbuf_append_string(lsa_data,"|");
1032
1033 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1034
1035
1036 }
1037 else if(res == HT_NEW_ENTRY)
1038 {
1039 hashtb_delete(e);
1040 }
1041
1042 hashtb_end(e);
1043}