akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [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 <sys/stat.h> |
| 8 | #include <assert.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <signal.h> |
| 11 | #include <sys/socket.h> |
| 12 | #include <sys/un.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <netinet/in.h> |
| 16 | #include <netdb.h> |
| 17 | #include <arpa/inet.h> |
| 18 | |
| 19 | #include <ccn/ccn.h> |
| 20 | #include <ccn/uri.h> |
| 21 | #include <ccn/keystore.h> |
| 22 | #include <ccn/signing.h> |
| 23 | #include <ccn/schedule.h> |
| 24 | #include <ccn/hashtb.h> |
| 25 | #include <ccn/sync.h> |
| 26 | #include <ccn/seqwriter.h> |
| 27 | |
| 28 | #include "nlsr.h" |
| 29 | #include "nlsr_sync.h" |
| 30 | #include "nlsr_lsdb.h" |
| 31 | #include "utility.h" |
| 32 | |
| 33 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 34 | char * |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 35 | hex_string(unsigned char *s, size_t l) |
| 36 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 37 | const char *hex_digits = "0123456789abcdef"; |
| 38 | char *r; |
| 39 | int i; |
| 40 | r = calloc(1, 1 + 2 * l); |
| 41 | for (i = 0; i < l; i++) { |
| 42 | r[2*i] = hex_digits[(s[i]>>4) & 0xf]; |
| 43 | r[1+2*i] = hex_digits[s[i] & 0xf]; |
| 44 | } |
| 45 | return(r); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 46 | } |
| 47 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 48 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 49 | sync_cb(struct ccns_name_closure *nc, |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 50 | struct ccn_charbuf *lhash, |
| 51 | struct ccn_charbuf *rhash, |
| 52 | struct ccn_charbuf *name) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 53 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 54 | int res; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 55 | //--Doing our thing from here |
| 56 | //struct ccn_indexbuf cid={0}; |
| 57 | |
| 58 | //struct ccn_indexbuf *components=&cid; |
| 59 | struct ccn_indexbuf *components=ccn_indexbuf_create(); |
| 60 | res=ccn_name_split (name, components); |
| 61 | if ( res < 0 ) |
| 62 | return 0; |
| 63 | //ccn_name_chop(name,components,-3); |
| 64 | //process_content_from_sync(name,components); |
| 65 | |
| 66 | struct ccn_charbuf *content_name = ccn_charbuf_create(); |
| 67 | ccn_name_init(content_name); |
| 68 | if (components->n < 2) |
| 69 | return 0; |
| 70 | res = ccn_name_append_components(content_name, name->buf, components->buf[0] |
| 71 | , components->buf[components->n - 1]); |
| 72 | |
| 73 | if ( res < 0) |
| 74 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 75 | |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 76 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 77 | // debugging purpose |
| 78 | struct ccn_charbuf *temp=ccn_charbuf_create(); |
| 79 | ccn_uri_append(temp, content_name->buf, content_name->length, 0); |
| 80 | if ( nlsr->debugging ) |
| 81 | printf("Name before chopping: %s \n",ccn_charbuf_as_string(temp)); |
| 82 | ccn_charbuf_destroy(&temp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 83 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 84 | //struct ccn_indexbuf cid1={0}; |
| 85 | //struct ccn_indexbuf *components1=&cid1; |
| 86 | struct ccn_indexbuf *components1=ccn_indexbuf_create(); |
| 87 | res=ccn_name_split (content_name, components1); |
| 88 | if ( res < 0) |
| 89 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 90 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 91 | if ( nlsr->debugging ) |
| 92 | { |
| 93 | printf("Number of components in name = %d \n",res); |
| 94 | printf("Number of components in name as indexbuf->n = %d \n", |
| 95 | (int)components1->n); |
| 96 | } |
| 97 | ccn_name_chop(content_name,components1,-3); |
| 98 | if ( nlsr->debugging ) |
| 99 | printf("Number of components in name as indexbuf->n after chopping= %d \n" |
| 100 | ,(int)components1->n); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 101 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 102 | //debugging purpose |
| 103 | struct ccn_charbuf *temp1=ccn_charbuf_create(); |
| 104 | ccn_uri_append(temp1, content_name->buf, content_name->length, 0); |
| 105 | if ( nlsr->debugging ) |
| 106 | printf("Name after chopping: %s \n",ccn_charbuf_as_string(temp1)); |
| 107 | ccn_charbuf_destroy(&temp1); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 108 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 109 | process_content_from_sync(content_name,components1); |
| 110 | ccn_charbuf_destroy(&content_name); |
| 111 | ccn_indexbuf_destroy(&components); |
| 112 | ccn_indexbuf_destroy(&components1); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 113 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 114 | return(0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
akmhoque | ccb33e9 | 2013-02-20 11:44:28 -0600 | [diff] [blame] | 118 | |
akmhoque | fd43925 | 2013-02-21 13:38:23 -0600 | [diff] [blame] | 119 | void |
akmhoque | ccb33e9 | 2013-02-20 11:44:28 -0600 | [diff] [blame] | 120 | get_name_part(struct name_prefix *name_part,struct ccn_charbuf * interest_ccnb, |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 121 | struct ccn_indexbuf *interest_comps, int offset) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 122 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 123 | int i; |
| 124 | int lsa_position=0; |
| 125 | int len=0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 126 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 127 | struct ccn_indexbuf cid={0}; |
| 128 | struct ccn_indexbuf *components=&cid; |
| 129 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 130 | ccn_name_from_uri(name,nlsr->slice_prefix); |
| 131 | ccn_name_split (name, components); |
| 132 | lsa_position=components->n-2; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 133 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 134 | ccn_charbuf_destroy(&name); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 135 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 136 | const unsigned char *comp_ptr1; |
| 137 | size_t comp_size; |
| 138 | for(i=lsa_position+1+offset;i<interest_comps->n-1;i++) |
| 139 | { |
| 140 | ccn_name_comp_get(interest_ccnb->buf, interest_comps,i,&comp_ptr1, |
| 141 | &comp_size); |
| 142 | len+=1; |
| 143 | len+=(int)comp_size; |
| 144 | } |
| 145 | len++; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 146 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 147 | char *neighbor=(char *)malloc(len); |
| 148 | memset(neighbor,0,len); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 149 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 150 | for(i=lsa_position+1+offset; i<interest_comps->n-1;i++) |
| 151 | { |
| 152 | ccn_name_comp_get(interest_ccnb->buf, interest_comps,i,&comp_ptr1, |
| 153 | &comp_size); |
| 154 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 155 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1, |
| 156 | strlen((char *)comp_ptr1)); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 157 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 158 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 159 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 160 | name_part->name=(char *)malloc(strlen(neighbor)+1); |
| 161 | memset(name_part->name,0,strlen(neighbor)+1); |
| 162 | memcpy(name_part->name,neighbor,strlen(neighbor)+1); |
| 163 | name_part->length=strlen(neighbor)+1; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 164 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 165 | // Add 01/31/2013 |
| 166 | free(neighbor); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 167 | } |
| 168 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 169 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 170 | |
| 171 | |
| 172 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 173 | void |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 174 | get_content_by_content_name(char *content_name, unsigned char **content_data) |
| 175 | { |
| 176 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 177 | struct ccn_charbuf *name = NULL; |
| 178 | struct ccn_charbuf *templ = NULL; |
| 179 | struct ccn_charbuf *resultbuf = NULL; |
| 180 | struct ccn_parsed_ContentObject pcobuf = { 0 }; |
| 181 | int res; |
| 182 | int allow_stale = 0; |
| 183 | int content_only = 1; |
| 184 | int scope = -1; |
| 185 | const unsigned char *ptr; |
| 186 | size_t length; |
| 187 | int resolve_version = CCN_V_HIGHEST; |
| 188 | int timeout_ms = 3000; |
| 189 | const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12; |
| 190 | unsigned lifetime_l12 = lifetime_default; |
| 191 | int get_flags = 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 192 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 193 | name = ccn_charbuf_create(); |
| 194 | res = ccn_name_from_uri(name,content_name); |
| 195 | if (res < 0) { |
| 196 | fprintf(stderr, "Bad ccn URI: %s\n", content_name); |
| 197 | exit(1); |
| 198 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 199 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 200 | if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) { |
| 201 | templ = ccn_charbuf_create(); |
| 202 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 203 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 204 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 205 | if (allow_stale) { |
| 206 | ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG); |
| 207 | ccnb_append_number(templ, |
| 208 | CCN_AOK_DEFAULT | CCN_AOK_STALE); |
| 209 | ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */ |
| 210 | } |
| 211 | if (scope != -1) { |
| 212 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 213 | } |
| 214 | if (lifetime_l12 != lifetime_default) { |
| 215 | /* |
| 216 | * Choose the interest lifetime so there are at least 3 |
| 217 | * expressions (in the unsatisfied case). |
| 218 | */ |
| 219 | unsigned char buf[3] = { 0 }; |
| 220 | int i; |
| 221 | for (i = sizeof(buf) - 1; i >= 0; i--, lifetime_l12 >>= 8) |
| 222 | buf[i] = lifetime_l12 & 0xff; |
| 223 | ccnb_append_tagged_blob(templ, CCN_DTAG_InterestLifetime, buf, |
| 224 | sizeof(buf)); |
| 225 | } |
| 226 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 227 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 228 | resultbuf = ccn_charbuf_create(); |
| 229 | if (resolve_version != 0) { |
| 230 | res = ccn_resolve_version(nlsr->ccn, name, resolve_version, 500); |
| 231 | if (res >= 0) { |
| 232 | ccn_uri_append(resultbuf, name->buf, name->length, 1); |
| 233 | resultbuf->length = 0; |
| 234 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 235 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 236 | res = ccn_get(nlsr->ccn, name, templ, timeout_ms, resultbuf, &pcobuf, NULL, |
| 237 | get_flags); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 238 | if (res >= 0) { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 239 | ptr = resultbuf->buf; |
| 240 | length = resultbuf->length; |
| 241 | if (content_only){ |
| 242 | ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length); |
| 243 | *content_data = (unsigned char *) calloc(length, sizeof(char *)); |
| 244 | memcpy (*content_data, ptr, length); |
| 245 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 246 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 247 | ccn_charbuf_destroy(&resultbuf); |
| 248 | ccn_charbuf_destroy(&templ); |
| 249 | ccn_charbuf_destroy(&name); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 250 | } |
| 251 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 252 | void |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 253 | process_incoming_sync_content_lsa( unsigned char *content_data) |
| 254 | { |
| 255 | |
| 256 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 257 | if ( nlsr->debugging ) |
| 258 | printf("process_incoming_sync_content_lsa called \n"); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 259 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 260 | char *sep="|"; |
| 261 | char *rem; |
| 262 | char *orig_router; |
| 263 | char *orl; |
| 264 | int orig_router_length; |
| 265 | char *lst; |
| 266 | int ls_type; |
| 267 | char *lsid; |
| 268 | long int ls_id; |
| 269 | char *isvld; |
| 270 | int isValid; |
| 271 | char *num_link; |
| 272 | int no_link; |
| 273 | char *np; |
| 274 | char *np_length; |
| 275 | int name_length; |
| 276 | char *data; |
| 277 | char *orig_time; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 278 | |
| 279 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 280 | if ( nlsr->debugging ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 281 | printf("LSA Data \n"); |
| 282 | |
| 283 | if( strlen((char *)content_data ) > 0 ) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 284 | { |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 285 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 286 | orig_router=strtok_r((char *)content_data,sep,&rem); |
| 287 | orl=strtok_r(NULL,sep,&rem); |
| 288 | orig_router_length=atoi(orl); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 289 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 290 | if ( nlsr->debugging ) |
| 291 | { |
| 292 | printf(" Orig Router Name : %s\n",orig_router); |
| 293 | printf(" Orig Router Length: %d\n",orig_router_length); |
| 294 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 295 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 296 | lst=strtok_r(NULL,sep,&rem); |
| 297 | ls_type=atoi(lst); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 298 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 299 | if ( nlsr->debugging ) |
| 300 | printf(" LS Type : %d\n",ls_type); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 301 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 302 | if ( ls_type == LS_TYPE_NAME ) |
| 303 | { |
| 304 | lsid=strtok_r(NULL,sep,&rem); |
| 305 | ls_id=atoi(lsid); |
| 306 | orig_time=strtok_r(NULL,sep,&rem); |
| 307 | isvld=strtok_r(NULL,sep,&rem); |
| 308 | isValid=atoi(isvld); |
| 309 | np=strtok_r(NULL,sep,&rem); |
| 310 | np_length=strtok_r(NULL,sep,&rem); |
| 311 | name_length=atoi(np_length); |
| 312 | if ( nlsr->debugging ) |
| 313 | { |
| 314 | printf(" LS ID : %ld\n",ls_id); |
| 315 | printf(" isValid : %d\n",isValid); |
| 316 | printf(" Name Prefix : %s\n",np); |
| 317 | printf(" Orig Time : %s\n",orig_time); |
| 318 | printf(" Name Prefix length: %d\n",name_length); |
| 319 | } |
| 320 | |
| 321 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np); |
| 322 | |
| 323 | print_name_lsdb(); |
| 324 | |
| 325 | } |
| 326 | else if ( ls_type == LS_TYPE_ADJ ) |
| 327 | { |
| 328 | orig_time=strtok_r(NULL,sep,&rem); |
| 329 | num_link=strtok_r(NULL,sep,&rem); |
| 330 | no_link=atoi(num_link); |
| 331 | data=rem; |
| 332 | |
| 333 | if ( nlsr->debugging ) |
| 334 | { |
| 335 | printf(" Orig Time : %s\n",orig_time); |
| 336 | printf(" No Link : %d\n",no_link); |
| 337 | printf(" Data : %s\n",data); |
| 338 | } |
| 339 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data); |
| 340 | } |
| 341 | else if ( ls_type == LS_TYPE_COR ) |
| 342 | { |
| 343 | orig_time=strtok_r(NULL,sep,&rem); |
| 344 | char *cor_r=strtok_r(NULL,sep,&rem); |
| 345 | char *cor_theta=strtok_r(NULL,sep,&rem); |
| 346 | |
| 347 | double r, theta; |
| 348 | r=strtof(cor_r,NULL); |
| 349 | theta=strtof(cor_theta,NULL); |
| 350 | |
| 351 | if ( nlsr->debugging ) |
| 352 | { |
| 353 | printf(" Orig Time : %s\n",orig_time); |
| 354 | printf(" Cor R : %f\n",r); |
| 355 | printf(" Cor Theta : %f\n",theta); |
| 356 | } |
| 357 | build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, (double)r, (double)theta); |
| 358 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 359 | |
| 360 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 361 | } |
| 362 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 363 | void |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 364 | process_content_from_sync(struct ccn_charbuf *content_name, struct ccn_indexbuf *components) |
| 365 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 366 | size_t comp_size; |
| 367 | char *lst; |
| 368 | char *lsid; |
| 369 | const unsigned char *second_last_comp; |
| 370 | const unsigned char *third_last_comp; |
| 371 | const unsigned char *origtime; |
| 372 | char *sep="."; |
| 373 | char *rem; |
| 374 | char *second_comp_type; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 375 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 376 | int ls_type; |
| 377 | long int ls_id=0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 378 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 379 | unsigned char *content_data = NULL; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 380 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 381 | char *time_stamp=(char *)malloc(20); |
| 382 | memset(time_stamp,0,20); |
| 383 | get_current_timestamp_micro(time_stamp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 384 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 385 | struct ccn_charbuf *uri = ccn_charbuf_create(); |
| 386 | ccn_uri_append(uri, content_name->buf, content_name->length, 0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 387 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 388 | struct name_prefix *orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix)); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 389 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 390 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 391 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 392 | ccn_name_comp_get(content_name->buf, components,components->n-1-2,&second_last_comp, &comp_size); |
| 393 | if (nlsr->debugging) |
| 394 | printf("2nd Last Component: %s \n",second_last_comp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 395 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 396 | second_comp_type=strtok_r((char *)second_last_comp,sep,&rem); |
| 397 | if ( strcmp( second_comp_type, "lsId" ) == 0 ) |
| 398 | { |
| 399 | lsid=rem; |
| 400 | ls_id=atoi(rem); |
| 401 | ccn_name_comp_get(content_name->buf, components,components->n-2-2,&third_last_comp, &comp_size); |
| 402 | lst=strtok_r((char *)third_last_comp,sep,&rem); |
| 403 | lst=rem; |
| 404 | ls_type=atoi(lst); |
| 405 | ccn_name_comp_get(content_name->buf, components,components->n-2,&origtime, &comp_size); |
| 406 | ccn_name_chop(content_name,components,-3); |
| 407 | get_name_part(orig_router,content_name,components,0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 408 | |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 409 | if ( nlsr->debugging ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 410 | printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n",orig_router->name,ls_type,ls_id,origtime); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 411 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 412 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 413 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 414 | if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time) |
| 415 | || (strcmp(orig_router->name,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 416 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 417 | int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,(char *)lst,(char *)lsid,(char *)origtime); |
| 418 | if ( is_new_name_lsa == 1 ) |
| 419 | { |
| 420 | if ( nlsr->debugging ) |
| 421 | printf("New NAME LSA.....\n"); |
| 422 | get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data); |
| 423 | if ( nlsr->debugging ) |
| 424 | printf("Content Data: %s \n",content_data); |
| 425 | process_incoming_sync_content_lsa(content_data); |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | if ( nlsr->debugging ) |
| 430 | printf("Name LSA / Newer Name LSA already xists in LSDB\n"); |
| 431 | get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 432 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 433 | if ( nlsr->debugging ) |
| 434 | printf("Content Data: %s \n",content_data); |
| 435 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 436 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 437 | else |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 438 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 439 | if ( nlsr->debugging ) |
| 440 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 441 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 442 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 443 | else |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 444 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 445 | ls_type=atoi(rem); |
| 446 | lst=rem; |
| 447 | if(ls_type == LS_TYPE_ADJ) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 448 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 449 | ccn_name_comp_get(content_name->buf, components,components->n-2,&origtime, &comp_size); |
| 450 | ccn_name_chop(content_name,components,-2); |
| 451 | get_name_part(orig_router,content_name,components,0); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 452 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 453 | if ( nlsr->debugging ) |
| 454 | printf("Orig Router: %s Ls Type: %d Orig Time: %s\n",orig_router->name,ls_type,origtime); |
| 455 | |
| 456 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
| 457 | if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time) || (strcmp(orig_router->name,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) ) |
| 458 | { |
| 459 | int is_new_adj_lsa=check_is_new_adj_lsa(orig_router->name,(char *)lst,(char *)origtime); |
| 460 | if ( is_new_adj_lsa == 1 ) |
| 461 | { |
| 462 | if ( nlsr->debugging ) |
| 463 | printf("New Adj LSA.....\n"); |
| 464 | get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data); |
| 465 | |
| 466 | if ( nlsr->debugging ) |
| 467 | printf("Content Data: %s \n",content_data); |
| 468 | process_incoming_sync_content_lsa(content_data); |
| 469 | } |
| 470 | else |
| 471 | { |
| 472 | if ( nlsr->debugging ) |
| 473 | printf("Adj LSA / Newer Adj LSA already exists in LSDB\n"); |
| 474 | get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data); |
| 475 | if ( nlsr->debugging ) |
| 476 | printf("Content Data: %s \n",content_data); |
| 477 | } |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | if ( nlsr->debugging ) |
| 482 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
| 483 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 484 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 485 | else if(ls_type == LS_TYPE_COR) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 486 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 487 | ccn_name_comp_get(content_name->buf, components,components->n-2,&origtime, &comp_size); |
| 488 | ccn_name_chop(content_name,components,-2); |
| 489 | get_name_part(orig_router,content_name,components,0); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 490 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 491 | if ( nlsr->debugging ) |
| 492 | printf("Orig Router: %s Ls Type: %d Orig Time: %s\n",orig_router->name,ls_type,origtime); |
| 493 | |
| 494 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
| 495 | if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time) || (strcmp(orig_router->name,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) ) |
| 496 | { |
| 497 | int is_new_cor_lsa=check_is_new_cor_lsa(orig_router->name,(char *)lst,(char *)origtime); |
| 498 | if ( is_new_cor_lsa == 1 ) |
| 499 | { |
| 500 | if ( nlsr->debugging ) |
| 501 | printf("New Cor LSA.....\n"); |
| 502 | get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data); |
| 503 | |
| 504 | if ( nlsr->debugging ) |
| 505 | printf("Content Data: %s \n",content_data); |
| 506 | process_incoming_sync_content_lsa(content_data); |
| 507 | } |
| 508 | else |
| 509 | { |
| 510 | if ( nlsr->debugging ) |
| 511 | printf("Cor LSA / Newer Cor LSA already exists in LSDB\n"); |
| 512 | get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data); |
| 513 | if ( nlsr->debugging ) |
| 514 | printf("Content Data: %s \n",content_data); |
| 515 | } |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | if ( nlsr->debugging ) |
| 520 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
| 521 | } |
| 522 | |
| 523 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 524 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 525 | |
Obaid Amin | 0530089 | 2013-02-21 13:45:25 -0600 | [diff] [blame] | 526 | if (orig_router) |
| 527 | free(orig_router); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 528 | ccn_charbuf_destroy(&uri); |
| 529 | //01/31/2013 |
| 530 | free(time_stamp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 531 | } |
| 532 | |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 533 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 534 | sync_monitor(char *topo_prefix, char *slice_prefix) |
| 535 | { |
| 536 | |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 537 | //static struct ccns_name_closure nc={0}; |
| 538 | //nlsr->closure = &nc; |
| 539 | nlsr->closure=(struct ccns_name_closure *)calloc(1,sizeof(struct ccns_name_closure)); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 540 | struct ccn_charbuf *prefix = ccn_charbuf_create(); |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 541 | //struct ccn_charbuf *roothash = NULL; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 542 | struct ccn_charbuf *topo = ccn_charbuf_create(); |
| 543 | nlsr->slice = ccns_slice_create(); |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 544 | //ccn_charbuf_reset(prefix); |
| 545 | //ccn_charbuf_reset(topo); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 546 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 547 | ccn_charbuf_reset(prefix); |
| 548 | ccn_name_from_uri(prefix, slice_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 549 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 550 | ccn_charbuf_reset(topo); |
| 551 | ccn_name_from_uri(topo, topo_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 552 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 553 | ccns_slice_set_topo_prefix(nlsr->slice, topo, prefix); |
| 554 | nlsr->closure->callback = &sync_cb; |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 555 | nlsr->ccns = ccns_open(nlsr->ccn, nlsr->slice, nlsr->closure, NULL, NULL); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 556 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 557 | //01/31/2013 |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 558 | //ccn_charbuf_destroy(&prefix); |
| 559 | //ccn_charbuf_destroy(&topo); |
| 560 | //ccn_charbuf_destroy(&roothash); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 561 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 562 | } |
| 563 | |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 564 | struct ccn_charbuf * |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 565 | make_template(int scope) |
| 566 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 567 | struct ccn_charbuf *templ = NULL; |
| 568 | templ = ccn_charbuf_create(); |
| 569 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 570 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 571 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 572 | if (0 <= scope && scope <= 2) |
| 573 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 574 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 575 | return(templ); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 576 | } |
| 577 | |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame^] | 578 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 579 | write_data_to_repo(char *data, char *name_prefix) |
| 580 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 581 | if ( nlsr->debugging ) |
| 582 | { |
| 583 | printf("write_data_to_repo called\n"); |
| 584 | printf("Content Name: %s \n",name_prefix); |
| 585 | printf("Content Data: %s \n",data); |
| 586 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 587 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 588 | struct ccn *temp_ccn; |
| 589 | temp_ccn=ccn_create(); |
| 590 | int ccn_fd=ccn_connect(temp_ccn, NULL); |
| 591 | if(ccn_fd == -1) |
| 592 | { |
| 593 | fprintf(stderr,"Could not connect to ccnd for Data Writing\n"); |
| 594 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd for Data Writing\n"); |
| 595 | return -1; |
| 596 | } |
| 597 | struct ccn_charbuf *name = NULL; |
| 598 | struct ccn_seqwriter *w = NULL; |
| 599 | int blocksize = 4096; |
| 600 | int freshness = -1; |
| 601 | int torepo = 1; |
| 602 | int scope = 1; |
| 603 | int res; |
| 604 | size_t blockread; |
| 605 | struct ccn_charbuf *templ; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 606 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 607 | name = ccn_charbuf_create(); |
| 608 | res = ccn_name_from_uri(name, name_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 609 | if (res < 0) { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 610 | fprintf(stderr, "bad CCN URI: %s\n",name_prefix); |
| 611 | return -1; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 612 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 613 | |
| 614 | |
| 615 | w = ccn_seqw_create(temp_ccn, name); |
| 616 | if (w == NULL) { |
| 617 | fprintf(stderr, "ccn_seqw_create failed\n"); |
| 618 | return -1; |
| 619 | } |
| 620 | ccn_seqw_set_block_limits(w, blocksize, blocksize); |
| 621 | if (freshness > -1) |
| 622 | ccn_seqw_set_freshness(w, freshness); |
| 623 | if (torepo) { |
| 624 | struct ccn_charbuf *name_v = ccn_charbuf_create(); |
| 625 | ccn_seqw_get_name(w, name_v); |
| 626 | ccn_name_from_uri(name_v, "%C1.R.sw"); |
| 627 | ccn_name_append_nonce(name_v); |
| 628 | templ = make_template(scope); |
| 629 | res = ccn_get(temp_ccn, name_v, templ, 60000, NULL, NULL, NULL, 0); |
| 630 | ccn_charbuf_destroy(&templ); |
| 631 | ccn_charbuf_destroy(&name_v); |
| 632 | if (res < 0) { |
| 633 | fprintf(stderr, "No response from repository\n"); |
| 634 | return -1; |
| 635 | } |
| 636 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 637 | |
| 638 | |
| 639 | |
| 640 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 641 | blockread = 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 642 | |
| 643 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 644 | blockread=strlen(data); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 645 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 646 | if (blockread > 0) { |
| 647 | ccn_run(temp_ccn, 100); |
| 648 | res = ccn_seqw_write(w, data, blockread); |
| 649 | while (res == -1) { |
| 650 | ccn_run(temp_ccn, 100); |
| 651 | res = ccn_seqw_write(w, data, blockread); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | ccn_seqw_close(w); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 656 | ccn_run(temp_ccn, 100); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 657 | ccn_charbuf_destroy(&name); |
| 658 | ccn_destroy(&temp_ccn); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 659 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 660 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 664 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 665 | create_sync_slice(char *topo_prefix, char *slice_prefix) |
| 666 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 667 | int res; |
| 668 | struct ccn *handle; |
| 669 | struct ccns_slice *slice; |
| 670 | struct ccn_charbuf *prefix = ccn_charbuf_create(); |
| 671 | struct ccn_charbuf *topo = ccn_charbuf_create(); |
| 672 | struct ccn_charbuf *clause = ccn_charbuf_create(); |
| 673 | struct ccn_charbuf *slice_name = ccn_charbuf_create(); |
| 674 | struct ccn_charbuf *slice_uri = ccn_charbuf_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 675 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 676 | if (prefix == NULL || topo == NULL || clause == NULL || |
| 677 | slice_name == NULL || slice_uri == NULL) { |
| 678 | fprintf(stderr, "Unable to allocate required memory.\n"); |
| 679 | return -1; |
| 680 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 681 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 682 | handle = ccn_create(); |
| 683 | res = ccn_connect(handle, NULL); |
| 684 | if (0 > res) { |
| 685 | fprintf(stderr, "Unable to connect to ccnd.\n"); |
| 686 | return -1; |
| 687 | } |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 688 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 689 | slice = ccns_slice_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 690 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 691 | ccn_charbuf_reset(topo); |
| 692 | ccn_name_from_uri(topo, topo_prefix); |
| 693 | ccn_charbuf_reset(prefix); |
| 694 | ccn_name_from_uri(prefix,slice_prefix ); |
| 695 | ccns_slice_set_topo_prefix(slice, topo, prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 696 | |
| 697 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 698 | res = ccns_write_slice(handle, slice, slice_name); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 699 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 700 | //01/31/2013 |
| 701 | ccns_slice_destroy(&slice); |
| 702 | ccn_destroy(&handle); |
| 703 | ccn_charbuf_destroy(&prefix); |
| 704 | ccn_charbuf_destroy(&topo); |
| 705 | ccn_charbuf_destroy(&clause); |
| 706 | ccn_charbuf_destroy(&slice_name); |
| 707 | ccn_charbuf_destroy(&slice_uri); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 708 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 709 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 710 | } |
| 711 | |