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" |
| 26 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 27 | /** |
| 28 | * add lifetime in second to a interest template |
| 29 | */ |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 30 | int |
| 31 | appendLifetime(struct ccn_charbuf *cb, int lifetime) |
| 32 | { |
| 33 | unsigned char buf[sizeof(int32_t)]; |
| 34 | int32_t dreck = lifetime << 12; |
| 35 | int pos = sizeof(int32_t); |
| 36 | int res = 0; |
| 37 | while (dreck > 0 && pos > 0) |
| 38 | { |
| 39 | pos--; |
| 40 | buf[pos] = dreck & 255; |
| 41 | dreck = dreck >> 8; |
| 42 | } |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 43 | res |= ccnb_append_tagged_blob(cb, CCN_DTAG_InterestLifetime, buf+pos, |
| 44 | sizeof(buf)-pos); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 45 | return res; |
| 46 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 47 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 48 | /** |
| 49 | * get neighbor name prefix from interest/content name and put into nbr |
| 50 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 51 | |
| 52 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 53 | get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, |
| 54 | struct ccn_upcall_info *info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 55 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 56 | if ( nlsr->debugging ) |
| 57 | printf("get_nbr called\n"); |
| 58 | if ( nlsr->detailed_logging ) |
| 59 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr called\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 60 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 61 | int res,i; |
| 62 | int nlsr_position=0; |
| 63 | int name_comps=(int)info->interest_comps->n; |
| 64 | int len=0; |
| 65 | |
| 66 | for(i=0;i<name_comps;i++) |
| 67 | { |
| 68 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 69 | if( res == 0) |
| 70 | { |
| 71 | nlsr_position=i; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |
| 77 | const unsigned char *comp_ptr1; |
| 78 | size_t comp_size; |
| 79 | for(i=0;i<nlsr_position;i++) |
| 80 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 81 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,& |
| 82 | comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 83 | len+=1; |
| 84 | len+=(int)comp_size; |
| 85 | } |
| 86 | len++; |
| 87 | |
| 88 | char *neighbor=(char *)malloc(len); |
| 89 | memset(neighbor,0,len); |
| 90 | |
| 91 | for(i=0; i<nlsr_position;i++) |
| 92 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 93 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i, |
| 94 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 95 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 96 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 97 | |
| 98 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 99 | |
| 100 | nbr->name=(char *)malloc(strlen(neighbor)+1); |
| 101 | memcpy(nbr->name,neighbor,strlen(neighbor)+1); |
| 102 | nbr->length=strlen(neighbor)+1; |
| 103 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 104 | if ( nlsr->debugging ) |
| 105 | printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length); |
| 106 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 107 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Length: %d\n", |
| 108 | nbr->name,nbr->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 109 | |
| 110 | } |
| 111 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 112 | /** |
| 113 | * Retrieve LSA identifier from content name |
| 114 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 115 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 116 | void |
| 117 | get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, |
| 118 | struct ccn_upcall_info *info, int offset) |
| 119 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 120 | |
| 121 | if ( nlsr->debugging ) |
| 122 | printf("get_lsa_identifier called\n"); |
| 123 | if ( nlsr->detailed_logging ) |
| 124 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsa_identifier called\n"); |
| 125 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 126 | int res,i; |
| 127 | int nlsr_position=0; |
| 128 | int name_comps=(int)info->interest_comps->n; |
| 129 | int len=0; |
| 130 | |
| 131 | for(i=0;i<name_comps;i++) |
| 132 | { |
| 133 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 134 | if( res == 0) |
| 135 | { |
| 136 | nlsr_position=i; |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
| 142 | const unsigned char *comp_ptr1; |
| 143 | size_t comp_size; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 144 | for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 145 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 146 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i, |
| 147 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 148 | len+=1; |
| 149 | len+=(int)comp_size; |
| 150 | } |
| 151 | len++; |
| 152 | |
| 153 | char *neighbor=(char *)malloc(len); |
| 154 | memset(neighbor,0,len); |
| 155 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 156 | for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 157 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 158 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i, |
| 159 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 160 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 161 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 162 | |
| 163 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 164 | |
| 165 | lsaId->name=(char *)malloc(strlen(neighbor)+1); |
| 166 | memset(lsaId->name,0,strlen(neighbor)+1); |
| 167 | memcpy(lsaId->name,neighbor,strlen(neighbor)+1); |
| 168 | lsaId->length=strlen(neighbor)+1; |
| 169 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 170 | if ( nlsr->debugging ) |
| 171 | printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1); |
| 172 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 173 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Identifier: %s Length: " |
| 174 | "%d\n",lsaId->name,lsaId->length-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 175 | |
| 176 | } |
| 177 | |
| 178 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * Call back function registered in ccnd to get all interest coming to NLSR |
| 182 | * application |
| 183 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 184 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 185 | enum ccn_upcall_res |
| 186 | incoming_interest(struct ccn_closure *selfp, |
| 187 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 188 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 189 | |
| 190 | nlsr_lock(); |
| 191 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 192 | switch (kind) { |
| 193 | case CCN_UPCALL_FINAL: |
| 194 | break; |
| 195 | case CCN_UPCALL_INTEREST: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 196 | // printing the name prefix for which it received interest |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 197 | if ( nlsr->debugging ) |
| 198 | printf("Interest Received for name: "); |
| 199 | if ( nlsr->detailed_logging ) |
| 200 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for name: "); |
| 201 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 202 | struct ccn_charbuf*c; |
| 203 | c=ccn_charbuf_create(); |
| 204 | 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] | 205 | |
| 206 | if ( nlsr->debugging ) |
| 207 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 208 | if ( nlsr->detailed_logging ) |
| 209 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 210 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 211 | ccn_charbuf_destroy(&c); |
| 212 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 213 | process_incoming_interest(selfp, info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 214 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 215 | break; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 216 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 217 | default: |
| 218 | break; |
| 219 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 220 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 221 | nlsr_unlock(); |
| 222 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 223 | return CCN_UPCALL_RESULT_OK; |
| 224 | } |
| 225 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 226 | /** |
| 227 | * Function for processing incoming interest and reply with content/NACK content |
| 228 | */ |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 229 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 230 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 231 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 232 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 233 | if ( nlsr->debugging ) |
| 234 | printf("process_incoming_interest called \n"); |
| 235 | if ( nlsr->detailed_logging ) |
| 236 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest called \n"); |
| 237 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 238 | const unsigned char *comp_ptr1; |
| 239 | size_t comp_size; |
| 240 | int res,i; |
| 241 | int nlsr_position=0; |
| 242 | int name_comps=(int)info->interest_comps->n; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 243 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 244 | for(i=0;i<name_comps;i++) |
| 245 | { |
| 246 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 247 | if( res == 0) |
| 248 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 249 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 250 | break; |
| 251 | } |
| 252 | } |
| 253 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 254 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1, |
| 255 | &comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 256 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 257 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 258 | if(!strcmp((char *)comp_ptr1,"info")) |
| 259 | { |
| 260 | process_incoming_interest_info(selfp,info); |
| 261 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 262 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 263 | } |
| 264 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 265 | /** |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 266 | * Processes incoming interest for "info" interest. Send back reply content back, |
| 267 | * if interest comes from a neighbor with status down, NLSR will send "info" |
| 268 | * ineterst to that neighbor |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 269 | */ |
| 270 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 271 | void |
| 272 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 273 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 274 | if ( nlsr->debugging ) |
| 275 | { |
| 276 | printf("process_incoming_interest_info called \n"); |
| 277 | printf("Sending Info Content back.....\n"); |
| 278 | } |
| 279 | if ( nlsr->detailed_logging ) |
| 280 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 281 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info" |
| 282 | " called \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 283 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 284 | } |
| 285 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 286 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 287 | int res; |
| 288 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 289 | struct ccn_charbuf *name=ccn_charbuf_create(); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 290 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 291 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 292 | res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 293 | 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] | 294 | if (res >= 0) |
| 295 | { |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 296 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 297 | |
| 298 | struct ccn_charbuf *pubid = ccn_charbuf_create(); |
| 299 | struct ccn_charbuf *pubkey = ccn_charbuf_create(); |
| 300 | |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 301 | //pubid is the digest_result pubkey is result |
| 302 | ccn_get_public_key(nlsr->ccn, NULL, pubid, pubkey); |
| 303 | |
| 304 | |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 305 | |
| 306 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 307 | sp.template_ccnb=ccn_charbuf_create(); |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 308 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 309 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG); |
| 310 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyLocator, CCN_DTAG); |
| 311 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyName, CCN_DTAG); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 312 | ccn_charbuf_append_charbuf(sp.template_ccnb, name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 313 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 314 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 315 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 316 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 317 | sp.sp_flags |= CCN_SP_TEMPL_KEY_LOCATOR; |
| 318 | sp.sp_flags |= CCN_SP_FINAL_BLOCK; |
| 319 | sp.type = CCN_CONTENT_KEY; |
akmhoque | 63571b0 | 2013-02-20 08:18:49 -0600 | [diff] [blame] | 320 | sp.freshness = 10; |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 321 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 322 | |
| 323 | /*ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 324 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 325 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 326 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 327 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 328 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 329 | char *raw_data=(char *)malloc(20); |
| 330 | memset(raw_data,0,20); |
| 331 | sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 332 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 333 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, pubkey->buf,pubkey->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 334 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 335 | { |
| 336 | if ( nlsr->debugging ) |
| 337 | printf("Signing info Content is successful \n"); |
| 338 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 339 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content" |
| 340 | " is successful \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 341 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 342 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 343 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 344 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 345 | { |
| 346 | if ( nlsr->debugging ) |
| 347 | printf("Sending Info Content is successful \n"); |
| 348 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 349 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content" |
| 350 | " is successful \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 351 | } |
| 352 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 353 | |
| 354 | |
| 355 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 356 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 357 | |
| 358 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 359 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length, |
| 360 | get_adjacent_status(nbr)); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 361 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 362 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d" |
| 363 | " Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 364 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 365 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 366 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr) >= |
| 367 | nlsr->interest_retry ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 368 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 369 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 370 | send_info_interest_to_neighbor(nbr); |
| 371 | } |
| 372 | |
| 373 | free(nbr); |
| 374 | free(raw_data); |
| 375 | ccn_charbuf_destroy(&sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 376 | ccn_charbuf_destroy(&pubid); |
| 377 | ccn_charbuf_destroy(&pubkey); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 378 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 379 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 380 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 381 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 382 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 386 | /** |
| 387 | * Call back function registered in ccnd to get all content coming to NLSR |
| 388 | * application |
| 389 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 390 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 391 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 392 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 393 | { |
| 394 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 395 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 396 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 397 | switch(kind) { |
| 398 | case CCN_UPCALL_FINAL: |
| 399 | break; |
| 400 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 401 | if ( nlsr->debugging ) |
| 402 | printf("Content Received for Name: "); |
| 403 | if ( nlsr->detailed_logging ) |
| 404 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 405 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 406 | struct ccn_charbuf*c; |
| 407 | c=ccn_charbuf_create(); |
| 408 | 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] | 409 | if ( nlsr->debugging ) |
| 410 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 411 | if ( nlsr->detailed_logging ) |
| 412 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 413 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 414 | ccn_charbuf_destroy(&c); |
| 415 | |
| 416 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 417 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 418 | break; |
| 419 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 420 | //printf("Interest Timed Out Received for Name: "); |
| 421 | if ( nlsr->debugging ) |
| 422 | printf("Interest Timed Out Received for Name: "); |
| 423 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 424 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv" |
| 425 | "ed for Name: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 426 | |
| 427 | struct ccn_charbuf*ito; |
| 428 | ito=ccn_charbuf_create(); |
| 429 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 430 | if ( nlsr->debugging ) |
| 431 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 432 | if ( nlsr->detailed_logging ) |
| 433 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 434 | ccn_charbuf_destroy(&ito); |
| 435 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 436 | |
| 437 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 438 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 439 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 440 | break; |
| 441 | default: |
| 442 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 443 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 444 | printf("Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 445 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 446 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of " |
| 447 | "kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 448 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 449 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 450 | |
| 451 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 452 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 453 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 454 | } |
| 455 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 456 | /** |
| 457 | * process any incoming content to NLSR from ccnd |
| 458 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 459 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 460 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 461 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 462 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 463 | if ( nlsr->debugging ) |
| 464 | printf("process_incoming_content called \n"); |
| 465 | if ( nlsr->detailed_logging ) |
| 466 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 467 | |
| 468 | const unsigned char *comp_ptr1; |
| 469 | size_t comp_size; |
| 470 | int res,i; |
| 471 | int nlsr_position=0; |
| 472 | int name_comps=(int)info->interest_comps->n; |
| 473 | |
| 474 | for(i=0;i<name_comps;i++) |
| 475 | { |
| 476 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 477 | if( res == 0) |
| 478 | { |
| 479 | nlsr_position=i; |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 484 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps, |
| 485 | nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 486 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 487 | |
| 488 | if(!strcmp((char *)comp_ptr1,"info")) |
| 489 | { |
| 490 | process_incoming_content_info(selfp,info); |
| 491 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 492 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 493 | } |
| 494 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 495 | /** |
| 496 | * process any incoming "info" content to NLSR from ccnd |
| 497 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 498 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 499 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 500 | process_incoming_content_info(struct ccn_closure *selfp, |
| 501 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 502 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 503 | if ( nlsr->debugging ) |
| 504 | printf("process_incoming_content_info called \n"); |
| 505 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 506 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info" |
| 507 | " called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 508 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 509 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 510 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 511 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 512 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 513 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name, |
| 514 | nbr->length); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 515 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 516 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Nei" |
| 517 | "ghbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 518 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 519 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 520 | if ( contain_key_name(info->content_ccnb, info->pco) == 1) |
| 521 | { |
| 522 | struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco); |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 523 | struct ccn_charbuf *key_uri = ccn_charbuf_create(); |
| 524 | ccn_uri_append(key_uri, key_name->buf, key_name->length, 1); |
| 525 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 526 | if(nlsr->debugging) |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 527 | printf("Key Name: %s\n",ccn_charbuf_as_string(key_uri)); |
| 528 | |
| 529 | ccn_charbuf_destroy(&key_uri); |
| 530 | ccn_charbuf_destroy(&key_name); |
| 531 | |
| 532 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 533 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 534 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 535 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 536 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 537 | print_adjacent_from_adl(); |
| 538 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 539 | |
| 540 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 541 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 542 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 543 | if ( nlsr->debugging ) |
| 544 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 545 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 546 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Inst" |
| 547 | "all Adj LSA...\n"); |
| 548 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, |
| 549 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 550 | nlsr->is_build_adj_lsa_sheduled=1; |
| 551 | } |
| 552 | else |
| 553 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 554 | if ( nlsr->debugging ) |
| 555 | printf("Build and Install Adj LSA already scheduled\n"); |
| 556 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 557 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA" |
| 558 | " already scheduled\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 559 | } |
| 560 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 561 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 562 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 563 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 564 | |
| 565 | } |
| 566 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 567 | /** |
| 568 | * process any incoming interest timed out content to NLSR from ccnd |
| 569 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 570 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 571 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 572 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 573 | process_incoming_timed_out_interest(struct ccn_closure* selfp, |
| 574 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 575 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 576 | |
| 577 | |
| 578 | if ( nlsr->debugging ) |
| 579 | printf("process_incoming_timed_out_interest called \n"); |
| 580 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 581 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 582 | "erest called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 583 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 584 | int res,i; |
| 585 | int nlsr_position=0; |
| 586 | int name_comps=(int)info->interest_comps->n; |
| 587 | |
| 588 | for(i=0;i<name_comps;i++) |
| 589 | { |
| 590 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 591 | if( res == 0) |
| 592 | { |
| 593 | nlsr_position=i; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 598 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps, |
| 599 | nlsr_position+1,"info") == 0) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 600 | { |
| 601 | process_incoming_timed_out_interest_info(selfp,info); |
| 602 | } |
| 603 | } |
| 604 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 605 | /** |
| 606 | * process any incoming "info" interest timed out content to NLSR from ccnd |
| 607 | */ |
| 608 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 609 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 610 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct |
| 611 | ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 612 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 613 | |
| 614 | if ( nlsr->debugging ) |
| 615 | printf("process_incoming_timed_out_interest_info called \n"); |
| 616 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 617 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 618 | "erest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 619 | |
| 620 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 621 | get_nbr(nbr,selfp,info); |
| 622 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 623 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 624 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n", |
| 625 | nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 626 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 627 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for" |
| 628 | " Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 629 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 630 | |
| 631 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 632 | update_adjacent_timed_out_to_adl(nbr,1); |
| 633 | print_adjacent_from_adl(); |
| 634 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 635 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 636 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 637 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name, |
| 638 | timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 639 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 640 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest " |
| 641 | "Timed Out: %d times\n",nbr->name,timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 642 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 643 | |
| 644 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 645 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 646 | send_info_interest_to_neighbor(nbr); |
| 647 | } |
| 648 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 649 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 650 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 651 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 652 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 653 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, |
| 654 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 655 | nlsr->is_build_adj_lsa_sheduled=1; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 660 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 661 | |
| 662 | } |
| 663 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 664 | /** |
| 665 | * send "info" interest to each and every neighbor in ADL and also schedule for |
| 666 | * itself for periodical sending of "info" interest |
| 667 | */ |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 668 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 669 | int |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 670 | send_info_interest(struct ccn_schedule *sched, void *clienth, |
| 671 | struct ccn_scheduled_event *ev, int flags) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 672 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 673 | if(flags == CCN_SCHEDULE_CANCEL) |
| 674 | { |
| 675 | return -1; |
| 676 | } |
| 677 | |
| 678 | nlsr_lock(); |
| 679 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 680 | if ( nlsr->debugging ) |
| 681 | printf("send_info_interest called \n"); |
| 682 | if ( nlsr->detailed_logging ) |
| 683 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 684 | |
| 685 | if ( nlsr->debugging ) |
| 686 | printf("\n"); |
| 687 | if ( nlsr->detailed_logging ) |
| 688 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 689 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 690 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 691 | struct ndn_neighbor *nbr; |
| 692 | |
| 693 | struct hashtb_enumerator ee; |
| 694 | struct hashtb_enumerator *e = ⅇ |
| 695 | |
| 696 | hashtb_start(nlsr->adl, e); |
| 697 | adl_element=hashtb_n(nlsr->adl); |
| 698 | |
| 699 | for(i=0;i<adl_element;i++) |
| 700 | { |
| 701 | nbr=e->data; |
| 702 | send_info_interest_to_neighbor(nbr->neighbor); |
| 703 | hashtb_next(e); |
| 704 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 705 | hashtb_end(e); |
| 706 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 707 | nlsr_unlock(); |
| 708 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 709 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, |
| 710 | NULL, 0); |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 711 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 712 | return 0; |
| 713 | } |
| 714 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 715 | |
| 716 | /** |
| 717 | * send "info" interest neighbor nbr |
| 718 | * |
| 719 | */ |
| 720 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 721 | void |
| 722 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 723 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 724 | |
| 725 | if ( nlsr->debugging ) |
| 726 | printf("send_info_interest_to_neighbor called \n"); |
| 727 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 728 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor" |
| 729 | " called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 730 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 731 | |
| 732 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 733 | char info_str[5]; |
| 734 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 735 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 736 | memset(&nlsr_str,0,5); |
| 737 | sprintf(nlsr_str,"nlsr"); |
| 738 | memset(&info_str,0,5); |
| 739 | sprintf(info_str,"info"); |
| 740 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 741 | |
| 742 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 743 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 744 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 745 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+ |
| 746 | strlen(info_str)+strlen(nlsr->router_name)+1); |
| 747 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+ |
| 748 | strlen(nlsr->router_name)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 749 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 750 | memcpy(int_name+strlen(int_name),"/",1); |
| 751 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 752 | memcpy(int_name+strlen(int_name),"/",1); |
| 753 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 754 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 755 | |
| 756 | |
| 757 | res=ccn_name_from_uri(name,int_name); |
| 758 | if ( res >=0 ) |
| 759 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 760 | /* adding InterestLifeTime and InterestScope filter */ |
| 761 | |
| 762 | struct ccn_charbuf *templ; |
| 763 | templ = ccn_charbuf_create(); |
| 764 | |
| 765 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 766 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 767 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 768 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 769 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 770 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 771 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 |
| 772 | //(not further than next host) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 773 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 774 | |
| 775 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 776 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 777 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 778 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 779 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 780 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 781 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 782 | printf("Sending info interest on name prefix : %s through Face:%u\n" |
| 783 | ,int_name,face_id); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 784 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 785 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on" |
| 786 | "name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 787 | |
| 788 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 789 | |
| 790 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 791 | { |
| 792 | if ( nlsr->debugging ) |
| 793 | printf("Info interest sending Successfull .... \n"); |
| 794 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 795 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info" |
| 796 | "interest sending Successfull .... \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 797 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 798 | ccn_charbuf_destroy(&templ); |
| 799 | } |
| 800 | ccn_charbuf_destroy(&name); |
| 801 | free(int_name); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 802 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 803 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 804 | /** |
| 805 | * Check whether content name contains a key name. Return 1 for containing |
| 806 | */ |
| 807 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 808 | int |
| 809 | contain_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco) |
| 810 | { |
| 811 | if (pco->offset[CCN_PCO_B_KeyLocator] == pco->offset[CCN_PCO_E_KeyLocator]) |
| 812 | return -1; |
| 813 | |
| 814 | struct ccn_buf_decoder decoder; |
| 815 | struct ccn_buf_decoder *d; |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 816 | d = ccn_buf_decoder_start(&decoder, ccnb + |
| 817 | pco->offset[CCN_PCO_B_Key_Certificate_KeyName], |
| 818 | pco->offset[CCN_PCO_E_Key_Certificate_KeyName] - |
| 819 | pco->offset[CCN_PCO_B_Key_Certificate_KeyName]); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 820 | if (ccn_buf_match_dtag(d, CCN_DTAG_KeyName)) |
| 821 | return 1; |
| 822 | |
| 823 | return -1; |
| 824 | } |
| 825 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 826 | /** |
| 827 | * Extract Key Name from Content Name and return the Key Name |
| 828 | * |
| 829 | */ |
| 830 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 831 | struct ccn_charbuf * |
| 832 | get_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco) |
| 833 | { |
| 834 | struct ccn_charbuf *key_name = ccn_charbuf_create(); |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 835 | ccn_charbuf_append(key_name, ccnb + pco->offset[CCN_PCO_B_KeyName_Name], |
| 836 | pco->offset[CCN_PCO_E_KeyName_Name] - pco->offset[CCN_PCO_B_KeyName_Name]); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 837 | |
| 838 | return key_name; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 839 | } |