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 | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 78 | if ( nlsr->debugging ) |
| 79 | { |
| 80 | printf("print_adjacent called\n"); |
| 81 | printf("--------Neighbor---------------------------\n"); |
| 82 | printf(" Neighbor: %s \n",nbr->neighbor->name); |
| 83 | printf(" Length : %d \n",nbr->neighbor->length); |
| 84 | printf(" Face : %d \n",nbr->face); |
| 85 | printf(" Metric : %d \n",nbr->metric); |
| 86 | printf(" Status : %d \n",nbr->status); |
| 87 | printf(" LSDB Version: %s \n",nbr->last_lsdb_version); |
| 88 | printf(" Info Version: %s \n",nbr->last_info_version); |
| 89 | printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out); |
| 90 | printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out); |
| 91 | printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval); |
| 92 | printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component); |
| 93 | printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested); |
| 94 | printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 95 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 96 | printf("\n"); |
| 97 | } |
| 98 | |
| 99 | if ( nlsr->detailed_logging ) |
| 100 | { |
| 101 | |
| 102 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent called\n"); |
| 103 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"--------Neighbor---------------------------\n"); |
| 104 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Neighbor: %s \n",nbr->neighbor->name); |
| 105 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Length : %d \n",nbr->neighbor->length); |
| 106 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face : %d \n",nbr->face); |
| 107 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric : %d \n",nbr->metric); |
| 108 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Status : %d \n",nbr->status); |
| 109 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Version: %s \n",nbr->last_lsdb_version); |
| 110 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Version: %s \n",nbr->last_info_version); |
| 111 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Interest Timed Out : %d \n",nbr->info_interest_timed_out); |
| 112 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out); |
| 113 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval); |
| 114 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component); |
| 115 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested); |
| 116 | writeLogg(__FILE__,__FUNCTION__,__LINE__," IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled); |
| 117 | |
| 118 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 119 | } |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 120 | |
| 121 | } |
| 122 | |
| 123 | void |
| 124 | print_adjacent_from_adl(void) |
| 125 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 126 | if ( nlsr->debugging ) |
| 127 | printf("print_adjacent_from_adl called \n"); |
| 128 | if ( nlsr->detailed_logging ) |
| 129 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent_from_adl called \n"); |
| 130 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 131 | int i, adl_element; |
| 132 | struct ndn_neighbor *nbr; |
| 133 | |
| 134 | struct hashtb_enumerator ee; |
| 135 | struct hashtb_enumerator *e = ⅇ |
| 136 | |
| 137 | hashtb_start(nlsr->adl, e); |
| 138 | adl_element=hashtb_n(nlsr->adl); |
| 139 | |
| 140 | for(i=0;i<adl_element;i++) |
| 141 | { |
| 142 | nbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 143 | print_adjacent(nbr); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 144 | hashtb_next(e); |
| 145 | } |
| 146 | |
| 147 | hashtb_end(e); |
| 148 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 149 | } |
| 150 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 151 | int |
| 152 | get_adjacent_status(struct name_prefix *nbr) |
| 153 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 154 | |
| 155 | if ( nlsr->debugging ) |
| 156 | printf("get_adjacent_status called \n"); |
| 157 | if ( nlsr->detailed_logging ) |
| 158 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adjacent_status called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 159 | |
| 160 | int res; |
| 161 | int status=-1; |
| 162 | struct ndn_neighbor *nnbr; |
| 163 | |
| 164 | struct hashtb_enumerator ee; |
| 165 | struct hashtb_enumerator *e = ⅇ |
| 166 | |
| 167 | hashtb_start(nlsr->adl, e); |
| 168 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 169 | |
| 170 | if (res == HT_OLD_ENTRY) |
| 171 | { |
| 172 | nnbr=e->data; |
| 173 | status=nnbr->status; |
| 174 | } |
| 175 | else if(res == HT_NEW_ENTRY) |
| 176 | { |
| 177 | hashtb_delete(e); |
| 178 | } |
| 179 | |
| 180 | hashtb_end(e); |
| 181 | |
| 182 | return status; |
| 183 | |
| 184 | } |
| 185 | |
| 186 | int |
| 187 | get_timed_out_number(struct name_prefix *nbr) |
| 188 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 189 | |
| 190 | if ( nlsr->debugging ) |
| 191 | printf("get_timed_out_number called \n"); |
| 192 | if ( nlsr->detailed_logging ) |
| 193 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called \n"); |
| 194 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 195 | |
| 196 | int res,ret=-1; |
| 197 | struct ndn_neighbor *nnbr; |
| 198 | |
| 199 | struct hashtb_enumerator ee; |
| 200 | struct hashtb_enumerator *e = ⅇ |
| 201 | |
| 202 | hashtb_start(nlsr->adl, e); |
| 203 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 204 | |
| 205 | if( res == HT_OLD_ENTRY ) |
| 206 | { |
| 207 | nnbr=e->data; |
| 208 | ret=nnbr->info_interest_timed_out; |
| 209 | } |
| 210 | else if(res == HT_NEW_ENTRY) |
| 211 | { |
| 212 | hashtb_delete(e); |
| 213 | } |
| 214 | |
| 215 | hashtb_end(e); |
| 216 | |
| 217 | return ret; |
| 218 | } |
| 219 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 220 | int |
| 221 | get_lsdb_interest_timed_out_number(struct name_prefix *nbr) |
| 222 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 223 | |
| 224 | if ( nlsr->debugging ) |
| 225 | printf("get_lsdb_interest_timed_out_number called \n"); |
| 226 | if ( nlsr->detailed_logging ) |
| 227 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_interest_timed_out_number called \n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 228 | |
| 229 | int res,ret=-1; |
| 230 | struct ndn_neighbor *nnbr; |
| 231 | |
| 232 | struct hashtb_enumerator ee; |
| 233 | struct hashtb_enumerator *e = ⅇ |
| 234 | |
| 235 | hashtb_start(nlsr->adl, e); |
| 236 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 237 | |
| 238 | if( res == HT_OLD_ENTRY ) |
| 239 | { |
| 240 | nnbr=e->data; |
| 241 | ret=nnbr->lsdb_interest_timed_out; |
| 242 | } |
| 243 | else if(res == HT_NEW_ENTRY) |
| 244 | { |
| 245 | hashtb_delete(e); |
| 246 | } |
| 247 | |
| 248 | hashtb_end(e); |
| 249 | |
| 250 | return ret; |
| 251 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 252 | |
| 253 | void |
| 254 | update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment) |
| 255 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 256 | if ( nlsr->debugging ) |
| 257 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 258 | if ( nlsr->detailed_logging ) |
| 259 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 260 | |
| 261 | int res; |
| 262 | struct ndn_neighbor *nnbr; |
| 263 | |
| 264 | struct hashtb_enumerator ee; |
| 265 | struct hashtb_enumerator *e = ⅇ |
| 266 | |
| 267 | hashtb_start(nlsr->adl, e); |
| 268 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 269 | |
| 270 | if( res == HT_OLD_ENTRY ) |
| 271 | { |
| 272 | nnbr=e->data; |
| 273 | nnbr->info_interest_timed_out += increment; |
| 274 | } |
| 275 | else if(res == HT_NEW_ENTRY) |
| 276 | { |
| 277 | hashtb_delete(e); |
| 278 | } |
| 279 | |
| 280 | hashtb_end(e); |
| 281 | } |
| 282 | |
| 283 | void |
| 284 | update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr) |
| 285 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 286 | if ( nlsr->debugging ) |
| 287 | printf("update_adjacent_timed_out_zero_to_adl called \n"); |
| 288 | if ( nlsr->detailed_logging ) |
| 289 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called \n"); |
| 290 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 291 | int time_out_number=get_timed_out_number(nbr); |
| 292 | update_adjacent_timed_out_to_adl(nbr,-time_out_number); |
| 293 | |
| 294 | } |
| 295 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 296 | |
| 297 | void |
| 298 | update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment) |
| 299 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 300 | if ( nlsr->debugging ) |
| 301 | printf("update_lsdb_interest_timed_out_to_adl called\n"); |
| 302 | if ( nlsr->detailed_logging ) |
| 303 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_interest_timed_out_to_adl called \n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 304 | |
| 305 | int res; |
| 306 | struct ndn_neighbor *nnbr; |
| 307 | |
| 308 | struct hashtb_enumerator ee; |
| 309 | struct hashtb_enumerator *e = ⅇ |
| 310 | |
| 311 | hashtb_start(nlsr->adl, e); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 312 | |
| 313 | //printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length); |
| 314 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 315 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 316 | |
| 317 | if( res == HT_OLD_ENTRY ) |
| 318 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 319 | //printf("Old Neighbor\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 320 | nnbr=e->data; |
| 321 | nnbr->lsdb_interest_timed_out += increment; |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 322 | //printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 323 | } |
| 324 | else if(res == HT_NEW_ENTRY) |
| 325 | { |
| 326 | hashtb_delete(e); |
| 327 | } |
| 328 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 329 | //print_adjacent_from_adl(); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 330 | hashtb_end(e); |
| 331 | } |
| 332 | |
| 333 | void |
| 334 | update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr) |
| 335 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 336 | if ( nlsr->debugging ) |
| 337 | printf("update_adjacent_timed_out_zero_to_adl called\n"); |
| 338 | if ( nlsr->detailed_logging ) |
| 339 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called\n"); |
| 340 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 341 | int time_out_number=get_lsdb_interest_timed_out_number(nbr); |
| 342 | update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number); |
| 343 | |
| 344 | } |
| 345 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 346 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 347 | update_adjacent_status_to_adl(struct name_prefix *nbr, int status) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 348 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 349 | if ( nlsr->debugging ) |
| 350 | printf("update_adjacent_status_to_adl called\n"); |
| 351 | if ( nlsr->detailed_logging ) |
| 352 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_status_to_adl called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 353 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 354 | int res; |
| 355 | struct ndn_neighbor *nnbr; |
| 356 | |
| 357 | struct hashtb_enumerator ee; |
| 358 | struct hashtb_enumerator *e = ⅇ |
| 359 | |
| 360 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 361 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 362 | |
akmhoque | 918ff9a | 2012-08-21 11:34:49 -0400 | [diff] [blame] | 363 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 364 | if (res == HT_OLD_ENTRY) |
| 365 | { |
| 366 | nnbr=e->data; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 367 | if ( nnbr->status!=status ) |
| 368 | { |
| 369 | nnbr->status=status; |
| 370 | nlsr->adj_build_flag++; |
| 371 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 372 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 373 | else if(res == HT_NEW_ENTRY) |
| 374 | { |
| 375 | hashtb_delete(e); |
| 376 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 377 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 378 | hashtb_end(e); |
| 379 | } |
| 380 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 381 | |
| 382 | void |
| 383 | delete_nbr_from_adl(struct name_prefix *nbr) |
| 384 | { |
| 385 | if ( nlsr->debugging ) |
| 386 | printf("delete_nbr_from_adl called\n"); |
| 387 | if ( nlsr->detailed_logging ) |
| 388 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_nbr_from_adl called \n"); |
| 389 | |
| 390 | int res; |
| 391 | struct hashtb_enumerator ee; |
| 392 | struct hashtb_enumerator *e = ⅇ |
| 393 | |
| 394 | hashtb_start(nlsr->adl, e); |
| 395 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 396 | |
| 397 | |
| 398 | if (res == HT_OLD_ENTRY) |
| 399 | { |
| 400 | hashtb_delete(e); |
| 401 | } |
| 402 | else if(res == HT_NEW_ENTRY) |
| 403 | { |
| 404 | hashtb_delete(e); |
| 405 | } |
| 406 | |
| 407 | hashtb_end(e); |
| 408 | } |
| 409 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 410 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 411 | update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 412 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 413 | if ( nlsr->debugging ) |
| 414 | printf("update_lsdb_synch_interval_to_adl called\n"); |
| 415 | if ( nlsr->detailed_logging ) |
| 416 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 417 | |
| 418 | int res; |
| 419 | struct ndn_neighbor *nnbr; |
| 420 | |
| 421 | struct hashtb_enumerator ee; |
| 422 | struct hashtb_enumerator *e = ⅇ |
| 423 | |
| 424 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 425 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 426 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 427 | |
| 428 | if (res == HT_OLD_ENTRY) |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 429 | { |
| 430 | nnbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 431 | if ( nnbr->lsdb_synch_interval!= interval ) |
| 432 | { |
| 433 | nnbr->lsdb_synch_interval=interval; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 434 | nnbr->lsdb_random_time_component=(int)(interval/2); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 435 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 436 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 437 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 438 | else if(res == HT_NEW_ENTRY) |
| 439 | { |
| 440 | hashtb_delete(e); |
| 441 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 442 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 443 | hashtb_end(e); |
| 444 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 445 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 446 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 447 | int |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 448 | no_active_nbr(void) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 449 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 450 | int i, adl_element; |
| 451 | int no_link=0; |
| 452 | struct ndn_neighbor *nbr; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 453 | struct hashtb_enumerator ee; |
| 454 | struct hashtb_enumerator *e = ⅇ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 455 | hashtb_start(nlsr->adl, e); |
| 456 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 457 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 458 | for(i=0;i<adl_element;i++) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 459 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 460 | nbr=e->data; |
| 461 | if( nbr->status == 1 ) |
| 462 | no_link++; |
| 463 | hashtb_next(e); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 464 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 465 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 466 | hashtb_end(e); |
| 467 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 468 | return no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 469 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 470 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 471 | |
| 472 | int |
| 473 | is_adj_lsa_build(void) |
| 474 | { |
| 475 | int ret=0; |
| 476 | |
| 477 | int nbr_count=0; |
| 478 | |
| 479 | int i, adl_element; |
| 480 | struct ndn_neighbor *nbr; |
| 481 | |
| 482 | struct hashtb_enumerator ee; |
| 483 | struct hashtb_enumerator *e = ⅇ |
| 484 | |
| 485 | hashtb_start(nlsr->adl, e); |
| 486 | adl_element=hashtb_n(nlsr->adl); |
| 487 | |
| 488 | for(i=0;i<adl_element;i++) |
| 489 | { |
| 490 | nbr=e->data; |
| 491 | if(nbr->status == 1 ) |
| 492 | { |
| 493 | nbr_count++; |
| 494 | } |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 495 | 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] | 496 | { |
| 497 | nbr_count++; |
| 498 | } |
| 499 | hashtb_next(e); |
| 500 | } |
| 501 | |
| 502 | hashtb_end(e); |
| 503 | if(nbr_count == adl_element) |
| 504 | ret=1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 505 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 506 | return ret; |
| 507 | } |
| 508 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 509 | |
| 510 | void |
| 511 | get_active_nbr_adj_data(struct ccn_charbuf *c) |
| 512 | { |
| 513 | |
| 514 | int i, adl_element; |
| 515 | struct ndn_neighbor *nbr; |
| 516 | struct hashtb_enumerator ee; |
| 517 | struct hashtb_enumerator *e = ⅇ |
| 518 | hashtb_start(nlsr->adl, e); |
| 519 | adl_element=hashtb_n(nlsr->adl); |
| 520 | |
| 521 | for(i=0;i<adl_element;i++) |
| 522 | { |
| 523 | nbr=e->data; |
| 524 | if( nbr->status == 1 ) |
| 525 | { |
| 526 | ccn_charbuf_append_string(c,nbr->neighbor->name); |
| 527 | ccn_charbuf_append_string(c,"|"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 528 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 529 | char *temp_length=(char *)malloc(20); |
| 530 | memset(temp_length,0,20); |
| 531 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 532 | ccn_charbuf_append_string(c,temp_length); |
| 533 | free(temp_length); |
| 534 | ccn_charbuf_append_string(c,"|"); |
| 535 | |
| 536 | char *temp_face=(char *)malloc(20); |
| 537 | memset(temp_face,0,20); |
| 538 | sprintf(temp_face,"%d",nbr->face); |
| 539 | ccn_charbuf_append_string(c,temp_face); |
| 540 | free(temp_face); |
| 541 | ccn_charbuf_append_string(c,"|"); |
| 542 | |
| 543 | char *temp_metric=(char *)malloc(20); |
| 544 | memset(temp_metric,0,20); |
| 545 | sprintf(temp_metric,"%d",nbr->metric); |
| 546 | ccn_charbuf_append_string(c,temp_metric); |
| 547 | free(temp_metric); |
| 548 | ccn_charbuf_append_string(c,"|"); |
| 549 | |
| 550 | } |
| 551 | hashtb_next(e); |
| 552 | } |
| 553 | |
| 554 | hashtb_end(e); |
| 555 | } |
| 556 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 557 | long int |
| 558 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 559 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 560 | if ( nlsr->debugging ) |
| 561 | printf("get_nbr_time_diff_lsdb_req called\n"); |
| 562 | if ( nlsr->detailed_logging ) |
| 563 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 564 | |
| 565 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 566 | int res; |
| 567 | struct ndn_neighbor *nnbr; |
| 568 | |
| 569 | struct hashtb_enumerator ee; |
| 570 | struct hashtb_enumerator *e = ⅇ |
| 571 | |
| 572 | hashtb_start(nlsr->adl, e); |
| 573 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 574 | |
| 575 | if (res == HT_OLD_ENTRY) |
| 576 | { |
| 577 | nnbr=e->data; |
| 578 | |
| 579 | if (nnbr->last_lsdb_requested == 0) |
| 580 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 581 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 582 | |
| 583 | } |
| 584 | else if(res == HT_NEW_ENTRY) |
| 585 | { |
| 586 | hashtb_delete(e); |
| 587 | } |
| 588 | |
| 589 | hashtb_end(e); |
| 590 | |
| 591 | return time_diff; |
| 592 | } |
| 593 | |
| 594 | long int |
| 595 | get_nbr_last_lsdb_requested(char *nbr) |
| 596 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 597 | if ( nlsr->debugging ) |
| 598 | printf("get_timed_out_number called\n"); |
| 599 | if ( nlsr->detailed_logging ) |
| 600 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 601 | |
| 602 | long int last_lsdb_requested=0; |
| 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); |
| 612 | |
| 613 | if (res == HT_OLD_ENTRY) |
| 614 | { |
| 615 | nnbr=e->data; |
| 616 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 617 | } |
| 618 | else if(res == HT_NEW_ENTRY) |
| 619 | { |
| 620 | hashtb_delete(e); |
| 621 | } |
| 622 | |
| 623 | hashtb_end(e); |
| 624 | |
| 625 | return last_lsdb_requested; |
| 626 | } |
| 627 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 628 | |
| 629 | int |
| 630 | get_nbr_random_time_component(char *nbr) |
| 631 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 632 | if ( nlsr->debugging ) |
| 633 | printf("get_nbr_random_time_component called\n"); |
| 634 | if ( nlsr->detailed_logging ) |
| 635 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 636 | |
| 637 | int time=0; |
| 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; |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 651 | 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] | 652 | } |
| 653 | else if(res == HT_NEW_ENTRY) |
| 654 | { |
| 655 | hashtb_delete(e); |
| 656 | } |
| 657 | |
| 658 | hashtb_end(e); |
| 659 | |
| 660 | return time; |
| 661 | } |
| 662 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 663 | long int |
| 664 | get_lsdb_synch_interval(char *nbr) |
| 665 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 666 | if ( nlsr->debugging ) |
| 667 | printf("get_lsdb_synch_interval called \n"); |
| 668 | if ( nlsr->detailed_logging ) |
| 669 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 670 | |
| 671 | long int lsdb_synch_interval=300; |
| 672 | |
| 673 | |
| 674 | int res; |
| 675 | struct ndn_neighbor *nnbr; |
| 676 | |
| 677 | struct hashtb_enumerator ee; |
| 678 | struct hashtb_enumerator *e = ⅇ |
| 679 | |
| 680 | hashtb_start(nlsr->adl, e); |
| 681 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 682 | |
| 683 | if (res == HT_OLD_ENTRY) |
| 684 | { |
| 685 | nnbr=e->data; |
| 686 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 687 | } |
| 688 | else if(res == HT_NEW_ENTRY) |
| 689 | { |
| 690 | hashtb_delete(e); |
| 691 | } |
| 692 | |
| 693 | hashtb_end(e); |
| 694 | |
| 695 | return lsdb_synch_interval; |
| 696 | |
| 697 | } |
| 698 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 699 | char * |
| 700 | get_nbr_lsdb_version(char *nbr) |
| 701 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 702 | if ( nlsr->debugging ) |
| 703 | printf("get_nbr_lsdb_version called \n"); |
| 704 | if ( nlsr->detailed_logging ) |
| 705 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 706 | |
| 707 | char *version=NULL; |
| 708 | |
| 709 | int res; |
| 710 | struct ndn_neighbor *nnbr; |
| 711 | |
| 712 | struct hashtb_enumerator ee; |
| 713 | struct hashtb_enumerator *e = ⅇ |
| 714 | |
| 715 | hashtb_start(nlsr->adl, e); |
| 716 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 717 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 718 | if (res == HT_OLD_ENTRY) |
| 719 | { |
| 720 | nnbr=e->data; |
| 721 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 722 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 723 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 724 | } |
| 725 | else if(res == HT_NEW_ENTRY) |
| 726 | { |
| 727 | hashtb_delete(e); |
| 728 | } |
| 729 | |
| 730 | hashtb_end(e); |
| 731 | |
| 732 | return version; |
| 733 | } |
| 734 | |
| 735 | void |
| 736 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 737 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 738 | if ( nlsr->debugging ) |
| 739 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 740 | if ( nlsr->detailed_logging ) |
| 741 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 742 | |
| 743 | int res; |
| 744 | struct ndn_neighbor *nnbr; |
| 745 | |
| 746 | struct hashtb_enumerator ee; |
| 747 | struct hashtb_enumerator *e = ⅇ |
| 748 | |
| 749 | hashtb_start(nlsr->adl, e); |
| 750 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 751 | |
| 752 | if( res == HT_OLD_ENTRY ) |
| 753 | { |
| 754 | nnbr=e->data; |
| 755 | nnbr->last_lsdb_requested=timestamp; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 756 | |
| 757 | } |
| 758 | else if(res == HT_NEW_ENTRY) |
| 759 | { |
| 760 | hashtb_delete(e); |
| 761 | } |
| 762 | |
| 763 | hashtb_end(e); |
| 764 | } |
| 765 | |
| 766 | void |
| 767 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 768 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 769 | if ( nlsr->debugging ) |
| 770 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 771 | if ( nlsr->detailed_logging ) |
| 772 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n"); |
| 773 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 774 | |
| 775 | int res; |
| 776 | struct ndn_neighbor *nnbr; |
| 777 | |
| 778 | struct hashtb_enumerator ee; |
| 779 | struct hashtb_enumerator *e = ⅇ |
| 780 | |
| 781 | hashtb_start(nlsr->adl, e); |
| 782 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 783 | |
| 784 | if (res == HT_OLD_ENTRY) |
| 785 | { |
| 786 | nnbr=e->data; |
| 787 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 788 | } |
| 789 | else if(res == HT_NEW_ENTRY) |
| 790 | { |
| 791 | hashtb_delete(e); |
| 792 | } |
| 793 | |
| 794 | hashtb_end(e); |
| 795 | } |
| 796 | |
| 797 | void |
| 798 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
| 799 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 800 | if ( nlsr->debugging ) |
| 801 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 802 | if ( nlsr->detailed_logging ) |
| 803 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 804 | |
| 805 | int res; |
| 806 | struct ndn_neighbor *nnbr; |
| 807 | |
| 808 | struct hashtb_enumerator ee; |
| 809 | struct hashtb_enumerator *e = ⅇ |
| 810 | |
| 811 | hashtb_start(nlsr->adl, e); |
| 812 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 813 | |
| 814 | if( res == HT_OLD_ENTRY ) |
| 815 | { |
| 816 | nnbr=e->data; |
| 817 | free(nnbr->last_lsdb_version); |
| 818 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 819 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 820 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 821 | } |
| 822 | else if(res == HT_NEW_ENTRY) |
| 823 | { |
| 824 | hashtb_delete(e); |
| 825 | } |
| 826 | |
| 827 | hashtb_end(e); |
| 828 | |
| 829 | } |
| 830 | |
| 831 | void |
| 832 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 833 | { |
| 834 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 835 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 836 | if ( nlsr->debugging ) |
| 837 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 838 | if ( nlsr->detailed_logging ) |
| 839 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n"); |
| 840 | |
| 841 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 842 | int res; |
| 843 | struct ndn_neighbor *nnbr; |
| 844 | |
| 845 | struct hashtb_enumerator ee; |
| 846 | struct hashtb_enumerator *e = ⅇ |
| 847 | |
| 848 | hashtb_start(nlsr->adl, e); |
| 849 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 850 | |
| 851 | if( res == HT_OLD_ENTRY ) |
| 852 | { |
| 853 | nnbr=e->data; |
| 854 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 855 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 856 | } |
| 857 | else if(res == HT_NEW_ENTRY) |
| 858 | { |
| 859 | hashtb_delete(e); |
| 860 | } |
| 861 | |
| 862 | hashtb_end(e); |
| 863 | |
| 864 | } |
| 865 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 866 | int |
| 867 | get_next_hop_face_from_adl(char *nbr) |
| 868 | { |
| 869 | int res; |
| 870 | int connecting_face=NO_FACE; |
| 871 | struct ndn_neighbor *nnbr; |
| 872 | |
| 873 | struct hashtb_enumerator ee; |
| 874 | struct hashtb_enumerator *e = ⅇ |
| 875 | |
| 876 | hashtb_start(nlsr->adl, e); |
| 877 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 878 | |
| 879 | if( res == HT_OLD_ENTRY ) |
| 880 | { |
| 881 | nnbr=e->data; |
| 882 | connecting_face=nnbr->face; |
| 883 | |
| 884 | } |
| 885 | else if(res == HT_NEW_ENTRY) |
| 886 | { |
| 887 | hashtb_delete(e); |
| 888 | } |
| 889 | |
| 890 | hashtb_end(e); |
| 891 | return connecting_face; |
| 892 | } |
| 893 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 894 | int |
| 895 | is_neighbor(char *nbr) |
| 896 | { |
| 897 | int ret=0; |
| 898 | |
| 899 | int res; |
| 900 | struct hashtb_enumerator ee; |
| 901 | struct hashtb_enumerator *e = ⅇ |
| 902 | |
| 903 | hashtb_start(nlsr->adl, e); |
| 904 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 905 | |
| 906 | if( res == HT_OLD_ENTRY ) |
| 907 | { |
| 908 | ret=1; |
| 909 | } |
| 910 | else if(res == HT_NEW_ENTRY) |
| 911 | { |
| 912 | hashtb_delete(e); |
| 913 | } |
| 914 | |
| 915 | hashtb_end(e); |
| 916 | |
| 917 | return ret; |
| 918 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 919 | |