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