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 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 251 | printf("update_lsdb_interest_timed_out_to_adl called \n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 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); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 260 | |
| 261 | //printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length); |
| 262 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 263 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 264 | |
| 265 | if( res == HT_OLD_ENTRY ) |
| 266 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 267 | //printf("Old Neighbor\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 268 | nnbr=e->data; |
| 269 | nnbr->lsdb_interest_timed_out += increment; |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 270 | //printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 271 | } |
| 272 | else if(res == HT_NEW_ENTRY) |
| 273 | { |
| 274 | hashtb_delete(e); |
| 275 | } |
| 276 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 277 | //print_adjacent_from_adl(); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 278 | hashtb_end(e); |
| 279 | } |
| 280 | |
| 281 | void |
| 282 | update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr) |
| 283 | { |
| 284 | printf("update_adjacent_timed_out_zero_to_adl called \n"); |
| 285 | int time_out_number=get_lsdb_interest_timed_out_number(nbr); |
| 286 | update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number); |
| 287 | |
| 288 | } |
| 289 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 290 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 291 | update_adjacent_status_to_adl(struct name_prefix *nbr, int status) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 292 | { |
| 293 | printf("update_adjacent_status_to_adl called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 294 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 295 | int res; |
| 296 | struct ndn_neighbor *nnbr; |
| 297 | |
| 298 | struct hashtb_enumerator ee; |
| 299 | struct hashtb_enumerator *e = ⅇ |
| 300 | |
| 301 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 302 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 303 | |
akmhoque | 918ff9a | 2012-08-21 11:34:49 -0400 | [diff] [blame] | 304 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 305 | if (res == HT_OLD_ENTRY) |
| 306 | { |
| 307 | nnbr=e->data; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 308 | if ( nnbr->status!=status ) |
| 309 | { |
| 310 | nnbr->status=status; |
| 311 | nlsr->adj_build_flag++; |
| 312 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 313 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 314 | else if(res == HT_NEW_ENTRY) |
| 315 | { |
| 316 | hashtb_delete(e); |
| 317 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 318 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 319 | hashtb_end(e); |
| 320 | } |
| 321 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 322 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 323 | update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 324 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 325 | printf("uupdate_lsdb_synch_interval_to_adl called \n"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 326 | |
| 327 | int res; |
| 328 | struct ndn_neighbor *nnbr; |
| 329 | |
| 330 | struct hashtb_enumerator ee; |
| 331 | struct hashtb_enumerator *e = ⅇ |
| 332 | |
| 333 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 334 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 335 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 336 | |
| 337 | if (res == HT_OLD_ENTRY) |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 338 | { |
| 339 | nnbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 340 | if ( nnbr->lsdb_synch_interval!= interval ) |
| 341 | { |
| 342 | nnbr->lsdb_synch_interval=interval; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 343 | nnbr->lsdb_random_time_component=(int)(interval/2); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 344 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 345 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 346 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 347 | else if(res == HT_NEW_ENTRY) |
| 348 | { |
| 349 | hashtb_delete(e); |
| 350 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 351 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 352 | hashtb_end(e); |
| 353 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 354 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 355 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 356 | int |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 357 | no_active_nbr(void) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 358 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 359 | int i, adl_element; |
| 360 | int no_link=0; |
| 361 | struct ndn_neighbor *nbr; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 362 | struct hashtb_enumerator ee; |
| 363 | struct hashtb_enumerator *e = ⅇ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 364 | hashtb_start(nlsr->adl, e); |
| 365 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 366 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 367 | for(i=0;i<adl_element;i++) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 368 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 369 | nbr=e->data; |
| 370 | if( nbr->status == 1 ) |
| 371 | no_link++; |
| 372 | hashtb_next(e); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 373 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 374 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 375 | hashtb_end(e); |
| 376 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 377 | return no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 378 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 379 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 380 | |
| 381 | int |
| 382 | is_adj_lsa_build(void) |
| 383 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 384 | //print_adjacent_from_adl(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 385 | int ret=0; |
| 386 | |
| 387 | int nbr_count=0; |
| 388 | |
| 389 | int i, adl_element; |
| 390 | struct ndn_neighbor *nbr; |
| 391 | |
| 392 | struct hashtb_enumerator ee; |
| 393 | struct hashtb_enumerator *e = ⅇ |
| 394 | |
| 395 | hashtb_start(nlsr->adl, e); |
| 396 | adl_element=hashtb_n(nlsr->adl); |
| 397 | |
| 398 | for(i=0;i<adl_element;i++) |
| 399 | { |
| 400 | nbr=e->data; |
| 401 | if(nbr->status == 1 ) |
| 402 | { |
| 403 | nbr_count++; |
| 404 | } |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 405 | else if ( (nbr->status == 0) && (nbr->info_interest_timed_out >= nlsr->interest_retry || nbr->lsdb_interest_timed_out >= nlsr->interest_retry)) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 406 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame^] | 407 | //printf(" In Status: 0 info_interest_timed_out= %d and lsdb_interest_timed_out= %d\n",nbr->info_interest_timed_out,nbr->lsdb_interest_timed_out); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 408 | nbr_count++; |
| 409 | } |
| 410 | hashtb_next(e); |
| 411 | } |
| 412 | |
| 413 | hashtb_end(e); |
| 414 | if(nbr_count == adl_element) |
| 415 | ret=1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 416 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 417 | return ret; |
| 418 | } |
| 419 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 420 | |
| 421 | void |
| 422 | get_active_nbr_adj_data(struct ccn_charbuf *c) |
| 423 | { |
| 424 | |
| 425 | int i, adl_element; |
| 426 | struct ndn_neighbor *nbr; |
| 427 | struct hashtb_enumerator ee; |
| 428 | struct hashtb_enumerator *e = ⅇ |
| 429 | hashtb_start(nlsr->adl, e); |
| 430 | adl_element=hashtb_n(nlsr->adl); |
| 431 | |
| 432 | for(i=0;i<adl_element;i++) |
| 433 | { |
| 434 | nbr=e->data; |
| 435 | if( nbr->status == 1 ) |
| 436 | { |
| 437 | ccn_charbuf_append_string(c,nbr->neighbor->name); |
| 438 | ccn_charbuf_append_string(c,"|"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 439 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 440 | char *temp_length=(char *)malloc(20); |
| 441 | memset(temp_length,0,20); |
| 442 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 443 | ccn_charbuf_append_string(c,temp_length); |
| 444 | free(temp_length); |
| 445 | ccn_charbuf_append_string(c,"|"); |
| 446 | |
| 447 | char *temp_face=(char *)malloc(20); |
| 448 | memset(temp_face,0,20); |
| 449 | sprintf(temp_face,"%d",nbr->face); |
| 450 | ccn_charbuf_append_string(c,temp_face); |
| 451 | free(temp_face); |
| 452 | ccn_charbuf_append_string(c,"|"); |
| 453 | |
| 454 | char *temp_metric=(char *)malloc(20); |
| 455 | memset(temp_metric,0,20); |
| 456 | sprintf(temp_metric,"%d",nbr->metric); |
| 457 | ccn_charbuf_append_string(c,temp_metric); |
| 458 | free(temp_metric); |
| 459 | ccn_charbuf_append_string(c,"|"); |
| 460 | |
| 461 | } |
| 462 | hashtb_next(e); |
| 463 | } |
| 464 | |
| 465 | hashtb_end(e); |
| 466 | } |
| 467 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 468 | long int |
| 469 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 470 | { |
| 471 | printf("get_nbr_time_diff_lsdb_req called \n"); |
| 472 | |
| 473 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 474 | int res; |
| 475 | struct ndn_neighbor *nnbr; |
| 476 | |
| 477 | struct hashtb_enumerator ee; |
| 478 | struct hashtb_enumerator *e = ⅇ |
| 479 | |
| 480 | hashtb_start(nlsr->adl, e); |
| 481 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 482 | |
| 483 | if (res == HT_OLD_ENTRY) |
| 484 | { |
| 485 | nnbr=e->data; |
| 486 | |
| 487 | if (nnbr->last_lsdb_requested == 0) |
| 488 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 489 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 490 | |
| 491 | } |
| 492 | else if(res == HT_NEW_ENTRY) |
| 493 | { |
| 494 | hashtb_delete(e); |
| 495 | } |
| 496 | |
| 497 | hashtb_end(e); |
| 498 | |
| 499 | return time_diff; |
| 500 | } |
| 501 | |
| 502 | long int |
| 503 | get_nbr_last_lsdb_requested(char *nbr) |
| 504 | { |
| 505 | printf("get_timed_out_number called \n"); |
| 506 | |
| 507 | long int last_lsdb_requested=0; |
| 508 | |
| 509 | int res; |
| 510 | struct ndn_neighbor *nnbr; |
| 511 | |
| 512 | struct hashtb_enumerator ee; |
| 513 | struct hashtb_enumerator *e = ⅇ |
| 514 | |
| 515 | hashtb_start(nlsr->adl, e); |
| 516 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 517 | |
| 518 | if (res == HT_OLD_ENTRY) |
| 519 | { |
| 520 | nnbr=e->data; |
| 521 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 522 | } |
| 523 | else if(res == HT_NEW_ENTRY) |
| 524 | { |
| 525 | hashtb_delete(e); |
| 526 | } |
| 527 | |
| 528 | hashtb_end(e); |
| 529 | |
| 530 | return last_lsdb_requested; |
| 531 | } |
| 532 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 533 | |
| 534 | int |
| 535 | get_nbr_random_time_component(char *nbr) |
| 536 | { |
| 537 | printf("get_timed_out_number called \n"); |
| 538 | |
| 539 | int time=0; |
| 540 | |
| 541 | int res; |
| 542 | struct ndn_neighbor *nnbr; |
| 543 | |
| 544 | struct hashtb_enumerator ee; |
| 545 | struct hashtb_enumerator *e = ⅇ |
| 546 | |
| 547 | hashtb_start(nlsr->adl, e); |
| 548 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 549 | |
| 550 | if (res == HT_OLD_ENTRY) |
| 551 | { |
| 552 | nnbr=e->data; |
| 553 | time=nnbr->lsdb_random_time_component * nnbr->lsdb_interest_timed_out; |
| 554 | } |
| 555 | else if(res == HT_NEW_ENTRY) |
| 556 | { |
| 557 | hashtb_delete(e); |
| 558 | } |
| 559 | |
| 560 | hashtb_end(e); |
| 561 | |
| 562 | return time; |
| 563 | } |
| 564 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 565 | long int |
| 566 | get_lsdb_synch_interval(char *nbr) |
| 567 | { |
| 568 | printf("get_lsdb_synch_interval called \n"); |
| 569 | |
| 570 | long int lsdb_synch_interval=300; |
| 571 | |
| 572 | |
| 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 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 586 | } |
| 587 | else if(res == HT_NEW_ENTRY) |
| 588 | { |
| 589 | hashtb_delete(e); |
| 590 | } |
| 591 | |
| 592 | hashtb_end(e); |
| 593 | |
| 594 | return lsdb_synch_interval; |
| 595 | |
| 596 | } |
| 597 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 598 | char * |
| 599 | get_nbr_lsdb_version(char *nbr) |
| 600 | { |
| 601 | printf("get_timed_out_number called \n"); |
| 602 | |
| 603 | char *version=NULL; |
| 604 | |
| 605 | int res; |
| 606 | struct ndn_neighbor *nnbr; |
| 607 | |
| 608 | struct hashtb_enumerator ee; |
| 609 | struct hashtb_enumerator *e = ⅇ |
| 610 | |
| 611 | hashtb_start(nlsr->adl, e); |
| 612 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 613 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 614 | if (res == HT_OLD_ENTRY) |
| 615 | { |
| 616 | nnbr=e->data; |
| 617 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 618 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 619 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 620 | } |
| 621 | else if(res == HT_NEW_ENTRY) |
| 622 | { |
| 623 | hashtb_delete(e); |
| 624 | } |
| 625 | |
| 626 | hashtb_end(e); |
| 627 | |
| 628 | return version; |
| 629 | } |
| 630 | |
| 631 | void |
| 632 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 633 | { |
| 634 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 635 | |
| 636 | int res; |
| 637 | struct ndn_neighbor *nnbr; |
| 638 | |
| 639 | struct hashtb_enumerator ee; |
| 640 | struct hashtb_enumerator *e = ⅇ |
| 641 | |
| 642 | hashtb_start(nlsr->adl, e); |
| 643 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 644 | |
| 645 | if( res == HT_OLD_ENTRY ) |
| 646 | { |
| 647 | nnbr=e->data; |
| 648 | nnbr->last_lsdb_requested=timestamp; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 649 | |
| 650 | } |
| 651 | else if(res == HT_NEW_ENTRY) |
| 652 | { |
| 653 | hashtb_delete(e); |
| 654 | } |
| 655 | |
| 656 | hashtb_end(e); |
| 657 | } |
| 658 | |
| 659 | void |
| 660 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 661 | { |
| 662 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 663 | |
| 664 | int res; |
| 665 | struct ndn_neighbor *nnbr; |
| 666 | |
| 667 | struct hashtb_enumerator ee; |
| 668 | struct hashtb_enumerator *e = ⅇ |
| 669 | |
| 670 | hashtb_start(nlsr->adl, e); |
| 671 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 672 | |
| 673 | if (res == HT_OLD_ENTRY) |
| 674 | { |
| 675 | nnbr=e->data; |
| 676 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 677 | } |
| 678 | else if(res == HT_NEW_ENTRY) |
| 679 | { |
| 680 | hashtb_delete(e); |
| 681 | } |
| 682 | |
| 683 | hashtb_end(e); |
| 684 | } |
| 685 | |
| 686 | void |
| 687 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
| 688 | { |
| 689 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 690 | |
| 691 | int res; |
| 692 | struct ndn_neighbor *nnbr; |
| 693 | |
| 694 | struct hashtb_enumerator ee; |
| 695 | struct hashtb_enumerator *e = ⅇ |
| 696 | |
| 697 | hashtb_start(nlsr->adl, e); |
| 698 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 699 | |
| 700 | if( res == HT_OLD_ENTRY ) |
| 701 | { |
| 702 | nnbr=e->data; |
| 703 | free(nnbr->last_lsdb_version); |
| 704 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 705 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 706 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 707 | } |
| 708 | else if(res == HT_NEW_ENTRY) |
| 709 | { |
| 710 | hashtb_delete(e); |
| 711 | } |
| 712 | |
| 713 | hashtb_end(e); |
| 714 | |
| 715 | } |
| 716 | |
| 717 | void |
| 718 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 719 | { |
| 720 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 721 | |
| 722 | int res; |
| 723 | struct ndn_neighbor *nnbr; |
| 724 | |
| 725 | struct hashtb_enumerator ee; |
| 726 | struct hashtb_enumerator *e = ⅇ |
| 727 | |
| 728 | hashtb_start(nlsr->adl, e); |
| 729 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 730 | |
| 731 | if( res == HT_OLD_ENTRY ) |
| 732 | { |
| 733 | nnbr=e->data; |
| 734 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 735 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 736 | } |
| 737 | else if(res == HT_NEW_ENTRY) |
| 738 | { |
| 739 | hashtb_delete(e); |
| 740 | } |
| 741 | |
| 742 | hashtb_end(e); |
| 743 | |
| 744 | } |
| 745 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 746 | int |
| 747 | get_next_hop_face_from_adl(char *nbr) |
| 748 | { |
| 749 | int res; |
| 750 | int connecting_face=NO_FACE; |
| 751 | struct ndn_neighbor *nnbr; |
| 752 | |
| 753 | struct hashtb_enumerator ee; |
| 754 | struct hashtb_enumerator *e = ⅇ |
| 755 | |
| 756 | hashtb_start(nlsr->adl, e); |
| 757 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 758 | |
| 759 | if( res == HT_OLD_ENTRY ) |
| 760 | { |
| 761 | nnbr=e->data; |
| 762 | connecting_face=nnbr->face; |
| 763 | |
| 764 | } |
| 765 | else if(res == HT_NEW_ENTRY) |
| 766 | { |
| 767 | hashtb_delete(e); |
| 768 | } |
| 769 | |
| 770 | hashtb_end(e); |
| 771 | return connecting_face; |
| 772 | } |
| 773 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 774 | int |
| 775 | is_neighbor(char *nbr) |
| 776 | { |
| 777 | int ret=0; |
| 778 | |
| 779 | int res; |
| 780 | struct hashtb_enumerator ee; |
| 781 | struct hashtb_enumerator *e = ⅇ |
| 782 | |
| 783 | hashtb_start(nlsr->adl, e); |
| 784 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 785 | |
| 786 | if( res == HT_OLD_ENTRY ) |
| 787 | { |
| 788 | ret=1; |
| 789 | } |
| 790 | else if(res == HT_NEW_ENTRY) |
| 791 | { |
| 792 | hashtb_delete(e); |
| 793 | } |
| 794 | |
| 795 | hashtb_end(e); |
| 796 | |
| 797 | return ret; |
| 798 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 799 | |