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