diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index 9a16924c8e..9a7c2b9121 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -48,6 +48,7 @@ #include "msg.h" #include "thread.h" #include "transceiver.h" +#include "hwtimer.h" #include "ccnl-riot-compat.h" #include "test_data/text.txt.ccnb.h" @@ -69,20 +70,20 @@ ccnl_run_events(void) long usec; ccnl_get_timeval(&now); - DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec); + //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); } @@ -289,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; @@ -315,14 +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 = 100 * 1000; + int hwtimer_id; while (!ccnl->halt_flag) { - DEBUGMSG(1, "waiting for incomming msg\n"); + //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(); 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); @@ -339,6 +359,7 @@ 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); @@ -349,6 +370,7 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) break; case (CCNL_RIOT_HALT): + 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, "\tNumb:\t%" PRIu32 "\n", in.content.value); @@ -357,6 +379,7 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) break; #if RIOT_CCNL_POPULATE case (CCNL_RIOT_POPULATE): + 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, "\tNumb:\t%" PRIu32 "\n", in.content.value); @@ -364,7 +387,12 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) handle_populate_cache(); break; #endif + 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"); @@ -383,6 +411,7 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate) { ccnl_get_timeval(&theRelay.startup_time); + theRelay.riot_pid = thread_pid; 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__); diff --git a/sys/net/ccn_lite/ccnl-core.c b/sys/net/ccn_lite/ccnl-core.c index 9437e46a95..d92b4d3d30 100644 --- a/sys/net/ccn_lite/ccnl-core.c +++ b/sys/net/ccn_lite/ccnl-core.c @@ -815,6 +815,7 @@ void ccnl_interest_propagate(struct ccnl_relay_s *ccnl, } if (forward_cnt == 0) { + DEBUGMSG(40, " ccnl_interest_propagate: using broadcast face!\n"); ccnl_face_enqueue(ccnl, ccnl->ifs[RIOT_TRANS_IDX].broadcast_face, buf_dup(i->pkt)); } @@ -1124,7 +1125,7 @@ void ccnl_do_ageing(void *ptr, void *dummy) struct ccnl_face_s *f = relay->faces; struct timeval now; ccnl_get_timeval(&now); - DEBUGMSG(999, "ccnl_do_ageing %ld:%ld\n", now.tv_sec, now.tv_usec); + //DEBUGMSG(999, "ccnl_do_ageing %ld:%ld\n", now.tv_sec, now.tv_usec); while (c) { if (ccnl_is_timeouted(&now, &c->last_used, CCNL_CONTENT_TIMEOUT_SEC, CCNL_CONTENT_TIMEOUT_USEC) @@ -1171,7 +1172,6 @@ void ccnl_do_ageing(void *ptr, void *dummy) struct ccnl_forward_s *fwd = relay->fib; while (fwd) { - DEBUGMSG(1, "cleaning up fwd: %p\n", 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); diff --git a/sys/net/ccn_lite/ccnl-core.h b/sys/net/ccn_lite/ccnl-core.h index b9fdcd4d89..90afa32009 100644 --- a/sys/net/ccn_lite/ccnl-core.h +++ b/sys/net/ccn_lite/ccnl-core.h @@ -106,6 +106,7 @@ struct ccnl_relay_s { 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 { diff --git a/sys/net/ccn_lite/ccnl-riot-compat.c b/sys/net/ccn_lite/ccnl-riot-compat.c index d7e059066a..e2bbd08ef7 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.c +++ b/sys/net/ccn_lite/ccnl-riot-compat.c @@ -97,6 +97,9 @@ 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"; + default: return "UNKNOWN"; } diff --git a/sys/net/ccn_lite/include/ccnl-riot.h b/sys/net/ccn_lite/include/ccnl-riot.h index fc0ad5e381..9d225599b4 100644 --- a/sys/net/ccn_lite/include/ccnl-riot.h +++ b/sys/net/ccn_lite/include/ccnl-riot.h @@ -51,6 +51,7 @@ typedef enum ccnl_riot_event { CCNL_RIOT_MSG = CCNL_RIOT_EVENT_NUMBER_OFFSET + 1, CCNL_RIOT_HALT, CCNL_RIOT_POPULATE, + CCNL_RIOT_TIMEOUT, CCNL_RIOT_RESERVED } ccnl_riot_event_t;