From 4ee51da5dd22c8e1744811925c150755f68bd042 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 21 Nov 2013 10:17:55 +0100 Subject: [PATCH 1/6] get rid of static buffer this buffer was used for two types of outgoing packets: 1. local msg - msg can be big, there is is no apriori boundary -> use dynamic memory instead 2. transceiver msg - no need to copy msg in this buffer -> transceiver send is blocking --- sys/net/ccn_lite/ccn-lite-relay.c | 5 +---- sys/net/ccn_lite/ccnl-riot-compat.c | 17 +++++++++++++---- sys/net/ccn_lite/util/ccnl-riot-client.c | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index eef9f28257..01ae24cdf0 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -58,8 +58,6 @@ /** message buffer */ msg_t msg_buffer_relay[RELAY_MSG_BUFFER_SIZE]; -uint8_t packet_out[PAYLOAD_SIZE]; - // ---------------------------------------------------------------------- struct ccnl_relay_s theRelay; @@ -124,8 +122,7 @@ void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, { (void) ccnl; /* unused */ - memcpy(&packet_out, &buf->data, buf->datalen); - ifc->sendfunc(packet_out, (uint16_t) buf->datalen, (uint16_t) dest->id); + ifc->sendfunc(buf->data, (uint16_t) buf->datalen, (uint16_t) dest->id); } // ---------------------------------------------------------------------- diff --git a/sys/net/ccn_lite/ccnl-riot-compat.c b/sys/net/ccn_lite/ccnl-riot-compat.c index 996873759b..d7e059066a 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.c +++ b/sys/net/ccn_lite/ccnl-riot-compat.c @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -60,13 +61,21 @@ int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to) DEBUGMSG(1, "this is a RIOT MSG based connection\n"); DEBUGMSG(1, "size=%" PRIu16 " to=%" PRIu16 "\n", size, to); - static riot_ccnl_msg_t rmsg; - rmsg.payload = buf; - rmsg.size = size; + uint8_t *buf2 = malloc(sizeof(riot_ccnl_msg_t) + size); + if (!buf2) { + DEBUGMSG(1, " malloc failed...dorpping msg!\n"); + return 0; + } + + riot_ccnl_msg_t *rmsg = (riot_ccnl_msg_t *) buf2; + rmsg->payload = buf2 + sizeof(riot_ccnl_msg_t); + rmsg->size = size; + + memcpy(rmsg->payload, buf, size); msg_t m; m.type = CCNL_RIOT_MSG; - m.content.ptr = (char *) &rmsg; + m.content.ptr = (char *) rmsg; DEBUGMSG(1, "sending msg to pid=%u\n", to); msg_send(&m, to, 1); diff --git a/sys/net/ccn_lite/util/ccnl-riot-client.c b/sys/net/ccn_lite/util/ccnl-riot-client.c index 4e924e3d95..fe53266ae0 100644 --- a/sys/net/ccn_lite/util/ccnl-riot-client.c +++ b/sys/net/ccn_lite/util/ccnl-riot-client.c @@ -70,11 +70,10 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf) msg_receive(&rep); riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; - memcpy(&compat_small_buf, rmsg_reply->payload, rmsg_reply->size); - unsigned char *data = compat_small_buf; - int datalen = (int) rmsg_reply->size; - DEBUGMSG(1, "%d bytes left; msg from=%u '%s'\n", datalen, rep.sender_pid, compat_small_buf); + unsigned char *data = rmsg_reply->payload; + int datalen = (int) rmsg_reply->size; + DEBUGMSG(1, "%d bytes left; msg from=%u '%s'\n", datalen, rep.sender_pid, data); int scope = 3, aok = 3, minsfx = 0, maxsfx = CCNL_MAX_NAME_COMP, contlen = 0; @@ -96,6 +95,7 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf) free_prefix(p); free_3ptr_list(buf, nonce, ppkd); + ccnl_free(rmsg_reply); if (contlen < CCNL_RIOT_CHUNK_SIZE || CCNL_RIOT_CHUNK_SIZE < contlen) { /* last chunk */ From b675629a424d0f7931567ab40b9c3a91e055c9ba Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 21 Nov 2013 10:18:41 +0100 Subject: [PATCH 2/6] tune CCNL_RIOT_CHUNK_SIZE this constant is used for two test cases: 1. populate + interest /riot/text -> static content has this=90 bytes size 2. appserver + interest /riot/appserver/test -> dynamic content is created with exact CCNL_RIOT_CHUNK_SIZE bytes -> CCNL_RIOT_CHUNK_SIZE can be any value the transceiver can handle --- sys/net/ccn_lite/include/ccnl-riot.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/net/ccn_lite/include/ccnl-riot.h b/sys/net/ccn_lite/include/ccnl-riot.h index debbf311cb..c5c70086db 100644 --- a/sys/net/ccn_lite/include/ccnl-riot.h +++ b/sys/net/ccn_lite/include/ccnl-riot.h @@ -55,7 +55,20 @@ typedef enum ccnl_riot_event { CCNL_RIOT_RESERVED } ccnl_riot_event_t; -#define CCNL_RIOT_CHUNK_SIZE 90 +#define CCNL_HEADER_SIZE (40) + +#ifdef MODULE_NATIVENET +/* + * static content for testing ccn get has this chunk size + * this test (populate + interest /riot/text) current works + * only on transceiver which can handle ~130 bytes + */ +# define CCNL_RIOT_CHUNK_SIZE (90) +#else +# define CCNL_RIOT_CHUNK_SIZE (PAYLOAD_SIZE - CCNL_HEADER_SIZE) +#endif + + /** * @brief starts the ccnl relay From 229a131924b17fbd693db2b672cc02b6c22d72ef Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Wed, 27 Nov 2013 17:02:06 +0100 Subject: [PATCH 3/6] make max_cache_entries a parameter --- sys/net/ccn_lite/ccn-lite-relay.c | 5 ++--- sys/net/ccn_lite/include/ccnl-riot.h | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index 01ae24cdf0..9eae66c400 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -368,15 +368,14 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) * @param pointer to count transceiver pids * */ -void ccnl_riot_relay_start(void) +void ccnl_riot_relay_start(int max_cache_entries) { - int max_cache_entries = 20; - struct timeval now; theRelay.startup_time = rtc_time(&now); DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", now.tv_sec, now.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()); ccnl_relay_config(&theRelay, max_cache_entries); diff --git a/sys/net/ccn_lite/include/ccnl-riot.h b/sys/net/ccn_lite/include/ccnl-riot.h index c5c70086db..2c9c0a5ce0 100644 --- a/sys/net/ccn_lite/include/ccnl-riot.h +++ b/sys/net/ccn_lite/include/ccnl-riot.h @@ -74,8 +74,10 @@ typedef enum ccnl_riot_event { * @brief starts the ccnl relay * * @note to stop the relay send msg "RIOT_HALT" to this thread + * + * @param max_cache_entries number of slots in the CS */ -void ccnl_riot_relay_start(void); +void ccnl_riot_relay_start(int max_cache_entries); /** * @brief starts an appication server, which can repy to ccn interests From b74ee26941003eb6eff2b3bfe97e0fcb313588f5 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 28 Nov 2013 12:07:25 +0100 Subject: [PATCH 4/6] fix: remove oldest dynamic entry in content store --- sys/net/ccn_lite/ccnl-core.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sys/net/ccn_lite/ccnl-core.c b/sys/net/ccn_lite/ccnl-core.c index 34f1cf942f..74886217cb 100644 --- a/sys/net/ccn_lite/ccnl-core.c +++ b/sys/net/ccn_lite/ccnl-core.c @@ -915,22 +915,34 @@ ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c) DEBUGMSG(99, "ccnl_content_add2cache (%d/%d)\n", ccnl->contentcnt, ccnl->max_cache_entries); - if (ccnl->max_cache_entries > 0 - && ccnl->contentcnt >= ccnl->max_cache_entries) { // remove oldest content - struct ccnl_content_s *c2; + if (ccnl->max_cache_entries <= 0) { + DEBUGMSG(1, " content store disabled...\n"); + return NULL; + } + + 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) + for (c2 = ccnl->contents; c2; c2 = c2->next) { if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) && ((age == 0) || c2->last_used < age)) { age = c2->last_used; + oldest = c2; } + } - if (c2) { - ccnl_content_remove(ccnl, c2); + if (oldest) { + 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"); + break; } } + DEBUGMSG(1, " add new content to store: '%s'\n", ccnl_prefix_to_path(c->name)); DBL_LINKED_LIST_ADD(ccnl->contents, c); ccnl->contentcnt++; return c; From 25f6d7f1db1556b40717433b3ed21051024cbda8 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Wed, 27 Nov 2013 23:41:06 +0100 Subject: [PATCH 5/6] enable timeout events --- sys/net/ccn_lite/ccn-lite-relay.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index 9eae66c400..57d69851d3 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -69,17 +69,20 @@ ccnl_run_events(void) long usec; rtc_time(&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); 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); if (t->fct) { (t->fct)(t->node, t->intarg); } @@ -192,6 +195,8 @@ void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries) else { DEBUGMSG(1, "sorry, could not open riot trans device\n"); } + + ccnl_set_timer(1000000, ccnl_ageing, relay, 0); } #if RIOT_CCNL_POPULATE @@ -305,9 +310,9 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) riot_ccnl_msg_t *m; while (!ccnl->halt_flag) { - // struct timeval *timeout = ccnl_run_events(); DEBUGMSG(1, "waiting for incomming msg\n"); msg_receive(&in); + struct timeval *timeout = ccnl_run_events(); switch (in.type) { case PKT_PENDING: From afc63253057e1ff0c265fe63e068de4c112b2fc0 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Fri, 29 Nov 2013 21:56:27 +0100 Subject: [PATCH 6/6] fix function declaration isn't a prototype --- sys/net/ccn_lite/ccn-lite-relay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index 57d69851d3..5bdb42481b 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -247,7 +247,7 @@ void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int data } } -void handle_populate_cache() +void handle_populate_cache(void) { 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);