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