Skip to content

Commit

Permalink
Add thunk example
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksheeep committed Apr 16, 2014
1 parent b10ae5f commit 6863664
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
25 changes: 22 additions & 3 deletions ccnl-core.c
Expand Up @@ -640,7 +640,7 @@ ccnl_interest_propagate(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i)
DEBUGMSG(99, "ccnl_interest_propagate\n");

ccnl_print_stats(ccnl, STAT_SND_I); // log_send_i

// CONFORM: "A node MUST implement some strategy rule, even if it is only to
// transmit an Interest Message on all listed dest faces in sequence."
// CCNL strategy: we forward on all FWD entries with a prefix match
Expand Down Expand Up @@ -969,14 +969,33 @@ ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
if (buf_equal(c->pkt, buf)) goto Skip; // content is dup
c = ccnl_content_new(relay, &buf, &p, &ppkd, content, contlen);
if (c) { // CONFORM: Step 2 (and 3)


#ifdef CCNL_NFN
fprintf(stderr, "PIT Entries: \n");
struct ccnl_interest_s *i_it;
for(i_it = relay->pit; i_it; i_it = i_it->next){
int it;
fprintf(stderr, " - ");
for(it = 0; it < i_it->prefix->compcnt; ++it){
fprintf(stderr, "/%s", i_it->prefix->comp[it]);
}
fprintf(stderr, " --- from-faceid: %d propagate: %d \n", i_it->from->faceid, i_it->propagate);
}
fprintf(stderr, "Content name: ");
int it = 0;
for(it = 0; it < c->name->compcnt; ++it){
fprintf(stderr, "/%s", c->name->comp[it]);
}fprintf(stderr, "\n");
if(!memcmp(c->name->comp[c->name->compcnt-1], "NFN", 3)){
struct ccnl_interest_s *i_it = NULL;
int found = 0;
for(i_it = relay->pit; i_it; i_it = i_it->next){
int md = i_it->prefix->compcnt - c->name->compcnt == 1 ? compute_ccnx_digest(c->pkt) : NULL;
//Check if prefix match and it is a nfn request
if(ccnl_prefix_cmp(c->name, md, i_it->prefix, CMP_EXACT)
//Check if prefix match and it is a nfn request
int cmp = ccnl_prefix_cmp(c->name, md, i_it->prefix, CMP_MATCH);
DEBUGMSG(99, "CMP: %d, faceid: %d \n", cmp, i_it->from->faceid);
if( ccnl_prefix_cmp(c->name, md, i_it->prefix, CMP_MATCH)
&& i_it->from->faceid < 0){
ccnl_content_add2cache(relay, c);
int threadid = -i_it->from->faceid;
Expand Down
4 changes: 3 additions & 1 deletion ccnl-ext-nfn.c
Expand Up @@ -114,7 +114,9 @@ ccnl_nfn_thread(void *arg)
{
ccnl_nfn_delete_prefix(prefix);
}*/
//pthread_exit ((void *) 0);
struct thread_s *thread1 = main_thread;
pthread_cond_broadcast(&thread1->cond);
pthread_exit ((void *) 0);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions krivine-common.c
Expand Up @@ -446,10 +446,10 @@ isLocalAvailable(struct ccnl_relay_s *ccnl, struct configuration_s *config, char
interest->propagate = 0;
int found = 0;
struct ccnl_content_s *c;
if((c = ccnl_nfn_local_content_search(ccnl, interest, CMP_MATCH)) != NULL){ //todo: exact match not only prefix
if((c = ccnl_nfn_local_content_search(ccnl, interest, CMP_EXACT)) != NULL){ //todo: exact match not only prefix
found = 1;
}
//interest = ccnl_interest_remove(ccnl, interest);
interest = ccnl_interest_remove(ccnl, interest);
return found;
}

Expand Down
2 changes: 2 additions & 0 deletions krivine.c
Expand Up @@ -699,9 +699,11 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *configuration,
if(thunk_request){ //if thunk_request push thunkid on the stack

--(*num_of_required_thunks);
DEBUGMSG(99, "%d thunks are required\n", *num_of_required_thunks);
char * thunkid = ccnl_nfn_add_thunk(ccnl, configuration, c->name);
push_to_stack(&configuration->result_stack, thunkid);
if( *num_of_required_thunks <= 0){
DEBUGMSG(99, "All thunks are available\n");
ccnl_nfn_reply_thunk(ccnl, original_prefix);
}
}
Expand Down
Binary file added test/ccnb/nfn/computation_dummy_thunk.ccnb
Binary file not shown.
31 changes: 31 additions & 0 deletions test/scripts/nfn/compute_thunk_demo.sh
@@ -0,0 +1,31 @@
killall ccn-lite-relay
killall python

$CCNL_HOME/ccn-lite-relay -v 99 -u 9000 -x /tmp/mgmt1.sock 2> /tmp/r0.log &
$CCNL_HOME/ccn-lite-relay -v 99 -u 9001 -x /tmp/mgmt2.sock 2> /tmp/r1.log &

sleep 3

$CCNL_HOME/util/ccn-lite-ctrl -x /tmp/mgmt1.sock newUDPface any 127.0.0.1 9001 | $CCNL_HOME/util/ccn-lite-ccnb2xml
$CCNL_HOME/util/ccn-lite-ctrl -x /tmp/mgmt2.sock newUDPface any 127.0.0.1 9002 | $CCNL_HOME/util/ccn-lite-ccnb2xml

sleep 3

$CCNL_HOME/util/ccn-lite-ctrl -x /tmp/mgmt1.sock prefixreg /test 2 | $CCNL_HOME/util/ccn-lite-ccnb2xml
$CCNL_HOME/util/ccn-lite-ctrl -x /tmp/mgmt2.sock prefixreg /COMPUTE 2 | $CCNL_HOME/util/ccn-lite-ccnb2xml

sleep 3

$CCNL_HOME/util/ccn-lite-ctrl -x /tmp/mgmt2.sock addContentToCache $CCNL_HOME/test/ccnb/nfn/computation_content.ccnb | $CCNL_HOME/util/ccn-lite-ccnb2xml

sleep 3

python $CCNL_HOME/test/scripts/nfn/dummyanswer.py & > /dev/null

sleep 3

$CCNL_HOME/util/ccn-lite-peekcomputation -t -u 127.0.0.1/9000 -w 100 "(@x add 6 (call 1 x))" "/test/data" | $CCNL_HOME/util/ccn-lite-ccnb2hex

sleep 5

$CCNL_HOME/util/ccn-lite-peekcomputation -u 127.0.0.1/9000 -w 100 "(@x add 6 (call 1 x))" "/test/data" | $CCNL_HOME/util/ccn-lite-ccnb2hex
2 changes: 1 addition & 1 deletion test/scripts/nfn/dummyanswer.py
Expand Up @@ -20,7 +20,7 @@
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data
time.sleep(2)
# time.sleep(2)
if "THUNK" in data:
sock.sendto(c_t, ("127.0.0.1", 9001))
else:
Expand Down

0 comments on commit 6863664

Please sign in to comment.