diff --git a/sys/net/ccn_lite/Makefile b/sys/net/ccn_lite/Makefile index a4516ae266..6275081efc 100644 --- a/sys/net/ccn_lite/Makefile +++ b/sys/net/ccn_lite/Makefile @@ -1,4 +1,4 @@ MODULE := ccn_lite -INCLUDES = -I$(RIOTBASE) -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/net -I$(RIOTBASE)/cpu/arm_common/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/net/ccn_lite/include/ +INCLUDES = -I$(RIOTBASE) -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/net -I$(RIOTBASE)/cpu/arm_common/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/net/include/ include $(RIOTBASE)/Makefile.base diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index 5bdb42481b..14df95563b 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -23,13 +23,6 @@ #include -#define CCNL_RIOT - -#define USE_CCNxDIGEST -#define USE_RIOT_MSG -#define USE_RIOT_TRANS -#define USE_APPSERVER -#define USE_MGMT #define RIOT_CCNL_POPULATE (1) #include "ccnl-includes.h" @@ -48,9 +41,10 @@ #include "msg.h" #include "thread.h" #include "transceiver.h" +#include "hwtimer.h" #include "ccnl-riot-compat.h" -#include "test_data/text.txt.ccnb.h" +#include "ccn_lite/test_data/text.txt.ccnb.h" /** The size of the message queue between router daemon and transceiver AND clients */ #define RELAY_MSG_BUFFER_SIZE (64) @@ -68,21 +62,21 @@ ccnl_run_events(void) static struct timeval now; long usec; - rtc_time(&now); - DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec); + ccnl_get_timeval(&now); + //DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec); while (eventqueue) { struct ccnl_timer_s *t = eventqueue; usec = timevaldelta(&(t->timeout), &now); if (usec >= 0) { - DEBUGMSG(1, "ccnl_run_events nothing to do: %ld:%ld\n", now.tv_sec, now.tv_usec); + //DEBUGMSG(1, "ccnl_run_events nothing to do: %ld:%ld\n", now.tv_sec, now.tv_usec); now.tv_sec = usec / 1000000; now.tv_usec = usec % 1000000; return &now; } - DEBUGMSG(1, "ccnl_run_events run event handler: %ld:%ld\n", now.tv_sec, now.tv_usec); + //DEBUGMSG(1, "ccnl_run_events run event handler: %ld:%ld\n", now.tv_sec, now.tv_usec); if (t->fct) { (t->fct)(t->node, t->intarg); } @@ -133,18 +127,26 @@ void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, void ccnl_ageing(void *relay, void *aux) { ccnl_do_ageing(relay, aux); - ccnl_set_timer(1000000, ccnl_ageing, relay, 0); + ccnl_set_timer(CCNL_CHECK_TIMEOUT_SEC * (1000*1000) + CCNL_CHECK_TIMEOUT_USEC, ccnl_ageing, relay, 0); +} + +void ccnl_retransmit(void *relay, void *aux) +{ + ccnl_do_retransmit(relay, aux); + ccnl_set_timer(CCNL_CHECK_RETRANSMIT_SEC * (1000*1000) + CCNL_CHECK_RETRANSMIT_USEC, ccnl_retransmit, relay, 0); } // ---------------------------------------------------------------------- -void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries) +void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate) { struct ccnl_if_s *i; DEBUGMSG(99, "ccnl_relay_config\n"); relay->max_cache_entries = max_cache_entries; + relay->fib_threshold_prefix = fib_threshold_prefix; + relay->fib_threshold_aggregate = fib_threshold_aggregate; if (RIOT_MSG_IDX != relay->ifcount) { DEBUGMSG(1, "sorry, idx did not match: riot msg device\n"); @@ -196,7 +198,13 @@ void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries) DEBUGMSG(1, "sorry, could not open riot trans device\n"); } - ccnl_set_timer(1000000, ccnl_ageing, relay, 0); + /* create default boardcast face on transceiver interface */ + struct ccnl_face_s * f = ccnl_get_face_or_create(relay, RIOT_TRANS_IDX, RIOT_BROADCAST); + f->flags |= CCNL_FACE_FLAGS_STATIC; + i->broadcast_face = f; + + ccnl_set_timer(CCNL_CHECK_TIMEOUT_USEC, ccnl_ageing, relay, 0); + ccnl_set_timer(CCNL_CHECK_RETRANSMIT_USEC, ccnl_retransmit, relay, 0); } #if RIOT_CCNL_POPULATE @@ -282,6 +290,15 @@ void handle_populate_cache(void) // ---------------------------------------------------------------------- +void ccnl_timeout_callback(void *ptr) +{ + struct ccnl_relay_s *ccnl = ptr; + + msg_t ccnl_timeout_msg; + ccnl_timeout_msg.type = CCNL_RIOT_TIMEOUT; + msg_send(&ccnl_timeout_msg, ccnl->riot_pid, false); +} + int ccnl_io_loop(struct ccnl_relay_s *ccnl) { int i, maxfd = -1; @@ -308,16 +325,24 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) msg_t in; radio_packet_t *p; riot_ccnl_msg_t *m; + struct timeval *timeout; + unsigned long us = CCNL_CHECK_RETRANSMIT_USEC; + int hwtimer_id; while (!ccnl->halt_flag) { - DEBUGMSG(1, "waiting for incomming msg\n"); + hwtimer_id = hwtimer_set(HWTIMER_TICKS(us), ccnl_timeout_callback, ccnl); + if (hwtimer_id == -1) { + puts("NO MORE TIMERS!"); + } else { + //DEBUGMSG(1, "hwtimer_id is %d\n", hwtimer_id); + } msg_receive(&in); - struct timeval *timeout = ccnl_run_events(); + //DEBUGMSG(1, "%s Packet waiting, us was %lu\n", riot_ccnl_event_to_string(in.type), us); switch (in.type) { case PKT_PENDING: + hwtimer_remove(hwtimer_id); p = (radio_packet_t *) in.content.ptr; - DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); DEBUGMSG(1, "\tLength:\t%u\n", p->length); DEBUGMSG(1, "\tSrc:\t%u\n", p->src); DEBUGMSG(1, "\tDst:\t%u\n", p->dst); @@ -332,8 +357,8 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) break; case (CCNL_RIOT_MSG): + hwtimer_remove(hwtimer_id); m = (riot_ccnl_msg_t *) in.content.ptr; - DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); DEBUGMSG(1, "\tLength:\t%u\n", m->size); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); @@ -342,22 +367,34 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) break; case (CCNL_RIOT_HALT): - DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); + hwtimer_remove(hwtimer_id); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value); ccnl->halt_flag = 1; break; + #if RIOT_CCNL_POPULATE case (CCNL_RIOT_POPULATE): - DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); + hwtimer_remove(hwtimer_id); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value); handle_populate_cache(); break; #endif + case (CCNL_RIOT_PRINT_STAT): + hwtimer_remove(hwtimer_id); + for (struct ccnl_face_s *f = ccnl->faces; f; f = f->next) { + ccnl_face_print_stat(f); + } + break; + case (CCNL_RIOT_TIMEOUT): + timeout = ccnl_run_events(); + us = timeout->tv_sec * 1000 * 1000 + timeout->tv_usec; + break; default: + hwtimer_remove(hwtimer_id); DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); DEBUGMSG(1, "\tdropping it...\n"); @@ -373,17 +410,18 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) * @param pointer to count transceiver pids * */ -void ccnl_riot_relay_start(int max_cache_entries) +void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate) { - struct timeval now; - theRelay.startup_time = rtc_time(&now); + ccnl_get_timeval(&theRelay.startup_time); + theRelay.riot_pid = thread_pid; - DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", now.tv_sec, now.tv_usec); + DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay.startup_time.tv_sec, theRelay.startup_time.tv_usec); DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__); DEBUGMSG(1, " max_cache_entries: %d\n", max_cache_entries); - DEBUGMSG(1, " compile options: %s\n", compile_string()); + DEBUGMSG(1, " threshold_prefix: %d\n", fib_threshold_prefix); + DEBUGMSG(1, " threshold_aggregate: %d\n", fib_threshold_aggregate); - ccnl_relay_config(&theRelay, max_cache_entries); + ccnl_relay_config(&theRelay, max_cache_entries, fib_threshold_prefix, fib_threshold_aggregate); ccnl_io_loop(&theRelay); DEBUGMSG(1, "ioloop stopped\n"); diff --git a/sys/net/ccn_lite/ccnl-core.c b/sys/net/ccn_lite/ccnl-core.c index 74886217cb..5ca3920c6d 100644 --- a/sys/net/ccn_lite/ccnl-core.c +++ b/sys/net/ccn_lite/ccnl-core.c @@ -37,7 +37,7 @@ #include "ccnl-riot-compat.h" -#define USE_RIOT_MSG +#define CCNL_DYNAMIC_FIB (0) static struct ccnl_interest_s *ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i); @@ -77,6 +77,12 @@ void free_content(struct ccnl_content_s *c) free_2ptr_list(c->pkt, c); } +void free_forward(struct ccnl_forward_s *fwd) +{ + free_prefix(fwd->prefix); + ccnl_free(fwd); +} + // ---------------------------------------------------------------------- // datastructure support functions @@ -376,43 +382,28 @@ int ccnl_addr_cmp(sockunion *s1, sockunion *s2) struct ccnl_face_s * ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id) { - DEBUGMSG(1, "ifndx=%d sender_id=%d\n", ifndx, sender_id); - - static int i; - struct ccnl_face_s *f; for (f = ccnl->faces; f; f = f->next) { - DEBUGMSG(1, "f=%p\n", (void *) f); - if (ifndx == f->ifndx && (f->faceid == sender_id)) { DEBUGMSG(1, "face found! ifidx=%d sender_id=%d faceid=%d\n", ifndx, sender_id, f->faceid); - f->last_used = CCNL_NOW(); + ccnl_get_timeval(&f->last_used); return f; } } - if (ifndx == -1) { - for (i = 0; i < ccnl->ifcount; i++) { - ifndx = i; - break; - } - - if (ifndx == -1) { // no suitable interface found - return NULL; - } - } - f = (struct ccnl_face_s *) ccnl_calloc(1, sizeof(struct ccnl_face_s)); - if (!f) { return NULL; } - f->faceid = sender_id; // ++seqno; - DEBUGMSG(1, "faceid=%d\n", f->faceid); + f->faceid = sender_id; f->ifndx = ifndx; + if (sender_id == RIOT_BROADCAST) { + f->flags |= CCNL_FACE_FLAGS_BROADCAST; + } + if (ifndx >= 0) { if (ccnl->defaultFaceScheduler) f->sched = ccnl->defaultFaceScheduler(ccnl, @@ -449,7 +440,7 @@ ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id #endif - f->last_used = CCNL_NOW(); + ccnl_get_timeval(&f->last_used); DBL_LINKED_LIST_ADD(ccnl->faces, f); return f; @@ -495,9 +486,9 @@ ccnl_face_remove(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) for (ppfwd = &ccnl->fib; *ppfwd;) { if ((*ppfwd)->face == f) { struct ccnl_forward_s *pfwd = *ppfwd; - free_prefix(pfwd->prefix); *ppfwd = pfwd->next; - ccnl_free(pfwd); + + ccnl_forward_remove(ccnl, pfwd); } else { ppfwd = &(*ppfwd)->next; @@ -510,12 +501,30 @@ ccnl_face_remove(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) f->outq = tmp; } + ccnl_face_print_stat(f); + f2 = f->next; DBL_LINKED_LIST_REMOVE(ccnl->faces, f); ccnl_free(f); return f2; } +void ccnl_face_print_stat(struct ccnl_face_s *f) +{ + DEBUGMSG(1, "ccnl_face_print_stat: faceid=%d ifndx=%d\n", f->faceid, f->ifndx); + DEBUGMSG(1, " STAT interest send=%d:%d:%d:%d:%d\n", f->stat.send_interest[0], + f->stat.send_interest[1], f->stat.send_interest[2], + f->stat.send_interest[3], f->stat.send_interest[4]); + + DEBUGMSG(1, " STAT content send=%d:%d:%d:%d:%d\n", f->stat.send_content[0], + f->stat.send_content[1], f->stat.send_content[2], + f->stat.send_content[3], f->stat.send_content[4]); + + DEBUGMSG(1, " STAT interest received=%d\n", f->stat.received_interest); + + DEBUGMSG(1, " STAT content received=%d\n", f->stat.received_content); +} + void ccnl_interface_cleanup(struct ccnl_if_s *i) { int j; @@ -728,7 +737,7 @@ ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from, *ppkd = 0; i->minsuffix = minsuffix; i->maxsuffix = maxsuffix; - i->last_used = CCNL_NOW(); + ccnl_get_timeval(&i->last_used); DBL_LINKED_LIST_ADD(ccnl->pit, i); return i; } @@ -742,7 +751,7 @@ int ccnl_interest_append_pending(struct ccnl_interest_s *i, for (pi = i->pending; pi; pi = pi->next) { // check whether already listed if (pi->face == from) { DEBUGMSG(40, " we found a matching interest, updating time\n"); - pi->last_used = CCNL_NOW(); + ccnl_get_timeval(&pi->last_used); return 0; } @@ -758,7 +767,7 @@ int ccnl_interest_append_pending(struct ccnl_interest_s *i, } pi->face = from; - pi->last_used = CCNL_NOW(); + ccnl_get_timeval(&pi->last_used); if (last) { last->next = pi; @@ -776,13 +785,10 @@ void ccnl_interest_propagate(struct ccnl_relay_s *ccnl, struct ccnl_forward_s *fwd; DEBUGMSG(99, "ccnl_interest_propagate\n"); - ccnl_print_stats(ccnl, STAT_SND_I); // log_send_i - - int hits = 0; - // 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 + int forward_cnt = 0; for (fwd = ccnl->fib; fwd; fwd = fwd->next) { int rc = ccnl_prefix_cmp(fwd->prefix, NULL, i->prefix, CMP_LONGEST); DEBUGMSG(40, " ccnl_interest_propagate, rc=%d/%d\n", rc, @@ -797,15 +803,21 @@ void ccnl_interest_propagate(struct ccnl_relay_s *ccnl, // suppress forwarding to origin of interest, except wireless if (!i->from || fwd->face != i->from || (i->from->flags & CCNL_FACE_FLAGS_REFLECT)) { + + i->forwarded_over = fwd; + fwd->face->stat.send_interest[i->retries]++; + ccnl_get_timeval(&i->last_used); ccnl_face_enqueue(ccnl, fwd->face, buf_dup(i->pkt)); - hits++; + ccnl_get_timeval(&fwd->last_used); + forward_cnt++; } } - if (hits == 0) { - DEBUGMSG(1, "no hits in the fib...find riot transceiver face\n"); - struct ccnl_face_s *face = ccnl_get_face_or_create(ccnl, RIOT_TRANS_IDX, 0 /* broadcast */); - ccnl_face_enqueue(ccnl, face, buf_dup(i->pkt)); + if (forward_cnt == 0) { + DEBUGMSG(40, " ccnl_interest_propagate: using broadcast face!\n"); + ccnl->ifs[RIOT_TRANS_IDX].broadcast_face->stat.send_interest[i->retries]++; + ccnl_get_timeval(&i->last_used); + ccnl_face_enqueue(ccnl, ccnl->ifs[RIOT_TRANS_IDX].broadcast_face, buf_dup(i->pkt)); } return; @@ -880,7 +892,7 @@ ccnl_content_new(struct ccnl_relay_s *ccnl, struct ccnl_buf_s **pkt, return NULL; } - c->last_used = CCNL_NOW(); + ccnl_get_timeval(&c->last_used); c->content = content; c->contentlen = contlen; c->pkt = *pkt; @@ -923,18 +935,17 @@ ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c) while (ccnl->max_cache_entries <= ccnl->contentcnt) { DEBUGMSG(1, " remove oldest content...\n"); struct ccnl_content_s *c2, *oldest = NULL; - int age = 0; for (c2 = ccnl->contents; c2; c2 = c2->next) { + DEBUGMSG(1, " '%s' -> %ld:%ld\n", ccnl_prefix_to_path(c2->name), c2->last_used.tv_sec, c2->last_used.tv_usec); if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) - && ((age == 0) || c2->last_used < age)) { - age = c2->last_used; + && ((!oldest) || timevaldelta(&c2->last_used, &oldest->last_used) < 0)) { oldest = c2; } } if (oldest) { - DEBUGMSG(1, " replaced: '%s'\n",ccnl_prefix_to_path(oldest->name)); + DEBUGMSG(1, " replaced: '%s'\n", ccnl_prefix_to_path(oldest->name)); ccnl_content_remove(ccnl, oldest); } else { DEBUGMSG(1, " no dynamic content to remove...\n"); @@ -984,16 +995,12 @@ int ccnl_content_serve_pending(struct ccnl_relay_s *ccnl, if (pi->face->ifndx >= 0) { DEBUGMSG(6, " forwarding content <%s>\n", ccnl_prefix_to_path(c->name)); - ccnl_print_stats(ccnl, STAT_SND_C); //log sent c + pi->face->stat.send_content[c->served_cnt % CCNL_MAX_CONTENT_SERVED_STAT]++; ccnl_face_enqueue(ccnl, pi->face, buf_dup(c->pkt)); } - else - // upcall to deliver content to local client - { - ccnl_app_RX(ccnl, c); - } c->served_cnt++; + ccnl_get_timeval(&c->last_used); cnt++; } @@ -1003,20 +1010,164 @@ int ccnl_content_serve_pending(struct ccnl_relay_s *ccnl, return cnt; } +/** + * returns an entry from the fib which has a common prefix with p. + * only returns that entry if it fullfils the aggregate threshold! + */ +struct ccnl_forward_s *ccn_forward_find_common_prefix_to_aggregate(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *p, int *match_len) +{ + if (!ccnl->fib) { + DEBUGMSG(999, "ccn_forward_find_common_prefix: fib was empty\n"); + return NULL; + } + + /* fib as at least one enty */ + struct ccnl_forward_s *fwd2 = ccnl->fib; + while (fwd2) { + DEBUGMSG(1, "ccn_forward_find_common_prefix: '%s' vs. '%s'\n", ccnl_prefix_to_path(p), ccnl_prefix_to_path(fwd2->prefix)); + *match_len = ccnl_prefix_cmp(fwd2->prefix, 0, p, CMP_LONGEST); + + /* check for threshold and never date up a static enty */ + if ((ccnl->fib_threshold_aggregate <= *match_len) && !(fwd2->flags & CCNL_FORWARD_FLAGS_STATIC)) { + return fwd2; + } + + fwd2 = fwd2->next; + } + + return NULL; +} + +static struct ccnl_forward_s *ccnl_forward_new(struct ccnl_prefix_s *p, struct ccnl_face_s *f, int threshold_prefix, int flags) +{ + struct ccnl_forward_s *fwd = ccnl_calloc(1, sizeof(struct ccnl_forward_s)); + fwd->prefix = ccnl_prefix_clone_strip(p, threshold_prefix); + fwd->face = f; + fwd->flags = flags; + return fwd; +} + +void ccnl_content_learn_name_route(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *p, struct ccnl_face_s *f, int threshold_prefix, int flags) +{ + /* + * we want to insert a new dynamic route in the fib, let's try to aggregate! + * for aggregation we ask the fib for a prefix match + */ + int match_len; + struct ccnl_forward_s *fwd = ccn_forward_find_common_prefix_to_aggregate(ccnl, p, &match_len); + if (!fwd) { + /* there was no prefix match with the user defined creteria. */ + + /* create a new fib entry */ + fwd = ccnl_forward_new(p, f, threshold_prefix, flags); + DBL_LINKED_LIST_ADD(ccnl->fib, fwd); + DEBUGMSG(999, "ccnl_content_learn_name_route: new route '%s' on face %d learned\n", ccnl_prefix_to_path(fwd->prefix), f->faceid); + } else { + /* there was a prefix match with the user defined creteria. */ + + /* if the new entry has shorter prefix */ + if (p->compcnt < fwd->prefix->compcnt) { + /* we need to aggregate! */ + DBL_LINKED_LIST_REMOVE(ccnl->fib, fwd); + + /* create a new fib entry */ + fwd = ccnl_forward_new(p, f, (p->compcnt - match_len), flags); + DBL_LINKED_LIST_ADD(ccnl->fib, fwd); + DEBUGMSG(999, "ccnl_content_learn_name_route: route '%s' on face %d replaced\n", ccnl_prefix_to_path(fwd->prefix), f->faceid); + } else { + /* we don't need to do an update, because we know a shorter prefix already */ + } + } + + /* refresh fwd entry */ + DEBUGMSG(999, "ccnl_content_learn_name_route refresh route '%s' on face %d\n", ccnl_prefix_to_path(fwd->prefix), f->faceid); + ccnl_get_timeval(&fwd->last_used); +} + +struct ccnl_forward_s * +ccnl_forward_remove(struct ccnl_relay_s *ccnl, struct ccnl_forward_s *fwd) +{ + struct ccnl_forward_s *fwd2; + DEBUGMSG(40, "ccnl_forward_remove %p\n", (void *) fwd); + + fwd2 = fwd->next; + DBL_LINKED_LIST_REMOVE(ccnl->fib, fwd); + + for (struct ccnl_interest_s *p = ccnl->pit; p; p = p->next) { + if (p->forwarded_over == fwd) { + p->forwarded_over = NULL; + } + } + DEBUGMSG(40, " ccnl_forward_remove next=%p\n", (void *) fwd2); + + free_forward(fwd); + return fwd2; +} + +bool ccnl_is_timeouted(struct timeval *now, struct timeval *last_used, time_t timeout_s, time_t timeout_us) +{ + struct timeval abs_timeout = { last_used->tv_sec + timeout_s, last_used->tv_usec + timeout_us }; + return timevaldelta(now, &abs_timeout) > 0; +} + +void ccnl_do_retransmit(void *ptr, void *dummy) +{ + (void) dummy; /* unused */ + + struct ccnl_relay_s *relay = (struct ccnl_relay_s *) ptr; + + for (struct ccnl_interest_s *i = relay->pit; i; i = i->next) { + // CONFORM: "Entries in the PIT MUST timeout rather + // than being held indefinitely." + if(i->retries <= CCNL_MAX_INTEREST_RETRANSMIT) { + // CONFORM: "A node MUST retransmit Interest Messages + // periodically for pending PIT entries." + DEBUGMSG(7, " retransmit %d <%s>\n", i->retries, + ccnl_prefix_to_path(i->prefix)); + + if (i->forwarded_over + && !(i->forwarded_over->flags & CCNL_FORWARD_FLAGS_STATIC) + && (i->retries >= CCNL_MAX_INTEREST_OPTIMISTIC)) { + DEBUGMSG(1, " removed dynamic forward %p\n", (void *) i->forwarded_over); + ccnl_forward_remove(relay, i->forwarded_over); + } + + i->retries++; + ccnl_interest_propagate(relay, i); + } + } +} + void ccnl_do_ageing(void *ptr, void *dummy) { (void) dummy; /* unused */ struct ccnl_relay_s *relay = (struct ccnl_relay_s *) ptr; - struct ccnl_content_s *c = relay->contents; struct ccnl_interest_s *i = relay->pit; + struct ccnl_content_s *c = relay->contents; + struct ccnl_face_s *f = relay->faces; - time_t t = CCNL_NOW(); - DEBUGMSG(999, "ccnl_do_ageing %d\n", (int) t); + struct timeval now; + ccnl_get_timeval(&now); + //DEBUGMSG(999, "ccnl_do_ageing %ld:%ld\n", now.tv_sec, now.tv_usec); + + while (i) { + if (ccnl_is_timeouted(&now, &i->last_used, CCNL_INTEREST_TIMEOUT_SEC, + CCNL_INTEREST_TIMEOUT_USEC)) { + if (i->from->ifndx == RIOT_MSG_IDX) { + /* this interest was requested by an app from this node */ + /* inform this app about this problem */ + riot_send_nack(i->from->faceid); + } + i = ccnl_interest_remove(relay, i); + } else { + i = i->next; + } + } while (c) { - if ((c->last_used + CCNL_CONTENT_TIMEOUT) <= t + if (ccnl_is_timeouted(&now, &c->last_used, CCNL_CONTENT_TIMEOUT_SEC, CCNL_CONTENT_TIMEOUT_USEC) && !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) { c = ccnl_content_remove(relay, c); } @@ -1025,32 +1176,25 @@ void ccnl_do_ageing(void *ptr, void *dummy) } } - while (i) { // CONFORM: "Entries in the PIT MUST timeout rather - // than being held indefinitely." - if ((i->last_used + CCNL_INTEREST_TIMEOUT) <= t || - i->retries > CCNL_MAX_INTEREST_RETRANSMIT) { - i = ccnl_interest_remove(relay, i); - } - else { - // CONFORM: "A node MUST retransmit Interest Messages - // periodically for pending PIT entries." - DEBUGMSG(7, " retransmit %d <%s>\n", i->retries, - ccnl_prefix_to_path(i->prefix)); - ccnl_interest_propagate(relay, i); - i->retries++; - i = i->next; - } - } - while (f) { if (!(f->flags & CCNL_FACE_FLAGS_STATIC) - && (f->last_used + CCNL_FACE_TIMEOUT) <= t) { + && ccnl_is_timeouted(&now, &f->last_used, CCNL_FACE_TIMEOUT_SEC, CCNL_FACE_TIMEOUT_USEC)) { f = ccnl_face_remove(relay, f); } else { f = f->next; } } + + struct ccnl_forward_s *fwd = relay->fib; + while (fwd) { + if (!(fwd->flags & CCNL_FORWARD_FLAGS_STATIC) + && ccnl_is_timeouted(&now, &fwd->last_used, CCNL_FWD_TIMEOUT_SEC, CCNL_FWD_TIMEOUT_USEC)) { + fwd = ccnl_forward_remove(relay, fwd); + } else { + fwd = fwd->next; + } + } } void ccnl_core_cleanup(struct ccnl_relay_s *ccnl) @@ -1111,7 +1255,7 @@ int ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from, if (buf->data[0] == 0x01 && buf->data[1] == 0xd2) { // interest DEBUGMSG(1, "ccnl_core_RX_i_or_c: interest=<%s>\n", ccnl_prefix_to_path(p)); - ccnl_print_stats(relay, STAT_RCV_I); //log count recv_interest + from->stat.received_interest++; if (p->compcnt > 0 && p->comp[0][0] == (unsigned char) 0xc1) { goto Skip; @@ -1134,14 +1278,12 @@ int ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from, // FIXME: should check stale bit in aok here DEBUGMSG(7, " matching content for interest, content %p\n", (void *) c); - ccnl_print_stats(relay, STAT_SND_C); //log sent_c + from->stat.send_content[c->served_cnt % CCNL_MAX_CONTENT_SERVED_STAT]++; + c->served_cnt++; if (from->ifndx >= 0) { ccnl_face_enqueue(relay, from, buf_dup(c->pkt)); } - else { - ccnl_app_RX(relay, c); - } goto Skip; } @@ -1180,7 +1322,7 @@ int ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from, } else { // content DEBUGMSG(6, " content=<%s>\n", ccnl_prefix_to_path(p)); - ccnl_print_stats(relay, STAT_RCV_C); //log count recv_content + from->stat.received_content++; // CONFORM: Step 1: for (c = relay->contents; c; c = c->next) @@ -1196,6 +1338,11 @@ int ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from, DEBUGMSG(7, " removed because no matching interest\n"); free_content(c); goto Skip; + } else { +#if CCNL_DYNAMIC_FIB + /* content has matched an interest, we considder this name as availeble on this face */ + ccnl_content_learn_name_route(relay, c->name, from, relay->fib_threshold_prefix, 0); +#endif } if (relay->max_cache_entries != 0) { // it's set to -1 or a limit @@ -1274,45 +1421,4 @@ ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data, ccnl_core_RX_datagram(relay, from, &data, &datalen); } -const char * -compile_string(void) -{ - static const char *cp = "" -#ifdef USE_CCNxDIGEST - "USE_CCNxDIGEST " -#endif -#ifdef USE_DEBUG - "USE_DEBUG " -#endif -#ifdef USE_DEBUG_MALLOC - "USE_DEBUG_MALLOC " -#endif -#ifdef USE_FRAG - "USE_FRAG " -#endif -#ifdef USE_ETHERNET - "USE_ETHERNET " -#endif -#ifdef USE_UDP - "USE_UDP " -#endif -#ifdef USE_HTTP_STATUS - "USE_HTTP_STATUS " -#endif -#ifdef USE_MGMT - "USE_MGMT " -#endif -#ifdef USE_SCHEDULER - "USE_SCHEDULER " -#endif -#ifdef USE_UNIXSOCKET - "USE_UNIXSOCKET " -#endif -#ifdef USE_APPSERVER - "USE_APPSERVER " -#endif - ; - return cp; -} - // eof diff --git a/sys/net/ccn_lite/ccnl-core.h b/sys/net/ccn_lite/ccnl-core.h index b69389d370..08d3b48a53 100644 --- a/sys/net/ccn_lite/ccnl-core.h +++ b/sys/net/ccn_lite/ccnl-core.h @@ -24,8 +24,6 @@ #ifndef CCNL_CORE_H__ #define CCNL_CORE_H__ -//#define CCNL_UNIX - #define EXACT_MATCH 1 #define PREFIX_MATCH 0 @@ -37,6 +35,7 @@ #define CCNL_FACE_FLAGS_REFLECT 2 #define CCNL_FACE_FLAGS_SERVED 4 #define CCNL_FACE_FLAGS_FWDALLI 8 // forward all interests, also known ones +#define CCNL_FACE_FLAGS_BROADCAST 16 #define CCNL_FRAG_NONE 0 #define CCNL_FRAG_SEQUENCED2012 1 @@ -45,10 +44,11 @@ #define CCNL_CONTENT_FLAGS_STATIC 0x01 #define CCNL_CONTENT_FLAGS_STALE 0x02 -enum {STAT_RCV_I, STAT_RCV_C, STAT_SND_I, STAT_SND_C, STAT_QLEN, STAT_EOP1}; +#define CCNL_FORWARD_FLAGS_STATIC 0x01 #include #include +#include #include "ccnl.h" @@ -77,10 +77,11 @@ struct ccnl_if_s { // interface for packet IO int qfront; // index of next packet to send struct ccnl_txrequest_s queue[CCNL_MAX_IF_QLEN]; struct ccnl_sched_s *sched; + struct ccnl_face_s *broadcast_face; }; struct ccnl_relay_s { - time_t startup_time; + struct timeval startup_time; int id; struct ccnl_face_s *faces; struct ccnl_forward_s *fib; @@ -99,6 +100,9 @@ struct ccnl_relay_s { struct ccnl_http_s *http; struct ccnl_stats_s *stats; void *aux; + int fib_threshold_prefix; /* how may name components should be considdered as dynamic */ + int fib_threshold_aggregate; + int riot_pid; }; struct ccnl_buf_s { @@ -114,6 +118,13 @@ struct ccnl_prefix_s { unsigned char *path; // memory for name component copies }; +struct ccnl_stat_s { + int send_interest[CCNL_MAX_INTEREST_RETRANSMIT]; + int send_content[CCNL_MAX_CONTENT_SERVED_STAT]; + int received_interest; + int received_content; +}; + struct ccnl_frag_s { int protocol; // (0=plain CCNx) int mtu; @@ -140,16 +151,20 @@ struct ccnl_face_s { int ifndx; sockunion peer; int flags; - int last_used; // updated when we receive a packet + struct timeval last_used; // updated when we receive a packet struct ccnl_buf_s *outq, *outqend; // queue of packets to send struct ccnl_frag_s *frag; // which special datagram armoring struct ccnl_sched_s *sched; + + struct ccnl_stat_s stat; }; struct ccnl_forward_s { - struct ccnl_forward_s *next; + struct ccnl_forward_s *next, *prev; struct ccnl_prefix_s *prefix; struct ccnl_face_s *face; + int flags; + struct timeval last_used; // updated when we use this fib entry }; struct ccnl_interest_s { @@ -160,14 +175,15 @@ struct ccnl_interest_s { int minsuffix, maxsuffix; struct ccnl_buf_s *ppkd; // publisher public key digest struct ccnl_buf_s *pkt; // full datagram - int last_used; + struct timeval last_used; int retries; + struct ccnl_forward_s *forwarded_over; }; struct ccnl_pendint_s { // pending interest struct ccnl_pendint_s *next; // , *prev; struct ccnl_face_s *face; - int last_used; + struct timeval last_used; }; struct ccnl_content_s { @@ -180,7 +196,7 @@ struct ccnl_content_s { int contentlen; // NON-CONFORM: "The [ContentSTore] MUST also implement the Staleness Bit." // >> CCNL: currently no stale bit, old content is fully removed << - int last_used; + struct timeval last_used; int served_cnt; }; @@ -223,6 +239,9 @@ ccnl_content_new(struct ccnl_relay_s *ccnl, struct ccnl_buf_s **pkt, struct ccnl_content_s * ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c); +void ccnl_content_learn_name_route(struct ccnl_relay_s *ccnl, struct ccnl_prefix_s *p, + struct ccnl_face_s *f, int threshold_prefix, int flags); + struct ccnl_face_s * ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id); @@ -232,18 +251,21 @@ int ccnl_face_enqueue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *to, struct ccnl_face_s * ccnl_face_remove(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f); +struct ccnl_forward_s * +ccnl_forward_remove(struct ccnl_relay_s *ccnl, struct ccnl_forward_s *fwd); + struct ccnl_buf_s * ccnl_extract_prefix_nonce_ppkd(unsigned char **data, int *datalen, int *scope, int *aok, int *min, int *max, struct ccnl_prefix_s **prefix, struct ccnl_buf_s **nonce, struct ccnl_buf_s **ppkd, unsigned char **content, int *contlen); +void ccnl_do_retransmit(void *ptr, void *dummy); void ccnl_do_ageing(void *ptr, void *dummy); void ccnl_interface_CTS(void *aux1, void *aux2); -#define ccnl_app_RX(x,y) do{}while(0) -#define ccnl_print_stats(x,y) do{}while(0) +void ccnl_face_print_stat(struct ccnl_face_s *f); #define ccnl_malloc(s) malloc(s) #define ccnl_calloc(n,s) calloc(n,s) diff --git a/sys/net/ccn_lite/ccnl-ext-appserver.c b/sys/net/ccn_lite/ccnl-ext-appserver.c index f39dba09ff..75f123cce8 100644 --- a/sys/net/ccn_lite/ccnl-ext-appserver.c +++ b/sys/net/ccn_lite/ccnl-ext-appserver.c @@ -22,8 +22,8 @@ #include "msg.h" #include "thread.h" -#include "util/ccnl-riot-client.h" -#include "ccnl-riot-compat.h" +#include "ccn_lite/util/ccnl-riot-client.h" +#include "ccn_lite/ccnl-riot-compat.h" #include "ccnl-includes.h" #include "ccnl-core.h" @@ -133,6 +133,8 @@ static void riot_ccnl_appserver_ioloop(void) DEBUGMSG(1, "new msg: size=%" PRIu16 " sender_pid=%" PRIu16 "\n", m->size, in.sender_pid); appserver_handle_interest(m->payload, m->size, in.sender_pid); + + ccnl_free(m); break; default: diff --git a/sys/net/ccn_lite/ccnl-ext-mgmt.c b/sys/net/ccn_lite/ccnl-ext-mgmt.c index 6610ae8689..ac088c295d 100644 --- a/sys/net/ccn_lite/ccnl-ext-mgmt.c +++ b/sys/net/ccn_lite/ccnl-ext-mgmt.c @@ -21,16 +21,6 @@ * 2012-05-06 created */ -#ifndef USE_MGMT -#define USE_MGMT 1 -#endif - -#ifndef CCNL_RIOT -#define CCNL_RIOT 1 -#endif - -#ifdef USE_MGMT - #include #include @@ -56,14 +46,13 @@ ccnl_addr2ascii(sockunion *su) // ---------------------------------------------------------------------- int -ccnl_is_local_addr(sockunion *su) +ccnl_is_local_addr(struct ccnl_face_s *f) { - (void) su ; /*unused */ - return 1; + return (f->ifndx == RIOT_MSG_IDX); } struct ccnl_prefix_s * -ccnl_prefix_clone(struct ccnl_prefix_s *p) +ccnl_prefix_clone_strip(struct ccnl_prefix_s *p, int strip) { int i, len; struct ccnl_prefix_s *p2; @@ -74,19 +63,22 @@ ccnl_prefix_clone(struct ccnl_prefix_s *p) return NULL; } - for (i = 0, len = 0; i < p->compcnt; len += p->complen[i++]); + int stripped_compcnt = p->compcnt; + stripped_compcnt -= (p->compcnt > strip) ? strip : 0; + + for (i = 0, len = 0; i < stripped_compcnt; len += p->complen[i++]); p2->path = (unsigned char *) ccnl_malloc(len); - p2->comp = (unsigned char **) ccnl_malloc(p->compcnt * sizeof(char *)); - p2->complen = (int *) ccnl_malloc(p->compcnt * sizeof(int)); + p2->comp = (unsigned char **) ccnl_malloc(stripped_compcnt * sizeof(char *)); + p2->complen = (int *) ccnl_malloc(stripped_compcnt * sizeof(int)); if (!p2->comp || !p2->complen || !p2->path) { goto Bail; } - p2->compcnt = p->compcnt; + p2->compcnt = stripped_compcnt; - for (i = 0, len = 0; i < p->compcnt; len += p2->complen[i++]) { + for (i = 0, len = 0; i < stripped_compcnt; len += p2->complen[i++]) { p2->complen[i] = p->complen[i]; p2->comp[i] = p2->path + len; memcpy(p2->comp[i], p->comp[i], p2->complen[i]); @@ -98,6 +90,11 @@ Bail: return NULL; } +struct ccnl_prefix_s * +ccnl_prefix_clone(struct ccnl_prefix_s *p) +{ + return ccnl_prefix_clone_strip(p, 0U); +} // ---------------------------------------------------------------------- // management protocols @@ -474,7 +471,6 @@ ccnl_mgmt_prefixreg(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, // should (re)verify that action=="prefixreg" if (faceid && p->compcnt > 0) { struct ccnl_face_s *f; - struct ccnl_forward_s *fwd, **fwd2; int fi = strtol((const char *)faceid, NULL, 0); DEBUGMSG(1, "mgmt: adding prefix %s to faceid='%s'='%d'\n", @@ -490,22 +486,8 @@ ccnl_mgmt_prefixreg(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, } DEBUGMSG(1, "Face %s found! ifndx=%d\n", faceid, f->ifndx); - fwd = (struct ccnl_forward_s *) ccnl_calloc(1, sizeof(*fwd)); - - if (!fwd) { - goto Bail; - } - - fwd->prefix = ccnl_prefix_clone(p); - fwd->face = f; - fwd2 = &ccnl->fib; - - while (*fwd2) { - fwd2 = &((*fwd2)->next); - } - - *fwd2 = fwd; + ccnl_content_learn_name_route(ccnl, p, f, 0, CCNL_FORWARD_FLAGS_STATIC); cp = "prefixreg cmd worked"; } else { @@ -595,11 +577,10 @@ int ccnl_mgmt(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, DEBUGMSG(99, "ccnl_mgmt request \"%s\"\n", cmd); - if (ccnl_is_local_addr(&from->peer)) + if (ccnl_is_local_addr(from)) goto MGMT; - DEBUGMSG(99, " rejecting because src=%s is not a local addr\n", - ccnl_addr2ascii(&from->peer)); + DEBUGMSG(99, " rejecting because src is not a local addr\n"); ccnl_mgmt_return_msg(ccnl, orig, from, "refused: origin of mgmt cmd is not local"); return -1; @@ -639,5 +620,4 @@ int ccnl_mgmt(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, } #endif -#endif // USE_MGMT // eof diff --git a/sys/net/ccn_lite/ccnl-ext.h b/sys/net/ccn_lite/ccnl-ext.h index 2639c849fb..c442f0574a 100644 --- a/sys/net/ccn_lite/ccnl-ext.h +++ b/sys/net/ccn_lite/ccnl-ext.h @@ -26,11 +26,7 @@ #ifndef CCNL_EXT_H__ #define CCNL_EXT_H__ -#ifdef USE_CCNxDIGEST -# define compute_ccnx_digest(buf) SHA256(buf->data, buf->datalen, NULL) -#else -# define compute_ccnx_digest(b) NULL -#endif +#define compute_ccnx_digest(buf) SHA256(buf->data, buf->datalen, NULL) #ifdef USE_FRAG @@ -84,6 +80,12 @@ int ccnl_is_fragment(unsigned char *data, int datalen); int ccnl_mgmt(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *buf, struct ccnl_prefix_s *prefix, struct ccnl_face_s *from); +struct ccnl_prefix_s * +ccnl_prefix_clone(struct ccnl_prefix_s *p); + +struct ccnl_prefix_s * +ccnl_prefix_clone_strip(struct ccnl_prefix_s *p, int strip); + // ---------------------------------------------------------------------- # define ccnl_sched_CTS_done(S,C,L) do{}while(0) diff --git a/sys/net/ccn_lite/ccnl-includes.h b/sys/net/ccn_lite/ccnl-includes.h index 5cd484c205..cfb311e39a 100644 --- a/sys/net/ccn_lite/ccnl-includes.h +++ b/sys/net/ccn_lite/ccnl-includes.h @@ -26,7 +26,6 @@ #include #include -#include "rtc.h" #include "sha256.h" #define RIOT_MSG_DEV (1) diff --git a/sys/net/ccn_lite/ccnl-pdu.c b/sys/net/ccn_lite/ccnl-pdu.c index 96997c3831..68d9f61ee8 100644 --- a/sys/net/ccn_lite/ccnl-pdu.c +++ b/sys/net/ccn_lite/ccnl-pdu.c @@ -22,9 +22,6 @@ * 2013-04-04 modified (ms): #if defined(CCNL_SIMULATION) || defined(CCNL_OMNET) */ -#ifndef CCNL_PDU -#define CCNL_PDU - #include #include "ccnl-core.h" @@ -235,5 +232,4 @@ mkContent(char **namecomp, char *data, int datalen, unsigned char *out) return len; } -#endif /*CCNL_PDU*/ // eof diff --git a/sys/net/ccn_lite/ccnl-pdu.h b/sys/net/ccn_lite/ccnl-pdu.h index c8e779b2de..f655feb075 100644 --- a/sys/net/ccn_lite/ccnl-pdu.h +++ b/sys/net/ccn_lite/ccnl-pdu.h @@ -16,8 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "ccnl-riot.h" - int dehead(unsigned char **buf, int *len, int *num, int *typ); int mkHeader(unsigned char *buf, unsigned int num, unsigned int tt); int mkBlob(unsigned char *out, unsigned int num, unsigned int tt, char *cp, int cnt); diff --git a/sys/net/ccn_lite/ccnl-platform.c b/sys/net/ccn_lite/ccnl-platform.c index 5b746cf33d..df362817e0 100644 --- a/sys/net/ccn_lite/ccnl-platform.c +++ b/sys/net/ccn_lite/ccnl-platform.c @@ -62,8 +62,7 @@ ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2), } t->fct2 = fct; - //gettimeofday(&t->timeout, NULL); - rtc_time(&t->timeout); + ccnl_get_timeval(&t->timeout); usec += t->timeout.tv_usec; t->timeout.tv_sec += usec / 1000000; t->timeout.tv_usec = usec % 1000000; @@ -133,30 +132,14 @@ ccnl_rem_timer(void *h) } } -double -current_time(void) -{ - struct timeval tv; - static time_t start; - static time_t start_usec; - - ccnl_get_timeval(&tv); - - if (!start) { - start = tv.tv_sec; - start_usec = tv.tv_usec; - } - - return (double)(tv.tv_sec) - start + - ((double)(tv.tv_usec) - start_usec) / 1000000; -} - char * timestamp(void) { static char ts[30], *cp; + struct timeval now; + ccnl_get_timeval(&now); - sprintf(ts, "%.4g", CCNL_NOW()); + sprintf(ts, "%.4lu", (time_t) 100000 * now.tv_sec + now.tv_usec); cp = strchr(ts, '.'); if (!cp) { diff --git a/sys/net/ccn_lite/ccnl-platform.h b/sys/net/ccn_lite/ccnl-platform.h index 8e73c4f6da..c074879de3 100644 --- a/sys/net/ccn_lite/ccnl-platform.h +++ b/sys/net/ccn_lite/ccnl-platform.h @@ -20,9 +20,6 @@ #include -double current_time(void); -#define CCNL_NOW() current_time() - // (ms) I moved the following struct def here because it is used by all // containers apart from the kernel (this way I don't need to redefine it // for omnet. @@ -39,6 +36,8 @@ struct ccnl_timer_s { int handler; }; +void ccnl_get_timeval(struct timeval *tv); + long timevaldelta(struct timeval *a, struct timeval *b); void *ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2), diff --git a/sys/net/ccn_lite/ccnl-riot-compat.c b/sys/net/ccn_lite/ccnl-riot-compat.c index d7e059066a..6cb52b55b4 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.c +++ b/sys/net/ccn_lite/ccnl-riot-compat.c @@ -82,6 +82,14 @@ int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to) return size; } +void riot_send_nack(uint16_t to) +{ + msg_t m; + m.type = CCNL_RIOT_NACK; + DEBUGMSG(1, "sending NACK msg to pid=%u\n", to); + msg_send(&m, to, 0); +} + char *riot_ccnl_event_to_string(ccnl_riot_event_t event) { switch (event) { @@ -97,6 +105,12 @@ char *riot_ccnl_event_to_string(ccnl_riot_event_t event) case CCNL_RIOT_POPULATE: return "RIOT_POPULATE"; + case CCNL_RIOT_TIMEOUT: + return "CCNL_RIOT_TIMEOUT"; + + case CCNL_RIOT_PRINT_STAT: + return "CCNL_RIOT_PRINT_STAT"; + default: return "UNKNOWN"; } diff --git a/sys/net/ccn_lite/ccnl-riot-compat.h b/sys/net/ccn_lite/ccnl-riot-compat.h index 614db99df7..ea5ed15e08 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.h +++ b/sys/net/ccn_lite/ccnl-riot-compat.h @@ -16,11 +16,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "ccnl-riot.h" +#include "ccn_lite/ccnl-riot.h" #define RIOT_CCN_EVENT_NUMBER_OFFSET (1 << 8) -#define RIOT_BROADCAST ((1 << sizeof(radio_address_t))-1) +#define RIOT_BROADCAST (UINT16_MAX) typedef struct riot_ccnl_msg { void *payload; @@ -29,4 +29,5 @@ typedef struct riot_ccnl_msg { int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to); int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to); +void riot_send_nack(uint16_t to); char *riot_ccnl_event_to_string(ccnl_riot_event_t event); diff --git a/sys/net/ccn_lite/ccnl.h b/sys/net/ccn_lite/ccnl.h index 5b775e740b..0be109ddfb 100644 --- a/sys/net/ccn_lite/ccnl.h +++ b/sys/net/ccn_lite/ccnl.h @@ -21,21 +21,35 @@ * 2011-03-30 created */ -#define CCNL_MAX_INTERFACES 10 -#define CCNL_MAX_PACKET_SIZE NATIVE_MAX_DATA_LENGTH +#define CCNL_MAX_INTERFACES 2 /* transceiver and msg interfaces */ -#define CCNL_CONTENT_TIMEOUT 30 // sec -#define CCNL_INTEREST_TIMEOUT 4 // sec -#define CCNL_MAX_INTEREST_RETRANSMIT 2 +#define CCNL_INTEREST_TIMEOUT_SEC 0 +#define CCNL_INTEREST_TIMEOUT_USEC (CCNL_CHECK_RETRANSMIT_USEC * (CCNL_MAX_INTEREST_RETRANSMIT + 1)) -#define CCNL_FACE_TIMEOUT 15 // sec +#define CCNL_CONTENT_TIMEOUT_SEC 2 +#define CCNL_CONTENT_TIMEOUT_USEC 0 -#define CCNL_MAX_NAME_COMP 16 -#define CCNL_MAX_IF_QLEN 64 +#define CCNL_MAX_CONTENT_SERVED_STAT 10 -#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 0 // means: no content caching -#define CCNL_MAX_NONCES 256 // for detected dups +#define CCNL_MAX_INTEREST_RETRANSMIT 5 +#define CCNL_MAX_INTEREST_OPTIMISTIC 2 +#define CCNL_FACE_TIMEOUT_SEC 10 +#define CCNL_FACE_TIMEOUT_USEC 0 + +#define CCNL_FWD_TIMEOUT_SEC 10 +#define CCNL_FWD_TIMEOUT_USEC 0 + +#define CCNL_CHECK_TIMEOUT_SEC 1 +#define CCNL_CHECK_TIMEOUT_USEC 0 + +#define CCNL_CHECK_RETRANSMIT_SEC 0 +#define CCNL_CHECK_RETRANSMIT_USEC ( 100 * 1000) + +#define CCNL_MAX_NAME_COMP 16 +#define CCNL_MAX_IF_QLEN 64 + +#define CCNL_MAX_NONCES 256 // for detected dups // ---------------------------------------------------------------------- // our own CCN-lite extensions for the ccnb encoding: diff --git a/sys/net/ccn_lite/util/Makefile b/sys/net/ccn_lite/util/Makefile index 878aaa02fe..cd74302c3b 100644 --- a/sys/net/ccn_lite/util/Makefile +++ b/sys/net/ccn_lite/util/Makefile @@ -1,4 +1,4 @@ MODULE := ccn_lite_client -INCLUDES = -I$(RIOTBASE) -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/net -I$(RIOTBASE)/cpu/arm_common/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/net/ccn_lite/ -I$(RIOTBASE)/sys/net/ccn_lite/include +INCLUDES = -I$(RIOTBASE) -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/net -I$(RIOTBASE)/cpu/arm_common/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/net/ccn_lite/ -I$(RIOTBASE)/sys/net/include include $(RIOTBASE)/Makefile.base diff --git a/sys/net/ccn_lite/util/ccnl-riot-client.c b/sys/net/ccn_lite/util/ccnl-riot-client.c index fe53266ae0..c5c3df4690 100644 --- a/sys/net/ccn_lite/util/ccnl-riot-client.c +++ b/sys/net/ccn_lite/util/ccnl-riot-client.c @@ -69,6 +69,12 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf) /* ######################################################################### */ msg_receive(&rep); + if (rep.type == CCNL_RIOT_NACK) { + /* network stack was not able to fetch this chunk */ + return 0; + } + + /* we got a chunk of data from the network stack */ riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; unsigned char *data = rmsg_reply->payload; @@ -128,7 +134,11 @@ int ccnl_riot_client_new_face(unsigned int relay_pid, char *type, char *faceid, DEBUGMSG(1, " received reply from relay\n"); riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; memcpy(reply_buf, rmsg_reply->payload, rmsg_reply->size); - return rmsg_reply->size; + int size = rmsg_reply->size; + + ccnl_free(rmsg_reply); + + return size; } int ccnl_riot_client_register_prefix(unsigned int relay_pid, char *prefix, char *faceid, @@ -154,8 +164,11 @@ int ccnl_riot_client_register_prefix(unsigned int relay_pid, char *prefix, char riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; memcpy(reply_buf, rmsg_reply->payload, rmsg_reply->size); reply_buf[rmsg_reply->size] = '\0'; + int size = rmsg_reply->size; - return rmsg_reply->size; + ccnl_free(rmsg_reply); + + return size; } int ccnl_riot_client_publish(unsigned int relay_pid, char *prefix, char *faceid, char *type, unsigned char *reply_buf) diff --git a/sys/net/ccn_lite/include/ccnl-riot.h b/sys/net/include/ccn_lite/ccnl-riot.h similarity index 86% rename from sys/net/ccn_lite/include/ccnl-riot.h rename to sys/net/include/ccn_lite/ccnl-riot.h index 2c9c0a5ce0..3307171c66 100644 --- a/sys/net/ccn_lite/include/ccnl-riot.h +++ b/sys/net/include/ccn_lite/ccnl-riot.h @@ -51,6 +51,9 @@ typedef enum ccnl_riot_event { CCNL_RIOT_MSG = CCNL_RIOT_EVENT_NUMBER_OFFSET + 1, CCNL_RIOT_HALT, CCNL_RIOT_POPULATE, + CCNL_RIOT_PRINT_STAT, + CCNL_RIOT_TIMEOUT, + CCNL_RIOT_NACK, CCNL_RIOT_RESERVED } ccnl_riot_event_t; @@ -76,8 +79,10 @@ typedef enum ccnl_riot_event { * @note to stop the relay send msg "RIOT_HALT" to this thread * * @param max_cache_entries number of slots in the CS + * @param fib_threshold_prefix conservative value how long a common prefix is (elemnts from behind) + * @param fib_threshold_aggregate optimistic value how long a common prefix is (elemnts from front) */ -void ccnl_riot_relay_start(int max_cache_entries); +void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate); /** * @brief starts an appication server, which can repy to ccn interests diff --git a/sys/net/ccn_lite/include/test_data/text.txt.ccnb.h b/sys/net/include/ccn_lite/test_data/text.txt.ccnb.h similarity index 100% rename from sys/net/ccn_lite/include/test_data/text.txt.ccnb.h rename to sys/net/include/ccn_lite/test_data/text.txt.ccnb.h diff --git a/sys/net/ccn_lite/include/util/ccnl-riot-client.h b/sys/net/include/ccn_lite/util/ccnl-riot-client.h similarity index 100% rename from sys/net/ccn_lite/include/util/ccnl-riot-client.h rename to sys/net/include/ccn_lite/util/ccnl-riot-client.h