aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/test/test-packet_cache.cc
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/test/test-packet_cache.cc')
-rw-r--r--hicn-light/src/hicn/test/test-packet_cache.cc240
1 files changed, 128 insertions, 112 deletions
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
+}