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