aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src/test
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2022-09-16 13:56:34 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2022-09-23 15:18:44 +0200
commitadbdfdf7489e1909f29e2dd02edb7d15c258ed19 (patch)
treee12231bddf4d19be089af34d131760e58ddba62f /lib/src/test
parentb498b1d3fe2684e0233986551fa581a07148e22b (diff)
fix(hicn-light): fix routing issues
Ref: HICN-786 Change-Id: I541c87d2d810907489ca4f59b3d7740a18c108fb Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'lib/src/test')
-rw-r--r--lib/src/test/CMakeLists.txt1
-rw-r--r--lib/src/test/test_ip_address.cc73
-rw-r--r--lib/src/test/test_name.cc61
3 files changed, 135 insertions, 0 deletions
diff --git a/lib/src/test/CMakeLists.txt b/lib/src/test/CMakeLists.txt
index d828c8dd8..8cf4359d2 100644
--- a/lib/src/test/CMakeLists.txt
+++ b/lib/src/test/CMakeLists.txt
@@ -24,6 +24,7 @@ list(APPEND TESTS_SRC
test_validation.cc
test_bitmap.cc
test_interest_manifest.cc
+ test_ip_address.cc
test_khash.cc
test_pool.cc
test_ring.cc
diff --git a/lib/src/test/test_ip_address.cc b/lib/src/test/test_ip_address.cc
new file mode 100644
index 000000000..1a7efb603
--- /dev/null
+++ b/lib/src/test/test_ip_address.cc
@@ -0,0 +1,73 @@
+/*
+ * 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>
+
+extern "C"
+{
+#define WITH_TESTS
+#include <hicn/util/ip_address.h>
+}
+
+#define DEFAULT_SIZE 10
+
+class IPAddressTest : public ::testing::Test
+{
+protected:
+ IPAddressTest () {}
+
+ virtual ~IPAddressTest () {}
+};
+
+TEST_F (IPAddressTest, IPAddressGetBit)
+{
+ hicn_ip_address_t a_0, a_1, a_1_0, a_1_1, a_1_48, a_1_49, a_1_63, a_1_64,
+ a_1_127;
+
+ hicn_ip_address_pton ("0::0", &a_0);
+ hicn_ip_address_pton ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", &a_1);
+
+ hicn_ip_address_pton ("8000::0", &a_1_0);
+ hicn_ip_address_pton ("4000::0", &a_1_1);
+ hicn_ip_address_pton ("0:0:0:8000::0", &a_1_48);
+ hicn_ip_address_pton ("0:0:0:4000::0", &a_1_49);
+ hicn_ip_address_pton ("0:0:0:1::0", &a_1_63);
+ hicn_ip_address_pton ("0::8000:0:0:0", &a_1_64);
+ hicn_ip_address_pton ("0::1", &a_1_127);
+
+#if 0
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_0, i), 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1, i), 1);
+#endif
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_0, i), (i == 0) ? 1 : 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_1, i), (i == 1) ? 1 : 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_48, i), (i == 48) ? 1 : 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_49, i), (i == 49) ? 1 : 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_63, i), (i == 63) ? 1 : 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_64, i), (i == 64) ? 1 : 0);
+ for (unsigned i = 0; i < 128; i++)
+ EXPECT_EQ (hicn_ip_address_get_bit (&a_1_127, i), (i == 127) ? 1 : 0);
+}
diff --git a/lib/src/test/test_name.cc b/lib/src/test/test_name.cc
index dbeab96cc..cd9ff2d4d 100644
--- a/lib/src/test/test_name.cc
+++ b/lib/src/test/test_name.cc
@@ -335,3 +335,64 @@ TEST_F (NameTest, NameNToP)
rc = strcmp (dst, expected4.str ().c_str ());
EXPECT_EQ (rc, 0);
}
+
+class PrefixTest : public ::testing::Test
+{
+protected:
+ PrefixTest () {}
+
+ virtual ~PrefixTest () {}
+};
+
+#define HICN_PREFIX(P, STR) \
+ hicn_prefix_t P; \
+ hicn_ip_prefix_t _##P; \
+ EXPECT_EQ (hicn_ip_prefix_pton (STR, &_##P), 0); \
+ EXPECT_EQ (hicn_prefix_create_from_ip_prefix (&_##P, &P), 0);
+
+TEST_F (PrefixTest, PrefixClear)
+{
+ HICN_PREFIX (hp_all, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128");
+
+ for (unsigned i = 0; i < 127; i++)
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, i), 1);
+
+ hicn_prefix_truncate (&hp_all, 127);
+ EXPECT_EQ (hicn_prefix_get_len (&hp_all), 127);
+
+ for (unsigned i = 0; i < 126; i++)
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, i), 1) << "bit[" << i << "] != 1";
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 127), 0);
+
+ hicn_prefix_truncate (&hp_all, 126);
+ EXPECT_EQ (hicn_prefix_get_len (&hp_all), 126);
+
+ for (unsigned i = 0; i < 125; i++)
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, i), 1);
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 126), 0);
+ EXPECT_EQ (_hicn_prefix_get_bit (&hp_all, 127), 0);
+}
+
+TEST_F (PrefixTest, PrefixClear2)
+{
+ HICN_PREFIX (hp_all, "b002::3");
+
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 125), 0);
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 126), 1);
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 127), 1);
+
+ hicn_prefix_truncate (&hp_all, 127);
+ EXPECT_EQ (hicn_prefix_get_len (&hp_all), 127);
+
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 125), 0);
+ EXPECT_EQ (hicn_prefix_get_bit (&hp_all, 126), 1);
+ EXPECT_EQ (_hicn_prefix_get_bit (&hp_all, 127), 0);
+}
+
+TEST_F (PrefixTest, PrefixLPM)
+{
+ HICN_PREFIX (b007, "b007::/64");
+ HICN_PREFIX (b009, "b009::/64");
+
+ EXPECT_EQ (hicn_prefix_lpm (&b007, &b009), (uint32_t) 12);
+}