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