blob: 61eadb3489f3dcbe0eeff05d94dda8fb29a6ffc6 [file] [log] [blame]
akmhoquea0e71152013-02-11 09:47:59 -06001#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"
akmhoqueedb68d92013-03-05 10:18:16 -060032#include "nlsr_km.h"
akmhoque7adb2772013-03-05 16:30:59 -060033#include "nlsr_km_util.h"
akmhoquea0e71152013-02-11 09:47:59 -060034
35
akmhoqueedb68d92013-03-05 10:18:16 -060036char *
akmhoquea0e71152013-02-11 09:47:59 -060037hex_string(unsigned char *s, size_t l)
38{
Obaid Amin806df812013-02-21 13:30:26 -060039 const char *hex_digits = "0123456789abcdef";
40 char *r;
41 int i;
42 r = calloc(1, 1 + 2 * l);
43 for (i = 0; i < l; i++) {
44 r[2*i] = hex_digits[(s[i]>>4) & 0xf];
45 r[1+2*i] = hex_digits[s[i] & 0xf];
46 }
47 return(r);
akmhoquea0e71152013-02-11 09:47:59 -060048}
49
akmhoquec25f2242013-03-15 00:24:43 -050050/**
51* call back function from sync. Receive notification of updates in sync.
52* This function calls process_content_from_sync to handle incoming content
53* from sync.
54*/
55
akmhoqueedb68d92013-03-05 10:18:16 -060056int
akmhoquea0e71152013-02-11 09:47:59 -060057sync_cb(struct ccns_name_closure *nc,
Obaid Amin806df812013-02-21 13:30:26 -060058 struct ccn_charbuf *lhash,
59 struct ccn_charbuf *rhash,
60 struct ccn_charbuf *name)
akmhoquea0e71152013-02-11 09:47:59 -060061{
akmhoque483c1eb2013-03-08 00:51:09 -060062 nlsr_lock();
Obaid Amin806df812013-02-21 13:30:26 -060063 int res;
Obaid Amin7997ad82013-02-22 16:41:56 -060064 struct ccn_charbuf *content_name;
65 struct ccn_indexbuf *content_comps;
66 struct ccn_indexbuf *name_comps;
67
68 content_comps = ccn_indexbuf_create();
69 res = ccn_name_split(name, content_comps);
Obaid Amin806df812013-02-21 13:30:26 -060070 if ( res < 0 )
71 return 0;
Obaid Amin7997ad82013-02-22 16:41:56 -060072
73 if (content_comps->n < 2)
Obaid Amin806df812013-02-21 13:30:26 -060074 return 0;
Obaid Amin7997ad82013-02-22 16:41:56 -060075
76 content_name = ccn_charbuf_create();
77 ccn_name_init(content_name);
78
79 res = ccn_name_append_components( content_name, name->buf,
80 content_comps->buf[0], content_comps->buf[content_comps->n - 1]);
Obaid Amin806df812013-02-21 13:30:26 -060081
82 if ( res < 0)
83 return 0;
akmhoquea0e71152013-02-11 09:47:59 -060084
Obaid Amin7997ad82013-02-22 16:41:56 -060085 // for debugging
Obaid Amin806df812013-02-21 13:30:26 -060086 struct ccn_charbuf *temp=ccn_charbuf_create();
87 ccn_uri_append(temp, content_name->buf, content_name->length, 0);
88 if ( nlsr->debugging )
89 printf("Name before chopping: %s \n",ccn_charbuf_as_string(temp));
90 ccn_charbuf_destroy(&temp);
akmhoquea0e71152013-02-11 09:47:59 -060091
Obaid Amin7997ad82013-02-22 16:41:56 -060092 name_comps = ccn_indexbuf_create();
93 res=ccn_name_split (content_name, name_comps);
94 if (res < 0)
Obaid Amin806df812013-02-21 13:30:26 -060095 return 0;
akmhoquea0e71152013-02-11 09:47:59 -060096
Obaid Amin806df812013-02-21 13:30:26 -060097 if ( nlsr->debugging )
98 {
99 printf("Number of components in name = %d \n",res);
100 printf("Number of components in name as indexbuf->n = %d \n",
Obaid Amin7997ad82013-02-22 16:41:56 -0600101 (int)name_comps->n);
Obaid Amin806df812013-02-21 13:30:26 -0600102 }
Obaid Amin7997ad82013-02-22 16:41:56 -0600103
104 ccn_name_chop(content_name, name_comps, -3);
Obaid Amin806df812013-02-21 13:30:26 -0600105 if ( nlsr->debugging )
106 printf("Number of components in name as indexbuf->n after chopping= %d \n"
Obaid Amin7997ad82013-02-22 16:41:56 -0600107 , (int)name_comps->n);
akmhoquea0e71152013-02-11 09:47:59 -0600108
Obaid Amin7997ad82013-02-22 16:41:56 -0600109 //for debugging
Obaid Amin806df812013-02-21 13:30:26 -0600110 struct ccn_charbuf *temp1=ccn_charbuf_create();
111 ccn_uri_append(temp1, content_name->buf, content_name->length, 0);
112 if ( nlsr->debugging )
113 printf("Name after chopping: %s \n",ccn_charbuf_as_string(temp1));
114 ccn_charbuf_destroy(&temp1);
akmhoquea0e71152013-02-11 09:47:59 -0600115
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600116 //main method that processes contents from the sync
Obaid Amin7997ad82013-02-22 16:41:56 -0600117 process_content_from_sync(content_name, name_comps);
118
Obaid Amin806df812013-02-21 13:30:26 -0600119 ccn_charbuf_destroy(&content_name);
Obaid Amin7997ad82013-02-22 16:41:56 -0600120 ccn_indexbuf_destroy(&content_comps);
121 ccn_indexbuf_destroy(&name_comps);
akmhoquea0e71152013-02-11 09:47:59 -0600122
akmhoque483c1eb2013-03-08 00:51:09 -0600123 nlsr_unlock();
Obaid Amin806df812013-02-21 13:30:26 -0600124 return(0);
akmhoquea0e71152013-02-11 09:47:59 -0600125}
126
127
akmhoquec25f2242013-03-15 00:24:43 -0500128/**
129* this function retrieve part of name from interest name and put it in name_part
130*/
akmhoqueccb33e92013-02-20 11:44:28 -0600131
akmhoqueedb68d92013-03-05 10:18:16 -0600132void
akmhoqueccb33e92013-02-20 11:44:28 -0600133get_name_part(struct name_prefix *name_part,struct ccn_charbuf * interest_ccnb,
Obaid Amin806df812013-02-21 13:30:26 -0600134 struct ccn_indexbuf *interest_comps, int offset)
akmhoquea0e71152013-02-11 09:47:59 -0600135{
Obaid Amin806df812013-02-21 13:30:26 -0600136 int lsa_position=0;
akmhoqueedb68d92013-03-05 10:18:16 -0600137
akmhoque0b60ba92013-02-25 17:55:35 -0600138 struct ccn_indexbuf *components=ccn_indexbuf_create();
Obaid Amin806df812013-02-21 13:30:26 -0600139 struct ccn_charbuf *name=ccn_charbuf_create();
140 ccn_name_from_uri(name,nlsr->slice_prefix);
141 ccn_name_split (name, components);
142 lsa_position=components->n-2;
Obaid Amin806df812013-02-21 13:30:26 -0600143 ccn_charbuf_destroy(&name);
akmhoquea0e71152013-02-11 09:47:59 -0600144
akmhoquef6773612013-02-23 09:53:00 -0600145 struct ccn_charbuf *temp=ccn_charbuf_create();
146 ccn_name_init(temp);
147 ccn_name_append_components( temp, interest_ccnb->buf,
akmhoque7adb2772013-03-05 16:30:59 -0600148 interest_comps->buf[lsa_position+1],
149 interest_comps->buf[interest_comps->n - 1]);
akmhoquef6773612013-02-23 09:53:00 -0600150
151 struct ccn_charbuf *temp1=ccn_charbuf_create();
152 ccn_uri_append(temp1, temp->buf, temp->length, 0);
153
akmhoque7adb2772013-03-05 16:30:59 -0600154 name_part->name=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
155 sizeof(char));
156 memcpy(name_part->name,ccn_charbuf_as_string(temp1),
157 strlen(ccn_charbuf_as_string(temp1)));
akmhoquef6773612013-02-23 09:53:00 -0600158 name_part->name[strlen(ccn_charbuf_as_string(temp1))]='\0';
159 name_part->length=strlen(ccn_charbuf_as_string(temp1))+1;
160
161 ccn_charbuf_destroy(&temp1);
162 ccn_charbuf_destroy(&temp);
akmhoque0b60ba92013-02-25 17:55:35 -0600163 ccn_indexbuf_destroy(&components);
akmhoquef6773612013-02-23 09:53:00 -0600164
165 if ( nlsr->debugging )
166 printf("Name Part: %s \n",name_part->name);
167
akmhoquea0e71152013-02-11 09:47:59 -0600168}
169
akmhoquea0e71152013-02-11 09:47:59 -0600170
akmhoquec25f2242013-03-15 00:24:43 -0500171/**
172* Get content value by content name and put the content value in content_data
173*/
akmhoquea0e71152013-02-11 09:47:59 -0600174
175
akmhoque7adb2772013-03-05 16:30:59 -0600176int
akmhoque5079b652013-03-15 19:48:49 -0500177get_content_by_content_name(char *content_name, unsigned char **content_data,
akmhoque7adb2772013-03-05 16:30:59 -0600178 char *orig_router)
akmhoquea0e71152013-02-11 09:47:59 -0600179{
akmhoque7adb2772013-03-05 16:30:59 -0600180
181 int ret=-1;
Obaid Amin806df812013-02-21 13:30:26 -0600182 struct ccn_charbuf *name = NULL;
183 struct ccn_charbuf *templ = NULL;
184 struct ccn_charbuf *resultbuf = NULL;
185 struct ccn_parsed_ContentObject pcobuf = { 0 };
186 int res;
akmhoque7adb2772013-03-05 16:30:59 -0600187 int allow_stale = 1;
Obaid Amin806df812013-02-21 13:30:26 -0600188 int content_only = 1;
189 int scope = -1;
akmhoquec90ca4d2013-03-15 09:30:17 -0500190 const unsigned char *ptr,*ptr_in;
191 size_t length,length_in;
Obaid Amin806df812013-02-21 13:30:26 -0600192 int resolve_version = CCN_V_HIGHEST;
193 int timeout_ms = 3000;
194 const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12;
195 unsigned lifetime_l12 = lifetime_default;
196 int get_flags = 0;
akmhoquea0e71152013-02-11 09:47:59 -0600197
Obaid Amin806df812013-02-21 13:30:26 -0600198 name = ccn_charbuf_create();
199 res = ccn_name_from_uri(name,content_name);
200 if (res < 0) {
201 fprintf(stderr, "Bad ccn URI: %s\n", content_name);
akmhoque7adb2772013-03-05 16:30:59 -0600202 ccn_charbuf_destroy(&name);
203 return ret;
Obaid Amin806df812013-02-21 13:30:26 -0600204 }
akmhoquea0e71152013-02-11 09:47:59 -0600205
Obaid Amin806df812013-02-21 13:30:26 -0600206 if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) {
207 templ = ccn_charbuf_create();
208 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
209 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
210 ccn_charbuf_append_closer(templ); /* </Name> */
211 if (allow_stale) {
212 ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
213 ccnb_append_number(templ,
214 CCN_AOK_DEFAULT | CCN_AOK_STALE);
215 ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */
216 }
217 if (scope != -1) {
218 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
219 }
220 if (lifetime_l12 != lifetime_default) {
221 /*
222 * Choose the interest lifetime so there are at least 3
223 * expressions (in the unsatisfied case).
224 */
225 unsigned char buf[3] = { 0 };
226 int i;
227 for (i = sizeof(buf) - 1; i >= 0; i--, lifetime_l12 >>= 8)
228 buf[i] = lifetime_l12 & 0xff;
229 ccnb_append_tagged_blob(templ, CCN_DTAG_InterestLifetime, buf,
230 sizeof(buf));
231 }
232 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoquea0e71152013-02-11 09:47:59 -0600233 }
Obaid Amin806df812013-02-21 13:30:26 -0600234 resultbuf = ccn_charbuf_create();
235 if (resolve_version != 0) {
236 res = ccn_resolve_version(nlsr->ccn, name, resolve_version, 500);
237 if (res >= 0) {
238 ccn_uri_append(resultbuf, name->buf, name->length, 1);
239 resultbuf->length = 0;
240 }
akmhoquea0e71152013-02-11 09:47:59 -0600241 }
Obaid Amin806df812013-02-21 13:30:26 -0600242 res = ccn_get(nlsr->ccn, name, templ, timeout_ms, resultbuf, &pcobuf, NULL,
243 get_flags);
akmhoquea0e71152013-02-11 09:47:59 -0600244 if (res >= 0) {
Obaid Amin806df812013-02-21 13:30:26 -0600245 ptr = resultbuf->buf;
246 length = resultbuf->length;
247 if (content_only){
248 ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length);
akmhoque7adb2772013-03-05 16:30:59 -0600249 struct ccn_parsed_ContentObject pcobuf1 = { 0 };
250 int chk_cont=ccn_parse_ContentObject(ptr,length,&pcobuf1,NULL);
akmhoquee2901222013-03-15 00:59:54 -0500251 if ( nlsr->debugging )
252 printf("Content Parsing result: %d\n",chk_cont);
akmhoque7adb2772013-03-05 16:30:59 -0600253 if ( contain_key_name(ptr, &pcobuf1) == 1){
akmhoque7adb2772013-03-05 16:30:59 -0600254
akmhoqueb7958182013-03-11 12:03:54 -0500255 int res_verify=verify_key(ptr,&pcobuf1,1);
akmhoque7adb2772013-03-05 16:30:59 -0600256
akmhoqueb7958182013-03-11 12:03:54 -0500257 if ( res_verify != 0 ){
akmhoquee2901222013-03-15 00:59:54 -0500258 if ( nlsr->debugging )
akmhoqueb7958182013-03-11 12:03:54 -0500259 printf("Error in verfiying keys !! :( \n");
260 }
261 else{
akmhoquee2901222013-03-15 00:59:54 -0500262 if ( nlsr->debugging )
263 printf("Key verification is successful :)\n");
akmhoquec90ca4d2013-03-15 09:30:17 -0500264 ptr_in=ptr;
265 length_in=length;
266 ccn_content_get_value(ptr_in, length_in, &pcobuf1,
267 &ptr_in, &length_in);
akmhoquee8319352013-03-15 19:51:53 -0500268 content_data = (unsigned char **)calloc(1,sizeof(char *));
akmhoque5079b652013-03-15 19:48:49 -0500269 *content_data = (unsigned char *) calloc(length_in,
akmhoque96607ec2013-03-15 19:53:03 -0500270 sizeof(char *));
akmhoque5079b652013-03-15 19:48:49 -0500271 memcpy (*content_data, ptr_in, length_in);
akmhoqueb7958182013-03-11 12:03:54 -0500272 ret=0;
273 }
akmhoque7adb2772013-03-05 16:30:59 -0600274 }
Obaid Amin806df812013-02-21 13:30:26 -0600275 }
akmhoquea0e71152013-02-11 09:47:59 -0600276 }
akmhoque7adb2772013-03-05 16:30:59 -0600277
Obaid Amin806df812013-02-21 13:30:26 -0600278 ccn_charbuf_destroy(&resultbuf);
279 ccn_charbuf_destroy(&templ);
akmhoque7adb2772013-03-05 16:30:59 -0600280 ccn_charbuf_destroy(&name);
281
282 return ret;
akmhoquea0e71152013-02-11 09:47:59 -0600283}
284
akmhoquec25f2242013-03-15 00:24:43 -0500285/**
286* Handle incoming lsa content, Calls functions to install lsa into lsdb
287*/
288
akmhoqueedb68d92013-03-05 10:18:16 -0600289void
akmhoquea0e71152013-02-11 09:47:59 -0600290process_incoming_sync_content_lsa( unsigned char *content_data)
291{
292
293
Obaid Amin806df812013-02-21 13:30:26 -0600294 if ( nlsr->debugging )
295 printf("process_incoming_sync_content_lsa called \n");
Obaid Aminbb8ac422013-02-20 17:08:48 -0600296
Obaid Amin806df812013-02-21 13:30:26 -0600297 char *sep="|";
298 char *rem;
299 char *orig_router;
300 char *orl;
301 int orig_router_length;
302 char *lst;
303 int ls_type;
304 char *lsid;
305 long int ls_id;
306 char *isvld;
307 int isValid;
308 char *num_link;
309 int no_link;
310 char *np;
311 char *np_length;
312 int name_length;
313 char *data;
314 char *orig_time;
Obaid Aminbb8ac422013-02-20 17:08:48 -0600315
316
akmhoquea0e71152013-02-11 09:47:59 -0600317 if ( nlsr->debugging )
Obaid Amin806df812013-02-21 13:30:26 -0600318 printf("LSA Data \n");
319
320 if( strlen((char *)content_data ) > 0 )
akmhoquea0e71152013-02-11 09:47:59 -0600321 {
Obaid Aminbb8ac422013-02-20 17:08:48 -0600322
Obaid Amin806df812013-02-21 13:30:26 -0600323 orig_router=strtok_r((char *)content_data,sep,&rem);
324 orl=strtok_r(NULL,sep,&rem);
325 orig_router_length=atoi(orl);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600326
Obaid Amin806df812013-02-21 13:30:26 -0600327 if ( nlsr->debugging )
328 {
329 printf(" Orig Router Name : %s\n",orig_router);
330 printf(" Orig Router Length: %d\n",orig_router_length);
331 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600332
Obaid Amin806df812013-02-21 13:30:26 -0600333 lst=strtok_r(NULL,sep,&rem);
334 ls_type=atoi(lst);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600335
Obaid Amin806df812013-02-21 13:30:26 -0600336 if ( nlsr->debugging )
337 printf(" LS Type : %d\n",ls_type);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600338
Obaid Amin806df812013-02-21 13:30:26 -0600339 if ( ls_type == LS_TYPE_NAME )
340 {
341 lsid=strtok_r(NULL,sep,&rem);
342 ls_id=atoi(lsid);
343 orig_time=strtok_r(NULL,sep,&rem);
344 isvld=strtok_r(NULL,sep,&rem);
345 isValid=atoi(isvld);
346 np=strtok_r(NULL,sep,&rem);
347 np_length=strtok_r(NULL,sep,&rem);
348 name_length=atoi(np_length);
349 if ( nlsr->debugging )
350 {
351 printf(" LS ID : %ld\n",ls_id);
352 printf(" isValid : %d\n",isValid);
353 printf(" Name Prefix : %s\n",np);
354 printf(" Orig Time : %s\n",orig_time);
355 printf(" Name Prefix length: %d\n",name_length);
356 }
357
akmhoque7adb2772013-03-05 16:30:59 -0600358 build_and_install_others_name_lsa(orig_router,ls_type,ls_id,
359 orig_time,isValid,np);
Obaid Amin806df812013-02-21 13:30:26 -0600360
361 print_name_lsdb();
362
363 }
364 else if ( ls_type == LS_TYPE_ADJ )
365 {
366 orig_time=strtok_r(NULL,sep,&rem);
367 num_link=strtok_r(NULL,sep,&rem);
368 no_link=atoi(num_link);
369 data=rem;
370
371 if ( nlsr->debugging )
372 {
373 printf(" Orig Time : %s\n",orig_time);
374 printf(" No Link : %d\n",no_link);
375 printf(" Data : %s\n",data);
376 }
akmhoque7adb2772013-03-05 16:30:59 -0600377 build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,
378 no_link,data);
Obaid Amin806df812013-02-21 13:30:26 -0600379 }
380 else if ( ls_type == LS_TYPE_COR )
381 {
382 orig_time=strtok_r(NULL,sep,&rem);
383 char *cor_r=strtok_r(NULL,sep,&rem);
384 char *cor_theta=strtok_r(NULL,sep,&rem);
385
386 double r, theta;
akmhoque8034d502013-02-24 11:53:24 -0600387 r=strtod(cor_r,NULL);
388 theta=strtod(cor_theta,NULL);
Obaid Amin806df812013-02-21 13:30:26 -0600389
390 if ( nlsr->debugging )
391 {
392 printf(" Orig Time : %s\n",orig_time);
393 printf(" Cor R : %f\n",r);
394 printf(" Cor Theta : %f\n",theta);
395 }
akmhoque7adb2772013-03-05 16:30:59 -0600396 build_and_install_others_cor_lsa(orig_router,ls_type,orig_time,
397 (double)r, (double)theta);
Obaid Amin806df812013-02-21 13:30:26 -0600398 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600399
400 }
akmhoquea0e71152013-02-11 09:47:59 -0600401}
402
akmhoquec25f2242013-03-15 00:24:43 -0500403/**
404* Check LSA whether its new. If new retrieve the LSA content and call
405* process_incoming_sync_content_lsa with content_data
406*/
407
akmhoque7adb2772013-03-05 16:30:59 -0600408void
Obaid Amin7997ad82013-02-22 16:41:56 -0600409process_content_from_sync (struct ccn_charbuf *content_name,
410 struct ccn_indexbuf *components)
akmhoquea0e71152013-02-11 09:47:59 -0600411{
akmhoque8c5e2662013-02-24 06:37:14 -0600412 if (nlsr->debugging)
413 printf("process_content_from_sync called \n");
Obaid Amin806df812013-02-21 13:30:26 -0600414 size_t comp_size;
415 char *lst;
416 char *lsid;
417 const unsigned char *second_last_comp;
418 const unsigned char *third_last_comp;
419 const unsigned char *origtime;
420 char *sep=".";
421 char *rem;
422 char *second_comp_type;
akmhoquea0e71152013-02-11 09:47:59 -0600423
Obaid Amin806df812013-02-21 13:30:26 -0600424 int ls_type;
425 long int ls_id=0;
akmhoquea0e71152013-02-11 09:47:59 -0600426
Obaid Amin806df812013-02-21 13:30:26 -0600427 unsigned char *content_data = NULL;
akmhoquea0e71152013-02-11 09:47:59 -0600428
akmhoqueb31caa12013-02-22 08:42:09 -0600429 char *time_stamp=get_current_timestamp_micro_v2();
akmhoquea0e71152013-02-11 09:47:59 -0600430
Obaid Amin806df812013-02-21 13:30:26 -0600431 struct ccn_charbuf *uri = ccn_charbuf_create();
432 ccn_uri_append(uri, content_name->buf, content_name->length, 0);
akmhoquea0e71152013-02-11 09:47:59 -0600433
Obaid Amin7997ad82013-02-22 16:41:56 -0600434 struct name_prefix *orig_router=(struct name_prefix *)
435 calloc( 1, sizeof(struct name_prefix));
akmhoquea0e71152013-02-11 09:47:59 -0600436
Obaid Amin7997ad82013-02-22 16:41:56 -0600437 ccn_name_comp_get( content_name->buf, components,
438 components->n-1-2, &second_last_comp, &comp_size);
439
Obaid Amin806df812013-02-21 13:30:26 -0600440 if (nlsr->debugging)
Obaid Amin7997ad82013-02-22 16:41:56 -0600441 printf("2nd Last Component: %s \n", second_last_comp);
akmhoquea0e71152013-02-11 09:47:59 -0600442
Obaid Amin7997ad82013-02-22 16:41:56 -0600443 second_comp_type=strtok_r((char *)second_last_comp, sep, &rem);
444 if (second_comp_type == NULL || rem == NULL)
445 {
446 printf ("Error: unable to tokenize the string: %s, calling exit()\n",
447 (char *)second_last_comp);
448 exit(0);
449 }
450
Obaid Amin806df812013-02-21 13:30:26 -0600451 if ( strcmp( second_comp_type, "lsId" ) == 0 )
452 {
453 lsid=rem;
454 ls_id=atoi(rem);
akmhoque7adb2772013-03-05 16:30:59 -0600455 ccn_name_comp_get(content_name->buf, components,components->n-2-2,
456 &third_last_comp, &comp_size);
Obaid Amin806df812013-02-21 13:30:26 -0600457 lst=strtok_r((char *)third_last_comp,sep,&rem);
458 lst=rem;
459 ls_type=atoi(lst);
akmhoque7adb2772013-03-05 16:30:59 -0600460 ccn_name_comp_get(content_name->buf, components,components->n-2,
461 &origtime, &comp_size);
Obaid Amin806df812013-02-21 13:30:26 -0600462 ccn_name_chop(content_name,components,-3);
463 get_name_part(orig_router,content_name,components,0);
akmhoquea0e71152013-02-11 09:47:59 -0600464
Obaid Aminbb8ac422013-02-20 17:08:48 -0600465 if ( nlsr->debugging )
akmhoque7adb2772013-03-05 16:30:59 -0600466 printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n",
467 orig_router->name,ls_type,ls_id,origtime);
akmhoquea0e71152013-02-11 09:47:59 -0600468
Obaid Amin806df812013-02-21 13:30:26 -0600469 int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
akmhoque8c5e2662013-02-24 06:37:14 -0600470 if ( nlsr->debugging )
471 printf("LSA Life time: %d\n",lsa_life_time);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600472
akmhoque483c1eb2013-03-08 00:51:09 -0600473 if ( strcmp(orig_router->name,nlsr->router_name) != 0
474 && (lsa_life_time < nlsr->router_dead_interval) )
Obaid Aminbb8ac422013-02-20 17:08:48 -0600475 {
akmhoque7adb2772013-03-05 16:30:59 -0600476 int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,
477 (char *)lst,(char *)lsid,(char *)origtime);
Obaid Amin806df812013-02-21 13:30:26 -0600478 if ( is_new_name_lsa == 1 )
479 {
480 if ( nlsr->debugging )
481 printf("New NAME LSA.....\n");
akmhoque7adb2772013-03-05 16:30:59 -0600482 int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
akmhoque5079b652013-03-15 19:48:49 -0500483 &content_data,orig_router->name);
akmhoque7adb2772013-03-05 16:30:59 -0600484 if ( chk_con == 0 ){
485 if ( nlsr->debugging )
486 printf("Content Data: %s \n",content_data);
487 process_incoming_sync_content_lsa(content_data);
488 }
489 else{
490 if ( nlsr->debugging )
491 printf("Verification failed. No content given back\n");
492 }
Obaid Amin806df812013-02-21 13:30:26 -0600493 }
494 else
495 {
496 if ( nlsr->debugging )
497 printf("Name LSA / Newer Name LSA already xists in LSDB\n");
akmhoque7adb2772013-03-05 16:30:59 -0600498 int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri)
akmhoque5079b652013-03-15 19:48:49 -0500499 , &content_data,orig_router->name);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600500
akmhoque7adb2772013-03-05 16:30:59 -0600501 if ( chk_con == 0 ){
502 if ( nlsr->debugging )
503 printf("Content Data: %s \n",content_data);
504 process_incoming_sync_content_lsa(content_data);
505 }
506 else{
507 if ( nlsr->debugging )
508 printf("Verification failed. No content given back\n");
509 }
Obaid Amin806df812013-02-21 13:30:26 -0600510 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600511 }
Obaid Amin806df812013-02-21 13:30:26 -0600512 else
Obaid Aminbb8ac422013-02-20 17:08:48 -0600513 {
Obaid Amin806df812013-02-21 13:30:26 -0600514 if ( nlsr->debugging )
515 printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
Obaid Aminbb8ac422013-02-20 17:08:48 -0600516 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600517 }
Obaid Amin806df812013-02-21 13:30:26 -0600518 else
Obaid Aminbb8ac422013-02-20 17:08:48 -0600519 {
Obaid Amin806df812013-02-21 13:30:26 -0600520 ls_type=atoi(rem);
521 lst=rem;
522 if(ls_type == LS_TYPE_ADJ)
Obaid Aminbb8ac422013-02-20 17:08:48 -0600523 {
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600524 ccn_name_comp_get(content_name->buf, components,components->n-2,
525 &origtime, &comp_size);
Obaid Amin806df812013-02-21 13:30:26 -0600526 ccn_name_chop(content_name,components,-2);
527 get_name_part(orig_router,content_name,components,0);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600528
Obaid Amin806df812013-02-21 13:30:26 -0600529 if ( nlsr->debugging )
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600530 printf("Orig Router: %s Ls Type: %d Orig Time: %s\n",
531 orig_router->name,ls_type,origtime);
Obaid Amin806df812013-02-21 13:30:26 -0600532
533 int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
akmhoque8c5e2662013-02-24 06:37:14 -0600534 if ( nlsr->debugging )
535 printf("LSA Life time: %d\n",lsa_life_time);
536
akmhoque483c1eb2013-03-08 00:51:09 -0600537 if ( strcmp(orig_router->name,nlsr->router_name) != 0
538 && (lsa_life_time < nlsr->router_dead_interval) )
Obaid Amin806df812013-02-21 13:30:26 -0600539 {
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600540 int is_new_adj_lsa = check_is_new_adj_lsa( orig_router->name,
541 (char *)lst, (char *)origtime);
Obaid Amin806df812013-02-21 13:30:26 -0600542 if ( is_new_adj_lsa == 1 )
543 {
544 if ( nlsr->debugging )
545 printf("New Adj LSA.....\n");
akmhoque7adb2772013-03-05 16:30:59 -0600546 int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
akmhoque5079b652013-03-15 19:48:49 -0500547 &content_data,orig_router->name);
Obaid Amin806df812013-02-21 13:30:26 -0600548
akmhoque7adb2772013-03-05 16:30:59 -0600549 if ( chk_con == 0 ){
550 if ( nlsr->debugging )
551 printf("Content Data: %s \n",content_data);
552 process_incoming_sync_content_lsa(content_data);
553 }
554 else{
555 if ( nlsr->debugging )
556 printf("Verification failed. No content given back\n");
557 }
Obaid Amin806df812013-02-21 13:30:26 -0600558 }
559 else
560 {
561 if ( nlsr->debugging )
562 printf("Adj LSA / Newer Adj LSA already exists in LSDB\n");
akmhoque7adb2772013-03-05 16:30:59 -0600563 int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
akmhoque5079b652013-03-15 19:48:49 -0500564 &content_data,orig_router->name);
akmhoque7adb2772013-03-05 16:30:59 -0600565 if ( chk_con == 0 ){
566 if ( nlsr->debugging )
567 printf("Content Data: %s \n",content_data);
568 process_incoming_sync_content_lsa(content_data);
569 }
570 else{
571 if ( nlsr->debugging )
572 printf("Verification failed. No content given back\n");
573 }
Obaid Amin806df812013-02-21 13:30:26 -0600574 }
575 }
576 else
577 {
578 if ( nlsr->debugging )
579 printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
580 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600581 }
Obaid Amin806df812013-02-21 13:30:26 -0600582 else if(ls_type == LS_TYPE_COR)
Obaid Aminbb8ac422013-02-20 17:08:48 -0600583 {
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600584 ccn_name_comp_get(content_name->buf, components, components->n-2,
585 &origtime, &comp_size);
Obaid Amin806df812013-02-21 13:30:26 -0600586 ccn_name_chop(content_name,components,-2);
587 get_name_part(orig_router,content_name,components,0);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600588
Obaid Amin806df812013-02-21 13:30:26 -0600589 if ( nlsr->debugging )
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600590 printf("Orig Router: %s Ls Type: %d Orig Time: %s\n",
591 orig_router->name,ls_type,origtime);
Obaid Amin806df812013-02-21 13:30:26 -0600592
593 int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
akmhoque8c5e2662013-02-24 06:37:14 -0600594 if ( nlsr->debugging )
595 printf("LSA Life time: %d\n",lsa_life_time);
596
akmhoque483c1eb2013-03-08 00:51:09 -0600597 if ( strcmp(orig_router->name,nlsr->router_name) != 0
598 && (lsa_life_time < nlsr->router_dead_interval) )
Obaid Amin806df812013-02-21 13:30:26 -0600599 {
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600600 int is_new_cor_lsa=check_is_new_cor_lsa( orig_router->name,
601 (char *)lst,(char *) origtime);
Obaid Amin806df812013-02-21 13:30:26 -0600602 if ( is_new_cor_lsa == 1 )
603 {
604 if ( nlsr->debugging )
605 printf("New Cor LSA.....\n");
akmhoque7adb2772013-03-05 16:30:59 -0600606 int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
akmhoque5079b652013-03-15 19:48:49 -0500607 &content_data,
akmhoque7adb2772013-03-05 16:30:59 -0600608 orig_router->name);
Obaid Amin806df812013-02-21 13:30:26 -0600609
akmhoque7adb2772013-03-05 16:30:59 -0600610 if ( chk_con == 0 ){
611 if ( nlsr->debugging )
612 printf("Content Data: %s \n",content_data);
613 process_incoming_sync_content_lsa(content_data);
614 }
615 else{
616 if ( nlsr->debugging )
617 printf("Verification failed. No content given back\n");
618 }
Obaid Amin806df812013-02-21 13:30:26 -0600619 }
620 else
621 {
622 if ( nlsr->debugging )
623 printf("Cor LSA / Newer Cor LSA already exists in LSDB\n");
akmhoque7adb2772013-03-05 16:30:59 -0600624 int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
akmhoque5079b652013-03-15 19:48:49 -0500625 &content_data,orig_router->name);
akmhoque7adb2772013-03-05 16:30:59 -0600626 if ( chk_con == 0 ){
627 if ( nlsr->debugging )
628 printf("Content Data: %s \n",content_data);
629 process_incoming_sync_content_lsa(content_data);
630 }
631 else{
632 if ( nlsr->debugging )
633 printf("Verification failed. No content given back\n");
634 }
Obaid Amin806df812013-02-21 13:30:26 -0600635 }
636 }
637 else
638 {
639 if ( nlsr->debugging )
640 printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
641 }
642
643 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600644 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600645
akmhoquec25f2242013-03-15 00:24:43 -0500646 if(content_data)
647 free(content_data);
648
akmhoquef6773612013-02-23 09:53:00 -0600649 if (orig_router->name)
650 free(orig_router->name);
Obaid Amin05300892013-02-21 13:45:25 -0600651 if (orig_router)
652 free(orig_router);
Obaid Amin806df812013-02-21 13:30:26 -0600653 ccn_charbuf_destroy(&uri);
654 //01/31/2013
655 free(time_stamp);
akmhoquea0e71152013-02-11 09:47:59 -0600656}
657
akmhoquec25f2242013-03-15 00:24:43 -0500658/**
659* This function performs same functionality as ccnsyncwatch
660*/
661
662
663int
akmhoquea0e71152013-02-11 09:47:59 -0600664sync_monitor(char *topo_prefix, char *slice_prefix)
665{
666
Obaid Amin806df812013-02-21 13:30:26 -0600667 struct ccn_charbuf *prefix = ccn_charbuf_create();
Obaid Amin806df812013-02-21 13:30:26 -0600668 struct ccn_charbuf *topo = ccn_charbuf_create();
Obaid Amin7997ad82013-02-22 16:41:56 -0600669
670 nlsr->closure=(struct ccns_name_closure *)
akmhoquececba942013-02-25 17:33:34 -0600671 calloc(1,sizeof(struct ccns_name_closure)); // leak
Obaid Amin7997ad82013-02-22 16:41:56 -0600672
Obaid Amin806df812013-02-21 13:30:26 -0600673 nlsr->slice = ccns_slice_create();
Obaid Aminbb8ac422013-02-20 17:08:48 -0600674
Obaid Amin806df812013-02-21 13:30:26 -0600675 ccn_charbuf_reset(prefix);
676 ccn_name_from_uri(prefix, slice_prefix);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600677
Obaid Amin806df812013-02-21 13:30:26 -0600678 ccn_charbuf_reset(topo);
679 ccn_name_from_uri(topo, topo_prefix);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600680
Obaid Amin806df812013-02-21 13:30:26 -0600681 ccns_slice_set_topo_prefix(nlsr->slice, topo, prefix);
682 nlsr->closure->callback = &sync_cb;
akmhoque54d86112013-02-21 16:42:34 -0600683 nlsr->ccns = ccns_open(nlsr->ccn, nlsr->slice, nlsr->closure, NULL, NULL);
akmhoquea0e71152013-02-11 09:47:59 -0600684
Obaid Amin7997ad82013-02-22 16:41:56 -0600685 ccn_charbuf_destroy(&prefix);
686 ccn_charbuf_destroy(&topo);
Obaid Amin806df812013-02-21 13:30:26 -0600687 return 0;
akmhoquea0e71152013-02-11 09:47:59 -0600688}
689
akmhoquead6d5692013-03-11 19:43:33 -0500690struct ccn_charbuf *
akmhoquea0e71152013-02-11 09:47:59 -0600691make_template(int scope)
692{
Obaid Amin806df812013-02-21 13:30:26 -0600693 struct ccn_charbuf *templ = NULL;
694 templ = ccn_charbuf_create();
695 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
696 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
697 ccn_charbuf_append_closer(templ); /* </Name> */
698 if (0 <= scope && scope <= 2)
699 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
700 ccn_charbuf_append_closer(templ); /* </Interest> */
701 return(templ);
akmhoquea0e71152013-02-11 09:47:59 -0600702}
703
akmhoquec25f2242013-03-15 00:24:43 -0500704/**
705* Write signed data to repo
706*/
707
708
709int
akmhoquea0e71152013-02-11 09:47:59 -0600710write_data_to_repo(char *data, char *name_prefix)
711{
akmhoque483c1eb2013-03-08 00:51:09 -0600712
713 nlsr_lock();
Obaid Amin806df812013-02-21 13:30:26 -0600714 if ( nlsr->debugging )
715 {
716 printf("write_data_to_repo called\n");
717 printf("Content Name: %s \n",name_prefix);
718 printf("Content Data: %s \n",data);
719 }
akmhoquea0e71152013-02-11 09:47:59 -0600720
Obaid Aminf210a322013-02-22 02:04:52 -0600721 struct ccn *temp_ccn;
Obaid Amin806df812013-02-21 13:30:26 -0600722 temp_ccn=ccn_create();
723 int ccn_fd=ccn_connect(temp_ccn, NULL);
724 if(ccn_fd == -1)
725 {
726 fprintf(stderr,"Could not connect to ccnd for Data Writing\n");
Obaid Amin4b0e4ec2013-02-24 22:15:01 -0600727 writeLogg(__FILE__,__FUNCTION__,__LINE__,
728 "Could not connect to ccnd for Data Writing\n");
Obaid Amin806df812013-02-21 13:30:26 -0600729 return -1;
730 }
Obaid Aminf210a322013-02-22 02:04:52 -0600731
Obaid Amin806df812013-02-21 13:30:26 -0600732 struct ccn_charbuf *name = NULL;
733 struct ccn_seqwriter *w = NULL;
734 int blocksize = 4096;
735 int freshness = -1;
Obaid Amin806df812013-02-21 13:30:26 -0600736 int scope = 1;
737 int res;
738 size_t blockread;
739 struct ccn_charbuf *templ;
Obaid Aminbb8ac422013-02-20 17:08:48 -0600740
Obaid Amin806df812013-02-21 13:30:26 -0600741 name = ccn_charbuf_create();
742 res = ccn_name_from_uri(name, name_prefix);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600743 if (res < 0) {
Obaid Amin806df812013-02-21 13:30:26 -0600744 fprintf(stderr, "bad CCN URI: %s\n",name_prefix);
745 return -1;
Obaid Aminbb8ac422013-02-20 17:08:48 -0600746 }
Obaid Amin806df812013-02-21 13:30:26 -0600747
Obaid Aminf210a322013-02-22 02:04:52 -0600748 w = ccn_seqw_create(temp_ccn, name);
Obaid Amin806df812013-02-21 13:30:26 -0600749 if (w == NULL) {
750 fprintf(stderr, "ccn_seqw_create failed\n");
751 return -1;
752 }
753 ccn_seqw_set_block_limits(w, blocksize, blocksize);
754 if (freshness > -1)
755 ccn_seqw_set_freshness(w, freshness);
akmhoquea0e71152013-02-11 09:47:59 -0600756
Obaid Amin7997ad82013-02-22 16:41:56 -0600757 struct ccn_charbuf *name_v = ccn_charbuf_create();
758 ccn_seqw_get_name(w, name_v);
759 ccn_name_from_uri(name_v, "%C1.R.sw");
760 ccn_name_append_nonce(name_v);
761 templ = make_template(scope);
762 res = ccn_get(temp_ccn, name_v, templ, 60000, NULL, NULL, NULL, 0);
763 ccn_charbuf_destroy(&templ);
764 ccn_charbuf_destroy(&name_v);
765 if (res < 0) {
766 fprintf(stderr, "No response from repository\n");
767 return -1;
768 }
akmhoquea0e71152013-02-11 09:47:59 -0600769
akmhoque7adb2772013-03-05 16:30:59 -0600770 struct ccn_charbuf *resultbuf=ccn_charbuf_create();
akmhoquea0e71152013-02-11 09:47:59 -0600771
akmhoque7adb2772013-03-05 16:30:59 -0600772 sign_content_with_user_defined_keystore(name,
773 resultbuf,
774 data,
775 strlen(data),
776 nlsr->keystore_path,
777 nlsr->keystore_passphrase,
778 nlsr->root_key_prefix,
779 nlsr->site_name,
780 nlsr->router_name);
781
782
akmhoque7adb2772013-03-05 16:30:59 -0600783 blockread=resultbuf->length;
akmhoquea0e71152013-02-11 09:47:59 -0600784
Obaid Amin806df812013-02-21 13:30:26 -0600785 if (blockread > 0) {
akmhoque7adb2772013-03-05 16:30:59 -0600786 res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);
Obaid Amin806df812013-02-21 13:30:26 -0600787 while (res == -1) {
akmhoquec25f2242013-03-15 00:24:43 -0500788 ccn_run(temp_ccn,1);
akmhoque7adb2772013-03-05 16:30:59 -0600789 res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);
Obaid Amin806df812013-02-21 13:30:26 -0600790 }
791 }
792
akmhoque8034d502013-02-24 11:53:24 -0600793 ccn_seqw_close(w);
akmhoquec25f2242013-03-15 00:24:43 -0500794 ccn_run(temp_ccn, 1);
Obaid Amin806df812013-02-21 13:30:26 -0600795 ccn_charbuf_destroy(&name);
akmhoque0ed6d982013-02-22 14:28:01 -0600796 ccn_destroy(&temp_ccn);
akmhoque6e2ba842013-03-05 19:35:26 -0600797 ccn_charbuf_destroy(&resultbuf);
akmhoquea0e71152013-02-11 09:47:59 -0600798
akmhoque483c1eb2013-03-08 00:51:09 -0600799 nlsr_unlock();
Obaid Amin806df812013-02-21 13:30:26 -0600800 return 0;
akmhoquea0e71152013-02-11 09:47:59 -0600801}
akmhoquec25f2242013-03-15 00:24:43 -0500802
803/**
804* Create slice for sync/repo
805*/
806
807
808int
809create_sync_slice(char *topo_prefix, char *slice_prefix)
akmhoquea0e71152013-02-11 09:47:59 -0600810{
Obaid Amin806df812013-02-21 13:30:26 -0600811 int res;
akmhoque7adb2772013-03-05 16:30:59 -0600812 struct ccn *handle;
Obaid Amin806df812013-02-21 13:30:26 -0600813 struct ccns_slice *slice;
814 struct ccn_charbuf *prefix = ccn_charbuf_create();
815 struct ccn_charbuf *topo = ccn_charbuf_create();
816 struct ccn_charbuf *clause = ccn_charbuf_create();
817 struct ccn_charbuf *slice_name = ccn_charbuf_create();
818 struct ccn_charbuf *slice_uri = ccn_charbuf_create();
Obaid Aminbb8ac422013-02-20 17:08:48 -0600819
Obaid Amin806df812013-02-21 13:30:26 -0600820 if (prefix == NULL || topo == NULL || clause == NULL ||
821 slice_name == NULL || slice_uri == NULL) {
822 fprintf(stderr, "Unable to allocate required memory.\n");
823 return -1;
824 }
Obaid Aminbb8ac422013-02-20 17:08:48 -0600825
akmhoque0ed6d982013-02-22 14:28:01 -0600826 handle = ccn_create();
Obaid Amin806df812013-02-21 13:30:26 -0600827 res = ccn_connect(handle, NULL);
828 if (0 > res) {
829 fprintf(stderr, "Unable to connect to ccnd.\n");
830 return -1;
831 }
akmhoque0ed6d982013-02-22 14:28:01 -0600832
Obaid Amin806df812013-02-21 13:30:26 -0600833 slice = ccns_slice_create();
Obaid Aminbb8ac422013-02-20 17:08:48 -0600834
Obaid Amin806df812013-02-21 13:30:26 -0600835 ccn_charbuf_reset(topo);
836 ccn_name_from_uri(topo, topo_prefix);
837 ccn_charbuf_reset(prefix);
838 ccn_name_from_uri(prefix,slice_prefix );
839 ccns_slice_set_topo_prefix(slice, topo, prefix);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600840
841
akmhoque0ed6d982013-02-22 14:28:01 -0600842 res = ccns_write_slice(handle, slice, slice_name);
Obaid Aminbb8ac422013-02-20 17:08:48 -0600843
Obaid Amin806df812013-02-21 13:30:26 -0600844 //01/31/2013
845 ccns_slice_destroy(&slice);
akmhoque0ed6d982013-02-22 14:28:01 -0600846 ccn_destroy(&handle);
Obaid Amin806df812013-02-21 13:30:26 -0600847 ccn_charbuf_destroy(&prefix);
848 ccn_charbuf_destroy(&topo);
849 ccn_charbuf_destroy(&clause);
850 ccn_charbuf_destroy(&slice_name);
851 ccn_charbuf_destroy(&slice_uri);
akmhoquea0e71152013-02-11 09:47:59 -0600852
Obaid Amin806df812013-02-21 13:30:26 -0600853 return 0;
akmhoquea0e71152013-02-11 09:47:59 -0600854}
855
akmhoque0eb8de22013-02-24 14:08:19 -0600856