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