1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

ccnl: use a second helper thread to handle e.g. timeouts

This commit is contained in:
Christian Mehlis 2014-04-17 18:21:31 +02:00
parent 04493cc026
commit 0b390040f4
5 changed files with 36 additions and 39 deletions

View File

@ -301,15 +301,6 @@ 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)
{
if (ccnl->ifcount == 0) {
@ -327,25 +318,15 @@ 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) {
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);
//DEBUGMSG(1, "%s Packet waiting, us was %lu\n", riot_ccnl_event_to_string(in.type), us);
msg_receive(&in);
mutex_lock(&theRelay.global_lock);
switch (in.type) {
case PKT_PENDING:
/* msg from transceiver */
hwtimer_remove(hwtimer_id);
p = (radio_packet_t *) in.content.ptr;
DEBUGMSG(1, "\tLength:\t%u\n", p->length);
DEBUGMSG(1, "\tSrc:\t%u\n", p->src);
@ -362,7 +343,6 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
case (CCNL_RIOT_MSG):
/* msg from device local client */
hwtimer_remove(hwtimer_id);
m = (riot_ccnl_msg_t *) in.content.ptr;
DEBUGMSG(1, "\tLength:\t%u\n", m->size);
DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid);
@ -373,7 +353,6 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
case (CCNL_RIOT_HALT):
/* cmd to stop the relay */
hwtimer_remove(hwtimer_id);
DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid);
DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value);
@ -383,7 +362,6 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
#if RIOT_CCNL_POPULATE
case (CCNL_RIOT_POPULATE):
/* cmd to polulate the cache */
hwtimer_remove(hwtimer_id);
DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid);
DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value);
@ -392,28 +370,21 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
#endif
case (CCNL_RIOT_PRINT_STAT):
/* cmd to print face statistics */
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):
/* ccn timeout from hwtimer, run pending events */
timeout = ccnl_run_events();
us = timeout->tv_sec * 1000 * 1000 + timeout->tv_usec;
break;
case (ENOBUFFER):
/* transceiver has not enough buffer to store incoming packets, one packet is dropped */
hwtimer_remove(hwtimer_id);
DEBUGMSG(1, "transceiver: one packet is dropped because buffers are full\n");
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");
break;
}
mutex_unlock(&theRelay.global_lock);
}
return 0;
@ -428,6 +399,7 @@ void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int
{
ccnl_get_timeval(&theRelay.startup_time);
theRelay.riot_pid = sched_active_pid;
mutex_init(&theRelay.global_lock);
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__);
@ -437,6 +409,8 @@ void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int
ccnl_relay_config(&theRelay, max_cache_entries, fib_threshold_prefix, fib_threshold_aggregate);
theRelay.riot_helper_pid = riot_start_helper_thread();
ccnl_io_loop(&theRelay);
DEBUGMSG(1, "ioloop stopped\n");
@ -447,4 +421,16 @@ void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int
ccnl_core_cleanup(&theRelay);
}
void ccnl_riot_relay_helper_start(void)
{
unsigned long us = CCNL_CHECK_RETRANSMIT_USEC;
while (!theRelay.halt_flag) {
hwtimer_wait(HWTIMER_TICKS(us));
mutex_lock(&theRelay.global_lock);
ccnl_run_events();
mutex_unlock(&theRelay.global_lock);
}
}
// eof

View File

@ -50,6 +50,8 @@
#include <time.h>
#include <sys/time.h>
#include "mutex.h"
#include "ccnl.h"
// ----------------------------------------------------------------------
@ -103,6 +105,8 @@ struct ccnl_relay_s {
int fib_threshold_prefix; /* how may name components should be considdered as dynamic */
int fib_threshold_aggregate;
int riot_pid;
int riot_helper_pid;
mutex_t global_lock;
};
struct ccnl_buf_s {

View File

@ -22,6 +22,7 @@
#include <inttypes.h>
#include "msg.h"
#include "thread.h"
#include "ccnl.h"
#include "ccnl-core.h"
@ -32,6 +33,8 @@ radio_packet_t p;
transceiver_command_t tcmd;
msg_t mesg, rep;
char relay_helper_stack[KERNEL_CONF_STACKSIZE_PRINTF];
int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to)
{
DEBUGMSG(1, "this is a RIOT TRANSCEIVER based connection\n");
@ -90,6 +93,13 @@ void riot_send_nack(uint16_t to)
msg_send(&m, to, 0);
}
void ccnl_riot_relay_helper_start(void);
int riot_start_helper_thread(void)
{
return thread_create(relay_helper_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 2, CREATE_STACKTEST, ccnl_riot_relay_helper_start, "relay-helper");
}
char *riot_ccnl_event_to_string(int event)
{
switch (event) {
@ -105,9 +115,6 @@ char *riot_ccnl_event_to_string(int 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";

View File

@ -30,4 +30,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);
int riot_start_helper_thread(void);
char *riot_ccnl_event_to_string(int event);

View File

@ -45,9 +45,8 @@
#define CCNL_RIOT_HALT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 1)
#define CCNL_RIOT_POPULATE (CCNL_RIOT_EVENT_NUMBER_OFFSET + 2)
#define CCNL_RIOT_PRINT_STAT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 3)
#define CCNL_RIOT_TIMEOUT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 4)
#define CCNL_RIOT_NACK (CCNL_RIOT_EVENT_NUMBER_OFFSET + 5)
#define CCNL_RIOT_RESERVED (CCNL_RIOT_EVENT_NUMBER_OFFSET + 6)
#define CCNL_RIOT_NACK (CCNL_RIOT_EVENT_NUMBER_OFFSET + 4)
#define CCNL_RIOT_RESERVED (CCNL_RIOT_EVENT_NUMBER_OFFSET + 5)
#define CCNL_HEADER_SIZE (40)