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