Skip to content

Commit

Permalink
Local Computation with NDNTLV
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksheeep committed Jun 13, 2014
1 parent 4a5fd24 commit 0698053
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 77 deletions.
1 change: 1 addition & 0 deletions ccnl-ext-nfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ ccnl_nfn(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig,
{
DEBUGMSG(49, "ccnl_nfn(%p, %p, %p, %p, %p)\n",
(void*)ccnl, (void*)orig, (void*)prefix, (void*)from, (void*)config);
DEBUGMSG(99, "Namecomps: %s \n", ccnl_prefix_to_path2(prefix));
int thunk_request = 0;
if(config){
suite = config->suite;
Expand Down
2 changes: 1 addition & 1 deletion fwd-ccnb.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ ccnl_ccnb_forwarder(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from,
if (c) { // CONFORM: Step 2 (and 3)
#ifdef CCNL_NFN
if(debug_level >= 99){
printf(stderr, "PIT Entries: \n");
fprintf(stderr, "PIT Entries: \n");
struct ccnl_interest_s *i_it;
for(i_it = ccnl->pit; i_it; i_it = i_it->next){
int it;
Expand Down
197 changes: 143 additions & 54 deletions fwd-ndntlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "pkt-ndntlv.h"
#include "pkt-ndntlv-dec.c"

#ifdef CCNL_NFN
#include "krivine-common.h"
#endif

// we use one extraction routine for both interest and data pkts
struct ccnl_buf_s*
ccnl_ndntlv_extract(int hdrlen, unsigned char **data, int *datalen,
Expand Down Expand Up @@ -149,60 +153,99 @@ ccnl_ndntlv_forwarder(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
}

if (typ == NDN_TLV_Interest) {
if (nonce && ccnl_nonce_find_or_append(relay, nonce)) {
DEBUGMSG(6, " dropped because of duplicate nonce\n"); goto Skip;
}
DEBUGMSG(6, " interest=<%s>\n", ccnl_prefix_to_path(p));
ccnl_print_stats(relay, STAT_RCV_I); //log count recv_interest
/*
filter here for link level management messages ...
if (p->compcnt == 4 && !memcmp(p->comp[0], "ccnx", 4)) {
rc = ccnl_mgmt(relay, buf, p, from); goto Done;
}
*/
// CONFORM: Step 1: search for matching local content
for (c = relay->contents; c; c = c->next) {
if (c->suite != CCNL_SUITE_NDNTLV) continue;
if (!ccnl_i_prefixof_c(p, minsfx, maxsfx, c)) continue;
if (ppkl && !buf_equal(ppkl, c->details.ndntlv.ppkl)) continue;
// FIXME: should check freshness (mbf) here
// if (mbf) // honor "answer-from-existing-content-store" flag
DEBUGMSG(7, " matching content for interest, content %p\n", (void *) c);
ccnl_print_stats(relay, STAT_SND_C); //log sent_c
if (from->ifndx >= 0)
ccnl_face_enqueue(relay, from, buf_dup(c->pkt));
else
ccnl_app_RX(relay, c);
goto Skip;
}
// CONFORM: Step 2: check whether interest is already known
for (i = relay->pit; i; i = i->next) {
if (i->suite == CCNL_SUITE_NDNTLV &&
!ccnl_prefix_cmp(i->prefix, NULL, p, CMP_EXACT) &&
i->details.ndntlv.minsuffix == minsfx &&
i->details.ndntlv.maxsuffix == maxsfx &&
((!ppkl && !i->details.ndntlv.ppkl) ||
buf_equal(ppkl, i->details.ndntlv.ppkl)) )
break;
}
if (!i) { // this is a new/unknown I request: create and propagate
i = ccnl_interest_new(relay, from, CCNL_SUITE_NDNTLV,
&buf, &p, minsfx, maxsfx);
if (ppkl)
i->details.ndntlv.ppkl = ppkl, ppkl = NULL;
if (i) { // CONFORM: Step 3 (and 4)
DEBUGMSG(7, " created new interest entry %p\n", (void *) i);
if (scope > 2)
ccnl_interest_propagate(relay, i);
}
} else if (scope > 2 && (from->flags & CCNL_FACE_FLAGS_FWDALLI)) {
DEBUGMSG(7, " old interest, nevertheless propagated %p\n", (void *) i);
ccnl_interest_propagate(relay, i);
}
if (i) { // store the I request, for the incoming face (Step 3)
DEBUGMSG(7, " appending interest entry %p\n", (void *) i);
ccnl_interest_append_pending(i, from);
}
if (nonce && ccnl_nonce_find_or_append(relay, nonce)) {
DEBUGMSG(6, " dropped because of duplicate nonce\n"); //goto Skip;
}
DEBUGMSG(6, " interest=<%s>\n", ccnl_prefix_to_path(p));
ccnl_print_stats(relay, STAT_RCV_I); //log count recv_interest
/*
filter here for link level management messages ...
if (p->compcnt == 4 && !memcmp(p->comp[0], "ccnx", 4)) {
rc = ccnl_mgmt(relay, buf, p, from); goto Done;
}
*/
// CONFORM: Step 1: search for matching local content
for (c = relay->contents; c; c = c->next) {
if (c->suite != CCNL_SUITE_NDNTLV) continue;
if (!ccnl_i_prefixof_c(p, minsfx, maxsfx, c)) continue;
if (ppkl && !buf_equal(ppkl, c->details.ndntlv.ppkl)) continue;
// FIXME: should check freshness (mbf) here
// if (mbf) // honor "answer-from-existing-content-store" flag
DEBUGMSG(7, " matching content for interest, content %p\n", (void *) c);
ccnl_print_stats(relay, STAT_SND_C); //log sent_c
if (from->ifndx >= 0){
#ifdef CCNL_NFN_MONITOR
char monitorpacket[CCNL_MAX_PACKET_SIZE];
int l = create_packet_log(inet_ntoa(from->peer.ip4.sin_addr),
ntohs(from->peer.ip4.sin_port),
c->name, (char*)c->content, c->contentlen, monitorpacket);
sendtomonitor(relay, monitorpacket, l);
#endif
ccnl_face_enqueue(relay, from, buf_dup(c->pkt));
}
else{
ccnl_app_RX(relay, c);
}
goto Skip;
}
// CONFORM: Step 2: check whether interest is already known
for (i = relay->pit; i; i = i->next) {
if (i->suite == CCNL_SUITE_NDNTLV &&
!ccnl_prefix_cmp(i->prefix, NULL, p, CMP_EXACT) &&
i->details.ndntlv.minsuffix == minsfx &&
i->details.ndntlv.maxsuffix == maxsfx &&
((!ppkl && !i->details.ndntlv.ppkl) ||
buf_equal(ppkl, i->details.ndntlv.ppkl)) )
break;
}
if (!i) { // this is a new/unknown I request: create and propagate
#ifdef CCNL_NFN
if((numOfRunningComputations < NFN_MAX_RUNNING_COMPUTATIONS) //full, do not compute but propagate
&& !memcmp(p->comp[p->compcnt-1], "NFN", 3)){
struct ccnl_buf_s *buf2 = buf;
//Create new prefix
struct ccnl_prefix_s *p2 = malloc(sizeof(struct ccnl_prefix_s));
p2->compcnt = p->compcnt;
p2->complen = malloc(sizeof(int) * p->compcnt);
p2->comp = malloc(sizeof(char *) * p->compcnt);
int it1, it2;
for(it1 = 0; it1 < p->compcnt; ++it1){
int len = 0;
p2->complen[it1] = p->complen[it1];
p2->comp[it1] = malloc(p->complen[it1] + 1);
for(it2 = 0; it2 < p->complen[it1]; ++it2){
len += sprintf(p2->comp[it1]+it2, "%c", p->comp[it1][it2]);
}
sprintf(p2->comp[it1]+ len, "\0");
printf("\n");
}

i = ccnl_interest_new(relay, from, CCNL_SUITE_NDNTLV,
&buf, &p, minsfx, maxsfx);

i->propagate = 0; //do not forward interests for running computations
ccnl_interest_append_pending(i, from);
if(!i->propagate)ccnl_nfn(relay, buf2, p2, from, NULL, i, CCNL_SUITE_NDNTLV);
goto Done;
}
#endif /*CCNL_NFN*/
i = ccnl_interest_new(relay, from, CCNL_SUITE_NDNTLV,
&buf, &p, minsfx, maxsfx);
if (ppkl)
i->details.ndntlv.ppkl = ppkl, ppkl = NULL;
if (i) { // CONFORM: Step 3 (and 4)
DEBUGMSG(7, " created new interest entry %p\n", (void *) i);
if (scope > 2)
ccnl_interest_propagate(relay, i);
}
} else if (scope > 2 && (from->flags & CCNL_FACE_FLAGS_FWDALLI)) {
DEBUGMSG(7, " old interest, nevertheless propagated %p\n", (void *) i);
ccnl_interest_propagate(relay, i);
}
if (i) { // store the I request, for the incoming face (Step 3)
DEBUGMSG(7, " appending interest entry %p\n", (void *) i);
ccnl_interest_append_pending(i, from);
}

} else { // data packet with content -------------------------------------
DEBUGMSG(6, " data=<%s>\n", ccnl_prefix_to_path(p));
Expand All @@ -225,6 +268,52 @@ ccnl_ndntlv_forwarder(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
c = ccnl_content_new(relay, CCNL_SUITE_NDNTLV,
&buf, &p, NULL, content, contlen);
if (c) { // CONFORM: Step 2 (and 3)
#ifdef CCNL_NFN
if(debug_level >= 99){
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*/){
//Check if prefix match and it is a nfn request
int cmp = ccnl_prefix_cmp(c->name, NULL, i_it->prefix, CMP_EXACT);
DEBUGMSG(99, "CMP: %d (match if zero), faceid: %d \n", cmp, i_it->from->faceid);
if( !ccnl_prefix_cmp(c->name, NULL, i_it->prefix, CMP_EXACT)
&& i_it->from->faceid < 0){
ccnl_content_add2cache(relay, c);
int configid = -i_it->from->faceid;
DEBUGMSG(49, "Continue configuration for configid: %d\n", configid);

int faceid = -i_it->from->faceid;
i_it->propagate = 1;
i_it = ccnl_interest_remove(relay, i_it);
ccnl_nfn_continue_computation(relay, faceid, 0);
++found;
//goto Done;
}
else{
i_it = i_it->next;
}
}
if(found) goto Done;
DEBUGMSG(99, "no running computation found \n");
}
#endif
if (!ccnl_content_serve_pending(relay, c)) { // unsolicited content
// CONFORM: "A node MUST NOT forward unsolicited data [...]"
DEBUGMSG(7, " removed because no matching interest\n");
Expand Down
29 changes: 18 additions & 11 deletions krivine-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ mkInterestObject(struct ccnl_relay_s *ccnl, struct configuration_s *config,
struct ccnl_buf_s *buf = 0, *nonce=0, *ppkd=0;
struct ccnl_prefix_s *p = 0;
unsigned char *out = malloc(CCNL_MAX_PACKET_SIZE);
unsigned char *cp, *content;
unsigned char *content;


struct ccnl_face_s * from = ccnl_malloc(sizeof(struct ccnl_face_s *));
Expand Down Expand Up @@ -325,9 +325,10 @@ mkInterestObject(struct ccnl_relay_s *ccnl, struct configuration_s *config,
len = ccnl_ndntlv_mkInterest(namecomps, -1, &tmplen, out);
memmove(out, out + tmplen, CCNL_MAX_PACKET_SIZE - tmplen);
len = CCNL_MAX_PACKET_SIZE - tmplen;

*cp = out;
if(ccnl_ndntlv_dehead(&out, &len, &typ, &num))
unsigned char *cp = out;
if(ccnl_ndntlv_dehead(&out, &len, &typ, &num)){
return 0;
}
buf = ccnl_ndntlv_extract(out - cp, &out, &len, &scope, &mbf, &minsfx, &maxsfx,
&p, &nonce, &ppkd, &content, &contlen);
return ccnl_interest_new(ccnl, from, CCNL_SUITE_NDNTLV, &buf, &p, minsfx, maxsfx);
Expand Down Expand Up @@ -366,15 +367,13 @@ struct ccnl_content_s *
create_content_object(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *prefix,
unsigned char *contentstr, int contentlen, int suite){
DEBUGMSG(49, "create_content_object()\n");
DEBUGMSG(49, "create_content_object()\n");
int i = 0;
int scope=3, aok=3, minsfx=0, maxsfx=CCNL_MAX_NAME_COMP, contlen, len, mbf = 0;
struct ccnl_buf_s *buf = 0, *nonce=0, *ppkd=0;
struct ccnl_content_s *c = 0;
struct ccnl_prefix_s *p = 0;
unsigned char *content = malloc(CCNL_MAX_PACKET_SIZE);
int num; int typ;
unsigned char *out = ccnl_malloc(CCNL_MAX_PACKET_SIZE), *cp;
unsigned char *out = malloc(CCNL_MAX_PACKET_SIZE);
memset(out, 0, CCNL_MAX_PACKET_SIZE);

char **prefixcomps = ccnl_malloc(sizeof(char *) * prefix->compcnt+1);
Expand All @@ -390,7 +389,9 @@ create_content_object(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *prefix,

if(suite == CCNL_SUITE_CCNB){
len = mkContent(prefixcomps, contentstr, contentlen, out);
dehead(&out, &len, &num, &typ);
if(dehead(&out, &len, &num, &typ)){
return NULL;
}
buf = ccnl_ccnb_extract(&out, &len, &scope, &aok, &minsfx, &maxsfx,
&p, &nonce, &ppkd, &content, &contlen);
return ccnl_content_new(ccnl, CCNL_SUITE_CCNB, &buf, &p, &ppkd, content, contlen);
Expand All @@ -400,9 +401,15 @@ create_content_object(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *prefix,
return 0;
}
else if(suite == CCNL_SUITE_NDNTLV){
len = ccnl_ndntlv_mkContent(prefixcomps, content, contentlen, out, CCNL_MAX_PACKET_SIZE);
*cp = out;
if(ccnl_ndntlv_dehead(&out, &len, &typ, &num))
int len2 = CCNL_MAX_PACKET_SIZE;
len = ccnl_ndntlv_mkContent(prefixcomps, contentstr, contentlen, &len2, out);
memmove(out, out+len2, CCNL_MAX_PACKET_SIZE - len2);
len = CCNL_MAX_PACKET_SIZE - len2;

unsigned char *cp = out;
if(ccnl_ndntlv_dehead(&out, &len, &typ, &num)){
return NULL;
}
buf = ccnl_ndntlv_extract(out - cp, &out, &len, &scope, &mbf, &minsfx, &maxsfx,
&p, &nonce, &ppkd, &content, &contlen);
return ccnl_content_new(ccnl, CCNL_SUITE_NDNTLV, &buf, &p, &ppkd, content, contlen);
Expand Down
22 changes: 11 additions & 11 deletions util/ccn-lite-peek.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,33 @@ main(int argc, char *argv[])
goto Usage;
cp = strtok(argv[optind], "|");
while (i < (CCNL_MAX_NAME_COMP - 1) && cp) {
prefix[i++] = cp;
cp = strtok(NULL, "/");
prefix[i++] = cp;
cp = strtok(NULL, "|");
}
prefix[i] = NULL;
if(!strncmp(packettype, "CCNB", 4)){
len = mkInterest(prefix, NULL, out);
}
else if(!strncmp(packettype, "NDNTLV", 6)){
int tmplen = sizeof(out);
int tmplen = CCNL_MAX_PACKET_SIZE;
len = ccnl_ndntlv_mkInterest(prefix, -1, &tmplen, out);
memmove(out, out + tmplen, CCNL_MAX_PACKET_SIZE - tmplen);
len = CCNL_MAX_PACKET_SIZE - tmplen;
}

if (ux) { // use UNIX socket
dest = ux;
sock = ux_open();
sendproc = ux_sendto;
dest = ux;
sock = ux_open();
sendproc = ux_sendto;
} else { // UDP
dest = udp;
sock = udp_open();
sendproc = udp_sendto;
dest = udp;
sock = udp_open();
sendproc = udp_sendto;
}

for (i = 0; i < 3; i++) {
request_content(sock, sendproc, dest, out, len, wait);
// fprintf(stderr, "retry\n");
request_content(sock, sendproc, dest, out, len, wait);
// fprintf(stderr, "retry\n");
}
close(sock);

Expand Down

0 comments on commit 0698053

Please sign in to comment.