aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/core')
-rw-r--r--hicn-light/src/hicn/core/CMakeLists.txt4
-rw-r--r--hicn-light/src/hicn/core/address_pair.h3
-rw-r--r--hicn-light/src/hicn/core/connection.h7
-rw-r--r--hicn-light/src/hicn/core/connection_table.h10
-rw-r--r--hicn-light/src/hicn/core/content_store.c14
-rw-r--r--hicn-light/src/hicn/core/content_store.h16
-rw-r--r--hicn-light/src/hicn/core/fib.h13
-rw-r--r--hicn-light/src/hicn/core/fib_entry.h17
-rw-r--r--hicn-light/src/hicn/core/forwarder.c20
-rw-r--r--hicn-light/src/hicn/core/forwarder.h19
-rw-r--r--hicn-light/src/hicn/core/listener.c2
-rw-r--r--hicn-light/src/hicn/core/listener.h2
-rw-r--r--hicn-light/src/hicn/core/listener_table.h12
-rw-r--r--hicn-light/src/hicn/core/messageHandler.h4
-rw-r--r--hicn-light/src/hicn/core/msgbuf_pool.c16
-rw-r--r--hicn-light/src/hicn/core/msgbuf_pool.h68
-rw-r--r--hicn-light/src/hicn/core/nameBitvector.h2
-rw-r--r--hicn-light/src/hicn/core/nexthops.h2
-rw-r--r--hicn-light/src/hicn/core/pit.c9
-rw-r--r--hicn-light/src/hicn/core/pit.h15
-rw-r--r--hicn-light/src/hicn/core/prefix_stats.h2
-rw-r--r--hicn-light/src/hicn/core/test/CMakeLists.txt25
-rw-r--r--hicn-light/src/hicn/core/test/test-msgbuf_pool.cc112
23 files changed, 288 insertions, 106 deletions
diff --git a/hicn-light/src/hicn/core/CMakeLists.txt b/hicn-light/src/hicn/core/CMakeLists.txt
index f877717aa..32b546400 100644
--- a/hicn-light/src/hicn/core/CMakeLists.txt
+++ b/hicn-light/src/hicn/core/CMakeLists.txt
@@ -75,3 +75,7 @@ set(TO_INSTALL_HEADER_FILES
${HEADER_FILES}
PARENT_SCOPE
)
+
+if (BUILD_TESTS)
+ add_subdirectory(test)
+endif() \ No newline at end of file
diff --git a/hicn-light/src/hicn/core/address_pair.h b/hicn-light/src/hicn/core/address_pair.h
index 4dfdfd9de..09800aa62 100644
--- a/hicn-light/src/hicn/core/address_pair.h
+++ b/hicn-light/src/hicn/core/address_pair.h
@@ -21,9 +21,10 @@
#ifndef HICNLIGHT_ADDRESS_PAIR_H
#define HICNLIGHT_ADDRESS_PAIR_H
-#include <hicn/core/address.h>
#include <hicn/util/ip_address.h>
+#include "address.h"
+
typedef struct {
address_t local;
address_t remote;
diff --git a/hicn-light/src/hicn/core/connection.h b/hicn-light/src/hicn/core/connection.h
index d9ef817d2..186cad5c3 100644
--- a/hicn-light/src/hicn/core/connection.h
+++ b/hicn-light/src/hicn/core/connection.h
@@ -21,11 +21,12 @@
#ifndef HICNLIGHT_CONNECTION_H
#define HICNLIGHT_CONNECTION_H
-#include <hicn/core/address_pair.h>
-#include <hicn/core/listener.h>
-#include <hicn/core/msgbuf.h>
#include <hicn/face.h>
+#include "address_pair.h"
+#include "listener.h"
+#include "msgbuf.h"
+
#ifdef WITH_POLICY
#include <hicn/policy.h>
#endif /* WITH_POLICY */
diff --git a/hicn-light/src/hicn/core/connection_table.h b/hicn-light/src/hicn/core/connection_table.h
index 8a9342f45..d32a5fee8 100644
--- a/hicn-light/src/hicn/core/connection_table.h
+++ b/hicn-light/src/hicn/core/connection_table.h
@@ -30,11 +30,11 @@
#ifndef HICNLIGHT_CONNECTION_TABLE_H
#define HICNLIGHT_CONNECTION_TABLE_H
-#include <hicn/core/address_pair.h>
-#include <hicn/core/connection.h>
-#include <hicn/base/hash.h>
-#include <hicn/base/khash.h>
-#include <hicn/base/pool.h>
+#include "address_pair.h"
+#include "connection.h"
+#include "../base/hash.h"
+#include "../base/khash.h"
+#include "../base/pool.h"
#define _ct_var(x) _ct_var_##x
diff --git a/hicn-light/src/hicn/core/content_store.c b/hicn-light/src/hicn/core/content_store.c
index 74b675224..cf1fe3af9 100644
--- a/hicn-light/src/hicn/core/content_store.c
+++ b/hicn-light/src/hicn/core/content_store.c
@@ -112,11 +112,10 @@ void cs_clear(cs_t * cs)
}
off_t
-cs_match(cs_t * cs, off_t msgbuf_id, uint64_t now)
+cs_match(cs_t * cs, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id, uint64_t now)
{
assert(cs);
- const msgbuf_pool_t * msgbuf_pool = cs_get_msgbuf_pool(cs);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf);
@@ -133,7 +132,7 @@ cs_match(cs_t * cs, off_t msgbuf_id, uint64_t now)
if (cs_entry_has_expiry_time(entry) &&
cs_entry_get_expiry_time(entry) < now) {
// the entry is expired, we can remove it
- cs_remove_entry(cs, entry);
+ cs_remove_entry(cs, msgbuf_pool, entry);
goto NOT_FOUND;
}
@@ -160,7 +159,7 @@ NOT_FOUND:
#define msgbuf_acquire(x) (x)
cs_entry_t *
-cs_add(cs_t * cs, off_t msgbuf_id, uint64_t now)
+cs_add(cs_t * cs, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id, uint64_t now)
{
assert(cs);
assert(msgbuf_id_is_valid(msgbuf_id));
@@ -235,7 +234,7 @@ ERR_ENTRY:
}
int
-cs_remove_entry(cs_t * cs, cs_entry_t * entry)
+cs_remove_entry(cs_t * cs, msgbuf_pool_t * msgbuf_pool, cs_entry_t * entry)
{
assert(cs);
assert(entry);
@@ -245,7 +244,6 @@ cs_remove_entry(cs_t * cs, cs_entry_t * entry)
off_t msgbuf_id = cs_entry_get_msgbuf_id(entry);
- const msgbuf_pool_t * msgbuf_pool = cs_get_msgbuf_pool(cs);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
khiter_t k = kh_get_cs_name(cs->index_by_name, msgbuf_get_name(msgbuf));
@@ -263,7 +261,7 @@ cs_remove_entry(cs_t * cs, cs_entry_t * entry)
//
// XXX TODO what is the difference between purge and remove ?
bool
-cs_remove(cs_t * cs, msgbuf_t * msgbuf)
+cs_remove(cs_t * cs, msgbuf_pool_t * msgbuf_pool, msgbuf_t * msgbuf)
{
assert(cs);
assert(msgbuf);
@@ -277,7 +275,7 @@ cs_remove(cs_t * cs, msgbuf_t * msgbuf)
cs_entry_t * entry = cs->entries + kh_val(cs->index_by_name, k);
assert(entry);
- cs_remove_entry(cs, entry);
+ cs_remove_entry(cs, msgbuf_pool, entry);
return true;
}
diff --git a/hicn-light/src/hicn/core/content_store.h b/hicn-light/src/hicn/core/content_store.h
index 2973b3955..95b0a1d0a 100644
--- a/hicn-light/src/hicn/core/content_store.h
+++ b/hicn-light/src/hicn/core/content_store.h
@@ -58,7 +58,6 @@ typedef struct {
void * index_by_expiry_time;
#endif
- const msgbuf_pool_t * msgbuf_pool;
void * data; // per cs type data
void * options;
@@ -96,13 +95,13 @@ void cs_free(cs_t * cs);
void cs_clear(cs_t * cs);
-off_t cs_match(cs_t * cs, off_t msgbuf_id, uint64_t now);
+off_t cs_match(cs_t * cs, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id, uint64_t now);
-cs_entry_t * cs_add(cs_t * cs, off_t msgbuf_id, uint64_t now);
+cs_entry_t * cs_add(cs_t * cs, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id, uint64_t now);
-int cs_remove_entry(cs_t * cs, cs_entry_t * entry);
+int cs_remove_entry(cs_t * cs, msgbuf_pool_t * msgbuf_pool, cs_entry_t * entry);
-bool cs_remove(cs_t * cs, msgbuf_t * msgbuf);
+bool cs_remove(cs_t * cs, msgbuf_pool_t * msgbuf_pool, msgbuf_t * msgbuf);
#define cs_size(content_store) (pool_len(cs->entries))
@@ -112,13 +111,6 @@ void cs_purge_entry(cs_t * cs, cs_entry_t * entry);
#define cs_entry_at(cs, id) (&(cs)->entries[id])
-static inline
-const msgbuf_pool_t *
-cs_get_msgbuf_pool(const cs_t * cs)
-{
- return cs->msgbuf_pool;
-}
-
typedef struct {
const char * name;
diff --git a/hicn-light/src/hicn/core/fib.h b/hicn-light/src/hicn/core/fib.h
index f60a42cae..2b9925b61 100644
--- a/hicn-light/src/hicn/core/fib.h
+++ b/hicn-light/src/hicn/core/fib.h
@@ -12,12 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef fib_h
-#define fib_h
-#include <hicn/core/msgbuf.h>
-#include <hicn/core/name.h>
-#include <hicn/core/fib_entry.h>
+#ifndef HICNLIGHT_FIB_H
+#define HICNLIGHT_FIB_H
+
+#include "fib_entry.h"
+#include "msgbuf.h"
+#include "name.h"
#define _fib_var(x) _fib_ ## x
@@ -57,4 +58,4 @@ do {
free(_fib_var(array)); \
} while(0)
-#endif // fib_h
+#endif /* HICNLIGHT_FIB_H */
diff --git a/hicn-light/src/hicn/core/fib_entry.h b/hicn-light/src/hicn/core/fib_entry.h
index 94d283d0f..5ec0f29de 100644
--- a/hicn-light/src/hicn/core/fib_entry.h
+++ b/hicn-light/src/hicn/core/fib_entry.h
@@ -37,17 +37,12 @@
#ifndef fib_entry_h
#define fib_entry_h
-#include <hicn/core/name.h>
-#include <hicn/core/strategy.h>
-#include <hicn/core/msgbuf.h>
-#include <hicn/core/nexthops.h>
-#include <hicn/core/prefix_stats.h>
-#include <hicn/utils/commands.h> // strategy type
-
-#ifdef WITH_MAPME
-//#include <parc/algol/parc_EventTimer.h>
-//#include <parc/algol/parc_Iterator.h>
-#endif /* WITH_MAPME */
+#include "name.h"
+#include "strategy.h"
+#include "msgbuf.h"
+#include "nexthops.h"
+#include "prefix_stats.h"
+//#include "../utils/commands.h" // strategy type
typedef struct {
Name *name;
diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c
index 543fc99e4..4a31075f6 100644
--- a/hicn-light/src/hicn/core/forwarder.c
+++ b/hicn-light/src/hicn/core/forwarder.c
@@ -658,7 +658,7 @@ _satisfy_from_cs(forwarder_t * forwarder, off_t msgbuf_id)
assert(forwarder);
assert(msgbuf_id_is_valid(msgbuf_id));
- const msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
+ msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_INTEREST);
@@ -670,14 +670,14 @@ _satisfy_from_cs(forwarder_t * forwarder, off_t msgbuf_id)
return false;
// See if there's a match in the store.
- off_t data_msgbuf_id = cs_match(forwarder_get_cs(forwarder), msgbuf_id,
+ off_t data_msgbuf_id = cs_match(forwarder_get_cs(forwarder), msgbuf_pool, msgbuf_id,
ticks_now());
if (msgbuf_id_is_valid(data_msgbuf_id))
return false;
// Remove it from the PIT. nexthops is allocated, so need to destroy
- nexthops_t * nexthops = pit_on_data(forwarder->pit, data_msgbuf_id);
+ nexthops_t * nexthops = pit_on_data(forwarder->pit, msgbuf_pool, data_msgbuf_id);
assert(nexthops); // Illegal state: got a null nexthops for an interest we just inserted
// send message in reply, then done
@@ -711,7 +711,7 @@ forwarder_process_interest(forwarder_t * forwarder, off_t msgbuf_id)
assert(forwarder);
assert(msgbuf_id_is_valid(msgbuf_id));
- const msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
+ msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_INTEREST);
@@ -726,7 +726,7 @@ forwarder_process_interest(forwarder_t * forwarder, off_t msgbuf_id)
// (1) Try to aggregate in PIT
- pit_verdict_t verdict = pit_on_interest(forwarder->pit, msgbuf_id);
+ pit_verdict_t verdict = pit_on_interest(forwarder->pit, msgbuf_pool, msgbuf_id);
switch(verdict) {
case PIT_VERDICT_AGGREGATE:
forwarder->stats.countInterestsAggregated++;
@@ -781,7 +781,7 @@ static
ssize_t
forwarder_process_data(forwarder_t * forwarder, off_t msgbuf_id)
{
- const msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
+ msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
char *nameString = name_ToString(msgbuf_get_name(msgbuf));
@@ -792,7 +792,7 @@ forwarder_process_data(forwarder_t * forwarder, off_t msgbuf_id)
forwarder->stats.countReceived++;
forwarder->stats.countObjectsReceived++;
- nexthops_t * ingressSetUnion = pit_on_data(forwarder->pit, msgbuf_id);
+ nexthops_t * ingressSetUnion = pit_on_data(forwarder->pit, msgbuf_pool, msgbuf_id);
if (!ingressSetUnion) {
// (1) If it does not match anything in the PIT, drop it
forwarder->stats.countDroppedNoReversePath++;
@@ -822,7 +822,7 @@ forwarder_process_data(forwarder_t * forwarder, off_t msgbuf_id)
const connection_t * conn = connection_table_get_by_id(table, msgbuf_get_connection_id(msgbuf));
if (forwarder->store_in_cs && connection_is_local(conn)) {
- cs_add(forwarder->cs, msgbuf_id, ticks_now());
+ cs_add(forwarder->cs, msgbuf_pool, msgbuf_id, ticks_now());
DEBUG("Message %p store in CS anyway", msgbuf);
}
@@ -831,7 +831,7 @@ forwarder_process_data(forwarder_t * forwarder, off_t msgbuf_id)
// (2) Add to Content Store. Store may remove expired content, if necessary,
// depending on store policy.
if (forwarder->store_in_cs) {
- cs_add(forwarder->cs, msgbuf_id, ticks_now());
+ cs_add(forwarder->cs, msgbuf_pool, msgbuf_id, ticks_now());
}
// (3) Reverse path forward via PIT entries
return forwarder_forward_to_nexthops(forwarder, msgbuf_id, ingressSetUnion);
@@ -1123,7 +1123,7 @@ forwarder_receive(forwarder_t * forwarder, listener_t * listener,
assert(msgbuf_id_is_valid(msgbuf_id));
assert(pair);
- const msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
+ msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf);
diff --git a/hicn-light/src/hicn/core/forwarder.h b/hicn-light/src/hicn/core/forwarder.h
index a76e36530..f5ac375da 100644
--- a/hicn-light/src/hicn/core/forwarder.h
+++ b/hicn-light/src/hicn/core/forwarder.h
@@ -29,23 +29,22 @@
#include <stdlib.h>
#include <sys/socket.h> // struct mmsghdr
-#include <hicn/core/msgbuf.h>
-#include <hicn/core/content_store.h>
-#include <hicn/core/connection.h>
-#include <hicn/core/connection_table.h>
-#include <hicn/core/listener_table.h>
-#include <hicn/core/msgbuf_pool.h>
-
-#include <hicn/config/configuration.h>
+#include "connection.h"
+#include "connection_table.h"
+#include "content_store.h"
+#include "listener_table.h"
+#include "msgbuf.h"
+#include "msgbuf_pool.h"
+#include "../config/configuration.h"
#ifdef WITH_MAPME
-#include <hicn/core/fib.h>
+#include "fib.h"
#endif /* WITH_MAPME */
#define PORT_NUMBER 9695
#define PORT_NUMBER_AS_STRING "9695"
-#include <hicn/utils/commands.h>
+//#include <hicn/utils/commands.h>
// ==============================================
diff --git a/hicn-light/src/hicn/core/listener.c b/hicn-light/src/hicn/core/listener.c
index d24fafba0..de078b889 100644
--- a/hicn-light/src/hicn/core/listener.c
+++ b/hicn-light/src/hicn/core/listener.c
@@ -216,7 +216,7 @@ listener_read_single(listener_t * listener)
for (;;) {
msgbuf_t * msgbuf = NULL;
- off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, msgbuf);
+ off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
if (!msgbuf_id_is_valid(msgbuf_id))
return 0;
diff --git a/hicn-light/src/hicn/core/listener.h b/hicn-light/src/hicn/core/listener.h
index eb1ec6893..79aefef51 100644
--- a/hicn-light/src/hicn/core/listener.h
+++ b/hicn-light/src/hicn/core/listener.h
@@ -21,9 +21,9 @@
#ifndef HICNLIGHT_LISTENER_H
#define HICNLIGHT_LISTENER_H
-#include <hicn/core/address_pair.h>
#include <hicn/face.h>
+#include "address_pair.h"
#include "msgbuf.h"
#include "../base/loop.h"
diff --git a/hicn-light/src/hicn/core/listener_table.h b/hicn-light/src/hicn/core/listener_table.h
index 70cd8bbbf..5824f0551 100644
--- a/hicn-light/src/hicn/core/listener_table.h
+++ b/hicn-light/src/hicn/core/listener_table.h
@@ -30,12 +30,12 @@
#ifndef HICNLIGHT_LISTENER_TABLE_H
#define HICNLIGHT_LISTENER_TABLE_H
-#include <hicn/core/address.h>
-#include <hicn/base/common.h>
-#include <hicn/base/hash.h>
-#include <hicn/base/khash.h>
-#include <hicn/core/listener.h>
-#include <hicn/base/pool.h>
+#include "address.h"
+#include "listener.h"
+#include "../base/common.h"
+#include "../base/hash.h"
+#include "../base/khash.h"
+#include "../base/pool.h"
#define _lt_var(x) _lt_var_##x
diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h
index bc7ecf597..1df511a5c 100644
--- a/hicn-light/src/hicn/core/messageHandler.h
+++ b/hicn-light/src/hicn/core/messageHandler.h
@@ -551,7 +551,7 @@ static inline uint8_t * messageHandler_CreateProbePacket(hicn_format_t format,
size_t header_length;
hicn_packet_get_header_length_from_format(format, &header_length);
- uint8_t *pkt = calloc(header_length, 1);
+ uint8_t *pkt = (uint8_t *) calloc(header_length, 1);
hicn_packet_init_header(format, (hicn_header_t *) pkt);
@@ -584,7 +584,7 @@ static inline void messageHandler_CreateProbeReply(uint8_t * probe,
}
static inline hicn_name_t * messageHandler_CreateProbeName(const ip_prefix_t *address){
- hicn_name_t * name = calloc(sizeof(hicn_name_t), 1);
+ hicn_name_t * name = (hicn_name_t *) calloc(sizeof(hicn_name_t), 1);
hicn_name_create_from_ip_prefix(address, 0, name);
return name;
}
diff --git a/hicn-light/src/hicn/core/msgbuf_pool.c b/hicn-light/src/hicn/core/msgbuf_pool.c
index 597123a7a..137d9bb99 100644
--- a/hicn-light/src/hicn/core/msgbuf_pool.c
+++ b/hicn-light/src/hicn/core/msgbuf_pool.c
@@ -43,11 +43,10 @@ msgbuf_pool_free(msgbuf_pool_t * msgbuf_pool)
free(msgbuf_pool);
}
-int
-msgbuf_pool_get(msgbuf_pool_t * msgbuf_pool, msgbuf_t * msgbuf)
+off_t
+msgbuf_pool_get(msgbuf_pool_t * msgbuf_pool, msgbuf_t ** msgbuf)
{
- pool_get(msgbuf_pool->buffers, msgbuf);
- return 0;
+ return pool_get(msgbuf_pool->buffers, *msgbuf);
}
void
@@ -60,15 +59,16 @@ int
msgbuf_pool_getn(msgbuf_pool_t * msgbuf_pool, msgbuf_t ** msgbuf, size_t n)
{
for (unsigned i = 0; i < n; i++) {
- if (!msgbuf_pool_get(msgbuf_pool, msgbuf[i])) {
+ // If not able to get the msgbuf
+ if (msgbuf_pool_get(msgbuf_pool, &msgbuf[i]) < 0) {
+ // Release all the msgbufs retrieved so far
for (unsigned j = 0; j < i; j++) {
msgbuf_pool_put(msgbuf_pool, msgbuf[j]);
- return 0;
}
- break;
+ return -1;
}
}
- return -1;
+ return 0;
}
off_t
diff --git a/hicn-light/src/hicn/core/msgbuf_pool.h b/hicn-light/src/hicn/core/msgbuf_pool.h
index 2ada9fa14..a5c0248bc 100644
--- a/hicn-light/src/hicn/core/msgbuf_pool.h
+++ b/hicn-light/src/hicn/core/msgbuf_pool.h
@@ -17,7 +17,7 @@
* @file msgbuf_pool.h
* @brief hICN msgbuf pool.
*
- * THe msgbuf pool is used to store packet payloads while the packets are in
+ * The msgbuf pool is used to store packet payloads while the packets are in
* transit, as well as holding them into the packet cache (PIT, CSS), WLDR,
* mapme, etc.
*
@@ -46,20 +46,80 @@ typedef struct {
msgbuf_t * buffers;
} msgbuf_pool_t;
-// 0 for init size means a default value (of 1024)
-// 0 for max_size means no limit
+/**
+ * @brief Allocate and initialize a msgbuf pool structure (helper).
+ *
+ * @param[in] init_size Number of buffers that can be stored in msgbuf pool.
+ * @param[in] max_size Maximum size.
+ * @return msgbuf_pool_t* Pointer to the msgbuf pool created.
+ *
+ * @note
+ * - 0 for init size means a default value (of 1024)
+ * - 0 for max_size means no limit
+ */
msgbuf_pool_t * _msgbuf_pool_create(size_t init_size, size_t max_size);
+/**
+ * @brief Allocate and initialize a msgbuf pool data structure.
+ *
+ * @return msgbuf_pool_t* Pointer to the msgbuf pool created.
+ */
#define msgbuf_pool_create() _msgbuf_pool_create(0, 0)
+/**
+ * @brief Free a msgbuf pool data structure.
+ *
+ * @param[in] msgbuf_pool Pointer to the msgbuf pool data structure to free.
+ */
void msgbuf_pool_free(msgbuf_pool_t * msgbuf_pool);
-int msgbuf_pool_get(msgbuf_pool_t * msgbuf_pool, msgbuf_t * msgbuf);
+/**
+ * @brief Get a free msgbuf from the msgbuf pool data structure.
+ *
+ * @param[in] msgbuf_pool Pointer to the msgbuf pool data structure to use.
+ * @param[in, out] msgbuf Empty msgbuf that will be used to return the
+ * allocated one from the msgbuf pool.
+ * @return off_t ID of the msgbuf requested.
+ */
+off_t msgbuf_pool_get(msgbuf_pool_t * msgbuf_pool, msgbuf_t ** msgbuf);
+/**
+ * @brief Release a msgbuf previously obtained, making it available to the msgbuf pool.
+ *
+ * @param[in] msgbuf_pool Pointer to the msgbuf pool data structure to use.
+ * @param[in] msgbuf Pointer to the msgbuf to release.
+ */
+void msgbuf_pool_put(msgbuf_pool_t * msgbuf_pool, msgbuf_t * msgbuf);
+
+
+/**
+ * @brief Get multiple free msgbufs from the msgbuf pool data structure.
+ *
+ * @param[in] msgbuf_pool Pointer to the msgbuf pool data structure to use.
+ * @param[in, out] msgbuf Pointer to the first empty msgbuf that will be used to
+ * allocate the msgbufs.
+ * @param[in] n Number of msgbufs requested.
+ * @retval 0 Success.
+ * @retval -1 Error.
+ */
int msgbuf_pool_getn(msgbuf_pool_t * msgbuf_pool, msgbuf_t ** msgbuf, size_t n);
+/**
+ * @brief Get the ID corresponding to the msgbuf requested.
+ *
+ * @param[in] msgbuf_pool Pointer to the msgbuf pool data structure to use.
+ * @param[in] msgbuf Pointer to the msgbuf to retrieve the ID for.
+ * @return off_t ID of the msgbuf requested.
+ */
off_t msgbuf_pool_get_id(msgbuf_pool_t * msgbuf_pool, msgbuf_t * msgbuf);
+/**
+ * @brief Get the msgbuf corresponding to the ID requested.
+ *
+ * @param[in] msgbuf_pool Pointer to the msgbuf pool data structure to use.
+ * @param[in] id Index of the msgbuf to retrieve.
+ * @return msgbuf_t* Pointer to the msgbuf corresponding to the ID requested.
+ */
msgbuf_t * msgbuf_pool_at(const msgbuf_pool_t * msgbuf_pool, off_t id);
#endif /* HICNLIGHT_MSGBUF_POOL_H */
diff --git a/hicn-light/src/hicn/core/nameBitvector.h b/hicn-light/src/hicn/core/nameBitvector.h
index 256af68a0..d5977f5c0 100644
--- a/hicn-light/src/hicn/core/nameBitvector.h
+++ b/hicn-light/src/hicn/core/nameBitvector.h
@@ -20,7 +20,7 @@
#include <stdint.h>
#include <stdlib.h>
-#include <hicn/core/address.h>
+#include "address.h"
struct name_bitvector;
typedef struct name_bitvector NameBitvector;
diff --git a/hicn-light/src/hicn/core/nexthops.h b/hicn-light/src/hicn/core/nexthops.h
index 8e4878b45..e144fcdc4 100644
--- a/hicn-light/src/hicn/core/nexthops.h
+++ b/hicn-light/src/hicn/core/nexthops.h
@@ -25,7 +25,7 @@
#include <stdbool.h>
#include <stdlib.h>
-#include <hicn/core/strategy.h>
+#include "strategy.h"
#define _nexthops_var(x) _nexthops_##x
diff --git a/hicn-light/src/hicn/core/pit.c b/hicn-light/src/hicn/core/pit.c
index e80d895ec..36ec8aed1 100644
--- a/hicn-light/src/hicn/core/pit.c
+++ b/hicn-light/src/hicn/core/pit.c
@@ -96,12 +96,11 @@ pit_free(pit_t * pit)
}
pit_verdict_t
-pit_on_interest(pit_t * pit, off_t msgbuf_id)
+pit_on_interest(pit_t * pit, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id)
{
assert(pit);
assert(msgbuf_id_is_valid(msgbuf_id));
- const msgbuf_pool_t * msgbuf_pool = pit_get_msgbuf_pool(pit);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_INTEREST);
@@ -175,12 +174,11 @@ NOT_FOUND:
}
nexthops_t *
-pit_on_data(pit_t * pit, off_t msgbuf_id)
+pit_on_data(pit_t * pit, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id)
{
assert(pit);
assert(msgbuf_id_is_valid(msgbuf_id));
- const msgbuf_pool_t * msgbuf_pool = pit_get_msgbuf_pool(pit);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_DATA);
@@ -219,12 +217,11 @@ NOT_FOUND:
}
void
-pit_remove(pit_t * pit, off_t msgbuf_id)
+pit_remove(pit_t * pit, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id)
{
assert(pit);
assert(msgbuf_id_is_valid(msgbuf_id));
- const msgbuf_pool_t * msgbuf_pool = pit_get_msgbuf_pool(pit);
const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
assert(msgbuf);
diff --git a/hicn-light/src/hicn/core/pit.h b/hicn-light/src/hicn/core/pit.h
index 5607827fe..85958f88e 100644
--- a/hicn-light/src/hicn/core/pit.h
+++ b/hicn-light/src/hicn/core/pit.h
@@ -69,7 +69,6 @@ typedef enum {
KHASH_INIT(pit_name, const Name *, unsigned, 0, name_hash, name_hash_eq);
typedef struct {
- msgbuf_pool_t * msgbuf_pool;
size_t max_size;
pit_entry_t * entries; // pool
kh_pit_name_t * index_by_name;
@@ -77,17 +76,17 @@ typedef struct {
/**
* @brief Allocate a new PIT data structure (extended parameters)
- *
+ *
* @param init_size Initial size (0 = default)
* @param max_size Maximum size (0 = unbounded)
- *
+ *
* @return pit_t* Newly allocated PIT data structure
*/
pit_t * _pit_create(size_t init_size, size_t max_size);
/**
* @brief Allocate a new PIT data structure
- *
+ *
* @return pit_t* Newly allocated PIT data structure
*/
#define pit_create() _pit_create(0, 0)
@@ -108,14 +107,12 @@ do {
#define pit_at(pit, i) (pit->entries + i)
-pit_verdict_t pit_on_interest(pit_t * pit, off_t msgbuf_id);
+pit_verdict_t pit_on_interest(pit_t * pit, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id);
-nexthops_t * pit_on_data(pit_t * pit, off_t msgbuf_id);
+nexthops_t * pit_on_data(pit_t * pit, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id);
-void pit_remove(pit_t * pit, off_t msgbuf_id);
+void pit_remove(pit_t * pit, msgbuf_pool_t * msgbuf_pool, off_t msgbuf_id);
pit_entry_t * pit_lookup(const pit_t * pit, const msgbuf_t * msgbuf);
-#define pit_get_msgbuf_pool(pit) (pit->msgbuf_pool)
-
#endif /* HICNLIGHT_PIT_H */
diff --git a/hicn-light/src/hicn/core/prefix_stats.h b/hicn-light/src/hicn/core/prefix_stats.h
index 4d441203e..deedda793 100644
--- a/hicn-light/src/hicn/core/prefix_stats.h
+++ b/hicn-light/src/hicn/core/prefix_stats.h
@@ -4,7 +4,7 @@
#ifdef WITH_PREFIX_STATS
-#include <hicn/base/loop.h>
+#include "../base/loop.h"
typedef struct prefix_stats_mgr_s {
void * forwarder;
diff --git a/hicn-light/src/hicn/core/test/CMakeLists.txt b/hicn-light/src/hicn/core/test/CMakeLists.txt
new file mode 100644
index 000000000..1043ce580
--- /dev/null
+++ b/hicn-light/src/hicn/core/test/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+
+include(BuildMacros)
+
+list(APPEND TESTS
+ test-msgbuf_pool
+)
+
+foreach(test ${TESTS})
+ build_executable(${test}
+ NO_INSTALL
+ SOURCES ${test}.cc
+ LINK_LIBRARIES ${LIBHICN_LIGHT_SHARED} ${LIBHICNCTRL_SHARED} ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+ INCLUDE_DIRS ${HICN_LIGHT_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
+ DEPENDS gtest ${LIBHICNCTRL_SHARED} ${LIBHICN_LIGHT_SHARED}
+ COMPONENT ${HICN_LIGHT}
+ DEFINITIONS "${COMPILER_DEFINITIONS}"
+ )
+
+ if(${CMAKE_VERSION} VERSION_GREATER "3.10.0")
+ gtest_discover_tests(${test}-bin TEST_PREFIX new:)
+ else()
+ add_test(NAME ${test}-bin COMMAND ${test})
+ endif()
+endforeach()
diff --git a/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc b/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc
new file mode 100644
index 000000000..027f16ac9
--- /dev/null
+++ b/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <netinet/in.h>
+
+extern "C" {
+#define WITH_TESTS
+#include <hicn/core/msgbuf_pool.h>
+#include <hicn/base/pool.h> // TODO: remove this line
+}
+
+#define PACKET_POOL_DEFAULT_INIT_SIZE 1024
+
+class MsgbufPoolTest : public ::testing::Test {
+protected:
+ MsgbufPoolTest() {
+ msgbuf_pool = msgbuf_pool_create();
+ }
+ virtual ~MsgbufPoolTest() {
+ msgbuf_pool_free(msgbuf_pool);
+ }
+
+ msgbuf_pool_t *msgbuf_pool;
+};
+
+TEST_F(MsgbufPoolTest, Create)
+{
+ /* Check msgbuf_pool allocation */
+ EXPECT_NE(msgbuf_pool, nullptr);
+
+ /* Check msgbuf_pool size */
+ size_t msgbuf_pool_size = pool_hdr(msgbuf_pool->buffers)->alloc_size;
+ EXPECT_EQ(msgbuf_pool_size, (size_t) PACKET_POOL_DEFAULT_INIT_SIZE);
+}
+
+TEST_F(MsgbufPoolTest, GetMsgbuf)
+{
+ msgbuf_t *msgbuf = NULL;
+
+ /* Get valid msgbuf from msgbuf_pool */
+ off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
+ EXPECT_NE(msgbuf, nullptr);
+ EXPECT_NE(msgbuf_id_is_valid((unsigned long) msgbuf_id), 0);
+
+ /* Check if the returned id is correct */
+ off_t id = msgbuf_pool_get_id(msgbuf_pool, msgbuf);
+ EXPECT_EQ(id, msgbuf_id);
+
+ /* Check if the returned msgbuf is correct */
+ msgbuf_t *msgbuf_retrieved = msgbuf_pool_at(msgbuf_pool, id);
+ EXPECT_EQ(msgbuf_retrieved, msgbuf);
+}
+
+TEST_F(MsgbufPoolTest, PutMsgbuf)
+{
+ /* Check that asking a msgbuf right after releasing another one
+ returns the same msgbuf */
+
+ msgbuf_t *msgbuf = NULL;
+
+ off_t id1 = msgbuf_pool_get(msgbuf_pool, &msgbuf);
+ EXPECT_NE(msgbuf, nullptr);
+
+ msgbuf_pool_put(msgbuf_pool, msgbuf);
+
+ off_t id2 = msgbuf_pool_get(msgbuf_pool, &msgbuf);
+ EXPECT_NE(msgbuf, nullptr);
+
+ EXPECT_EQ(id2, id1);
+}
+
+TEST_F(MsgbufPoolTest, GetMultipleMsgbufs)
+{
+ const int NUM_MSG = 3;
+ msgbuf_t *msgbufs[NUM_MSG];
+
+ /* Check if successful allocation */
+ int ret = msgbuf_pool_getn(msgbuf_pool, msgbufs, NUM_MSG);
+ EXPECT_EQ(ret, 0);
+
+ /* Check if all msgbufs are valid */
+ for (unsigned i = 0; i < NUM_MSG; i++) {
+ msgbuf_pool_get_id(msgbuf_pool, msgbufs[i]);
+ EXPECT_NE(msgbufs[i], nullptr) << "Invalid index: " << i;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}