Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nanocoap: align macros to use kconfig symbols
Browse files Browse the repository at this point in the history
cgundogan committed May 15, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
miri64 Martine Lenders
1 parent b75a426 commit 3816adf
Showing 4 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions sys/include/net/nanocoap/cache.h
Original file line number Diff line number Diff line change
@@ -35,22 +35,22 @@ extern "C" {
/**
* @brief The number of maximum cache entries.
*/
#ifndef NANOCOAP_CACHE_ENTRIES
#define NANOCOAP_CACHE_ENTRIES (8)
#ifndef CONFIG_NANOCOAP_CACHE_ENTRIES
#define CONFIG_NANOCOAP_CACHE_ENTRIES (8)
#endif

/**
* @brief The length of the cache key in bytes.
*/
#ifndef NANOCOAP_CACHE_KEY_LENGTH
#define NANOCOAP_CACHE_KEY_LENGTH (8)
#ifndef CONFIG_NANOCOAP_CACHE_KEY_LENGTH
#define CONFIG_NANOCOAP_CACHE_KEY_LENGTH (8)
#endif

/**
* @brief Size of the buffer to store responses in the cache.
*/
#ifndef NANOCOAP_CACHE_RESPONSE_SIZE
#define NANOCOAP_CACHE_RESPONSE_SIZE (128)
#ifndef CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE
#define CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE (128)
#endif

/**
@@ -65,7 +65,7 @@ typedef struct {
/**
* @brief the calculated cache key, see nanocoap_cache_key_generate().
*/
uint8_t cache_key[NANOCOAP_CACHE_KEY_LENGTH];
uint8_t cache_key[CONFIG_NANOCOAP_CACHE_KEY_LENGTH];

/**
* @brief packet representation of the response
@@ -75,7 +75,7 @@ typedef struct {
/**
* @brief buffer to hold the response message.
*/
uint8_t response_buf[NANOCOAP_CACHE_RESPONSE_SIZE];
uint8_t response_buf[CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE];

size_t response_len; /**< length of the message in @p response */

4 changes: 2 additions & 2 deletions sys/net/application_layer/gcoap/forward_proxy/forward_proxy.c
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ typedef struct {
int in_use;
sock_udp_ep_t ep;
#if IS_ACTIVE(MODULE_NANOCOAP_CACHE)
uint8_t cache_key[NANOCOAP_CACHE_KEY_LENGTH];
uint8_t cache_key[CONFIG_NANOCOAP_CACHE_KEY_LENGTH];
#endif
} client_ep_t;

@@ -103,7 +103,7 @@ static int _cache_lookup_and_process(coap_pkt_t *pdu,
}

#if IS_ACTIVE(MODULE_NANOCOAP_CACHE)
memcpy(cep->cache_key, cache_key, NANOCOAP_CACHE_KEY_LENGTH);
memcpy(cep->cache_key, cache_key, CONFIG_NANOCOAP_CACHE_KEY_LENGTH);
#endif

return 0;
10 changes: 5 additions & 5 deletions sys/net/application_layer/nanocoap/cache.c
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
static clist_node_t _cache_list_head = { NULL };
static clist_node_t _empty_list_head = { NULL };

static nanocoap_cache_entry_t _cache_entries[NANOCOAP_CACHE_ENTRIES];
static nanocoap_cache_entry_t _cache_entries[CONFIG_NANOCOAP_CACHE_ENTRIES];

static nanocoap_cache_replacement_strategy_t _replacement_strategy = NULL;

@@ -63,7 +63,7 @@ void nanocoap_cache_init(void)
_empty_list_head.next = NULL;
memset(_cache_entries, 0, sizeof(_cache_entries));
/* construct list of empty entries */
for (unsigned i = 0; i < NANOCOAP_CACHE_ENTRIES; i++) {
for (unsigned i = 0; i < CONFIG_NANOCOAP_CACHE_ENTRIES; i++) {
clist_rpush(&_empty_list_head, &_cache_entries[i].node);
}

@@ -105,15 +105,15 @@ void nanocoap_cache_key_generate(const coap_pkt_t *req, uint8_t *cache_key)

ssize_t nanocoap_cache_key_compare(uint8_t *cache_key1, uint8_t *cache_key2)
{
return memcmp(cache_key1, cache_key2, NANOCOAP_CACHE_KEY_LENGTH);
return memcmp(cache_key1, cache_key2, CONFIG_NANOCOAP_CACHE_KEY_LENGTH);
}

static int _compare_cache_keys(clist_node_t *ce, void *arg)
{
nanocoap_cache_entry_t *iterator = (nanocoap_cache_entry_t *) ce;
uint8_t *cache_key = (uint8_t *) arg;

if (!memcmp(iterator->cache_key, cache_key, NANOCOAP_CACHE_KEY_LENGTH)) {
if (!memcmp(iterator->cache_key, cache_key, CONFIG_NANOCOAP_CACHE_KEY_LENGTH)) {
return 1;
}
return 0;
@@ -249,7 +249,7 @@ nanocoap_cache_entry_t *nanocoap_cache_add_by_key(const uint8_t *cache_key,
}
}

memcpy(ce->cache_key, cache_key, NANOCOAP_CACHE_KEY_LENGTH);
memcpy(ce->cache_key, cache_key, CONFIG_NANOCOAP_CACHE_KEY_LENGTH);
memcpy(&ce->response_pkt, resp, sizeof(coap_pkt_t));
memcpy(&ce->response_buf, resp->hdr, resp_len);
ce->response_pkt.hdr = (coap_hdr_t *) ce->response_buf;
28 changes: 14 additions & 14 deletions tests/unittests/tests-nanocoap_cache/tests-nanocoap_cache.c
Original file line number Diff line number Diff line change
@@ -90,21 +90,21 @@ static void test_nanocoap_cache__add(void)
nanocoap_cache_entry_t *c = NULL;
size_t len;
nanocoap_cache_entry_t *temp;
uint8_t temp_cache_key[NANOCOAP_CACHE_KEY_LENGTH];
uint8_t temp_cache_key[CONFIG_NANOCOAP_CACHE_KEY_LENGTH];

/* initialize the nanocoap cache */
nanocoap_cache_init();

/* add more entries to test LRU replacement */
for (unsigned i = 0; i < NANOCOAP_CACHE_ENTRIES + 4; i++) {
if (i < NANOCOAP_CACHE_ENTRIES) {
TEST_ASSERT_EQUAL_INT(NANOCOAP_CACHE_ENTRIES - i,
for (unsigned i = 0; i < CONFIG_NANOCOAP_CACHE_ENTRIES + 4; i++) {
if (i < CONFIG_NANOCOAP_CACHE_ENTRIES) {
TEST_ASSERT_EQUAL_INT(CONFIG_NANOCOAP_CACHE_ENTRIES - i,
nanocoap_cache_free_count());
TEST_ASSERT_EQUAL_INT(i, nanocoap_cache_used_count());
}
else {
TEST_ASSERT_EQUAL_INT(0, nanocoap_cache_free_count());
TEST_ASSERT_EQUAL_INT(NANOCOAP_CACHE_ENTRIES,
TEST_ASSERT_EQUAL_INT(CONFIG_NANOCOAP_CACHE_ENTRIES,
nanocoap_cache_used_count());
}

@@ -127,18 +127,18 @@ static void test_nanocoap_cache__add(void)
the LRU replacement */
temp = c;
/* the last round */
if (i == NANOCOAP_CACHE_ENTRIES + 3) {
if (i == CONFIG_NANOCOAP_CACHE_ENTRIES + 3) {
/* set absolute access time to a very old value */
/* this will enforce that entry to be cached out */
temp->access_time = 0;
memcpy(temp_cache_key, temp->cache_key,
NANOCOAP_CACHE_KEY_LENGTH);
CONFIG_NANOCOAP_CACHE_KEY_LENGTH);
}

/* add a fake response buffer with fake response length */
c = nanocoap_cache_add_by_req((const coap_pkt_t *)&req,
(const coap_pkt_t *)&req,
NANOCOAP_CACHE_RESPONSE_SIZE);
CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE);
TEST_ASSERT_NOT_NULL(c);
}

@@ -164,7 +164,7 @@ static void test_nanocoap_cache__del(void)
/* initialize the nanocoap cache */
nanocoap_cache_init();

TEST_ASSERT_EQUAL_INT(NANOCOAP_CACHE_ENTRIES,
TEST_ASSERT_EQUAL_INT(CONFIG_NANOCOAP_CACHE_ENTRIES,
nanocoap_cache_free_count());
TEST_ASSERT_EQUAL_INT(0, nanocoap_cache_used_count());

@@ -183,17 +183,17 @@ static void test_nanocoap_cache__del(void)

c = nanocoap_cache_add_by_req((const coap_pkt_t *)&req,
(const coap_pkt_t *)&resp,
NANOCOAP_CACHE_RESPONSE_SIZE);
CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE);
TEST_ASSERT_NOT_NULL(c);

TEST_ASSERT_EQUAL_INT(NANOCOAP_CACHE_ENTRIES - 1,
TEST_ASSERT_EQUAL_INT(CONFIG_NANOCOAP_CACHE_ENTRIES - 1,
nanocoap_cache_free_count());
TEST_ASSERT_EQUAL_INT(1, nanocoap_cache_used_count());

/* delete previously added cache entry */
res = nanocoap_cache_del(c);
TEST_ASSERT_EQUAL_INT(0, res);
TEST_ASSERT_EQUAL_INT(NANOCOAP_CACHE_ENTRIES ,
TEST_ASSERT_EQUAL_INT(CONFIG_NANOCOAP_CACHE_ENTRIES ,
nanocoap_cache_free_count());
TEST_ASSERT_EQUAL_INT(0, nanocoap_cache_used_count());
}
@@ -230,7 +230,7 @@ static void test_nanocoap_cache__max_age(void)

c = nanocoap_cache_add_by_req((const coap_pkt_t *)&req,
(const coap_pkt_t *)&resp,
NANOCOAP_CACHE_RESPONSE_SIZE);
CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE);

/* the absolute time of max-age should be at approx. now + 30 sec
(1 sec buffer) */
@@ -250,7 +250,7 @@ static void test_nanocoap_cache__max_age(void)

c = nanocoap_cache_add_by_req((const coap_pkt_t *)&req,
(const coap_pkt_t *)&resp,
NANOCOAP_CACHE_RESPONSE_SIZE);
CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE);

/* the absolute time of max-age should be at approx. now + 60 sec
(1 sec buffer) */

0 comments on commit 3816adf

Please sign in to comment.