akmhoque | f1161eb | 2012-08-21 09:37:21 -0400 | [diff] [blame] | 1 | #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" |
| 21 | #include "nlsr_lsdb.h" |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 22 | #include "utility.h" |
akmhoque | 887fc0c | 2012-08-27 15:06:06 -0500 | [diff] [blame] | 23 | #include "nlsr_ndn.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 24 | #include "nlsr_adl.h" |
akmhoque | 438b07e | 2012-08-21 10:13:57 -0400 | [diff] [blame] | 25 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 26 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 27 | set_new_lsdb_version(void) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 28 | { |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 29 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 30 | char *time_stamp=get_current_timestamp_micro(); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 31 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 32 | free(nlsr->lsdb->version); |
| 33 | nlsr->lsdb->version=(char *)malloc(strlen(time_stamp)+1); |
| 34 | memset(nlsr->lsdb->version,0,strlen(time_stamp)+1); |
| 35 | memcpy(nlsr->lsdb->version,time_stamp,strlen(time_stamp)+1); |
| 36 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 37 | } |
| 38 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 39 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 40 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 41 | build_and_install_name_lsas(void) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 42 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 43 | printf("build_and_install_name_lsas called \n"); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 44 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 45 | int i, npl_element; |
| 46 | struct name_prefix *np; |
| 47 | |
| 48 | struct hashtb_enumerator ee; |
| 49 | struct hashtb_enumerator *e = ⅇ |
| 50 | |
| 51 | hashtb_start(nlsr->npl, e); |
| 52 | npl_element=hashtb_n(nlsr->npl); |
| 53 | |
| 54 | for(i=0;i<npl_element;i++) |
| 55 | { |
| 56 | np=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 57 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 58 | build_name_lsa(name_lsa,np); |
| 59 | print_name_lsa(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 60 | install_name_lsa(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 61 | free(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 62 | hashtb_next(e); |
| 63 | } |
| 64 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 65 | hashtb_end(e); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 66 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 67 | } |
| 68 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 69 | void |
| 70 | build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,int isValid,char *np) |
| 71 | { |
| 72 | printf("build_and_install_others_name_lsa called \n"); |
| 73 | |
| 74 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 75 | build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,isValid,np); |
| 76 | print_name_lsa(name_lsa); |
| 77 | install_name_lsa(name_lsa); |
| 78 | print_name_lsdb(); |
| 79 | free(name_lsa); |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,int isValid,char *np) |
| 84 | { |
| 85 | printf("build_others_name_lsa called \n"); |
| 86 | |
| 87 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 88 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 89 | |
| 90 | char *time_stamp=get_current_timestamp_micro(); |
| 91 | |
| 92 | name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 93 | memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 94 | memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 95 | |
| 96 | name_lsa->header->ls_id=ls_id; |
| 97 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 98 | name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 99 | memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 100 | memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 101 | name_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 102 | name_lsa->header->isValid=isValid; |
| 103 | |
| 104 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 105 | name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1); |
| 106 | memset(name_lsa->name_prefix->name,0,strlen(np)+1); |
| 107 | memcpy(name_lsa->name_prefix->name,np,strlen(np)+1); |
| 108 | name_lsa->name_prefix->length=strlen(np)+1; |
| 109 | |
| 110 | |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np) |
| 115 | { |
| 116 | printf("build_name_lsa called \n"); |
| 117 | |
| 118 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 119 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 120 | |
| 121 | char *time_stamp=get_current_timestamp_micro(); |
| 122 | |
| 123 | name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 124 | memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 125 | memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 126 | name_lsa->header->orig_time[strlen(name_lsa->header->orig_time)]='\0'; |
| 127 | |
| 128 | printf("Orig Time: %s\n",name_lsa->header->orig_time); |
| 129 | |
| 130 | name_lsa->header->ls_id=++nlsr->nlsa_id; |
| 131 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 132 | name_lsa->header->orig_router->name=(char *)malloc(nlsr->router_name->length); |
| 133 | memcpy(name_lsa->header->orig_router->name,nlsr->router_name->name,nlsr->router_name->length); |
| 134 | name_lsa->header->orig_router->length=nlsr->router_name->length; |
| 135 | name_lsa->header->isValid=1; |
| 136 | |
| 137 | |
| 138 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 139 | name_lsa->name_prefix->name=(char *)malloc(np->length); |
| 140 | memcpy(name_lsa->name_prefix->name,np->name,np->length); |
| 141 | name_lsa->name_prefix->length=np->length; |
| 142 | |
| 143 | } |
| 144 | |
| 145 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 146 | void |
| 147 | print_name_lsa(struct nlsa *name_lsa) |
| 148 | { |
| 149 | printf("print_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 150 | |
| 151 | printf("-----------Name LSA Content---------------\n"); |
| 152 | printf(" Origination Router : %s\n",name_lsa->header->orig_router->name); |
| 153 | printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 154 | printf(" LS Type : %d\n",name_lsa->header->ls_type); |
| 155 | printf(" LS Id : %ld\n",name_lsa->header->ls_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 156 | printf(" Origination Time : %s\n",name_lsa->header->orig_time); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 157 | printf(" Is Valid : %d\n",name_lsa->header->isValid); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 158 | printf(" LSA Data \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 159 | printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name); |
| 160 | printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 161 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 162 | printf("\n"); |
| 163 | } |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 164 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 165 | void |
| 166 | install_name_lsa(struct nlsa *name_lsa) |
| 167 | { |
| 168 | printf("install_name_lsa called \n"); |
| 169 | |
| 170 | print_name_lsa(name_lsa); |
| 171 | |
| 172 | char *key=make_name_lsa_key(name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 173 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 174 | |
| 175 | struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); |
| 176 | |
| 177 | struct hashtb_enumerator ee; |
| 178 | struct hashtb_enumerator *e = ⅇ |
| 179 | int res; |
| 180 | |
| 181 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 182 | res = hashtb_seek(e, key, strlen(key), 0); |
| 183 | |
| 184 | if(res == HT_NEW_ENTRY ) |
| 185 | { |
| 186 | printf("New Name LSA... Adding to LSDB\n"); |
| 187 | new_name_lsa = e->data; |
| 188 | |
| 189 | new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 190 | new_name_lsa->header->ls_type=name_lsa->header->ls_type; |
| 191 | |
| 192 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 193 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 194 | |
| 195 | printf("Orig Time: %s\n",new_name_lsa->header->orig_time); |
| 196 | |
| 197 | new_name_lsa->header->ls_id=name_lsa->header->ls_id; |
| 198 | new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 199 | new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length); |
| 200 | memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length); |
| 201 | new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length; |
| 202 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 203 | |
| 204 | |
| 205 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 206 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 207 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 208 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 209 | |
| 210 | printf("New Name LSA Added....\n"); |
| 211 | |
| 212 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version); |
| 213 | set_new_lsdb_version(); |
| 214 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version); |
| 215 | |
| 216 | } |
| 217 | else if(res == HT_OLD_ENTRY) |
| 218 | { |
| 219 | printf("Duplicate Name LSA. Discarded...\n"); |
| 220 | |
| 221 | } |
| 222 | |
| 223 | hashtb_end(e); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | char * |
| 228 | make_name_lsa_key(char *orig_router, int ls_type, long int ls_id) |
| 229 | { |
| 230 | |
| 231 | |
| 232 | printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id); |
| 233 | |
| 234 | char lst[2]; |
| 235 | memset(lst,0,2); |
| 236 | sprintf(lst,"%d",ls_type); |
| 237 | |
| 238 | char lsid[10]; |
| 239 | memset(lsid,0,10); |
| 240 | sprintf(lsid,"%ld",ls_id); |
| 241 | |
| 242 | |
| 243 | char *key=(char *)malloc(strlen(orig_router)+1+strlen(lst)+1+strlen(lsid)+1); |
| 244 | memset(key,0,strlen(orig_router)+1+strlen(lst)+1+strlen(lsid)+1); |
| 245 | memcpy(key+strlen(key),orig_router,strlen(orig_router)); |
| 246 | memcpy(key+strlen(key),"/",1); |
| 247 | memcpy(key+strlen(key),lst,strlen(lst)); |
| 248 | memcpy(key+strlen(key),"/",1); |
| 249 | memcpy(key+strlen(key),lsid,strlen(lsid)); |
| 250 | |
| 251 | printf("Key: %s\n",key); |
| 252 | |
| 253 | return key; |
| 254 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void |
| 258 | print_name_lsdb(void) |
| 259 | { |
| 260 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 261 | int i, name_lsdb_element; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 262 | struct nlsa *name_lsa; |
| 263 | |
| 264 | struct hashtb_enumerator ee; |
| 265 | struct hashtb_enumerator *e = ⅇ |
| 266 | |
| 267 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 268 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 269 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 270 | for(i=0;i<name_lsdb_element;i++) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 271 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 272 | printf("-----------Name LSA (%d)---------------\n",i+1); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 273 | name_lsa=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 274 | print_name_lsa(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 275 | hashtb_next(e); |
| 276 | } |
| 277 | |
| 278 | hashtb_end(e); |
| 279 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 280 | printf("\n"); |
| 281 | } |
| 282 | |
| 283 | int |
| 284 | build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 285 | { |
| 286 | printf("build_and_install_adj_lsa called \n"); |
| 287 | my_lock(); |
| 288 | |
| 289 | printf("adj_build_flag = %d \n",nlsr->adj_build_flag); |
| 290 | |
| 291 | if(nlsr->adj_build_flag > 0) |
| 292 | { |
| 293 | printf("is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 294 | if ( is_adj_lsa_build()> 0) |
| 295 | { |
| 296 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 297 | build_adj_lsa(adj_lsa); |
| 298 | print_adj_lsa(adj_lsa); |
| 299 | install_adj_lsa(adj_lsa); |
| 300 | free(adj_lsa); |
| 301 | nlsr->adj_build_flag=0; |
| 302 | print_adj_lsdb(); |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | printf("Can not build adj LSA now\n"); |
| 307 | } |
| 308 | } |
| 309 | nlsr->is_build_adj_lsa_sheduled=0; |
| 310 | my_unlock(); |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | void |
| 315 | build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data) |
| 316 | { |
| 317 | printf("build_and_install_others_adj_lsa called \n"); |
| 318 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 319 | build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data); |
| 320 | print_adj_lsa(adj_lsa); |
| 321 | install_adj_lsa(adj_lsa); |
| 322 | free(adj_lsa); |
| 323 | print_adj_lsdb(); |
| 324 | |
| 325 | } |
| 326 | |
| 327 | void |
| 328 | build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data) |
| 329 | { |
| 330 | printf("build_others_adj_lsa called \n"); |
| 331 | |
| 332 | /*Filling Up Header Data */ |
| 333 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 334 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 335 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 336 | memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 337 | memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 338 | |
| 339 | adj_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 340 | |
| 341 | |
| 342 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 343 | |
| 344 | adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 345 | memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 346 | memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
| 347 | |
| 348 | adj_lsa->no_link=no_link; |
| 349 | |
| 350 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 351 | memset(adj_lsa->body,0,strlen(data)+1); |
| 352 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 353 | |
| 354 | } |
| 355 | |
| 356 | void |
| 357 | build_adj_lsa(struct alsa * adj_lsa) |
| 358 | { |
| 359 | printf("build_adj_lsa called \n"); |
| 360 | |
| 361 | int no_link=no_active_nbr(); |
| 362 | printf("Number of link in Adjacent LSA: %d\n",no_link); |
| 363 | |
| 364 | /*Filling Up Header Data */ |
| 365 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 366 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 367 | |
| 368 | char *time_stamp=get_current_timestamp_micro(); |
| 369 | adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 370 | memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 371 | memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 372 | adj_lsa->header->orig_time[strlen(adj_lsa->header->orig_time)]='\0'; |
| 373 | |
| 374 | printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length); |
| 375 | |
| 376 | char *temp_r=(char *)malloc(nlsr->router_name->length); |
| 377 | memset(temp_r,0,nlsr->router_name->length); |
| 378 | sprintf(temp_r,"%s",nlsr->router_name->name); |
| 379 | printf("Router Name: %s Length: %d \n",temp_r,(int)strlen(temp_r)+1); |
| 380 | |
| 381 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 382 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(temp_r)+1); |
| 383 | memset(adj_lsa->header->orig_router->name,0,strlen(temp_r)+1); |
| 384 | memcpy(adj_lsa->header->orig_router->name,temp_r,strlen(temp_r)+1); |
| 385 | |
| 386 | adj_lsa->header->orig_router->length=strlen(temp_r)+1; |
| 387 | printf("Router Name: %s Length: %d \n",nlsr->router_name->name,nlsr->router_name->length); |
| 388 | |
| 389 | /* Filling Up Body Data */ |
| 390 | |
| 391 | adj_lsa->no_link=no_link; |
| 392 | |
| 393 | |
| 394 | struct ccn_charbuf *c=ccn_charbuf_create(); |
| 395 | get_active_nbr_adj_data(c); |
| 396 | char *data=ccn_charbuf_as_string(c); |
| 397 | printf("Adjacent data: %s \n",data); |
| 398 | |
| 399 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 400 | memset(adj_lsa->body,0,strlen(data)+1); |
| 401 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 402 | |
| 403 | |
| 404 | ccn_charbuf_destroy(&c); |
| 405 | |
| 406 | if( !nlsr->is_send_lsdb_interest_scheduled ) |
| 407 | { |
| 408 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0); |
| 409 | nlsr->is_send_lsdb_interest_scheduled=1; |
| 410 | } |
| 411 | nlsr->adj_build_count++; |
| 412 | |
| 413 | |
| 414 | free(temp_r); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 415 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 416 | |
| 417 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 418 | void |
| 419 | make_adj_lsa_key(char *key,struct alsa *adj_lsa) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 420 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 421 | memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 422 | memcpy(key+strlen(key),"/",1); |
| 423 | char ls_type[2]; |
| 424 | sprintf(ls_type,"%d",adj_lsa->header->ls_type); |
| 425 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 426 | key[strlen(key)]='\0'; |
| 427 | } |
| 428 | |
| 429 | void |
| 430 | install_adj_lsa(struct alsa * adj_lsa) |
| 431 | { |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 432 | printf("install_adj_lsa called \n"); |
| 433 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 434 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 435 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 436 | make_adj_lsa_key(key,adj_lsa); |
| 437 | printf("Adjacent LSA key: %s \n",key); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 438 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 439 | struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 440 | |
| 441 | struct hashtb_enumerator ee; |
| 442 | struct hashtb_enumerator *e = ⅇ |
| 443 | int res; |
| 444 | |
| 445 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 446 | res = hashtb_seek(e, key, strlen(key), 0); |
| 447 | |
| 448 | |
| 449 | |
| 450 | if(res == HT_NEW_ENTRY ) |
| 451 | { |
| 452 | printf("New ADJ LSA... Adding to LSDB\n"); |
| 453 | new_adj_lsa = e->data; |
| 454 | |
| 455 | new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 456 | new_adj_lsa->header->ls_type=adj_lsa->header->ls_type; |
| 457 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 458 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 459 | |
| 460 | new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 461 | new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length); |
| 462 | memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 463 | new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length; |
| 464 | |
| 465 | new_adj_lsa->no_link=adj_lsa->no_link; |
| 466 | |
| 467 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 468 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 469 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 470 | |
| 471 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version); |
| 472 | set_new_lsdb_version(); |
| 473 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version); |
| 474 | |
| 475 | |
| 476 | } |
| 477 | else if(res == HT_OLD_ENTRY) |
| 478 | { |
| 479 | new_adj_lsa = e->data; |
| 480 | if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0) |
| 481 | { |
| 482 | printf("Older/Duplicate Adj LSA. Discarded...\n"); |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | new_adj_lsa = e->data; |
| 487 | |
| 488 | free(new_adj_lsa->header->orig_time); |
| 489 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 490 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 491 | |
| 492 | new_adj_lsa->no_link=adj_lsa->no_link; |
| 493 | |
| 494 | free(new_adj_lsa->body); |
| 495 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 496 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 497 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 498 | |
| 499 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->version); |
| 500 | set_new_lsdb_version(); |
| 501 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->version); |
| 502 | |
| 503 | } |
| 504 | |
| 505 | } |
| 506 | |
| 507 | hashtb_end(e); |
| 508 | |
| 509 | free(key); |
| 510 | } |
| 511 | |
| 512 | void |
| 513 | print_adj_lsa_body(const char *body, int no_link) |
| 514 | { |
| 515 | int i=0; |
| 516 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 517 | memset( lsa_data,0,strlen(body)+1); |
| 518 | memcpy(lsa_data,body,strlen(body)+1); |
| 519 | char *sep="|"; |
| 520 | char *rem; |
| 521 | char *rtr_id; |
| 522 | char *length; |
| 523 | char *face; |
| 524 | char *metric; |
| 525 | |
| 526 | printf(" Lsa Data:\n"); |
| 527 | printf(" No of Link : %d\n",no_link); |
| 528 | |
| 529 | if(no_link >0 ) |
| 530 | { |
| 531 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 532 | length=strtok_r(NULL,sep,&rem); |
| 533 | face=strtok_r(NULL,sep,&rem); |
| 534 | metric=strtok_r(NULL,sep,&rem); |
| 535 | |
| 536 | printf(" Link %d \n",i+1); |
| 537 | printf(" Neighbor : %s \n",rtr_id); |
| 538 | printf(" Neighbor Length : %s \n",length); |
| 539 | printf(" Connecting Face : %s \n",face); |
| 540 | printf(" Metric : %s \n",metric); |
| 541 | |
| 542 | |
| 543 | for(i=1;i<no_link;i++) |
| 544 | { |
| 545 | rtr_id=strtok_r(NULL,sep,&rem); |
| 546 | length=strtok_r(NULL,sep,&rem); |
| 547 | face=strtok_r(NULL,sep,&rem); |
| 548 | metric=strtok_r(NULL,sep,&rem); |
| 549 | printf(" Link %d \n",i+1); |
| 550 | printf(" Neighbor : %s \n",rtr_id); |
| 551 | printf(" Neighbor Length : %s \n",length); |
| 552 | printf(" Connecting Face : %s \n",face); |
| 553 | printf(" Metric : %s \n",metric); |
| 554 | |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | free(lsa_data); |
| 559 | } |
| 560 | |
| 561 | void |
| 562 | print_adj_lsa(struct alsa * adj_lsa) |
| 563 | { |
| 564 | |
| 565 | printf("print_adj_lsa called \n"); |
| 566 | |
| 567 | printf("-----------ADJ LSA Content---------------\n"); |
| 568 | printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name); |
| 569 | printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 570 | printf(" LS Type : %d\n",adj_lsa->header->ls_type); |
| 571 | printf(" Origination Time : %s\n",adj_lsa->header->orig_time); |
| 572 | |
| 573 | print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 574 | |
| 575 | |
| 576 | printf("\n"); |
| 577 | |
| 578 | } |
| 579 | |
| 580 | void |
| 581 | print_adj_lsdb(void) |
| 582 | { |
| 583 | printf("print_name_lsdb called \n"); |
| 584 | int i, adj_lsdb_element; |
| 585 | struct alsa *adj_lsa; |
| 586 | |
| 587 | struct hashtb_enumerator ee; |
| 588 | struct hashtb_enumerator *e = ⅇ |
| 589 | |
| 590 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 591 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 592 | |
| 593 | for(i=0;i<adj_lsdb_element;i++) |
| 594 | { |
| 595 | printf("-----------Adj LSA (%d)---------------\n",i+1); |
| 596 | adj_lsa=e->data; |
| 597 | print_adj_lsa(adj_lsa); |
| 598 | hashtb_next(e); |
| 599 | } |
| 600 | |
| 601 | hashtb_end(e); |
| 602 | |
| 603 | printf("\n"); |
| 604 | |
| 605 | } |
| 606 | |
| 607 | char * |
| 608 | get_name_lsdb_summary() |
| 609 | { |
| 610 | printf("get_name_lsdb_summary called \n"); |
| 611 | int i, name_lsdb_element; |
| 612 | |
| 613 | long int len=0; |
| 614 | |
| 615 | struct nlsa *name_lsa; |
| 616 | struct hashtb_enumerator ee; |
| 617 | struct hashtb_enumerator *e = ⅇ |
| 618 | |
| 619 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 620 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 621 | |
| 622 | for(i=0;i<name_lsdb_element;i++) |
| 623 | { |
| 624 | name_lsa=e->data; |
| 625 | |
| 626 | //ccn_charbuf_append_string(sum_data,name_lsa->header->orig_router->name); |
| 627 | len+=strlen(name_lsa->header->orig_router->name); |
| 628 | //ccn_charbuf_append_string(sum_data,"|"); |
| 629 | len++; |
| 630 | |
| 631 | char *temp=(char *)malloc(20); |
| 632 | memset(temp,0,20); |
| 633 | sprintf(temp,"%d",name_lsa->header->ls_type); |
| 634 | len+=strlen(temp); |
| 635 | //ccn_charbuf_append_string(sum_data,temp); |
| 636 | free(temp); |
| 637 | //ccn_charbuf_append_string(sum_data,"|"); |
| 638 | len++; |
| 639 | |
| 640 | char *temp1=(char *)malloc(20); |
| 641 | memset(temp1,0,20); |
| 642 | sprintf(temp1,"%ld",name_lsa->header->ls_id); |
| 643 | //ccn_charbuf_append_string(sum_data,temp1); |
| 644 | len+=strlen(temp1); |
| 645 | free(temp1); |
| 646 | //ccn_charbuf_append_string(sum_data,"|"); |
| 647 | len++; |
| 648 | |
| 649 | hashtb_next(e); |
| 650 | } |
| 651 | |
| 652 | hashtb_end(e); |
| 653 | |
| 654 | len++; |
| 655 | |
| 656 | char *sum_data=malloc(len); |
| 657 | memset(sum_data,0,len); |
| 658 | |
| 659 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 660 | for(i=0;i<name_lsdb_element;i++) |
| 661 | { |
| 662 | name_lsa=e->data; |
| 663 | |
| 664 | //ccn_charbuf_append_string(sum_data,name_lsa->header->orig_router->name); |
| 665 | memcpy(sum_data+strlen(sum_data),name_lsa->header->orig_router->name,strlen(name_lsa->header->orig_router->name)); |
| 666 | //len+=strlen(name_lsa->header->orig_router->name); |
| 667 | //ccn_charbuf_append_string(sum_data,"|"); |
| 668 | memcpy(sum_data+strlen(sum_data),"|",1); |
| 669 | //len++; |
| 670 | |
| 671 | char *tempstr=(char *)malloc(20); |
| 672 | memset(tempstr,0,20); |
| 673 | sprintf(tempstr,"%d",name_lsa->header->ls_type); |
| 674 | //len+=strlen(tempstr); |
| 675 | //ccn_charbuf_append_string(sum_data,temp); |
| 676 | memcpy(sum_data+strlen(sum_data),tempstr,strlen(tempstr)); |
| 677 | free(tempstr); |
| 678 | //ccn_charbuf_append_string(sum_data,"|"); |
| 679 | memcpy(sum_data+strlen(sum_data),"|",1); |
| 680 | //len++; |
| 681 | |
| 682 | char *temp1str=(char *)malloc(20); |
| 683 | memset(temp1str,0,20); |
| 684 | sprintf(temp1str,"%ld",name_lsa->header->ls_id); |
| 685 | //ccn_charbuf_append_string(sum_data,temp1); |
| 686 | memcpy(sum_data+strlen(sum_data),temp1str,strlen(temp1str)); |
| 687 | //len+=strlen(temp1str); |
| 688 | free(temp1str); |
| 689 | //ccn_charbuf_append_string(sum_data,"|"); |
| 690 | memcpy(sum_data+strlen(sum_data),"|",1); |
| 691 | //len++; |
| 692 | |
| 693 | hashtb_next(e); |
| 694 | } |
| 695 | |
| 696 | hashtb_end(e); |
| 697 | |
| 698 | printf("Summary Name LSDB: %s\n",sum_data); |
| 699 | |
| 700 | return sum_data; |
| 701 | } |
| 702 | |
| 703 | char * |
| 704 | get_adj_lsdb_summary(void) |
| 705 | { |
| 706 | printf("get_adj_lsdb_summary called \n"); |
| 707 | int i, adj_lsdb_element; |
| 708 | struct alsa *adj_lsa; |
| 709 | |
| 710 | long int len=0; |
| 711 | |
| 712 | struct hashtb_enumerator ee; |
| 713 | struct hashtb_enumerator *e = ⅇ |
| 714 | |
| 715 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 716 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 717 | |
| 718 | for(i=0;i<adj_lsdb_element;i++) |
| 719 | { |
| 720 | adj_lsa=e->data; |
| 721 | |
| 722 | //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_router->name); |
| 723 | len+=strlen(adj_lsa->header->orig_router->name); |
| 724 | //ccn_charbuf_append_string(sum_data,"|"); |
| 725 | len++; |
| 726 | |
| 727 | char *temp=(char *)malloc(20); |
| 728 | memset(temp,0,20); |
| 729 | sprintf(temp,"%d",adj_lsa->header->ls_type); |
| 730 | len+=strlen(temp); |
| 731 | //ccn_charbuf_append_string(sum_data,temp); |
| 732 | free(temp); |
| 733 | //ccn_charbuf_append_string(sum_data,"|"); |
| 734 | len++; |
| 735 | |
| 736 | //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_time); |
| 737 | len+=strlen(adj_lsa->header->orig_time); |
| 738 | //ccn_charbuf_append_string(sum_data,"|"); |
| 739 | len++; |
| 740 | |
| 741 | hashtb_next(e); |
| 742 | } |
| 743 | |
| 744 | hashtb_end(e); |
| 745 | len++; |
| 746 | |
| 747 | char *sum_data=(char *)malloc(len); |
| 748 | memset(sum_data,0,len); |
| 749 | |
| 750 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 751 | for(i=0;i<adj_lsdb_element;i++) |
| 752 | { |
| 753 | adj_lsa=e->data; |
| 754 | |
| 755 | //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_router->name); |
| 756 | memcpy(sum_data+strlen(sum_data),adj_lsa->header->orig_router->name,strlen(adj_lsa->header->orig_router->name)); |
| 757 | //len+=strlen(adj_lsa->header->orig_router->name); |
| 758 | //ccn_charbuf_append_string(sum_data,"|"); |
| 759 | memcpy(sum_data+strlen(sum_data),"|",1); |
| 760 | //len++; |
| 761 | |
| 762 | char *temp1=(char *)malloc(20); |
| 763 | memset(temp1,0,20); |
| 764 | sprintf(temp1,"%d",adj_lsa->header->ls_type); |
| 765 | //len+=strlen(temp); |
| 766 | //ccn_charbuf_append_string(sum_data,temp); |
| 767 | memcpy(sum_data+strlen(sum_data),temp1,strlen(temp1)); |
| 768 | free(temp1); |
| 769 | //ccn_charbuf_append_string(sum_data,"|"); |
| 770 | memcpy(sum_data+strlen(sum_data),"|",1); |
| 771 | //len++; |
| 772 | |
| 773 | //ccn_charbuf_append_string(sum_data,adj_lsa->header->orig_time); |
| 774 | memcpy(sum_data+strlen(sum_data),adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)); |
| 775 | //len+=strlen(adj_lsa->header->orig_time); |
| 776 | //ccn_charbuf_append_string(sum_data,"|"); |
| 777 | memcpy(sum_data+strlen(sum_data),"|",1); |
| 778 | //len++; |
| 779 | |
| 780 | hashtb_next(e); |
| 781 | } |
| 782 | |
| 783 | hashtb_end(e); |
| 784 | |
| 785 | printf("Summary ADJ LSDB: %s\n",sum_data); |
| 786 | |
| 787 | return sum_data; |
| 788 | } |
| 789 | |
| 790 | void |
| 791 | get_name_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 792 | { |
| 793 | printf("get_name_lsa_data called \n"); |
| 794 | |
| 795 | struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); |
| 796 | |
| 797 | struct hashtb_enumerator ee; |
| 798 | struct hashtb_enumerator *e = ⅇ |
| 799 | int res; |
| 800 | |
| 801 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 802 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 803 | |
| 804 | if( res == HT_OLD_ENTRY ) |
| 805 | { |
| 806 | name_lsa=e->data; |
| 807 | printf("NAME LSA found\n"); |
| 808 | |
| 809 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name); |
| 810 | ccn_charbuf_append_string(lsa_data,"|"); |
| 811 | |
| 812 | char *temp_length=(char *)malloc(20); |
| 813 | memset(temp_length,0,20); |
| 814 | sprintf(temp_length,"%d",name_lsa->header->orig_router->length); |
| 815 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 816 | free(temp_length); |
| 817 | ccn_charbuf_append_string(lsa_data,"|"); |
| 818 | |
| 819 | char *temp_ltype=(char *)malloc(20); |
| 820 | memset(temp_ltype,0,20); |
| 821 | sprintf(temp_ltype,"%d",name_lsa->header->ls_type); |
| 822 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 823 | free(temp_ltype); |
| 824 | ccn_charbuf_append_string(lsa_data,"|"); |
| 825 | |
| 826 | char *temp_lsid=(char *)malloc(20); |
| 827 | memset(temp_lsid,0,20); |
| 828 | sprintf(temp_lsid,"%ld",name_lsa->header->ls_id); |
| 829 | ccn_charbuf_append_string(lsa_data,temp_lsid); |
| 830 | free(temp_lsid); |
| 831 | ccn_charbuf_append_string(lsa_data,"|"); |
| 832 | |
| 833 | char *temp_valid=(char *)malloc(20); |
| 834 | memset(temp_valid,0,20); |
| 835 | sprintf(temp_valid,"%d",name_lsa->header->isValid); |
| 836 | ccn_charbuf_append_string(lsa_data,temp_valid); |
| 837 | free(temp_valid); |
| 838 | ccn_charbuf_append_string(lsa_data,"|"); |
| 839 | |
| 840 | ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name); |
| 841 | ccn_charbuf_append_string(lsa_data,"|"); |
| 842 | |
| 843 | char *temp_npl=(char *)malloc(20); |
| 844 | memset(temp_npl,0,20); |
| 845 | sprintf(temp_npl,"%d",name_lsa->name_prefix->length); |
| 846 | ccn_charbuf_append_string(lsa_data,temp_npl); |
| 847 | free(temp_npl); |
| 848 | ccn_charbuf_append_string(lsa_data,"|"); |
| 849 | |
| 850 | } |
| 851 | else if(res == HT_NEW_ENTRY) |
| 852 | { |
| 853 | hashtb_delete(e); |
| 854 | } |
| 855 | |
| 856 | hashtb_end(e); |
| 857 | } |
| 858 | |
| 859 | void |
| 860 | get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 861 | { |
| 862 | printf("get_adj_lsa_data called \n"); |
| 863 | |
| 864 | struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 865 | |
| 866 | struct hashtb_enumerator ee; |
| 867 | struct hashtb_enumerator *e = ⅇ |
| 868 | int res; |
| 869 | |
| 870 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 871 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 872 | |
| 873 | if( res == HT_OLD_ENTRY ) |
| 874 | { |
| 875 | adj_lsa=e->data; |
| 876 | printf("NAME LSA found\n"); |
| 877 | |
| 878 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name); |
| 879 | ccn_charbuf_append_string(lsa_data,"|"); |
| 880 | |
| 881 | char *temp_length=(char *)malloc(20); |
| 882 | memset(temp_length,0,20); |
| 883 | sprintf(temp_length,"%d",adj_lsa->header->orig_router->length); |
| 884 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 885 | free(temp_length); |
| 886 | ccn_charbuf_append_string(lsa_data,"|"); |
| 887 | |
| 888 | char *temp_ltype=(char *)malloc(20); |
| 889 | memset(temp_ltype,0,20); |
| 890 | sprintf(temp_ltype,"%d",adj_lsa->header->ls_type); |
| 891 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 892 | free(temp_ltype); |
| 893 | ccn_charbuf_append_string(lsa_data,"|"); |
| 894 | |
| 895 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time); |
| 896 | ccn_charbuf_append_string(lsa_data,"|"); |
| 897 | |
| 898 | char *temp_nl=(char *)malloc(20); |
| 899 | memset(temp_nl,0,20); |
| 900 | sprintf(temp_nl,"%d",adj_lsa->no_link); |
| 901 | ccn_charbuf_append_string(lsa_data,temp_nl); |
| 902 | free(temp_nl); |
| 903 | ccn_charbuf_append_string(lsa_data,"|"); |
| 904 | |
| 905 | ccn_charbuf_append_string(lsa_data,adj_lsa->body); |
| 906 | |
| 907 | |
| 908 | } |
| 909 | else if(res == HT_NEW_ENTRY) |
| 910 | { |
| 911 | hashtb_delete(e); |
| 912 | } |
| 913 | |
| 914 | hashtb_end(e); |
| 915 | } |
| 916 | |
| 917 | long int |
| 918 | get_name_lsdb_num_element(void) |
| 919 | { |
| 920 | long int num_element; |
| 921 | |
| 922 | |
| 923 | struct hashtb_enumerator ee; |
| 924 | struct hashtb_enumerator *e = ⅇ |
| 925 | |
| 926 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 927 | num_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 928 | hashtb_end(e); |
| 929 | |
| 930 | return num_element; |
| 931 | } |
| 932 | |
| 933 | long int |
| 934 | get_adj_lsdb_num_element(void) |
| 935 | { |
| 936 | long int num_element; |
| 937 | |
| 938 | |
| 939 | struct hashtb_enumerator ee; |
| 940 | struct hashtb_enumerator *e = ⅇ |
| 941 | |
| 942 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 943 | num_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 944 | hashtb_end(e); |
| 945 | |
| 946 | return num_element; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 947 | } |