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