blob: 29c7440b80be932ef0128f7c48f15a604fe0a709 [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"
akmhoque438b07e2012-08-21 10:13:57 -040026
akmhoquef71d9082012-08-22 12:51:53 -040027void
akmhoque53f64222012-09-05 13:57:51 -050028set_new_lsdb_version(void)
akmhoquef71d9082012-08-22 12:51:53 -040029{
akmhoquef71d9082012-08-22 12:51:53 -040030
akmhoque03004e62012-09-06 01:12:28 -050031 char *time_stamp=(char *)malloc(20);
32 memset(time_stamp,0,20);
33 get_current_timestamp_micro(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040034
akmhoque03004e62012-09-06 01:12:28 -050035 free(nlsr->lsdb->lsdb_version);
36 nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
37 memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1);
38 memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
39
40 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050041
akmhoquef71d9082012-08-22 12:51:53 -040042}
43
akmhoque03004e62012-09-06 01:12:28 -050044void
45make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
46{
47
48
49 printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id);
50
51 char lst[2];
52 memset(lst,0,2);
53 sprintf(lst,"%d",ls_type);
54
55 char lsid[10];
56 memset(lsid,0,10);
57 sprintf(lsid,"%ld",ls_id);
58
59 memcpy(key+strlen(key),orig_router,strlen(orig_router));
60 memcpy(key+strlen(key),"/",1);
61 memcpy(key+strlen(key),lst,strlen(lst));
62 memcpy(key+strlen(key),"/",1);
63 memcpy(key+strlen(key),lsid,strlen(lsid));
64
65 printf("Key: %s\n",key);
66
67}
akmhoque53f64222012-09-05 13:57:51 -050068
akmhoquef71d9082012-08-22 12:51:53 -040069void
akmhoque53f64222012-09-05 13:57:51 -050070build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -040071{
akmhoque53f64222012-09-05 13:57:51 -050072 printf("build_and_install_name_lsas called \n");
akmhoquef71d9082012-08-22 12:51:53 -040073
akmhoquef71d9082012-08-22 12:51:53 -040074 int i, npl_element;
75 struct name_prefix *np;
76
77 struct hashtb_enumerator ee;
78 struct hashtb_enumerator *e = &ee;
79
80 hashtb_start(nlsr->npl, e);
81 npl_element=hashtb_n(nlsr->npl);
82
83 for(i=0;i<npl_element;i++)
84 {
85 np=e->data;
akmhoque53f64222012-09-05 13:57:51 -050086 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
87 build_name_lsa(name_lsa,np);
akmhoque03004e62012-09-06 01:12:28 -050088
akmhoquef71d9082012-08-22 12:51:53 -040089 install_name_lsa(name_lsa);
akmhoque03004e62012-09-06 01:12:28 -050090 free(name_lsa->header->orig_router->name);
91 free(name_lsa->header->orig_router);
92 free(name_lsa->header);
93 free(name_lsa->name_prefix->name);
94 free(name_lsa->name_prefix);
akmhoquef71d9082012-08-22 12:51:53 -040095 free(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -040096 hashtb_next(e);
97 }
98
akmhoque53f64222012-09-05 13:57:51 -050099 hashtb_end(e);
akmhoquef71d9082012-08-22 12:51:53 -0400100
akmhoquef71d9082012-08-22 12:51:53 -0400101}
102
akmhoque53f64222012-09-05 13:57:51 -0500103void
104build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
105{
akmhoque53f64222012-09-05 13:57:51 -0500106 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
107 name_lsa->header->ls_type=LS_TYPE_NAME;
108
akmhoque03004e62012-09-06 01:12:28 -0500109 char *time_stamp=(char *)malloc(20);
110 memset(time_stamp,0,20);
111 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500112
akmhoque03004e62012-09-06 01:12:28 -0500113 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500114 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
115 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500116
117 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500118
119 name_lsa->header->ls_id=++nlsr->nlsa_id;
120 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500121 name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
122 memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
123 memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
124 name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
akmhoque53f64222012-09-05 13:57:51 -0500125 name_lsa->header->isValid=1;
126
127
128 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
129 name_lsa->name_prefix->name=(char *)malloc(np->length);
130 memcpy(name_lsa->name_prefix->name,np->name,np->length);
131 name_lsa->name_prefix->length=np->length;
132
133}
134
akmhoque53f64222012-09-05 13:57:51 -0500135void
136install_name_lsa(struct nlsa *name_lsa)
137{
akmhoque53f64222012-09-05 13:57:51 -0500138
akmhoque03004e62012-09-06 01:12:28 -0500139 char lst[2];
140 memset(lst,0,2);
141 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoque53f64222012-09-05 13:57:51 -0500142
akmhoque03004e62012-09-06 01:12:28 -0500143 char lsid[10];
144 memset(lsid,0,10);
145 sprintf(lsid,"%ld",name_lsa->header->ls_id);
146
147
148 char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
149 memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1);
150
151
152 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 -0500153 printf("Key:%s Length:%d\n",key,(int)strlen(key));
154
akmhoque03004e62012-09-06 01:12:28 -0500155 struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free
akmhoque53f64222012-09-05 13:57:51 -0500156
157 struct hashtb_enumerator ee;
158 struct hashtb_enumerator *e = &ee;
159 int res;
160
161 hashtb_start(nlsr->lsdb->name_lsdb, e);
162 res = hashtb_seek(e, key, strlen(key), 0);
163
164 if(res == HT_NEW_ENTRY )
165 {
166 printf("New Name LSA... Adding to LSDB\n");
167 new_name_lsa = e->data;
168
akmhoque03004e62012-09-06 01:12:28 -0500169 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free
akmhoque53f64222012-09-05 13:57:51 -0500170 new_name_lsa->header->ls_type=name_lsa->header->ls_type;
171
172 new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1);
akmhoque03004e62012-09-06 01:12:28 -0500173 memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500174 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
175
akmhoque53f64222012-09-05 13:57:51 -0500176 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque03004e62012-09-06 01:12:28 -0500177 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque53f64222012-09-05 13:57:51 -0500178 new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length);
179 memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length);
180 new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length;
181 new_name_lsa->header->isValid=name_lsa->header->isValid;
182
183
akmhoque03004e62012-09-06 01:12:28 -0500184 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque53f64222012-09-05 13:57:51 -0500185 new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length);
186 memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length);
187 new_name_lsa->name_prefix->length=name_lsa->name_prefix->length;
188
189 printf("New Name LSA Added....\n");
190
akmhoque03004e62012-09-06 01:12:28 -0500191 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500192 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500193 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500194
195 }
196 else if(res == HT_OLD_ENTRY)
197 {
198 printf("Duplicate Name LSA. Discarded...\n");
199
200 }
201
202 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500203
204 free(key);
akmhoque53f64222012-09-05 13:57:51 -0500205}
206
207
akmhoque03004e62012-09-06 01:12:28 -0500208void
209print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500210{
211
akmhoque03004e62012-09-06 01:12:28 -0500212 printf("-----------Name LSA Content---------------\n");
213 printf(" Origination Router : %s\n",name_lsa->header->orig_router->name);
214 printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length);
215 printf(" LS Type : %d\n",name_lsa->header->ls_type);
216 printf(" LS Id : %ld\n",name_lsa->header->ls_id);
217 printf(" Origination Time : %s\n",name_lsa->header->orig_time);
218 printf(" Is Valid : %d\n",name_lsa->header->isValid);
219 printf(" LSA Data \n");
220 printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name);
221 printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length);
akmhoque53f64222012-09-05 13:57:51 -0500222
akmhoque03004e62012-09-06 01:12:28 -0500223 printf("\n");
akmhoquef71d9082012-08-22 12:51:53 -0400224}
225
226void
227print_name_lsdb(void)
228{
229 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500230 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400231 struct nlsa *name_lsa;
232
233 struct hashtb_enumerator ee;
234 struct hashtb_enumerator *e = &ee;
235
236 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500237 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400238
akmhoque53f64222012-09-05 13:57:51 -0500239 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400240 {
akmhoque53f64222012-09-05 13:57:51 -0500241 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400242 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500243 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400244 hashtb_next(e);
245 }
246
247 hashtb_end(e);
248
akmhoque53f64222012-09-05 13:57:51 -0500249 printf("\n");
250}
251
akmhoque03004e62012-09-06 01:12:28 -0500252
253void
254build_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 -0500255{
akmhoque03004e62012-09-06 01:12:28 -0500256 printf("build_and_install_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500257
akmhoque03004e62012-09-06 01:12:28 -0500258 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
259 build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np);
260 print_name_lsa(name_lsa);
261 install_name_lsa(name_lsa);
262 print_name_lsdb();
akmhoque53f64222012-09-05 13:57:51 -0500263
akmhoque53f64222012-09-05 13:57:51 -0500264
akmhoque03004e62012-09-06 01:12:28 -0500265 free(name_lsa->header->orig_router->name);
266 free(name_lsa->header->orig_router);
267 free(name_lsa->header);
268 free(name_lsa->name_prefix->name);
269 free(name_lsa->name_prefix);
270 free(name_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500271
272}
273
274void
akmhoque03004e62012-09-06 01:12:28 -0500275build_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 -0500276{
akmhoque03004e62012-09-06 01:12:28 -0500277 printf("build_others_name_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500278
akmhoque03004e62012-09-06 01:12:28 -0500279 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
280 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500281
akmhoque03004e62012-09-06 01:12:28 -0500282 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
283 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
284 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500285
akmhoque03004e62012-09-06 01:12:28 -0500286 name_lsa->header->ls_id=ls_id;
287 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
288 name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
289 memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1);
290 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
291 name_lsa->header->orig_router->length=strlen(orig_router)+1;
292 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500293
akmhoque03004e62012-09-06 01:12:28 -0500294 name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
295 name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1);
296 memset(name_lsa->name_prefix->name,0,strlen(np)+1);
297 memcpy(name_lsa->name_prefix->name,np,strlen(np)+1);
298 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400299}
akmhoqued79438d2012-08-27 13:31:42 -0500300
301
akmhoque53f64222012-09-05 13:57:51 -0500302void
303make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500304{
akmhoque53f64222012-09-05 13:57:51 -0500305 memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
306 memcpy(key+strlen(key),"/",1);
307 char ls_type[2];
308 sprintf(ls_type,"%d",adj_lsa->header->ls_type);
309 memcpy(key+strlen(key),ls_type,strlen(ls_type));
310 key[strlen(key)]='\0';
311}
312
akmhoque03004e62012-09-06 01:12:28 -0500313int
314build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
315{
316 printf("build_and_install_adj_lsa called \n");
317
318 printf("adj_build_flag = %d \n",nlsr->adj_build_flag);
319
320 if(nlsr->adj_build_flag > 0)
321 {
322 printf("is_adj_lsa_build = %d \n",is_adj_lsa_build());
323 if ( is_adj_lsa_build()> 0)
324 {
325 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
326 build_adj_lsa(adj_lsa);
327 install_adj_lsa(adj_lsa);
328
329 free(adj_lsa->header->orig_router->name);
330 free(adj_lsa->header->orig_router);
331 free(adj_lsa->header->orig_time);
332 free(adj_lsa->header);
333 free(adj_lsa->body);
334 free(adj_lsa);
335 nlsr->adj_build_flag=0;
336 print_adj_lsdb();
337 }
338 else
339 {
340 printf("Can not build adj LSA now\n");
341 }
342 }
343 nlsr->is_build_adj_lsa_sheduled=0;
344 return 0;
345}
346
347
348void
349build_adj_lsa(struct alsa * adj_lsa)
350{
351 printf("build_adj_lsa called \n");
352
353 int no_link=no_active_nbr();
354 printf("Number of link in Adjacent LSA: %d\n",no_link);
355
356 /*Filling Up Header Data */
357 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
358 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
359 adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1);
360 memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1);
361 memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1);
362 adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1;
363
364 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
365
366 char *time_stamp=(char *)malloc(20);
367 memset(time_stamp,0,20);
368 get_current_timestamp_micro(time_stamp);
369
370 adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1);
371 memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1);
372 memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
373 free(time_stamp);
374
375
376 /* Filling Up Body Data */
377
378 adj_lsa->no_link=no_link;
379/*
380 struct link *templ=(struct link *)malloc(2*sizeof(struct link));
381 adj_lsa->links=templ;
382
383 int i, adl_element;
384 struct ndn_neighbor *nbr;
385 struct hashtb_enumerator ee;
386 struct hashtb_enumerator *e = &ee;
387 hashtb_start(nlsr->adl, e);
388 adl_element=hashtb_n(nlsr->adl);
389
390 for(i=0;i<adl_element;i++)
391 {
392 nbr=e->data;
393 if( nbr->status == 1 )
394 {
395 struct link *temp=(struct link *)malloc(sizeof(struct link));
396 temp->nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix));
397 temp->nbr->name=(char *)malloc(nbr->neighbor->length);
398 memset(temp->nbr->name,0,nbr->neighbor->length);
399 memcpy(temp->nbr->name,nbr->neighbor->name,nbr->neighbor->length);
400
401 temp->nbr->length=nbr->neighbor->length;
402 temp->face=nbr->face;
403 temp->metric=nbr->metric;
404
405 templ=temp;
406 templ++;
407 }
408 hashtb_next(e);
409 }
410
411 hashtb_end(e);
412*/
413
414
415 struct ccn_charbuf *c=ccn_charbuf_create();
416 get_active_nbr_adj_data(c);
417 char *data=ccn_charbuf_as_string(c);
418
419 adj_lsa->body=(char *)malloc(strlen(data)+1);
420 memset(adj_lsa->body,0,strlen(data)+1);
421 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
422 ccn_charbuf_destroy(&c);
423
424
425
426 if( !nlsr->is_send_lsdb_interest_scheduled )
427 {
428 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0);
429 nlsr->is_send_lsdb_interest_scheduled=1;
430 }
431
432 nlsr->adj_build_count++;
433
434
435}
436
437
akmhoque53f64222012-09-05 13:57:51 -0500438void
439install_adj_lsa(struct alsa * adj_lsa)
440{
akmhoqued79438d2012-08-27 13:31:42 -0500441 printf("install_adj_lsa called \n");
442
akmhoque53f64222012-09-05 13:57:51 -0500443 char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2);
444 memset(key,0,adj_lsa->header->orig_router->length+2);
445 make_adj_lsa_key(key,adj_lsa);
446 printf("Adjacent LSA key: %s \n",key);
akmhoque03004e62012-09-06 01:12:28 -0500447
akmhoque53f64222012-09-05 13:57:51 -0500448 struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
449
450 struct hashtb_enumerator ee;
451 struct hashtb_enumerator *e = &ee;
452 int res;
453
454 hashtb_start(nlsr->lsdb->adj_lsdb, e);
455 res = hashtb_seek(e, key, strlen(key), 0);
456
akmhoque03004e62012-09-06 01:12:28 -0500457
akmhoque53f64222012-09-05 13:57:51 -0500458
459 if(res == HT_NEW_ENTRY )
460 {
461 printf("New ADJ LSA... Adding to LSDB\n");
462 new_adj_lsa = e->data;
463
464 new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
465 new_adj_lsa->header->ls_type=adj_lsa->header->ls_type;
466 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
467 memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1);
468
469 new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
470 new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length);
471 memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length);
472 new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length;
akmhoque53f64222012-09-05 13:57:51 -0500473
akmhoque03004e62012-09-06 01:12:28 -0500474 new_adj_lsa->no_link=adj_lsa->no_link;
475
akmhoque53f64222012-09-05 13:57:51 -0500476 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
477 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
478 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
479
akmhoque03004e62012-09-06 01:12:28 -0500480 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500481 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500482 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
483
akmhoque53f64222012-09-05 13:57:51 -0500484
485 }
486 else if(res == HT_OLD_ENTRY)
487 {
488 new_adj_lsa = e->data;
489 if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0)
490 {
491 printf("Older/Duplicate Adj LSA. Discarded...\n");
492 }
493 else
494 {
495 new_adj_lsa = e->data;
496
497 free(new_adj_lsa->header->orig_time);
498 new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1);
499 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 -0500500
akmhoque03004e62012-09-06 01:12:28 -0500501 new_adj_lsa->no_link=adj_lsa->no_link;
502
akmhoque53f64222012-09-05 13:57:51 -0500503 new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1);
504 memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
505 memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
506
akmhoque03004e62012-09-06 01:12:28 -0500507 printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500508 set_new_lsdb_version();
akmhoque03004e62012-09-06 01:12:28 -0500509 printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500510
511 }
512
513 }
514
515 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500516
akmhoque53f64222012-09-05 13:57:51 -0500517 free(key);
518}
519
520void
521print_adj_lsa_body(const char *body, int no_link)
522{
523 int i=0;
524 char *lsa_data=(char *)malloc(strlen(body)+1);
525 memset( lsa_data,0,strlen(body)+1);
526 memcpy(lsa_data,body,strlen(body)+1);
527 char *sep="|";
528 char *rem;
529 char *rtr_id;
530 char *length;
531 char *face;
532 char *metric;
533
akmhoque53f64222012-09-05 13:57:51 -0500534 if(no_link >0 )
535 {
536 rtr_id=strtok_r(lsa_data,sep,&rem);
537 length=strtok_r(NULL,sep,&rem);
538 face=strtok_r(NULL,sep,&rem);
539 metric=strtok_r(NULL,sep,&rem);
540
541 printf(" Link %d \n",i+1);
542 printf(" Neighbor : %s \n",rtr_id);
543 printf(" Neighbor Length : %s \n",length);
544 printf(" Connecting Face : %s \n",face);
545 printf(" Metric : %s \n",metric);
akmhoque03004e62012-09-06 01:12:28 -0500546
akmhoque53f64222012-09-05 13:57:51 -0500547
548 for(i=1;i<no_link;i++)
549 {
550 rtr_id=strtok_r(NULL,sep,&rem);
551 length=strtok_r(NULL,sep,&rem);
552 face=strtok_r(NULL,sep,&rem);
553 metric=strtok_r(NULL,sep,&rem);
554 printf(" Link %d \n",i+1);
555 printf(" Neighbor : %s \n",rtr_id);
556 printf(" Neighbor Length : %s \n",length);
557 printf(" Connecting Face : %s \n",face);
558 printf(" Metric : %s \n",metric);
559
560 }
561 }
562
563 free(lsa_data);
564}
565
566void
567print_adj_lsa(struct alsa * adj_lsa)
568{
akmhoque03004e62012-09-06 01:12:28 -0500569
akmhoque53f64222012-09-05 13:57:51 -0500570 printf("print_adj_lsa called \n");
akmhoque03004e62012-09-06 01:12:28 -0500571
akmhoque53f64222012-09-05 13:57:51 -0500572 printf("-----------ADJ LSA Content---------------\n");
573 printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name);
574 printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length);
575 printf(" LS Type : %d\n",adj_lsa->header->ls_type);
576 printf(" Origination Time : %s\n",adj_lsa->header->orig_time);
akmhoque03004e62012-09-06 01:12:28 -0500577 printf(" Lsa Data:\n");
578 printf(" No of Link : %d\n",adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500579
580 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
akmhoque53f64222012-09-05 13:57:51 -0500581
akmhoque03004e62012-09-06 01:12:28 -0500582/*
583 struct link *templ=adj_lsa->links;
584 int i;
585
586 for(i=0 ; i< adj_lsa->no_link ; i++)
587 {
588 printf(" Link %d \n",i+1);
589 printf(" Neighbor : %s \n",templ->nbr->name);
590 printf(" Neighbor Length : %d \n",templ->nbr->length);
591 printf(" Connecting Face : %d \n",templ->face);
592 printf(" Metric : %d \n",templ->metric);
593
594 templ++;
595 }
596*/
akmhoque53f64222012-09-05 13:57:51 -0500597 printf("\n");
598
599}
600
601void
602print_adj_lsdb(void)
603{
604 printf("print_name_lsdb called \n");
605 int i, adj_lsdb_element;
606 struct alsa *adj_lsa;
607
608 struct hashtb_enumerator ee;
609 struct hashtb_enumerator *e = &ee;
610
611 hashtb_start(nlsr->lsdb->adj_lsdb, e);
612 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
613
614 for(i=0;i<adj_lsdb_element;i++)
615 {
616 printf("-----------Adj LSA (%d)---------------\n",i+1);
617 adj_lsa=e->data;
618 print_adj_lsa(adj_lsa);
619 hashtb_next(e);
620 }
621
622 hashtb_end(e);
623
624 printf("\n");
akmhoque53f64222012-09-05 13:57:51 -0500625}
626
627void
akmhoque03004e62012-09-06 01:12:28 -0500628build_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 -0500629{
akmhoque03004e62012-09-06 01:12:28 -0500630 printf("build_and_install_others_adj_lsa called \n");
631 struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa ));
632 build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data);
633 //print_adj_lsa(adj_lsa);
634 install_adj_lsa(adj_lsa);
635
akmhoque53f64222012-09-05 13:57:51 -0500636
akmhoque03004e62012-09-06 01:12:28 -0500637 free(adj_lsa->header->orig_router->name);
638 free(adj_lsa->header->orig_router);
639 free(adj_lsa->header->orig_time);
640 free(adj_lsa->header);
641 free(adj_lsa->body);
642 free(adj_lsa);
akmhoque53f64222012-09-05 13:57:51 -0500643
akmhoque03004e62012-09-06 01:12:28 -0500644 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -0500645
akmhoque53f64222012-09-05 13:57:51 -0500646}
647
akmhoque03004e62012-09-06 01:12:28 -0500648
akmhoque53f64222012-09-05 13:57:51 -0500649void
akmhoque03004e62012-09-06 01:12:28 -0500650build_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 -0500651{
akmhoque03004e62012-09-06 01:12:28 -0500652 printf("build_others_adj_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500653
akmhoque03004e62012-09-06 01:12:28 -0500654 /*Filling Up Header Data */
655 adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header ));
656 adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
657 adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1);
658 memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1);
659 memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1);
akmhoque53f64222012-09-05 13:57:51 -0500660
akmhoque03004e62012-09-06 01:12:28 -0500661 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -0500662
akmhoque53f64222012-09-05 13:57:51 -0500663
akmhoque03004e62012-09-06 01:12:28 -0500664 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -0500665
akmhoque03004e62012-09-06 01:12:28 -0500666 adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
667 memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1);
668 memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1);
akmhoque53f64222012-09-05 13:57:51 -0500669
akmhoque03004e62012-09-06 01:12:28 -0500670 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -0500671
akmhoque03004e62012-09-06 01:12:28 -0500672 adj_lsa->body=(char *)malloc(strlen(data)+1);
673 memset(adj_lsa->body,0,strlen(data)+1);
674 memcpy(adj_lsa->body,(char *)data,strlen(data)+1);
akmhoque53f64222012-09-05 13:57:51 -0500675
akmhoque53f64222012-09-05 13:57:51 -0500676}
677
akmhoque03004e62012-09-06 01:12:28 -0500678
akmhoque53f64222012-09-05 13:57:51 -0500679long int
680get_name_lsdb_num_element(void)
681{
682 long int num_element;
683
684
685 struct hashtb_enumerator ee;
686 struct hashtb_enumerator *e = &ee;
687
688 hashtb_start(nlsr->lsdb->name_lsdb, e);
689 num_element=hashtb_n(nlsr->lsdb->name_lsdb);
690 hashtb_end(e);
691
692 return num_element;
693}
694
695long int
696get_adj_lsdb_num_element(void)
697{
698 long int num_element;
699
700
701 struct hashtb_enumerator ee;
702 struct hashtb_enumerator *e = &ee;
703
704 hashtb_start(nlsr->lsdb->adj_lsdb, e);
705 num_element=hashtb_n(nlsr->lsdb->adj_lsdb);
706 hashtb_end(e);
707
708 return num_element;
akmhoqued79438d2012-08-27 13:31:42 -0500709}
akmhoque03004e62012-09-06 01:12:28 -0500710
711void
712get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data)
713{
714 printf("get_name_lsdb_summary called \n");
715 int i, name_lsdb_element;
716
717 struct nlsa *name_lsa;
718 struct hashtb_enumerator ee;
719 struct hashtb_enumerator *e = &ee;
720
721 hashtb_start(nlsr->lsdb->name_lsdb, e);
722 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
723
724 for(i=0;i<name_lsdb_element;i++)
725 {
726 name_lsa=e->data;
727
728 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name);
729 ccn_charbuf_append_string(name_lsdb_data,"|");
730
731 char *lst=(char *)malloc(20);
732 memset(lst,0,20);
733 sprintf(lst,"%d",name_lsa->header->ls_type);
734 ccn_charbuf_append_string(name_lsdb_data,lst);
735 free(lst);
736 ccn_charbuf_append_string(name_lsdb_data,"|");
737
738 char *lsid=(char *)malloc(20);
739 memset(lsid,0,20);
740 sprintf(lsid,"%ld",name_lsa->header->ls_id);
741 ccn_charbuf_append_string(name_lsdb_data,lsid);
742 free(lsid);
743 ccn_charbuf_append_string(name_lsdb_data,"|");
744
745 ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time);
746 ccn_charbuf_append_string(name_lsdb_data,"|");
747
748 hashtb_next(e);
749 }
750
751 hashtb_end(e);
752
753}
754
755
756void
757get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data)
758{
759 printf("get_adj_lsdb_summary called \n");
760 int i, adj_lsdb_element;
761 struct alsa *adj_lsa;
762
763 struct hashtb_enumerator ee;
764 struct hashtb_enumerator *e = &ee;
765
766 hashtb_start(nlsr->lsdb->adj_lsdb, e);
767 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
768
769 for(i=0;i<adj_lsdb_element;i++)
770 {
771 adj_lsa=e->data;
772
773 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name);
774 ccn_charbuf_append_string(adj_lsdb_data,"|");
775
776 char *lst=(char *)malloc(20);
777 memset(lst,0,20);
778 sprintf(lst,"%d",adj_lsa->header->ls_type);
779 ccn_charbuf_append_string(adj_lsdb_data,lst);
780 free(lst);
781 ccn_charbuf_append_string(adj_lsdb_data,"|");
782
783 ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time);
784 ccn_charbuf_append_string(adj_lsdb_data,"|");
785
786 hashtb_next(e);
787 }
788
789 hashtb_end(e);
790}
791
792
793void
794get_lsdb_summary(struct ccn_charbuf *lsdb_data)
795{
796 struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create();
797 struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create();
798
799 get_name_lsdb_summary(name_lsdb_data);
800 get_adj_lsdb_summary(adj_lsdb_data);
801
802 long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element();
803 char *num_element=(char *)malloc(15);
804 memset(num_element,0,15);
805 sprintf(num_element,"%ld",num_lsa);
806
807 if( num_lsa > 0)
808 {
809 ccn_charbuf_append_string(lsdb_data,num_element);
810 ccn_charbuf_append_string(lsdb_data,"|");
811 }
812 if(name_lsdb_data->length>0)
813 {
814 char *data1=ccn_charbuf_as_string(name_lsdb_data);
815 ccn_charbuf_append_string(lsdb_data,(char *)data1);
816 }
817 if(adj_lsdb_data->length>0)
818 {
819 char *data2=ccn_charbuf_as_string(adj_lsdb_data);
820 ccn_charbuf_append_string(lsdb_data,(char *)data2);
821 }
822 ccn_charbuf_destroy(&name_lsdb_data);
823 ccn_charbuf_destroy(&adj_lsdb_data);
824 free(num_element);
825
826}
827
828int
829check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time)
830{
831 int ret=0;
832 struct ccn_charbuf *key=ccn_charbuf_create();
833 ccn_charbuf_append_string(key,orig_router);
834 ccn_charbuf_append_string(key,"/");
835 ccn_charbuf_append_string(key,lst);
836 ccn_charbuf_append_string(key,"/");
837 ccn_charbuf_append_string(key,lsid);
838
839 int res;
840 struct nlsa *name_lsa;
841
842 struct hashtb_enumerator ee;
843 struct hashtb_enumerator *e = &ee;
844
845 hashtb_start(nlsr->lsdb->name_lsdb, e);
846 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
847
848 if( res == HT_NEW_ENTRY )
849 {
850 hashtb_delete(e);
851 ret=1;
852
853 }
854 else if(res == HT_OLD_ENTRY)
855 {
856 name_lsa=e->data;
857 if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 )
858 {
859 ret=1;
860 }
861 }
862
863 hashtb_end(e);
864
865 ccn_charbuf_destroy(&key);
866
867 return ret;
868}
869
870int
871check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time)
872{
873 int ret=0;
874 struct ccn_charbuf *key=ccn_charbuf_create();
875 ccn_charbuf_append_string(key,orig_router);
876 ccn_charbuf_append_string(key,"/");
877 ccn_charbuf_append_string(key,lst);
878
879 int res;
880 struct alsa *adj_lsa;
881
882 struct hashtb_enumerator ee;
883 struct hashtb_enumerator *e = &ee;
884
885 hashtb_start(nlsr->lsdb->adj_lsdb, e);
886 res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0);
887
888 if( res == HT_NEW_ENTRY )
889 {
890 hashtb_delete(e);
891 ret=1;
892
893 }
894 else if(res == HT_OLD_ENTRY)
895 {
896 adj_lsa=e->data;
897 if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 )
898 {
899 ret=1;
900 }
901 }
902
903 hashtb_end(e);
904
905 ccn_charbuf_destroy(&key);
906
907 return ret;
908}
909
910void
911get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
912{
913 printf("get_name_lsa_data called \n");
914
915 struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa ));
916
917 struct hashtb_enumerator ee;
918 struct hashtb_enumerator *e = &ee;
919 int res;
920
921 hashtb_start(nlsr->lsdb->name_lsdb, e);
922 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
923
924 if( res == HT_OLD_ENTRY )
925 {
926 name_lsa=e->data;
927 printf("NAME LSA found\n");
928
929 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name);
930 ccn_charbuf_append_string(lsa_data,"|");
931
932 char *temp_length=(char *)malloc(20);
933 memset(temp_length,0,20);
934 sprintf(temp_length,"%d",name_lsa->header->orig_router->length);
935 ccn_charbuf_append_string(lsa_data,temp_length);
936 free(temp_length);
937 ccn_charbuf_append_string(lsa_data,"|");
938
939 char *temp_ltype=(char *)malloc(20);
940 memset(temp_ltype,0,20);
941 sprintf(temp_ltype,"%d",name_lsa->header->ls_type);
942 ccn_charbuf_append_string(lsa_data,temp_ltype);
943 free(temp_ltype);
944 ccn_charbuf_append_string(lsa_data,"|");
945
946 char *temp_lsid=(char *)malloc(20);
947 memset(temp_lsid,0,20);
948 sprintf(temp_lsid,"%ld",name_lsa->header->ls_id);
949 ccn_charbuf_append_string(lsa_data,temp_lsid);
950 free(temp_lsid);
951 ccn_charbuf_append_string(lsa_data,"|");
952
953 ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time);
954 ccn_charbuf_append_string(lsa_data,"|");
955
956 char *temp_valid=(char *)malloc(20);
957 memset(temp_valid,0,20);
958 sprintf(temp_valid,"%d",name_lsa->header->isValid);
959 ccn_charbuf_append_string(lsa_data,temp_valid);
960 free(temp_valid);
961 ccn_charbuf_append_string(lsa_data,"|");
962
963 ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name);
964 ccn_charbuf_append_string(lsa_data,"|");
965
966 char *temp_npl=(char *)malloc(20);
967 memset(temp_npl,0,20);
968 sprintf(temp_npl,"%d",name_lsa->name_prefix->length);
969 ccn_charbuf_append_string(lsa_data,temp_npl);
970 free(temp_npl);
971 ccn_charbuf_append_string(lsa_data,"|");
972
973 }
974 else if(res == HT_NEW_ENTRY)
975 {
976 hashtb_delete(e);
977 }
978
979 hashtb_end(e);
980}
981
982void
983get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
984{
985 printf("get_adj_lsa_data called \n");
986
987 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
988
989 struct hashtb_enumerator ee;
990 struct hashtb_enumerator *e = &ee;
991 int res;
992
993 hashtb_start(nlsr->lsdb->adj_lsdb, e);
994 res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0);
995
996 if( res == HT_OLD_ENTRY )
997 {
998 adj_lsa=e->data;
999 printf("NAME LSA found\n");
1000
1001 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name);
1002 ccn_charbuf_append_string(lsa_data,"|");
1003
1004 char *temp_length=(char *)malloc(20);
1005 memset(temp_length,0,20);
1006 sprintf(temp_length,"%d",adj_lsa->header->orig_router->length);
1007 ccn_charbuf_append_string(lsa_data,temp_length);
1008 free(temp_length);
1009 ccn_charbuf_append_string(lsa_data,"|");
1010
1011 char *temp_ltype=(char *)malloc(20);
1012 memset(temp_ltype,0,20);
1013 sprintf(temp_ltype,"%d",adj_lsa->header->ls_type);
1014 ccn_charbuf_append_string(lsa_data,temp_ltype);
1015 free(temp_ltype);
1016 ccn_charbuf_append_string(lsa_data,"|");
1017
1018 ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time);
1019 ccn_charbuf_append_string(lsa_data,"|");
1020
1021 char *temp_nl=(char *)malloc(20);
1022 memset(temp_nl,0,20);
1023 sprintf(temp_nl,"%d",adj_lsa->no_link);
1024 ccn_charbuf_append_string(lsa_data,temp_nl);
1025 free(temp_nl);
1026 ccn_charbuf_append_string(lsa_data,"|");
1027
1028 ccn_charbuf_append_string(lsa_data,adj_lsa->body);
1029
1030
1031 }
1032 else if(res == HT_NEW_ENTRY)
1033 {
1034 hashtb_delete(e);
1035 }
1036
1037 hashtb_end(e);
1038}