mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 07:21:18 +01:00
Merge pull request #1026 from mehlis/ccnl-helper-thread
ccnl: refactor ccn lite stack
This commit is contained in:
commit
e2052cb6a9
@ -4,7 +4,7 @@ simple appserver (all in one shell)
|
||||
0. create tap devices: *./cpu/native/tapsetup.sh create 3*
|
||||
1. build ccn-lite-client: *make -B clean all-valgrind*
|
||||
2. start: *./bin/native/ccn-lite-client.elf tap0* (valgrind support included)
|
||||
3. start ccn thread: *ccn* [enter] (this starts the ccn relay network stack)
|
||||
3. optinonal: *config 20* [enter] (this sets the content store size)
|
||||
4. start appserver thread: *appserver* [enter] (this starts the userland appserver, which registers for "/riot/appserver/"
|
||||
5. request content: *interest /riot/appserver/test* [enter] (ask the relay for this "file", userland code splits this up in
|
||||
chunks and requests them from the relay. In the relay the name "/riot/appserver" is registered to the RIOT MSG face with
|
||||
@ -20,27 +20,27 @@ SHELL 1 |
|
||||
0. create tap devices: *./cpu/native/tapsetup.sh create 3* |
|
||||
1. build ccn-lite-client: *make -B clean all* | build ccn-lite: *make clean all*
|
||||
2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/ccn-lite-relay.elf tap1*
|
||||
3. start ccn thread: *ccn* [enter] | [it starts ccn automaticly]
|
||||
3. set content store size: *config 20* [enter] | [stack starts automaticly]
|
||||
4. set address: *addr 1* [enter] | [it picks address 42 automaticly]
|
||||
5. register prefix the ccn-lite stack: *prefix /riot/ newTRANSface 42* [enter] | [it populates the cache automaticly]
|
||||
6. request content: *interest /riot/text* [enter] |
|
||||
7. tear down ccn network stack: *haltccn* [enter]
|
||||
|
||||
advanced forward (needs three [four] shells)
|
||||
advanced forward (needs three shells)
|
||||
====================================================
|
||||
|
||||
SHELL 1 | SHELL 2 | SHELL 3
|
||||
SHELL 1 | SHELL 2 | SHELL 3
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
0. create tap devices: *./cpu/native/tapsetup.sh create 3* | |
|
||||
1. build ccn-lite-client: *make -B clean all* | | build ccn-lite: make clean all
|
||||
2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/native/ccn-lite-client.elf tap1* | start: ./bin/ccn-lite-relay.elf tap2
|
||||
3. start ccn thread: *ccn* [enter] | start ccn thread: *ccn* [enter] | [it starts ccn automaticly]
|
||||
4. set address: *addr 1* [enter] | set address: *addr 2* [enter] | [it picks address 42 automaticly]
|
||||
5. *prefix /riot/ newTRANSface 2* [enter] | *prefix /riot/ newTRANSface 42* [enter] | [it populates the cache automaticly]
|
||||
6. request content: *interest /riot/text* [enter] | |
|
||||
0. create tap devices: *./cpu/native/tapsetup.sh create 3* | |
|
||||
1. build ccn-lite-client: *make -B clean all* | | build ccn-lite: make clean all
|
||||
2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/native/ccn-lite-client.elf tap1* | start: ./bin/ccn-lite-relay.elf tap2
|
||||
3. set content store size: *cconfig 20* [enter] | set content store size: *cconfig 20* [enter] | [it starts ccn automaticly]
|
||||
4. set address: *addr 1* [enter] | set address: *addr 2* [enter] | [it picks address 42 automaticly]
|
||||
5. *prefix /riot/ newTRANSface 2* [enter] | *prefix /riot/ newTRANSface 42* [enter] | [it populates the cache automaticly]
|
||||
6. request content: *interest /riot/text* [enter] | |
|
||||
|
||||
|
||||
overdosed forward (needs three [four] shells)
|
||||
overdosed forward (needs three shells)
|
||||
====================================================
|
||||
|
||||
SHELL 1 | SHELL 2 | SHELL 3
|
||||
@ -48,7 +48,7 @@ SHELL 1 | SH
|
||||
0. create tap devices: *./cpu/native/tapsetup.sh create 3* | |
|
||||
1. build ccn-lite-client: *make -B clean all* | |
|
||||
2. start: *./bin/native/ccn-lite-client.elf tap0* | start: *./bin/native/ccn-lite-client.elf tap1* | start: *./bin/native/ccn-lite-client.elf tap2*
|
||||
3. start ccn thread: *ccn* [enter] | start ccn thread: *ccn* [enter] | start ccn thread: *ccn* [enter]
|
||||
3. set content store size: *cconfig 20* [enter] | sset content store size: *cconfig 20* [enter] | sset content store size: *cconfig 20* [enter]
|
||||
4. set address: *addr 1* [enter] | set address: *addr 2* [enter] | set address: *addr 3* [enter]
|
||||
5. | | start appserver: *appserver* [enter]
|
||||
6. *prefix /riot/ newTRANSface 2* [enter] | *prefix /riot/ newTRANSface 3* [enter] |
|
||||
|
||||
@ -27,14 +27,12 @@ RIOTBASE ?= $(CURDIR)/../..
|
||||
# Change this to 0 show compiler invocation lines by default:
|
||||
QUIET ?= 1
|
||||
|
||||
BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4
|
||||
BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu redbee-econotag udoo z1 qemu-i386 \
|
||||
BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag
|
||||
BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \
|
||||
stm32f0discovery stm32f4discovery
|
||||
# mbed_lpc1768: see https://github.com/RIOT-OS/RIOT/issues/675
|
||||
# msb-430: see https://github.com/RIOT-OS/RIOT/issues/658
|
||||
# pttu: see https://github.com/RIOT-OS/RIOT/issues/659
|
||||
# redbee-econotag: see https://github.com/RIOT-OS/RIOT/issues/676
|
||||
# z1: lacks RTC features
|
||||
# qemu-i386: no transceiver, yet
|
||||
# stm32f0discovery: no transceiver, yet
|
||||
# stm32f4discovery: no transceiver, yet
|
||||
@ -47,7 +45,7 @@ USEMODULE += posix
|
||||
USEMODULE += ps
|
||||
USEMODULE += random
|
||||
USEMODULE += defaulttransceiver
|
||||
USEMODULE += rtc
|
||||
USEMODULE += vtimer
|
||||
USEMODULE += ccn_lite
|
||||
USEMODULE += ccn_lite_client
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
#include "shell.h"
|
||||
#include "board_uart0.h"
|
||||
#include "transceiver.h"
|
||||
#include "rtc.h"
|
||||
#include "vtimer.h"
|
||||
#include "ps.h"
|
||||
#include "ltc4150.h"
|
||||
|
||||
@ -41,9 +41,6 @@
|
||||
|
||||
#define RIOT_CCN_APPSERVER (1)
|
||||
#define RIOT_CCN_TESTS (0)
|
||||
#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 0 // means: no content caching
|
||||
#define CCNL_DEFAULT_THRESHOLD_PREFIX 1
|
||||
#define CCNL_DEFAULT_THRESHOLD_AGGREGATE 2
|
||||
|
||||
char relay_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
||||
|
||||
@ -52,8 +49,6 @@ char appserver_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
||||
#endif
|
||||
int relay_pid, appserver_pid;
|
||||
|
||||
int shell_max_cache_entries, shell_threshold_prefix, shell_threshold_aggregate;
|
||||
|
||||
#define SHELL_MSG_BUFFER_SIZE (64)
|
||||
msg_t msg_buffer_shell[SHELL_MSG_BUFFER_SIZE];
|
||||
|
||||
@ -63,12 +58,6 @@ unsigned char big_buf[3 * 1024];
|
||||
char small_buf[PAYLOAD_SIZE];
|
||||
|
||||
#if RIOT_CCN_APPSERVER
|
||||
static void *appserver_thread(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
ccnl_riot_appserver_start(relay_pid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void riot_ccn_appserver(int argc, char **argv)
|
||||
{
|
||||
@ -83,7 +72,7 @@ static void riot_ccn_appserver(int argc, char **argv)
|
||||
appserver_pid = thread_create(
|
||||
appserver_stack, sizeof(appserver_stack),
|
||||
PRIORITY_MAIN - 1, CREATE_STACKTEST,
|
||||
appserver_thread, NULL, "appserver");
|
||||
ccnl_riot_appserver_start, (void *) relay_pid, "appserver");
|
||||
DEBUG("ccn-lite appserver on thread_id %d...\n", appserver_pid);
|
||||
}
|
||||
#endif
|
||||
@ -135,46 +124,68 @@ static void riot_ccn_register_prefix(int argc, char **argv)
|
||||
puts("done");
|
||||
}
|
||||
|
||||
static void *relay_thread(void *arg)
|
||||
static void riot_ccn_relay_config(int argc, char **argv)
|
||||
{
|
||||
(void) arg;
|
||||
ccnl_riot_relay_start(shell_max_cache_entries, shell_threshold_prefix, shell_threshold_aggregate);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void riot_ccn_relay_start(int argc, char **argv)
|
||||
{
|
||||
if (relay_pid) {
|
||||
/* already running */
|
||||
if (!relay_pid) {
|
||||
puts("ccnl stack not running");
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
shell_max_cache_entries = CCNL_DEFAULT_MAX_CACHE_ENTRIES;
|
||||
}
|
||||
else {
|
||||
shell_max_cache_entries = atoi(argv[1]);
|
||||
printf("%s: <max_cache_entries>\n", argv[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
shell_threshold_prefix = CCNL_DEFAULT_THRESHOLD_PREFIX;
|
||||
}
|
||||
else {
|
||||
shell_threshold_prefix = atoi(argv[2]);
|
||||
msg_t m;
|
||||
m.content.value = atoi(argv[1]);
|
||||
m.type = CCNL_RIOT_CONFIG_CACHE;
|
||||
msg_send(&m, relay_pid, 1);
|
||||
}
|
||||
|
||||
static void riot_ccn_transceiver_start(int relay_pid)
|
||||
{
|
||||
transceiver_init(TRANSCEIVER);
|
||||
int transceiver_pid = transceiver_start();
|
||||
DEBUG("transceiver on thread_id %d...\n", transceiver_pid);
|
||||
|
||||
/* register for transceiver events */
|
||||
uint8_t reg = transceiver_register(TRANSCEIVER, relay_pid);
|
||||
if (reg != 1) {
|
||||
DEBUG("transceiver register failed\n");
|
||||
}
|
||||
|
||||
if (argc < 4) {
|
||||
shell_threshold_aggregate = CCNL_DEFAULT_THRESHOLD_AGGREGATE;
|
||||
/* set channel to CCNL_CHAN */
|
||||
msg_t mesg;
|
||||
transceiver_command_t tcmd;
|
||||
int32_t c = CCNL_DEFAULT_CHANNEL;
|
||||
tcmd.transceivers = TRANSCEIVER;
|
||||
tcmd.data = &c;
|
||||
mesg.content.ptr = (char *) &tcmd;
|
||||
mesg.type = SET_CHANNEL;
|
||||
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
||||
if (c == -1) {
|
||||
puts("[transceiver] Error setting/getting channel");
|
||||
}
|
||||
else {
|
||||
shell_threshold_aggregate = atoi(argv[3]);
|
||||
printf("[transceiver] Got channel: %" PRIi32 "\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
static void riot_ccn_relay_start(void)
|
||||
{
|
||||
if (relay_pid) {
|
||||
DEBUG("ccn-lite relay on thread_id %d...please stop it first!\n", relay_pid);
|
||||
/* already running */
|
||||
return;
|
||||
}
|
||||
|
||||
relay_pid = thread_create(
|
||||
relay_stack, sizeof(relay_stack),
|
||||
PRIORITY_MAIN - 2, CREATE_STACKTEST,
|
||||
relay_thread, NULL, "relay");
|
||||
ccnl_riot_relay_start, NULL, "relay");
|
||||
DEBUG("ccn-lite relay on thread_id %d...\n", relay_pid);
|
||||
|
||||
riot_ccn_transceiver_start(relay_pid);
|
||||
}
|
||||
|
||||
static void riot_ccn_relay_stop(int argc, char **argv)
|
||||
@ -214,7 +225,7 @@ static void riot_ccn_pit_test(int argc, char **argv)
|
||||
msg_t m;
|
||||
riot_ccnl_msg_t rmsg;
|
||||
char segment_string[16]; //max=999\0
|
||||
struct timeval now;
|
||||
timex_t now;
|
||||
|
||||
int segment;
|
||||
|
||||
@ -233,7 +244,7 @@ static void riot_ccn_pit_test(int argc, char **argv)
|
||||
msg_send(&m, relay_pid, 1);
|
||||
|
||||
if ((segment % 50) == 0) {
|
||||
rtc_time(&now);
|
||||
vtimer_now(&now);
|
||||
printf("done: %d - %ld.%ld\n", segment, now.tv_sec, now.tv_usec);
|
||||
}
|
||||
}
|
||||
@ -251,7 +262,7 @@ static void riot_ccn_fib_test(int argc, char **argv)
|
||||
|
||||
riot_new_face(relay_pid, type, faceid, big_buf);
|
||||
|
||||
struct timeval now;
|
||||
timex_t now;
|
||||
int i = -1;
|
||||
|
||||
do {
|
||||
@ -260,7 +271,7 @@ static void riot_ccn_fib_test(int argc, char **argv)
|
||||
riot_register_prefix(relay_pid, small_buf, faceid, big_buf);
|
||||
|
||||
if (i % 50 == 0) {
|
||||
rtc_time(&now);
|
||||
vtimer_now(&now);
|
||||
printf("done: %d - %ld.%ld\n", i, now.tv_sec, now.tv_usec);
|
||||
}
|
||||
}
|
||||
@ -294,12 +305,12 @@ static void riot_ccn_stat(int argc, char **argv)
|
||||
}
|
||||
|
||||
static const shell_command_t sc[] = {
|
||||
{ "ccn", "starts ccn relay", riot_ccn_relay_start },
|
||||
{ "haltccn", "stops ccn relay", riot_ccn_relay_stop },
|
||||
{ "interest", "express an interest", riot_ccn_express_interest },
|
||||
{ "populate", "populate the cache of the relay with data", riot_ccn_populate },
|
||||
{ "prefix", "registers a prefix to a face", riot_ccn_register_prefix },
|
||||
{ "stat", "prints out forwarding statistics", riot_ccn_stat },
|
||||
{ "config", "changes the runtime config of the ccn lite relay", riot_ccn_relay_config },
|
||||
#if RIOT_CCN_APPSERVER
|
||||
{ "appserver", "starts an application server to reply to interests", riot_ccn_appserver },
|
||||
#endif
|
||||
@ -310,27 +321,24 @@ static const shell_command_t sc[] = {
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
void riot_ccn_runner(void)
|
||||
{
|
||||
if (msg_init_queue(msg_buffer_shell, SHELL_MSG_BUFFER_SIZE) != 0) {
|
||||
DEBUG("msg init queue failed...abording\n");
|
||||
return;
|
||||
}
|
||||
|
||||
puts("posix open");
|
||||
posix_open(uart0_handler_pid, 0);
|
||||
puts("shell init");
|
||||
shell_init(&shell, sc, UART0_BUFSIZE, uart0_readc, uart0_putc);
|
||||
puts("shell run");
|
||||
shell_run(&shell);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("CCN!");
|
||||
|
||||
if (msg_init_queue(msg_buffer_shell, SHELL_MSG_BUFFER_SIZE) != 0) {
|
||||
DEBUG("msg init queue failed...abording\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
riot_ccn_relay_start();
|
||||
|
||||
puts("starting shell...");
|
||||
riot_ccn_runner();
|
||||
puts(" posix open");
|
||||
posix_open(uart0_handler_pid, 0);
|
||||
puts(" shell init");
|
||||
shell_init(&shell, sc, UART0_BUFSIZE, uart0_readc, uart0_putc);
|
||||
puts(" shell run");
|
||||
shell_run(&shell);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -27,14 +27,12 @@ RIOTBASE ?= $(CURDIR)/../..
|
||||
# Change this to 0 show compiler invocation lines by default:
|
||||
QUIET ?= 1
|
||||
|
||||
BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4
|
||||
BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu redbee-econotag udoo z1 qemu-i386 \
|
||||
BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag
|
||||
BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \
|
||||
stm32f0discovery stm32f4discovery
|
||||
# mbed_lpc1768: see https://github.com/RIOT-OS/RIOT/issues/675
|
||||
# msb-430: see https://github.com/RIOT-OS/RIOT/issues/658
|
||||
# pttu: see https://github.com/RIOT-OS/RIOT/issues/659
|
||||
# redbee-econotag: see https://github.com/RIOT-OS/RIOT/issues/676
|
||||
# z1: lacks RTC features
|
||||
# qemu-i386: no transceiver, yet
|
||||
# stm32f0discovery: no transceiver, yet
|
||||
# stm32f4discovery: no transceiver, yet
|
||||
|
||||
@ -35,10 +35,6 @@ int relay_pid;
|
||||
|
||||
char t2_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
||||
|
||||
#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 1
|
||||
#define CCNL_DEFAULT_THRESHOLD_PREFIX 1
|
||||
#define CCNL_DEFAULT_THRESHOLD_AGGREGATE 2
|
||||
|
||||
void set_address_handler(uint16_t a)
|
||||
{
|
||||
msg_t mesg;
|
||||
@ -79,13 +75,11 @@ int main(void)
|
||||
|
||||
relay_pid = thread_getpid();
|
||||
|
||||
thread_create(t2_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN + 1,
|
||||
thread_create(t2_stack, sizeof(t2_stack), PRIORITY_MAIN + 1,
|
||||
CREATE_STACKTEST, second_thread, NULL, "helper thread");
|
||||
|
||||
printf("starting ccn-lite relay...\n");
|
||||
ccnl_riot_relay_start(CCNL_DEFAULT_MAX_CACHE_ENTRIES,
|
||||
CCNL_DEFAULT_THRESHOLD_PREFIX,
|
||||
CCNL_DEFAULT_THRESHOLD_AGGREGATE);
|
||||
ccnl_riot_relay_start(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
#include "msg.h"
|
||||
#include "thread.h"
|
||||
#include "transceiver.h"
|
||||
#include "hwtimer.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
#include "ccnl-riot-compat.h"
|
||||
#include "ccn_lite/test_data/text.txt.ccnb.h"
|
||||
@ -52,9 +52,7 @@
|
||||
/** message buffer */
|
||||
msg_t msg_buffer_relay[RELAY_MSG_BUFFER_SIZE];
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
struct ccnl_relay_s theRelay;
|
||||
struct ccnl_relay_s *theRelay = NULL;
|
||||
|
||||
struct timeval *
|
||||
ccnl_run_events(void)
|
||||
@ -95,23 +93,12 @@ ccnl_run_events(void)
|
||||
|
||||
int ccnl_open_riotmsgdev(void)
|
||||
{
|
||||
/*
|
||||
* nothing to do here, msg system just needs a buffer, and this is
|
||||
* generated staticly
|
||||
*/
|
||||
return RIOT_MSG_DEV; /* sock id */
|
||||
return RIOT_MSG_DEV;
|
||||
}
|
||||
|
||||
int ccnl_open_riottransdev(void)
|
||||
{
|
||||
|
||||
transceiver_init(TRANSCEIVER);
|
||||
transceiver_start();
|
||||
|
||||
/** register for transceiver events */
|
||||
transceiver_register(TRANSCEIVER, thread_getpid());
|
||||
|
||||
return RIOT_TRANS_DEV; /* sock id */
|
||||
return RIOT_TRANS_DEV;
|
||||
}
|
||||
|
||||
void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc,
|
||||
@ -266,50 +253,41 @@ void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int data
|
||||
}
|
||||
}
|
||||
|
||||
void handle_populate_cache(void)
|
||||
void handle_populate_cache(struct ccnl_relay_s *ccnl)
|
||||
{
|
||||
DEBUGMSG(1, "ccnl_populate_cache with: text_txt_ccnb\n");
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_0, (int) text_txt_ccnb_0_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_1, (int) text_txt_ccnb_1_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_2, (int) text_txt_ccnb_2_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_3, (int) text_txt_ccnb_3_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_4, (int) text_txt_ccnb_4_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_5, (int) text_txt_ccnb_5_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_6, (int) text_txt_ccnb_6_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_7, (int) text_txt_ccnb_7_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_8, (int) text_txt_ccnb_8_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_9, (int) text_txt_ccnb_9_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_10, (int) text_txt_ccnb_10_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_11, (int) text_txt_ccnb_11_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_12, (int) text_txt_ccnb_12_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_13, (int) text_txt_ccnb_13_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_14, (int) text_txt_ccnb_14_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_15, (int) text_txt_ccnb_15_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_16, (int) text_txt_ccnb_16_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_17, (int) text_txt_ccnb_17_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_18, (int) text_txt_ccnb_18_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_19, (int) text_txt_ccnb_19_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_20, (int) text_txt_ccnb_20_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_21, (int) text_txt_ccnb_21_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_22, (int) text_txt_ccnb_22_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_23, (int) text_txt_ccnb_23_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_24, (int) text_txt_ccnb_24_len);
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_25, (int) text_txt_ccnb_25_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_0, (int) text_txt_ccnb_0_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_1, (int) text_txt_ccnb_1_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_2, (int) text_txt_ccnb_2_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_3, (int) text_txt_ccnb_3_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_4, (int) text_txt_ccnb_4_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_5, (int) text_txt_ccnb_5_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_6, (int) text_txt_ccnb_6_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_7, (int) text_txt_ccnb_7_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_8, (int) text_txt_ccnb_8_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_9, (int) text_txt_ccnb_9_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_10, (int) text_txt_ccnb_10_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_11, (int) text_txt_ccnb_11_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_12, (int) text_txt_ccnb_12_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_13, (int) text_txt_ccnb_13_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_14, (int) text_txt_ccnb_14_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_15, (int) text_txt_ccnb_15_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_16, (int) text_txt_ccnb_16_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_17, (int) text_txt_ccnb_17_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_18, (int) text_txt_ccnb_18_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_19, (int) text_txt_ccnb_19_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_20, (int) text_txt_ccnb_20_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_21, (int) text_txt_ccnb_21_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_22, (int) text_txt_ccnb_22_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_23, (int) text_txt_ccnb_23_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_24, (int) text_txt_ccnb_24_len);
|
||||
ccnl_populate_cache(ccnl, (unsigned char *) text_txt_ccnb_25, (int) text_txt_ccnb_25_len);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
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 +305,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(&ccnl->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 +330,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 +340,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,37 +349,34 @@ 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);
|
||||
|
||||
handle_populate_cache();
|
||||
handle_populate_cache(ccnl);
|
||||
break;
|
||||
#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;
|
||||
case (CCNL_RIOT_CONFIG_CACHE):
|
||||
/* cmd to configure the size of the cache at runtime */
|
||||
ccnl->max_cache_entries = in.content.value;
|
||||
DEBUGMSG(1, "max_cache_entries set to %d\n", ccnl->max_cache_entries);
|
||||
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(&ccnl->global_lock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -424,27 +387,54 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
|
||||
* @param pointer to count transceiver pids
|
||||
*
|
||||
*/
|
||||
void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate)
|
||||
void *ccnl_riot_relay_start(void *arg)
|
||||
{
|
||||
ccnl_get_timeval(&theRelay.startup_time);
|
||||
theRelay.riot_pid = sched_active_pid;
|
||||
(void) arg;
|
||||
|
||||
DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay.startup_time.tv_sec, theRelay.startup_time.tv_usec);
|
||||
theRelay = calloc(1, sizeof(struct ccnl_relay_s));
|
||||
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__);
|
||||
DEBUGMSG(1, " max_cache_entries: %d\n", max_cache_entries);
|
||||
DEBUGMSG(1, " threshold_prefix: %d\n", fib_threshold_prefix);
|
||||
DEBUGMSG(1, " threshold_aggregate: %d\n", fib_threshold_aggregate);
|
||||
DEBUGMSG(1, " max_cache_entries: %d\n", CCNL_DEFAULT_MAX_CACHE_ENTRIES);
|
||||
DEBUGMSG(1, " threshold_prefix: %d\n", CCNL_DEFAULT_THRESHOLD_PREFIX);
|
||||
DEBUGMSG(1, " threshold_aggregate: %d\n", CCNL_DEFAULT_THRESHOLD_AGGREGATE);
|
||||
|
||||
ccnl_relay_config(&theRelay, max_cache_entries, fib_threshold_prefix, fib_threshold_aggregate);
|
||||
ccnl_relay_config(theRelay, CCNL_DEFAULT_MAX_CACHE_ENTRIES, CCNL_DEFAULT_THRESHOLD_PREFIX, CCNL_DEFAULT_THRESHOLD_AGGREGATE);
|
||||
|
||||
ccnl_io_loop(&theRelay);
|
||||
theRelay->riot_helper_pid = riot_start_helper_thread();
|
||||
|
||||
ccnl_io_loop(theRelay);
|
||||
DEBUGMSG(1, "ioloop stopped\n");
|
||||
|
||||
while (eventqueue) {
|
||||
ccnl_rem_timer(eventqueue);
|
||||
}
|
||||
|
||||
ccnl_core_cleanup(&theRelay);
|
||||
ccnl_core_cleanup(theRelay);
|
||||
|
||||
mutex_lock(&theRelay->stop_lock);
|
||||
ccnl_free(theRelay);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ccnl_riot_relay_helper_start(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
unsigned long us = CCNL_CHECK_RETRANSMIT_USEC;
|
||||
mutex_lock(&theRelay->stop_lock);
|
||||
while (!theRelay->halt_flag) {
|
||||
mutex_lock(&theRelay->global_lock);
|
||||
ccnl_run_events();
|
||||
mutex_unlock(&theRelay->global_lock);
|
||||
|
||||
vtimer_usleep(us);
|
||||
}
|
||||
|
||||
mutex_unlock(&theRelay->stop_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// eof
|
||||
|
||||
@ -50,6 +50,8 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "mutex.h"
|
||||
|
||||
#include "ccnl.h"
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@ -103,6 +105,9 @@ 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;
|
||||
mutex_t stop_lock;
|
||||
};
|
||||
|
||||
struct ccnl_buf_s {
|
||||
|
||||
@ -166,12 +166,14 @@ static void riot_ccnl_appserver_register(void)
|
||||
free(mgnt_pkg);
|
||||
}
|
||||
|
||||
void ccnl_riot_appserver_start(int _relay_pid)
|
||||
void *ccnl_riot_appserver_start(void *arg)
|
||||
{
|
||||
int _relay_pid = (int) arg;
|
||||
relay_pid = _relay_pid;
|
||||
riot_ccnl_appserver_register();
|
||||
riot_ccnl_appserver_ioloop();
|
||||
DEBUGMSG(1, "appserver terminated\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
#include "ccnl-core.h"
|
||||
#include "ccnl-platform.h"
|
||||
|
||||
#include "rtc.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
long
|
||||
timevaldelta(struct timeval *a, struct timeval *b)
|
||||
@ -45,8 +45,12 @@ struct ccnl_timer_s *eventqueue;
|
||||
void
|
||||
ccnl_get_timeval(struct timeval *tv)
|
||||
{
|
||||
//gettimeofday(tv, NULL);
|
||||
rtc_time(tv);
|
||||
timex_t now;
|
||||
|
||||
vtimer_now(&now);
|
||||
|
||||
tv->tv_sec = now.seconds;
|
||||
tv->tv_usec = now.microseconds;
|
||||
}
|
||||
|
||||
void *
|
||||
|
||||
@ -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_MAIN];
|
||||
|
||||
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,15 @@ 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, sizeof(relay_helper_stack),
|
||||
PRIORITY_MAIN - 2, CREATE_STACKTEST,
|
||||
ccnl_riot_relay_helper_start, NULL, "relay-helper");
|
||||
}
|
||||
|
||||
char *riot_ccnl_event_to_string(int event)
|
||||
{
|
||||
switch (event) {
|
||||
@ -105,9 +117,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";
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -40,13 +40,18 @@
|
||||
|
||||
#define TRANSCEIVER TRANSCEIVER_DEFAULT
|
||||
|
||||
#define CCNL_DEFAULT_CHANNEL 6
|
||||
#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 0 /* 0: no content caching, cache is disabled */
|
||||
#define CCNL_DEFAULT_THRESHOLD_PREFIX 1
|
||||
#define CCNL_DEFAULT_THRESHOLD_AGGREGATE 2
|
||||
|
||||
#define CCNL_RIOT_EVENT_NUMBER_OFFSET (1 << 8)
|
||||
#define CCNL_RIOT_MSG (CCNL_RIOT_EVENT_NUMBER_OFFSET + 0)
|
||||
#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_NACK (CCNL_RIOT_EVENT_NUMBER_OFFSET + 4)
|
||||
#define CCNL_RIOT_CONFIG_CACHE (CCNL_RIOT_EVENT_NUMBER_OFFSET + 5)
|
||||
#define CCNL_RIOT_RESERVED (CCNL_RIOT_EVENT_NUMBER_OFFSET + 6)
|
||||
|
||||
#define CCNL_HEADER_SIZE (40)
|
||||
@ -67,18 +72,15 @@
|
||||
*
|
||||
* @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, int fib_threshold_prefix, int fib_threshold_aggregate);
|
||||
void *ccnl_riot_relay_start(void *arg);
|
||||
|
||||
/**
|
||||
* @brief starts an appication server, which can repy to ccn interests
|
||||
*
|
||||
* @param relay_pid the pid of the relay
|
||||
* @param arg the pid of the relay
|
||||
*/
|
||||
void ccnl_riot_appserver_start(int relay_pid);
|
||||
void *ccnl_riot_appserver_start(void *arg);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user