akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [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_ndn.h" |
| 22 | #include "nlsr_lsdb.h" |
| 23 | #include "utility.h" |
| 24 | #include "nlsr_npl.h" |
| 25 | #include "nlsr_adl.h" |
| 26 | #include "nlsr_route.h" |
| 27 | #include "nlsr_npt.h" |
| 28 | #include "nlsr_sync.h" |
| 29 | |
| 30 | void |
| 31 | set_new_lsdb_version(void) |
| 32 | { |
| 33 | |
| 34 | char *time_stamp=(char *)malloc(20); |
| 35 | memset(time_stamp,0,20); |
| 36 | get_current_timestamp_micro(time_stamp); |
| 37 | |
| 38 | free(nlsr->lsdb->lsdb_version); |
| 39 | nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1); |
| 40 | memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1); |
| 41 | memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1); |
| 42 | |
| 43 | free(time_stamp); |
| 44 | |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id) |
| 49 | { |
| 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 | } |
| 66 | |
| 67 | |
| 68 | void |
| 69 | make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type, long int ls_id,char *orig_time,char *slice_prefix) |
| 70 | { |
| 71 | |
| 72 | |
| 73 | //printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id); |
| 74 | |
| 75 | char lst[2]; |
| 76 | memset(lst,0,2); |
| 77 | sprintf(lst,"%d",ls_type); |
| 78 | |
| 79 | char lsid[10]; |
| 80 | memset(lsid,0,10); |
| 81 | sprintf(lsid,"%ld",ls_id); |
| 82 | memcpy(key+strlen(key),slice_prefix,strlen(slice_prefix)); |
| 83 | memcpy(key+strlen(key),"/",1); |
| 84 | memcpy(key+strlen(key),lst,strlen(lst)); |
| 85 | memcpy(key+strlen(key),"/",1); |
| 86 | memcpy(key+strlen(key),lsid,strlen(lsid)); |
| 87 | memcpy(key+strlen(key),"/",1); |
| 88 | memcpy(key+strlen(key),orig_time,strlen(orig_time)); |
| 89 | memcpy(key+strlen(key),orig_router,strlen(orig_router)); |
| 90 | |
| 91 | //printf("Key: %s\n",key); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | build_and_install_name_lsas(void) |
| 96 | { |
| 97 | if ( nlsr->debugging ) |
| 98 | printf("build_and_install_name_lsas called \n"); |
| 99 | if ( nlsr->detailed_logging ) |
| 100 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n"); |
| 101 | |
| 102 | int i, npl_element; |
| 103 | //struct name_prefix *np; |
| 104 | struct name_prefix_list_entry *npe; |
| 105 | |
| 106 | struct hashtb_enumerator ee; |
| 107 | struct hashtb_enumerator *e = ⅇ |
| 108 | |
| 109 | hashtb_start(nlsr->npl, e); |
| 110 | npl_element=hashtb_n(nlsr->npl); |
| 111 | |
| 112 | for(i=0;i<npl_element;i++) |
| 113 | { |
| 114 | npe=e->data; |
| 115 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 116 | build_name_lsa(name_lsa,npe->np); |
| 117 | |
| 118 | install_name_lsa(name_lsa); |
| 119 | update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id); |
| 120 | free(name_lsa->header->orig_router->name); |
| 121 | free(name_lsa->header->orig_router); |
| 122 | free(name_lsa->header); |
| 123 | free(name_lsa->name_prefix->name); |
| 124 | free(name_lsa->name_prefix); |
| 125 | free(name_lsa); |
| 126 | hashtb_next(e); |
| 127 | } |
| 128 | |
| 129 | hashtb_end(e); |
| 130 | |
| 131 | print_name_prefix_from_npl(); |
| 132 | |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | build_and_install_single_name_lsa(struct name_prefix *np) |
| 137 | { |
| 138 | if ( nlsr->debugging ) |
| 139 | printf("build_and_install_single_name_lsa called \n"); |
| 140 | if ( nlsr->detailed_logging ) |
| 141 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name_lsa called\n"); |
| 142 | |
| 143 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 144 | build_name_lsa(name_lsa,np); |
| 145 | |
| 146 | install_name_lsa(name_lsa); |
| 147 | update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id); |
| 148 | |
| 149 | free(name_lsa->header->orig_router->name); |
| 150 | free(name_lsa->header->orig_router); |
| 151 | free(name_lsa->header); |
| 152 | free(name_lsa->name_prefix->name); |
| 153 | free(name_lsa->name_prefix); |
| 154 | free(name_lsa); |
| 155 | |
| 156 | print_name_prefix_from_npl(); |
| 157 | |
| 158 | } |
| 159 | |
| 160 | void |
| 161 | build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np) |
| 162 | { |
| 163 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 164 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 165 | |
| 166 | char *time_stamp=(char *)malloc(20); |
| 167 | memset(time_stamp,0,20); |
| 168 | get_current_timestamp_micro(time_stamp); |
| 169 | |
| 170 | name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free |
| 171 | memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 172 | memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 173 | |
| 174 | free(time_stamp); |
| 175 | |
| 176 | name_lsa->header->ls_id=++nlsr->nlsa_id; |
| 177 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 178 | name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 179 | memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 180 | memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 181 | name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 182 | name_lsa->header->isValid=1; |
| 183 | |
| 184 | |
| 185 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 186 | name_lsa->name_prefix->name=(char *)malloc(np->length); |
| 187 | memcpy(name_lsa->name_prefix->name,np->name,np->length); |
| 188 | name_lsa->name_prefix->length=np->length; |
| 189 | |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | install_name_lsa(struct nlsa *name_lsa) |
| 194 | { |
| 195 | |
| 196 | char *time_stamp=(char *)malloc(20); |
| 197 | memset(time_stamp,0,20); |
| 198 | get_current_timestamp_micro(time_stamp); |
| 199 | //long int lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
| 200 | |
| 201 | //printf("time difference: %ld \n",lsa_life_time); |
| 202 | |
| 203 | |
| 204 | char lst[2]; |
| 205 | memset(lst,0,2); |
| 206 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 207 | |
| 208 | char lsid[10]; |
| 209 | memset(lsid,0,10); |
| 210 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 211 | |
| 212 | |
| 213 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 214 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 215 | |
| 216 | |
| 217 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 218 | if ( nlsr->debugging ) |
| 219 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 220 | if ( nlsr->detailed_logging ) |
| 221 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key)); |
| 222 | |
| 223 | |
| 224 | struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free |
| 225 | |
| 226 | struct hashtb_enumerator ee; |
| 227 | struct hashtb_enumerator *e = ⅇ |
| 228 | int res; |
| 229 | |
| 230 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 231 | res = hashtb_seek(e, key, strlen(key), 0); |
| 232 | |
| 233 | if(res == HT_NEW_ENTRY ) |
| 234 | { |
| 235 | |
| 236 | if ( nlsr->debugging ) |
| 237 | printf("New Name LSA... Adding to LSDB\n"); |
| 238 | if ( nlsr->detailed_logging ) |
| 239 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n"); |
| 240 | |
| 241 | |
| 242 | new_name_lsa = e->data; |
| 243 | |
| 244 | new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free |
| 245 | new_name_lsa->header->ls_type=name_lsa->header->ls_type; |
| 246 | |
| 247 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 248 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 249 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 250 | |
| 251 | new_name_lsa->header->ls_id=name_lsa->header->ls_id; |
| 252 | new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 253 | new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length); |
| 254 | memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length); |
| 255 | new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length; |
| 256 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 257 | |
| 258 | |
| 259 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 260 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 261 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 262 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 263 | |
| 264 | if ( nlsr->debugging ) |
| 265 | { |
| 266 | printf("New Name LSA Added....\n"); |
| 267 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 268 | } |
| 269 | if ( nlsr->detailed_logging ) |
| 270 | { |
| 271 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n"); |
| 272 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 273 | } |
| 274 | set_new_lsdb_version(); |
| 275 | if ( nlsr->debugging ) |
| 276 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 277 | if ( nlsr->detailed_logging ) |
| 278 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 279 | |
| 280 | |
| 281 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
| 282 | if ( num_next_hop < 0 ) |
| 283 | { |
| 284 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL); |
| 285 | if ( check == HT_NEW_ENTRY ) |
| 286 | { |
| 287 | if ( nlsr->debugging ) |
| 288 | printf("Added in npt \n"); |
| 289 | if ( nlsr->detailed_logging ) |
| 290 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
| 291 | } |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 296 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 297 | int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs); |
| 298 | if ( nlsr->debugging ) |
| 299 | { |
| 300 | printf("Printing from install_name_lsa \n"); |
| 301 | int j; |
| 302 | for(j=0;j<num_next_hop;j++) |
| 303 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 304 | } |
| 305 | if ( nlsr->detailed_logging ) |
| 306 | { |
| 307 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n"); |
| 308 | int j; |
| 309 | for(j=0;j<num_next_hop;j++) |
| 310 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 311 | } |
| 312 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs); |
| 313 | if ( check == HT_NEW_ENTRY ) |
| 314 | { |
| 315 | if ( nlsr->debugging ) |
| 316 | printf("Added in npt \n"); |
| 317 | if ( nlsr->detailed_logging ) |
| 318 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
| 319 | } |
| 320 | free(faces); |
| 321 | free(route_costs); |
| 322 | |
| 323 | } |
| 324 | |
| 325 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 326 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 327 | write_log_for_name_lsa(new_name_lsa); |
| 328 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 329 | |
| 330 | free(time_stamp); |
| 331 | |
| 332 | } |
| 333 | else if(res == HT_OLD_ENTRY) |
| 334 | { |
| 335 | new_name_lsa=e->data; |
| 336 | if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0) |
| 337 | { |
| 338 | if ( nlsr->debugging ) |
| 339 | printf("Older Adj LSA. Discarded... \n"); |
| 340 | if ( nlsr->detailed_logging ) |
| 341 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n"); |
| 342 | } |
| 343 | else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 ) |
| 344 | { |
| 345 | if ( nlsr->debugging ) |
| 346 | printf("Duplicate Adj LSA. Discarded... \n"); |
| 347 | if ( nlsr->detailed_logging ) |
| 348 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n"); |
| 349 | } |
| 350 | else |
| 351 | { |
| 352 | if ( name_lsa->header->isValid == 0 ) |
| 353 | { |
| 354 | // have to call to delete npt table entry |
| 355 | delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name); |
| 356 | |
| 357 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0) |
| 358 | { |
| 359 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 360 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 361 | write_log_for_name_lsa(new_name_lsa); |
| 362 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 363 | |
| 364 | hashtb_delete(e); |
| 365 | if ( nlsr->debugging ) |
| 366 | printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name); |
| 367 | if ( nlsr->detailed_logging ) |
| 368 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name); |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 373 | free(new_name_lsa->header->orig_time); |
| 374 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 375 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 376 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 377 | } |
| 378 | if ( nlsr->debugging ) |
| 379 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 380 | if ( nlsr->detailed_logging ) |
| 381 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 382 | set_new_lsdb_version(); |
| 383 | if ( nlsr->debugging ) |
| 384 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 385 | if ( nlsr->detailed_logging ) |
| 386 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | int is_npt_update=0; |
| 391 | if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 ) |
| 392 | { |
| 393 | is_npt_update=1; |
| 394 | delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name); |
| 395 | } |
| 396 | |
| 397 | // copying LSA content with header |
| 398 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 399 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 400 | write_log_for_name_lsa(new_name_lsa); |
| 401 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 402 | |
| 403 | |
| 404 | free(new_name_lsa->header->orig_time); |
| 405 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 406 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 407 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 408 | |
| 409 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 410 | |
| 411 | free(new_name_lsa->name_prefix->name); |
| 412 | free(new_name_lsa->name_prefix); |
| 413 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 414 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 415 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 416 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 417 | |
| 418 | |
| 419 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 420 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 421 | write_log_for_name_lsa(new_name_lsa); |
| 422 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 423 | |
| 424 | if ( nlsr->debugging ) |
| 425 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 426 | if ( nlsr->detailed_logging ) |
| 427 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 428 | |
| 429 | set_new_lsdb_version(); |
| 430 | |
| 431 | if ( nlsr->debugging ) |
| 432 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 433 | if ( nlsr->detailed_logging ) |
| 434 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 435 | |
| 436 | |
| 437 | if( is_npt_update == 1 ) |
| 438 | { |
| 439 | //struct hashtb *face_list; |
| 440 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
| 441 | if ( num_next_hop < 0 ) |
| 442 | { |
| 443 | |
| 444 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL); |
| 445 | if ( check == HT_NEW_ENTRY ) |
| 446 | { |
| 447 | if ( nlsr->debugging ) |
| 448 | printf("Added in npt \n"); |
| 449 | if ( nlsr->detailed_logging ) |
| 450 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
| 451 | } |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 456 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 457 | int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs); |
| 458 | |
| 459 | if ( nlsr->debugging ) |
| 460 | { |
| 461 | printf("Printing from install_name_lsa \n"); |
| 462 | int j; |
| 463 | for(j=0;j<num_next_hop;j++) |
| 464 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 465 | } |
| 466 | if ( nlsr->detailed_logging ) |
| 467 | { |
| 468 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n"); |
| 469 | int j; |
| 470 | for(j=0;j<num_next_hop;j++) |
| 471 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs); |
| 476 | if ( check == HT_NEW_ENTRY ) |
| 477 | { |
| 478 | //printf("Added in npt \n"); |
| 479 | if ( nlsr->debugging ) |
| 480 | printf("Added in npt \n"); |
| 481 | if ( nlsr->detailed_logging ) |
| 482 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
| 483 | } |
| 484 | free(faces); |
| 485 | free(route_costs); |
| 486 | |
| 487 | } |
| 488 | |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | } |
| 494 | |
| 495 | hashtb_end(e); |
| 496 | |
| 497 | free(key); |
| 498 | } |
| 499 | |
| 500 | void |
| 501 | write_log_for_name_lsa(struct nlsa *name_lsa) |
| 502 | { |
| 503 | |
| 504 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n"); |
| 505 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name); |
| 506 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
| 507 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type); |
| 508 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id); |
| 509 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time); |
| 510 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid); |
| 511 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n"); |
| 512 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name); |
| 513 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length); |
| 514 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 515 | } |
| 516 | |
| 517 | void |
| 518 | print_name_lsa(struct nlsa *name_lsa) |
| 519 | { |
| 520 | |
| 521 | if ( nlsr->debugging ) |
| 522 | { |
| 523 | printf("-----------Name LSA Content---------------\n"); |
| 524 | printf(" Origination Router : %s\n",name_lsa->header->orig_router->name); |
| 525 | printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
| 526 | printf(" LS Type : %d\n",name_lsa->header->ls_type); |
| 527 | printf(" LS Id : %ld\n",name_lsa->header->ls_id); |
| 528 | printf(" Origination Time : %s\n",name_lsa->header->orig_time); |
| 529 | printf(" Is Valid : %d\n",name_lsa->header->isValid); |
| 530 | printf(" LSA Data \n"); |
| 531 | printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name); |
| 532 | printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length); |
| 533 | |
| 534 | printf("\n"); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | void |
| 539 | print_name_lsdb(void) |
| 540 | { |
| 541 | if ( nlsr->debugging ) |
| 542 | printf("print_name_lsdb called \n"); |
| 543 | int i, name_lsdb_element; |
| 544 | struct nlsa *name_lsa; |
| 545 | |
| 546 | struct hashtb_enumerator ee; |
| 547 | struct hashtb_enumerator *e = ⅇ |
| 548 | |
| 549 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 550 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 551 | |
| 552 | for(i=0;i<name_lsdb_element;i++) |
| 553 | { |
| 554 | if ( nlsr->debugging ) |
| 555 | printf("-----------Name LSA (%d)---------------\n",i+1); |
| 556 | name_lsa=e->data; |
| 557 | print_name_lsa(name_lsa); |
| 558 | hashtb_next(e); |
| 559 | } |
| 560 | |
| 561 | hashtb_end(e); |
| 562 | |
| 563 | if ( nlsr->debugging ) |
| 564 | printf("\n"); |
| 565 | if ( nlsr->detailed_logging ) |
| 566 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 567 | } |
| 568 | |
| 569 | |
| 570 | void |
| 571 | build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np) |
| 572 | { |
| 573 | if ( nlsr->debugging ) |
| 574 | printf("build_and_install_others_name_lsa called \n"); |
| 575 | if ( nlsr->detailed_logging ) |
| 576 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n"); |
| 577 | |
| 578 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 579 | build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np); |
| 580 | print_name_lsa(name_lsa); |
| 581 | install_name_lsa(name_lsa); |
| 582 | print_name_lsdb(); |
| 583 | print_npt(); |
| 584 | |
| 585 | free(name_lsa->header->orig_router->name); |
| 586 | free(name_lsa->header->orig_router); |
| 587 | free(name_lsa->header); |
| 588 | free(name_lsa->name_prefix->name); |
| 589 | free(name_lsa->name_prefix); |
| 590 | free(name_lsa); |
| 591 | |
| 592 | } |
| 593 | |
| 594 | void |
| 595 | build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np) |
| 596 | { |
| 597 | if ( nlsr->debugging ) |
| 598 | printf("build_others_name_lsa called\n"); |
| 599 | if ( nlsr->detailed_logging ) |
| 600 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n"); |
| 601 | |
| 602 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 603 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 604 | |
| 605 | name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 606 | memset(name_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 607 | memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
| 608 | |
| 609 | name_lsa->header->ls_id=ls_id; |
| 610 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 611 | name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 612 | memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 613 | memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 614 | name_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 615 | name_lsa->header->isValid=isValid; |
| 616 | |
| 617 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 618 | name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1); |
| 619 | memset(name_lsa->name_prefix->name,0,strlen(np)+1); |
| 620 | memcpy(name_lsa->name_prefix->name,np,strlen(np)+1); |
| 621 | name_lsa->name_prefix->length=strlen(np)+1; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | void |
| 628 | make_adj_lsa_key(char *key,struct alsa *adj_lsa) |
| 629 | { |
| 630 | memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 631 | memcpy(key+strlen(key),"/",1); |
| 632 | char ls_type[2]; |
| 633 | sprintf(ls_type,"%d",adj_lsa->header->ls_type); |
| 634 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 635 | key[strlen(key)]='\0'; |
| 636 | } |
| 637 | |
| 638 | int |
| 639 | build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 640 | { |
| 641 | if(flags == CCN_SCHEDULE_CANCEL) |
| 642 | { |
| 643 | return -1; |
| 644 | } |
| 645 | |
| 646 | nlsr_lock(); |
| 647 | |
| 648 | if ( nlsr->debugging ) |
| 649 | printf("build_and_install_adj_lsa called \n"); |
| 650 | if ( nlsr->detailed_logging ) |
| 651 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n"); |
| 652 | |
| 653 | if ( nlsr->debugging ) |
| 654 | printf("adj_build_flag = %d \n",nlsr->adj_build_flag); |
| 655 | if ( nlsr->detailed_logging ) |
| 656 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag); |
| 657 | |
| 658 | if(nlsr->adj_build_flag > 0) |
| 659 | { |
| 660 | if ( nlsr->debugging ) |
| 661 | printf("is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 662 | if ( nlsr->detailed_logging ) |
| 663 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 664 | |
| 665 | if ( is_adj_lsa_build()> 0) |
| 666 | { |
| 667 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 668 | build_adj_lsa(adj_lsa); |
| 669 | install_adj_lsa(adj_lsa); |
| 670 | |
| 671 | free(adj_lsa->header->orig_router->name); |
| 672 | free(adj_lsa->header->orig_router); |
| 673 | free(adj_lsa->header->orig_time); |
| 674 | free(adj_lsa->header); |
| 675 | free(adj_lsa->body); |
| 676 | free(adj_lsa); |
| 677 | nlsr->adj_build_flag=0; |
| 678 | print_adj_lsdb(); |
| 679 | } |
| 680 | else |
| 681 | { |
| 682 | if ( nlsr->debugging ) |
| 683 | printf("Can not build adj LSA now\n"); |
| 684 | if ( nlsr->detailed_logging ) |
| 685 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n"); |
| 686 | } |
| 687 | } |
| 688 | nlsr->is_build_adj_lsa_sheduled=0; |
| 689 | |
| 690 | nlsr_unlock(); |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | |
| 696 | void |
| 697 | build_adj_lsa(struct alsa * adj_lsa) |
| 698 | { |
| 699 | if ( nlsr->debugging ) |
| 700 | printf("build_adj_lsa called \n"); |
| 701 | if ( nlsr->detailed_logging ) |
| 702 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n"); |
| 703 | |
| 704 | int no_link=no_active_nbr(); |
| 705 | |
| 706 | //printf("Number of link in Adjacent LSA: %d\n",no_link); |
| 707 | |
| 708 | /*Filling Up Header Data */ |
| 709 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 710 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 711 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 712 | memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 713 | memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 714 | adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 715 | |
| 716 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 717 | |
| 718 | char *time_stamp=(char *)malloc(20); |
| 719 | memset(time_stamp,0,20); |
| 720 | get_current_timestamp_micro(time_stamp); |
| 721 | |
| 722 | adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 723 | memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 724 | memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 725 | free(time_stamp); |
| 726 | |
| 727 | |
| 728 | /* Filling Up Body Data */ |
| 729 | |
| 730 | adj_lsa->no_link=no_link; |
| 731 | |
| 732 | |
| 733 | struct ccn_charbuf *c=ccn_charbuf_create(); |
| 734 | get_active_nbr_adj_data(c); |
| 735 | char *data=ccn_charbuf_as_string(c); |
| 736 | |
| 737 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 738 | memset(adj_lsa->body,0,strlen(data)+1); |
| 739 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 740 | ccn_charbuf_destroy(&c); |
| 741 | |
| 742 | |
| 743 | |
| 744 | if( !nlsr->is_send_lsdb_interest_scheduled ) |
| 745 | { |
| 746 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0); |
| 747 | nlsr->is_send_lsdb_interest_scheduled=1; |
| 748 | } |
| 749 | |
| 750 | nlsr->adj_build_count++; |
| 751 | |
| 752 | |
| 753 | } |
| 754 | |
| 755 | |
| 756 | void |
| 757 | install_adj_lsa(struct alsa * adj_lsa) |
| 758 | { |
| 759 | |
| 760 | if ( nlsr->debugging ) |
| 761 | printf("install_adj_lsa called \n"); |
| 762 | if ( nlsr->detailed_logging ) |
| 763 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n"); |
| 764 | |
| 765 | |
| 766 | char *time_stamp=(char *)malloc(20); |
| 767 | memset(time_stamp,0,20); |
| 768 | get_current_timestamp_micro(time_stamp); |
| 769 | //long int lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
| 770 | |
| 771 | //printf("time difference: %ld \n",lsa_life_time); |
| 772 | |
| 773 | |
| 774 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 775 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 776 | make_adj_lsa_key(key,adj_lsa); |
| 777 | //printf("Adjacent LSA key: %s \n",key); |
| 778 | |
| 779 | struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 780 | |
| 781 | struct hashtb_enumerator ee; |
| 782 | struct hashtb_enumerator *e = ⅇ |
| 783 | int res; |
| 784 | |
| 785 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 786 | res = hashtb_seek(e, key, strlen(key), 0); |
| 787 | |
| 788 | |
| 789 | |
| 790 | if(res == HT_NEW_ENTRY) |
| 791 | { |
| 792 | if ( adj_lsa->no_link > 0) |
| 793 | { |
| 794 | if ( nlsr->debugging ) |
| 795 | printf("New ADJ LSA... Adding to LSDB\n"); |
| 796 | if ( nlsr->detailed_logging ) |
| 797 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n"); |
| 798 | new_adj_lsa = e->data; |
| 799 | |
| 800 | new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 801 | new_adj_lsa->header->ls_type=adj_lsa->header->ls_type; |
| 802 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 803 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 804 | |
| 805 | new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 806 | new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length); |
| 807 | memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 808 | new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length; |
| 809 | |
| 810 | new_adj_lsa->no_link=adj_lsa->no_link; |
| 811 | |
| 812 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 813 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 814 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 815 | |
| 816 | add_next_hop_router(new_adj_lsa->header->orig_router->name); |
| 817 | add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link); |
| 818 | |
| 819 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 820 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 821 | write_log_for_adj_lsa(new_adj_lsa); |
| 822 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 823 | } |
| 824 | else |
| 825 | { |
| 826 | hashtb_delete(e); |
| 827 | } |
| 828 | |
| 829 | if ( nlsr->debugging ) |
| 830 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 831 | if ( nlsr->detailed_logging ) |
| 832 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 833 | |
| 834 | set_new_lsdb_version(); |
| 835 | |
| 836 | if ( nlsr->debugging ) |
| 837 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 838 | if ( nlsr->detailed_logging ) |
| 839 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 840 | |
| 841 | } |
| 842 | else if(res == HT_OLD_ENTRY) |
| 843 | { |
| 844 | new_adj_lsa = e->data; |
| 845 | if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0) |
| 846 | { |
| 847 | if ( nlsr->debugging ) |
| 848 | printf("Older/Duplicate Adj LSA. Discarded...\n"); |
| 849 | if ( nlsr->detailed_logging ) |
| 850 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n"); |
| 851 | } |
| 852 | else |
| 853 | { |
| 854 | |
| 855 | if ( adj_lsa->no_link > 0) |
| 856 | { |
| 857 | //new_adj_lsa = e->data; |
| 858 | |
| 859 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 860 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 861 | write_log_for_adj_lsa(new_adj_lsa); |
| 862 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 863 | |
| 864 | free(new_adj_lsa->header->orig_time); |
| 865 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 866 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 867 | |
| 868 | new_adj_lsa->no_link=adj_lsa->no_link; |
| 869 | |
| 870 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 871 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 872 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 873 | |
| 874 | add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link); |
| 875 | |
| 876 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 877 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 878 | write_log_for_adj_lsa(new_adj_lsa); |
| 879 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 880 | } |
| 881 | else |
| 882 | { |
| 883 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 884 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 885 | write_log_for_adj_lsa(new_adj_lsa); |
| 886 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 887 | |
| 888 | hashtb_delete(e); |
| 889 | } |
| 890 | |
| 891 | if ( nlsr->debugging ) |
| 892 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 893 | if ( nlsr->detailed_logging ) |
| 894 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 895 | |
| 896 | set_new_lsdb_version(); |
| 897 | |
| 898 | if ( nlsr->debugging ) |
| 899 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 900 | if ( nlsr->detailed_logging ) |
| 901 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 902 | } |
| 903 | |
| 904 | } |
| 905 | hashtb_end(e); |
| 906 | |
| 907 | if ( !nlsr->is_route_calculation_scheduled ) |
| 908 | { |
| 909 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 910 | nlsr->is_route_calculation_scheduled=1; |
| 911 | } |
| 912 | |
| 913 | |
| 914 | free(key); |
| 915 | |
| 916 | free(time_stamp); |
| 917 | } |
| 918 | |
| 919 | void |
| 920 | write_log_for_adj_lsa_body(const char *body, int no_link) |
| 921 | { |
| 922 | int i=0; |
| 923 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 924 | memset( lsa_data,0,strlen(body)+1); |
| 925 | memcpy(lsa_data,body,strlen(body)+1); |
| 926 | char *sep="|"; |
| 927 | char *rem; |
| 928 | char *rtr_id; |
| 929 | char *length; |
| 930 | char *face; |
| 931 | char *metric; |
| 932 | |
| 933 | if(no_link >0 ) |
| 934 | { |
| 935 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 936 | length=strtok_r(NULL,sep,&rem); |
| 937 | face=strtok_r(NULL,sep,&rem); |
| 938 | metric=strtok_r(NULL,sep,&rem); |
| 939 | |
| 940 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
| 941 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 942 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
| 943 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
| 944 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
| 945 | |
| 946 | |
| 947 | for(i=1;i<no_link;i++) |
| 948 | { |
| 949 | rtr_id=strtok_r(NULL,sep,&rem); |
| 950 | length=strtok_r(NULL,sep,&rem); |
| 951 | face=strtok_r(NULL,sep,&rem); |
| 952 | metric=strtok_r(NULL,sep,&rem); |
| 953 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
| 954 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 955 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
| 956 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
| 957 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
| 958 | |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | free(lsa_data); |
| 963 | } |
| 964 | |
| 965 | |
| 966 | void |
| 967 | write_log_for_adj_lsa(struct alsa * adj_lsa) |
| 968 | { |
| 969 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n"); |
| 970 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name); |
| 971 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 972 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type); |
| 973 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time); |
| 974 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n"); |
| 975 | writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link); |
| 976 | |
| 977 | write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 978 | |
| 979 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 980 | |
| 981 | } |
| 982 | |
| 983 | void |
| 984 | print_adj_lsa_body(const char *body, int no_link) |
| 985 | { |
| 986 | int i=0; |
| 987 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 988 | memset( lsa_data,0,strlen(body)+1); |
| 989 | memcpy(lsa_data,body,strlen(body)+1); |
| 990 | char *sep="|"; |
| 991 | char *rem; |
| 992 | char *rtr_id; |
| 993 | char *length; |
| 994 | char *face; |
| 995 | char *metric; |
| 996 | |
| 997 | if(no_link >0 ) |
| 998 | { |
| 999 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 1000 | length=strtok_r(NULL,sep,&rem); |
| 1001 | face=strtok_r(NULL,sep,&rem); |
| 1002 | metric=strtok_r(NULL,sep,&rem); |
| 1003 | |
| 1004 | printf(" Link %d \n",i+1); |
| 1005 | printf(" Neighbor : %s \n",rtr_id); |
| 1006 | printf(" Neighbor Length : %s \n",length); |
| 1007 | printf(" Connecting Face : %s \n",face); |
| 1008 | printf(" Metric : %s \n",metric); |
| 1009 | |
| 1010 | |
| 1011 | for(i=1;i<no_link;i++) |
| 1012 | { |
| 1013 | rtr_id=strtok_r(NULL,sep,&rem); |
| 1014 | length=strtok_r(NULL,sep,&rem); |
| 1015 | face=strtok_r(NULL,sep,&rem); |
| 1016 | metric=strtok_r(NULL,sep,&rem); |
| 1017 | printf(" Link %d \n",i+1); |
| 1018 | printf(" Neighbor : %s \n",rtr_id); |
| 1019 | printf(" Neighbor Length : %s \n",length); |
| 1020 | printf(" Connecting Face : %s \n",face); |
| 1021 | printf(" Metric : %s \n",metric); |
| 1022 | |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | free(lsa_data); |
| 1027 | } |
| 1028 | |
| 1029 | void |
| 1030 | print_adj_lsa(struct alsa * adj_lsa) |
| 1031 | { |
| 1032 | if ( nlsr->debugging ) |
| 1033 | { |
| 1034 | printf("-----------ADJ LSA Content---------------\n"); |
| 1035 | printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name); |
| 1036 | printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 1037 | printf(" LS Type : %d\n",adj_lsa->header->ls_type); |
| 1038 | printf(" Origination Time : %s\n",adj_lsa->header->orig_time); |
| 1039 | printf(" Lsa Data:\n"); |
| 1040 | printf(" No of Link : %d\n",adj_lsa->no_link); |
| 1041 | |
| 1042 | print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 1043 | printf("\n"); |
| 1044 | } |
| 1045 | |
| 1046 | } |
| 1047 | |
| 1048 | void |
| 1049 | print_adj_lsdb(void) |
| 1050 | { |
| 1051 | if ( nlsr->debugging ) |
| 1052 | printf("print_name_lsdb called \n"); |
| 1053 | int i, adj_lsdb_element; |
| 1054 | struct alsa *adj_lsa; |
| 1055 | |
| 1056 | struct hashtb_enumerator ee; |
| 1057 | struct hashtb_enumerator *e = ⅇ |
| 1058 | |
| 1059 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1060 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1061 | |
| 1062 | for(i=0;i<adj_lsdb_element;i++) |
| 1063 | { |
| 1064 | if ( nlsr->debugging ) |
| 1065 | printf("-----------Adj LSA (%d)---------------\n",i+1); |
| 1066 | adj_lsa=e->data; |
| 1067 | print_adj_lsa(adj_lsa); |
| 1068 | hashtb_next(e); |
| 1069 | } |
| 1070 | |
| 1071 | hashtb_end(e); |
| 1072 | |
| 1073 | if ( nlsr->debugging ) |
| 1074 | printf("\n"); |
| 1075 | if ( nlsr->detailed_logging ) |
| 1076 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 1077 | } |
| 1078 | |
| 1079 | void |
| 1080 | build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data) |
| 1081 | { |
| 1082 | if ( nlsr->debugging ) |
| 1083 | printf("build_and_install_others_adj_lsa called \n"); |
| 1084 | if ( nlsr->detailed_logging ) |
| 1085 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n"); |
| 1086 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 1087 | build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data); |
| 1088 | //print_adj_lsa(adj_lsa); |
| 1089 | install_adj_lsa(adj_lsa); |
| 1090 | |
| 1091 | |
| 1092 | free(adj_lsa->header->orig_router->name); |
| 1093 | free(adj_lsa->header->orig_router); |
| 1094 | free(adj_lsa->header->orig_time); |
| 1095 | free(adj_lsa->header); |
| 1096 | free(adj_lsa->body); |
| 1097 | free(adj_lsa); |
| 1098 | |
| 1099 | print_adj_lsdb(); |
| 1100 | |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | void |
| 1105 | build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data) |
| 1106 | { |
| 1107 | //printf("build_others_adj_lsa called \n"); |
| 1108 | if ( nlsr->debugging ) |
| 1109 | printf("build_others_adj_lsa called \n"); |
| 1110 | if ( nlsr->detailed_logging ) |
| 1111 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n"); |
| 1112 | |
| 1113 | /*Filling Up Header Data */ |
| 1114 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 1115 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1116 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 1117 | memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 1118 | memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 1119 | |
| 1120 | adj_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 1121 | |
| 1122 | |
| 1123 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 1124 | |
| 1125 | adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 1126 | memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 1127 | memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
| 1128 | |
| 1129 | adj_lsa->no_link=no_link; |
| 1130 | |
| 1131 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 1132 | memset(adj_lsa->body,0,strlen(data)+1); |
| 1133 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 1134 | |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | long int |
| 1139 | get_name_lsdb_num_element(void) |
| 1140 | { |
| 1141 | long int num_element; |
| 1142 | |
| 1143 | |
| 1144 | struct hashtb_enumerator ee; |
| 1145 | struct hashtb_enumerator *e = ⅇ |
| 1146 | |
| 1147 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1148 | num_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1149 | hashtb_end(e); |
| 1150 | |
| 1151 | return num_element; |
| 1152 | } |
| 1153 | |
| 1154 | long int |
| 1155 | get_adj_lsdb_num_element(void) |
| 1156 | { |
| 1157 | long int num_element; |
| 1158 | |
| 1159 | |
| 1160 | struct hashtb_enumerator ee; |
| 1161 | struct hashtb_enumerator *e = ⅇ |
| 1162 | |
| 1163 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1164 | num_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1165 | hashtb_end(e); |
| 1166 | |
| 1167 | return num_element; |
| 1168 | } |
| 1169 | |
| 1170 | void |
| 1171 | get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data) |
| 1172 | { |
| 1173 | //printf("get_name_lsdb_summary called \n"); |
| 1174 | if ( nlsr->debugging ) |
| 1175 | printf("get_name_lsdb_summary called \n"); |
| 1176 | if ( nlsr->detailed_logging ) |
| 1177 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsdb_summary called \n"); |
| 1178 | |
| 1179 | int i, name_lsdb_element; |
| 1180 | |
| 1181 | struct nlsa *name_lsa; |
| 1182 | struct hashtb_enumerator ee; |
| 1183 | struct hashtb_enumerator *e = ⅇ |
| 1184 | |
| 1185 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1186 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1187 | |
| 1188 | for(i=0;i<name_lsdb_element;i++) |
| 1189 | { |
| 1190 | name_lsa=e->data; |
| 1191 | |
| 1192 | ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name); |
| 1193 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1194 | |
| 1195 | char *lst=(char *)malloc(20); |
| 1196 | memset(lst,0,20); |
| 1197 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1198 | ccn_charbuf_append_string(name_lsdb_data,lst); |
| 1199 | free(lst); |
| 1200 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1201 | |
| 1202 | char *lsid=(char *)malloc(20); |
| 1203 | memset(lsid,0,20); |
| 1204 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1205 | ccn_charbuf_append_string(name_lsdb_data,lsid); |
| 1206 | free(lsid); |
| 1207 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1208 | |
| 1209 | ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time); |
| 1210 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1211 | |
| 1212 | hashtb_next(e); |
| 1213 | } |
| 1214 | |
| 1215 | hashtb_end(e); |
| 1216 | |
| 1217 | } |
| 1218 | |
| 1219 | |
| 1220 | void |
| 1221 | get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data) |
| 1222 | { |
| 1223 | if ( nlsr->debugging ) |
| 1224 | printf("get_adj_lsdb_summary called \n"); |
| 1225 | if ( nlsr->detailed_logging ) |
| 1226 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsdb_summary called \n"); |
| 1227 | int i, adj_lsdb_element; |
| 1228 | struct alsa *adj_lsa; |
| 1229 | |
| 1230 | struct hashtb_enumerator ee; |
| 1231 | struct hashtb_enumerator *e = ⅇ |
| 1232 | |
| 1233 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1234 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1235 | |
| 1236 | for(i=0;i<adj_lsdb_element;i++) |
| 1237 | { |
| 1238 | adj_lsa=e->data; |
| 1239 | |
| 1240 | ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name); |
| 1241 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 1242 | |
| 1243 | char *lst=(char *)malloc(20); |
| 1244 | memset(lst,0,20); |
| 1245 | sprintf(lst,"%d",adj_lsa->header->ls_type); |
| 1246 | ccn_charbuf_append_string(adj_lsdb_data,lst); |
| 1247 | free(lst); |
| 1248 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 1249 | |
| 1250 | ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time); |
| 1251 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 1252 | |
| 1253 | hashtb_next(e); |
| 1254 | } |
| 1255 | |
| 1256 | hashtb_end(e); |
| 1257 | } |
| 1258 | |
| 1259 | |
| 1260 | void |
| 1261 | get_lsdb_summary(struct ccn_charbuf *lsdb_data) |
| 1262 | { |
| 1263 | struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create(); |
| 1264 | struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create(); |
| 1265 | |
| 1266 | get_name_lsdb_summary(name_lsdb_data); |
| 1267 | get_adj_lsdb_summary(adj_lsdb_data); |
| 1268 | |
| 1269 | long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element(); |
| 1270 | char *num_element=(char *)malloc(15); |
| 1271 | memset(num_element,0,15); |
| 1272 | sprintf(num_element,"%ld",num_lsa); |
| 1273 | |
| 1274 | if( num_lsa > 0) |
| 1275 | { |
| 1276 | ccn_charbuf_append_string(lsdb_data,num_element); |
| 1277 | ccn_charbuf_append_string(lsdb_data,"|"); |
| 1278 | } |
| 1279 | if(name_lsdb_data->length>0) |
| 1280 | { |
| 1281 | char *data1=ccn_charbuf_as_string(name_lsdb_data); |
| 1282 | ccn_charbuf_append_string(lsdb_data,(char *)data1); |
| 1283 | } |
| 1284 | if(adj_lsdb_data->length>0) |
| 1285 | { |
| 1286 | char *data2=ccn_charbuf_as_string(adj_lsdb_data); |
| 1287 | ccn_charbuf_append_string(lsdb_data,(char *)data2); |
| 1288 | } |
| 1289 | ccn_charbuf_destroy(&name_lsdb_data); |
| 1290 | ccn_charbuf_destroy(&adj_lsdb_data); |
| 1291 | free(num_element); |
| 1292 | |
| 1293 | } |
| 1294 | |
| 1295 | int |
| 1296 | check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time) |
| 1297 | { |
| 1298 | int ret=0; |
| 1299 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1300 | ccn_charbuf_append_string(key,orig_router); |
| 1301 | ccn_charbuf_append_string(key,"/"); |
| 1302 | ccn_charbuf_append_string(key,lst); |
| 1303 | ccn_charbuf_append_string(key,"/"); |
| 1304 | ccn_charbuf_append_string(key,lsid); |
| 1305 | |
| 1306 | int res; |
| 1307 | struct nlsa *name_lsa; |
| 1308 | |
| 1309 | struct hashtb_enumerator ee; |
| 1310 | struct hashtb_enumerator *e = ⅇ |
| 1311 | |
| 1312 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1313 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1314 | |
| 1315 | if( res == HT_NEW_ENTRY ) |
| 1316 | { |
| 1317 | hashtb_delete(e); |
| 1318 | ret=1; |
| 1319 | |
| 1320 | } |
| 1321 | else if(res == HT_OLD_ENTRY) |
| 1322 | { |
| 1323 | name_lsa=e->data; |
| 1324 | if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 ) |
| 1325 | { |
| 1326 | ret=1; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | hashtb_end(e); |
| 1331 | |
| 1332 | ccn_charbuf_destroy(&key); |
| 1333 | |
| 1334 | return ret; |
| 1335 | } |
| 1336 | |
| 1337 | int |
| 1338 | check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time) |
| 1339 | { |
| 1340 | int ret=0; |
| 1341 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1342 | ccn_charbuf_append_string(key,orig_router); |
| 1343 | ccn_charbuf_append_string(key,"/"); |
| 1344 | ccn_charbuf_append_string(key,lst); |
| 1345 | |
| 1346 | int res; |
| 1347 | struct alsa *adj_lsa; |
| 1348 | |
| 1349 | struct hashtb_enumerator ee; |
| 1350 | struct hashtb_enumerator *e = ⅇ |
| 1351 | |
| 1352 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1353 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1354 | |
| 1355 | if( res == HT_NEW_ENTRY ) |
| 1356 | { |
| 1357 | hashtb_delete(e); |
| 1358 | ret=1; |
| 1359 | |
| 1360 | } |
| 1361 | else if(res == HT_OLD_ENTRY) |
| 1362 | { |
| 1363 | adj_lsa=e->data; |
| 1364 | if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 ) |
| 1365 | { |
| 1366 | ret=1; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | hashtb_end(e); |
| 1371 | |
| 1372 | ccn_charbuf_destroy(&key); |
| 1373 | |
| 1374 | return ret; |
| 1375 | } |
| 1376 | |
| 1377 | void |
| 1378 | get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId) |
| 1379 | { |
| 1380 | //printf("get_name_lsa_data called \n"); |
| 1381 | if ( nlsr->debugging ) |
| 1382 | printf("get_name_lsa_data called \n"); |
| 1383 | if ( nlsr->detailed_logging ) |
| 1384 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n"); |
| 1385 | |
| 1386 | struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); |
| 1387 | |
| 1388 | struct hashtb_enumerator ee; |
| 1389 | struct hashtb_enumerator *e = ⅇ |
| 1390 | int res; |
| 1391 | |
| 1392 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1393 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1394 | |
| 1395 | if( res == HT_OLD_ENTRY ) |
| 1396 | { |
| 1397 | name_lsa=e->data; |
| 1398 | //printf("NAME LSA found\n"); |
| 1399 | |
| 1400 | if ( nlsr->debugging ) |
| 1401 | printf("NAME LSA found \n"); |
| 1402 | if ( nlsr->detailed_logging ) |
| 1403 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n"); |
| 1404 | |
| 1405 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name); |
| 1406 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1407 | |
| 1408 | char *temp_length=(char *)malloc(20); |
| 1409 | memset(temp_length,0,20); |
| 1410 | sprintf(temp_length,"%d",name_lsa->header->orig_router->length); |
| 1411 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1412 | free(temp_length); |
| 1413 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1414 | |
| 1415 | char *temp_ltype=(char *)malloc(20); |
| 1416 | memset(temp_ltype,0,20); |
| 1417 | sprintf(temp_ltype,"%d",name_lsa->header->ls_type); |
| 1418 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1419 | free(temp_ltype); |
| 1420 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1421 | |
| 1422 | char *temp_lsid=(char *)malloc(20); |
| 1423 | memset(temp_lsid,0,20); |
| 1424 | sprintf(temp_lsid,"%ld",name_lsa->header->ls_id); |
| 1425 | ccn_charbuf_append_string(lsa_data,temp_lsid); |
| 1426 | free(temp_lsid); |
| 1427 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1428 | |
| 1429 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time); |
| 1430 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1431 | |
| 1432 | char *temp_valid=(char *)malloc(20); |
| 1433 | memset(temp_valid,0,20); |
| 1434 | sprintf(temp_valid,"%d",name_lsa->header->isValid); |
| 1435 | ccn_charbuf_append_string(lsa_data,temp_valid); |
| 1436 | free(temp_valid); |
| 1437 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1438 | |
| 1439 | ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name); |
| 1440 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1441 | |
| 1442 | char *temp_npl=(char *)malloc(20); |
| 1443 | memset(temp_npl,0,20); |
| 1444 | sprintf(temp_npl,"%d",name_lsa->name_prefix->length); |
| 1445 | ccn_charbuf_append_string(lsa_data,temp_npl); |
| 1446 | free(temp_npl); |
| 1447 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1448 | |
| 1449 | } |
| 1450 | else if(res == HT_NEW_ENTRY) |
| 1451 | { |
| 1452 | hashtb_delete(e); |
| 1453 | } |
| 1454 | |
| 1455 | hashtb_end(e); |
| 1456 | } |
| 1457 | |
| 1458 | void |
| 1459 | get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 1460 | { |
| 1461 | if ( nlsr->debugging ) |
| 1462 | printf("get_adj_lsa_data called \n"); |
| 1463 | if ( nlsr->detailed_logging ) |
| 1464 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n"); |
| 1465 | |
| 1466 | struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 1467 | |
| 1468 | struct hashtb_enumerator ee; |
| 1469 | struct hashtb_enumerator *e = ⅇ |
| 1470 | int res; |
| 1471 | |
| 1472 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1473 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1474 | |
| 1475 | if( res == HT_OLD_ENTRY ) |
| 1476 | { |
| 1477 | adj_lsa=e->data; |
| 1478 | //printf("Adj LSA found\n"); |
| 1479 | |
| 1480 | if ( nlsr->debugging ) |
| 1481 | printf("Adj LSA found \n"); |
| 1482 | if ( nlsr->detailed_logging ) |
| 1483 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n"); |
| 1484 | |
| 1485 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name); |
| 1486 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1487 | |
| 1488 | char *temp_length=(char *)malloc(20); |
| 1489 | memset(temp_length,0,20); |
| 1490 | sprintf(temp_length,"%d",adj_lsa->header->orig_router->length); |
| 1491 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1492 | free(temp_length); |
| 1493 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1494 | |
| 1495 | char *temp_ltype=(char *)malloc(20); |
| 1496 | memset(temp_ltype,0,20); |
| 1497 | sprintf(temp_ltype,"%d",adj_lsa->header->ls_type); |
| 1498 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1499 | free(temp_ltype); |
| 1500 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1501 | |
| 1502 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time); |
| 1503 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1504 | |
| 1505 | char *temp_nl=(char *)malloc(20); |
| 1506 | memset(temp_nl,0,20); |
| 1507 | sprintf(temp_nl,"%d",adj_lsa->no_link); |
| 1508 | ccn_charbuf_append_string(lsa_data,temp_nl); |
| 1509 | free(temp_nl); |
| 1510 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1511 | |
| 1512 | ccn_charbuf_append_string(lsa_data,adj_lsa->body); |
| 1513 | |
| 1514 | |
| 1515 | } |
| 1516 | else if(res == HT_NEW_ENTRY) |
| 1517 | { |
| 1518 | hashtb_delete(e); |
| 1519 | } |
| 1520 | |
| 1521 | hashtb_end(e); |
| 1522 | } |
| 1523 | |
| 1524 | void |
| 1525 | make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id) |
| 1526 | { |
| 1527 | |
| 1528 | if ( nlsr->debugging ) |
| 1529 | printf("make_name_lsa_invalid called \n"); |
| 1530 | if ( nlsr->detailed_logging ) |
| 1531 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n"); |
| 1532 | |
| 1533 | |
| 1534 | char lst[2]; |
| 1535 | memset(lst,0,2); |
| 1536 | sprintf(lst,"%d",ls_type); |
| 1537 | |
| 1538 | char lsid[10]; |
| 1539 | memset(lsid,0,10); |
| 1540 | sprintf(lsid,"%ld",ls_id); |
| 1541 | |
| 1542 | |
| 1543 | char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1544 | memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1545 | |
| 1546 | |
| 1547 | make_name_lsa_key(key, np->name,ls_type,ls_id); |
| 1548 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 1549 | |
| 1550 | struct nlsa *nlsa; |
| 1551 | |
| 1552 | struct hashtb_enumerator ee; |
| 1553 | struct hashtb_enumerator *e = ⅇ |
| 1554 | |
| 1555 | int res; |
| 1556 | |
| 1557 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1558 | res = hashtb_seek(e, key,strlen(key) , 0); |
| 1559 | |
| 1560 | if( res == HT_OLD_ENTRY ) |
| 1561 | { |
| 1562 | nlsa=e->data; |
| 1563 | |
| 1564 | nlsa->header->isValid=0; |
| 1565 | |
| 1566 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1567 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1568 | write_log_for_name_lsa(nlsa); |
| 1569 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1570 | |
| 1571 | hashtb_delete(e); |
| 1572 | } |
| 1573 | else if( res == HT_NEW_ENTRY ) |
| 1574 | { |
| 1575 | hashtb_delete(e); |
| 1576 | } |
| 1577 | hashtb_end(e); |
| 1578 | |
| 1579 | if ( nlsr->debugging ) |
| 1580 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1581 | if ( nlsr->detailed_logging ) |
| 1582 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1583 | |
| 1584 | set_new_lsdb_version(); |
| 1585 | |
| 1586 | if ( nlsr->debugging ) |
| 1587 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1588 | if ( nlsr->detailed_logging ) |
| 1589 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1590 | |
| 1591 | } |
| 1592 | |
| 1593 | int |
| 1594 | delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1595 | { |
| 1596 | //printf("delete_name_lsa called \n"); |
| 1597 | |
| 1598 | if ( nlsr->debugging ) |
| 1599 | printf("delete_name_lsa called \n"); |
| 1600 | if ( nlsr->detailed_logging ) |
| 1601 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n"); |
| 1602 | |
| 1603 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1604 | { |
| 1605 | return -1; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | nlsr_lock(); |
| 1611 | |
| 1612 | if ( nlsr->debugging ) |
| 1613 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1614 | if ( nlsr->detailed_logging ) |
| 1615 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata); |
| 1616 | |
| 1617 | struct nlsa *nlsa; |
| 1618 | |
| 1619 | struct hashtb_enumerator ee; |
| 1620 | struct hashtb_enumerator *e = ⅇ |
| 1621 | |
| 1622 | int res; |
| 1623 | |
| 1624 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1625 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1626 | |
| 1627 | if( res == HT_OLD_ENTRY ) |
| 1628 | { |
| 1629 | nlsa=e->data; |
| 1630 | delete_npt_entry_by_router_and_name_prefix(nlsa->header->orig_router->name, nlsa->name_prefix->name); |
| 1631 | |
| 1632 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1633 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1634 | write_log_for_name_lsa(nlsa); |
| 1635 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1636 | |
| 1637 | hashtb_delete(e); |
| 1638 | } |
| 1639 | else if( res == HT_NEW_ENTRY ) |
| 1640 | { |
| 1641 | hashtb_delete(e); |
| 1642 | } |
| 1643 | hashtb_end(e); |
| 1644 | |
| 1645 | if ( nlsr->debugging ) |
| 1646 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1647 | if ( nlsr->detailed_logging ) |
| 1648 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1649 | |
| 1650 | set_new_lsdb_version(); |
| 1651 | |
| 1652 | if ( nlsr->debugging ) |
| 1653 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1654 | if ( nlsr->detailed_logging ) |
| 1655 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1656 | |
| 1657 | //print_name_lsdb(); |
| 1658 | |
| 1659 | nlsr_unlock(); |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | int |
| 1665 | delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1666 | { |
| 1667 | //printf("delete_adj_lsa called \n"); |
| 1668 | |
| 1669 | if ( nlsr->debugging ) |
| 1670 | printf("delete_adj_lsa called \n"); |
| 1671 | if ( nlsr->detailed_logging ) |
| 1672 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n"); |
| 1673 | |
| 1674 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1675 | { |
| 1676 | return -1; |
| 1677 | } |
| 1678 | nlsr_lock(); |
| 1679 | |
| 1680 | //printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1681 | |
| 1682 | if ( nlsr->debugging ) |
| 1683 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1684 | if ( nlsr->detailed_logging ) |
| 1685 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata); |
| 1686 | |
| 1687 | struct alsa *alsa; |
| 1688 | struct hashtb_enumerator ee; |
| 1689 | struct hashtb_enumerator *e = ⅇ |
| 1690 | int res; |
| 1691 | |
| 1692 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1693 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1694 | |
| 1695 | if( res == HT_OLD_ENTRY ) |
| 1696 | { |
| 1697 | alsa=e->data; |
| 1698 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1699 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1700 | write_log_for_adj_lsa(alsa); |
| 1701 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1702 | |
| 1703 | hashtb_delete(e); |
| 1704 | } |
| 1705 | else if( res == HT_OLD_ENTRY ) |
| 1706 | { |
| 1707 | hashtb_delete(e); |
| 1708 | } |
| 1709 | hashtb_end(e); |
| 1710 | |
| 1711 | if ( nlsr->debugging ) |
| 1712 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1713 | if ( nlsr->detailed_logging ) |
| 1714 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1715 | |
| 1716 | set_new_lsdb_version(); |
| 1717 | |
| 1718 | if ( nlsr->debugging ) |
| 1719 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1720 | if ( nlsr->detailed_logging ) |
| 1721 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1722 | |
| 1723 | |
| 1724 | if ( !nlsr->is_route_calculation_scheduled) |
| 1725 | { |
| 1726 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 1727 | nlsr->is_route_calculation_scheduled=1; |
| 1728 | } |
| 1729 | |
| 1730 | //print_adj_lsdb(); |
| 1731 | |
| 1732 | nlsr_unlock(); |
| 1733 | |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | void |
| 1738 | refresh_name_lsdb(void) |
| 1739 | { |
| 1740 | //printf("refresh_name_lsdb called \n"); |
| 1741 | |
| 1742 | if ( nlsr->debugging ) |
| 1743 | printf("refresh_name_lsdb called \n"); |
| 1744 | if ( nlsr->detailed_logging ) |
| 1745 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n"); |
| 1746 | |
| 1747 | //int lsa_change_count=0; |
| 1748 | |
| 1749 | char *time_stamp=(char *)malloc(20); |
| 1750 | memset(time_stamp,0,20); |
| 1751 | get_current_timestamp_micro(time_stamp); |
| 1752 | |
| 1753 | long int lsa_life_time; |
| 1754 | |
| 1755 | int i, name_lsdb_element; |
| 1756 | struct nlsa *name_lsa; |
| 1757 | |
| 1758 | struct hashtb_enumerator ee; |
| 1759 | struct hashtb_enumerator *e = ⅇ |
| 1760 | |
| 1761 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1762 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1763 | |
| 1764 | for(i=0;i<name_lsdb_element;i++) |
| 1765 | { |
| 1766 | name_lsa=e->data; |
| 1767 | |
| 1768 | lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
| 1769 | if ( nlsr->debugging ) |
| 1770 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1771 | if ( nlsr->detailed_logging ) |
| 1772 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
| 1773 | |
| 1774 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1775 | { |
| 1776 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1777 | { |
| 1778 | if ( name_lsa->header->isValid == NAME_LSA_VALID ) |
| 1779 | { |
| 1780 | if ( nlsr->debugging ) |
| 1781 | printf("Own Name LSA need to be refrshed\n"); |
| 1782 | if ( nlsr->detailed_logging ) |
| 1783 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n"); |
| 1784 | |
| 1785 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1786 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1787 | write_log_for_name_lsa(name_lsa); |
| 1788 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1789 | |
| 1790 | |
| 1791 | char *current_time_stamp=(char *)malloc(20); |
| 1792 | memset(current_time_stamp,0,20); |
| 1793 | get_current_timestamp_micro(current_time_stamp); |
| 1794 | |
| 1795 | free(name_lsa->header->orig_time); |
| 1796 | name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1797 | memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1798 | memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1799 | |
| 1800 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1801 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 1802 | write_log_for_name_lsa(name_lsa); |
| 1803 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1804 | |
| 1805 | free(current_time_stamp); |
| 1806 | } |
| 1807 | else |
| 1808 | { |
| 1809 | char lst[2]; |
| 1810 | memset(lst,0,2); |
| 1811 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1812 | |
| 1813 | char lsid[10]; |
| 1814 | memset(lsid,0,10); |
| 1815 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1816 | |
| 1817 | |
| 1818 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1819 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1820 | |
| 1821 | |
| 1822 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 1823 | //printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 1824 | |
| 1825 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
| 1826 | } |
| 1827 | |
| 1828 | if ( nlsr->debugging ) |
| 1829 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1830 | if ( nlsr->detailed_logging ) |
| 1831 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1832 | |
| 1833 | set_new_lsdb_version(); |
| 1834 | |
| 1835 | if ( nlsr->debugging ) |
| 1836 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1837 | if ( nlsr->detailed_logging ) |
| 1838 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | print_name_lsdb(); |
| 1843 | //lsa_change_count++; |
| 1844 | } |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1849 | { |
| 1850 | if ( nlsr->debugging ) |
| 1851 | printf("Others Name LSA need to be deleted\n"); |
| 1852 | if ( nlsr->detailed_logging ) |
| 1853 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n"); |
| 1854 | |
| 1855 | char lst[2]; |
| 1856 | memset(lst,0,2); |
| 1857 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1858 | |
| 1859 | char lsid[10]; |
| 1860 | memset(lsid,0,10); |
| 1861 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1862 | |
| 1863 | |
| 1864 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1865 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1866 | |
| 1867 | |
| 1868 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 1869 | //printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 1870 | |
| 1871 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
| 1872 | //lsa_change_count++; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | hashtb_next(e); |
| 1877 | } |
| 1878 | |
| 1879 | hashtb_end(e); |
| 1880 | |
| 1881 | free(time_stamp); |
| 1882 | |
| 1883 | |
| 1884 | } |
| 1885 | |
| 1886 | void |
| 1887 | refresh_adj_lsdb(void) |
| 1888 | { |
| 1889 | //printf("refresh_adj_lsdb called \n"); |
| 1890 | |
| 1891 | if ( nlsr->debugging ) |
| 1892 | printf("refresh_adj_lsdb called \n"); |
| 1893 | if ( nlsr->detailed_logging ) |
| 1894 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n"); |
| 1895 | |
| 1896 | char *time_stamp=(char *)malloc(20); |
| 1897 | memset(time_stamp,0,20); |
| 1898 | get_current_timestamp_micro(time_stamp); |
| 1899 | |
| 1900 | long int lsa_life_time; |
| 1901 | |
| 1902 | int i, adj_lsdb_element; |
| 1903 | struct alsa *adj_lsa; |
| 1904 | |
| 1905 | struct hashtb_enumerator ee; |
| 1906 | struct hashtb_enumerator *e = ⅇ |
| 1907 | |
| 1908 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1909 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1910 | |
| 1911 | for(i=0;i<adj_lsdb_element;i++) |
| 1912 | { |
| 1913 | adj_lsa=e->data; |
| 1914 | |
| 1915 | lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
| 1916 | //printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1917 | |
| 1918 | if ( nlsr->debugging ) |
| 1919 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1920 | if ( nlsr->detailed_logging ) |
| 1921 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
| 1922 | |
| 1923 | if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1924 | { |
| 1925 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1926 | { |
| 1927 | //printf("Own Adj LSA need to be refrshed\n"); |
| 1928 | if ( nlsr->debugging ) |
| 1929 | printf("Own Adj LSA need to be refrshed\n"); |
| 1930 | if ( nlsr->detailed_logging ) |
| 1931 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n"); |
| 1932 | |
| 1933 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1934 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1935 | write_log_for_adj_lsa(adj_lsa); |
| 1936 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1937 | |
| 1938 | char *current_time_stamp=(char *)malloc(20); |
| 1939 | memset(current_time_stamp,0,20); |
| 1940 | get_current_timestamp_micro(current_time_stamp); |
| 1941 | |
| 1942 | free(adj_lsa->header->orig_time); |
| 1943 | adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1944 | memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1945 | memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1946 | |
| 1947 | free(current_time_stamp); |
| 1948 | |
| 1949 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1950 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 1951 | write_log_for_adj_lsa(adj_lsa); |
| 1952 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1953 | |
| 1954 | if ( nlsr->debugging ) |
| 1955 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1956 | if ( nlsr->detailed_logging ) |
| 1957 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1958 | |
| 1959 | set_new_lsdb_version(); |
| 1960 | |
| 1961 | if ( nlsr->debugging ) |
| 1962 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1963 | if ( nlsr->detailed_logging ) |
| 1964 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1965 | |
| 1966 | print_adj_lsdb(); |
| 1967 | } |
| 1968 | } |
| 1969 | else |
| 1970 | { |
| 1971 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1972 | { |
| 1973 | //printf("Others Adj LSA need to be deleted\n"); |
| 1974 | |
| 1975 | if ( nlsr->debugging ) |
| 1976 | printf("Others Adj LSA need to be deleted\n"); |
| 1977 | if ( nlsr->detailed_logging ) |
| 1978 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n"); |
| 1979 | |
| 1980 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 1981 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 1982 | make_adj_lsa_key(key,adj_lsa); |
| 1983 | //printf("Adjacent LSA key: %s \n",key); |
| 1984 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0); |
| 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | hashtb_next(e); |
| 1991 | } |
| 1992 | |
| 1993 | hashtb_end(e); |
| 1994 | |
| 1995 | free(time_stamp); |
| 1996 | } |
| 1997 | |
| 1998 | int |
| 1999 | refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 2000 | { |
| 2001 | if(flags == CCN_SCHEDULE_CANCEL) |
| 2002 | { |
| 2003 | return -1; |
| 2004 | } |
| 2005 | |
| 2006 | nlsr_lock(); |
| 2007 | |
| 2008 | //printf("refresh_lsdb called \n"); |
| 2009 | |
| 2010 | if ( nlsr->debugging ) |
| 2011 | printf("refresh_lsdb called\n"); |
| 2012 | if ( nlsr->detailed_logging ) |
| 2013 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n"); |
| 2014 | |
| 2015 | refresh_name_lsdb(); |
| 2016 | refresh_adj_lsdb(); |
| 2017 | |
| 2018 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
| 2019 | |
| 2020 | nlsr_unlock(); |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | void |
| 2025 | write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id) |
| 2026 | { |
| 2027 | printf("Content Preifx: %s\n",repo_content_prefix); |
| 2028 | |
| 2029 | |
| 2030 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2031 | get_name_lsa_data(lsa_data,lsa_id); |
| 2032 | printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
| 2033 | |
| 2034 | write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix); |
| 2035 | |
| 2036 | ccn_charbuf_destroy(&lsa_data); |
| 2037 | } |
| 2038 | |
| 2039 | |
| 2040 | void |
| 2041 | write_name_lsdb_to_repo(char *slice_prefix) |
| 2042 | { |
| 2043 | int i, name_lsdb_element; |
| 2044 | |
| 2045 | struct nlsa *name_lsa; |
| 2046 | struct hashtb_enumerator ee; |
| 2047 | struct hashtb_enumerator *e = ⅇ |
| 2048 | |
| 2049 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 2050 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 2051 | |
| 2052 | for(i=0;i<name_lsdb_element;i++) |
| 2053 | { |
| 2054 | name_lsa=e->data; |
| 2055 | |
| 2056 | char lst[2]; |
| 2057 | memset(lst,0,2); |
| 2058 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 2059 | |
| 2060 | char lsid[10]; |
| 2061 | memset(lsid,0,10); |
| 2062 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 2063 | |
| 2064 | |
| 2065 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 2066 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 2067 | |
| 2068 | |
| 2069 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 2070 | printf("Name LSA Key: %s \n",key); |
| 2071 | |
| 2072 | |
| 2073 | char *repo_key=(char *)malloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1); |
| 2074 | memset(repo_key,0,strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1); |
| 2075 | make_name_lsa_prefix_for_repo(repo_key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id,name_lsa->header->orig_time,slice_prefix); |
| 2076 | |
| 2077 | printf("Name LSA Repo Key: %s \n",repo_key); |
| 2078 | |
| 2079 | struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix)); |
| 2080 | lsaid->name=(char *)malloc(strlen(key)+1); |
| 2081 | memset(lsaid->name,strlen(key)+1,0); |
| 2082 | memcpy(lsaid->name,key,strlen(key)); |
| 2083 | lsaid->length=strlen(key)+1; |
| 2084 | |
| 2085 | |
| 2086 | write_name_lsa_to_repo(repo_key, lsaid); |
| 2087 | |
| 2088 | free(key); |
| 2089 | free(repo_key); |
| 2090 | free(lsaid->name); |
| 2091 | free(lsaid); |
| 2092 | |
| 2093 | hashtb_next(e); |
| 2094 | } |
| 2095 | |
| 2096 | hashtb_end(e); |
| 2097 | |
| 2098 | |
| 2099 | } |