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