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); |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame^] | 285 | */ |
akmhoque | 7ca519b | 2013-02-20 09:49:43 -0600 | [diff] [blame] | 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 | 4ef95e7 | 2013-03-22 09:51:54 -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 | |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame^] | 304 | /* |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 305 | res=sign_content_with_user_defined_keystore(name, |
| 306 | resultbuf, |
| 307 | "info", |
| 308 | strlen("info"), |
| 309 | nlsr->keystore_path, |
| 310 | nlsr->keystore_passphrase, |
| 311 | nlsr->root_key_prefix, |
| 312 | nlsr->site_name, |
akmhoque | 2fafaa5 | 2013-03-22 05:10:52 -0500 | [diff] [blame] | 313 | nlsr->router_name, |
| 314 | 10); |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame^] | 315 | |
| 316 | */ |
| 317 | res= ccn_sign_content(nlsr->ccn, resultbuf, 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 | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame^] | 327 | |
| 328 | res=ccn_put(nlsr->ccn,resultbuf->buf,resultbuf->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 329 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 330 | { |
| 331 | if ( nlsr->debugging ) |
| 332 | printf("Sending Info Content is successful \n"); |
| 333 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 334 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content" |
| 335 | " is successful \n"); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 336 | } |
| 337 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 338 | |
| 339 | |
akmhoque | e1dd777 | 2013-02-24 14:21:49 -0600 | [diff] [blame] | 340 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 341 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 342 | |
| 343 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 344 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length, |
| 345 | get_adjacent_status(nbr)); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 346 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 347 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d" |
| 348 | " Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 349 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 350 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 351 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr) >= |
| 352 | nlsr->interest_retry ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 353 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 354 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 355 | send_info_interest_to_neighbor(nbr); |
| 356 | } |
| 357 | |
akmhoque | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 358 | if ( nbr->name != NULL ) |
| 359 | free(nbr->name); |
| 360 | if ( nbr != NULL ) |
| 361 | free(nbr); |
akmhoque | 284056b | 2013-03-15 01:20:16 -0500 | [diff] [blame] | 362 | ccn_charbuf_destroy(&resultbuf); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 363 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 364 | |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 365 | //ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 366 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 367 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 371 | /** |
| 372 | * Call back function registered in ccnd to get all content coming to NLSR |
| 373 | * application |
| 374 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 375 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 376 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 377 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 378 | { |
| 379 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 380 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 381 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 382 | switch(kind) { |
| 383 | case CCN_UPCALL_FINAL: |
| 384 | break; |
| 385 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 386 | if ( nlsr->debugging ) |
| 387 | printf("Content Received for Name: "); |
| 388 | if ( nlsr->detailed_logging ) |
| 389 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 390 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 391 | struct ccn_charbuf*c; |
| 392 | c=ccn_charbuf_create(); |
| 393 | 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] | 394 | if ( nlsr->debugging ) |
| 395 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 396 | if ( nlsr->detailed_logging ) |
| 397 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 398 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 399 | ccn_charbuf_destroy(&c); |
| 400 | |
| 401 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 402 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 403 | break; |
| 404 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 405 | //printf("Interest Timed Out Received for Name: "); |
| 406 | if ( nlsr->debugging ) |
| 407 | printf("Interest Timed Out Received for Name: "); |
| 408 | if ( nlsr->detailed_logging ) |
| 409 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv" |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 410 | "ed for Name: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 411 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 412 | struct ccn_charbuf*ito; |
| 413 | ito=ccn_charbuf_create(); |
| 414 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 415 | if ( nlsr->debugging ) |
| 416 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 417 | if ( nlsr->detailed_logging ) |
| 418 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
| 419 | ccn_charbuf_destroy(&ito); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 420 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 421 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 422 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 423 | break; |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 424 | |
| 425 | case CCN_UPCALL_CONTENT_UNVERIFIED: |
| 426 | if ( nlsr->debugging ) |
| 427 | printf("Unverified Content Received ..Waiting for verification\n"); |
| 428 | if ( nlsr->detailed_logging ) |
| 429 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unverified Content" |
| 430 | " Received ..Waiting for verification\n"); |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 431 | //return CCN_UPCALL_RESULT_VERIFY; |
akmhoque | 4637d9d | 2013-03-08 06:52:00 -0600 | [diff] [blame] | 432 | process_incoming_content(selfp,info); |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 433 | break; |
| 434 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 435 | default: |
| 436 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 437 | if ( nlsr->debugging ) |
| 438 | printf("Unexpected response of kind %d\n", kind); |
| 439 | if ( nlsr->detailed_logging ) |
| 440 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of " |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 441 | "kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 442 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 443 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 444 | |
| 445 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 446 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 447 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 448 | } |
| 449 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 450 | /** |
| 451 | * process any incoming content to NLSR from ccnd |
| 452 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 453 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 454 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 455 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 456 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 457 | if ( nlsr->debugging ) |
| 458 | printf("process_incoming_content called \n"); |
| 459 | if ( nlsr->detailed_logging ) |
| 460 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 461 | |
| 462 | const unsigned char *comp_ptr1; |
| 463 | size_t comp_size; |
| 464 | int res,i; |
| 465 | int nlsr_position=0; |
| 466 | int name_comps=(int)info->interest_comps->n; |
| 467 | |
| 468 | for(i=0;i<name_comps;i++) |
| 469 | { |
| 470 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 471 | if( res == 0) |
| 472 | { |
| 473 | nlsr_position=i; |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 478 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps, |
| 479 | nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 480 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 481 | |
| 482 | if(!strcmp((char *)comp_ptr1,"info")) |
| 483 | { |
| 484 | process_incoming_content_info(selfp,info); |
| 485 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 486 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 487 | } |
| 488 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 489 | /** |
| 490 | * process any incoming "info" content to NLSR from ccnd |
| 491 | */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 492 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 493 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 494 | process_incoming_content_info(struct ccn_closure *selfp, |
| 495 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 496 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 497 | if ( nlsr->debugging ) |
| 498 | printf("process_incoming_content_info called \n"); |
| 499 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 500 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info" |
| 501 | " called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 502 | |
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 | 4ef95e7 | 2013-03-22 09:51:54 -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){ |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 516 | int res_verify=-1; |
| 517 | int key_exists=0; |
| 518 | struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco); |
| 519 | struct ccn_charbuf *key_uri = ccn_charbuf_create(); |
| 520 | ccn_uri_append(key_uri, key_name->buf, key_name->length, 0); |
| 521 | key_exists=does_key_exist(ccn_charbuf_as_string(key_uri)); |
| 522 | int key_type=get_key_type_from_key_name(key_name); |
| 523 | |
| 524 | if ( res_verify == 1 && key_type == NLSR_KEY ){ |
| 525 | res_verify=0; |
| 526 | } |
| 527 | else{ |
| 528 | res_verify=verify_key(info->content_ccnb,info->pco,0); |
| 529 | } |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 530 | |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 531 | //int res_verify=verify_key(info->content_ccnb,info->pco,0); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 532 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 533 | if ( res_verify != 0 ){ |
akmhoque | 1162d85 | 2013-03-15 01:07:00 -0500 | [diff] [blame] | 534 | if ( nlsr->debugging ) |
| 535 | printf("Error in verfiying keys !! :( \n"); |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 536 | ccn_charbuf_destroy(&key_name); |
| 537 | ccn_charbuf_destroy(&key_uri); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 538 | } |
| 539 | else{ |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 540 | if ( key_exists == 0 ) |
| 541 | add_key(ccn_charbuf_as_string(key_uri)); |
| 542 | ccn_charbuf_destroy(&key_name); |
| 543 | ccn_charbuf_destroy(&key_uri); |
akmhoque | 1162d85 | 2013-03-15 01:07:00 -0500 | [diff] [blame] | 544 | if ( nlsr->debugging ) |
| 545 | printf("Key verification is successful :)\n"); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 546 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 547 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 548 | print_adjacent_from_adl(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 549 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 550 | if(!nlsr->is_build_adj_lsa_sheduled){ |
| 551 | if ( nlsr->debugging ) |
| 552 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 553 | if ( nlsr->detailed_logging ) |
| 554 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling" |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 555 | "Build and Install Adj LSA...\n"); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 556 | nlsr->event_build_adj_lsa = ccn_schedule_event( |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 557 | nlsr->sched, 100000, |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 558 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 559 | nlsr->is_build_adj_lsa_sheduled=1; |
| 560 | } |
| 561 | else{ |
| 562 | if ( nlsr->debugging ) |
| 563 | printf("Build and Install Adj LSA already scheduled\n"); |
| 564 | if ( nlsr->detailed_logging ) |
| 565 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA" |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 566 | " already scheduled\n"); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 567 | } |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 568 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame] | 569 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 570 | } |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame^] | 571 | */ |
| 572 | |
akmhoque | 10c9a21 | 2013-03-08 07:05:18 -0600 | [diff] [blame] | 573 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 574 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 575 | print_adjacent_from_adl(); |
| 576 | |
| 577 | if(!nlsr->is_build_adj_lsa_sheduled){ |
| 578 | if ( nlsr->debugging ) |
| 579 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 580 | if ( nlsr->detailed_logging ) |
| 581 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling" |
| 582 | "Build and Install Adj LSA...\n"); |
| 583 | nlsr->event_build_adj_lsa = ccn_schedule_event( |
| 584 | nlsr->sched, 100000, |
| 585 | &build_and_install_adj_lsa, NULL, 0); |
| 586 | nlsr->is_build_adj_lsa_sheduled=1; |
| 587 | } |
| 588 | else{ |
| 589 | if ( nlsr->debugging ) |
| 590 | printf("Build and Install Adj LSA already scheduled\n"); |
| 591 | if ( nlsr->detailed_logging ) |
| 592 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA" |
| 593 | " already scheduled\n"); |
| 594 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 595 | |
akmhoque | 4ef95e7 | 2013-03-22 09:51:54 -0500 | [diff] [blame^] | 596 | |
akmhoque | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 597 | if ( nbr->name != NULL ) |
| 598 | free(nbr->name); |
| 599 | if ( nbr != NULL ) |
| 600 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 601 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 602 | |
| 603 | } |
| 604 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 605 | /** |
| 606 | * process any incoming interest timed out content to NLSR from ccnd |
| 607 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 608 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 609 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 610 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 611 | process_incoming_timed_out_interest(struct ccn_closure* selfp, |
| 612 | struct ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 613 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 614 | |
| 615 | |
| 616 | if ( nlsr->debugging ) |
| 617 | printf("process_incoming_timed_out_interest called \n"); |
| 618 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 619 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 620 | "erest called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 621 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 622 | int res,i; |
| 623 | int nlsr_position=0; |
| 624 | int name_comps=(int)info->interest_comps->n; |
| 625 | |
| 626 | for(i=0;i<name_comps;i++) |
| 627 | { |
| 628 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 629 | if( res == 0) |
| 630 | { |
| 631 | nlsr_position=i; |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 636 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps, |
| 637 | nlsr_position+1,"info") == 0) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 638 | { |
| 639 | process_incoming_timed_out_interest_info(selfp,info); |
| 640 | } |
| 641 | } |
| 642 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 643 | /** |
| 644 | * process any incoming "info" interest timed out content to NLSR from ccnd |
| 645 | */ |
| 646 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 647 | void |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 648 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct |
| 649 | ccn_upcall_info* info) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 650 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 651 | |
| 652 | if ( nlsr->debugging ) |
| 653 | printf("process_incoming_timed_out_interest_info called \n"); |
| 654 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 655 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int" |
| 656 | "erest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 657 | |
| 658 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 659 | get_nbr(nbr,selfp,info); |
| 660 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 661 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 662 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n", |
| 663 | nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 664 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 665 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for" |
| 666 | " Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 667 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 668 | |
| 669 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 670 | update_adjacent_timed_out_to_adl(nbr,1); |
| 671 | print_adjacent_from_adl(); |
| 672 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 673 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 674 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 675 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name, |
| 676 | timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 677 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 678 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest " |
| 679 | "Timed Out: %d times\n",nbr->name,timed_out); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 680 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 681 | |
| 682 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 683 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 684 | send_info_interest_to_neighbor(nbr); |
| 685 | } |
| 686 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 687 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 688 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 689 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 690 | { |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 691 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, |
| 692 | &build_and_install_adj_lsa, NULL, 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 693 | nlsr->is_build_adj_lsa_sheduled=1; |
| 694 | } |
| 695 | } |
| 696 | |
akmhoque | 284056b | 2013-03-15 01:20:16 -0500 | [diff] [blame] | 697 | if ( nbr->name != NULL ) |
| 698 | free(nbr->name); |
| 699 | if ( nbr != NULL ) |
| 700 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 701 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 702 | |
| 703 | } |
| 704 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 705 | /** |
| 706 | * send "info" interest to each and every neighbor in ADL and also schedule for |
| 707 | * itself for periodical sending of "info" interest |
| 708 | */ |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 709 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 710 | int |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 711 | send_info_interest(struct ccn_schedule *sched, void *clienth, |
| 712 | struct ccn_scheduled_event *ev, int flags) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 713 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 714 | if(flags == CCN_SCHEDULE_CANCEL) |
| 715 | { |
| 716 | return -1; |
| 717 | } |
| 718 | |
| 719 | nlsr_lock(); |
| 720 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 721 | if ( nlsr->debugging ) |
| 722 | printf("send_info_interest called \n"); |
| 723 | if ( nlsr->detailed_logging ) |
| 724 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 725 | |
| 726 | if ( nlsr->debugging ) |
| 727 | printf("\n"); |
| 728 | if ( nlsr->detailed_logging ) |
| 729 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 730 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 731 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 732 | struct ndn_neighbor *nbr; |
| 733 | |
| 734 | struct hashtb_enumerator ee; |
| 735 | struct hashtb_enumerator *e = ⅇ |
| 736 | |
| 737 | hashtb_start(nlsr->adl, e); |
| 738 | adl_element=hashtb_n(nlsr->adl); |
| 739 | |
| 740 | for(i=0;i<adl_element;i++) |
| 741 | { |
| 742 | nbr=e->data; |
| 743 | send_info_interest_to_neighbor(nbr->neighbor); |
| 744 | hashtb_next(e); |
| 745 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 746 | hashtb_end(e); |
| 747 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 748 | nlsr_unlock(); |
| 749 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 750 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, |
| 751 | NULL, 0); |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 752 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 753 | return 0; |
| 754 | } |
| 755 | |
akmhoque | 7ab49a3 | 2013-02-20 11:27:51 -0600 | [diff] [blame] | 756 | |
| 757 | /** |
| 758 | * send "info" interest neighbor nbr |
| 759 | * |
| 760 | */ |
| 761 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 762 | void |
| 763 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 764 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 765 | |
| 766 | if ( nlsr->debugging ) |
| 767 | printf("send_info_interest_to_neighbor called \n"); |
| 768 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 769 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor" |
| 770 | " called \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 771 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 772 | |
| 773 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 774 | char info_str[5]; |
| 775 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 776 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 777 | memset(&nlsr_str,0,5); |
| 778 | sprintf(nlsr_str,"nlsr"); |
| 779 | memset(&info_str,0,5); |
| 780 | sprintf(info_str,"info"); |
| 781 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 782 | |
| 783 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 784 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 785 | |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 786 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+ |
| 787 | strlen(info_str)+strlen(nlsr->router_name)+1); |
| 788 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+ |
| 789 | strlen(nlsr->router_name)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 790 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 791 | memcpy(int_name+strlen(int_name),"/",1); |
| 792 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 793 | memcpy(int_name+strlen(int_name),"/",1); |
| 794 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 795 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 796 | |
| 797 | |
| 798 | res=ccn_name_from_uri(name,int_name); |
| 799 | if ( res >=0 ) |
| 800 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 801 | /* adding InterestLifeTime and InterestScope filter */ |
| 802 | |
| 803 | struct ccn_charbuf *templ; |
| 804 | templ = ccn_charbuf_create(); |
| 805 | |
| 806 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 807 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 808 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 809 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 810 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 811 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 812 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 |
| 813 | //(not further than next host) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 814 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 815 | |
| 816 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 817 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 818 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 819 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 820 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 821 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 822 | if ( nlsr->debugging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 823 | printf("Sending info interest on name prefix : %s through Face:%u\n" |
| 824 | ,int_name,face_id); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 825 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 826 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on" |
| 827 | "name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 828 | |
| 829 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 830 | |
| 831 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 832 | { |
| 833 | if ( nlsr->debugging ) |
| 834 | printf("Info interest sending Successfull .... \n"); |
| 835 | if ( nlsr->detailed_logging ) |
akmhoque | 3d319d4 | 2013-02-20 11:08:32 -0600 | [diff] [blame] | 836 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info" |
| 837 | "interest sending Successfull .... \n"); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 838 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 839 | ccn_charbuf_destroy(&templ); |
| 840 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 841 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 842 | ccn_charbuf_destroy(&name); |
| 843 | free(int_name); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame] | 844 | } |