From 32dccec98e4c7d7e4ce902e19ba8d1b29b823758 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Wed, 23 Sep 2020 17:50:52 +0200 Subject: [HICN-570] Message buffer (incl. CS and PIT changes) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4c508e4b04dee3acbfc3da1d26e1770cb826f22b Signed-off-by: Jordan Augé --- hicn-light/src/hicn/core/pit.c | 132 +++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 50 deletions(-) (limited to 'hicn-light/src/hicn/core/pit.c') diff --git a/hicn-light/src/hicn/core/pit.c b/hicn-light/src/hicn/core/pit.c index fa54e2429..e80d895ec 100644 --- a/hicn-light/src/hicn/core/pit.c +++ b/hicn-light/src/hicn/core/pit.c @@ -31,43 +31,56 @@ #include #include +#include #define __STDC_FORMAT_MACROS #include -#include -#include -#include #include +#include "msgbuf.h" +#include "msgbuf_pool.h" +#include "ticks.h" +#include "../base/pool.h" + #include "pit.h" // XXX TODO Should not be defined here #define DEFAULT_INTEREST_LIFETIME 4000000000ULL -static Ticks _pit_calculate_lifetime(pit_t * pit, - msgbuf_t *interest_msgbuf) { - uint64_t interestLifetimeTicks = - msgbuf_get_interest_lifetime(interest_msgbuf); - if (interestLifetimeTicks == 0) { - interestLifetimeTicks = NSEC_TO_TICKS(DEFAULT_INTEREST_LIFETIME); - } +static +Ticks +_pit_calculate_lifetime(pit_t * pit, const msgbuf_t * msgbuf) +{ + uint64_t lifetime = msgbuf_get_lifetime(msgbuf); + if (lifetime == 0) + lifetime = NSEC_TO_TICKS(DEFAULT_INTEREST_LIFETIME); - Ticks expiry_time = ticks_now() + interestLifetimeTicks; - return expiry_time; + return ticks_now() + lifetime; } -// max_elts default is 65535 +/* This is only used as a hint for first allocation, as the table is resizeable */ +#define DEFAULT_PIT_SIZE 65535 + pit_t * -pit_create(size_t max_elts) +_pit_create(size_t init_size, size_t max_size) { pit_t * pit = malloc(sizeof(pit_t)); if (!pit) return NULL; - pool_init(pit->entries, max_elts); + if (init_size == 0) + init_size = DEFAULT_PIT_SIZE; + + pit->max_size = max_size; + + /* Initialize indices */ pit->index_by_name = kh_init(pit_name); - DEBUG("PIT %p created", pit); + /* + * We start by allocating a reasonably-sized pool, as this will eventually + * be resized if needed. + */ + pool_init(pit->entries, init_size, 0); return pit; } @@ -76,53 +89,57 @@ void pit_free(pit_t * pit) { assert(pit); - // XXX TODO + + free(pit); DEBUG("PIT %p destroyed", pit); } pit_verdict_t -pit_on_interest(pit_t * pit, msgbuf_t * interest_msgbuf) +pit_on_interest(pit_t * pit, off_t msgbuf_id) { assert(pit); - assert(interest_msgbuf); - assert(msgbuf_get_type(interest_msgbuf) == MESSAGE_TYPE_INTEREST); + assert(msgbuf_id_is_valid(msgbuf_id)); + + const msgbuf_pool_t * msgbuf_pool = pit_get_msgbuf_pool(pit); + const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id); + assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_INTEREST); fib_entry_t * fib_entry; - Ticks expiry_time; + Ticks expire_ts; /* Lookup entry by name */ - khiter_t k = kh_get_pit_name(pit->index_by_name, msgbuf_get_name(interest_msgbuf)); + khiter_t k = kh_get_pit_name(pit->index_by_name, msgbuf_get_name(msgbuf)); if (k == kh_end(pit->index_by_name)) goto NOT_FOUND; pit_entry_t * entry = pit->entries + kh_val(pit->index_by_name, k); assert(entry); // has it expired? - if (ticks_now() >= pit_entry_get_expiry_time(entry)) + if (ticks_now() >= pit_entry_get_expire_ts(entry)) goto TIMEOUT; /* Extend entry lifetime */ - expiry_time = _pit_calculate_lifetime(pit, interest_msgbuf); - if (expiry_time > pit_entry_get_expiry_time(entry)) - pit_entry_set_expiry_time(entry, expiry_time); + expire_ts = _pit_calculate_lifetime(pit, msgbuf); + if (expire_ts > pit_entry_get_expire_ts(entry)) + pit_entry_set_expire_ts(entry, expire_ts); - unsigned connection_id = msgbuf_get_connection_id(interest_msgbuf); + unsigned connection_id = msgbuf_get_connection_id(msgbuf); // Is the reverse path already in the PIT entry? if (pit_entry_ingress_contains(entry, connection_id)) { // It is already in the PIT entry, so this is a retransmission, so // forward it. - DEBUG("Message %p existing entry (expiry %" PRIu64 ") and reverse path, forwarding", - interest_msgbuf, pit_entry_get_expiry_time(entry)); + DEBUG("Message %lu existing entry (expiry %" PRIu64 ") and reverse path, forwarding", + msgbuf_id, pit_entry_get_expire_ts(entry)); return PIT_VERDICT_RETRANSMIT; } // It is in the PIT but this is the first interest for the reverse path pit_entry_ingress_add(entry, connection_id); - DEBUG("Message %p existing entry (expiry %" PRIu64 ") and reverse path is new, aggregate", - interest_msgbuf, pit_entry_get_expiry_time(entry)); + DEBUG("Message %lu existing entry (expiry %" PRIu64 ") and reverse path is new, aggregate", + msgbuf_id, pit_entry_get_expire_ts(entry)); return PIT_VERDICT_AGGREGATE; TIMEOUT: @@ -131,36 +148,46 @@ TIMEOUT: fib_entry_on_timeout(fib_entry, pit_entry_get_egress(entry)); // it's an old entry, remove it - k = kh_get(pit_name, pit->index_by_name, msgbuf_get_name(interest_msgbuf)); + k = kh_get(pit_name, pit->index_by_name, msgbuf_get_name(msgbuf)); if (k != kh_end(pit->index_by_name)) kh_del(pit_name, pit->index_by_name, k); NOT_FOUND: /* Create PIT entry */ - expiry_time = _pit_calculate_lifetime(pit, interest_msgbuf); + expire_ts = _pit_calculate_lifetime(pit, msgbuf); - pit_allocate(pit, entry, interest_msgbuf); - pit_entry_from_msgbuf(entry, interest_msgbuf, expiry_time, ticks_now()); + pit_allocate(pit, entry, msgbuf); - DEBUG("Message %p added to PIT (expiry %" PRIu64 ") ingress %u", - interest_msgbuf, pit_entry_get_expiry_time(entry), - msgbuf_get_connection_id(interest_msgbuf)); + *entry = (pit_entry_t) { + .msgbuf_id = msgbuf_id, + .fib_entry = NULL, + .create_ts = ticks_now(), + .expire_ts = expire_ts, + }; + pit_entry_ingress_add(entry, msgbuf_get_connection_id(msgbuf)); + + DEBUG("Message %lu added to PIT (expiry %" PRIu64 ") ingress %u", + msgbuf_id, pit_entry_get_expire_ts(entry), + msgbuf_get_connection_id(msgbuf)); return PIT_VERDICT_FORWARD; } nexthops_t * -pit_on_data(pit_t * pit, const msgbuf_t * data_msgbuf) +pit_on_data(pit_t * pit, off_t msgbuf_id) { assert(pit); - assert(data_msgbuf); - assert(msgbuf_get_type(data_msgbuf) == MESSAGE_TYPE_DATA); + assert(msgbuf_id_is_valid(msgbuf_id)); + + const msgbuf_pool_t * msgbuf_pool = pit_get_msgbuf_pool(pit); + const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id); + assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_DATA); nexthops_t * nexthops = NULL; /* Lookup entry by name */ - khiter_t k = kh_get_pit_name(pit->index_by_name, msgbuf_get_name(data_msgbuf)); + khiter_t k = kh_get_pit_name(pit->index_by_name, msgbuf_get_name(msgbuf)); if (k == kh_end(pit->index_by_name)) goto NOT_FOUND; @@ -170,14 +197,14 @@ pit_on_data(pit_t * pit, const msgbuf_t * data_msgbuf) // here we need to check if the PIT entry is expired // if so, remove the PIT entry. Ticks now = ticks_now(); - if (now >= pit_entry_get_expiry_time(entry)) + if (now >= pit_entry_get_expire_ts(entry)) goto TIMEOUT; /* PIT entry is not expired, use it */ fib_entry_t * fib_entry = pit_entry_get_fib_entry(entry); if (fib_entry) fib_entry_on_data(fib_entry, pit_entry_get_egress(entry), - data_msgbuf, pit_entry_get_creation_time(entry), ticks_now()); + msgbuf, pit_entry_get_create_ts(entry), ticks_now()); // XXX TODO : be sure nexthops are valid b/c pit entry is removed // XXX TODO eventually pass holding structure as parameter @@ -192,20 +219,25 @@ NOT_FOUND: } void -pit_remove(pit_t * pit, const msgbuf_t * interest_msgbuf) +pit_remove(pit_t * pit, off_t msgbuf_id) { assert(pit); - assert(interest_msgbuf); - assert(msgbuf_get_type(interest_msgbuf) == MESSAGE_TYPE_INTEREST); + assert(msgbuf_id_is_valid(msgbuf_id)); + + const msgbuf_pool_t * msgbuf_pool = pit_get_msgbuf_pool(pit); + const msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id); + + assert(msgbuf); + assert(msgbuf_get_type(msgbuf) == MSGBUF_TYPE_INTEREST); - khiter_t k = kh_get(pit_name, pit->index_by_name, msgbuf_get_name(interest_msgbuf)); + khiter_t k = kh_get(pit_name, pit->index_by_name, msgbuf_get_name(msgbuf)); if (k == kh_end(pit->index_by_name)) return; //off_t index = kh_val(pit->index_by_name, k); //pit_entry_t * entry = pit_at(pit, index); kh_del(pit_name, pit->index_by_name, k); - DEBUG("Message %p removed from PIT", interest_msgbuf); + DEBUG("Message %p removed from PIT", msgbuf); } pit_entry_t * @@ -213,7 +245,7 @@ pit_lookup(const pit_t * pit, const msgbuf_t * interest_msgbuf) { assert(pit); assert(interest_msgbuf); - assert(msgbuf_get_type(interest_msgbuf) == MESSAGE_TYPE_INTEREST); + assert(msgbuf_get_type(interest_msgbuf) == MSGBUF_TYPE_INTEREST); khiter_t k = kh_get(pit_name, pit->index_by_name, msgbuf_get_name(interest_msgbuf)); -- cgit 1.2.3-korg