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