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