diff --git a/ccn-lite-client/HOWTO b/ccn-lite-client/HOWTO new file mode 100644 index 0000000..f9b74e9 --- /dev/null +++ b/ccn-lite-client/HOWTO @@ -0,0 +1,55 @@ +simple appserver (all in one shell) +==================================================== + +0. create tap devices: *./cpu/native/tapsetup.sh create 3* +1. build ccn-lite-client: *CFLAGS="-DHAVE_VALGRIND_VALGRIND_H" make -B clean all* +2. start: *./bin/ccn-lite-client.elf tap0* (valgrind support included) +3. start ccn thread: *ccn* [enter] (this starts the ccn relay network stack) +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 +thread of the appserver. Interest is forwarded to appserver which replies with content.... +6. tear down ccn network stack: *haltccn* [enter] +7. now you can hit *ctrl+c* to stop the RIOT process [in valgrind you can notice that there is no leak] + +simple forward (needs two shells) +==================================================== + +SHELL 1 | SHELL 2 +-------------------------------------------------------------------------------------------------------------- +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/ccn-lite-client.elf tap0* | start: *./bin/ccn-lite-relay.elf tap1* +3. start ccn thread: *ccn* [enter] | [it starts ccn 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) +==================================================== + +SHELL 1 | SHELL 2 | SHELL 3 | SHELL 4 (currently a bug in the native port on heavy traffic) +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +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 | ping -Itapbr0 8.8.8.8 +2. start: *./bin/ccn-lite-client.elf tap0* | start: *./bin/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] | | | + + +overdosed forward (needs three [four] shells) +==================================================== + +SHELL 1 | SHELL 2 | SHELL 3 | SHELL 4 +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +0. create tap devices: *./cpu/native/tapsetup.sh create 3* | | | +1. build ccn-lite-client: *make -B clean all* | | | ping -Itapbr0 8.8.8.8 +2. start: *./bin/ccn-lite-client.elf tap0* | start: *./bin/ccn-lite-client.elf tap1* | start: *./bin/ccn-lite-client.elf tap2* | +3. start ccn thread: *ccn* [enter] | start ccn thread: *ccn* [enter] | start ccn thread: *ccn* [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] | | +7. request content: *interest /riot/appserver/test* [enter] | | | diff --git a/ccn-lite-client/Makefile b/ccn-lite-client/Makefile new file mode 100644 index 0000000..c75a590 --- /dev/null +++ b/ccn-lite-client/Makefile @@ -0,0 +1,52 @@ +#### +#### Sample Makefile for building apps with the RIOT OS +#### +#### The Sample Filesystem Layout is: +#### /this makefile +#### ../../RIOT +#### ../../boards for board definitions (if you have one or more) +#### + +# name of your project +export PROJECT=ccn-lite-client + +# for easy switching of boards +ifeq ($(strip $(BOARD)),) + export BOARD=native +endif + +# this has to be the absolute path of the RIOT-base dir +export RIOTBASE =$(CURDIR)/../../RIOT +export RIOTBOARD =$(CURDIR)/../../boards + +ifeq ($(BOARD),stm32f4discovery) + include Makefile.$(BOARD) +endif + +## Modules to include. + +USEMODULE += config +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += uart0 +USEMODULE += posix +USEMODULE += ps +USEMODULE += auto_init + +USEMODULE += transceiver +ifeq ($(BOARD),msba2) + USEMODULE += cc110x_ng +else ifeq ($(BOARD),native) + USEMODULE += nativenet +endif + +USEMODULE += rtc +USEMODULE += crypto +USEMODULE += ccn_lite +USEMODULE += ccn_lite_client +USEMODULE += bloom +USEMODULE += hashes + +export INCLUDES=-I$(RIOTBOARD)/$(BOARD)/include -I$(RIOTBASE)/core/include -I$(RIOTCPU)/$(CPU)/include -I$(RIOTBASE)/sys/lib -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/net/ccn_lite/include + +include $(RIOTBASE)/Makefile.include diff --git a/ccn-lite-client/main.c b/ccn-lite-client/main.c new file mode 100644 index 0000000..da97b54 --- /dev/null +++ b/ccn-lite-client/main.c @@ -0,0 +1,293 @@ +/** + * RIOT CCN SHELL + * + * Copyright (C) 2013 Freie Universität Berlin + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * \{ + * \file riot_ccn.c + * \author Christian Mehlis + * \} + */ + +#include +#include +#include +#include + +#include "msg.h" +#include "thread.h" +#include "posix_io.h" +#include "shell.h" +#include "board_uart0.h" +#include "transceiver.h" +#include "rtc.h" +#include "ps.h" + +#define ENABLE_DEBUG (1) +#include "debug.h" + +#include "ccnl-riot.h" +#include "util/ccnl-riot-client.h" + +#define RIOT_CCN_APPSERVER (1) +#define RIOT_CCN_TESTS (0) + +char relay_stack[KERNEL_CONF_STACKSIZE_PRINTF]; + +#if RIOT_CCN_APPSERVER +char appserver_stack[KERNEL_CONF_STACKSIZE_PRINTF]; +#endif +int relay_pid, appserver_pid; + +#define SHELL_MSG_BUFFER_SIZE (64) +msg_t msg_buffer_shell[SHELL_MSG_BUFFER_SIZE]; + +shell_t shell; + +unsigned char big_buf[3 * 1024]; +char small_buf[PAYLOAD_SIZE]; + +#if RIOT_CCN_APPSERVER +static void appserver_thread(void) +{ + ccnl_riot_appserver_start(relay_pid); +} + +static void riot_ccn_appserver(char *str) +{ + (void) str; /* unused */ + + if (appserver_pid) { + /* already running */ + return; + } + + appserver_pid = thread_create(appserver_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 1, CREATE_STACKTEST, appserver_thread, "appserver"); + DEBUG("ccn-lite appserver on thread_id %d...\n", appserver_pid); +} +#endif + +static void riot_ccn_express_interest(char *str) +{ + char *given_interest = strtok(str, " "); /* str=interest, skip that */ + given_interest = strtok(NULL, " "); + static const char *default_interest = "/ccnx/0.7.1/doc/technical/CanonicalOrder.txt"; + + if (!given_interest) { + strncpy(small_buf, default_interest, 100); // null terminated + } + else { + strncpy(small_buf, given_interest, 100); + } + + DEBUG("in='%s'\n", small_buf); + + int content_len = ccnl_riot_client_get(relay_pid, small_buf, (char *) big_buf); // small_buf=name to request + + if (content_len == 0) { + puts("riot_get returned 0 bytes...aborting!"); + return; + } + + puts("####################################################"); + big_buf[content_len] = '\0'; + printf("data='%s'\n", big_buf); + puts("####################################################"); + puts("done"); +} + +static void riot_ccn_register_prefix(char *str) +{ + char *given_prefix = strtok(str, " "); + given_prefix = strtok(NULL, " "); + static const char *default_prefix = "/ccnx/0.7.1/doc/technical"; + + if (!given_prefix) { + strncpy(small_buf, default_prefix, 100); + } + else { + strncpy(small_buf, given_prefix, 100); + } + + DEBUG("prefix='%s'\n", small_buf); + + char *type = strtok(NULL, " "); + + if (!type) { + puts("enter: prefix /path/to/abc faceid"); + return; + } + + char *faceid = strtok(NULL, " ");//"2"; // 0=trans;1=msg + + if (!faceid) { + puts("enter: prefix /path/to/abc faceid"); + return; + } + + int content_len = ccnl_riot_client_publish(relay_pid, small_buf, faceid, type, big_buf); + + DEBUG("shell received: '%s'\n", big_buf); + DEBUG("received %d bytes.\n", content_len); + puts("done"); +} + +static void relay_thread(void) +{ + ccnl_riot_relay_start(); +} + +static void riot_ccn_relay_start(char *str) +{ + (void) str; /* unused */ + + if (relay_pid) { + /* already running */ + return; + } + + relay_pid = thread_create(relay_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 2, CREATE_STACKTEST, relay_thread, "relay"); + DEBUG("ccn-lite relay on thread_id %d...\n", relay_pid); +} + +static void riot_ccn_relay_stop(char *str) +{ + (void) str; /* unused */ + + msg_t m; + m.content.value = 0; + m.type = CCNL_RIOT_HALT; + msg_send(&m, relay_pid, 1); +} + +#if RIOT_CCN_TESTS +static void riot_ccn_pit_test(char *str) +{ + (void) str; /* unused */ + + char name[] = "/riot/test"; + + char *prefix[CCNL_MAX_NAME_COMP]; + char *cp = strtok(name, "/"); + int i = 0; + + while (i < (CCNL_MAX_NAME_COMP - 1) && cp) { + prefix[i++] = cp; + cp = strtok(NULL, "/"); + } + + //prefix[i] = 0; //segment to request + prefix[i + 1] = 0; + + msg_t m; + riot_ccnl_msg_t rmsg; + char segment_string[16]; //max=999\0 + struct timeval now; + + int segment; + + for (segment = 0; segment < 200; segment++) { + memset(segment_string, 0, 16); + snprintf(segment_string, 16, "%d", segment); + prefix[i] = segment_string; + int interest_len = mkInterest(prefix, NULL, (unsigned char *) small_buf); + + rmsg.payload = &small_buf; + rmsg.size = interest_len; + m.content.ptr = (char *) &rmsg; + m.type = CCNL_RIOT_MSG; + + msg_send(&m, relay_pid, 1); + + if ((segment % 50) == 0) { + rtc_time(&now); + printf("done: %d - %ld.%ld\n", segment, now.tv_sec, now.tv_usec); + } + } + + printf("done: tried to send %d interests\n", segment); +} + +static void riot_ccn_fib_test(char *str) +{ + (void) str; /* unused */ + + char type[] = "newTRANSface"; + char faceid[] = "42"; + + riot_new_face(relay_pid, type, faceid, big_buf); + + struct timeval now; + int i = -1; + + do { + i++; + snprintf(small_buf, sizeof(small_buf), "/riot/test/fib/%d/", i); + riot_register_prefix(relay_pid, small_buf, faceid, big_buf); + + if (i % 50 == 0) { + rtc_time(&now); + printf("done: %d - %ld.%ld\n", i, now.tv_sec, now.tv_usec); + } + } + while (0 == strcmp((const char *) big_buf, "prefixreg cmd worked")); + + DEBUG("%d: '%s'\n", i, big_buf); + printf("done: %d\n", i - 1); +} +#endif + +static void riot_ccn_populate(char *str) +{ + (void) str; /* unused */ + + msg_t m; + m.content.value = 0; + m.type = CCNL_RIOT_POPULATE; + msg_send(&m, relay_pid, 1); +} + +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 }, +#if RIOT_CCN_APPSERVER + { "appserver", "starts an application server to reply to interests", riot_ccn_appserver }, +#endif +#if RIOT_CCN_TESTS + { "pittest", "starts a test for the size and speed of pit operations", riot_ccn_pit_test }, + { "fibtest", "starts a test for the size and speed of fib operations", riot_ccn_fib_test }, +#endif + { 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_readc, uart0_putc); + puts("shell run"); + shell_run(&shell); +} + +int main(void) +{ + puts("CCN!"); + + puts("starting shell..."); + riot_ccn_runner(); + + return 0; +} diff --git a/ccn-lite-relay/Makefile b/ccn-lite-relay/Makefile new file mode 100644 index 0000000..ecbc51e --- /dev/null +++ b/ccn-lite-relay/Makefile @@ -0,0 +1,48 @@ +#### +#### Sample Makefile for building apps with the RIOT OS +#### +#### The Sample Filesystem Layout is: +#### /this makefile +#### ../../RIOT +#### ../../boards for board definitions (if you have one or more) +#### + +# name of your project +export PROJECT=ccn-lite-relay + +# for easy switching of boards +ifeq ($(strip $(BOARD)),) + export BOARD=native +endif + +# this has to be the absolute path of the RIOT-base dir +export RIOTBASE =$(CURDIR)/../../RIOT +export RIOTBOARD =$(CURDIR)/../../boards + +ifeq ($(BOARD),stm32f4discovery) + include Makefile.$(BOARD) +endif + +## Modules to include. + +USEMODULE += uart0 +USEMODULE += posix + +USEMODULE += auto_init + +USEMODULE += transceiver +ifeq ($(BOARD),msba2) + USEMODULE += cc110x_ng +else ifeq ($(BOARD),native) + USEMODULE += nativenet +endif + +USEMODULE += rtc +USEMODULE += ccn_lite +USEMODULE += crypto +USEMODULE += bloom +USEMODULE += hashes + +export INCLUDES=-I$(RIOTBOARD)/$(BOARD)/include -I$(RIOTBASE)/core/include -I$(RIOTCPU)/$(CPU)/include -I$(RIOTBASE)/sys/lib -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/net/ccn_lite/include/ + +include $(RIOTBASE)/Makefile.include diff --git a/ccn-lite-relay/main.c b/ccn-lite-relay/main.c new file mode 100644 index 0000000..2b119e0 --- /dev/null +++ b/ccn-lite-relay/main.c @@ -0,0 +1,77 @@ +/** + * RIOT CCN MAIN APP + * + * Copyright (C) 2013 Freie Universität Berlin + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * \{ + * \file main.c + * \author Christian Mehlis + * \} + */ + +// system +#include +#include +#include +#include + +// riot +#include "thread.h" +#include "rtc.h" + +// ccn +#include "ccnl-riot.h" + +int relay_pid; + +char t2_stack[KERNEL_CONF_STACKSIZE_PRINTF]; + +void set_address_handler(uint16_t a) +{ + msg_t mesg; + transceiver_command_t tcmd; + + tcmd.transceivers = transceiver_ids; + tcmd.data = &a; + mesg.content.ptr = (char *) &tcmd; + + printf("trying to set address %"PRIu16"\n", a); + mesg.type = SET_ADDRESS; + + printf("transceiver_pid=%d\n", transceiver_pid); + + msg_send_receive(&mesg, &mesg, transceiver_pid); + printf("got address: %"PRIu16"\n", a); +} + +void populate_cache() +{ + msg_t m; + m.content.value = 0; + m.type = CCNL_RIOT_POPULATE; + msg_send(&m, relay_pid, 1); +} + +void second_thread(void) +{ + set_address_handler(42); + populate_cache(); +} + +int main(void) +{ + printf("CCN!\n"); + + relay_pid = thread_getpid(); + + thread_create(t2_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN + 1, CREATE_STACKTEST, second_thread, "helper thread"); + + printf("starting ccn-lite relay...\n"); + ccnl_riot_relay_start(); + + return 0; +}