summaryrefslogtreecommitdiffstats
path: root/hicn-light/src
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2022-09-21 17:11:22 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2022-09-30 09:17:13 +0200
commit3476dd9ddecc87d9212c3bf56a5be52079e27def (patch)
tree3c7ea2664e8f99fc4fd4588b9e4493f0dc9bbb93 /hicn-light/src
parent29647f687c8dadc90e2ba4d3a772eee09a1a4f1b (diff)
feat: support for new packet format in hicn-light
Ref: HICN-792 Change-Id: I3204006bd2dd2be6504c33035c6578ec0292455a Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'hicn-light/src')
-rw-r--r--hicn-light/src/hicn/core/fib.c126
-rw-r--r--hicn-light/src/hicn/io/CMakeLists.txt8
-rw-r--r--hicn-light/src/hicn/io/udp.c14
-rw-r--r--hicn-light/src/hicn/test/test-fib.cc60
4 files changed, 104 insertions, 104 deletions
diff --git a/hicn-light/src/hicn/core/fib.c b/hicn-light/src/hicn/core/fib.c
index 66e6ae339..b3b5d4036 100644
--- a/hicn-light/src/hicn/core/fib.c
+++ b/hicn-light/src/hicn/core/fib.c
@@ -124,11 +124,13 @@ fib_node_t *fib_search(const fib_t *fib, const hicn_prefix_t *prefix,
uint32_t curr_len;
uint32_t match_len;
- char buf[MAXSZ_HICN_PREFIX];
- int rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix);
- if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- INFO("FIB SEARCH: %s prefix len %d", buf, prefix_len);
+ WITH_DEBUG({
+ char buf[MAXSZ_HICN_PREFIX];
+ int rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix);
+ if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
+ snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
+ DEBUG("[fib_search] prefix=%s prefix_len=%d\n", buf, prefix_len);
+ });
fib_node_t *parent = NULL;
fib_node_t *gparent = NULL;
@@ -136,23 +138,13 @@ fib_node_t *fib_search(const fib_t *fib, const hicn_prefix_t *prefix,
while (curr) {
const hicn_prefix_t *curr_prefix = fib_entry_get_prefix(curr->entry);
- rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, curr_prefix);
- if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- INFO(" >> current %s", buf);
-
curr_len = hicn_prefix_get_len(curr_prefix);
match_len = hicn_prefix_lpm(prefix, curr_prefix);
- INFO("curr len %d match len %d", curr_len, match_len);
-
- // XXX >= vs == for the second stop condition
// curr_len >= prefix_len l >= L
// L is a prefix of l
// > means we did not find
// = means we could have found
- // leverage this info for contains!
- // XXX remove this comment when done
if (match_len < curr_len || curr_len >= prefix_len) break;
gparent = parent;
@@ -191,30 +183,14 @@ fib_node_t *_fib_insert(fib_t *fib, fib_entry_t *entry, fib_node_t *parent,
const hicn_prefix_t *parent_prefix = fib_entry_get_prefix(parent->entry);
uint32_t parent_prefix_len = hicn_prefix_get_len(parent_prefix);
uint8_t next_bit = hicn_prefix_get_bit(prefix, parent_prefix_len);
- INFO("parent prefix len %d next bit %d", parent_prefix_len, next_bit);
parent->child[next_bit] = new_node;
}
if (child) {
- char buf[MAXSZ_HICN_PREFIX];
- int rc;
-
const hicn_prefix_t *child_prefix = fib_entry_get_prefix(child->entry);
- INFO("prefix lengths %d==127 %d==128", hicn_prefix_get_len(prefix),
- hicn_prefix_get_len(child_prefix));
- INFO("LPM BETWEEN");
- rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix);
- if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- INFO("prefix %s", buf);
- rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, child_prefix);
- if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- INFO("child prefix %s", buf);
uint32_t match_len = hicn_prefix_lpm(prefix, child_prefix);
uint8_t next_bit = hicn_prefix_get_bit(child_prefix, match_len);
new_node->child[next_bit] = child;
- INFO("child match len %d next bit %d", match_len, next_bit);
}
if (is_used) fib->size++;
@@ -319,16 +295,34 @@ void fib_add(fib_t *fib, fib_entry_t *entry) {
fib_search_t search;
fib_node_t *curr = fib_search(fib, prefix, &search);
+ char buf[MAXSZ_HICN_PREFIX];
+ char buf2[MAXSZ_HICN_PREFIX];
+ int rc;
+
+ rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix);
+ if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
+ snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
+ if (curr) {
+ rc = hicn_prefix_snprintf(buf2, MAXSZ_HICN_PREFIX,
+ fib_entry_get_prefix(curr->entry));
+ if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
+ snprintf(buf2, MAXSZ_HICN_PREFIX, "%s", "(error)");
+ } else {
+ snprintf(buf2, MAXSZ_HICN_PREFIX, "%s", "(null)");
+ search.prefix_len = 0;
+ search.match_len = 0;
+ }
+ DEBUG("fib_search(%s) result: curr=%s, prefix_len=%d; match_len=%d\n", buf,
+ buf2, search.prefix_len, search.match_len);
+
/* Case 1 */
if (!curr) {
- INFO("Case 1");
_fib_insert(fib, entry, search.parent, NULL, true);
goto END;
}
/* Case 2 */
if (search.prefix_len == search.match_len && prefix_len == search.match_len) {
- INFO("Case 2");
if (!curr->is_used) {
curr->is_used = true;
if (curr->entry) fib_entry_free(curr->entry);
@@ -345,51 +339,28 @@ void fib_add(fib_t *fib, fib_entry_t *entry) {
/* Case 3 */
if (prefix_len == search.match_len) {
- INFO("Case 3");
_fib_insert(fib, entry, search.parent, curr, true);
goto END;
}
/* Case 4 */
- char buf[MAXSZ_HICN_PREFIX];
- int rc;
-
- INFO("Case 4 : match len = %d", search.match_len);
hicn_prefix_t inner_prefix; /* dup'ed in fib_entry_create */
hicn_prefix_copy(&inner_prefix, prefix);
- rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, &inner_prefix);
- if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- INFO("inner prefix before truncate %s", buf);
- INFO("last bit should be 1: %d", hicn_prefix_get_bit(&inner_prefix, 127));
-
- INFO("truncate to length = %d", search.match_len);
hicn_prefix_truncate(&inner_prefix, search.match_len);
- INFO("last bit should be 0: %d", hicn_prefix_get_bit(&inner_prefix, 127));
-
- rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, &inner_prefix);
- if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- INFO("inner prefix after truncate %s", buf);
fib_entry_t *inner_entry = fib_entry_create(
&inner_prefix, STRATEGY_TYPE_UNDEFINED, NULL, fib->forwarder);
- INFO("inner prefix len=%d", hicn_prefix_get_len(&inner_prefix));
- // debug
- const hicn_prefix_t *parent_prefix = fib_entry_get_prefix(inner_entry);
- INFO("inner prefix len=%d", hicn_prefix_get_len(parent_prefix));
-
- INFO("insert inner");
fib_node_t *new_node =
_fib_insert(fib, inner_entry, search.parent, curr, false);
- INFO("insert new node");
- fib_dump(fib);
_fib_insert(fib, entry, new_node, NULL, true);
END:
+#if 0
fib_dump(fib);
+#endif
+ ; /* required for clang */
}
/*
@@ -695,18 +666,16 @@ bool __fib_check_preorder(const fib_node_t *node,
if (!hicn_prefix_equals(prefix, prefix_array[*pos])) {
char buf[MAXSZ_HICN_PREFIX];
+ char buf2[MAXSZ_HICN_PREFIX];
int rc;
- ERROR("Prefix mismatch in position %d %s != %s", pos);
rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix);
if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- ERROR("Expected: %s", buf);
-
- rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix_array[*pos]);
+ rc = hicn_prefix_snprintf(buf2, MAXSZ_HICN_PREFIX, prefix_array[*pos]);
if (rc < 0 || rc >= MAXSZ_HICN_PREFIX)
- snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)");
- ERROR("Expected: %s", buf);
+ snprintf(buf2, MAXSZ_HICN_PREFIX, "%s", "(error)");
+ ERROR("Prefix mismatch in position %ld %s != %s", *pos, buf, buf2);
return false;
}
@@ -736,7 +705,7 @@ bool _fib_check_preorder(const fib_t *fib, const hicn_prefix_t **prefix_array,
}
// XXX print empty node but not recurse
-void _fib_dump(const fib_node_t *node, int start, int indent) {
+void _fib_dump(const fib_node_t *node, int start, int indent, int location) {
char buf[MAXSZ_HICN_PREFIX];
if (node) {
@@ -748,20 +717,25 @@ void _fib_dump(const fib_node_t *node, int start, int indent) {
snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(null)");
}
- // Left
if (indent > 0) {
- for (int i = 0; i < start - 1; i++) printf(" ");
- for (int i = start + 1; i < indent; i++) printf("| ");
- printf("|");
- printf("_ %s\n", buf);
- } else {
- printf("%s\n", buf);
+ for (int i = 0; i < start; i++) printf(" ");
+ for (int i = 0; i < indent - start - 1; i++) printf("| ");
+ printf("|_ ");
}
+ printf("%s", buf);
+ if (node && !node->is_used) printf(" [inner]");
+ printf("\n");
if (!node) return;
- _fib_dump(node->child[ZERO], start, indent + 1);
- _fib_dump(node->child[ONE], start + 1, indent + 1);
+ if (location == 2) {
+ start++;
+ location = 0;
+ }
+ _fib_dump(node->child[ZERO], start, indent + 1,
+ (location == 0) ? 1 : location);
+ _fib_dump(node->child[ONE], start, indent + 1,
+ (location == 0) ? 2 : location);
}
-void fib_dump(const fib_t *fib) { _fib_dump(fib->root, 0, 0); }
+void fib_dump(const fib_t *fib) { _fib_dump(fib->root, 0, 0, 0); }
diff --git a/hicn-light/src/hicn/io/CMakeLists.txt b/hicn-light/src/hicn/io/CMakeLists.txt
index 68a5baec5..1a04aad75 100644
--- a/hicn-light/src/hicn/io/CMakeLists.txt
+++ b/hicn-light/src/hicn/io/CMakeLists.txt
@@ -21,13 +21,5 @@ list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/udp.c
)
-#if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
-# list(APPEND SOURCE_FILES
-# io/hicnTunnel.c
-# io/hicnConnection.c
-# io/hicnListener.c
-# )
-#endif()
-
set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
diff --git a/hicn-light/src/hicn/io/udp.c b/hicn-light/src/hicn/io/udp.c
index b06ee7bce..d704a64f1 100644
--- a/hicn-light/src/hicn/io/udp.c
+++ b/hicn-light/src/hicn/io/udp.c
@@ -15,10 +15,8 @@
/**
* @file udp.c
- * #brief Implementation of the UDP face
- *
- * Old comment:
- * - The Send() function may overflow the output buffer
+ * #brief Implementation of the native UDP face leveraging the new packet format
+ * to avoid encapsulation.
*
*/
@@ -59,14 +57,6 @@
#include "../core/listener.h"
#include "../core/listener_vft.h"
#include "../core/msgbuf.h"
-//#include "../hicn-light/config.h"
-
-// Batching based on recvmmsg is also generic
-// the difference is the handling of packet as in tcp we need to go through the
-// ring buffer first to do the framing, while in UDP this is already done
-//
-// each module should have a function to process a packet, then call a callback
-// in the forwarder again
#define BATCH_SOCKET_BUFFER 512 * 1024 /* 256k */
diff --git a/hicn-light/src/hicn/test/test-fib.cc b/hicn-light/src/hicn/test/test-fib.cc
index 125515e41..d2c5d1e1c 100644
--- a/hicn-light/src/hicn/test/test-fib.cc
+++ b/hicn-light/src/hicn/test/test-fib.cc
@@ -55,20 +55,30 @@ void _fib_add_prefix(fib_t *fib, const hicn_prefix_t *prefix) {
fib_add(fib, entry);
}
+#if 0
static const hicn_prefix_t p0010 = (hicn_prefix_t){
.name = {.v6 = {.as_u64 = {0x1122334455667788, 0x9900aabbccddeeff}}},
.len = 4};
+#endif
+
+#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: Fib allocation and initialization */
TEST_F(FibTest, FibAddOne) {
/* Empty fib should be valid */
+ HICN_PREFIX(pfx, "1122:3344:5566:7788:9900:aabb:ccdd:eeff/4");
+
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};
+ const hicn_prefix_t *prefix_array[] = {&pfx};
bool used_array[] = {true};
for (unsigned i = 0; i < ARRAY_SIZE(prefix_array); i++) {
@@ -84,10 +94,44 @@ TEST_F(FibTest, FibAddOne) {
/* Check that free indices and bitmaps are correctly updated */
}
-#if 0
-22-09-2022 13:07:57 fib_entry_on_event: b002::/64
-22-09-2022 13:08:01 fib_entry_on_event: b002::abcd:0:0:0/128
-22-09-2022 13:08:01 fib_entry_on_event: b002::2/128
-22-09-2022 13:08:01 fib_entry_on_event: b002::abcd:0:0:1/128
-22-09-2022 13:08:01 fib_entry_on_event: b002::3/128
-#endif
+TEST_F(FibTest, FibAddTwo) {
+ HICN_PREFIX(b001, "b001::/64");
+ HICN_PREFIX(c001, "c001::/64");
+ HICN_PREFIX(inner_8000_1, "8000::/1");
+
+ const hicn_prefix_t *prefix_array[] = {&b001, &inner_8000_1, &c001};
+ bool used_array[] = {true, false, true};
+
+ _fib_add_prefix(fib, &b001);
+ _fib_add_prefix(fib, &c001);
+
+ fib_dump(fib);
+
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array));
+}
+
+TEST_F(FibTest, FibAddFive) {
+ HICN_PREFIX(b002, "b002::/64");
+ HICN_PREFIX(b002_abcd_0, "b002::abcd:0:0:0/128");
+ HICN_PREFIX(b002_2, "b002::2/128");
+ HICN_PREFIX(b002_abcd_1, "b002::abcd:0:0:1/128");
+ HICN_PREFIX(b002_3, "b002::3/128");
+ HICN_PREFIX(inner_b002_2, "b002::2/127");
+ HICN_PREFIX(inner_b002_abcd_0, "b002::abcd:0:0:0/127");
+ const hicn_prefix_t *prefix_array[] = {
+ &b002_2, &inner_b002_2, &b002_3, &b002,
+ &b002_abcd_0, &inner_b002_abcd_0, &b002_abcd_1};
+ bool used_array[] = {true, false, true, true, true, false, true};
+
+ _fib_add_prefix(fib, &b002);
+ _fib_add_prefix(fib, &b002_abcd_0);
+ _fib_add_prefix(fib, &b002_2);
+ _fib_add_prefix(fib, &b002_abcd_1);
+ _fib_add_prefix(fib, &b002_3);
+
+ fib_dump(fib);
+
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array));
+}