aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/test
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/test')
-rw-r--r--hicn-light/src/hicn/test/CMakeLists.txt15
-rw-r--r--hicn-light/src/hicn/test/test-bitmap.cc144
-rw-r--r--hicn-light/src/hicn/test/test-connection_table.cc3
-rw-r--r--hicn-light/src/hicn/test/test-ctrl.cc11
-rw-r--r--hicn-light/src/hicn/test/test-fib.cc85
-rw-r--r--hicn-light/src/hicn/test/test-interest_manifest.cc79
-rw-r--r--hicn-light/src/hicn/test/test-khash.cc154
-rw-r--r--hicn-light/src/hicn/test/test-listener_table.cc2
-rw-r--r--hicn-light/src/hicn/test/test-local_prefixes.cc195
-rw-r--r--hicn-light/src/hicn/test/test-msgbuf_pool.cc12
-rw-r--r--hicn-light/src/hicn/test/test-packet_cache.cc240
-rw-r--r--hicn-light/src/hicn/test/test-parser.cc4
-rw-r--r--hicn-light/src/hicn/test/test-pool.cc196
-rw-r--r--hicn-light/src/hicn/test/test-ring.cc99
-rw-r--r--hicn-light/src/hicn/test/test-strategy-replication.cc1
-rw-r--r--hicn-light/src/hicn/test/test-subscription.cc6
-rw-r--r--hicn-light/src/hicn/test/test-vector.cc232
-rw-r--r--hicn-light/src/hicn/test/test_hash.cc (renamed from hicn-light/src/hicn/test/test-hash.cc)3
18 files changed, 348 insertions, 1133 deletions
diff --git a/hicn-light/src/hicn/test/CMakeLists.txt b/hicn-light/src/hicn/test/CMakeLists.txt
index 65e216c1e..cbe939297 100644
--- a/hicn-light/src/hicn/test/CMakeLists.txt
+++ b/hicn-light/src/hicn/test/CMakeLists.txt
@@ -1,19 +1,13 @@
-# Copyright (c) 2021 Cisco and/or its affiliates.
+# Copyright (c) 2021-2022 Cisco and/or its affiliates.
include(BuildMacros)
list(APPEND TESTS_SRC
- test-bitmap.cc
test-configuration.cc
- test-hash.cc
- test-khash.cc
+ test-fib.cc
test-loop.cc
- test-pool.cc
test-parser.cc
test-ctrl.cc
- test-ring.cc
- test-vector.cc
- test-interest_manifest.cc
test-msgbuf_pool.cc
test-nexthops.cc
test-connection_table.cc
@@ -26,8 +20,8 @@ list(APPEND TESTS_SRC
test-subscription.cc
test-local_prefixes.cc
test-probe_generator.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/../config/command_listener.c
- ${CMAKE_CURRENT_SOURCE_DIR}/../config/command_route.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../ctrl/libhicnctrl/src/commands/command_listener.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../ctrl/libhicnctrl/src/commands/command_route.c
main.cc
)
@@ -39,6 +33,7 @@ build_executable(hicn_light_tests
DEPENDS gtest ${LIBHICNCTRL_STATIC} ${LIBHICN_LIGHT_SHARED}
COMPONENT ${HICN_LIGHT}
DEFINITIONS "${COMPILER_DEFINITIONS}"
+ COMPILE_OPTIONS ${COMPILER_OPTIONS}
)
add_test_internal(hicn_light_tests)
diff --git a/hicn-light/src/hicn/test/test-bitmap.cc b/hicn-light/src/hicn/test/test-bitmap.cc
deleted file mode 100644
index 1fd21a1bb..000000000
--- a/hicn-light/src/hicn/test/test-bitmap.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (c) 2021 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/util/bitmap.h>
-}
-
-#define DEFAULT_SIZE 10
-
-class BitmapTest : public ::testing::Test {
- protected:
- BitmapTest() {}
-
- virtual ~BitmapTest() {}
-
- bitmap_t* bitmap;
-};
-
-/*
- * TEST: bitmap allocation
- */
-TEST_F(BitmapTest, BitmapAllocation) {
- int rc;
-
- /*
- * We take a value < 32 on purpose to avoid confusion on the choice of a 32
- * or 64 bit integer for storage
- */
- size_t size_not_pow2 = DEFAULT_SIZE;
- bitmap_init(bitmap, size_not_pow2, 0);
-
- /*
- * Bitmap should have been allocated with a size rounded to the next power
- * of 2
- */
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
-
- /* By default, no element should be set */
- EXPECT_FALSE(bitmap_is_set(bitmap, 0));
- EXPECT_TRUE(bitmap_is_unset(bitmap, 0));
-
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
-
- EXPECT_FALSE(bitmap_is_set(bitmap, size_not_pow2 - 1));
- EXPECT_TRUE(bitmap_is_unset(bitmap, size_not_pow2 - 1));
-
- /* Bitmap should not have been reallocated */
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
-
- /* After setting a bit after the end, bitmap should have been reallocated */
- bitmap_set(bitmap, sizeof(bitmap[0]) * 8 - 1);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
-
- /* After setting a bit after the end, bitmap should have been reallocated */
- rc = bitmap_set(bitmap, sizeof(bitmap[0]) * 8);
- EXPECT_GE(rc, 0);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 2UL);
-
- rc = bitmap_set(bitmap, sizeof(bitmap[0]) * 8 + 1);
- EXPECT_GE(rc, 0);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 2UL);
-
- bitmap_free(bitmap);
-
- size_t size_pow2 = 16;
-
- /* Limiting test for allocation size */
- bitmap_init(bitmap, size_pow2, 0);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
-
- bitmap_free(bitmap);
-}
-
-TEST_F(BitmapTest, BitmapSet) {
- bitmap_init(bitmap, DEFAULT_SIZE, 0);
-
- bitmap_set(bitmap, 20);
- EXPECT_TRUE(bitmap_is_set(bitmap, 20));
- EXPECT_FALSE(bitmap_is_unset(bitmap, 20));
- EXPECT_FALSE(bitmap_is_set(bitmap, 19));
- EXPECT_TRUE(bitmap_is_unset(bitmap, 19));
-
- // Test edge cases (i.e. start and end of block)
- off_t start_position = 0;
- bitmap_set(bitmap, start_position);
- EXPECT_TRUE(bitmap_is_set(bitmap, start_position));
- EXPECT_FALSE(bitmap_is_unset(bitmap, start_position));
-
- off_t end_position = BITMAP_WIDTH(bitmap) - 1;
- bitmap_set(bitmap, end_position);
- EXPECT_TRUE(bitmap_is_set(bitmap, end_position));
- EXPECT_FALSE(bitmap_is_unset(bitmap, end_position));
-
- bitmap_free(bitmap);
-}
-
-TEST_F(BitmapTest, BitmapUnSet) {
- bitmap_init(bitmap, DEFAULT_SIZE, 0);
-
- bitmap_set(bitmap, 20);
- bitmap_set(bitmap, 19);
- bitmap_unset(bitmap, 20);
- EXPECT_FALSE(bitmap_is_set(bitmap, 20));
- EXPECT_TRUE(bitmap_is_unset(bitmap, 20));
- EXPECT_TRUE(bitmap_is_set(bitmap, 19));
- EXPECT_FALSE(bitmap_is_unset(bitmap, 19));
-
- bitmap_free(bitmap);
-}
-
-TEST_F(BitmapTest, BitmapSetTo) {
- bitmap_init(bitmap, DEFAULT_SIZE, 0);
-
- bitmap_set_to(bitmap, 40);
- EXPECT_TRUE(bitmap_is_set(bitmap, 20));
- EXPECT_TRUE(bitmap_is_set(bitmap, 21));
- EXPECT_TRUE(bitmap_is_unset(bitmap, 41));
- EXPECT_TRUE(bitmap_is_unset(bitmap, 42));
-
- bitmap_free(bitmap);
-}
diff --git a/hicn-light/src/hicn/test/test-connection_table.cc b/hicn-light/src/hicn/test/test-connection_table.cc
index d17de7c2c..171921b53 100644
--- a/hicn-light/src/hicn/test/test-connection_table.cc
+++ b/hicn-light/src/hicn/test/test-connection_table.cc
@@ -27,6 +27,7 @@
extern "C" {
#define WITH_TESTS
#include <hicn/core/connection_table.h>
+#include <hicn/util/log.h>
}
#define CONNECTION_NAME "connection_name_test"
@@ -275,7 +276,7 @@ TEST_F(ConnectionTableTest, GenerateConnNameExhaustion) {
bool unable_to_allocate = false;
// Force name exhaustion
- int i, n_connections = 1 + USHRT_MAX;
+ int n_connections = 1 + USHRT_MAX;
for (int i = 0; i <= n_connections; i++) {
int rc = connection_table_get_random_name(conn_table_, conn_name);
if (rc < 0) {
diff --git a/hicn-light/src/hicn/test/test-ctrl.cc b/hicn-light/src/hicn/test/test-ctrl.cc
index e24b47f27..f0d3e7c37 100644
--- a/hicn-light/src/hicn/test/test-ctrl.cc
+++ b/hicn-light/src/hicn/test/test-ctrl.cc
@@ -18,7 +18,7 @@
extern "C" {
#include <hicn/util/log.h>
#include <hicn/ctrl.h>
-#include <hicn/config/parse.h>
+#include <hicn/ctrl/parse.h>
#include <hicn/ctrl/route.h>
#include <hicn/util/sstrncpy.h>
}
@@ -27,7 +27,7 @@ class CtrlTest : public ::testing::Test {
protected:
CtrlTest() {
log_conf.log_level = LOG_INFO;
- s_ = hc_sock_create_forwarder(HICNLIGHT_NG);
+ s_ = hc_sock_create_forwarder(FORWARDER_TYPE_HICNLIGHT);
}
virtual ~CtrlTest() { hc_sock_free(s_); }
@@ -40,7 +40,7 @@ class CtrlTest : public ::testing::Test {
* Here we test the serialization of the commands i.e. from command
* to message sent to the forwarder.
*/
-
+#if 0
TEST_F(CtrlTest, AddValidListener) {
std::string cmd = "add listener udp udp0 10.0.0.1 9695 eth0";
ASSERT_EQ(parse(cmd.c_str(), &command_), 0);
@@ -81,7 +81,7 @@ TEST_F(CtrlTest, AddListenerInvalidLocalAddress) {
hc_result_t *result = hc_listener_create_conf(s_, &command_.object.listener);
bool success = hc_result_get_success(s_, result);
- EXPECT_FALSE(success);
+ EXPECT_EQ(success, false);
}
TEST_F(CtrlTest, AddListenerEmptyLocalAddress) {
@@ -193,4 +193,5 @@ TEST_F(CtrlTest, RouteNameOrID) {
route.face_id = 1;
snprintf(route.name, SYMBOLIC_NAME_LEN, "%s", "1test");
EXPECT_EQ(hc_route_validate(&route), -1);
-} \ No newline at end of file
+}
+#endif
diff --git a/hicn-light/src/hicn/test/test-fib.cc b/hicn-light/src/hicn/test/test-fib.cc
new file mode 100644
index 000000000..5db47415f
--- /dev/null
+++ b/hicn-light/src/hicn/test/test-fib.cc
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2021-2022 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/util/ip_address.h>
+#include <hicn/config/configuration.h>
+#include <hicn/core/forwarder.h>
+#include <hicn/core/fib.h>
+}
+
+/*
+ * TODO
+ * - test max_size
+ */
+
+#define DEFAULT_SIZE 10
+#define ARRAY_SIZE(a) ((sizeof(a) / sizeof(*(a))))
+
+class FibTest : public ::testing::Test {
+ protected:
+ FibTest() { fib = fib_create(NULL); }
+ virtual ~FibTest() { fib_free(fib); }
+
+ configuration_t *configuration;
+ forwarder_t *forwarder;
+ fib_t *fib;
+};
+
+void _fib_add_prefix(fib_t *fib, const hicn_prefix_t *prefix) {
+ fib_entry_t *entry =
+ fib_entry_create(prefix, STRATEGY_TYPE_UNDEFINED, NULL, NULL);
+ fib_add(fib, entry);
+}
+
+static const hicn_prefix_t p0010 = (hicn_prefix_t){
+ .name = {.v6 = {.as_u64 = {0x1122334455667788, 0x9900aabbccddeeff}}},
+ .len = 4};
+
+/* TEST: Fib allocation and initialization */
+TEST_F(FibTest, FibAddOne) {
+ /* Empty fib should be valid */
+
+ const hicn_prefix_t *empty_prefix_array[] = {};
+ bool empty_used_array[] = {};
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, empty_prefix_array, empty_used_array));
+
+ const hicn_prefix_t *prefix_array[] = {&p0010};
+ bool used_array[] = {true};
+
+ for (unsigned i = 0; i < ARRAY_SIZE(prefix_array); i++) {
+ if (!used_array[i]) continue;
+ _fib_add_prefix(fib, prefix_array[i]);
+ }
+
+ fib_dump(fib);
+
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array));
+
+ /* Check that free indices and bitmaps are correctly updated */
+}
diff --git a/hicn-light/src/hicn/test/test-interest_manifest.cc b/hicn-light/src/hicn/test/test-interest_manifest.cc
deleted file mode 100644
index 6408a3f2a..000000000
--- a/hicn-light/src/hicn/test/test-interest_manifest.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2021 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>
-
-extern "C" {
-#include <hicn/core/interest_manifest.h>
-}
-
-static constexpr size_t WORD_SIZE = 32;
-
-class InterestManifestTest : public ::testing::Test {
- protected:
- InterestManifestTest() {}
- virtual ~InterestManifestTest() {}
-};
-
-TEST_F(InterestManifestTest, OneWordBitmapUpdate) {
- u32 initial_bitmap[1];
- u32 curr_bitmap[1] = {0};
- initial_bitmap[0] = 0x00000b07; // 000000000000000000000101100000111
-
- // Consume first 4 'one' bits (i.e. suffixes), reaching position 9
- int pos = 0, max_suffixes = 4;
- pos = interest_manifest_update_bitmap(initial_bitmap, curr_bitmap, pos,
- WORD_SIZE, max_suffixes);
- EXPECT_EQ(pos, 9);
- EXPECT_EQ(curr_bitmap[0], 0x00000107);
-
- // Consume the remaining 2 'one' bits, reaching end of bitmap
- u32 curr_bitmap2[1] = {0};
- pos = interest_manifest_update_bitmap(initial_bitmap, curr_bitmap2, pos,
- WORD_SIZE, max_suffixes);
- EXPECT_EQ(pos, WORD_SIZE);
- EXPECT_EQ(curr_bitmap2[0], 0x00000a00);
-
- // Consume all suffixes at once
- u32 curr_bitmap3[1] = {0};
- max_suffixes = 16;
- pos = interest_manifest_update_bitmap(initial_bitmap, curr_bitmap3, 0,
- WORD_SIZE, max_suffixes);
- EXPECT_EQ(pos, WORD_SIZE);
- EXPECT_EQ(curr_bitmap3[0], initial_bitmap[0]);
-}
-
-TEST_F(InterestManifestTest, TwoWordBitmapUpdate) {
- u32 initial_bitmap[2];
- initial_bitmap[0] = 0x00000b07;
- initial_bitmap[1] = 0x00000b07;
- // -> 100000000000000000000101100000111000000000000000000000101100000111
-
- int expected_pos[] = {34, 64};
- u32 expected_bitmap[][2] = {{0x00000b07, 0x00000003}, {0x0, 0x00000b04}};
-
- // Loop to consume all suffixes
- int pos = 0, max_suffixes = 8, i = 0, len = WORD_SIZE * 2;
- while (pos != len) {
- u32 curr_bitmap[2] = {0};
- pos = interest_manifest_update_bitmap(initial_bitmap, curr_bitmap, pos, len,
- max_suffixes);
-
- EXPECT_EQ(pos, expected_pos[i]);
- EXPECT_EQ(curr_bitmap[0], expected_bitmap[i][0]);
- EXPECT_EQ(curr_bitmap[1], expected_bitmap[i][1]);
- i++;
- }
-} \ No newline at end of file
diff --git a/hicn-light/src/hicn/test/test-khash.cc b/hicn-light/src/hicn/test/test-khash.cc
deleted file mode 100644
index f437f8858..000000000
--- a/hicn-light/src/hicn/test/test-khash.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2021 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" {
-#include <hicn/util/khash.h>
-}
-
-KHASH_MAP_INIT_INT(int, unsigned char)
-
-typedef struct {
- unsigned key;
- unsigned char val;
-} int_unpack_t;
-
-typedef struct {
- unsigned key;
- unsigned char val;
-} __attribute__((__packed__)) int_packed_t;
-
-#define hash_eq(a, b) ((a).key == (b).key)
-#define hash_func(a) ((a).key)
-
-KHASH_INIT(iun, int_unpack_t, char, 0, hash_func, hash_eq)
-KHASH_INIT(ipk, int_packed_t, char, 0, hash_func, hash_eq)
-
-class KHashTest : public ::testing::Test {
- protected:
- KHashTest() {}
-
- virtual ~KHashTest() {
- // You can do clean-up work that doesn't throw exceptions here.
- }
-
- // If the constructor and destructor are not enough for setting up
- // and cleaning up each test, you can define the following methods:
-
- virtual void SetUp() { khash = kh_init(int); }
-
- virtual void TearDown() { kh_destroy(int, khash); }
- khash_t(int) * khash;
-};
-
-TEST_F(KHashTest, KhashIntSize) {
- int ret;
- int k;
- int size = kh_size(khash);
-
- EXPECT_EQ(size, 0);
- k = kh_put(int, khash, 10, &ret);
- if (ret == 1) {
- kh_val(khash, k) = 10;
- }
- size = kh_size(khash);
- EXPECT_EQ(size, 1);
-}
-
-TEST_F(KHashTest, KhashIntPut) {
- int ret;
- int k;
- k = kh_put(int, khash, 10, &ret);
- if (ret == 1) {
- kh_val(khash, k) = 10;
- }
- int size = kh_size(khash);
- EXPECT_EQ(size, 1);
- k = kh_put(int, khash, 20, &ret);
- if (ret == 1) {
- kh_val(khash, k) = 20;
- }
- size = kh_size(khash);
- EXPECT_EQ(size, 2);
-}
-
-TEST_F(KHashTest, KhashCheckValue) {
- int ret;
- int k;
- k = kh_put(int, khash, 10, &ret);
- if (ret == 1) {
- kh_val(khash, k) = 100;
- }
- k = kh_put(int, khash, 20, &ret);
- if (ret == 1) {
- kh_val(khash, k) = 200;
- }
-
- k = kh_put(int, khash, 10, &ret);
- int val = -1;
- if (!ret) val = kh_val(khash, k);
- EXPECT_EQ(val, 100);
-
- k = kh_put(int, khash, 20, &ret);
- val = -1;
- if (!ret) val = kh_val(khash, k);
- EXPECT_EQ(val, 200);
-}
-
-// Check that there are no collisions in case of same key hash
-typedef struct {
- int x;
-} Key;
-#define hash_key(key) 1 // Hash is always 1 to simulate collisions
-#define key_hash_eq(a, b) (a->x == b->x) // Function used in case of collisions
-KHASH_INIT(test_map, const Key *, unsigned, 1, hash_key, key_hash_eq);
-
-TEST_F(KHashTest, Collisions) {
- int ret;
- khiter_t k;
-
- kh_test_map_t *map = kh_init(test_map);
- Key key1 = {.x = 10};
- Key key2 = {.x = 11};
-
- k = kh_put_test_map(map, &key1, &ret);
- EXPECT_EQ(ret, 1);
- kh_val(map, k) = 15;
-
- k = kh_put_test_map(map, &key2, &ret);
- EXPECT_EQ(ret, 1);
- kh_val(map, k) = 27;
-
- k = kh_get_test_map(map, &key1);
- ASSERT_NE(k, kh_end(map));
- unsigned val = kh_val(map, k);
- EXPECT_EQ(val, 15u);
-
- k = kh_get_test_map(map, &key2);
- ASSERT_NE(k, kh_end(map));
- val = kh_val(map, k);
- EXPECT_EQ(val, 27u);
-
- kh_destroy_test_map(map);
-}
diff --git a/hicn-light/src/hicn/test/test-listener_table.cc b/hicn-light/src/hicn/test/test-listener_table.cc
index b2ed0c276..f4af02ee1 100644
--- a/hicn-light/src/hicn/test/test-listener_table.cc
+++ b/hicn-light/src/hicn/test/test-listener_table.cc
@@ -27,6 +27,7 @@
extern "C" {
#define WITH_TESTS
#include <hicn/core/listener_table.h>
+#include <hicn/util/log.h>
}
#define LISTENER_NAME "listener_name_test"
@@ -217,7 +218,6 @@ TEST_F(ListenerTableTest, Iterate) {
listener_2->key = key_2;
// Iterate over the listener table and count the listeners
- listener_t *l;
int count = 0;
listener_table_foreach(listener_table_, l, { count++; });
EXPECT_EQ(count, 2);
diff --git a/hicn-light/src/hicn/test/test-local_prefixes.cc b/hicn-light/src/hicn/test/test-local_prefixes.cc
index 80eb46501..52b1c746e 100644
--- a/hicn-light/src/hicn/test/test-local_prefixes.cc
+++ b/hicn-light/src/hicn/test/test-local_prefixes.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 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:
@@ -28,7 +28,6 @@ extern "C" {
#define WITH_TESTS
#include <hicn/strategies/local_prefixes.h>
#include <hicn/core/strategy.h>
-#include <hicn/core/name.h>
}
const char *name_str1 = "b001::0";
@@ -51,53 +50,65 @@ class LocalPrefixesTest : public ::testing::Test {
};
TEST_F(LocalPrefixesTest, LocalPrefixesAddName) {
+ int rc;
local_prefixes_t *lp = create_local_prefixes();
EXPECT_FALSE(lp == nullptr);
- ip_address_t result;
- inet_pton(AF_INET6, name_str1, (struct in6_addr *)&result);
- Name name1;
- name_CreateFromAddress(&name1, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str2, (struct in6_addr *)&result);
- Name name2;
- name_CreateFromAddress(&name2, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str3, (struct in6_addr *)&result);
- Name name3;
- name_CreateFromAddress(&name3, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str4, (struct in6_addr *)&result);
- Name name4;
- name_CreateFromAddress(&name4, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str5, (struct in6_addr *)&result);
- Name name5;
- name_CreateFromAddress(&name5, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str6, (struct in6_addr *)&result);
- Name name6;
- name_CreateFromAddress(&name6, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str7, (struct in6_addr *)&result);
- Name name7;
- name_CreateFromAddress(&name7, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str8, (struct in6_addr *)&result);
- Name name8;
- name_CreateFromAddress(&name8, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str9, (struct in6_addr *)&result);
- Name name9;
- name_CreateFromAddress(&name9, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str10, (struct in6_addr *)&result);
- Name name10;
- name_CreateFromAddress(&name10, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str11, (struct in6_addr *)&result);
- Name name11;
- name_CreateFromAddress(&name11, AF_INET6, result, 128);
+ hicn_ip_address_t result = IP_ADDRESS_EMPTY;
+ hicn_ip_address_pton(name_str1, &result);
+ hicn_prefix_t name1;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name1);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str2, &result);
+ hicn_prefix_t name2;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name2);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str3, &result);
+ hicn_prefix_t name3;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name3);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str4, &result);
+ hicn_prefix_t name4;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name4);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str5, &result);
+ hicn_prefix_t name5;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name5);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str6, &result);
+ hicn_prefix_t name6;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name6);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str7, &result);
+ hicn_prefix_t name7;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name7);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str8, &result);
+ hicn_prefix_t name8;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name8);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str9, &result);
+ hicn_prefix_t name9;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name9);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str10, &result);
+ hicn_prefix_t name10;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name10);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str11, &result);
+ hicn_prefix_t name11;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name11);
+ EXPECT_EQ(rc, 0);
local_prefixes_add_prefix(lp, &name1);
EXPECT_EQ(local_prefixes_get_len(lp), (unsigned)1);
@@ -142,29 +153,34 @@ TEST_F(LocalPrefixesTest, LocalPrefixesAddName) {
}
TEST_F(LocalPrefixesTest, LocalPrefixesAddPrefixes) {
+ int rc;
local_prefixes_t *lp = create_local_prefixes();
EXPECT_FALSE(lp == nullptr);
- ip_address_t result;
+ hicn_ip_address_t result;
local_prefixes_t *lp1 = create_local_prefixes();
EXPECT_FALSE(lp1 == nullptr);
- inet_pton(AF_INET6, name_str1, (struct in6_addr *)&result);
- Name name1;
- name_CreateFromAddress(&name1, AF_INET6, result, 128);
+ hicn_ip_address_pton(name_str1, &result);
+ hicn_prefix_t name1;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name1);
+ EXPECT_EQ(rc, 0);
- inet_pton(AF_INET6, name_str2, (struct in6_addr *)&result);
- Name name2;
- name_CreateFromAddress(&name2, AF_INET6, result, 128);
+ hicn_ip_address_pton(name_str2, &result);
+ hicn_prefix_t name2;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name2);
+ EXPECT_EQ(rc, 0);
- inet_pton(AF_INET6, name_str3, (struct in6_addr *)&result);
- Name name3;
- name_CreateFromAddress(&name3, AF_INET6, result, 128);
+ hicn_ip_address_pton(name_str3, &result);
+ hicn_prefix_t name3;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name3);
+ EXPECT_EQ(rc, 0);
- inet_pton(AF_INET6, name_str4, (struct in6_addr *)&result);
- Name name4;
- name_CreateFromAddress(&name4, AF_INET6, result, 128);
+ hicn_ip_address_pton(name_str4, &result);
+ hicn_prefix_t name4;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name4);
+ EXPECT_EQ(rc, 0);
local_prefixes_add_prefix(lp1, &name1);
local_prefixes_add_prefix(lp1, &name2);
@@ -182,33 +198,40 @@ TEST_F(LocalPrefixesTest, LocalPrefixesAddPrefixes) {
local_prefixes_t *lp2 = create_local_prefixes();
EXPECT_FALSE(lp2 == nullptr);
- inet_pton(AF_INET6, name_str5, (struct in6_addr *)&result);
- Name name5;
- name_CreateFromAddress(&name5, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str6, (struct in6_addr *)&result);
- Name name6;
- name_CreateFromAddress(&name6, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str7, (struct in6_addr *)&result);
- Name name7;
- name_CreateFromAddress(&name7, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str8, (struct in6_addr *)&result);
- Name name8;
- name_CreateFromAddress(&name8, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str9, (struct in6_addr *)&result);
- Name name9;
- name_CreateFromAddress(&name9, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str10, (struct in6_addr *)&result);
- Name name10;
- name_CreateFromAddress(&name10, AF_INET6, result, 128);
-
- inet_pton(AF_INET6, name_str11, (struct in6_addr *)&result);
- Name name11;
- name_CreateFromAddress(&name11, AF_INET6, result, 128);
+ hicn_ip_address_pton(name_str5, &result);
+ hicn_prefix_t name5;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name5);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str6, &result);
+ hicn_prefix_t name6;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name6);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str7, &result);
+ hicn_prefix_t name7;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name7);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str8, &result);
+ hicn_prefix_t name8;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name8);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str9, &result);
+ hicn_prefix_t name9;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name9);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str10, &result);
+ hicn_prefix_t name10;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name10);
+ EXPECT_EQ(rc, 0);
+
+ hicn_ip_address_pton(name_str11, &result);
+ hicn_prefix_t name11;
+ rc = hicn_prefix_create_from_ip_address_len(&result, 128, &name11);
+ EXPECT_EQ(rc, 0);
local_prefixes_add_prefix(lp2, &name5);
local_prefixes_add_prefix(lp2, &name6);
diff --git a/hicn-light/src/hicn/test/test-msgbuf_pool.cc b/hicn-light/src/hicn/test/test-msgbuf_pool.cc
index e9c8e6424..0a78a7a5d 100644
--- a/hicn-light/src/hicn/test/test-msgbuf_pool.cc
+++ b/hicn-light/src/hicn/test/test-msgbuf_pool.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 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:
@@ -100,7 +100,7 @@ TEST_F(MsgbufPoolTest, AcquireMsgbuf) {
// Get msgbuf from msgbuf_pool
off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
- msgbuf->type = MSGBUF_TYPE_COMMAND;
+ msgbuf_set_type(msgbuf, HICN_PACKET_TYPE_COMMAND);
EXPECT_NE(msgbuf, nullptr);
EXPECT_NE(msgbuf_id_is_valid((unsigned long)msgbuf_id), 0);
@@ -119,7 +119,7 @@ TEST_F(MsgbufPoolTest, ReleaseMsgbuf) {
// Get msgbuf from msgbuf_pool
off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
- msgbuf->type = MSGBUF_TYPE_COMMAND;
+ msgbuf_set_type(msgbuf, HICN_PACKET_TYPE_COMMAND);
EXPECT_NE(msgbuf, nullptr);
EXPECT_NE(msgbuf_id_is_valid((unsigned long)msgbuf_id), 0);
@@ -137,7 +137,7 @@ TEST_F(MsgbufPoolTest, ReleaseNotAcquiredMsgbuf) {
// Get valid msgbuf from msgbuf_pool
off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
- msgbuf->type = MSGBUF_TYPE_COMMAND;
+ msgbuf_set_type(msgbuf, HICN_PACKET_TYPE_COMMAND);
EXPECT_NE(msgbuf, nullptr);
EXPECT_NE(msgbuf_id_is_valid((unsigned long)msgbuf_id), 0);
@@ -157,7 +157,7 @@ TEST_F(MsgbufPoolTest, MultipleAcquireAndReleaseMsgbuf) {
// Get msgbuf from msgbuf_pool
off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
- msgbuf->type = MSGBUF_TYPE_COMMAND;
+ msgbuf_set_type(msgbuf, HICN_PACKET_TYPE_COMMAND);
EXPECT_NE(msgbuf, nullptr);
EXPECT_NE(msgbuf_id_is_valid((unsigned long)msgbuf_id), 0);
@@ -177,7 +177,7 @@ TEST_F(MsgbufPoolTest, MultipleAcquireAndReleaseMsgbuf) {
TEST_F(MsgbufPoolTest, CloneMsgbuf) {
msgbuf_t *msgbuf = NULL;
off_t msgbuf_id = msgbuf_pool_get(msgbuf_pool, &msgbuf);
- msgbuf->type = MSGBUF_TYPE_COMMAND;
+ msgbuf_set_type(msgbuf, HICN_PACKET_TYPE_COMMAND);
EXPECT_NE(msgbuf, nullptr);
EXPECT_NE(msgbuf_id_is_valid((unsigned long)msgbuf_id), 0);
diff --git a/hicn-light/src/hicn/test/test-packet_cache.cc b/hicn-light/src/hicn/test/test-packet_cache.cc
index 0b4b214f0..76fdb4516 100644
--- a/hicn-light/src/hicn/test/test-packet_cache.cc
+++ b/hicn-light/src/hicn/test/test-packet_cache.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 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:
@@ -31,8 +31,6 @@ static constexpr unsigned MSGBUF_ID = 0;
static constexpr unsigned MSGBUF_ID_2 = 1;
static constexpr unsigned MSGBUF_ID_3 = 2;
static constexpr unsigned FIVE_SECONDS = 5000;
-static constexpr unsigned IPV4_LEN = 32;
-static constexpr unsigned IPV6_LEN = 128;
static constexpr int N_OPS = 50000;
@@ -40,39 +38,50 @@ class PacketCacheTest : public ::testing::Test {
protected:
PacketCacheTest() {
pkt_cache = pkt_cache_create(CS_SIZE);
- name = (Name *)malloc(sizeof(Name));
- name_CreateFromAddress(name, AF_INET, IPV4_ANY, IPV4_LEN);
+ int rc = hicn_name_create_from_ip_address(IPV4_ANY, 0, &name);
+ EXPECT_EQ(rc, 0);
msgbuf_pool = msgbuf_pool_create();
- msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, name);
+ msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, &name);
}
virtual ~PacketCacheTest() {
- free(name);
msgbuf_pool_free(msgbuf_pool);
pkt_cache_free(pkt_cache);
}
msgbuf_t *msgbuf_create(msgbuf_pool_t *msgbuf_pool, unsigned conn_id,
- Name *name,
+ hicn_name_t *name,
std::optional<Ticks> lifetime = FIVE_SECONDS) {
msgbuf_t *msgbuf;
msgbuf_pool_get(msgbuf_pool, &msgbuf);
msgbuf->connection_id = conn_id;
- name_Copy(name, msgbuf_get_name(msgbuf));
- hicn_packet_init_header(HF_INET6_TCP,
- (hicn_header_t *)msgbuf_get_packet(msgbuf));
+ msgbuf_set_name(msgbuf, name);
+
+ hicn_packet_set_format(msgbuf_get_pkbuf(msgbuf),
+ HICN_PACKET_FORMAT_IPV6_TCP);
+ hicn_packet_set_type(msgbuf_get_pkbuf(msgbuf), HICN_PACKET_TYPE_INTEREST);
+
+ hicn_packet_buffer_t *pkbuf = msgbuf_get_pkbuf(msgbuf);
+ hicn_packet_set_buffer(pkbuf, msgbuf->packet, MTU, 0);
+
+ int rc = hicn_packet_init_header(msgbuf_get_pkbuf(msgbuf), 0);
+ EXPECT_EQ(rc, 0);
+
+ // Same as 'msgbuf_set_data_expiry_time',
+ // it would write in the same field
msgbuf_set_interest_lifetime(msgbuf, *lifetime);
return msgbuf;
}
- Name get_name_from_prefix(const char *prefix_str) {
- ip_address_t prefix;
+ hicn_name_t get_name_from_prefix(const char *prefix_str) {
+ hicn_ip_address_t prefix;
inet_pton(AF_INET6, prefix_str, (struct in6_addr *)&prefix);
- Name name;
- name_CreateFromAddress(&name, AF_INET6, prefix, IPV6_LEN);
+ hicn_name_t name;
+ int rc = hicn_name_create_from_ip_address(prefix, 0, &name);
+ EXPECT_EQ(rc, 0);
return name;
}
@@ -80,39 +89,33 @@ class PacketCacheTest : public ::testing::Test {
pkt_cache_t *pkt_cache;
pkt_cache_entry_t *entry = nullptr;
msgbuf_pool_t *msgbuf_pool;
- Name *name;
+ hicn_name_t name;
msgbuf_t *msgbuf;
};
TEST_F(PacketCacheTest, LowLevelOperations) {
- int rc;
kh_pkt_cache_prefix_t *prefix_to_suffixes = kh_init_pkt_cache_prefix();
- NameBitvector *prefix = name_GetContentName(name);
+ const hicn_name_prefix_t *prefix = hicn_name_get_prefix(&name);
_add_suffix(prefix_to_suffixes, prefix, 1, 11);
_add_suffix(prefix_to_suffixes, prefix, 2, 22);
- unsigned id = _get_suffix(prefix_to_suffixes, prefix, 1, &rc);
- EXPECT_EQ(rc, KH_FOUND);
- EXPECT_EQ(id, 11);
+ unsigned id = _get_suffix(prefix_to_suffixes, prefix, 1);
+ EXPECT_EQ(id, 11UL);
- id = _get_suffix(prefix_to_suffixes, prefix, 2, &rc);
- EXPECT_EQ(rc, KH_FOUND);
- EXPECT_EQ(id, 22);
+ id = _get_suffix(prefix_to_suffixes, prefix, 2);
+ EXPECT_EQ(id, 22UL);
- id = _get_suffix(prefix_to_suffixes, prefix, 5, &rc);
- EXPECT_EQ(rc, KH_NOT_FOUND);
- EXPECT_EQ(id, -1);
+ id = _get_suffix(prefix_to_suffixes, prefix, 5);
+ EXPECT_EQ(id, HICN_INVALID_SUFFIX);
_add_suffix(prefix_to_suffixes, prefix, 5, 55);
- id = _get_suffix(prefix_to_suffixes, prefix, 5, &rc);
- EXPECT_EQ(rc, KH_FOUND);
- EXPECT_EQ(id, 55);
+ id = _get_suffix(prefix_to_suffixes, prefix, 5);
+ EXPECT_EQ(id, 55UL);
_remove_suffix(prefix_to_suffixes, prefix, 2);
_add_suffix(prefix_to_suffixes, prefix, 2, 222);
- id = _get_suffix(prefix_to_suffixes, prefix, 2, &rc);
- EXPECT_EQ(rc, KH_FOUND);
- EXPECT_EQ(id, 222);
+ id = _get_suffix(prefix_to_suffixes, prefix, 2);
+ EXPECT_EQ(id, 222UL);
_prefix_map_free(prefix_to_suffixes);
}
@@ -133,15 +136,17 @@ TEST_F(PacketCacheTest, CreatePacketCache) {
TEST_F(PacketCacheTest, AddPacketCacheEntry) {
// Add entry to the packet cache
- entry = pkt_cache_allocate(pkt_cache, name);
+ entry = pkt_cache_allocate(pkt_cache);
EXPECT_NE(entry, nullptr);
+ entry->name = name;
ASSERT_EQ(pkt_cache_get_size(pkt_cache), 1u);
+ pkt_cache_add_to_index(pkt_cache, entry);
// Get entry by name
pkt_cache_lookup_t lookup_result;
off_t entry_id;
- pkt_cache_entry_t *entry = pkt_cache_lookup(pkt_cache, name, msgbuf_pool,
- &lookup_result, &entry_id, true);
+ pkt_cache_lookup(pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id,
+ true);
EXPECT_NE(lookup_result, PKT_CACHE_LU_NONE);
}
@@ -165,7 +170,7 @@ TEST_F(PacketCacheTest, GetPIT) {
TEST_F(PacketCacheTest, LookupEmpty) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
- pkt_cache_entry_t *entry = pkt_cache_lookup(pkt_cache, name, msgbuf_pool,
+ pkt_cache_entry_t *entry = pkt_cache_lookup(pkt_cache, &name, msgbuf_pool,
&lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_NONE);
@@ -174,15 +179,17 @@ TEST_F(PacketCacheTest, LookupEmpty) {
TEST_F(PacketCacheTest, AddEntryAndLookup) {
// Add entry to the packet cache
- entry = pkt_cache_allocate(pkt_cache, name);
+ entry = pkt_cache_allocate(pkt_cache);
+ entry->name = name;
entry->entry_type = PKT_CACHE_PIT_TYPE;
ASSERT_NE(entry, nullptr);
+ pkt_cache_add_to_index(pkt_cache, entry);
// Perform lookup
pkt_cache_lookup_t lookup_result;
off_t entry_id;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_TRUE(lookup_result == PKT_CACHE_LU_INTEREST_NOT_EXPIRED ||
lookup_result == PKT_CACHE_LU_INTEREST_EXPIRED);
@@ -192,7 +199,7 @@ TEST_F(PacketCacheTest, AddEntryAndLookup) {
TEST_F(PacketCacheTest, AddToPIT) {
// Check if entry properly created
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
ASSERT_NE(entry, nullptr);
EXPECT_EQ(entry->entry_type, PKT_CACHE_PIT_TYPE);
EXPECT_TRUE(pit_entry_ingress_contains(&entry->u.pit_entry, CONN_ID));
@@ -203,7 +210,7 @@ TEST_F(PacketCacheTest, AddToPIT) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_INTEREST_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
@@ -229,14 +236,14 @@ TEST_F(PacketCacheTest, AddToCS) {
// Check if hashtable correctly updated
pkt_cache_lookup_t lookup_result;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_DATA_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
TEST_F(PacketCacheTest, PitToCS) {
// Prepare PIT entry
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
off_t entry_id = pkt_cache_get_entry_id(pkt_cache, entry);
ASSERT_EQ(pkt_cache_get_pit_size(pkt_cache), 1u);
ASSERT_EQ(pkt_cache_get_cs_size(pkt_cache), 0u);
@@ -261,7 +268,7 @@ TEST_F(PacketCacheTest, PitToCS) {
// Check if hashtable correctly updated
pkt_cache_lookup_t lookup_result;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_DATA_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
@@ -286,18 +293,19 @@ TEST_F(PacketCacheTest, CsToPIT) {
// Check if hashtable correctly updated
pkt_cache_lookup_t lookup_result;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_INTEREST_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
TEST_F(PacketCacheTest, UpdateInPIT) {
// Prepare PIT entry
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
off_t entry_id = pkt_cache_get_entry_id(pkt_cache, entry);
- Name new_name;
- name_CreateFromAddress(&new_name, AF_INET, IPV4_LOOPBACK, IPV4_LEN);
+ hicn_name_t new_name;
+ int rc = hicn_name_create_from_ip_address(IPV4_LOOPBACK, 0, &new_name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *new_msgbuf = msgbuf_create(msgbuf_pool, CONN_ID_2, &new_name);
// Check if entry properly updated
@@ -311,7 +319,7 @@ TEST_F(PacketCacheTest, UpdateInPIT) {
// Check if hashtable correctly updated
pkt_cache_lookup_t lookup_result;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_INTEREST_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
@@ -322,8 +330,9 @@ TEST_F(PacketCacheTest, UpdateInCS) {
pkt_cache_add_to_cs(pkt_cache, msgbuf_pool, msgbuf, MSGBUF_ID);
off_t entry_id = pkt_cache_get_entry_id(pkt_cache, entry);
- Name new_name;
- name_CreateFromAddress(&new_name, AF_INET, IPV4_LOOPBACK, IPV4_LEN);
+ hicn_name_t new_name;
+ int rc = hicn_name_create_from_ip_address(IPV4_LOOPBACK, 0, &new_name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *new_msgbuf = msgbuf_create(msgbuf_pool, CONN_ID_2, &new_name);
// Check if entry properly updated
@@ -338,18 +347,18 @@ TEST_F(PacketCacheTest, UpdateInCS) {
// Check if hashtable correctly updated
pkt_cache_lookup_t lookup_result;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_DATA_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
TEST_F(PacketCacheTest, RemoveFromPIT) {
// Prepare PIT entry
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
ASSERT_EQ(pkt_cache_get_pit_size(pkt_cache), 1u);
ASSERT_EQ(pkt_cache_get_cs_size(pkt_cache), 0u);
- pkt_cache_pit_remove_entry(pkt_cache, entry, name);
+ pkt_cache_pit_remove_entry(pkt_cache, entry);
ASSERT_EQ(pkt_cache_get_pit_size(pkt_cache), 0u);
ASSERT_EQ(pkt_cache_get_cs_size(pkt_cache), 0u);
@@ -357,7 +366,7 @@ TEST_F(PacketCacheTest, RemoveFromPIT) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_NONE);
EXPECT_EQ(lu_entry, nullptr);
}
@@ -383,15 +392,16 @@ TEST_F(PacketCacheTest, RemoveFromCS) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_NONE);
EXPECT_EQ(lu_entry, nullptr);
}
TEST_F(PacketCacheTest, AddTwoEntriesToCS) {
// Prepare another msgbuf
- Name new_name;
- name_CreateFromAddress(&new_name, AF_INET, IPV4_LOOPBACK, IPV4_LEN);
+ hicn_name_t new_name;
+ int rc = hicn_name_create_from_ip_address(IPV4_LOOPBACK, 0, &new_name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *new_msgbuf = msgbuf_create(msgbuf_pool, CONN_ID_2, &new_name);
pkt_cache_entry_t *entry_1 =
@@ -412,16 +422,17 @@ TEST_F(PacketCacheTest, AddTwoEntriesToCS) {
TEST_F(PacketCacheTest, AggregateInPIT) {
// Prepare another msgbuf
- Name new_name;
- name_CreateFromAddress(&new_name, AF_INET, IPV4_LOOPBACK, IPV4_LEN);
+ hicn_name_t new_name;
+ int rc = hicn_name_create_from_ip_address(IPV4_LOOPBACK, 0, &new_name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *new_msgbuf = msgbuf_create(msgbuf_pool, CONN_ID_2, &new_name);
// Check if entry properly created (use sleep to get an updated ts)
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
Ticks old_lifetime = entry->expire_ts;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
bool is_aggregated =
- pkt_cache_try_aggregate_in_pit(pkt_cache, entry, new_msgbuf, name);
+ pkt_cache_try_aggregate_in_pit(pkt_cache, entry, new_msgbuf, &name);
Ticks new_lifetime = entry->expire_ts;
ASSERT_NE(entry, nullptr);
@@ -433,23 +444,24 @@ TEST_F(PacketCacheTest, AggregateInPIT) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_INTEREST_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
TEST_F(PacketCacheTest, RetransmissionInPIT) {
// Prepare another msgbuf (using same connection ID)
- Name new_name;
- name_CreateFromAddress(&new_name, AF_INET, IPV4_LOOPBACK, IPV4_LEN);
+ hicn_name_t new_name;
+ int rc = hicn_name_create_from_ip_address(IPV4_LOOPBACK, 0, &new_name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *new_msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, &new_name);
// Check if entry properly created (use sleep to get an updated ts)
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
Ticks old_lifetime = entry->expire_ts;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
bool is_aggregated =
- pkt_cache_try_aggregate_in_pit(pkt_cache, entry, new_msgbuf, name);
+ pkt_cache_try_aggregate_in_pit(pkt_cache, entry, new_msgbuf, &name);
Ticks new_lifetime = entry->expire_ts;
ASSERT_NE(entry, nullptr);
@@ -461,17 +473,17 @@ TEST_F(PacketCacheTest, RetransmissionInPIT) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
pkt_cache_entry_t *lu_entry = pkt_cache_lookup(
- pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id, true);
+ pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id, true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_INTEREST_NOT_EXPIRED);
EXPECT_EQ(lu_entry, entry);
}
TEST_F(PacketCacheTest, LookupExpiredInterest) {
// Prepare msgbuf with 0 as interest lifetime
- msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, name, 0);
+ msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, &name, 0);
// Add to PIT
- pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, name);
+ pkt_cache_entry_t *entry = pkt_cache_add_to_pit(pkt_cache, msgbuf, &name);
ASSERT_NE(entry, nullptr);
// Wait to make the interest expire
@@ -479,14 +491,14 @@ TEST_F(PacketCacheTest, LookupExpiredInterest) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
- pkt_cache_lookup(pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id,
+ pkt_cache_lookup(pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id,
true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_INTEREST_EXPIRED);
}
TEST_F(PacketCacheTest, LookupExpiredData) {
// Prepare msgbuf with 0 as data expiry time
- msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, name, 0);
+ msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, &name, 0);
// Add to CS
pkt_cache_entry_t *entry =
@@ -498,25 +510,27 @@ TEST_F(PacketCacheTest, LookupExpiredData) {
pkt_cache_lookup_t lookup_result;
off_t entry_id;
- pkt_cache_lookup(pkt_cache, name, msgbuf_pool, &lookup_result, &entry_id,
+ pkt_cache_lookup(pkt_cache, &name, msgbuf_pool, &lookup_result, &entry_id,
true);
EXPECT_EQ(lookup_result, PKT_CACHE_LU_DATA_EXPIRED);
}
TEST_F(PacketCacheTest, GetStaleEntries) {
// Add to CS a msgbuf with immediate expiration (i.e. stale)
- msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, name, 0);
+ msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, CONN_ID, &name, 0);
pkt_cache_add_to_cs(pkt_cache, msgbuf_pool, msgbuf, MSGBUF_ID);
// Add to CS another msgbuf with immediate expiration (i.e. stale)
- Name name_2;
- name_CreateFromAddress(&name_2, AF_INET, IPV4_LOOPBACK, IPV4_LEN);
+ hicn_name_t name_2;
+ int rc = hicn_name_create_from_ip_address(IPV4_LOOPBACK, 0, &name_2);
+ EXPECT_EQ(rc, 0);
msgbuf_t *msgbuf_2 = msgbuf_create(msgbuf_pool, CONN_ID, &name_2, 0);
pkt_cache_add_to_cs(pkt_cache, msgbuf_pool, msgbuf_2, MSGBUF_ID_2);
// Add to CS a msgbuf with 5-seconds expiration (i.e. not stale)
- Name name_3;
- name_CreateFromAddress(&name_3, AF_INET6, IPV6_LOOPBACK, IPV6_LEN);
+ hicn_name_t name_3;
+ rc = hicn_name_create_from_ip_address(IPV6_LOOPBACK, 0, &name_3);
+ EXPECT_EQ(rc, 0);
msgbuf_t *msgbuf_3 =
msgbuf_create(msgbuf_pool, CONN_ID, &name_3, FIVE_SECONDS);
pkt_cache_add_to_cs(pkt_cache, msgbuf_pool, msgbuf_3, MSGBUF_ID_3);
@@ -526,17 +540,19 @@ TEST_F(PacketCacheTest, GetStaleEntries) {
}
TEST_F(PacketCacheTest, GetMultipleStaleEntries) {
- ip_address_t addr;
+ hicn_ip_address_t addr;
char name[30];
const int NUM_STALES = 10;
+ int rc;
// Add to CS multiple msgbufs with immediate expiration (i.e. 0 seconds),
// resulting in stale entries
for (int i = 0; i < NUM_STALES; i++) {
snprintf(name, 30, "b001::%d", i);
inet_pton(AF_INET6, name, (struct in6_addr *)&addr);
- Name name;
- name_CreateFromAddress(&name, AF_INET6, addr, IPV6_LEN);
+ hicn_name_t name;
+ rc = hicn_name_create_from_ip_address(addr, 0, &name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, i, &name, 0);
pkt_cache_add_to_cs(pkt_cache, msgbuf_pool, msgbuf, i);
@@ -547,8 +563,9 @@ TEST_F(PacketCacheTest, GetMultipleStaleEntries) {
for (int i = NUM_STALES; i < 15; i++) {
snprintf(name, 30, "b001::%d", i);
inet_pton(AF_INET6, name, (struct in6_addr *)&addr);
- Name name;
- name_CreateFromAddress(&name, AF_INET6, addr, IPV6_LEN);
+ hicn_name_t name;
+ rc = hicn_name_create_from_ip_address(addr, 0, &name);
+ EXPECT_EQ(rc, 0);
msgbuf_t *msgbuf = msgbuf_create(msgbuf_pool, i, &name, FIVE_SECONDS);
pkt_cache_add_to_cs(pkt_cache, msgbuf_pool, msgbuf, i);
@@ -559,23 +576,22 @@ TEST_F(PacketCacheTest, GetMultipleStaleEntries) {
}
TEST_F(PacketCacheTest, PerformanceDoubleLookup) {
- Name tmp = get_name_from_prefix("b001::0");
+ hicn_name_t tmp = get_name_from_prefix("b001::0");
auto elapsed_time_double = get_execution_time([&]() {
kh_pkt_cache_prefix_t *prefix_to_suffixes = kh_init_pkt_cache_prefix();
// Add to hash table
for (int seq = 0; seq < N_OPS; seq++) {
- name_SetSegment(&tmp, seq);
- _add_suffix(prefix_to_suffixes, name_GetContentName(&tmp),
- name_GetSegment(&tmp), name_GetSegment(&tmp));
+ hicn_name_set_suffix(&tmp, seq);
+ _add_suffix(prefix_to_suffixes, hicn_name_get_prefix(&tmp),
+ hicn_name_get_suffix(&tmp), hicn_name_get_suffix(&tmp));
}
// Read from hash table
- int rc;
for (int seq = 0; seq < N_OPS; seq++) {
- name_SetSegment(&tmp, seq);
- _get_suffix(prefix_to_suffixes, name_GetContentName(&tmp), seq, &rc);
+ hicn_name_set_suffix(&tmp, seq);
+ _get_suffix(prefix_to_suffixes, hicn_name_get_prefix(&tmp), seq);
}
_prefix_map_free(prefix_to_suffixes);
@@ -584,24 +600,24 @@ TEST_F(PacketCacheTest, PerformanceDoubleLookup) {
}
TEST_F(PacketCacheTest, PerformanceCachedLookup) {
- Name tmp = get_name_from_prefix("b001::0");
+ hicn_name_t tmp = get_name_from_prefix("b001::0");
auto elapsed_time_single = get_execution_time([&]() {
kh_pkt_cache_prefix_t *prefix_to_suffixes = kh_init_pkt_cache_prefix();
kh_pkt_cache_suffix_t *suffixes =
- _get_suffixes(prefix_to_suffixes, name_GetContentName(&tmp));
+ _get_suffixes(prefix_to_suffixes, hicn_name_get_prefix(&tmp), true);
// Add to hash table
for (int seq = 0; seq < N_OPS; seq++) {
- name_SetSegment(&tmp, seq);
- __add_suffix(suffixes, name_GetSegment(&tmp), name_GetSegment(&tmp));
+ hicn_name_set_suffix(&tmp, seq);
+ __add_suffix(suffixes, hicn_name_get_suffix(&tmp),
+ hicn_name_get_suffix(&tmp));
}
// Read from hash table
- int rc;
for (int seq = 0; seq < N_OPS; seq++) {
- name_SetSegment(&tmp, seq);
- __get_suffix(suffixes, name_GetSegment(&tmp), &rc);
+ hicn_name_set_suffix(&tmp, seq);
+ __get_suffix(suffixes, hicn_name_get_suffix(&tmp));
}
_prefix_map_free(prefix_to_suffixes);
@@ -610,7 +626,7 @@ TEST_F(PacketCacheTest, PerformanceCachedLookup) {
}
TEST_F(PacketCacheTest, PerformanceCachedLookupRandom) {
- Name tmp = get_name_from_prefix("b001::0");
+ hicn_name_t tmp = get_name_from_prefix("b001::0");
// Prepare random sequence numbers
std::random_device rd;
@@ -622,19 +638,19 @@ TEST_F(PacketCacheTest, PerformanceCachedLookupRandom) {
auto elapsed_time_single_rand = get_execution_time([&]() {
kh_pkt_cache_prefix_t *prefix_to_suffixes = kh_init_pkt_cache_prefix();
kh_pkt_cache_suffix_t *suffixes =
- _get_suffixes(prefix_to_suffixes, name_GetContentName(&tmp));
+ _get_suffixes(prefix_to_suffixes, hicn_name_get_prefix(&tmp), true);
// Add to hash table
for (int seq = 0; seq < N_OPS; seq++) {
- name_SetSegment(&tmp, seqs[seq]);
- __add_suffix(suffixes, name_GetSegment(&tmp), name_GetSegment(&tmp));
+ hicn_name_set_suffix(&tmp, seqs[seq]);
+ __add_suffix(suffixes, hicn_name_get_suffix(&tmp),
+ hicn_name_get_suffix(&tmp));
}
// Read from hash table
- int rc;
for (int seq = 0; seq < N_OPS; seq++) {
- name_SetSegment(&tmp, seqs[seq]);
- __get_suffix(suffixes, name_GetSegment(&tmp), &rc);
+ hicn_name_set_suffix(&tmp, seqs[seq]);
+ __get_suffix(suffixes, hicn_name_get_suffix(&tmp));
}
_prefix_map_free(prefix_to_suffixes);
@@ -643,17 +659,17 @@ TEST_F(PacketCacheTest, PerformanceCachedLookupRandom) {
}
TEST_F(PacketCacheTest, Clear) {
- Name tmp_name1, tmp_name2;
+ hicn_name_t tmp_name1, tmp_name2;
cs_t *cs = pkt_cache_get_cs(pkt_cache);
// Create name and add to msgbuf pool
- name_Copy(name, &tmp_name1);
- name_SetSegment(&tmp_name1, 1);
+ hicn_name_copy(&tmp_name1, &name);
+ hicn_name_set_suffix(&tmp_name1, 1);
msgbuf_t *tmp_msgbuf1 = msgbuf_create(msgbuf_pool, CONN_ID_2, &tmp_name1);
// Create (another) name and add to msgbuf pool
- name_Copy(name, &tmp_name2);
- name_SetSegment(&tmp_name2, 2);
+ hicn_name_copy(&tmp_name2, &name);
+ hicn_name_set_suffix(&tmp_name2, 2);
msgbuf_t *tmp_msgbuf2 = msgbuf_create(msgbuf_pool, CONN_ID_2, &tmp_name2);
// Add to packet cache (2 entries in the CS, 1 in the PIT)
@@ -665,7 +681,7 @@ TEST_F(PacketCacheTest, Clear) {
ASSERT_EQ(pkt_cache_get_size(pkt_cache), 3u);
ASSERT_EQ(pkt_cache_get_pit_size(pkt_cache), 1u);
ASSERT_EQ(pkt_cache_get_cs_size(pkt_cache), 2u);
- ASSERT_EQ(cs->num_entries, 2u);
+ ASSERT_EQ(cs->num_entries, 2);
ASSERT_EQ(cs->stats.lru.countAdds, 2u);
// Clear packet cache (i.e. remove content packets from packet cache):
@@ -677,6 +693,6 @@ TEST_F(PacketCacheTest, Clear) {
ASSERT_EQ(pkt_cache_get_size(pkt_cache), 1u);
ASSERT_EQ(pkt_cache_get_pit_size(pkt_cache), 1u);
ASSERT_EQ(pkt_cache_get_cs_size(pkt_cache), 0u);
- ASSERT_EQ(cs->num_entries, 0u);
+ ASSERT_EQ(cs->num_entries, 0);
ASSERT_EQ(cs->stats.lru.countAdds, 0u);
-} \ No newline at end of file
+}
diff --git a/hicn-light/src/hicn/test/test-parser.cc b/hicn-light/src/hicn/test/test-parser.cc
index 3a8d2cdb2..2e396b97d 100644
--- a/hicn-light/src/hicn/test/test-parser.cc
+++ b/hicn-light/src/hicn/test/test-parser.cc
@@ -17,7 +17,7 @@
extern "C" {
#include <hicn/util/log.h>
-#include <hicn/config/parse.h>
+#include <hicn/ctrl/parse.h>
}
class ParserTest : public ::testing::Test {
@@ -68,4 +68,4 @@ TEST_F(ParserTest, AddListenerInvalidPortString) {
TEST_F(ParserTest, UnknownCommnad) {
std::string cmd = "add face";
ASSERT_EQ(parse(cmd.c_str(), &command_), -1);
-} \ No newline at end of file
+}
diff --git a/hicn-light/src/hicn/test/test-pool.cc b/hicn-light/src/hicn/test/test-pool.cc
deleted file mode 100644
index 8cd891d6a..000000000
--- a/hicn-light/src/hicn/test/test-pool.cc
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 2021 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/util/pool.h>
-}
-
-/*
- * TODO
- * - test max_size
- */
-
-#define DEFAULT_SIZE 10
-
-class PoolTest : public ::testing::Test {
- protected:
- PoolTest() {}
- virtual ~PoolTest() {}
-
- int *pool;
-};
-
-TEST_F(PoolTest, PoolAllocation) {
- int rc;
-
- pool_init(pool, DEFAULT_SIZE, 0);
-
- size_t pool_size = next_pow2(DEFAULT_SIZE);
-
- EXPECT_EQ(pool_get_alloc_size(pool), pool_size);
-
- /* Check that free indices and bitmaps are correctly initialize */
- off_t *fi = pool_get_free_indices(pool);
- EXPECT_EQ(vector_len(fi), pool_size);
- EXPECT_EQ(fi[0], (long)(pool_size - 1));
- EXPECT_EQ(fi[pool_size - 1], 0);
-
- /* The allocated size of the underlying vector should be the next power of two
- */
- EXPECT_EQ(vector_get_alloc_size(fi), pool_size);
-
- bitmap_t *fb = pool_get_free_bitmap(pool);
- EXPECT_TRUE(bitmap_is_set(fb, 0));
- EXPECT_TRUE(bitmap_is_set(fb, pool_size - 2));
- EXPECT_TRUE(bitmap_is_set(fb, pool_size - 1));
- EXPECT_TRUE(bitmap_is_unset(fb, pool_size));
-
- /* Getting elements from the pool should correctly update the free indices
- * and bitmap */
- int *elt;
-
- rc = pool_get(pool, elt);
- EXPECT_GE(rc, 0);
- EXPECT_EQ(vector_len(fi), pool_size - 1);
- EXPECT_TRUE(bitmap_is_unset(fb, 0));
-
- rc = pool_get(pool, elt);
- EXPECT_GE(rc, 0);
- EXPECT_EQ(vector_len(fi), pool_size - 2);
- EXPECT_TRUE(bitmap_is_unset(fb, 1));
-
- for (unsigned i = 0; i < pool_size - 4; i++) {
- rc = pool_get(pool, elt);
- EXPECT_GE(rc, 0);
- }
-
- rc = pool_get(pool, elt);
- EXPECT_GE(rc, 0);
- EXPECT_EQ(vector_len(fi), 1UL);
- EXPECT_TRUE(bitmap_is_unset(fb, pool_size - 2));
-
- rc = pool_get(pool, elt);
- EXPECT_GE(rc, 0);
- EXPECT_EQ(vector_len(fi), 0UL);
- EXPECT_TRUE(bitmap_is_unset(fb, pool_size - 1));
-
- /*
- * Getting elements within the allocated range should not have triggered a
- * resize
- */
- EXPECT_EQ(pool_len(pool), pool_size);
-
- /*
- * Getting elements once the allocated range has been exceeded should
- * trigger a resize
- */
- rc = pool_get(pool, elt);
- EXPECT_GE(rc, 0);
-
- EXPECT_EQ(pool_get_alloc_size(pool), pool_size * 2);
-
- EXPECT_EQ(pool_len(pool), pool_size + 1);
-
- /*
- * Doubling the size, we should have again pool_size elements free, minus 1
- */
- EXPECT_EQ(pool_get_free_indices_size(pool), pool_size - 1);
-
- /*
- * NOTE: this is wrong as there has been a realloc and the old fi
- * pointer is now invalid
- */
- // EXPECT_EQ(vector_len(fi), pool_size - 1);
-
- /* And the bitmap should also be correctly modified */
- fb = pool_get_free_bitmap(pool);
- EXPECT_TRUE(bitmap_is_unset(fb, pool_size));
-
- /* Check that surrounding values are also correct */
- EXPECT_TRUE(bitmap_is_unset(fb, pool_size - 1));
- EXPECT_TRUE(bitmap_is_set(fb, pool_size + 1));
-
- /* Setting elements after should through */
-
- /* Check that free indices and bitmaps are correctly updated */
-
- pool_free(pool);
-}
-
-TEST_F(PoolTest, PoolPut) {
- pool_init(pool, DEFAULT_SIZE, 0);
-
- int *elt;
- pool_get(pool, elt);
- *elt = 10;
- pool_put(pool, elt);
-
- pool_free(pool);
-}
-
-TEST_F(PoolTest, PoolGetForceBitmapRealloc) {
- const int N = 64;
- int *elts[N];
- int *elt = NULL;
- pool_init(pool, N, 0);
-
- for (int i = 0; i < N; i++) pool_get(pool, elts[i]);
- pool_get(pool, elt);
-
- pool_free(pool);
-}
-
-TEST_F(PoolTest, PoolGetAfterReleasing) {
- int *elt1 = NULL, *elt2 = NULL, *tmp = NULL;
- pool_init(pool, DEFAULT_SIZE, 0);
-
- // If two elements are requested...
- off_t id1 = pool_get(pool, elt1);
- pool_get(pool, tmp);
-
- // ...and the first one is released...
- pool_put(pool, elt1);
-
- // ...requesting a new one should return
- // the first one (that was freed)
- off_t id2 = pool_get(pool, elt2);
- EXPECT_EQ(id1, id2);
- EXPECT_EQ(elt1, elt2);
-
- pool_free(pool);
-}
-
-TEST_F(PoolTest, PoolGetMultipleElementsAfterReleasing) {
- const int N = 2;
- int *elts[N];
- pool_init(pool, N, 0);
-
- for (int i = 0; i < N; i++) pool_get(pool, elts[i]);
- for (int i = 0; i < N; i++) pool_put(pool, elts[i]);
- for (int i = 0; i < N; i++) pool_get(pool, elts[i]);
-
- pool_free(pool);
-}
diff --git a/hicn-light/src/hicn/test/test-ring.cc b/hicn-light/src/hicn/test/test-ring.cc
deleted file mode 100644
index ab96d76c0..000000000
--- a/hicn-light/src/hicn/test/test-ring.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2021 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/util/ring.h>
-}
-
-#define DEFAULT_SIZE 10UL
-
-class RingTest : public ::testing::Test {
- protected:
- RingTest() { ring_init(ring, DEFAULT_SIZE); }
- virtual ~RingTest() { ring_free(ring); }
-
- int *ring = NULL;
-};
-
-/* TEST: Ring allocation and initialization */
-TEST_F(RingTest, RingAddOne) {
- int val = -1;
- /* Allocated size should be the next power of two */
- EXPECT_EQ(ring_get_size(ring), 0UL);
- ring_add_value(ring, 1);
- EXPECT_EQ(ring_get_size(ring), 1UL);
- ring_get(ring, 0, &val);
- EXPECT_EQ(val, 1);
- EXPECT_EQ(ring_get_size(ring), 1UL);
- ring_advance(ring, 1);
- EXPECT_EQ(ring_get_size(ring), 0UL);
-}
-
-TEST_F(RingTest, RingAddMany) {
- size_t i = 0;
- int val = -1;
- size_t count = 0;
-
- /* Allocated size should be the next power of two */
- EXPECT_EQ(ring_get_size(ring), 0UL);
- for (unsigned i = 0; i < DEFAULT_SIZE; i++) ring_add_value(ring, i);
- EXPECT_EQ(ring_get_size(ring), DEFAULT_SIZE);
-
- count = 0;
- ring_enumerate_n(ring, i, &val, 1, {
- EXPECT_EQ(val, (int)(i));
- count++;
- });
- EXPECT_EQ(count, 1UL);
-
- count = 0;
- ring_enumerate_n(ring, i, &val, DEFAULT_SIZE, {
- EXPECT_EQ(val, (int)(i));
- count++;
- });
- EXPECT_EQ(count, DEFAULT_SIZE);
-
- count = 0;
- ring_enumerate_n(ring, i, &val, DEFAULT_SIZE + 1, {
- EXPECT_EQ(val, (int)(i));
- count++;
- });
- EXPECT_EQ(count, DEFAULT_SIZE);
-
- // Drop one
- ring_add_value(ring, DEFAULT_SIZE);
- EXPECT_EQ(ring_get_size(ring), DEFAULT_SIZE);
-
- count = 0;
- ring_enumerate_n(ring, i, &val, DEFAULT_SIZE, {
- EXPECT_EQ(val, (int)(i + 1)); // all values shoud be shifted
- count++;
- });
- EXPECT_EQ(count, DEFAULT_SIZE);
-
- ring_advance(ring, DEFAULT_SIZE);
- EXPECT_EQ(ring_get_size(ring), 0UL);
-}
diff --git a/hicn-light/src/hicn/test/test-strategy-replication.cc b/hicn-light/src/hicn/test/test-strategy-replication.cc
index ab7dae1f7..2924173cb 100644
--- a/hicn-light/src/hicn/test/test-strategy-replication.cc
+++ b/hicn-light/src/hicn/test/test-strategy-replication.cc
@@ -152,7 +152,6 @@ TEST_F(StrategyReplicationTest, MultipleNexthops) {
/* Retrieve candidate */
- unsigned nexthop;
unsigned tests = 0;
nexthops_foreach(nexthops, nexthop, {
EXPECT_TRUE(nexthop == NEXTHOP_ID1 || nexthop == NEXTHOP_ID2);
diff --git a/hicn-light/src/hicn/test/test-subscription.cc b/hicn-light/src/hicn/test/test-subscription.cc
index f89254e67..5fd3ab57d 100644
--- a/hicn-light/src/hicn/test/test-subscription.cc
+++ b/hicn-light/src/hicn/test/test-subscription.cc
@@ -40,10 +40,10 @@ TEST_F(SubscriptionTest, SetTopic) {
TEST_F(SubscriptionTest, GetObjectFromTopic) {
hc_object_type_t object_type = object_from_topic(TOPIC_STRATEGY);
- EXPECT_EQ(object_type, OBJECT_STRATEGY);
+ EXPECT_EQ(object_type, OBJECT_TYPE_STRATEGY);
object_type = object_from_topic(TOPIC_FACE);
- EXPECT_EQ(object_type, OBJECT_FACE);
+ EXPECT_EQ(object_type, OBJECT_TYPE_FACE);
}
TEST_F(SubscriptionTest, AddSubscription) {
@@ -201,4 +201,4 @@ TEST_F(SubscriptionTest, GetConnectionsForSubscription) {
subscription_table_get_connections_for_topic(subscriptions, TOPIC_FACE);
EXPECT_EQ(vector_len(conn_ids), 1u);
EXPECT_EQ(conn_ids[0], (unsigned)CONN_ID);
-} \ No newline at end of file
+}
diff --git a/hicn-light/src/hicn/test/test-vector.cc b/hicn-light/src/hicn/test/test-vector.cc
deleted file mode 100644
index dda71fd0c..000000000
--- a/hicn-light/src/hicn/test/test-vector.cc
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (c) 2021 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>
-
-extern "C" {
-#include <hicn/util/vector.h>
-}
-
-static constexpr size_t DEFAULT_SIZE = 10;
-static constexpr size_t N_ELEMENTS = 5;
-
-class VectorTest : public ::testing::Test {
- protected:
- VectorTest() { vector_init(vector, DEFAULT_SIZE, 0); }
- virtual ~VectorTest() { vector_free(vector); }
-
- int *vector = NULL;
-};
-
-TEST_F(VectorTest, VectorAllocateAndResize) {
- // Allocated size should be the next power of two
- EXPECT_EQ(vector_get_alloc_size(vector), 16UL);
-
- // Setting elements within the allocated size should not trigger a resize
- vector_ensure_pos(vector, 15);
- EXPECT_EQ(vector_get_alloc_size(vector), 16UL);
-
- // Setting elements after should through
- vector_ensure_pos(vector, 16);
- EXPECT_EQ(vector_get_alloc_size(vector), 32UL);
-}
-
-TEST_F(VectorTest, VectorSize) {
- EXPECT_EQ(vector_len(vector), 0);
-
- // Check size after pushing one element
- vector_push(vector, 1);
- EXPECT_EQ(vector_len(vector), 1);
-
- // Check size after pushing additional elements
- vector_push(vector, 2);
- vector_push(vector, 3);
- EXPECT_EQ(vector_len(vector), 3);
-
- // Try adding multiple elements
- const int n_elements_to_add = 5;
- size_t expected_new_len = vector_len(vector) + n_elements_to_add;
- for (int i = 0; i < n_elements_to_add; i++) vector_push(vector, i);
- EXPECT_EQ(vector_len(vector), expected_new_len);
-}
-
-TEST_F(VectorTest, VectorCheckValue) {
- // Add elements
- vector_push(vector, 109);
- vector_push(vector, 200);
- EXPECT_EQ(vector_at(vector, 0), 109);
- EXPECT_EQ(vector_at(vector, 1), 200);
-
- // Update element
- vector_set(vector, 1, 400);
- EXPECT_EQ(vector_at(vector, 1), 400);
-
- // Add at last available position
- size_t prev_size = vector_len(vector);
- vector_set(vector, vector_len(vector) - 1, 123);
- EXPECT_EQ(vector_at(vector, vector_len(vector) - 1), 123);
- EXPECT_EQ(prev_size, vector_len(vector)) << "Size should not have changed";
-}
-
-TEST_F(VectorTest, RemoveElement) {
- // Populate vector
- for (size_t i = 0; i < N_ELEMENTS; i++) vector_push(vector, i);
- EXPECT_EQ(vector_len(vector), N_ELEMENTS);
- for (size_t i = 0; i < vector_len(vector); i++)
- EXPECT_EQ(vector_at(vector, i), (int)i);
-
- // Remove element
- int value_to_remove = 3;
- int num_removed = vector_remove_unordered(vector, value_to_remove);
-
- EXPECT_EQ(vector_len(vector), N_ELEMENTS - 1);
- EXPECT_EQ(num_removed, 1);
- for (size_t i = 0; i < vector_len(vector); i++)
- EXPECT_NE(vector_at(vector, i), value_to_remove);
-}
-
-TEST_F(VectorTest, RemoveNonExistingElement) {
- // Push some initial values
- vector_push(vector, 1);
- vector_push(vector, 2);
- vector_push(vector, 3);
- EXPECT_EQ(vector_len(vector), 3);
-
- // Remove non-existing element
- int num_removed = vector_remove_unordered(vector, 5);
- EXPECT_EQ(num_removed, 0);
- size_t prev_size = vector_len(vector);
- EXPECT_EQ(prev_size, vector_len(vector)) << "Size should not have changed";
-}
-
-TEST_F(VectorTest, RemoveDuplicatedElement) {
- // Populate vector
- for (size_t i = 0; i < N_ELEMENTS; i++) vector_push(vector, i);
- EXPECT_EQ(vector_len(vector), N_ELEMENTS);
- for (size_t i = 0; i < vector_len(vector); i++)
- EXPECT_EQ(vector_at(vector, i), (int)i);
- vector_set(vector, 0, 3); // Duplicate element
-
- // Remove (duplicated) elements
- int value_to_remove = 3;
- int num_removed = vector_remove_unordered(vector, value_to_remove);
-
- EXPECT_EQ(vector_len(vector), N_ELEMENTS - 2);
- EXPECT_EQ(num_removed, 2);
- for (size_t i = 0; i < vector_len(vector); i++)
- EXPECT_NE(vector_at(vector, i), value_to_remove);
-}
-
-TEST_F(VectorTest, Iterate) {
- for (size_t i = 0; i < N_ELEMENTS; i++) vector_push(vector, i);
-
- int count = 0;
- int *elem;
- vector_foreach(vector, elem, { EXPECT_EQ(*elem, count++); });
-}
-
-TEST_F(VectorTest, MultipleResize) {
- // Use small vector (size=1) to force multiple realloc operations
- int *small_vector;
- vector_init(small_vector, 1, 0);
-
- for (size_t i = 0; i < N_ELEMENTS; i++) vector_push(small_vector, i);
-
- for (size_t i = 0; i < N_ELEMENTS; i++)
- EXPECT_EQ(vector_at(small_vector, i), (int)i);
-
- EXPECT_EQ(vector_len(small_vector), 5UL);
- EXPECT_EQ(vector_get_alloc_size(small_vector), 8UL);
-
- vector_free(small_vector);
-}
-
-TEST_F(VectorTest, MaxSize) {
- const int max_size = 4;
-
- // Fill the vector until max size is reached
- int *small_vector;
- vector_init(small_vector, 2, max_size);
- for (int i = 0; i < max_size; i++) vector_push(small_vector, i);
-
- // Try expanding or appending elements should fail
- int rc = vector_ensure_pos(small_vector, max_size);
- EXPECT_EQ(rc, -1);
- rc = vector_push(small_vector, 123);
- EXPECT_EQ(rc, -1);
-
- vector_free(small_vector);
-}
-
-TEST_F(VectorTest, Contains) {
- // No elements
- EXPECT_EQ(vector_contains(vector, 1), false);
-
- // Push one element
- vector_push(vector, 1);
- EXPECT_EQ(vector_contains(vector, 1), true);
-
- // Update element
- vector_set(vector, 0, 2);
- EXPECT_EQ(vector_contains(vector, 1), false);
- EXPECT_EQ(vector_contains(vector, 2), true);
-}
-
-TEST_F(VectorTest, Remove) {
- // Remove element at invalid position
- int rc = vector_remove_at(vector, 2);
- EXPECT_EQ(rc, -1); // Failure
-
- // Push two elements and remove the second one
- vector_push(vector, 1);
- vector_push(vector, 2);
- rc = vector_remove_at(vector, 1);
- EXPECT_EQ(rc, 0); // Success
- EXPECT_EQ(vector_len(vector), 1);
-
- // Push another element: it should replace the previous one
- vector_push(vector, 3);
- EXPECT_EQ(vector_len(vector), 2);
- EXPECT_EQ(vector_at(vector, 1), 3);
-}
-
-TEST_F(VectorTest, RemoveInTheMiddle) {
- for (size_t i = 0; i < N_ELEMENTS; i++) vector_push(vector, i);
-
- // Remove element in central position
- int rc = vector_remove_at(vector, 2);
- EXPECT_EQ(rc, 0); // Success
- EXPECT_EQ(vector_contains(vector, 2), false);
- EXPECT_EQ(vector_len(vector), N_ELEMENTS - 1);
-
- // Check if elements have been shifted (preserving the order)
- int expected[] = {0, 1, 3, 4};
- for (int i = 0; i < vector_len(vector); i++)
- EXPECT_EQ(vector_at(vector, i), expected[i]);
-}
-
-TEST_F(VectorTest, Reset) {
- vector_push(vector, 1);
- vector_push(vector, 2);
- EXPECT_EQ(vector_len(vector), 2);
-
- vector_reset(vector);
- EXPECT_EQ(vector_len(vector), 0);
-
- vector_push(vector, 5);
- EXPECT_EQ(vector_len(vector), 1);
- EXPECT_EQ(vector_contains(vector, 5), true);
- EXPECT_EQ(vector_at(vector, 0), 5);
-} \ No newline at end of file
diff --git a/hicn-light/src/hicn/test/test-hash.cc b/hicn-light/src/hicn/test/test_hash.cc
index 3b03a08a6..c742aa248 100644
--- a/hicn-light/src/hicn/test/test-hash.cc
+++ b/hicn-light/src/hicn/test/test_hash.cc
@@ -187,8 +187,7 @@ TEST(HashTest, PerformanceComparisonBigStruct) {
TEST(HashTest, CollisionsComparison) {
small_struct_t small_struct = {0};
std::unordered_set<uint32_t> hashes;
- int n_collisions_fnv = 0, n_collisions_jenkins = 0, n_collisions_murmur = 0,
- n_collisions_xxhash = 0;
+ int n_collisions_fnv = 0, n_collisions_jenkins = 0;
// FNV
for (int i = 0; i < 10 * N_HASHES; i++) {