akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [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 "utility.h" |
| 23 | #include "nlsr_adl.h" |
| 24 | |
| 25 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 26 | add_adjacent_to_adl(struct name_prefix *np, int face) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 27 | { |
| 28 | printf("\nadd_adjacent_to_adl called\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 29 | printf("Neighbor: %s Length: %d Face:%d\n",np->name,np->length,face); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 30 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 31 | struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor)); |
| 32 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 33 | struct hashtb_enumerator ee; |
| 34 | struct hashtb_enumerator *e = ⅇ |
| 35 | int res; |
| 36 | |
| 37 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 38 | res = hashtb_seek(e, np->name, np->length, 0); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 39 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 40 | if(res == HT_NEW_ENTRY ) |
| 41 | { |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 42 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 43 | nbr = e->data; |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 44 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 45 | nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); |
| 46 | nbr->neighbor->name=(char *)malloc(np->length); |
| 47 | memcpy(nbr->neighbor->name,np->name,np->length); |
| 48 | nbr->neighbor->length=np->length; |
| 49 | nbr->face=face; |
| 50 | nbr->status=NBR_DOWN; |
| 51 | nbr->info_interest_timed_out=0; |
| 52 | nbr->lsdb_synch_interval=300; |
| 53 | nbr->metric=10; |
| 54 | nbr->is_lsdb_send_interest_scheduled=0; |
| 55 | |
| 56 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 57 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 58 | char *time_stamp=get_current_timestamp_micro(); |
| 59 | nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); |
| 60 | memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1); |
| 61 | memset(nbr->last_lsdb_version,'0',strlen(time_stamp)); |
| 62 | |
| 63 | nbr->last_lsdb_requested=0; |
| 64 | |
| 65 | //nbr->last_lsdb_requested=(char *)malloc(strlen(time_stamp)+1); |
| 66 | //memcpy(nbr->last_lsdb_requested,time_stamp,strlen(time_stamp)+1); |
| 67 | //memset(nbr->last_lsdb_requested,'0',strlen(time_stamp)); |
| 68 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 69 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 70 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 71 | hashtb_end(e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 72 | } |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 73 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 74 | void |
| 75 | print_adjacent(struct ndn_neighbor *nbr) |
| 76 | { |
| 77 | printf("\nprint_adjacent called\n"); |
| 78 | printf("--------Neighbor---------------------------\n"); |
| 79 | printf(" Neighbor: %s \n",nbr->neighbor->name); |
| 80 | printf(" Length : %d \n",nbr->neighbor->length); |
| 81 | printf(" Face : %d \n",nbr->face); |
| 82 | printf(" Metric : %d \n",nbr->metric); |
| 83 | printf(" Status : %d \n",nbr->status); |
| 84 | printf(" LSDB Version: %s \n",nbr->last_lsdb_version); |
| 85 | printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out); |
| 86 | printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval); |
| 87 | printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 88 | |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | print_adjacent_from_adl(void) |
| 93 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 94 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 95 | printf("print_adjacent_from_adl called \n"); |
| 96 | int i, adl_element; |
| 97 | struct ndn_neighbor *nbr; |
| 98 | |
| 99 | struct hashtb_enumerator ee; |
| 100 | struct hashtb_enumerator *e = ⅇ |
| 101 | |
| 102 | hashtb_start(nlsr->adl, e); |
| 103 | adl_element=hashtb_n(nlsr->adl); |
| 104 | |
| 105 | for(i=0;i<adl_element;i++) |
| 106 | { |
| 107 | nbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 108 | print_adjacent(nbr); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 109 | hashtb_next(e); |
| 110 | } |
| 111 | |
| 112 | hashtb_end(e); |
| 113 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 117 | update_adjacent_status_to_adl(struct name_prefix *nbr, int status) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 118 | { |
| 119 | printf("update_adjacent_status_to_adl called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 120 | //int ret; |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 121 | int res; |
| 122 | struct ndn_neighbor *nnbr; |
| 123 | |
| 124 | struct hashtb_enumerator ee; |
| 125 | struct hashtb_enumerator *e = ⅇ |
| 126 | |
| 127 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 128 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 129 | |
akmhoque | 918ff9a | 2012-08-21 11:34:49 -0400 | [diff] [blame] | 130 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 131 | if (res == HT_OLD_ENTRY) |
| 132 | { |
| 133 | nnbr=e->data; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 134 | if ( nnbr->status!=status ) |
| 135 | { |
| 136 | nnbr->status=status; |
| 137 | nlsr->adj_build_flag++; |
| 138 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 139 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 140 | else if(res == HT_NEW_ENTRY) |
| 141 | { |
| 142 | hashtb_delete(e); |
| 143 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 144 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 145 | hashtb_end(e); |
| 146 | } |
| 147 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 148 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 149 | update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 150 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 151 | printf("uupdate_lsdb_synch_interval_to_adl called \n"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 152 | |
| 153 | int res; |
| 154 | struct ndn_neighbor *nnbr; |
| 155 | |
| 156 | struct hashtb_enumerator ee; |
| 157 | struct hashtb_enumerator *e = ⅇ |
| 158 | |
| 159 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 160 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 161 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 162 | |
| 163 | if (res == HT_OLD_ENTRY) |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 164 | { |
| 165 | nnbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 166 | if ( nnbr->lsdb_synch_interval!= interval ) |
| 167 | { |
| 168 | nnbr->lsdb_synch_interval=interval; |
| 169 | |
| 170 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 171 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 172 | else if(res == HT_NEW_ENTRY) |
| 173 | { |
| 174 | hashtb_delete(e); |
| 175 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 176 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 177 | hashtb_end(e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 178 | |
| 179 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 180 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 181 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 182 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 183 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 184 | update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 185 | { |
| 186 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 187 | |
| 188 | int res; |
| 189 | struct ndn_neighbor *nnbr; |
| 190 | |
| 191 | struct hashtb_enumerator ee; |
| 192 | struct hashtb_enumerator *e = ⅇ |
| 193 | |
| 194 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 195 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 196 | |
| 197 | if( res == HT_OLD_ENTRY ) |
| 198 | { |
| 199 | nnbr=e->data; |
| 200 | nnbr->info_interest_timed_out += increment; |
| 201 | } |
| 202 | else if(res == HT_NEW_ENTRY) |
| 203 | { |
| 204 | hashtb_delete(e); |
| 205 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 206 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 207 | hashtb_end(e); |
| 208 | } |
| 209 | |
| 210 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 211 | update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 212 | { |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 213 | printf("update_adjacent_timed_out_zero_to_adl called \n"); |
| 214 | int time_out_number=get_timed_out_number(nbr); |
| 215 | update_adjacent_timed_out_to_adl(nbr,-time_out_number); |
| 216 | |
| 217 | } |
| 218 | |
| 219 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 220 | void |
| 221 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 222 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 223 | printf("update_adjacent_timed_out_to_adl called \n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 224 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 225 | int res; |
| 226 | struct ndn_neighbor *nnbr; |
| 227 | |
| 228 | struct hashtb_enumerator ee; |
| 229 | struct hashtb_enumerator *e = ⅇ |
| 230 | |
| 231 | hashtb_start(nlsr->adl, e); |
| 232 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 233 | |
| 234 | if( res == HT_OLD_ENTRY ) |
| 235 | { |
| 236 | nnbr=e->data; |
| 237 | free(nnbr->last_lsdb_version); |
| 238 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 239 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 240 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
| 241 | } |
| 242 | else if(res == HT_NEW_ENTRY) |
| 243 | { |
| 244 | hashtb_delete(e); |
| 245 | } |
| 246 | |
| 247 | hashtb_end(e); |
| 248 | |
| 249 | } |
| 250 | |
| 251 | int |
| 252 | get_timed_out_number(struct name_prefix *nbr) |
| 253 | { |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 254 | printf("get_timed_out_number called \n"); |
| 255 | |
| 256 | int res,ret=-1; |
| 257 | struct ndn_neighbor *nnbr; |
| 258 | |
| 259 | struct hashtb_enumerator ee; |
| 260 | struct hashtb_enumerator *e = ⅇ |
| 261 | |
| 262 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 263 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 264 | |
| 265 | if( res == HT_OLD_ENTRY ) |
| 266 | { |
| 267 | nnbr=e->data; |
| 268 | ret=nnbr->info_interest_timed_out; |
| 269 | } |
| 270 | else if(res == HT_NEW_ENTRY) |
| 271 | { |
| 272 | hashtb_delete(e); |
| 273 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 274 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 275 | hashtb_end(e); |
| 276 | |
| 277 | return ret; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 278 | |
| 279 | return 0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 280 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame^] | 281 | |
| 282 | int |
| 283 | is_adj_lsa_build(void) |
| 284 | { |
| 285 | int ret=0; |
| 286 | |
| 287 | int nbr_count=0; |
| 288 | |
| 289 | int i, adl_element; |
| 290 | struct ndn_neighbor *nbr; |
| 291 | |
| 292 | struct hashtb_enumerator ee; |
| 293 | struct hashtb_enumerator *e = ⅇ |
| 294 | |
| 295 | hashtb_start(nlsr->adl, e); |
| 296 | adl_element=hashtb_n(nlsr->adl); |
| 297 | |
| 298 | for(i=0;i<adl_element;i++) |
| 299 | { |
| 300 | nbr=e->data; |
| 301 | if(nbr->status == 1 ) |
| 302 | { |
| 303 | nbr_count++; |
| 304 | } |
| 305 | else if (nbr->info_interest_timed_out >= nlsr->interest_retry) |
| 306 | { |
| 307 | nbr_count++; |
| 308 | } |
| 309 | hashtb_next(e); |
| 310 | } |
| 311 | |
| 312 | hashtb_end(e); |
| 313 | if(nbr_count == adl_element) |
| 314 | ret=1; |
| 315 | |
| 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | int |
| 320 | no_active_nbr(void) |
| 321 | { |
| 322 | int i, adl_element; |
| 323 | int no_link=0; |
| 324 | struct ndn_neighbor *nbr; |
| 325 | struct hashtb_enumerator ee; |
| 326 | struct hashtb_enumerator *e = ⅇ |
| 327 | hashtb_start(nlsr->adl, e); |
| 328 | adl_element=hashtb_n(nlsr->adl); |
| 329 | |
| 330 | for(i=0;i<adl_element;i++) |
| 331 | { |
| 332 | nbr=e->data; |
| 333 | if( nbr->status == 1 ) |
| 334 | no_link++; |
| 335 | hashtb_next(e); |
| 336 | } |
| 337 | |
| 338 | hashtb_end(e); |
| 339 | |
| 340 | return no_link; |
| 341 | |
| 342 | } |
| 343 | |
| 344 | long int |
| 345 | len_active_nbr_data(void) |
| 346 | { |
| 347 | int i, adl_element; |
| 348 | int no_link=0; |
| 349 | long int len=0; |
| 350 | struct ndn_neighbor *nbr; |
| 351 | struct hashtb_enumerator ee; |
| 352 | struct hashtb_enumerator *e = ⅇ |
| 353 | hashtb_start(nlsr->adl, e); |
| 354 | adl_element=hashtb_n(nlsr->adl); |
| 355 | |
| 356 | for(i=0;i<adl_element;i++) |
| 357 | { |
| 358 | nbr=e->data; |
| 359 | if( nbr->status == 1 ) |
| 360 | { |
| 361 | char *temp_face=(char *)malloc(20); |
| 362 | char *temp_metric=(char *)malloc(20); |
| 363 | char *temp_length=(char *)malloc(20); |
| 364 | |
| 365 | len+=strlen(nbr->neighbor->name); |
| 366 | |
| 367 | memset( temp_face,0,20); |
| 368 | sprintf(temp_face,"%d",nbr->face); |
| 369 | len+=strlen(temp_face); |
| 370 | |
| 371 | memset( temp_metric,0,20); |
| 372 | sprintf(temp_face,"%d",nbr->metric); |
| 373 | len+=strlen(temp_metric); |
| 374 | |
| 375 | memset( temp_length,0,20); |
| 376 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 377 | len+=strlen(temp_length); |
| 378 | |
| 379 | no_link++; |
| 380 | |
| 381 | free(temp_face); |
| 382 | free(temp_metric); |
| 383 | free(temp_length); |
| 384 | |
| 385 | } |
| 386 | hashtb_next(e); |
| 387 | } |
| 388 | |
| 389 | hashtb_end(e); |
| 390 | |
| 391 | len=len+ no_link*4+1; |
| 392 | |
| 393 | return len; |
| 394 | |
| 395 | } |
| 396 | |
| 397 | void |
| 398 | get_active_nbr_adj_data(struct ccn_charbuf *c) |
| 399 | { |
| 400 | |
| 401 | int i, adl_element; |
| 402 | struct ndn_neighbor *nbr; |
| 403 | struct hashtb_enumerator ee; |
| 404 | struct hashtb_enumerator *e = ⅇ |
| 405 | hashtb_start(nlsr->adl, e); |
| 406 | adl_element=hashtb_n(nlsr->adl); |
| 407 | |
| 408 | for(i=0;i<adl_element;i++) |
| 409 | { |
| 410 | nbr=e->data; |
| 411 | if( nbr->status == 1 ) |
| 412 | { |
| 413 | ccn_charbuf_append_string(c,nbr->neighbor->name); |
| 414 | ccn_charbuf_append_string(c,"|"); |
| 415 | |
| 416 | char *temp_length=(char *)malloc(20); |
| 417 | memset(temp_length,0,20); |
| 418 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 419 | ccn_charbuf_append_string(c,temp_length); |
| 420 | free(temp_length); |
| 421 | ccn_charbuf_append_string(c,"|"); |
| 422 | |
| 423 | char *temp_face=(char *)malloc(20); |
| 424 | memset(temp_face,0,20); |
| 425 | sprintf(temp_face,"%d",nbr->face); |
| 426 | ccn_charbuf_append_string(c,temp_face); |
| 427 | free(temp_face); |
| 428 | ccn_charbuf_append_string(c,"|"); |
| 429 | |
| 430 | char *temp_metric=(char *)malloc(20); |
| 431 | memset(temp_metric,0,20); |
| 432 | sprintf(temp_metric,"%d",nbr->metric); |
| 433 | ccn_charbuf_append_string(c,temp_metric); |
| 434 | free(temp_metric); |
| 435 | ccn_charbuf_append_string(c,"|"); |
| 436 | |
| 437 | } |
| 438 | hashtb_next(e); |
| 439 | } |
| 440 | |
| 441 | hashtb_end(e); |
| 442 | } |
| 443 | |
| 444 | char * |
| 445 | get_nbr_lsdb_version(char *nbr) |
| 446 | { |
| 447 | printf("get_timed_out_number called \n"); |
| 448 | |
| 449 | char *version=NULL; |
| 450 | |
| 451 | int res; |
| 452 | struct ndn_neighbor *nnbr; |
| 453 | |
| 454 | struct hashtb_enumerator ee; |
| 455 | struct hashtb_enumerator *e = ⅇ |
| 456 | |
| 457 | hashtb_start(nlsr->adl, e); |
| 458 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 459 | |
| 460 | if (res == HT_OLD_ENTRY) |
| 461 | { |
| 462 | nnbr=e->data; |
| 463 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 464 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 465 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 466 | } |
| 467 | else if(res == HT_NEW_ENTRY) |
| 468 | { |
| 469 | hashtb_delete(e); |
| 470 | } |
| 471 | |
| 472 | hashtb_end(e); |
| 473 | |
| 474 | return version; |
| 475 | } |
| 476 | |
| 477 | void |
| 478 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 479 | { |
| 480 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 481 | |
| 482 | int res; |
| 483 | struct ndn_neighbor *nnbr; |
| 484 | |
| 485 | struct hashtb_enumerator ee; |
| 486 | struct hashtb_enumerator *e = ⅇ |
| 487 | |
| 488 | hashtb_start(nlsr->adl, e); |
| 489 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 490 | |
| 491 | if( res == HT_OLD_ENTRY ) |
| 492 | { |
| 493 | nnbr=e->data; |
| 494 | nnbr->last_lsdb_requested=timestamp; |
| 495 | |
| 496 | } |
| 497 | else if(res == HT_NEW_ENTRY) |
| 498 | { |
| 499 | hashtb_delete(e); |
| 500 | } |
| 501 | |
| 502 | hashtb_end(e); |
| 503 | |
| 504 | } |
| 505 | |
| 506 | void |
| 507 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 508 | { |
| 509 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 510 | |
| 511 | int res; |
| 512 | struct ndn_neighbor *nnbr; |
| 513 | |
| 514 | struct hashtb_enumerator ee; |
| 515 | struct hashtb_enumerator *e = ⅇ |
| 516 | |
| 517 | hashtb_start(nlsr->adl, e); |
| 518 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 519 | |
| 520 | if( res == HT_OLD_ENTRY ) |
| 521 | { |
| 522 | nnbr=e->data; |
| 523 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
| 524 | |
| 525 | } |
| 526 | else if(res == HT_NEW_ENTRY) |
| 527 | { |
| 528 | hashtb_delete(e); |
| 529 | } |
| 530 | |
| 531 | hashtb_end(e); |
| 532 | |
| 533 | } |
| 534 | |
| 535 | |
| 536 | long int |
| 537 | get_nbr_last_lsdb_requested(char *nbr) |
| 538 | { |
| 539 | printf("get_timed_out_number called \n"); |
| 540 | |
| 541 | long int last_lsdb_requested=0; |
| 542 | |
| 543 | int res; |
| 544 | struct ndn_neighbor *nnbr; |
| 545 | |
| 546 | struct hashtb_enumerator ee; |
| 547 | struct hashtb_enumerator *e = ⅇ |
| 548 | |
| 549 | hashtb_start(nlsr->adl, e); |
| 550 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 551 | |
| 552 | if (res == HT_OLD_ENTRY) |
| 553 | { |
| 554 | nnbr=e->data; |
| 555 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 556 | } |
| 557 | else if(res == HT_NEW_ENTRY) |
| 558 | { |
| 559 | hashtb_delete(e); |
| 560 | } |
| 561 | |
| 562 | hashtb_end(e); |
| 563 | |
| 564 | return last_lsdb_requested; |
| 565 | } |
| 566 | |
| 567 | long int |
| 568 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 569 | { |
| 570 | printf("get_nbr_time_diff_lsdb_req called \n"); |
| 571 | |
| 572 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 573 | int res; |
| 574 | struct ndn_neighbor *nnbr; |
| 575 | |
| 576 | struct hashtb_enumerator ee; |
| 577 | struct hashtb_enumerator *e = ⅇ |
| 578 | |
| 579 | hashtb_start(nlsr->adl, e); |
| 580 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 581 | |
| 582 | if (res == HT_OLD_ENTRY) |
| 583 | { |
| 584 | nnbr=e->data; |
| 585 | |
| 586 | if (nnbr->last_lsdb_requested == 0) |
| 587 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 588 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 589 | |
| 590 | } |
| 591 | else if(res == HT_NEW_ENTRY) |
| 592 | { |
| 593 | hashtb_delete(e); |
| 594 | } |
| 595 | |
| 596 | hashtb_end(e); |
| 597 | |
| 598 | return time_diff; |
| 599 | } |
| 600 | |
| 601 | long int |
| 602 | get_lsdb_synch_interval(char *nbr) |
| 603 | { |
| 604 | printf("get_lsdb_synch_interval called \n"); |
| 605 | |
| 606 | long int lsdb_synch_interval=300; |
| 607 | |
| 608 | |
| 609 | int res; |
| 610 | struct ndn_neighbor *nnbr; |
| 611 | |
| 612 | struct hashtb_enumerator ee; |
| 613 | struct hashtb_enumerator *e = ⅇ |
| 614 | |
| 615 | hashtb_start(nlsr->adl, e); |
| 616 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 617 | |
| 618 | if (res == HT_OLD_ENTRY) |
| 619 | { |
| 620 | nnbr=e->data; |
| 621 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 622 | } |
| 623 | else if(res == HT_NEW_ENTRY) |
| 624 | { |
| 625 | hashtb_delete(e); |
| 626 | } |
| 627 | |
| 628 | hashtb_end(e); |
| 629 | |
| 630 | return lsdb_synch_interval; |
| 631 | |
| 632 | } |
| 633 | |
| 634 | void |
| 635 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 636 | { |
| 637 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 638 | |
| 639 | int res; |
| 640 | struct ndn_neighbor *nnbr; |
| 641 | |
| 642 | struct hashtb_enumerator ee; |
| 643 | struct hashtb_enumerator *e = ⅇ |
| 644 | |
| 645 | hashtb_start(nlsr->adl, e); |
| 646 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 647 | |
| 648 | if (res == HT_OLD_ENTRY) |
| 649 | { |
| 650 | nnbr=e->data; |
| 651 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 652 | } |
| 653 | else if(res == HT_NEW_ENTRY) |
| 654 | { |
| 655 | hashtb_delete(e); |
| 656 | } |
| 657 | |
| 658 | hashtb_end(e); |
| 659 | |
| 660 | } |
| 661 | |
| 662 | |
| 663 | int |
| 664 | get_adjacent_status(struct name_prefix *nbr) |
| 665 | { |
| 666 | printf("get_adjacent_status called \n"); |
| 667 | |
| 668 | int res; |
| 669 | int status=-1; |
| 670 | struct ndn_neighbor *nnbr; |
| 671 | |
| 672 | struct hashtb_enumerator ee; |
| 673 | struct hashtb_enumerator *e = ⅇ |
| 674 | |
| 675 | hashtb_start(nlsr->adl, e); |
| 676 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 677 | |
| 678 | if (res == HT_OLD_ENTRY) |
| 679 | { |
| 680 | nnbr=e->data; |
| 681 | status=nnbr->status; |
| 682 | } |
| 683 | else if(res == HT_NEW_ENTRY) |
| 684 | { |
| 685 | hashtb_delete(e); |
| 686 | } |
| 687 | |
| 688 | hashtb_end(e); |
| 689 | |
| 690 | return status; |
| 691 | |
| 692 | } |
| 693 | |