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 | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 381 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 382 | update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 383 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 384 | if ( nlsr->debugging ) |
| 385 | printf("update_lsdb_synch_interval_to_adl called\n"); |
| 386 | if ( nlsr->detailed_logging ) |
| 387 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 388 | |
| 389 | int res; |
| 390 | struct ndn_neighbor *nnbr; |
| 391 | |
| 392 | struct hashtb_enumerator ee; |
| 393 | struct hashtb_enumerator *e = ⅇ |
| 394 | |
| 395 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 396 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 397 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 398 | |
| 399 | if (res == HT_OLD_ENTRY) |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 400 | { |
| 401 | nnbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 402 | if ( nnbr->lsdb_synch_interval!= interval ) |
| 403 | { |
| 404 | nnbr->lsdb_synch_interval=interval; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 405 | nnbr->lsdb_random_time_component=(int)(interval/2); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 406 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 407 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 408 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 409 | else if(res == HT_NEW_ENTRY) |
| 410 | { |
| 411 | hashtb_delete(e); |
| 412 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 413 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 414 | hashtb_end(e); |
| 415 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 416 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 417 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 418 | int |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 419 | no_active_nbr(void) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 420 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 421 | int i, adl_element; |
| 422 | int no_link=0; |
| 423 | struct ndn_neighbor *nbr; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 424 | struct hashtb_enumerator ee; |
| 425 | struct hashtb_enumerator *e = ⅇ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 426 | hashtb_start(nlsr->adl, e); |
| 427 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 428 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 429 | for(i=0;i<adl_element;i++) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 430 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 431 | nbr=e->data; |
| 432 | if( nbr->status == 1 ) |
| 433 | no_link++; |
| 434 | hashtb_next(e); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 435 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 436 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 437 | hashtb_end(e); |
| 438 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 439 | return no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 440 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 441 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 442 | |
| 443 | int |
| 444 | is_adj_lsa_build(void) |
| 445 | { |
| 446 | int ret=0; |
| 447 | |
| 448 | int nbr_count=0; |
| 449 | |
| 450 | int i, adl_element; |
| 451 | struct ndn_neighbor *nbr; |
| 452 | |
| 453 | struct hashtb_enumerator ee; |
| 454 | struct hashtb_enumerator *e = ⅇ |
| 455 | |
| 456 | hashtb_start(nlsr->adl, e); |
| 457 | adl_element=hashtb_n(nlsr->adl); |
| 458 | |
| 459 | for(i=0;i<adl_element;i++) |
| 460 | { |
| 461 | nbr=e->data; |
| 462 | if(nbr->status == 1 ) |
| 463 | { |
| 464 | nbr_count++; |
| 465 | } |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 466 | 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] | 467 | { |
| 468 | nbr_count++; |
| 469 | } |
| 470 | hashtb_next(e); |
| 471 | } |
| 472 | |
| 473 | hashtb_end(e); |
| 474 | if(nbr_count == adl_element) |
| 475 | ret=1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 476 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 477 | return ret; |
| 478 | } |
| 479 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 480 | |
| 481 | void |
| 482 | get_active_nbr_adj_data(struct ccn_charbuf *c) |
| 483 | { |
| 484 | |
| 485 | int i, adl_element; |
| 486 | struct ndn_neighbor *nbr; |
| 487 | struct hashtb_enumerator ee; |
| 488 | struct hashtb_enumerator *e = ⅇ |
| 489 | hashtb_start(nlsr->adl, e); |
| 490 | adl_element=hashtb_n(nlsr->adl); |
| 491 | |
| 492 | for(i=0;i<adl_element;i++) |
| 493 | { |
| 494 | nbr=e->data; |
| 495 | if( nbr->status == 1 ) |
| 496 | { |
| 497 | ccn_charbuf_append_string(c,nbr->neighbor->name); |
| 498 | ccn_charbuf_append_string(c,"|"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 499 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 500 | char *temp_length=(char *)malloc(20); |
| 501 | memset(temp_length,0,20); |
| 502 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 503 | ccn_charbuf_append_string(c,temp_length); |
| 504 | free(temp_length); |
| 505 | ccn_charbuf_append_string(c,"|"); |
| 506 | |
| 507 | char *temp_face=(char *)malloc(20); |
| 508 | memset(temp_face,0,20); |
| 509 | sprintf(temp_face,"%d",nbr->face); |
| 510 | ccn_charbuf_append_string(c,temp_face); |
| 511 | free(temp_face); |
| 512 | ccn_charbuf_append_string(c,"|"); |
| 513 | |
| 514 | char *temp_metric=(char *)malloc(20); |
| 515 | memset(temp_metric,0,20); |
| 516 | sprintf(temp_metric,"%d",nbr->metric); |
| 517 | ccn_charbuf_append_string(c,temp_metric); |
| 518 | free(temp_metric); |
| 519 | ccn_charbuf_append_string(c,"|"); |
| 520 | |
| 521 | } |
| 522 | hashtb_next(e); |
| 523 | } |
| 524 | |
| 525 | hashtb_end(e); |
| 526 | } |
| 527 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 528 | long int |
| 529 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 530 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 531 | if ( nlsr->debugging ) |
| 532 | printf("get_nbr_time_diff_lsdb_req called\n"); |
| 533 | if ( nlsr->detailed_logging ) |
| 534 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 535 | |
| 536 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 537 | int res; |
| 538 | struct ndn_neighbor *nnbr; |
| 539 | |
| 540 | struct hashtb_enumerator ee; |
| 541 | struct hashtb_enumerator *e = ⅇ |
| 542 | |
| 543 | hashtb_start(nlsr->adl, e); |
| 544 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 545 | |
| 546 | if (res == HT_OLD_ENTRY) |
| 547 | { |
| 548 | nnbr=e->data; |
| 549 | |
| 550 | if (nnbr->last_lsdb_requested == 0) |
| 551 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 552 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 553 | |
| 554 | } |
| 555 | else if(res == HT_NEW_ENTRY) |
| 556 | { |
| 557 | hashtb_delete(e); |
| 558 | } |
| 559 | |
| 560 | hashtb_end(e); |
| 561 | |
| 562 | return time_diff; |
| 563 | } |
| 564 | |
| 565 | long int |
| 566 | get_nbr_last_lsdb_requested(char *nbr) |
| 567 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 568 | if ( nlsr->debugging ) |
| 569 | printf("get_timed_out_number called\n"); |
| 570 | if ( nlsr->detailed_logging ) |
| 571 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 572 | |
| 573 | long int last_lsdb_requested=0; |
| 574 | |
| 575 | int res; |
| 576 | struct ndn_neighbor *nnbr; |
| 577 | |
| 578 | struct hashtb_enumerator ee; |
| 579 | struct hashtb_enumerator *e = ⅇ |
| 580 | |
| 581 | hashtb_start(nlsr->adl, e); |
| 582 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 583 | |
| 584 | if (res == HT_OLD_ENTRY) |
| 585 | { |
| 586 | nnbr=e->data; |
| 587 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 588 | } |
| 589 | else if(res == HT_NEW_ENTRY) |
| 590 | { |
| 591 | hashtb_delete(e); |
| 592 | } |
| 593 | |
| 594 | hashtb_end(e); |
| 595 | |
| 596 | return last_lsdb_requested; |
| 597 | } |
| 598 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 599 | |
| 600 | int |
| 601 | get_nbr_random_time_component(char *nbr) |
| 602 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 603 | if ( nlsr->debugging ) |
| 604 | printf("get_nbr_random_time_component called\n"); |
| 605 | if ( nlsr->detailed_logging ) |
| 606 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 607 | |
| 608 | int time=0; |
| 609 | |
| 610 | int res; |
| 611 | struct ndn_neighbor *nnbr; |
| 612 | |
| 613 | struct hashtb_enumerator ee; |
| 614 | struct hashtb_enumerator *e = ⅇ |
| 615 | |
| 616 | hashtb_start(nlsr->adl, e); |
| 617 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 618 | |
| 619 | if (res == HT_OLD_ENTRY) |
| 620 | { |
| 621 | nnbr=e->data; |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 622 | 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] | 623 | } |
| 624 | else if(res == HT_NEW_ENTRY) |
| 625 | { |
| 626 | hashtb_delete(e); |
| 627 | } |
| 628 | |
| 629 | hashtb_end(e); |
| 630 | |
| 631 | return time; |
| 632 | } |
| 633 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 634 | long int |
| 635 | get_lsdb_synch_interval(char *nbr) |
| 636 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 637 | if ( nlsr->debugging ) |
| 638 | printf("get_lsdb_synch_interval called \n"); |
| 639 | if ( nlsr->detailed_logging ) |
| 640 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 641 | |
| 642 | long int lsdb_synch_interval=300; |
| 643 | |
| 644 | |
| 645 | int res; |
| 646 | struct ndn_neighbor *nnbr; |
| 647 | |
| 648 | struct hashtb_enumerator ee; |
| 649 | struct hashtb_enumerator *e = ⅇ |
| 650 | |
| 651 | hashtb_start(nlsr->adl, e); |
| 652 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 653 | |
| 654 | if (res == HT_OLD_ENTRY) |
| 655 | { |
| 656 | nnbr=e->data; |
| 657 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 658 | } |
| 659 | else if(res == HT_NEW_ENTRY) |
| 660 | { |
| 661 | hashtb_delete(e); |
| 662 | } |
| 663 | |
| 664 | hashtb_end(e); |
| 665 | |
| 666 | return lsdb_synch_interval; |
| 667 | |
| 668 | } |
| 669 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 670 | char * |
| 671 | get_nbr_lsdb_version(char *nbr) |
| 672 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 673 | if ( nlsr->debugging ) |
| 674 | printf("get_nbr_lsdb_version called \n"); |
| 675 | if ( nlsr->detailed_logging ) |
| 676 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 677 | |
| 678 | char *version=NULL; |
| 679 | |
| 680 | int res; |
| 681 | struct ndn_neighbor *nnbr; |
| 682 | |
| 683 | struct hashtb_enumerator ee; |
| 684 | struct hashtb_enumerator *e = ⅇ |
| 685 | |
| 686 | hashtb_start(nlsr->adl, e); |
| 687 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 688 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 689 | if (res == HT_OLD_ENTRY) |
| 690 | { |
| 691 | nnbr=e->data; |
| 692 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 693 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 694 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 695 | } |
| 696 | else if(res == HT_NEW_ENTRY) |
| 697 | { |
| 698 | hashtb_delete(e); |
| 699 | } |
| 700 | |
| 701 | hashtb_end(e); |
| 702 | |
| 703 | return version; |
| 704 | } |
| 705 | |
| 706 | void |
| 707 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 708 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 709 | if ( nlsr->debugging ) |
| 710 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 711 | if ( nlsr->detailed_logging ) |
| 712 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 713 | |
| 714 | int res; |
| 715 | struct ndn_neighbor *nnbr; |
| 716 | |
| 717 | struct hashtb_enumerator ee; |
| 718 | struct hashtb_enumerator *e = ⅇ |
| 719 | |
| 720 | hashtb_start(nlsr->adl, e); |
| 721 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 722 | |
| 723 | if( res == HT_OLD_ENTRY ) |
| 724 | { |
| 725 | nnbr=e->data; |
| 726 | nnbr->last_lsdb_requested=timestamp; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 727 | |
| 728 | } |
| 729 | else if(res == HT_NEW_ENTRY) |
| 730 | { |
| 731 | hashtb_delete(e); |
| 732 | } |
| 733 | |
| 734 | hashtb_end(e); |
| 735 | } |
| 736 | |
| 737 | void |
| 738 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 739 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 740 | if ( nlsr->debugging ) |
| 741 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 742 | if ( nlsr->detailed_logging ) |
| 743 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n"); |
| 744 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 745 | |
| 746 | int res; |
| 747 | struct ndn_neighbor *nnbr; |
| 748 | |
| 749 | struct hashtb_enumerator ee; |
| 750 | struct hashtb_enumerator *e = ⅇ |
| 751 | |
| 752 | hashtb_start(nlsr->adl, e); |
| 753 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 754 | |
| 755 | if (res == HT_OLD_ENTRY) |
| 756 | { |
| 757 | nnbr=e->data; |
| 758 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 759 | } |
| 760 | else if(res == HT_NEW_ENTRY) |
| 761 | { |
| 762 | hashtb_delete(e); |
| 763 | } |
| 764 | |
| 765 | hashtb_end(e); |
| 766 | } |
| 767 | |
| 768 | void |
| 769 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
| 770 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 771 | if ( nlsr->debugging ) |
| 772 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 773 | if ( nlsr->detailed_logging ) |
| 774 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 775 | |
| 776 | int res; |
| 777 | struct ndn_neighbor *nnbr; |
| 778 | |
| 779 | struct hashtb_enumerator ee; |
| 780 | struct hashtb_enumerator *e = ⅇ |
| 781 | |
| 782 | hashtb_start(nlsr->adl, e); |
| 783 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 784 | |
| 785 | if( res == HT_OLD_ENTRY ) |
| 786 | { |
| 787 | nnbr=e->data; |
| 788 | free(nnbr->last_lsdb_version); |
| 789 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 790 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 791 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 792 | } |
| 793 | else if(res == HT_NEW_ENTRY) |
| 794 | { |
| 795 | hashtb_delete(e); |
| 796 | } |
| 797 | |
| 798 | hashtb_end(e); |
| 799 | |
| 800 | } |
| 801 | |
| 802 | void |
| 803 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 804 | { |
| 805 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 806 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 807 | if ( nlsr->debugging ) |
| 808 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 809 | if ( nlsr->detailed_logging ) |
| 810 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n"); |
| 811 | |
| 812 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 813 | int res; |
| 814 | struct ndn_neighbor *nnbr; |
| 815 | |
| 816 | struct hashtb_enumerator ee; |
| 817 | struct hashtb_enumerator *e = ⅇ |
| 818 | |
| 819 | hashtb_start(nlsr->adl, e); |
| 820 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 821 | |
| 822 | if( res == HT_OLD_ENTRY ) |
| 823 | { |
| 824 | nnbr=e->data; |
| 825 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 826 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 827 | } |
| 828 | else if(res == HT_NEW_ENTRY) |
| 829 | { |
| 830 | hashtb_delete(e); |
| 831 | } |
| 832 | |
| 833 | hashtb_end(e); |
| 834 | |
| 835 | } |
| 836 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 837 | int |
| 838 | get_next_hop_face_from_adl(char *nbr) |
| 839 | { |
| 840 | int res; |
| 841 | int connecting_face=NO_FACE; |
| 842 | struct ndn_neighbor *nnbr; |
| 843 | |
| 844 | struct hashtb_enumerator ee; |
| 845 | struct hashtb_enumerator *e = ⅇ |
| 846 | |
| 847 | hashtb_start(nlsr->adl, e); |
| 848 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 849 | |
| 850 | if( res == HT_OLD_ENTRY ) |
| 851 | { |
| 852 | nnbr=e->data; |
| 853 | connecting_face=nnbr->face; |
| 854 | |
| 855 | } |
| 856 | else if(res == HT_NEW_ENTRY) |
| 857 | { |
| 858 | hashtb_delete(e); |
| 859 | } |
| 860 | |
| 861 | hashtb_end(e); |
| 862 | return connecting_face; |
| 863 | } |
| 864 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 865 | int |
| 866 | is_neighbor(char *nbr) |
| 867 | { |
| 868 | int ret=0; |
| 869 | |
| 870 | int res; |
| 871 | struct hashtb_enumerator ee; |
| 872 | struct hashtb_enumerator *e = ⅇ |
| 873 | |
| 874 | hashtb_start(nlsr->adl, e); |
| 875 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 876 | |
| 877 | if( res == HT_OLD_ENTRY ) |
| 878 | { |
| 879 | ret=1; |
| 880 | } |
| 881 | else if(res == HT_NEW_ENTRY) |
| 882 | { |
| 883 | hashtb_delete(e); |
| 884 | } |
| 885 | |
| 886 | hashtb_end(e); |
| 887 | |
| 888 | return ret; |
| 889 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 890 | |