akmhoque | 59980a5 | 2012-08-09 12:36:09 -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" |
| 21 | #include "nlsr_ndn.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 22 | #include "nlsr_npl.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 23 | #include "nlsr_adl.h" |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 24 | #include "nlsr_lsdb.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 25 | #include "utility.h" |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 26 | #include "nlsr_km.h" |
| 27 | #include "nlsr_km_util.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 28 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 29 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 30 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 31 | /** |
| 32 | * get neighbor name prefix from interest/content name and put into nbr |
| 33 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 34 | |
| 35 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 36 | get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, |
| 37 | struct ccn_upcall_info *info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 38 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 39 | if ( nlsr->debugging ) |
| 40 | printf("get_nbr called\n"); |
| 41 | if ( nlsr->detailed_logging ) |
| 42 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr called\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 43 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 44 | int res,i; |
| 45 | int nlsr_position=0; |
| 46 | int name_comps=(int)info->interest_comps->n; |
| 47 | int len=0; |
| 48 | |
| 49 | for(i=0;i<name_comps;i++) |
| 50 | { |
| 51 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 52 | if( res == 0) |
| 53 | { |
| 54 | nlsr_position=i; |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | const unsigned char *comp_ptr1; |
| 61 | size_t comp_size; |
| 62 | for(i=0;i<nlsr_position;i++) |
| 63 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 64 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,& |
| 65 | comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 66 | len+=1; |
| 67 | len+=(int)comp_size; |
| 68 | } |
| 69 | len++; |
| 70 | |
| 71 | char *neighbor=(char *)malloc(len); |
| 72 | memset(neighbor,0,len); |
| 73 | |
| 74 | for(i=0; i<nlsr_position;i++) |
| 75 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 76 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i, |
| 77 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 78 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 79 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 80 | |
| 81 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 82 | |
akmhoque | 284056b | 2013-03-15 01:20:16 -0500 | [diff] [blame] | 83 | nbr->name=(char *)calloc(strlen(neighbor)+1,sizeof(char)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 84 | memcpy(nbr->name,neighbor,strlen(neighbor)+1); |
| 85 | nbr->length=strlen(neighbor)+1; |
| 86 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 87 | if ( nlsr->debugging ) |
| 88 | printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length); |
| 89 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 90 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Length: %d\n", |
| 91 | nbr->name,nbr->length); |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 92 | free(neighbor); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 93 | } |
| 94 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 95 | /** |
| 96 | * Retrieve LSA identifier from content name |
| 97 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 98 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 99 | void |
| 100 | get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, |
| 101 | struct ccn_upcall_info *info, int offset) |
| 102 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 103 | |
| 104 | if ( nlsr->debugging ) |
| 105 | printf("get_lsa_identifier called\n"); |
| 106 | if ( nlsr->detailed_logging ) |
| 107 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsa_identifier called\n"); |
| 108 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 109 | int res,i; |
| 110 | int nlsr_position=0; |
| 111 | int name_comps=(int)info->interest_comps->n; |
| 112 | int len=0; |
| 113 | |
| 114 | for(i=0;i<name_comps;i++) |
| 115 | { |
| 116 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 117 | if( res == 0) |
| 118 | { |
| 119 | nlsr_position=i; |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | |
| 125 | const unsigned char *comp_ptr1; |
| 126 | size_t comp_size; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 127 | for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 128 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 129 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i, |
| 130 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 131 | len+=1; |
| 132 | len+=(int)comp_size; |
| 133 | } |
| 134 | len++; |
| 135 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 136 | char *neighbor=(char *)calloc(len,sizeof(char)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 137 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 138 | for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 139 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 140 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i, |
| 141 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 142 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 143 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 144 | |
| 145 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 146 | |
akmhoque | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 147 | lsaId->name=(char *)calloc(strlen(neighbor)+1,sizeof(char)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 148 | memcpy(lsaId->name,neighbor,strlen(neighbor)+1); |
| 149 | lsaId->length=strlen(neighbor)+1; |
| 150 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 151 | if ( nlsr->debugging ) |
| 152 | printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1); |
| 153 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 154 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Identifier: %s Length: " |
| 155 | "%d\n",lsaId->name,lsaId->length-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 156 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 157 | free(neighbor); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
akmhoque | 9635b85 | 2013-04-04 23:29:48 -0500 | [diff] [blame] | 161 | int |
| 162 | get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 163 | { |
| 164 | int res,i; |
| 165 | int nlsr_position=0; |
| 166 | int name_comps=(int)info->interest_comps->n; |
| 167 | |
| 168 | int ret=0; |
| 169 | |
| 170 | for(i=0;i<name_comps;i++) |
| 171 | { |
| 172 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 173 | if( res == 0) |
| 174 | { |
| 175 | nlsr_position=i; |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | const unsigned char *comp_ptr1; |
| 182 | size_t comp_size; |
| 183 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size); |
| 184 | |
| 185 | ret=atoi((char *)comp_ptr1); |
| 186 | |
| 187 | return ret; |
| 188 | |
| 189 | } |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Call back function registered in ccnd to get all interest coming to NLSR |
| 193 | * application |
| 194 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 195 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 196 | enum ccn_upcall_res |
| 197 | incoming_interest(struct ccn_closure *selfp, |
| 198 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 199 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 200 | |
| 201 | nlsr_lock(); |
| 202 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 203 | switch (kind) { |
| 204 | case CCN_UPCALL_FINAL: |
| 205 | break; |
| 206 | case CCN_UPCALL_INTEREST: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 207 | // printing the name prefix for which it received interest |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 208 | if ( nlsr->debugging ) |
| 209 | printf("Interest Received for name: "); |
| 210 | if ( nlsr->detailed_logging ) |
| 211 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for name: "); |
| 212 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 213 | struct ccn_charbuf*c; |
| 214 | c=ccn_charbuf_create(); |
| 215 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 216 | |
| 217 | if ( nlsr->debugging ) |
| 218 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 219 | if ( nlsr->detailed_logging ) |
| 220 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 221 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 222 | ccn_charbuf_destroy(&c); |
| 223 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 224 | process_incoming_interest(selfp, info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 225 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 226 | break; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 227 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 228 | default: |
| 229 | break; |
| 230 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 231 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 232 | nlsr_unlock(); |
| 233 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 234 | return CCN_UPCALL_RESULT_OK; |
| 235 | } |
| 236 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 237 | /** |
| 238 | * Function for processing incoming interest and reply with content/NACK content |
| 239 | */ |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 240 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 241 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 242 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 243 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 244 | if ( nlsr->debugging ) |
| 245 | printf("process_incoming_interest called \n"); |
| 246 | if ( nlsr->detailed_logging ) |
| 247 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest called \n"); |
| 248 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 249 | const unsigned char *comp_ptr1; |
| 250 | size_t comp_size; |
| 251 | int res,i; |
| 252 | int nlsr_position=0; |
| 253 | int name_comps=(int)info->interest_comps->n; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 254 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 255 | for(i=0;i<name_comps;i++) |
| 256 | { |
| 257 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 258 | if( res == 0) |
| 259 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 260 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 261 | break; |
| 262 | } |
| 263 | } |
| 264 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 265 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1, |
| 266 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 267 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 268 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 269 | if(!strcmp((char *)comp_ptr1,"info")) |
| 270 | { |
| 271 | process_incoming_interest_info(selfp,info); |
| 272 | } |
akmhoque | 9635b85 | 2013-04-04 23:29:48 -0500 | [diff] [blame] | 273 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 274 | { |
| 275 | process_incoming_interest_lsdb(selfp,info); |
| 276 | } |
| 277 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 278 | { |
| 279 | process_incoming_interest_lsa(selfp,info); |
| 280 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 281 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 282 | } |
| 283 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 284 | /** |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 285 | * Processes incoming interest for "info" interest. Send back reply content back, |
| 286 | * if interest comes from a neighbor with status down, NLSR will send "info" |
| 287 | * ineterst to that neighbor |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 288 | */ |
| 289 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 290 | void |
| 291 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 292 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 293 | if ( nlsr->debugging ) |
| 294 | { |
| 295 | printf("process_incoming_interest_info called \n"); |
| 296 | printf("Sending Info Content back.....\n"); |
| 297 | } |
| 298 | if ( nlsr->detailed_logging ) |
| 299 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 300 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info" |
| 301 | " called \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 302 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 303 | } |
| 304 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 305 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 306 | int res; |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 307 | //struct ccn_charbuf *data=ccn_charbuf_create(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 308 | struct ccn_charbuf *name=ccn_charbuf_create(); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 309 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 310 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 311 | res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 312 | info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 313 | if (res >= 0) |
| 314 | { |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 315 | |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 316 | /* |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 317 | struct ccn_charbuf *pubid = ccn_charbuf_create(); |
| 318 | struct ccn_charbuf *pubkey = ccn_charbuf_create(); |
| 319 | |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 320 | //pubid is the digest_result pubkey is result |
| 321 | ccn_get_public_key(nlsr->ccn, NULL, pubid, pubkey); |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 322 | */ |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 323 | |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 324 | |
| 325 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 326 | sp.template_ccnb=ccn_charbuf_create(); |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 327 | |
akmhoque | b63a41e | 2013-03-01 12:00:20 -0600 | [diff] [blame] | 328 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 329 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 330 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 331 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | b63a41e | 2013-03-01 12:00:20 -0600 | [diff] [blame] | 332 | |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 333 | /* |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 334 | char *raw_data=(char *)malloc(20); |
| 335 | memset(raw_data,0,20); |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 336 | sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version); |
| 337 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 338 | |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 339 | struct ccn_charbuf *resultbuf=ccn_charbuf_create(); |
| 340 | |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 341 | /* |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 342 | res=sign_content_with_user_defined_keystore(name, |
| 343 | resultbuf, |
| 344 | "info", |
| 345 | strlen("info"), |
| 346 | nlsr->keystore_path, |
| 347 | nlsr->keystore_passphrase, |
| 348 | nlsr->root_key_prefix, |
| 349 | nlsr->site_name, |
akmhoque | 2fafaa5 | 2013-03-22 05:10:52 -0500 | [diff] [blame] | 350 | nlsr->router_name, |
| 351 | 10); |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 352 | |
| 353 | */ |
| 354 | res= ccn_sign_content(nlsr->ccn, resultbuf, name, &sp, "info",strlen("info")); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 355 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 356 | { |
| 357 | if ( nlsr->debugging ) |
| 358 | printf("Signing info Content is successful \n"); |
| 359 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 360 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content" |
| 361 | " is successful \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 362 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 363 | } |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 364 | |
| 365 | res=ccn_put(nlsr->ccn,resultbuf->buf,resultbuf->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 366 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 367 | { |
| 368 | if ( nlsr->debugging ) |
| 369 | printf("Sending Info Content is successful \n"); |
| 370 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 371 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content" |
| 372 | " is successful \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 373 | } |
| 374 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 375 | |
| 376 | |
akmhoque | e1dd777 | 2013-02-24 14:21:49 -0600 | [diff] [blame] | 377 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 378 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 379 | |
| 380 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 381 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length, |
| 382 | get_adjacent_status(nbr)); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 383 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 384 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d" |
| 385 | " Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 386 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 387 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 388 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr) >= |
| 389 | nlsr->interest_retry ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 390 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 391 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 392 | send_info_interest_to_neighbor(nbr); |
| 393 | } |
| 394 | |
akmhoque | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 395 | if ( nbr->name != NULL ) |
| 396 | free(nbr->name); |
| 397 | if ( nbr != NULL ) |
| 398 | free(nbr); |
akmhoque | 284056b | 2013-03-15 01:20:16 -0500 | [diff] [blame] | 399 | ccn_charbuf_destroy(&resultbuf); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 400 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 401 | |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 402 | //ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 403 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 404 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
akmhoque | 9635b85 | 2013-04-04 23:29:48 -0500 | [diff] [blame] | 408 | |
| 409 | void |
| 410 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 411 | { |
| 412 | //printf("process_incoming_interest_lsdb called \n"); |
| 413 | |
| 414 | if ( nlsr->debugging ) |
| 415 | printf("process_incoming_interest_lsdb called \n"); |
| 416 | if ( nlsr->detailed_logging ) |
| 417 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsdb called \n"); |
| 418 | |
| 419 | |
| 420 | int l,res; |
| 421 | const unsigned char *exclbase; |
| 422 | size_t size; |
| 423 | struct ccn_buf_decoder decoder; |
| 424 | struct ccn_buf_decoder *d; |
| 425 | const unsigned char *comp; |
| 426 | int dbcmp=0; |
| 427 | |
| 428 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 429 | if (l > 0) |
| 430 | { |
| 431 | comp = NULL; |
| 432 | size = 0; |
| 433 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 434 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 435 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 436 | { |
| 437 | ccn_buf_advance(d); |
| 438 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 439 | ccn_buf_advance_past_element(d); |
| 440 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 441 | { |
| 442 | ccn_buf_advance(d); |
| 443 | ccn_buf_match_blob(d, &comp, &size); |
| 444 | ccn_buf_check_close(d); |
| 445 | |
| 446 | |
| 447 | } |
| 448 | ccn_buf_check_close(d); |
| 449 | } |
| 450 | if (comp != NULL) |
| 451 | { |
| 452 | if ( nlsr->debugging ) |
| 453 | { |
| 454 | printf("LSDB Version in Exclusion Filter is %s\n",comp); |
| 455 | printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version); |
| 456 | } |
| 457 | if ( nlsr->detailed_logging ) |
| 458 | { |
| 459 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is %s\n",comp); |
| 460 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version); |
| 461 | } |
| 462 | dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp); |
| 463 | } |
| 464 | /* Now comp points to the start of your potential number, and size is its length */ |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | if ( nlsr->debugging ) |
| 469 | printf("LSDB Version in Exclusion Filter is: None Added\n"); |
| 470 | if ( nlsr->detailed_logging ) |
| 471 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is: None Added\n"); |
| 472 | dbcmp=1; |
| 473 | |
| 474 | } |
| 475 | |
| 476 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 477 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 478 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 479 | |
| 480 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 481 | |
| 482 | sp.template_ccnb=ccn_charbuf_create(); |
| 483 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 484 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 485 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 486 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 487 | |
| 488 | |
| 489 | if(dbcmp>0) |
| 490 | { |
| 491 | if ( nlsr->debugging ) |
| 492 | { |
| 493 | printf("Has Updated Database than Neighbor\n"); |
| 494 | printf("Sending LSDB Summary of Updated LSDB Content...\n"); |
| 495 | } |
| 496 | if ( nlsr->detailed_logging ) |
| 497 | { |
| 498 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Has Updated Database than Neighbor\n"); |
| 499 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content...\n"); |
| 500 | } |
| 501 | ccn_name_append_str(name,nlsr->lsdb->lsdb_version); |
| 502 | |
| 503 | struct ccn_charbuf *lsdb_data=ccn_charbuf_create(); |
| 504 | get_lsdb_summary(lsdb_data); |
| 505 | |
| 506 | char *raw_data=ccn_charbuf_as_string(lsdb_data); |
| 507 | |
| 508 | //printf("Content Data to be sent: %s \n",raw_data); |
| 509 | |
| 510 | if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 ) |
| 511 | { |
| 512 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT")); |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 517 | } |
| 518 | |
| 519 | if(res >= 0) |
| 520 | { |
| 521 | if ( nlsr->debugging ) |
| 522 | printf("Signing LSDB Summary of Updated LSDB Content is successful \n"); |
| 523 | if ( nlsr->detailed_logging ) |
| 524 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSDB Summary of Updated LSDB Content is successful \n"); |
| 525 | } |
| 526 | |
| 527 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 528 | |
| 529 | if(res >= 0) |
| 530 | { |
| 531 | if ( nlsr->debugging ) |
| 532 | printf("Sending LSDB Summary of Updated LSDB Content is successful \n"); |
| 533 | if ( nlsr->detailed_logging ) |
| 534 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content is successful \n"); |
| 535 | } |
| 536 | |
| 537 | ccn_charbuf_destroy(&lsdb_data); |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | if ( nlsr->debugging ) |
| 542 | { |
| 543 | printf("Does not have Updated Database than Neighbor\n"); |
| 544 | printf("Sending NACK Content.....\n"); |
| 545 | } |
| 546 | if ( nlsr->detailed_logging ) |
| 547 | { |
| 548 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Does not have Updated Database than Neighbor\n"); |
| 549 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content.....\n"); |
| 550 | } |
| 551 | |
| 552 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
| 553 | |
| 554 | if(res >= 0) |
| 555 | { |
| 556 | if ( nlsr->debugging ) |
| 557 | printf("Signing NACK Content is successful \n"); |
| 558 | if ( nlsr->detailed_logging ) |
| 559 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing NACK Content is successful \n"); |
| 560 | } |
| 561 | |
| 562 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 563 | |
| 564 | if(res >= 0) |
| 565 | { |
| 566 | if ( nlsr->debugging ) |
| 567 | printf("Sending NACK Content is successful \n"); |
| 568 | if ( nlsr->detailed_logging ) |
| 569 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content is successful \n"); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | } |
| 574 | |
| 575 | ccn_charbuf_destroy(&data); |
| 576 | ccn_charbuf_destroy(&name); |
| 577 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 578 | |
| 579 | |
| 580 | } |
| 581 | |
| 582 | |
| 583 | void |
| 584 | process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 585 | { |
| 586 | if ( nlsr->debugging ) |
| 587 | printf("process_incoming_interest_lsa called \n"); |
| 588 | if ( nlsr->detailed_logging ) |
| 589 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsa called \n"); |
| 590 | |
| 591 | int res; |
| 592 | |
| 593 | struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 594 | get_lsa_identifier(lsaId,selfp,info,0); |
| 595 | |
| 596 | //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length); |
| 597 | int ls_type=get_ls_type(selfp, info); |
| 598 | |
| 599 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 600 | |
| 601 | if ( ls_type == LS_TYPE_NAME ) |
| 602 | { |
| 603 | if ( nlsr->debugging ) |
| 604 | printf("Interest Received for NAME LSA \n"); |
| 605 | if ( nlsr->detailed_logging ) |
| 606 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for NAME LSA \n"); |
| 607 | get_name_lsa_data(lsa_data,lsaId); |
| 608 | } |
| 609 | else if ( ls_type == LS_TYPE_ADJ ) |
| 610 | { |
| 611 | if ( nlsr->debugging ) |
| 612 | printf("Interest Received for ADJ LSA \n"); |
| 613 | if ( nlsr->detailed_logging ) |
| 614 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for ADJ LSA \n"); |
| 615 | get_adj_lsa_data(lsa_data,lsaId); |
| 616 | } |
| 617 | |
| 618 | char *rdata=ccn_charbuf_as_string(lsa_data); |
| 619 | char *raw_data=(char *)malloc(strlen(rdata)+1); |
| 620 | memset(raw_data,0,strlen(rdata)+1); |
| 621 | memcpy(raw_data,(char *)rdata,strlen(rdata)+1); |
| 622 | //printf("Content Data to be sent: %s\n",raw_data); |
| 623 | |
| 624 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 625 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 626 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 627 | |
| 628 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 629 | |
| 630 | sp.template_ccnb=ccn_charbuf_create(); |
| 631 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 632 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 633 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 634 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 635 | |
| 636 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 637 | |
| 638 | if(res >= 0) |
| 639 | { |
| 640 | if ( nlsr->debugging ) |
| 641 | printf("Signing LSA Content is successful \n"); |
| 642 | if ( nlsr->detailed_logging ) |
| 643 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSA Content is successful \n"); |
| 644 | } |
| 645 | |
| 646 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 647 | |
| 648 | if(res >= 0) |
| 649 | { |
| 650 | if ( nlsr->debugging ) |
| 651 | printf("Sending LSA Content is successful \n"); |
| 652 | if ( nlsr->detailed_logging ) |
| 653 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSA Content is successful \n"); |
| 654 | } |
| 655 | |
| 656 | |
| 657 | |
| 658 | ccn_charbuf_destroy(&data); |
| 659 | ccn_charbuf_destroy(&name); |
| 660 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 661 | ccn_charbuf_destroy(&lsa_data); |
| 662 | |
| 663 | free(raw_data); |
| 664 | free(lsaId); |
| 665 | } |
| 666 | |
| 667 | |
| 668 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 669 | /** |
| 670 | * Call back function registered in ccnd to get all content coming to NLSR |
| 671 | * application |
| 672 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 673 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 674 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 675 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 676 | { |
| 677 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 678 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 679 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 680 | switch(kind) { |
| 681 | case CCN_UPCALL_FINAL: |
| 682 | break; |
| 683 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 684 | if ( nlsr->debugging ) |
| 685 | printf("Content Received for Name: "); |
| 686 | if ( nlsr->detailed_logging ) |
| 687 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 688 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 689 | struct ccn_charbuf*c; |
| 690 | c=ccn_charbuf_create(); |
| 691 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 692 | if ( nlsr->debugging ) |
| 693 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 694 | if ( nlsr->detailed_logging ) |
| 695 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 696 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 697 | ccn_charbuf_destroy(&c); |
| 698 | |
| 699 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 700 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 701 | break; |
| 702 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 703 | //printf("Interest Timed Out Received for Name: "); |
| 704 | if ( nlsr->debugging ) |
| 705 | printf("Interest Timed Out Received for Name: "); |
| 706 | if ( nlsr->detailed_logging ) |
| 707 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv" |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 708 | "ed for Name: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 709 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 710 | struct ccn_charbuf*ito; |
| 711 | ito=ccn_charbuf_create(); |
| 712 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 713 | if ( nlsr->debugging ) |
| 714 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 715 | if ( nlsr->detailed_logging ) |
| 716 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
| 717 | ccn_charbuf_destroy(&ito); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 718 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 719 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 720 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 721 | break; |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 722 | |
| 723 | case CCN_UPCALL_CONTENT_UNVERIFIED: |
| 724 | if ( nlsr->debugging ) |
| 725 | printf("Unverified Content Received ..Waiting for verification\n"); |
| 726 | if ( nlsr->detailed_logging ) |
| 727 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unverified Content" |
| 728 | " Received ..Waiting for verification\n"); |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 729 | //return CCN_UPCALL_RESULT_VERIFY; |
akmhoque | 4637d9d | 2013-03-08 06:52:00 -0600 | [diff] [blame] | 730 | process_incoming_content(selfp,info); |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 731 | break; |
| 732 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 733 | default: |
| 734 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 735 | if ( nlsr->debugging ) |
| 736 | printf("Unexpected response of kind %d\n", kind); |
| 737 | if ( nlsr->detailed_logging ) |
| 738 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of " |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 739 | "kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 740 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 741 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 742 | |
| 743 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 744 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 745 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 746 | } |
| 747 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 748 | /** |
| 749 | * process any incoming content to NLSR from ccnd |
| 750 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 751 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 752 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 753 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 754 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 755 | if ( nlsr->debugging ) |
| 756 | printf("process_incoming_content called \n"); |
| 757 | if ( nlsr->detailed_logging ) |
| 758 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 759 | |
| 760 | const unsigned char *comp_ptr1; |
| 761 | size_t comp_size; |
| 762 | int res,i; |
| 763 | int nlsr_position=0; |
| 764 | int name_comps=(int)info->interest_comps->n; |
| 765 | |
| 766 | for(i=0;i<name_comps;i++) |
| 767 | { |
| 768 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 769 | if( res == 0) |
| 770 | { |
| 771 | nlsr_position=i; |
| 772 | break; |
| 773 | } |
| 774 | } |
| 775 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 776 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps, |
| 777 | nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 778 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 779 | |
| 780 | if(!strcmp((char *)comp_ptr1,"info")) |
| 781 | { |
| 782 | process_incoming_content_info(selfp,info); |
| 783 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 784 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 785 | } |
| 786 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 787 | /** |
| 788 | * process any incoming "info" content to NLSR from ccnd |
| 789 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 790 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 791 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 792 | process_incoming_content_info(struct ccn_closure *selfp, |
| 793 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 794 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 795 | if ( nlsr->debugging ) |
| 796 | printf("process_incoming_content_info called \n"); |
| 797 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 798 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info" |
| 799 | " called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 800 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 801 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 802 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 803 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 804 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 805 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name, |
| 806 | nbr->length); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 807 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 808 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Nei" |
| 809 | "ghbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 810 | |
akmhoque | fc7016f | 2013-03-08 07:17:14 -0600 | [diff] [blame] | 811 | |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 812 | /* |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 813 | if ( contain_key_name(info->content_ccnb, info->pco) == 1){ |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 814 | int res_verify=-1; |
| 815 | int key_exists=0; |
| 816 | struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco); |
| 817 | struct ccn_charbuf *key_uri = ccn_charbuf_create(); |
| 818 | ccn_uri_append(key_uri, key_name->buf, key_name->length, 0); |
| 819 | key_exists=does_key_exist(ccn_charbuf_as_string(key_uri)); |
| 820 | int key_type=get_key_type_from_key_name(key_name); |
| 821 | |
| 822 | if ( res_verify == 1 && key_type == NLSR_KEY ){ |
| 823 | res_verify=0; |
| 824 | } |
| 825 | else{ |
| 826 | res_verify=verify_key(info->content_ccnb,info->pco,0); |
| 827 | } |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 828 | |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 829 | //int res_verify=verify_key(info->content_ccnb,info->pco,0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 830 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 831 | if ( res_verify != 0 ){ |
akmhoque | 1162d85 | 2013-03-15 01:07:00 -0500 | [diff] [blame] | 832 | if ( nlsr->debugging ) |
| 833 | printf("Error in verfiying keys !! :( \n"); |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 834 | ccn_charbuf_destroy(&key_name); |
| 835 | ccn_charbuf_destroy(&key_uri); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 836 | } |
| 837 | else{ |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 838 | if ( key_exists == 0 ) |
| 839 | add_key(ccn_charbuf_as_string(key_uri)); |
| 840 | ccn_charbuf_destroy(&key_name); |
| 841 | ccn_charbuf_destroy(&key_uri); |
akmhoque | 1162d85 | 2013-03-15 01:07:00 -0500 | [diff] [blame] | 842 | if ( nlsr->debugging ) |
| 843 | printf("Key verification is successful :)\n"); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 844 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 845 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 846 | print_adjacent_from_adl(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 847 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 848 | if(!nlsr->is_build_adj_lsa_sheduled){ |
| 849 | if ( nlsr->debugging ) |
| 850 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 851 | if ( nlsr->detailed_logging ) |
| 852 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling" |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 853 | "Build and Install Adj LSA...\n"); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 854 | nlsr->event_build_adj_lsa = ccn_schedule_event( |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 855 | nlsr->sched, 100000, |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 856 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 857 | nlsr->is_build_adj_lsa_sheduled=1; |
| 858 | } |
| 859 | else{ |
| 860 | if ( nlsr->debugging ) |
| 861 | printf("Build and Install Adj LSA already scheduled\n"); |
| 862 | if ( nlsr->detailed_logging ) |
| 863 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA" |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 864 | " already scheduled\n"); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 865 | } |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 866 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 867 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 868 | } |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 869 | */ |
| 870 | |
akmhoque | 10c9a21 | 2013-03-08 07:05:18 -0600 | [diff] [blame] | 871 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 872 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 873 | print_adjacent_from_adl(); |
| 874 | |
| 875 | if(!nlsr->is_build_adj_lsa_sheduled){ |
| 876 | if ( nlsr->debugging ) |
| 877 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 878 | if ( nlsr->detailed_logging ) |
| 879 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling" |
| 880 | "Build and Install Adj LSA...\n"); |
| 881 | nlsr->event_build_adj_lsa = ccn_schedule_event( |
| 882 | nlsr->sched, 100000, |
| 883 | &build_and_install_adj_lsa, NULL, 0); |
| 884 | nlsr->is_build_adj_lsa_sheduled=1; |
| 885 | } |
| 886 | else{ |
| 887 | if ( nlsr->debugging ) |
| 888 | printf("Build and Install Adj LSA already scheduled\n"); |
| 889 | if ( nlsr->detailed_logging ) |
| 890 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA" |
| 891 | " already scheduled\n"); |
| 892 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 893 | |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame] | 894 | |
akmhoque | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 895 | if ( nbr->name != NULL ) |
| 896 | free(nbr->name); |
| 897 | if ( nbr != NULL ) |
| 898 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 899 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 900 | |
| 901 | } |
| 902 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 903 | /** |
| 904 | * process any incoming interest timed out content to NLSR from ccnd |
| 905 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 906 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 907 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 908 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 909 | process_incoming_timed_out_interest(struct ccn_closure* selfp, |
| 910 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 911 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 912 | |
| 913 | |
| 914 | if ( nlsr->debugging ) |
| 915 | printf("process_incoming_timed_out_interest called \n"); |
| 916 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 917 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 918 | "erest called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 919 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 920 | int res,i; |
| 921 | int nlsr_position=0; |
| 922 | int name_comps=(int)info->interest_comps->n; |
| 923 | |
| 924 | for(i=0;i<name_comps;i++) |
| 925 | { |
| 926 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 927 | if( res == 0) |
| 928 | { |
| 929 | nlsr_position=i; |
| 930 | break; |
| 931 | } |
| 932 | } |
| 933 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 934 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps, |
| 935 | nlsr_position+1,"info") == 0) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 936 | { |
| 937 | process_incoming_timed_out_interest_info(selfp,info); |
| 938 | } |
| 939 | } |
| 940 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 941 | /** |
| 942 | * process any incoming "info" interest timed out content to NLSR from ccnd |
| 943 | */ |
| 944 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 945 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 946 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct |
| 947 | ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 948 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 949 | |
| 950 | if ( nlsr->debugging ) |
| 951 | printf("process_incoming_timed_out_interest_info called \n"); |
| 952 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 953 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 954 | "erest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 955 | |
| 956 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 957 | get_nbr(nbr,selfp,info); |
| 958 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 959 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 960 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n", |
| 961 | nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 962 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 963 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for" |
| 964 | " Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 965 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 966 | |
| 967 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 968 | update_adjacent_timed_out_to_adl(nbr,1); |
| 969 | print_adjacent_from_adl(); |
| 970 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 971 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 972 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 973 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name, |
| 974 | timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 975 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 976 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest " |
| 977 | "Timed Out: %d times\n",nbr->name,timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 978 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 979 | |
| 980 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 981 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 982 | send_info_interest_to_neighbor(nbr); |
| 983 | } |
| 984 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 985 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 986 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 987 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 988 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 989 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, |
| 990 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 991 | nlsr->is_build_adj_lsa_sheduled=1; |
| 992 | } |
| 993 | } |
| 994 | |
akmhoque | 284056b | 2013-03-15 01:20:16 -0500 | [diff] [blame] | 995 | if ( nbr->name != NULL ) |
| 996 | free(nbr->name); |
| 997 | if ( nbr != NULL ) |
| 998 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 999 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1000 | |
| 1001 | } |
| 1002 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 1003 | /** |
| 1004 | * send "info" interest to each and every neighbor in ADL and also schedule for |
| 1005 | * itself for periodical sending of "info" interest |
| 1006 | */ |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1007 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1008 | int |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1009 | send_info_interest(struct ccn_schedule *sched, void *clienth, |
| 1010 | struct ccn_scheduled_event *ev, int flags) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1011 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1012 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1013 | { |
| 1014 | return -1; |
| 1015 | } |
| 1016 | |
| 1017 | nlsr_lock(); |
| 1018 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1019 | if ( nlsr->debugging ) |
| 1020 | printf("send_info_interest called \n"); |
| 1021 | if ( nlsr->detailed_logging ) |
| 1022 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 1023 | |
| 1024 | if ( nlsr->debugging ) |
| 1025 | printf("\n"); |
| 1026 | if ( nlsr->detailed_logging ) |
| 1027 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1028 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1029 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1030 | struct ndn_neighbor *nbr; |
| 1031 | |
| 1032 | struct hashtb_enumerator ee; |
| 1033 | struct hashtb_enumerator *e = ⅇ |
| 1034 | |
| 1035 | hashtb_start(nlsr->adl, e); |
| 1036 | adl_element=hashtb_n(nlsr->adl); |
| 1037 | |
| 1038 | for(i=0;i<adl_element;i++) |
| 1039 | { |
| 1040 | nbr=e->data; |
| 1041 | send_info_interest_to_neighbor(nbr->neighbor); |
| 1042 | hashtb_next(e); |
| 1043 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1044 | hashtb_end(e); |
| 1045 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1046 | nlsr_unlock(); |
| 1047 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1048 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, |
| 1049 | NULL, 0); |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 1050 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1051 | return 0; |
| 1052 | } |
| 1053 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 1054 | |
| 1055 | /** |
| 1056 | * send "info" interest neighbor nbr |
| 1057 | * |
| 1058 | */ |
| 1059 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1060 | void |
| 1061 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 1062 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1063 | |
| 1064 | if ( nlsr->debugging ) |
| 1065 | printf("send_info_interest_to_neighbor called \n"); |
| 1066 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1067 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor" |
| 1068 | " called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1069 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1070 | |
| 1071 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1072 | char info_str[5]; |
| 1073 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1074 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1075 | memset(&nlsr_str,0,5); |
| 1076 | sprintf(nlsr_str,"nlsr"); |
| 1077 | memset(&info_str,0,5); |
| 1078 | sprintf(info_str,"info"); |
| 1079 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1080 | |
| 1081 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1082 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1083 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1084 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+ |
| 1085 | strlen(info_str)+strlen(nlsr->router_name)+1); |
| 1086 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+ |
| 1087 | strlen(nlsr->router_name)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1088 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 1089 | memcpy(int_name+strlen(int_name),"/",1); |
| 1090 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1091 | memcpy(int_name+strlen(int_name),"/",1); |
| 1092 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1093 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1094 | |
| 1095 | |
| 1096 | res=ccn_name_from_uri(name,int_name); |
| 1097 | if ( res >=0 ) |
| 1098 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1099 | /* adding InterestLifeTime and InterestScope filter */ |
| 1100 | |
| 1101 | struct ccn_charbuf *templ; |
| 1102 | templ = ccn_charbuf_create(); |
| 1103 | |
| 1104 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1105 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1106 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1107 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1108 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1109 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1110 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 |
| 1111 | //(not further than next host) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1112 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1113 | |
| 1114 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1115 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 1116 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1117 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1118 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1119 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1120 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1121 | printf("Sending info interest on name prefix : %s through Face:%u\n" |
| 1122 | ,int_name,face_id); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1123 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1124 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on" |
| 1125 | "name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1126 | |
| 1127 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1128 | |
| 1129 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1130 | { |
| 1131 | if ( nlsr->debugging ) |
| 1132 | printf("Info interest sending Successfull .... \n"); |
| 1133 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 1134 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info" |
| 1135 | "interest sending Successfull .... \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1136 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1137 | ccn_charbuf_destroy(&templ); |
| 1138 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1139 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1140 | ccn_charbuf_destroy(&name); |
| 1141 | free(int_name); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 1142 | } |
akmhoque | 9635b85 | 2013-04-04 23:29:48 -0500 | [diff] [blame] | 1143 | |
| 1144 | |
| 1145 | void |
| 1146 | send_lsdb_interest_to_nbr(struct name_prefix *nbr) |
| 1147 | { |
| 1148 | /* |
| 1149 | if ( nlsr->debugging ) |
| 1150 | printf("send_lsdb_interest_to_nbr called \n"); |
| 1151 | if ( nlsr->detailed_logging ) |
| 1152 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest_to_nbr called \n"); |
| 1153 | |
| 1154 | char *last_lsdb_version=get_nbr_lsdb_version(nbr->name); |
| 1155 | |
| 1156 | if(last_lsdb_version !=NULL) |
| 1157 | { |
| 1158 | |
| 1159 | |
| 1160 | if ( nlsr->debugging ) |
| 1161 | printf("Last LSDB Version: %s \n",last_lsdb_version); |
| 1162 | if ( nlsr->detailed_logging ) |
| 1163 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Last LSDB Version: %s \n",last_lsdb_version); |
| 1164 | |
| 1165 | struct ccn_charbuf *name; |
| 1166 | int res; |
| 1167 | char lsdb_str[5]; |
| 1168 | char nlsr_str[5]; |
| 1169 | |
| 1170 | memset(&nlsr_str,0,5); |
| 1171 | sprintf(nlsr_str,"nlsr"); |
| 1172 | memset(&lsdb_str,0,5); |
| 1173 | sprintf(lsdb_str,"lsdb"); |
| 1174 | //make and send interest with exclusion filter as last_lsdb_version |
| 1175 | if ( nlsr->debugging ) |
| 1176 | printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str); |
| 1177 | if ( nlsr->detailed_logging ) |
| 1178 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str); |
| 1179 | |
| 1180 | name=ccn_charbuf_create(); |
| 1181 | res=ccn_name_from_uri(name,nbr->name); |
| 1182 | |
| 1183 | if( res >= 0) |
| 1184 | { |
| 1185 | ccn_name_append_str(name,nlsr_str); |
| 1186 | ccn_name_append_str(name,lsdb_str); |
| 1187 | // adding Exclusion filter |
| 1188 | |
| 1189 | struct ccn_charbuf *templ; |
| 1190 | templ = ccn_charbuf_create(); |
| 1191 | |
| 1192 | struct ccn_charbuf *c; |
| 1193 | c = ccn_charbuf_create(); |
| 1194 | |
| 1195 | |
| 1196 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1197 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1198 | ccn_charbuf_append_closer(templ); // </Name> |
| 1199 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 1200 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 1201 | ccn_charbuf_reset(c); |
| 1202 | ccn_charbuf_putf(c, "%s", last_lsdb_version); |
| 1203 | |
| 1204 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 1205 | ccn_charbuf_append_closer(templ); // </Exclude> |
| 1206 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1207 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1208 | ccn_charbuf_append(templ, "2", 1); |
| 1209 | ccn_charbuf_append_closer(templ); // </Scope> |
| 1210 | |
| 1211 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1212 | |
| 1213 | ccn_charbuf_append_closer(templ); // </Interest> |
| 1214 | |
| 1215 | |
| 1216 | // Adding Exclusion filter done |
| 1217 | |
| 1218 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1219 | |
| 1220 | if ( res >= 0 ) |
| 1221 | { |
| 1222 | if ( nlsr->debugging ) |
| 1223 | printf("Interest sending Successfull .... \n"); |
| 1224 | if ( nlsr->detailed_logging ) |
| 1225 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest sending Successfull .... \n"); |
| 1226 | update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec()); |
| 1227 | |
| 1228 | } |
| 1229 | ccn_charbuf_destroy(&c); |
| 1230 | ccn_charbuf_destroy(&templ); |
| 1231 | } |
| 1232 | ccn_charbuf_destroy(&name); |
| 1233 | } |
| 1234 | set_is_lsdb_send_interest_scheduled_to_zero(nbr->name); |
| 1235 | */ |
| 1236 | } |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | int |
| 1241 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1242 | { |
| 1243 | |
| 1244 | /* |
| 1245 | if ( nlsr->debugging ) |
| 1246 | printf("send_lsdb_interest called \n"); |
| 1247 | if ( nlsr->detailed_logging ) |
| 1248 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest called \n"); |
| 1249 | |
| 1250 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1251 | { |
| 1252 | return -1; |
| 1253 | } |
| 1254 | |
| 1255 | nlsr_lock(); |
| 1256 | |
| 1257 | int i, adl_element; |
| 1258 | struct ndn_neighbor *nbr; |
| 1259 | |
| 1260 | struct hashtb_enumerator ee; |
| 1261 | struct hashtb_enumerator *e = ⅇ |
| 1262 | |
| 1263 | hashtb_start(nlsr->adl, e); |
| 1264 | adl_element=hashtb_n(nlsr->adl); |
| 1265 | |
| 1266 | for(i=0;i<adl_element;i++) |
| 1267 | { |
| 1268 | nbr=e->data; |
| 1269 | |
| 1270 | if(nbr->status == NBR_ACTIVE) |
| 1271 | { |
| 1272 | if(nbr->is_lsdb_send_interest_scheduled == 0) |
| 1273 | { |
| 1274 | long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name); |
| 1275 | if ( nlsr->debugging ) |
| 1276 | printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name); |
| 1277 | if ( nlsr->detailed_logging ) |
| 1278 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name); |
| 1279 | |
| 1280 | |
| 1281 | if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) ) |
| 1282 | { |
| 1283 | nbr->is_lsdb_send_interest_scheduled=1; |
| 1284 | send_lsdb_interest_to_nbr(nbr->neighbor); |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | hashtb_next(e); |
| 1289 | } |
| 1290 | |
| 1291 | hashtb_end(e); |
| 1292 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0); |
| 1293 | |
| 1294 | nlsr_unlock(); |
| 1295 | |
| 1296 | */ |
| 1297 | return 0; |
| 1298 | |
| 1299 | } |
| 1300 | |
| 1301 | |