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 | /** |
| 266 | * |
| 267 | */ |
| 268 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 269 | void |
| 270 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 271 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 272 | if ( nlsr->debugging ) |
| 273 | { |
| 274 | printf("process_incoming_interest_info called \n"); |
| 275 | printf("Sending Info Content back.....\n"); |
| 276 | } |
| 277 | if ( nlsr->detailed_logging ) |
| 278 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 279 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info" |
| 280 | " called \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 281 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 282 | } |
| 283 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 284 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 285 | int res; |
| 286 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 287 | struct ccn_charbuf *name=ccn_charbuf_create(); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 288 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 289 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 290 | res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 291 | 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] | 292 | if (res >= 0) |
| 293 | { |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 294 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 295 | |
| 296 | struct ccn_charbuf *pubid = ccn_charbuf_create(); |
| 297 | struct ccn_charbuf *pubkey = ccn_charbuf_create(); |
| 298 | |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 299 | //pubid is the digest_result pubkey is result |
| 300 | ccn_get_public_key(nlsr->ccn, NULL, pubid, pubkey); |
| 301 | |
| 302 | |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 303 | |
| 304 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 305 | sp.template_ccnb=ccn_charbuf_create(); |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 306 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 307 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG); |
| 308 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyLocator, CCN_DTAG); |
| 309 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyName, CCN_DTAG); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 310 | ccn_charbuf_append_charbuf(sp.template_ccnb, name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 311 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 312 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 313 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | dd7a7a7 | 2013-02-20 08:25:41 -0600 | [diff] [blame] | 314 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 315 | sp.sp_flags |= CCN_SP_TEMPL_KEY_LOCATOR; |
| 316 | sp.sp_flags |= CCN_SP_FINAL_BLOCK; |
| 317 | sp.type = CCN_CONTENT_KEY; |
akmhoque | 63571b0 | 2013-02-20 08:18:49 -0600 | [diff] [blame] | 318 | sp.freshness = 10; |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 319 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 320 | |
| 321 | /*ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 322 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 323 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 324 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 325 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 326 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 327 | char *raw_data=(char *)malloc(20); |
| 328 | memset(raw_data,0,20); |
| 329 | sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 330 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 331 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, pubkey->buf,pubkey->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 332 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 333 | { |
| 334 | if ( nlsr->debugging ) |
| 335 | printf("Signing info Content is successful \n"); |
| 336 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 337 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content" |
| 338 | " is successful \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 339 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 340 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 341 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 342 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 343 | { |
| 344 | if ( nlsr->debugging ) |
| 345 | printf("Sending Info Content is successful \n"); |
| 346 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 347 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content" |
| 348 | " is successful \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 349 | } |
| 350 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 351 | |
| 352 | |
| 353 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 354 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 355 | |
| 356 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 357 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length, |
| 358 | get_adjacent_status(nbr)); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 359 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 360 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d" |
| 361 | " Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 362 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 363 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 364 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr) >= |
| 365 | nlsr->interest_retry ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 366 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 367 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 368 | send_info_interest_to_neighbor(nbr); |
| 369 | } |
| 370 | |
| 371 | free(nbr); |
| 372 | free(raw_data); |
| 373 | ccn_charbuf_destroy(&sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 374 | ccn_charbuf_destroy(&pubid); |
| 375 | ccn_charbuf_destroy(&pubkey); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 376 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 377 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 378 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 379 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 380 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 384 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 385 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 386 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 387 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 388 | { |
| 389 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 390 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 391 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 392 | switch(kind) { |
| 393 | case CCN_UPCALL_FINAL: |
| 394 | break; |
| 395 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 396 | if ( nlsr->debugging ) |
| 397 | printf("Content Received for Name: "); |
| 398 | if ( nlsr->detailed_logging ) |
| 399 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 400 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 401 | struct ccn_charbuf*c; |
| 402 | c=ccn_charbuf_create(); |
| 403 | 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] | 404 | if ( nlsr->debugging ) |
| 405 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 406 | if ( nlsr->detailed_logging ) |
| 407 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 408 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 409 | ccn_charbuf_destroy(&c); |
| 410 | |
| 411 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 412 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 413 | break; |
| 414 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 415 | //printf("Interest Timed Out Received for Name: "); |
| 416 | if ( nlsr->debugging ) |
| 417 | printf("Interest Timed Out Received for Name: "); |
| 418 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 419 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv" |
| 420 | "ed for Name: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 421 | |
| 422 | struct ccn_charbuf*ito; |
| 423 | ito=ccn_charbuf_create(); |
| 424 | 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] | 425 | if ( nlsr->debugging ) |
| 426 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 427 | if ( nlsr->detailed_logging ) |
| 428 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 429 | ccn_charbuf_destroy(&ito); |
| 430 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 431 | |
| 432 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 433 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 434 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 435 | break; |
| 436 | default: |
| 437 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 438 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 439 | printf("Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 440 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 441 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of " |
| 442 | "kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 443 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 444 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 445 | |
| 446 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 447 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 448 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 449 | } |
| 450 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 451 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 452 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 453 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 454 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 455 | if ( nlsr->debugging ) |
| 456 | printf("process_incoming_content called \n"); |
| 457 | if ( nlsr->detailed_logging ) |
| 458 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 459 | |
| 460 | const unsigned char *comp_ptr1; |
| 461 | size_t comp_size; |
| 462 | int res,i; |
| 463 | int nlsr_position=0; |
| 464 | int name_comps=(int)info->interest_comps->n; |
| 465 | |
| 466 | for(i=0;i<name_comps;i++) |
| 467 | { |
| 468 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 469 | if( res == 0) |
| 470 | { |
| 471 | nlsr_position=i; |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 476 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps, |
| 477 | nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 478 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 479 | |
| 480 | if(!strcmp((char *)comp_ptr1,"info")) |
| 481 | { |
| 482 | process_incoming_content_info(selfp,info); |
| 483 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 484 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 485 | } |
| 486 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 487 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 488 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 489 | process_incoming_content_info(struct ccn_closure *selfp, |
| 490 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 491 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 492 | if ( nlsr->debugging ) |
| 493 | printf("process_incoming_content_info called \n"); |
| 494 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 495 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info" |
| 496 | " called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 497 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 498 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 499 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 500 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 501 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 502 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name, |
| 503 | nbr->length); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 504 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 505 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Nei" |
| 506 | "ghbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 507 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 508 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 509 | if ( contain_key_name(info->content_ccnb, info->pco) == 1) |
| 510 | { |
| 511 | struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco); |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 512 | struct ccn_charbuf *key_uri = ccn_charbuf_create(); |
| 513 | ccn_uri_append(key_uri, key_name->buf, key_name->length, 1); |
| 514 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 515 | if(nlsr->debugging) |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 516 | printf("Key Name: %s\n",ccn_charbuf_as_string(key_uri)); |
| 517 | |
| 518 | ccn_charbuf_destroy(&key_uri); |
| 519 | ccn_charbuf_destroy(&key_name); |
| 520 | |
| 521 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 522 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 523 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 524 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 525 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 526 | print_adjacent_from_adl(); |
| 527 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 528 | |
| 529 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 530 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 531 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 532 | if ( nlsr->debugging ) |
| 533 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 534 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 535 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Inst" |
| 536 | "all Adj LSA...\n"); |
| 537 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, |
| 538 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 539 | nlsr->is_build_adj_lsa_sheduled=1; |
| 540 | } |
| 541 | else |
| 542 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 543 | if ( nlsr->debugging ) |
| 544 | printf("Build and Install Adj LSA already scheduled\n"); |
| 545 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 546 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA" |
| 547 | " already scheduled\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 548 | } |
| 549 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 550 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 551 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 552 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 553 | |
| 554 | } |
| 555 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 556 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 557 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 558 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 559 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 560 | process_incoming_timed_out_interest(struct ccn_closure* selfp, |
| 561 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 562 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 563 | |
| 564 | |
| 565 | if ( nlsr->debugging ) |
| 566 | printf("process_incoming_timed_out_interest called \n"); |
| 567 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 568 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 569 | "erest called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 570 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 571 | int res,i; |
| 572 | int nlsr_position=0; |
| 573 | int name_comps=(int)info->interest_comps->n; |
| 574 | |
| 575 | for(i=0;i<name_comps;i++) |
| 576 | { |
| 577 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 578 | if( res == 0) |
| 579 | { |
| 580 | nlsr_position=i; |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 585 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps, |
| 586 | nlsr_position+1,"info") == 0) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 587 | { |
| 588 | process_incoming_timed_out_interest_info(selfp,info); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 593 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct |
| 594 | ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 595 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 596 | |
| 597 | if ( nlsr->debugging ) |
| 598 | printf("process_incoming_timed_out_interest_info called \n"); |
| 599 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 600 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 601 | "erest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 602 | |
| 603 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 604 | get_nbr(nbr,selfp,info); |
| 605 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 606 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 607 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n", |
| 608 | nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 609 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 610 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for" |
| 611 | " Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 612 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 613 | |
| 614 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 615 | update_adjacent_timed_out_to_adl(nbr,1); |
| 616 | print_adjacent_from_adl(); |
| 617 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 618 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 619 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 620 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name, |
| 621 | timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 622 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 623 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest " |
| 624 | "Timed Out: %d times\n",nbr->name,timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 625 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 626 | |
| 627 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 628 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 629 | send_info_interest_to_neighbor(nbr); |
| 630 | } |
| 631 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 632 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 633 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 634 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 635 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 636 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, |
| 637 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 638 | nlsr->is_build_adj_lsa_sheduled=1; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 643 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 644 | |
| 645 | } |
| 646 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 647 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 648 | int |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 649 | send_info_interest(struct ccn_schedule *sched, void *clienth, |
| 650 | struct ccn_scheduled_event *ev, int flags) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 651 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 652 | if(flags == CCN_SCHEDULE_CANCEL) |
| 653 | { |
| 654 | return -1; |
| 655 | } |
| 656 | |
| 657 | nlsr_lock(); |
| 658 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 659 | if ( nlsr->debugging ) |
| 660 | printf("send_info_interest called \n"); |
| 661 | if ( nlsr->detailed_logging ) |
| 662 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 663 | |
| 664 | if ( nlsr->debugging ) |
| 665 | printf("\n"); |
| 666 | if ( nlsr->detailed_logging ) |
| 667 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 668 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 669 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 670 | struct ndn_neighbor *nbr; |
| 671 | |
| 672 | struct hashtb_enumerator ee; |
| 673 | struct hashtb_enumerator *e = ⅇ |
| 674 | |
| 675 | hashtb_start(nlsr->adl, e); |
| 676 | adl_element=hashtb_n(nlsr->adl); |
| 677 | |
| 678 | for(i=0;i<adl_element;i++) |
| 679 | { |
| 680 | nbr=e->data; |
| 681 | send_info_interest_to_neighbor(nbr->neighbor); |
| 682 | hashtb_next(e); |
| 683 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 684 | hashtb_end(e); |
| 685 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 686 | nlsr_unlock(); |
| 687 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 688 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, |
| 689 | NULL, 0); |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 690 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | void |
| 695 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 696 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 697 | |
| 698 | if ( nlsr->debugging ) |
| 699 | printf("send_info_interest_to_neighbor called \n"); |
| 700 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 701 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor" |
| 702 | " called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 703 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 704 | |
| 705 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 706 | char info_str[5]; |
| 707 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 708 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 709 | memset(&nlsr_str,0,5); |
| 710 | sprintf(nlsr_str,"nlsr"); |
| 711 | memset(&info_str,0,5); |
| 712 | sprintf(info_str,"info"); |
| 713 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 714 | |
| 715 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 716 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 717 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 718 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+ |
| 719 | strlen(info_str)+strlen(nlsr->router_name)+1); |
| 720 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+ |
| 721 | strlen(nlsr->router_name)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 722 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 723 | memcpy(int_name+strlen(int_name),"/",1); |
| 724 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 725 | memcpy(int_name+strlen(int_name),"/",1); |
| 726 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 727 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 728 | |
| 729 | |
| 730 | res=ccn_name_from_uri(name,int_name); |
| 731 | if ( res >=0 ) |
| 732 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 733 | /* adding InterestLifeTime and InterestScope filter */ |
| 734 | |
| 735 | struct ccn_charbuf *templ; |
| 736 | templ = ccn_charbuf_create(); |
| 737 | |
| 738 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 739 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 740 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 741 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 742 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 743 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 744 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 |
| 745 | //(not further than next host) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 746 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 747 | |
| 748 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 749 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 750 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 751 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 752 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 753 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 754 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 755 | printf("Sending info interest on name prefix : %s through Face:%u\n" |
| 756 | ,int_name,face_id); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 757 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 758 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on" |
| 759 | "name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 760 | |
| 761 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 762 | |
| 763 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 764 | { |
| 765 | if ( nlsr->debugging ) |
| 766 | printf("Info interest sending Successfull .... \n"); |
| 767 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 768 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info" |
| 769 | "interest sending Successfull .... \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 770 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 771 | ccn_charbuf_destroy(&templ); |
| 772 | } |
| 773 | ccn_charbuf_destroy(&name); |
| 774 | free(int_name); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 775 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 776 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 777 | int |
| 778 | contain_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco) |
| 779 | { |
| 780 | if (pco->offset[CCN_PCO_B_KeyLocator] == pco->offset[CCN_PCO_E_KeyLocator]) |
| 781 | return -1; |
| 782 | |
| 783 | struct ccn_buf_decoder decoder; |
| 784 | struct ccn_buf_decoder *d; |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 785 | d = ccn_buf_decoder_start(&decoder, ccnb + |
| 786 | pco->offset[CCN_PCO_B_Key_Certificate_KeyName], |
| 787 | pco->offset[CCN_PCO_E_Key_Certificate_KeyName] - |
| 788 | pco->offset[CCN_PCO_B_Key_Certificate_KeyName]); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 789 | if (ccn_buf_match_dtag(d, CCN_DTAG_KeyName)) |
| 790 | return 1; |
| 791 | |
| 792 | return -1; |
| 793 | } |
| 794 | |
| 795 | struct ccn_charbuf * |
| 796 | get_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco) |
| 797 | { |
| 798 | struct ccn_charbuf *key_name = ccn_charbuf_create(); |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 799 | ccn_charbuf_append(key_name, ccnb + pco->offset[CCN_PCO_B_KeyName_Name], |
| 800 | 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] | 801 | |
| 802 | return key_name; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 803 | } |