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