akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | |
| 12 | |
| 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
| 19 | |
| 20 | #include "nlsr.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 21 | #include "nlsr_npl.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 22 | #include "nlsr_adl.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 23 | #include "utility.h" |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 24 | #include "nlsr_npt.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 25 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 26 | void |
| 27 | add_nbr_to_adl(struct name_prefix *new_nbr,int face) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 28 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 29 | struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 30 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 31 | struct hashtb_enumerator ee; |
| 32 | struct hashtb_enumerator *e = ⅇ |
| 33 | int res; |
| 34 | |
| 35 | hashtb_start(nlsr->adl, e); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 36 | res = hashtb_seek(e, new_nbr->name, new_nbr->length, 0); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 37 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 38 | if(res == HT_NEW_ENTRY ) |
| 39 | { |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 40 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 41 | nbr = e->data; |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 42 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 43 | nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free |
| 44 | nbr->neighbor->name=(char *)malloc(new_nbr->length); |
| 45 | memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length); |
| 46 | nbr->neighbor->length=new_nbr->length; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 47 | nbr->face=face; |
| 48 | nbr->status=NBR_DOWN; |
| 49 | nbr->info_interest_timed_out=0; |
| 50 | nbr->lsdb_synch_interval=300; |
| 51 | nbr->metric=10; |
| 52 | nbr->is_lsdb_send_interest_scheduled=0; |
| 53 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 54 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 55 | char *time_stamp=(char *)malloc(20); |
| 56 | get_current_timestamp_micro(time_stamp); |
| 57 | nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 58 | memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1); |
| 59 | memset(nbr->last_lsdb_version,'0',strlen(time_stamp)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 60 | nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free |
| 61 | memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1); |
| 62 | memset(nbr->last_info_version,'0',strlen(time_stamp)); |
| 63 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 64 | |
| 65 | nbr->last_lsdb_requested=0; |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 66 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 67 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 68 | hashtb_end(e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 69 | } |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 70 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 71 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 72 | void |
| 73 | print_adjacent(struct ndn_neighbor *nbr) |
| 74 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 75 | printf("print_adjacent called\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 76 | printf("--------Neighbor---------------------------\n"); |
| 77 | printf(" Neighbor: %s \n",nbr->neighbor->name); |
| 78 | printf(" Length : %d \n",nbr->neighbor->length); |
| 79 | printf(" Face : %d \n",nbr->face); |
| 80 | printf(" Metric : %d \n",nbr->metric); |
| 81 | printf(" Status : %d \n",nbr->status); |
| 82 | printf(" LSDB Version: %s \n",nbr->last_lsdb_version); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 83 | printf(" Info Version: %s \n",nbr->last_info_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 84 | printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out); |
| 85 | printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval); |
| 86 | printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 87 | printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled); |
| 88 | |
| 89 | printf("\n"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 90 | |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | print_adjacent_from_adl(void) |
| 95 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 96 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 97 | printf("print_adjacent_from_adl called \n"); |
| 98 | int i, adl_element; |
| 99 | struct ndn_neighbor *nbr; |
| 100 | |
| 101 | struct hashtb_enumerator ee; |
| 102 | struct hashtb_enumerator *e = ⅇ |
| 103 | |
| 104 | hashtb_start(nlsr->adl, e); |
| 105 | adl_element=hashtb_n(nlsr->adl); |
| 106 | |
| 107 | for(i=0;i<adl_element;i++) |
| 108 | { |
| 109 | nbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 110 | print_adjacent(nbr); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 111 | hashtb_next(e); |
| 112 | } |
| 113 | |
| 114 | hashtb_end(e); |
| 115 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 116 | } |
| 117 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 118 | int |
| 119 | get_adjacent_status(struct name_prefix *nbr) |
| 120 | { |
| 121 | printf("get_adjacent_status called \n"); |
| 122 | |
| 123 | int res; |
| 124 | int status=-1; |
| 125 | struct ndn_neighbor *nnbr; |
| 126 | |
| 127 | struct hashtb_enumerator ee; |
| 128 | struct hashtb_enumerator *e = ⅇ |
| 129 | |
| 130 | hashtb_start(nlsr->adl, e); |
| 131 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 132 | |
| 133 | if (res == HT_OLD_ENTRY) |
| 134 | { |
| 135 | nnbr=e->data; |
| 136 | status=nnbr->status; |
| 137 | } |
| 138 | else if(res == HT_NEW_ENTRY) |
| 139 | { |
| 140 | hashtb_delete(e); |
| 141 | } |
| 142 | |
| 143 | hashtb_end(e); |
| 144 | |
| 145 | return status; |
| 146 | |
| 147 | } |
| 148 | |
| 149 | int |
| 150 | get_timed_out_number(struct name_prefix *nbr) |
| 151 | { |
| 152 | printf("get_timed_out_number called \n"); |
| 153 | |
| 154 | int res,ret=-1; |
| 155 | struct ndn_neighbor *nnbr; |
| 156 | |
| 157 | struct hashtb_enumerator ee; |
| 158 | struct hashtb_enumerator *e = ⅇ |
| 159 | |
| 160 | hashtb_start(nlsr->adl, e); |
| 161 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 162 | |
| 163 | if( res == HT_OLD_ENTRY ) |
| 164 | { |
| 165 | nnbr=e->data; |
| 166 | ret=nnbr->info_interest_timed_out; |
| 167 | } |
| 168 | else if(res == HT_NEW_ENTRY) |
| 169 | { |
| 170 | hashtb_delete(e); |
| 171 | } |
| 172 | |
| 173 | hashtb_end(e); |
| 174 | |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | void |
| 180 | update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment) |
| 181 | { |
| 182 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 183 | |
| 184 | int res; |
| 185 | struct ndn_neighbor *nnbr; |
| 186 | |
| 187 | struct hashtb_enumerator ee; |
| 188 | struct hashtb_enumerator *e = ⅇ |
| 189 | |
| 190 | hashtb_start(nlsr->adl, e); |
| 191 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 192 | |
| 193 | if( res == HT_OLD_ENTRY ) |
| 194 | { |
| 195 | nnbr=e->data; |
| 196 | nnbr->info_interest_timed_out += increment; |
| 197 | } |
| 198 | else if(res == HT_NEW_ENTRY) |
| 199 | { |
| 200 | hashtb_delete(e); |
| 201 | } |
| 202 | |
| 203 | hashtb_end(e); |
| 204 | } |
| 205 | |
| 206 | void |
| 207 | update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr) |
| 208 | { |
| 209 | printf("update_adjacent_timed_out_zero_to_adl called \n"); |
| 210 | int time_out_number=get_timed_out_number(nbr); |
| 211 | update_adjacent_timed_out_to_adl(nbr,-time_out_number); |
| 212 | |
| 213 | } |
| 214 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 215 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 216 | update_adjacent_status_to_adl(struct name_prefix *nbr, int status) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 217 | { |
| 218 | printf("update_adjacent_status_to_adl called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 219 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 220 | int res; |
| 221 | struct ndn_neighbor *nnbr; |
| 222 | |
| 223 | struct hashtb_enumerator ee; |
| 224 | struct hashtb_enumerator *e = ⅇ |
| 225 | |
| 226 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 227 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 228 | |
akmhoque | 918ff9a | 2012-08-21 11:34:49 -0400 | [diff] [blame] | 229 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 230 | if (res == HT_OLD_ENTRY) |
| 231 | { |
| 232 | nnbr=e->data; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 233 | if ( nnbr->status!=status ) |
| 234 | { |
| 235 | nnbr->status=status; |
| 236 | nlsr->adj_build_flag++; |
| 237 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 238 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 239 | else if(res == HT_NEW_ENTRY) |
| 240 | { |
| 241 | hashtb_delete(e); |
| 242 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 243 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 244 | hashtb_end(e); |
| 245 | } |
| 246 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 247 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 248 | update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 249 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 250 | printf("uupdate_lsdb_synch_interval_to_adl called \n"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 251 | |
| 252 | int res; |
| 253 | struct ndn_neighbor *nnbr; |
| 254 | |
| 255 | struct hashtb_enumerator ee; |
| 256 | struct hashtb_enumerator *e = ⅇ |
| 257 | |
| 258 | hashtb_start(nlsr->adl, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 259 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 260 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 261 | |
| 262 | if (res == HT_OLD_ENTRY) |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 263 | { |
| 264 | nnbr=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 265 | if ( nnbr->lsdb_synch_interval!= interval ) |
| 266 | { |
| 267 | nnbr->lsdb_synch_interval=interval; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 268 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 269 | } |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 270 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 271 | else if(res == HT_NEW_ENTRY) |
| 272 | { |
| 273 | hashtb_delete(e); |
| 274 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 275 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 276 | hashtb_end(e); |
| 277 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 278 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 279 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 280 | int |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 281 | no_active_nbr(void) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 282 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 283 | int i, adl_element; |
| 284 | int no_link=0; |
| 285 | struct ndn_neighbor *nbr; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 286 | struct hashtb_enumerator ee; |
| 287 | struct hashtb_enumerator *e = ⅇ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 288 | hashtb_start(nlsr->adl, e); |
| 289 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 290 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 291 | for(i=0;i<adl_element;i++) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 292 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 293 | nbr=e->data; |
| 294 | if( nbr->status == 1 ) |
| 295 | no_link++; |
| 296 | hashtb_next(e); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 297 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 298 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 299 | hashtb_end(e); |
| 300 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 301 | return no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 302 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 303 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 304 | |
| 305 | int |
| 306 | is_adj_lsa_build(void) |
| 307 | { |
| 308 | int ret=0; |
| 309 | |
| 310 | int nbr_count=0; |
| 311 | |
| 312 | int i, adl_element; |
| 313 | struct ndn_neighbor *nbr; |
| 314 | |
| 315 | struct hashtb_enumerator ee; |
| 316 | struct hashtb_enumerator *e = ⅇ |
| 317 | |
| 318 | hashtb_start(nlsr->adl, e); |
| 319 | adl_element=hashtb_n(nlsr->adl); |
| 320 | |
| 321 | for(i=0;i<adl_element;i++) |
| 322 | { |
| 323 | nbr=e->data; |
| 324 | if(nbr->status == 1 ) |
| 325 | { |
| 326 | nbr_count++; |
| 327 | } |
| 328 | else if (nbr->info_interest_timed_out >= nlsr->interest_retry) |
| 329 | { |
| 330 | nbr_count++; |
| 331 | } |
| 332 | hashtb_next(e); |
| 333 | } |
| 334 | |
| 335 | hashtb_end(e); |
| 336 | if(nbr_count == adl_element) |
| 337 | ret=1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 338 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 339 | return ret; |
| 340 | } |
| 341 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 342 | |
| 343 | void |
| 344 | get_active_nbr_adj_data(struct ccn_charbuf *c) |
| 345 | { |
| 346 | |
| 347 | int i, adl_element; |
| 348 | struct ndn_neighbor *nbr; |
| 349 | struct hashtb_enumerator ee; |
| 350 | struct hashtb_enumerator *e = ⅇ |
| 351 | hashtb_start(nlsr->adl, e); |
| 352 | adl_element=hashtb_n(nlsr->adl); |
| 353 | |
| 354 | for(i=0;i<adl_element;i++) |
| 355 | { |
| 356 | nbr=e->data; |
| 357 | if( nbr->status == 1 ) |
| 358 | { |
| 359 | ccn_charbuf_append_string(c,nbr->neighbor->name); |
| 360 | ccn_charbuf_append_string(c,"|"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 361 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 362 | char *temp_length=(char *)malloc(20); |
| 363 | memset(temp_length,0,20); |
| 364 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 365 | ccn_charbuf_append_string(c,temp_length); |
| 366 | free(temp_length); |
| 367 | ccn_charbuf_append_string(c,"|"); |
| 368 | |
| 369 | char *temp_face=(char *)malloc(20); |
| 370 | memset(temp_face,0,20); |
| 371 | sprintf(temp_face,"%d",nbr->face); |
| 372 | ccn_charbuf_append_string(c,temp_face); |
| 373 | free(temp_face); |
| 374 | ccn_charbuf_append_string(c,"|"); |
| 375 | |
| 376 | char *temp_metric=(char *)malloc(20); |
| 377 | memset(temp_metric,0,20); |
| 378 | sprintf(temp_metric,"%d",nbr->metric); |
| 379 | ccn_charbuf_append_string(c,temp_metric); |
| 380 | free(temp_metric); |
| 381 | ccn_charbuf_append_string(c,"|"); |
| 382 | |
| 383 | } |
| 384 | hashtb_next(e); |
| 385 | } |
| 386 | |
| 387 | hashtb_end(e); |
| 388 | } |
| 389 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 390 | long int |
| 391 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 392 | { |
| 393 | printf("get_nbr_time_diff_lsdb_req called \n"); |
| 394 | |
| 395 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 396 | int res; |
| 397 | struct ndn_neighbor *nnbr; |
| 398 | |
| 399 | struct hashtb_enumerator ee; |
| 400 | struct hashtb_enumerator *e = ⅇ |
| 401 | |
| 402 | hashtb_start(nlsr->adl, e); |
| 403 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 404 | |
| 405 | if (res == HT_OLD_ENTRY) |
| 406 | { |
| 407 | nnbr=e->data; |
| 408 | |
| 409 | if (nnbr->last_lsdb_requested == 0) |
| 410 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 411 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 412 | |
| 413 | } |
| 414 | else if(res == HT_NEW_ENTRY) |
| 415 | { |
| 416 | hashtb_delete(e); |
| 417 | } |
| 418 | |
| 419 | hashtb_end(e); |
| 420 | |
| 421 | return time_diff; |
| 422 | } |
| 423 | |
| 424 | long int |
| 425 | get_nbr_last_lsdb_requested(char *nbr) |
| 426 | { |
| 427 | printf("get_timed_out_number called \n"); |
| 428 | |
| 429 | long int last_lsdb_requested=0; |
| 430 | |
| 431 | int res; |
| 432 | struct ndn_neighbor *nnbr; |
| 433 | |
| 434 | struct hashtb_enumerator ee; |
| 435 | struct hashtb_enumerator *e = ⅇ |
| 436 | |
| 437 | hashtb_start(nlsr->adl, e); |
| 438 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 439 | |
| 440 | if (res == HT_OLD_ENTRY) |
| 441 | { |
| 442 | nnbr=e->data; |
| 443 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 444 | } |
| 445 | else if(res == HT_NEW_ENTRY) |
| 446 | { |
| 447 | hashtb_delete(e); |
| 448 | } |
| 449 | |
| 450 | hashtb_end(e); |
| 451 | |
| 452 | return last_lsdb_requested; |
| 453 | } |
| 454 | |
| 455 | long int |
| 456 | get_lsdb_synch_interval(char *nbr) |
| 457 | { |
| 458 | printf("get_lsdb_synch_interval called \n"); |
| 459 | |
| 460 | long int lsdb_synch_interval=300; |
| 461 | |
| 462 | |
| 463 | int res; |
| 464 | struct ndn_neighbor *nnbr; |
| 465 | |
| 466 | struct hashtb_enumerator ee; |
| 467 | struct hashtb_enumerator *e = ⅇ |
| 468 | |
| 469 | hashtb_start(nlsr->adl, e); |
| 470 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 471 | |
| 472 | if (res == HT_OLD_ENTRY) |
| 473 | { |
| 474 | nnbr=e->data; |
| 475 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 476 | } |
| 477 | else if(res == HT_NEW_ENTRY) |
| 478 | { |
| 479 | hashtb_delete(e); |
| 480 | } |
| 481 | |
| 482 | hashtb_end(e); |
| 483 | |
| 484 | return lsdb_synch_interval; |
| 485 | |
| 486 | } |
| 487 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 488 | char * |
| 489 | get_nbr_lsdb_version(char *nbr) |
| 490 | { |
| 491 | printf("get_timed_out_number called \n"); |
| 492 | |
| 493 | char *version=NULL; |
| 494 | |
| 495 | int res; |
| 496 | struct ndn_neighbor *nnbr; |
| 497 | |
| 498 | struct hashtb_enumerator ee; |
| 499 | struct hashtb_enumerator *e = ⅇ |
| 500 | |
| 501 | hashtb_start(nlsr->adl, e); |
| 502 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 503 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 504 | if (res == HT_OLD_ENTRY) |
| 505 | { |
| 506 | nnbr=e->data; |
| 507 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 508 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 509 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 510 | } |
| 511 | else if(res == HT_NEW_ENTRY) |
| 512 | { |
| 513 | hashtb_delete(e); |
| 514 | } |
| 515 | |
| 516 | hashtb_end(e); |
| 517 | |
| 518 | return version; |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 523 | { |
| 524 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 525 | |
| 526 | int res; |
| 527 | struct ndn_neighbor *nnbr; |
| 528 | |
| 529 | struct hashtb_enumerator ee; |
| 530 | struct hashtb_enumerator *e = ⅇ |
| 531 | |
| 532 | hashtb_start(nlsr->adl, e); |
| 533 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 534 | |
| 535 | if( res == HT_OLD_ENTRY ) |
| 536 | { |
| 537 | nnbr=e->data; |
| 538 | nnbr->last_lsdb_requested=timestamp; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 539 | |
| 540 | } |
| 541 | else if(res == HT_NEW_ENTRY) |
| 542 | { |
| 543 | hashtb_delete(e); |
| 544 | } |
| 545 | |
| 546 | hashtb_end(e); |
| 547 | } |
| 548 | |
| 549 | void |
| 550 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 551 | { |
| 552 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 553 | |
| 554 | int res; |
| 555 | struct ndn_neighbor *nnbr; |
| 556 | |
| 557 | struct hashtb_enumerator ee; |
| 558 | struct hashtb_enumerator *e = ⅇ |
| 559 | |
| 560 | hashtb_start(nlsr->adl, e); |
| 561 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 562 | |
| 563 | if (res == HT_OLD_ENTRY) |
| 564 | { |
| 565 | nnbr=e->data; |
| 566 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 567 | } |
| 568 | else if(res == HT_NEW_ENTRY) |
| 569 | { |
| 570 | hashtb_delete(e); |
| 571 | } |
| 572 | |
| 573 | hashtb_end(e); |
| 574 | } |
| 575 | |
| 576 | void |
| 577 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
| 578 | { |
| 579 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 580 | |
| 581 | int res; |
| 582 | struct ndn_neighbor *nnbr; |
| 583 | |
| 584 | struct hashtb_enumerator ee; |
| 585 | struct hashtb_enumerator *e = ⅇ |
| 586 | |
| 587 | hashtb_start(nlsr->adl, e); |
| 588 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 589 | |
| 590 | if( res == HT_OLD_ENTRY ) |
| 591 | { |
| 592 | nnbr=e->data; |
| 593 | free(nnbr->last_lsdb_version); |
| 594 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 595 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 596 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 597 | } |
| 598 | else if(res == HT_NEW_ENTRY) |
| 599 | { |
| 600 | hashtb_delete(e); |
| 601 | } |
| 602 | |
| 603 | hashtb_end(e); |
| 604 | |
| 605 | } |
| 606 | |
| 607 | void |
| 608 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 609 | { |
| 610 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 611 | |
| 612 | int res; |
| 613 | struct ndn_neighbor *nnbr; |
| 614 | |
| 615 | struct hashtb_enumerator ee; |
| 616 | struct hashtb_enumerator *e = ⅇ |
| 617 | |
| 618 | hashtb_start(nlsr->adl, e); |
| 619 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 620 | |
| 621 | if( res == HT_OLD_ENTRY ) |
| 622 | { |
| 623 | nnbr=e->data; |
| 624 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 625 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 626 | } |
| 627 | else if(res == HT_NEW_ENTRY) |
| 628 | { |
| 629 | hashtb_delete(e); |
| 630 | } |
| 631 | |
| 632 | hashtb_end(e); |
| 633 | |
| 634 | } |
| 635 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 636 | int |
| 637 | get_next_hop_face_from_adl(char *nbr) |
| 638 | { |
| 639 | int res; |
| 640 | int connecting_face=NO_FACE; |
| 641 | struct ndn_neighbor *nnbr; |
| 642 | |
| 643 | struct hashtb_enumerator ee; |
| 644 | struct hashtb_enumerator *e = ⅇ |
| 645 | |
| 646 | hashtb_start(nlsr->adl, e); |
| 647 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 648 | |
| 649 | if( res == HT_OLD_ENTRY ) |
| 650 | { |
| 651 | nnbr=e->data; |
| 652 | connecting_face=nnbr->face; |
| 653 | |
| 654 | } |
| 655 | else if(res == HT_NEW_ENTRY) |
| 656 | { |
| 657 | hashtb_delete(e); |
| 658 | } |
| 659 | |
| 660 | hashtb_end(e); |
| 661 | return connecting_face; |
| 662 | } |
| 663 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 664 | |