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