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 | 8876e98 | 2013-02-21 13:35:46 -0600 | [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 | 018692c | 2013-02-11 11:33:39 -0600 | [diff] [blame] | 61 | nbr->ip_address=(char *)malloc(strlen(ip)+1); |
| 62 | memset(nbr->ip_address,0,strlen(ip)+1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 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 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 538 | /*char *temp_face=(char *)malloc(20); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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,"|"); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 544 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 545 | |
| 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 | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 560 | long int |
| 561 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 562 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 563 | if ( nlsr->debugging ) |
| 564 | printf("get_nbr_time_diff_lsdb_req called\n"); |
| 565 | if ( nlsr->detailed_logging ) |
| 566 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 567 | |
| 568 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 569 | int res; |
| 570 | struct ndn_neighbor *nnbr; |
| 571 | |
| 572 | struct hashtb_enumerator ee; |
| 573 | struct hashtb_enumerator *e = ⅇ |
| 574 | |
| 575 | hashtb_start(nlsr->adl, e); |
| 576 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 577 | |
| 578 | if (res == HT_OLD_ENTRY) |
| 579 | { |
| 580 | nnbr=e->data; |
| 581 | |
| 582 | if (nnbr->last_lsdb_requested == 0) |
| 583 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 584 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 585 | |
| 586 | } |
| 587 | else if(res == HT_NEW_ENTRY) |
| 588 | { |
| 589 | hashtb_delete(e); |
| 590 | } |
| 591 | |
| 592 | hashtb_end(e); |
| 593 | |
| 594 | return time_diff; |
| 595 | } |
| 596 | |
| 597 | long int |
| 598 | get_nbr_last_lsdb_requested(char *nbr) |
| 599 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 600 | if ( nlsr->debugging ) |
| 601 | printf("get_timed_out_number called\n"); |
| 602 | if ( nlsr->detailed_logging ) |
| 603 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 604 | |
| 605 | long int last_lsdb_requested=0; |
| 606 | |
| 607 | int res; |
| 608 | struct ndn_neighbor *nnbr; |
| 609 | |
| 610 | struct hashtb_enumerator ee; |
| 611 | struct hashtb_enumerator *e = ⅇ |
| 612 | |
| 613 | hashtb_start(nlsr->adl, e); |
| 614 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 615 | |
| 616 | if (res == HT_OLD_ENTRY) |
| 617 | { |
| 618 | nnbr=e->data; |
| 619 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 620 | } |
| 621 | else if(res == HT_NEW_ENTRY) |
| 622 | { |
| 623 | hashtb_delete(e); |
| 624 | } |
| 625 | |
| 626 | hashtb_end(e); |
| 627 | |
| 628 | return last_lsdb_requested; |
| 629 | } |
| 630 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 631 | |
| 632 | int |
| 633 | get_nbr_random_time_component(char *nbr) |
| 634 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 635 | if ( nlsr->debugging ) |
| 636 | printf("get_nbr_random_time_component called\n"); |
| 637 | if ( nlsr->detailed_logging ) |
| 638 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 639 | |
| 640 | int time=0; |
| 641 | |
| 642 | int res; |
| 643 | struct ndn_neighbor *nnbr; |
| 644 | |
| 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 | nnbr=e->data; |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 654 | 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] | 655 | } |
| 656 | else if(res == HT_NEW_ENTRY) |
| 657 | { |
| 658 | hashtb_delete(e); |
| 659 | } |
| 660 | |
| 661 | hashtb_end(e); |
| 662 | |
| 663 | return time; |
| 664 | } |
| 665 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 666 | long int |
| 667 | get_lsdb_synch_interval(char *nbr) |
| 668 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 669 | if ( nlsr->debugging ) |
| 670 | printf("get_lsdb_synch_interval called \n"); |
| 671 | if ( nlsr->detailed_logging ) |
| 672 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 673 | |
| 674 | long int lsdb_synch_interval=300; |
| 675 | |
| 676 | |
| 677 | int res; |
| 678 | struct ndn_neighbor *nnbr; |
| 679 | |
| 680 | struct hashtb_enumerator ee; |
| 681 | struct hashtb_enumerator *e = ⅇ |
| 682 | |
| 683 | hashtb_start(nlsr->adl, e); |
| 684 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 685 | |
| 686 | if (res == HT_OLD_ENTRY) |
| 687 | { |
| 688 | nnbr=e->data; |
| 689 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 690 | } |
| 691 | else if(res == HT_NEW_ENTRY) |
| 692 | { |
| 693 | hashtb_delete(e); |
| 694 | } |
| 695 | |
| 696 | hashtb_end(e); |
| 697 | |
| 698 | return lsdb_synch_interval; |
| 699 | |
| 700 | } |
| 701 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 702 | char * |
| 703 | get_nbr_lsdb_version(char *nbr) |
| 704 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 705 | if ( nlsr->debugging ) |
| 706 | printf("get_nbr_lsdb_version called \n"); |
| 707 | if ( nlsr->detailed_logging ) |
| 708 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 709 | |
| 710 | char *version=NULL; |
| 711 | |
| 712 | int res; |
| 713 | struct ndn_neighbor *nnbr; |
| 714 | |
| 715 | struct hashtb_enumerator ee; |
| 716 | struct hashtb_enumerator *e = ⅇ |
| 717 | |
| 718 | hashtb_start(nlsr->adl, e); |
| 719 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 720 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 721 | if (res == HT_OLD_ENTRY) |
| 722 | { |
| 723 | nnbr=e->data; |
| 724 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 725 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 726 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 727 | } |
| 728 | else if(res == HT_NEW_ENTRY) |
| 729 | { |
| 730 | hashtb_delete(e); |
| 731 | } |
| 732 | |
| 733 | hashtb_end(e); |
| 734 | |
| 735 | return version; |
| 736 | } |
| 737 | |
| 738 | void |
| 739 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 740 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 741 | if ( nlsr->debugging ) |
| 742 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 743 | if ( nlsr->detailed_logging ) |
| 744 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 745 | |
| 746 | int res; |
| 747 | struct ndn_neighbor *nnbr; |
| 748 | |
| 749 | struct hashtb_enumerator ee; |
| 750 | struct hashtb_enumerator *e = ⅇ |
| 751 | |
| 752 | hashtb_start(nlsr->adl, e); |
| 753 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 754 | |
| 755 | if( res == HT_OLD_ENTRY ) |
| 756 | { |
| 757 | nnbr=e->data; |
| 758 | nnbr->last_lsdb_requested=timestamp; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 759 | |
| 760 | } |
| 761 | else if(res == HT_NEW_ENTRY) |
| 762 | { |
| 763 | hashtb_delete(e); |
| 764 | } |
| 765 | |
| 766 | hashtb_end(e); |
| 767 | } |
| 768 | |
| 769 | void |
| 770 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 771 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 772 | if ( nlsr->debugging ) |
| 773 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 774 | if ( nlsr->detailed_logging ) |
| 775 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n"); |
| 776 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 777 | |
| 778 | int res; |
| 779 | struct ndn_neighbor *nnbr; |
| 780 | |
| 781 | struct hashtb_enumerator ee; |
| 782 | struct hashtb_enumerator *e = ⅇ |
| 783 | |
| 784 | hashtb_start(nlsr->adl, e); |
| 785 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 786 | |
| 787 | if (res == HT_OLD_ENTRY) |
| 788 | { |
| 789 | nnbr=e->data; |
| 790 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 791 | } |
| 792 | else if(res == HT_NEW_ENTRY) |
| 793 | { |
| 794 | hashtb_delete(e); |
| 795 | } |
| 796 | |
| 797 | hashtb_end(e); |
| 798 | } |
| 799 | |
| 800 | void |
| 801 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
| 802 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 803 | if ( nlsr->debugging ) |
| 804 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 805 | if ( nlsr->detailed_logging ) |
| 806 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 807 | |
| 808 | int res; |
| 809 | struct ndn_neighbor *nnbr; |
| 810 | |
| 811 | struct hashtb_enumerator ee; |
| 812 | struct hashtb_enumerator *e = ⅇ |
| 813 | |
| 814 | hashtb_start(nlsr->adl, e); |
| 815 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 816 | |
| 817 | if( res == HT_OLD_ENTRY ) |
| 818 | { |
| 819 | nnbr=e->data; |
| 820 | free(nnbr->last_lsdb_version); |
| 821 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 822 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 823 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 824 | } |
| 825 | else if(res == HT_NEW_ENTRY) |
| 826 | { |
| 827 | hashtb_delete(e); |
| 828 | } |
| 829 | |
| 830 | hashtb_end(e); |
| 831 | |
| 832 | } |
| 833 | |
| 834 | void |
| 835 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 836 | { |
| 837 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 838 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 839 | if ( nlsr->debugging ) |
| 840 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 841 | if ( nlsr->detailed_logging ) |
| 842 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n"); |
| 843 | |
| 844 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 845 | int res; |
| 846 | struct ndn_neighbor *nnbr; |
| 847 | |
| 848 | struct hashtb_enumerator ee; |
| 849 | struct hashtb_enumerator *e = ⅇ |
| 850 | |
| 851 | hashtb_start(nlsr->adl, e); |
| 852 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 853 | |
| 854 | if( res == HT_OLD_ENTRY ) |
| 855 | { |
| 856 | nnbr=e->data; |
| 857 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 858 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 859 | } |
| 860 | else if(res == HT_NEW_ENTRY) |
| 861 | { |
| 862 | hashtb_delete(e); |
| 863 | } |
| 864 | |
| 865 | hashtb_end(e); |
| 866 | |
| 867 | } |
| 868 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 869 | int |
| 870 | get_next_hop_face_from_adl(char *nbr) |
| 871 | { |
| 872 | int res; |
| 873 | int connecting_face=NO_FACE; |
| 874 | struct ndn_neighbor *nnbr; |
| 875 | |
| 876 | struct hashtb_enumerator ee; |
| 877 | struct hashtb_enumerator *e = ⅇ |
| 878 | |
| 879 | hashtb_start(nlsr->adl, e); |
| 880 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 881 | |
| 882 | if( res == HT_OLD_ENTRY ) |
| 883 | { |
| 884 | nnbr=e->data; |
| 885 | connecting_face=nnbr->face; |
| 886 | |
| 887 | } |
| 888 | else if(res == HT_NEW_ENTRY) |
| 889 | { |
| 890 | hashtb_delete(e); |
| 891 | } |
| 892 | |
| 893 | hashtb_end(e); |
| 894 | return connecting_face; |
| 895 | } |
| 896 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 897 | void |
| 898 | update_face_to_adl_for_nbr(char *nbr, int face) |
| 899 | { |
| 900 | int res; |
| 901 | struct ndn_neighbor *nnbr; |
| 902 | |
| 903 | struct hashtb_enumerator ee; |
| 904 | struct hashtb_enumerator *e = ⅇ |
| 905 | |
| 906 | hashtb_start(nlsr->adl, e); |
| 907 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 908 | |
| 909 | if( res == HT_OLD_ENTRY ) |
| 910 | { |
| 911 | nnbr=e->data; |
| 912 | nnbr->face=face; |
| 913 | |
| 914 | } |
| 915 | else if(res == HT_NEW_ENTRY) |
| 916 | { |
| 917 | hashtb_delete(e); |
| 918 | } |
| 919 | |
| 920 | hashtb_end(e); |
| 921 | } |
| 922 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 923 | int |
| 924 | is_neighbor(char *nbr) |
| 925 | { |
| 926 | int ret=0; |
| 927 | |
| 928 | int res; |
| 929 | struct hashtb_enumerator ee; |
| 930 | struct hashtb_enumerator *e = ⅇ |
| 931 | |
| 932 | hashtb_start(nlsr->adl, e); |
| 933 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 934 | |
| 935 | if( res == HT_OLD_ENTRY ) |
| 936 | { |
| 937 | ret=1; |
| 938 | } |
| 939 | else if(res == HT_NEW_ENTRY) |
| 940 | { |
| 941 | hashtb_delete(e); |
| 942 | } |
| 943 | |
| 944 | hashtb_end(e); |
| 945 | |
| 946 | return ret; |
| 947 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 948 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 949 | int |
| 950 | is_active_neighbor(char *nbr) |
| 951 | { |
| 952 | int ret=0; |
| 953 | |
| 954 | int res; |
| 955 | struct hashtb_enumerator ee; |
| 956 | struct hashtb_enumerator *e = ⅇ |
| 957 | |
| 958 | hashtb_start(nlsr->adl, e); |
| 959 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 960 | |
| 961 | if( res == HT_OLD_ENTRY ) |
| 962 | { |
| 963 | struct ndn_neighbor *nnbr; |
| 964 | nnbr=e->data; |
| 965 | if (nnbr->status == NBR_ACTIVE ) |
| 966 | { |
| 967 | ret=1; |
| 968 | } |
| 969 | } |
| 970 | else if(res == HT_NEW_ENTRY) |
| 971 | { |
| 972 | hashtb_delete(e); |
| 973 | } |
| 974 | |
| 975 | hashtb_end(e); |
| 976 | |
| 977 | return ret; |
| 978 | } |
| 979 | |
akmhoque | ccb33e9 | 2013-02-20 11:44:28 -0600 | [diff] [blame] | 980 | |
| 981 | void |
| 982 | get_host_name_from_command_string(struct name_prefix *name_part, |
| 983 | char *nbr_name_uri, int offset) |
| 984 | { |
| 985 | |
| 986 | |
| 987 | |
| 988 | int res,i; |
| 989 | int len=0; |
| 990 | const unsigned char *comp_ptr1; |
| 991 | size_t comp_size; |
| 992 | |
| 993 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 994 | name = ccn_charbuf_create(); |
| 995 | res = ccn_name_from_uri(name,nbr_name_uri); |
| 996 | if (res < 0) { |
| 997 | fprintf(stderr, "Bad ccn URI: %s\n", nbr_name_uri); |
| 998 | exit(1); |
| 999 | } |
| 1000 | |
| 1001 | struct ccn_indexbuf cid={0}; |
| 1002 | |
| 1003 | struct ccn_indexbuf *components=&cid; |
| 1004 | ccn_name_split (name, components); |
| 1005 | |
| 1006 | for(i=components->n-2;i> (0+offset);i--) |
| 1007 | { |
| 1008 | res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size); |
| 1009 | len+=1; |
| 1010 | len+=(int)comp_size; |
| 1011 | } |
| 1012 | len++; |
| 1013 | |
| 1014 | char *neighbor=(char *)malloc(len); |
| 1015 | memset(neighbor,0,len); |
| 1016 | |
| 1017 | for(i=components->n-2;i> (0+offset);i--) |
| 1018 | { |
| 1019 | res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size); |
| 1020 | if ( i != components->n-2) |
| 1021 | memcpy(neighbor+strlen(neighbor),".",1); |
| 1022 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1, |
| 1023 | strlen((char *)comp_ptr1)); |
| 1024 | |
| 1025 | } |
| 1026 | |
| 1027 | name_part->name=(char *)malloc(strlen(neighbor)+1); |
| 1028 | memset(name_part->name,0,strlen(neighbor)+1); |
| 1029 | memcpy(name_part->name,neighbor,strlen(neighbor)+1); |
| 1030 | name_part->length=strlen(neighbor)+1; |
| 1031 | |
| 1032 | // 01/31/2013 |
| 1033 | free(neighbor); |
| 1034 | ccn_charbuf_destroy(&name); |
| 1035 | } |
| 1036 | |
| 1037 | |